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
14 #include <XpsObjectModel.h>
16 #include "SkAutoCoInitialize.h"
17 #include "SkBitmapDevice.h"
27 #include "SkTScopedComPtr.h"
28 #include "SkTypeface.h"
30 //#define SK_XPS_USE_DETERMINISTIC_IDS
32 /** \class SkXPSDevice
34 The drawing context for the XPS backend.
36 class SkXPSDevice : public SkBitmapDevice {
39 SK_API virtual ~SkXPSDevice();
41 virtual bool beginPortfolio(SkWStream* outputStream);
43 @param unitsPerMeter converts geometry units into physical units.
44 @param pixelsPerMeter resolution to use when geometry must be rasterized.
45 @param trimSize final page size in physical units.
46 The top left of the trim is the origin of physical space.
47 @param mediaBox The size of the physical media in physical units.
48 The top and left must be less than zero.
49 The bottom and right must be greater than the trimSize.
50 The default is to coincide with the trimSize.
51 @param bleedBox The size of the bleed box in physical units.
52 Must be contained within the mediaBox.
53 The default is to coincide with the mediaBox.
54 @param artBox The size of the content box in physical units.
55 Must be contained within the trimSize.
56 The default is to coincide with the trimSize.
57 @param cropBox The size of the recommended view port in physical units.
58 Must be contained within the mediaBox.
59 The default is to coincide with the mediaBox.
61 virtual bool beginSheet(
62 const SkVector& unitsPerMeter,
63 const SkVector& pixelsPerMeter,
64 const SkSize& trimSize,
65 const SkRect* mediaBox = NULL,
66 const SkRect* bleedBox = NULL,
67 const SkRect* artBox = NULL,
68 const SkRect* cropBox = NULL);
70 virtual bool endSheet();
71 virtual bool endPortfolio();
74 void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE;
76 virtual void drawPoints(
78 SkCanvas::PointMode mode,
79 size_t count, const SkPoint[],
80 const SkPaint& paint) SK_OVERRIDE;
82 virtual void drawRect(
85 const SkPaint& paint) SK_OVERRIDE;
87 virtual void drawRRect(
90 const SkPaint& paint) SK_OVERRIDE;
92 virtual void drawPath(
94 const SkPath& platonicPath,
96 const SkMatrix* prePathMatrix,
97 bool pathIsMutable) SK_OVERRIDE;
99 virtual void drawBitmap(
101 const SkBitmap& bitmap,
102 const SkMatrix& matrix,
103 const SkPaint& paint) SK_OVERRIDE;
105 virtual void drawSprite(
107 const SkBitmap& bitmap,
109 const SkPaint& paint) SK_OVERRIDE;
111 virtual void drawText(
113 const void* text, size_t len,
114 SkScalar x, SkScalar y,
115 const SkPaint& paint) SK_OVERRIDE;
117 virtual void drawPosText(
119 const void* text, size_t len,
120 const SkScalar pos[], int scalarsPerPos,
121 const SkPoint& offset, const SkPaint& paint) SK_OVERRIDE;
123 virtual void drawVertices(
125 SkCanvas::VertexMode,
126 int vertexCount, const SkPoint verts[],
127 const SkPoint texs[], const SkColor colors[],
129 const uint16_t indices[], int indexCount,
130 const SkPaint& paint) SK_OVERRIDE;
132 virtual void drawDevice(
134 SkBaseDevice* device,
136 const SkPaint& paint) SK_OVERRIDE;
139 class TypefaceUse : ::SkNoncopyable {
144 IXpsOMFontResource* xpsFont;
145 SkBitSet* glyphsUsed;
147 explicit TypefaceUse();
150 friend static HRESULT subset_typeface(TypefaceUse* current);
152 SkXPSDevice(IXpsOMObjectFactory* xpsFactory);
154 SkAutoCoInitialize fAutoCo;
155 SkTScopedComPtr<IXpsOMObjectFactory> fXpsFactory;
156 SkTScopedComPtr<IStream> fOutputStream;
157 SkTScopedComPtr<IXpsOMPackageWriter> fPackageWriter;
159 unsigned int fCurrentPage;
160 SkTScopedComPtr<IXpsOMCanvas> fCurrentXpsCanvas;
161 SkSize fCurrentCanvasSize;
162 SkVector fCurrentUnitsPerMeter;
163 SkVector fCurrentPixelsPerMeter;
165 SkTArray<TypefaceUse, true> fTypefaces;
167 /** Creates a GUID based id and places it into buffer.
168 buffer should have space for at least GUID_ID_LEN wide characters.
169 The string will always be wchar null terminated.
170 XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX0
171 The string may begin with a digit,
172 and so may not be suitable as a bare resource key.
174 HRESULT createId(wchar_t* buffer, size_t bufferSize, wchar_t sep = '-');
175 #ifdef SK_XPS_USE_DETERMINISTIC_IDS
176 decltype(GUID::Data1) fNextId = 0;
179 HRESULT initXpsDocumentWriter(IXpsOMImageResource* image);
181 HRESULT createXpsPage(
182 const XPS_SIZE& pageSize,
185 HRESULT createXpsThumbnail(
186 IXpsOMPage* page, const unsigned int pageNumber,
187 IXpsOMImageResource** image);
189 void internalDrawRect(
193 const SkPaint& paint);
195 HRESULT createXpsBrush(
196 const SkPaint& skPaint,
197 IXpsOMBrush** xpsBrush,
198 const SkMatrix* parentTransform = NULL);
200 HRESULT createXpsSolidColorBrush(
201 const SkColor skColor, const SkAlpha alpha,
202 IXpsOMBrush** xpsBrush);
204 HRESULT createXpsImageBrush(
205 const SkBitmap& bitmap,
206 const SkMatrix& localMatrix,
207 const SkShader::TileMode (&xy)[2],
209 IXpsOMTileBrush** xpsBrush);
211 HRESULT createXpsLinearGradient(
212 SkShader::GradientInfo info,
214 const SkMatrix& localMatrix,
215 IXpsOMMatrixTransform* xpsMatrixToUse,
216 IXpsOMBrush** xpsBrush);
218 HRESULT createXpsRadialGradient(
219 SkShader::GradientInfo info,
221 const SkMatrix& localMatrix,
222 IXpsOMMatrixTransform* xpsMatrixToUse,
223 IXpsOMBrush** xpsBrush);
225 HRESULT createXpsGradientStop(
226 const SkColor skColor,
227 const SkScalar offset,
228 IXpsOMGradientStop** xpsGradStop);
230 HRESULT createXpsTransform(
231 const SkMatrix& matrix,
232 IXpsOMMatrixTransform ** xpsTransform);
234 HRESULT createXpsRect(
236 BOOL stroke, BOOL fill,
237 IXpsOMGeometryFigure** xpsRect);
239 HRESULT createXpsQuad(
240 const SkPoint (&points)[4],
241 BOOL stroke, BOOL fill,
242 IXpsOMGeometryFigure** xpsQuad);
244 HRESULT CreateTypefaceUse(
245 const SkPaint& paint,
246 TypefaceUse** fontResource);
250 IXpsOMObjectFactory* xpsFactory,
251 IXpsOMCanvas* canvas,
254 XPS_GLYPH_INDEX* xpsGlyphs,
258 XPS_STYLE_SIMULATION sims,
259 const SkMatrix& transform,
260 const SkPaint& paint);
262 HRESULT addXpsPathGeometry(
263 IXpsOMGeometryFigureCollection* figures,
264 BOOL stroke, BOOL fill, const SkPath& path);
267 IXpsOMGeometryFigure* figure,
268 IXpsOMVisualCollection* visuals,
272 const SkRect& leftPoints, const XPS_RECT& left,
273 IXpsOMImageResource* imageResource,
274 IXpsOMVisualCollection* visuals);
276 HRESULT cornerOfClamp(
277 const SkRect& tlPoints,
279 IXpsOMVisualCollection* visuals);
282 IXpsOMVisual* xpsVisual,
285 IXpsOMVisual* xpsVisual,
286 const SkPath& clipPath,
287 XPS_FILL_RULE fillRule);
289 HRESULT drawInverseWindingPath(
291 const SkPath& devicePath,
292 IXpsOMPath* xpsPath);
295 IXpsOMPath* shadedPath,
296 const SkPaint& shaderPaint,
297 const SkMatrix& matrix,
298 BOOL* fill, BOOL* stroke);
301 const SkMaskFilter* filter,
304 const SkIRect& clip, SkIRect* clipIRect);
309 const SkVector& ppuScale,
310 IXpsOMPath* shadedPath);
312 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) SK_OVERRIDE;
314 // Disable the default copy and assign implementation.
315 SkXPSDevice(const SkXPSDevice&);
316 void operator=(const SkXPSDevice&);
318 typedef SkBitmapDevice INHERITED;