gfx/skia/trunk/include/device/xps/SkXPSDevice.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:078cc9cc31fb
1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkXPSDevice_DEFINED
9 #define SkXPSDevice_DEFINED
10
11 #include "SkTypes.h"
12 #include <ObjBase.h>
13 #include <XpsObjectModel.h>
14
15 #include "SkAutoCoInitialize.h"
16 #include "SkBitmapDevice.h"
17 #include "SkBitSet.h"
18 #include "SkCanvas.h"
19 #include "SkColor.h"
20 #include "SkPaint.h"
21 #include "SkPath.h"
22 #include "SkPoint.h"
23 #include "SkShader.h"
24 #include "SkSize.h"
25 #include "SkTArray.h"
26 #include "SkTScopedComPtr.h"
27 #include "SkTypeface.h"
28
29 /** \class SkXPSDevice
30
31 The drawing context for the XPS backend.
32 */
33 class SkXPSDevice : public SkBitmapDevice {
34 public:
35 SK_API SkXPSDevice();
36 SK_API virtual ~SkXPSDevice();
37
38 virtual bool beginPortfolio(SkWStream* outputStream);
39 /**
40 @param unitsPerMeter converts geometry units into physical units.
41 @param pixelsPerMeter resolution to use when geometry must be rasterized.
42 @param trimSize final page size in physical units.
43 The top left of the trim is the origin of physical space.
44 @param mediaBox The size of the physical media in physical units.
45 The top and left must be less than zero.
46 The bottom and right must be greater than the trimSize.
47 The default is to coincide with the trimSize.
48 @param bleedBox The size of the bleed box in physical units.
49 Must be contained within the mediaBox.
50 The default is to coincide with the mediaBox.
51 @param artBox The size of the content box in physical units.
52 Must be contained within the trimSize.
53 The default is to coincide with the trimSize.
54 @param cropBox The size of the recommended view port in physical units.
55 Must be contained within the mediaBox.
56 The default is to coincide with the mediaBox.
57 */
58 virtual bool beginSheet(
59 const SkVector& unitsPerMeter,
60 const SkVector& pixelsPerMeter,
61 const SkSize& trimSize,
62 const SkRect* mediaBox = NULL,
63 const SkRect* bleedBox = NULL,
64 const SkRect* artBox = NULL,
65 const SkRect* cropBox = NULL);
66
67 virtual bool endSheet();
68 virtual bool endPortfolio();
69
70 protected:
71 virtual void clear(SkColor color) SK_OVERRIDE;
72
73 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE;
74
75 virtual void drawPoints(
76 const SkDraw&,
77 SkCanvas::PointMode mode,
78 size_t count, const SkPoint[],
79 const SkPaint& paint) SK_OVERRIDE;
80
81 virtual void drawRect(
82 const SkDraw&,
83 const SkRect& r,
84 const SkPaint& paint) SK_OVERRIDE;
85
86 virtual void drawRRect(
87 const SkDraw&,
88 const SkRRect&,
89 const SkPaint& paint) SK_OVERRIDE;
90
91 virtual void drawPath(
92 const SkDraw&,
93 const SkPath& platonicPath,
94 const SkPaint& paint,
95 const SkMatrix* prePathMatrix,
96 bool pathIsMutable) SK_OVERRIDE;
97
98 virtual void drawBitmap(
99 const SkDraw&,
100 const SkBitmap& bitmap,
101 const SkMatrix& matrix,
102 const SkPaint& paint) SK_OVERRIDE;
103
104 virtual void drawSprite(
105 const SkDraw&,
106 const SkBitmap& bitmap,
107 int x, int y,
108 const SkPaint& paint) SK_OVERRIDE;
109
110 virtual void drawText(
111 const SkDraw&,
112 const void* text, size_t len,
113 SkScalar x, SkScalar y,
114 const SkPaint& paint) SK_OVERRIDE;
115
116 virtual void drawPosText(
117 const SkDraw&,
118 const void* text, size_t len,
119 const SkScalar pos[], SkScalar constY, int scalarsPerPos,
120 const SkPaint& paint) SK_OVERRIDE;
121
122 virtual void drawTextOnPath(
123 const SkDraw&,
124 const void* text, size_t len,
125 const SkPath& path,
126 const SkMatrix* matrix,
127 const SkPaint& paint) SK_OVERRIDE;
128
129 virtual void drawVertices(
130 const SkDraw&,
131 SkCanvas::VertexMode,
132 int vertexCount, const SkPoint verts[],
133 const SkPoint texs[], const SkColor colors[],
134 SkXfermode* xmode,
135 const uint16_t indices[], int indexCount,
136 const SkPaint& paint) SK_OVERRIDE;
137
138 virtual void drawDevice(
139 const SkDraw&,
140 SkBaseDevice* device,
141 int x, int y,
142 const SkPaint& paint) SK_OVERRIDE;
143
144 virtual bool onReadPixels(const SkBitmap& bitmap,
145 int x,
146 int y,
147 SkCanvas::Config8888) SK_OVERRIDE;
148
149 virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE;
150
151 private:
152 class TypefaceUse : ::SkNoncopyable {
153 public:
154 SkFontID typefaceId;
155 int ttcIndex;
156 SkStream* fontData;
157 IXpsOMFontResource* xpsFont;
158 SkBitSet* glyphsUsed;
159
160 explicit TypefaceUse();
161 ~TypefaceUse();
162 };
163 friend static HRESULT subset_typeface(TypefaceUse* current);
164
165 SkXPSDevice(IXpsOMObjectFactory* xpsFactory);
166
167 SkAutoCoInitialize fAutoCo;
168 SkTScopedComPtr<IXpsOMObjectFactory> fXpsFactory;
169 SkTScopedComPtr<IStream> fOutputStream;
170 SkTScopedComPtr<IXpsOMPackageWriter> fPackageWriter;
171
172 unsigned int fCurrentPage;
173 SkTScopedComPtr<IXpsOMCanvas> fCurrentXpsCanvas;
174 SkSize fCurrentCanvasSize;
175 SkVector fCurrentUnitsPerMeter;
176 SkVector fCurrentPixelsPerMeter;
177
178 SkTArray<TypefaceUse, true> fTypefaces;
179
180 HRESULT initXpsDocumentWriter(IXpsOMImageResource* image);
181
182 HRESULT createXpsPage(
183 const XPS_SIZE& pageSize,
184 IXpsOMPage** page);
185
186 HRESULT createXpsThumbnail(
187 IXpsOMPage* page, const unsigned int pageNumber,
188 IXpsOMImageResource** image);
189
190 void internalDrawRect(
191 const SkDraw&,
192 const SkRect& r,
193 bool transformRect,
194 const SkPaint& paint);
195
196 HRESULT createXpsBrush(
197 const SkPaint& skPaint,
198 IXpsOMBrush** xpsBrush,
199 const SkMatrix* parentTransform = NULL);
200
201 HRESULT createXpsSolidColorBrush(
202 const SkColor skColor, const SkAlpha alpha,
203 IXpsOMBrush** xpsBrush);
204
205 HRESULT createXpsImageBrush(
206 const SkBitmap& bitmap,
207 const SkMatrix& localMatrix,
208 const SkShader::TileMode (&xy)[2],
209 const SkAlpha alpha,
210 IXpsOMTileBrush** xpsBrush);
211
212 HRESULT createXpsLinearGradient(
213 SkShader::GradientInfo info,
214 const SkAlpha alpha,
215 const SkMatrix& localMatrix,
216 IXpsOMMatrixTransform* xpsMatrixToUse,
217 IXpsOMBrush** xpsBrush);
218
219 HRESULT createXpsRadialGradient(
220 SkShader::GradientInfo info,
221 const SkAlpha alpha,
222 const SkMatrix& localMatrix,
223 IXpsOMMatrixTransform* xpsMatrixToUse,
224 IXpsOMBrush** xpsBrush);
225
226 HRESULT createXpsGradientStop(
227 const SkColor skColor,
228 const SkScalar offset,
229 IXpsOMGradientStop** xpsGradStop);
230
231 HRESULT createXpsTransform(
232 const SkMatrix& matrix,
233 IXpsOMMatrixTransform ** xpsTransform);
234
235 HRESULT createXpsRect(
236 const SkRect& rect,
237 BOOL stroke, BOOL fill,
238 IXpsOMGeometryFigure** xpsRect);
239
240 HRESULT createXpsQuad(
241 const SkPoint (&points)[4],
242 BOOL stroke, BOOL fill,
243 IXpsOMGeometryFigure** xpsQuad);
244
245 HRESULT CreateTypefaceUse(
246 const SkPaint& paint,
247 TypefaceUse** fontResource);
248
249 HRESULT AddGlyphs(
250 const SkDraw& d,
251 IXpsOMObjectFactory* xpsFactory,
252 IXpsOMCanvas* canvas,
253 TypefaceUse* font,
254 LPCWSTR text,
255 XPS_GLYPH_INDEX* xpsGlyphs,
256 UINT32 xpsGlyphsLen,
257 XPS_POINT *origin,
258 FLOAT fontSize,
259 XPS_STYLE_SIMULATION sims,
260 const SkMatrix& transform,
261 const SkPaint& paint);
262
263 HRESULT addXpsPathGeometry(
264 IXpsOMGeometryFigureCollection* figures,
265 BOOL stroke, BOOL fill, const SkPath& path);
266
267 HRESULT createPath(
268 IXpsOMGeometryFigure* figure,
269 IXpsOMVisualCollection* visuals,
270 IXpsOMPath** path);
271
272 HRESULT sideOfClamp(
273 const SkRect& leftPoints, const XPS_RECT& left,
274 IXpsOMImageResource* imageResource,
275 IXpsOMVisualCollection* visuals);
276
277 HRESULT cornerOfClamp(
278 const SkRect& tlPoints,
279 const SkColor color,
280 IXpsOMVisualCollection* visuals);
281
282 HRESULT clip(
283 IXpsOMVisual* xpsVisual,
284 const SkDraw& d);
285 HRESULT clipToPath(
286 IXpsOMVisual* xpsVisual,
287 const SkPath& clipPath,
288 XPS_FILL_RULE fillRule);
289
290 HRESULT drawInverseWindingPath(
291 const SkDraw& d,
292 const SkPath& devicePath,
293 IXpsOMPath* xpsPath);
294
295 HRESULT shadePath(
296 IXpsOMPath* shadedPath,
297 const SkPaint& shaderPaint,
298 const SkMatrix& matrix,
299 BOOL* fill, BOOL* stroke);
300
301 void convertToPpm(
302 const SkMaskFilter* filter,
303 SkMatrix* matrix,
304 SkVector* ppuScale,
305 const SkIRect& clip, SkIRect* clipIRect);
306
307 HRESULT applyMask(
308 const SkDraw& d,
309 const SkMask& mask,
310 const SkVector& ppuScale,
311 IXpsOMPath* shadedPath);
312
313 virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
314
315 // Disable the default copy and assign implementation.
316 SkXPSDevice(const SkXPSDevice&);
317 void operator=(const SkXPSDevice&);
318
319 typedef SkBitmapDevice INHERITED;
320 };
321
322 #endif

mercurial