2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkXPSDevice_DEFINED
9 #define SkXPSDevice_DEFINED
13 #include <XpsObjectModel.h>
15 #include "SkAutoCoInitialize.h"
16 #include "SkBitmapDevice.h"
26 #include "SkTScopedComPtr.h"
27 #include "SkTypeface.h"
29 /** \class SkXPSDevice
31 The drawing context for the XPS backend.
33 class SkXPSDevice : public SkBitmapDevice {
36 SK_API virtual ~SkXPSDevice();
38 virtual bool beginPortfolio(SkWStream* outputStream);
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.
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);
67 virtual bool endSheet();
68 virtual bool endPortfolio();
70 virtual uint32_t getDeviceCapabilities() SK_OVERRIDE;
73 virtual void clear(SkColor color) SK_OVERRIDE;
75 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE;
77 virtual void drawPoints(
79 SkCanvas::PointMode mode,
80 size_t count, const SkPoint[],
81 const SkPaint& paint) SK_OVERRIDE;
83 virtual void drawRect(
86 const SkPaint& paint) SK_OVERRIDE;
88 virtual void drawRRect(
91 const SkPaint& paint) SK_OVERRIDE;
93 virtual void drawPath(
95 const SkPath& platonicPath,
97 const SkMatrix* prePathMatrix,
98 bool pathIsMutable) SK_OVERRIDE;
100 virtual void drawBitmap(
102 const SkBitmap& bitmap,
103 const SkMatrix& matrix,
104 const SkPaint& paint) SK_OVERRIDE;
106 virtual void drawSprite(
108 const SkBitmap& bitmap,
110 const SkPaint& paint) SK_OVERRIDE;
112 virtual void drawText(
114 const void* text, size_t len,
115 SkScalar x, SkScalar y,
116 const SkPaint& paint) SK_OVERRIDE;
118 virtual void drawPosText(
120 const void* text, size_t len,
121 const SkScalar pos[], SkScalar constY, int scalarsPerPos,
122 const SkPaint& paint) SK_OVERRIDE;
124 virtual void drawTextOnPath(
126 const void* text, size_t len,
128 const SkMatrix* matrix,
129 const SkPaint& paint) SK_OVERRIDE;
131 virtual void drawVertices(
133 SkCanvas::VertexMode,
134 int vertexCount, const SkPoint verts[],
135 const SkPoint texs[], const SkColor colors[],
137 const uint16_t indices[], int indexCount,
138 const SkPaint& paint) SK_OVERRIDE;
140 virtual void drawDevice(
142 SkBaseDevice* device,
144 const SkPaint& paint) SK_OVERRIDE;
146 virtual bool onReadPixels(const SkBitmap& bitmap,
149 SkCanvas::Config8888) SK_OVERRIDE;
151 virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE;
154 class TypefaceUse : ::SkNoncopyable {
159 IXpsOMFontResource* xpsFont;
160 SkBitSet* glyphsUsed;
162 explicit TypefaceUse();
165 friend static HRESULT subset_typeface(TypefaceUse* current);
167 SkXPSDevice(IXpsOMObjectFactory* xpsFactory);
169 SkAutoCoInitialize fAutoCo;
170 SkTScopedComPtr<IXpsOMObjectFactory> fXpsFactory;
171 SkTScopedComPtr<IStream> fOutputStream;
172 SkTScopedComPtr<IXpsOMPackageWriter> fPackageWriter;
174 unsigned int fCurrentPage;
175 SkTScopedComPtr<IXpsOMCanvas> fCurrentXpsCanvas;
176 SkSize fCurrentCanvasSize;
177 SkVector fCurrentUnitsPerMeter;
178 SkVector fCurrentPixelsPerMeter;
180 SkTArray<TypefaceUse, true> fTypefaces;
182 HRESULT initXpsDocumentWriter(IXpsOMImageResource* image);
184 HRESULT createXpsPage(
185 const XPS_SIZE& pageSize,
188 HRESULT createXpsThumbnail(
189 IXpsOMPage* page, const unsigned int pageNumber,
190 IXpsOMImageResource** image);
192 void internalDrawRect(
196 const SkPaint& paint);
198 HRESULT createXpsBrush(
199 const SkPaint& skPaint,
200 IXpsOMBrush** xpsBrush,
201 const SkMatrix* parentTransform = NULL);
203 HRESULT createXpsSolidColorBrush(
204 const SkColor skColor, const SkAlpha alpha,
205 IXpsOMBrush** xpsBrush);
207 HRESULT createXpsImageBrush(
208 const SkBitmap& bitmap,
209 const SkMatrix& localMatrix,
210 const SkShader::TileMode (&xy)[2],
212 IXpsOMTileBrush** xpsBrush);
214 HRESULT createXpsLinearGradient(
215 SkShader::GradientInfo info,
217 const SkMatrix& localMatrix,
218 IXpsOMMatrixTransform* xpsMatrixToUse,
219 IXpsOMBrush** xpsBrush);
221 HRESULT createXpsRadialGradient(
222 SkShader::GradientInfo info,
224 const SkMatrix& localMatrix,
225 IXpsOMMatrixTransform* xpsMatrixToUse,
226 IXpsOMBrush** xpsBrush);
228 HRESULT createXpsGradientStop(
229 const SkColor skColor,
230 const SkScalar offset,
231 IXpsOMGradientStop** xpsGradStop);
233 HRESULT createXpsTransform(
234 const SkMatrix& matrix,
235 IXpsOMMatrixTransform ** xpsTransform);
237 HRESULT createXpsRect(
239 BOOL stroke, BOOL fill,
240 IXpsOMGeometryFigure** xpsRect);
242 HRESULT createXpsQuad(
243 const SkPoint (&points)[4],
244 BOOL stroke, BOOL fill,
245 IXpsOMGeometryFigure** xpsQuad);
247 HRESULT CreateTypefaceUse(
248 const SkPaint& paint,
249 TypefaceUse** fontResource);
253 IXpsOMObjectFactory* xpsFactory,
254 IXpsOMCanvas* canvas,
257 XPS_GLYPH_INDEX* xpsGlyphs,
261 XPS_STYLE_SIMULATION sims,
262 const SkMatrix& transform,
263 const SkPaint& paint);
265 HRESULT addXpsPathGeometry(
266 IXpsOMGeometryFigureCollection* figures,
267 BOOL stroke, BOOL fill, const SkPath& path);
270 IXpsOMGeometryFigure* figure,
271 IXpsOMVisualCollection* visuals,
275 const SkRect& leftPoints, const XPS_RECT& left,
276 IXpsOMImageResource* imageResource,
277 IXpsOMVisualCollection* visuals);
279 HRESULT cornerOfClamp(
280 const SkRect& tlPoints,
282 IXpsOMVisualCollection* visuals);
285 IXpsOMVisual* xpsVisual,
288 IXpsOMVisual* xpsVisual,
289 const SkPath& clipPath,
290 XPS_FILL_RULE fillRule);
292 HRESULT drawInverseWindingPath(
294 const SkPath& devicePath,
295 IXpsOMPath* xpsPath);
298 IXpsOMPath* shadedPath,
299 const SkPaint& shaderPaint,
300 const SkMatrix& matrix,
301 BOOL* fill, BOOL* stroke);
304 const SkMaskFilter* filter,
307 const SkIRect& clip, SkIRect* clipIRect);
312 const SkVector& ppuScale,
313 IXpsOMPath* shadedPath);
315 // override from SkBaseDevice
316 virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config,
317 int width, int height,
319 Usage usage) SK_OVERRIDE;
321 // Disable the default copy and assign implementation.
322 SkXPSDevice(const SkXPSDevice&);
323 void operator=(const SkXPSDevice&);
325 typedef SkBitmapDevice INHERITED;