bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 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" |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 12 | |
halcanary | 0cbe7ee | 2015-12-01 09:02:49 -0800 | [diff] [blame] | 13 | #ifdef SK_BUILD_FOR_WIN |
| 14 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 15 | #include <ObjBase.h> |
| 16 | #include <XpsObjectModel.h> |
| 17 | |
| 18 | #include "SkAutoCoInitialize.h" |
Mike Reed | 27d07f0 | 2017-03-04 21:47:47 +0000 | [diff] [blame] | 19 | #include "SkBitSet.h" |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 20 | #include "SkBitmapDevice.h" |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 21 | #include "SkCanvas.h" |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 22 | #include "SkClipStackDevice.h" |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 23 | #include "SkColor.h" |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 24 | #include "SkPaint.h" |
| 25 | #include "SkPath.h" |
| 26 | #include "SkPoint.h" |
| 27 | #include "SkShader.h" |
| 28 | #include "SkSize.h" |
| 29 | #include "SkTArray.h" |
| 30 | #include "SkTScopedComPtr.h" |
| 31 | #include "SkTypeface.h" |
| 32 | |
Ben Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 33 | //#define SK_XPS_USE_DETERMINISTIC_IDS |
| 34 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 35 | /** \class SkXPSDevice |
| 36 | |
| 37 | The drawing context for the XPS backend. |
| 38 | */ |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 39 | class SkXPSDevice : public SkClipStackDevice { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 40 | public: |
Hal Canary | b39b09e | 2017-02-01 17:04:44 -0500 | [diff] [blame] | 41 | SK_API SkXPSDevice(SkISize); |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 42 | SK_API ~SkXPSDevice() override; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 43 | |
Hal Canary | abc88d2 | 2017-02-06 09:26:49 -0500 | [diff] [blame] | 44 | bool beginPortfolio(SkWStream* outputStream, IXpsOMObjectFactory*); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 45 | /** |
| 46 | @param unitsPerMeter converts geometry units into physical units. |
| 47 | @param pixelsPerMeter resolution to use when geometry must be rasterized. |
| 48 | @param trimSize final page size in physical units. |
| 49 | The top left of the trim is the origin of physical space. |
| 50 | @param mediaBox The size of the physical media in physical units. |
| 51 | The top and left must be less than zero. |
| 52 | The bottom and right must be greater than the trimSize. |
| 53 | The default is to coincide with the trimSize. |
| 54 | @param bleedBox The size of the bleed box in physical units. |
| 55 | Must be contained within the mediaBox. |
| 56 | The default is to coincide with the mediaBox. |
| 57 | @param artBox The size of the content box in physical units. |
| 58 | Must be contained within the trimSize. |
| 59 | The default is to coincide with the trimSize. |
| 60 | @param cropBox The size of the recommended view port in physical units. |
| 61 | Must be contained within the mediaBox. |
| 62 | The default is to coincide with the mediaBox. |
| 63 | */ |
Hal Canary | b39b09e | 2017-02-01 17:04:44 -0500 | [diff] [blame] | 64 | bool beginSheet( |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 65 | const SkVector& unitsPerMeter, |
| 66 | const SkVector& pixelsPerMeter, |
| 67 | const SkSize& trimSize, |
| 68 | const SkRect* mediaBox = NULL, |
| 69 | const SkRect* bleedBox = NULL, |
| 70 | const SkRect* artBox = NULL, |
| 71 | const SkRect* cropBox = NULL); |
| 72 | |
Hal Canary | b39b09e | 2017-02-01 17:04:44 -0500 | [diff] [blame] | 73 | bool endSheet(); |
| 74 | bool endPortfolio(); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 75 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 76 | protected: |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 77 | void drawPaint(const SkPaint& paint) override; |
| 78 | void drawPoints(SkCanvas::PointMode mode, size_t count, |
| 79 | const SkPoint[], const SkPaint& paint) override; |
| 80 | void drawRect(const SkRect& r, |
| 81 | const SkPaint& paint) override; |
| 82 | void drawOval(const SkRect& oval, |
| 83 | const SkPaint& paint) override; |
| 84 | void drawRRect(const SkRRect& rr, |
| 85 | const SkPaint& paint) override; |
| 86 | void drawPath(const SkPath& path, |
| 87 | const SkPaint& paint, |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 88 | bool pathIsMutable = false) override; |
| 89 | void drawBitmap(const SkBitmap& bitmap, |
Hal Canary | b964238 | 2017-06-27 09:58:56 -0400 | [diff] [blame] | 90 | SkScalar x, |
| 91 | SkScalar y, |
| 92 | const SkPaint& paint) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 93 | void drawSprite(const SkBitmap& bitmap, |
| 94 | int x, int y, const SkPaint& paint) override; |
| 95 | void drawBitmapRect(const SkBitmap&, |
| 96 | const SkRect* srcOrNull, const SkRect& dst, |
| 97 | const SkPaint& paint, |
Hal Canary | b39b09e | 2017-02-01 17:04:44 -0500 | [diff] [blame] | 98 | SkCanvas::SrcRectConstraint) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 99 | void drawPosText(const void* text, size_t len, |
| 100 | const SkScalar pos[], int scalarsPerPos, |
| 101 | const SkPoint& offset, const SkPaint& paint) override; |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 102 | void drawVertices(const SkVertices*, const SkVertices::Bone bones[], int boneCount, SkBlendMode, |
Ruiqi Mao | f510149 | 2018-06-29 14:32:21 -0400 | [diff] [blame] | 103 | const SkPaint&) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 104 | void drawDevice(SkBaseDevice*, int x, int y, |
| 105 | const SkPaint&) override; |
Hal Canary | b39b09e | 2017-02-01 17:04:44 -0500 | [diff] [blame] | 106 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 107 | private: |
| 108 | class TypefaceUse : ::SkNoncopyable { |
| 109 | public: |
| 110 | SkFontID typefaceId; |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 111 | int ttcIndex; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 112 | SkStream* fontData; |
| 113 | IXpsOMFontResource* xpsFont; |
| 114 | SkBitSet* glyphsUsed; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 115 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 116 | explicit TypefaceUse(); |
| 117 | ~TypefaceUse(); |
| 118 | }; |
halcanary | a634b74 | 2016-10-13 08:44:11 -0700 | [diff] [blame] | 119 | friend HRESULT subset_typeface(TypefaceUse* current); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 120 | |
Hal Canary | abc88d2 | 2017-02-06 09:26:49 -0500 | [diff] [blame] | 121 | bool createCanvasForLayer(); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 122 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 123 | SkTScopedComPtr<IXpsOMObjectFactory> fXpsFactory; |
| 124 | SkTScopedComPtr<IStream> fOutputStream; |
| 125 | SkTScopedComPtr<IXpsOMPackageWriter> fPackageWriter; |
| 126 | |
| 127 | unsigned int fCurrentPage; |
| 128 | SkTScopedComPtr<IXpsOMCanvas> fCurrentXpsCanvas; |
| 129 | SkSize fCurrentCanvasSize; |
| 130 | SkVector fCurrentUnitsPerMeter; |
| 131 | SkVector fCurrentPixelsPerMeter; |
| 132 | |
| 133 | SkTArray<TypefaceUse, true> fTypefaces; |
| 134 | |
Ben Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 135 | /** Creates a GUID based id and places it into buffer. |
| 136 | buffer should have space for at least GUID_ID_LEN wide characters. |
| 137 | The string will always be wchar null terminated. |
| 138 | XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX0 |
| 139 | The string may begin with a digit, |
| 140 | and so may not be suitable as a bare resource key. |
| 141 | */ |
| 142 | HRESULT createId(wchar_t* buffer, size_t bufferSize, wchar_t sep = '-'); |
| 143 | #ifdef SK_XPS_USE_DETERMINISTIC_IDS |
| 144 | decltype(GUID::Data1) fNextId = 0; |
| 145 | #endif |
| 146 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 147 | HRESULT initXpsDocumentWriter(IXpsOMImageResource* image); |
| 148 | |
| 149 | HRESULT createXpsPage( |
| 150 | const XPS_SIZE& pageSize, |
| 151 | IXpsOMPage** page); |
| 152 | |
| 153 | HRESULT createXpsThumbnail( |
| 154 | IXpsOMPage* page, const unsigned int pageNumber, |
| 155 | IXpsOMImageResource** image); |
| 156 | |
| 157 | void internalDrawRect( |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 158 | const SkRect& r, |
| 159 | bool transformRect, |
| 160 | const SkPaint& paint); |
| 161 | |
| 162 | HRESULT createXpsBrush( |
| 163 | const SkPaint& skPaint, |
| 164 | IXpsOMBrush** xpsBrush, |
| 165 | const SkMatrix* parentTransform = NULL); |
| 166 | |
| 167 | HRESULT createXpsSolidColorBrush( |
| 168 | const SkColor skColor, const SkAlpha alpha, |
| 169 | IXpsOMBrush** xpsBrush); |
| 170 | |
| 171 | HRESULT createXpsImageBrush( |
| 172 | const SkBitmap& bitmap, |
| 173 | const SkMatrix& localMatrix, |
| 174 | const SkShader::TileMode (&xy)[2], |
| 175 | const SkAlpha alpha, |
| 176 | IXpsOMTileBrush** xpsBrush); |
| 177 | |
| 178 | HRESULT createXpsLinearGradient( |
| 179 | SkShader::GradientInfo info, |
| 180 | const SkAlpha alpha, |
| 181 | const SkMatrix& localMatrix, |
| 182 | IXpsOMMatrixTransform* xpsMatrixToUse, |
| 183 | IXpsOMBrush** xpsBrush); |
| 184 | |
| 185 | HRESULT createXpsRadialGradient( |
| 186 | SkShader::GradientInfo info, |
| 187 | const SkAlpha alpha, |
| 188 | const SkMatrix& localMatrix, |
| 189 | IXpsOMMatrixTransform* xpsMatrixToUse, |
| 190 | IXpsOMBrush** xpsBrush); |
| 191 | |
| 192 | HRESULT createXpsGradientStop( |
| 193 | const SkColor skColor, |
| 194 | const SkScalar offset, |
| 195 | IXpsOMGradientStop** xpsGradStop); |
| 196 | |
| 197 | HRESULT createXpsTransform( |
| 198 | const SkMatrix& matrix, |
| 199 | IXpsOMMatrixTransform ** xpsTransform); |
| 200 | |
| 201 | HRESULT createXpsRect( |
| 202 | const SkRect& rect, |
| 203 | BOOL stroke, BOOL fill, |
| 204 | IXpsOMGeometryFigure** xpsRect); |
| 205 | |
| 206 | HRESULT createXpsQuad( |
| 207 | const SkPoint (&points)[4], |
| 208 | BOOL stroke, BOOL fill, |
| 209 | IXpsOMGeometryFigure** xpsQuad); |
| 210 | |
| 211 | HRESULT CreateTypefaceUse( |
| 212 | const SkPaint& paint, |
| 213 | TypefaceUse** fontResource); |
| 214 | |
| 215 | HRESULT AddGlyphs( |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 216 | IXpsOMObjectFactory* xpsFactory, |
| 217 | IXpsOMCanvas* canvas, |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 218 | TypefaceUse* font, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 219 | LPCWSTR text, |
| 220 | XPS_GLYPH_INDEX* xpsGlyphs, |
| 221 | UINT32 xpsGlyphsLen, |
| 222 | XPS_POINT *origin, |
| 223 | FLOAT fontSize, |
| 224 | XPS_STYLE_SIMULATION sims, |
| 225 | const SkMatrix& transform, |
| 226 | const SkPaint& paint); |
| 227 | |
| 228 | HRESULT addXpsPathGeometry( |
| 229 | IXpsOMGeometryFigureCollection* figures, |
| 230 | BOOL stroke, BOOL fill, const SkPath& path); |
| 231 | |
| 232 | HRESULT createPath( |
| 233 | IXpsOMGeometryFigure* figure, |
| 234 | IXpsOMVisualCollection* visuals, |
| 235 | IXpsOMPath** path); |
| 236 | |
| 237 | HRESULT sideOfClamp( |
| 238 | const SkRect& leftPoints, const XPS_RECT& left, |
| 239 | IXpsOMImageResource* imageResource, |
| 240 | IXpsOMVisualCollection* visuals); |
| 241 | |
| 242 | HRESULT cornerOfClamp( |
| 243 | const SkRect& tlPoints, |
| 244 | const SkColor color, |
| 245 | IXpsOMVisualCollection* visuals); |
| 246 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 247 | HRESULT clip(IXpsOMVisual* xpsVisual); |
| 248 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 249 | HRESULT clipToPath( |
| 250 | IXpsOMVisual* xpsVisual, |
| 251 | const SkPath& clipPath, |
| 252 | XPS_FILL_RULE fillRule); |
| 253 | |
| 254 | HRESULT drawInverseWindingPath( |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 255 | const SkPath& devicePath, |
| 256 | IXpsOMPath* xpsPath); |
| 257 | |
| 258 | HRESULT shadePath( |
| 259 | IXpsOMPath* shadedPath, |
| 260 | const SkPaint& shaderPaint, |
| 261 | const SkMatrix& matrix, |
| 262 | BOOL* fill, BOOL* stroke); |
| 263 | |
| 264 | void convertToPpm( |
| 265 | const SkMaskFilter* filter, |
| 266 | SkMatrix* matrix, |
| 267 | SkVector* ppuScale, |
| 268 | const SkIRect& clip, SkIRect* clipIRect); |
| 269 | |
| 270 | HRESULT applyMask( |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 271 | const SkMask& mask, |
| 272 | const SkVector& ppuScale, |
| 273 | IXpsOMPath* shadedPath); |
| 274 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 275 | SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 276 | |
| 277 | // Disable the default copy and assign implementation. |
| 278 | SkXPSDevice(const SkXPSDevice&); |
| 279 | void operator=(const SkXPSDevice&); |
| 280 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 281 | typedef SkClipStackDevice INHERITED; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 282 | }; |
| 283 | |
halcanary | 0cbe7ee | 2015-12-01 09:02:49 -0800 | [diff] [blame] | 284 | #endif // SK_BUILD_FOR_WIN |
| 285 | #endif // SkXPSDevice_DEFINED |