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 drawPath(
90 const SkPath& platonicPath,
92 const SkMatrix* prePathMatrix,
93 bool pathIsMutable) SK_OVERRIDE;
95 virtual void drawBitmap(
97 const SkBitmap& bitmap,
98 const SkMatrix& matrix,
99 const SkPaint& paint) SK_OVERRIDE;
101 virtual void drawSprite(
103 const SkBitmap& bitmap,
105 const SkPaint& paint) SK_OVERRIDE;
107 virtual void drawText(
109 const void* text, size_t len,
110 SkScalar x, SkScalar y,
111 const SkPaint& paint) SK_OVERRIDE;
113 virtual void drawPosText(
115 const void* text, size_t len,
116 const SkScalar pos[], SkScalar constY, int scalarsPerPos,
117 const SkPaint& paint) SK_OVERRIDE;
119 virtual void drawTextOnPath(
121 const void* text, size_t len,
123 const SkMatrix* matrix,
124 const SkPaint& paint) SK_OVERRIDE;
126 virtual void drawVertices(
128 SkCanvas::VertexMode,
129 int vertexCount, const SkPoint verts[],
130 const SkPoint texs[], const SkColor colors[],
132 const uint16_t indices[], int indexCount,
133 const SkPaint& paint) SK_OVERRIDE;
135 virtual void drawDevice(
137 SkBaseDevice* device,
139 const SkPaint& paint) SK_OVERRIDE;
141 virtual bool onReadPixels(const SkBitmap& bitmap,
144 SkCanvas::Config8888) SK_OVERRIDE;
146 virtual bool allowImageFilter(SkImageFilter*) SK_OVERRIDE;
149 class TypefaceUse : ::SkNoncopyable {
154 IXpsOMFontResource* xpsFont;
155 SkBitSet* glyphsUsed;
157 explicit TypefaceUse();
160 friend static HRESULT subset_typeface(TypefaceUse* current);
162 SkXPSDevice(IXpsOMObjectFactory* xpsFactory);
164 SkAutoCoInitialize fAutoCo;
165 SkTScopedComPtr<IXpsOMObjectFactory> fXpsFactory;
166 SkTScopedComPtr<IStream> fOutputStream;
167 SkTScopedComPtr<IXpsOMPackageWriter> fPackageWriter;
169 unsigned int fCurrentPage;
170 SkTScopedComPtr<IXpsOMCanvas> fCurrentXpsCanvas;
171 SkSize fCurrentCanvasSize;
172 SkVector fCurrentUnitsPerMeter;
173 SkVector fCurrentPixelsPerMeter;
175 SkTArray<TypefaceUse, true> fTypefaces;
177 HRESULT initXpsDocumentWriter(IXpsOMImageResource* image);
179 HRESULT createXpsPage(
180 const XPS_SIZE& pageSize,
183 HRESULT createXpsThumbnail(
184 IXpsOMPage* page, const unsigned int pageNumber,
185 IXpsOMImageResource** image);
187 void internalDrawRect(
191 const SkPaint& paint);
193 HRESULT createXpsBrush(
194 const SkPaint& skPaint,
195 IXpsOMBrush** xpsBrush,
196 const SkMatrix* parentTransform = NULL);
198 HRESULT createXpsSolidColorBrush(
199 const SkColor skColor, const SkAlpha alpha,
200 IXpsOMBrush** xpsBrush);
202 HRESULT createXpsImageBrush(
203 const SkBitmap& bitmap,
204 const SkMatrix& localMatrix,
205 const SkShader::TileMode (&xy)[2],
207 IXpsOMTileBrush** xpsBrush);
209 HRESULT createXpsLinearGradient(
210 SkShader::GradientInfo info,
212 const SkMatrix& localMatrix,
213 IXpsOMMatrixTransform* xpsMatrixToUse,
214 IXpsOMBrush** xpsBrush);
216 HRESULT createXpsRadialGradient(
217 SkShader::GradientInfo info,
219 const SkMatrix& localMatrix,
220 IXpsOMMatrixTransform* xpsMatrixToUse,
221 IXpsOMBrush** xpsBrush);
223 HRESULT createXpsGradientStop(
224 const SkColor skColor,
225 const SkScalar offset,
226 IXpsOMGradientStop** xpsGradStop);
228 HRESULT createXpsTransform(
229 const SkMatrix& matrix,
230 IXpsOMMatrixTransform ** xpsTransform);
232 HRESULT createXpsRect(
234 BOOL stroke, BOOL fill,
235 IXpsOMGeometryFigure** xpsRect);
237 HRESULT createXpsQuad(
238 const SkPoint (&points)[4],
239 BOOL stroke, BOOL fill,
240 IXpsOMGeometryFigure** xpsQuad);
242 HRESULT CreateTypefaceUse(
243 const SkPaint& paint,
244 TypefaceUse** fontResource);
248 IXpsOMObjectFactory* xpsFactory,
249 IXpsOMCanvas* canvas,
252 XPS_GLYPH_INDEX* xpsGlyphs,
256 XPS_STYLE_SIMULATION sims,
257 const SkMatrix& transform,
258 const SkPaint& paint);
260 HRESULT addXpsPathGeometry(
261 IXpsOMGeometryFigureCollection* figures,
262 BOOL stroke, BOOL fill, const SkPath& path);
265 IXpsOMGeometryFigure* figure,
266 IXpsOMVisualCollection* visuals,
270 const SkRect& leftPoints, const XPS_RECT& left,
271 IXpsOMImageResource* imageResource,
272 IXpsOMVisualCollection* visuals);
274 HRESULT cornerOfClamp(
275 const SkRect& tlPoints,
277 IXpsOMVisualCollection* visuals);
280 IXpsOMVisual* xpsVisual,
283 IXpsOMVisual* xpsVisual,
284 const SkPath& clipPath,
285 XPS_FILL_RULE fillRule);
287 HRESULT drawInverseWindingPath(
289 const SkPath& devicePath,
290 IXpsOMPath* xpsPath);
293 IXpsOMPath* shadedPath,
294 const SkPaint& shaderPaint,
295 const SkMatrix& matrix,
296 BOOL* fill, BOOL* stroke);
299 const SkMaskFilter* filter,
302 const SkIRect& clip, SkIRect* clipIRect);
307 const SkVector& ppuScale,
308 IXpsOMPath* shadedPath);
310 // override from SkBaseDevice
311 virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config,
312 int width, int height,
314 Usage usage) SK_OVERRIDE;
316 // Disable the default copy and assign implementation.
317 SkXPSDevice(const SkXPSDevice&);
318 void operator=(const SkXPSDevice&);
320 typedef SkBitmapDevice INHERITED;