/src/mozilla-central/layout/printing/PrintTranslator.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_layout_PrintTranslator_h |
8 | | #define mozilla_layout_PrintTranslator_h |
9 | | |
10 | | #include <istream> |
11 | | |
12 | | #include "mozilla/gfx/2D.h" |
13 | | #include "mozilla/gfx/Filters.h" |
14 | | #include "mozilla/gfx/RecordedEvent.h" |
15 | | #include "nsRefPtrHashtable.h" |
16 | | |
17 | | class nsDeviceContext; |
18 | | |
19 | | namespace mozilla { |
20 | | namespace layout { |
21 | | |
22 | | using gfx::Translator; |
23 | | using gfx::ReferencePtr; |
24 | | using gfx::DrawTarget; |
25 | | using gfx::Path; |
26 | | using gfx::SourceSurface; |
27 | | using gfx::FilterNode; |
28 | | using gfx::GradientStops; |
29 | | using gfx::ScaledFont; |
30 | | using gfx::UnscaledFont; |
31 | | using gfx::NativeFontResource; |
32 | | |
33 | | class PrintTranslator final : public Translator |
34 | | { |
35 | | public: |
36 | | explicit PrintTranslator(nsDeviceContext* aDeviceContext); |
37 | | |
38 | | bool TranslateRecording(PRFileDescStream& aRecording); |
39 | | |
40 | | DrawTarget* LookupDrawTarget(ReferencePtr aRefPtr) final |
41 | 0 | { |
42 | 0 | DrawTarget* result = mDrawTargets.GetWeak(aRefPtr); |
43 | 0 | MOZ_ASSERT(result); |
44 | 0 | return result; |
45 | 0 | } |
46 | | |
47 | | Path* LookupPath(ReferencePtr aRefPtr) final |
48 | 0 | { |
49 | 0 | Path* result = mPaths.GetWeak(aRefPtr); |
50 | 0 | MOZ_ASSERT(result); |
51 | 0 | return result; |
52 | 0 | } |
53 | | |
54 | | SourceSurface* LookupSourceSurface(ReferencePtr aRefPtr) final |
55 | 0 | { |
56 | 0 | SourceSurface* result = mSourceSurfaces.GetWeak(aRefPtr); |
57 | 0 | MOZ_ASSERT(result); |
58 | 0 | return result; |
59 | 0 | } |
60 | | |
61 | | FilterNode* LookupFilterNode(ReferencePtr aRefPtr) final |
62 | 0 | { |
63 | 0 | FilterNode* result = mFilterNodes.GetWeak(aRefPtr); |
64 | 0 | MOZ_ASSERT(result); |
65 | 0 | return result; |
66 | 0 | } |
67 | | |
68 | | GradientStops* LookupGradientStops(ReferencePtr aRefPtr) final |
69 | 0 | { |
70 | 0 | GradientStops* result = mGradientStops.GetWeak(aRefPtr); |
71 | 0 | MOZ_ASSERT(result); |
72 | 0 | return result; |
73 | 0 | } |
74 | | |
75 | | ScaledFont* LookupScaledFont(ReferencePtr aRefPtr) final |
76 | 0 | { |
77 | 0 | ScaledFont* result = mScaledFonts.GetWeak(aRefPtr); |
78 | 0 | MOZ_ASSERT(result); |
79 | 0 | return result; |
80 | 0 | } |
81 | | |
82 | | UnscaledFont* LookupUnscaledFont(ReferencePtr aRefPtr) final |
83 | 0 | { |
84 | 0 | UnscaledFont* result = mUnscaledFonts.GetWeak(aRefPtr); |
85 | 0 | MOZ_ASSERT(result); |
86 | 0 | return result; |
87 | 0 | } |
88 | | |
89 | | NativeFontResource* LookupNativeFontResource(uint64_t aKey) final |
90 | 0 | { |
91 | 0 | NativeFontResource* result = mNativeFontResources.GetWeak(aKey); |
92 | 0 | MOZ_ASSERT(result); |
93 | 0 | return result; |
94 | 0 | } |
95 | | |
96 | | void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget *aDT) final |
97 | 0 | { |
98 | 0 | mDrawTargets.Put(aRefPtr, aDT); |
99 | 0 | } |
100 | | |
101 | | void AddPath(ReferencePtr aRefPtr, Path *aPath) final |
102 | 0 | { |
103 | 0 | mPaths.Put(aRefPtr, aPath); |
104 | 0 | } |
105 | | |
106 | | void AddSourceSurface(ReferencePtr aRefPtr, SourceSurface *aSurface) final |
107 | 0 | { |
108 | 0 | mSourceSurfaces.Put(aRefPtr, aSurface); |
109 | 0 | } |
110 | | |
111 | | void AddFilterNode(ReferencePtr aRefPtr, FilterNode *aFilter) final |
112 | 0 | { |
113 | 0 | mFilterNodes.Put(aRefPtr, aFilter); |
114 | 0 | } |
115 | | |
116 | | void AddGradientStops(ReferencePtr aRefPtr, GradientStops *aStops) final |
117 | 0 | { |
118 | 0 | mGradientStops.Put(aRefPtr, aStops); |
119 | 0 | } |
120 | | |
121 | | void AddScaledFont(ReferencePtr aRefPtr, ScaledFont *aScaledFont) final |
122 | 0 | { |
123 | 0 | mScaledFonts.Put(aRefPtr, aScaledFont); |
124 | 0 | } |
125 | | |
126 | | void AddUnscaledFont(ReferencePtr aRefPtr, UnscaledFont* aUnscaledFont) final |
127 | 0 | { |
128 | 0 | mUnscaledFonts.Put(aRefPtr, aUnscaledFont); |
129 | 0 | } |
130 | | |
131 | | void AddNativeFontResource(uint64_t aKey, |
132 | | NativeFontResource *aScaledFontResouce) final |
133 | 0 | { |
134 | 0 | mNativeFontResources.Put(aKey, aScaledFontResouce); |
135 | 0 | } |
136 | | |
137 | | void RemoveDrawTarget(ReferencePtr aRefPtr) final |
138 | 0 | { |
139 | 0 | mDrawTargets.Remove(aRefPtr); |
140 | 0 | } |
141 | | |
142 | | void RemovePath(ReferencePtr aRefPtr) final |
143 | 0 | { |
144 | 0 | mPaths.Remove(aRefPtr); |
145 | 0 | } |
146 | | |
147 | | void RemoveSourceSurface(ReferencePtr aRefPtr) final |
148 | 0 | { |
149 | 0 | mSourceSurfaces.Remove(aRefPtr); |
150 | 0 | } |
151 | | |
152 | | void RemoveFilterNode(ReferencePtr aRefPtr) final |
153 | 0 | { |
154 | 0 | mFilterNodes.Remove(aRefPtr); |
155 | 0 | } |
156 | | |
157 | | void RemoveGradientStops(ReferencePtr aRefPtr) final |
158 | 0 | { |
159 | 0 | mGradientStops.Remove(aRefPtr); |
160 | 0 | } |
161 | | |
162 | | void RemoveScaledFont(ReferencePtr aRefPtr) final |
163 | 0 | { |
164 | 0 | mScaledFonts.Remove(aRefPtr); |
165 | 0 | } |
166 | | |
167 | | void RemoveUnscaledFont(ReferencePtr aRefPtr) final |
168 | 0 | { |
169 | 0 | mUnscaledFonts.Remove(aRefPtr); |
170 | 0 | } |
171 | | |
172 | | already_AddRefed<DrawTarget> CreateDrawTarget(ReferencePtr aRefPtr, |
173 | | const gfx::IntSize &aSize, |
174 | | gfx::SurfaceFormat aFormat) final; |
175 | | |
176 | 0 | mozilla::gfx::DrawTarget* GetReferenceDrawTarget() final { return mBaseDT; } |
177 | | |
178 | | private: |
179 | | RefPtr<nsDeviceContext> mDeviceContext; |
180 | | RefPtr<DrawTarget> mBaseDT; |
181 | | |
182 | | nsRefPtrHashtable<nsPtrHashKey<void>, DrawTarget> mDrawTargets; |
183 | | nsRefPtrHashtable<nsPtrHashKey<void>, Path> mPaths; |
184 | | nsRefPtrHashtable<nsPtrHashKey<void>, SourceSurface> mSourceSurfaces; |
185 | | nsRefPtrHashtable<nsPtrHashKey<void>, FilterNode> mFilterNodes; |
186 | | nsRefPtrHashtable<nsPtrHashKey<void>, GradientStops> mGradientStops; |
187 | | nsRefPtrHashtable<nsPtrHashKey<void>, ScaledFont> mScaledFonts; |
188 | | nsRefPtrHashtable<nsPtrHashKey<void>, UnscaledFont> mUnscaledFonts; |
189 | | nsRefPtrHashtable<nsUint64HashKey, NativeFontResource> mNativeFontResources; |
190 | | }; |
191 | | |
192 | | } // namespace layout |
193 | | } // namespace mozilla |
194 | | |
195 | | #endif // mozilla_layout_PrintTranslator_h |