blob: e73b726464318f7e92d349df72d1b3c924152d7a [file] [log] [blame]
bungeman@google.comb29c8832011-10-10 13:19:10 +00001/*
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
halcanary47ef4d52015-03-03 09:13:09 -08008#include "SkTypes.h"
Mike Klein8f11d4d2018-01-24 12:42:55 -05009#if defined(SK_BUILD_FOR_WIN)
halcanary47ef4d52015-03-03 09:13:09 -080010
halcanary4dbbd042016-06-07 17:21:10 -070011#include "SkLeanWindows.h"
12
bungeman@google.comb29c8832011-10-10 13:19:10 +000013#ifndef UNICODE
14#define UNICODE
15#endif
16#ifndef _UNICODE
17#define _UNICODE
18#endif
bungeman@google.comb29c8832011-10-10 13:19:10 +000019#include <ObjBase.h>
20#include <XpsObjectModel.h>
21#include <T2EmbApi.h>
22#include <FontSub.h>
halcanarybfa92752016-05-31 11:23:42 -070023#include <limits>
bungeman@google.comb29c8832011-10-10 13:19:10 +000024
25#include "SkColor.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000026#include "SkData.h"
27#include "SkDraw.h"
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +000028#include "SkEndian.h"
herbbda26432015-11-24 08:37:01 -080029#include "SkFindAndPlaceGlyph.h"
halcanary47ef4d52015-03-03 09:13:09 -080030#include "SkGeometry.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000031#include "SkGlyphCache.h"
32#include "SkHRESULT.h"
Hal Canaryb39b09e2017-02-01 17:04:44 -050033#include "SkIStream.h"
Mike Reed627778d2016-09-28 17:13:38 -040034#include "SkImage.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000035#include "SkImageEncoder.h"
Hal Canaryb39b09e2017-02-01 17:04:44 -050036#include "SkImagePriv.h"
Mike Reed80747ef2018-01-23 15:29:32 -050037#include "SkMaskFilterBase.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000038#include "SkPaint.h"
reeda4393342016-03-18 11:22:57 -070039#include "SkPathEffect.h"
Ben Wagnerda5a1b82014-08-22 15:07:06 -040040#include "SkPathOps.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000041#include "SkPoint.h"
reed1e7f5e72016-04-27 07:49:17 -070042#include "SkRasterClip.h"
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +000043#include "SkSFNTHeader.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000044#include "SkShader.h"
45#include "SkSize.h"
46#include "SkStream.h"
Herb Derbydce19a72018-04-18 16:02:17 -040047#include "SkStrikeCache.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000048#include "SkTDArray.h"
49#include "SkTLazy.h"
50#include "SkTScopedComPtr.h"
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +000051#include "SkTTCFHeader.h"
Hal Canaryc640d0d2018-06-13 09:59:02 -040052#include "SkTo.h"
reed@google.com398de9a2013-03-21 21:43:51 +000053#include "SkTypefacePriv.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000054#include "SkUtils.h"
Mike Reed2f6b5a42017-03-19 15:04:17 -040055#include "SkVertices.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000056#include "SkXPSDevice.h"
57
58//Windows defines a FLOAT type,
59//make it clear when converting a scalar that this is what is wanted.
60#define SkScalarToFLOAT(n) SkScalarToFloat(n)
61
Ben Wagnerda5a1b82014-08-22 15:07:06 -040062//Dummy representation of a GUID from createId.
bungeman@google.comb29c8832011-10-10 13:19:10 +000063#define L_GUID_ID L"XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX"
halcanary96fcdcc2015-08-27 07:41:13 -070064//Length of GUID representation from createId, including nullptr terminator.
bungeman@google.comb29c8832011-10-10 13:19:10 +000065#define GUID_ID_LEN SK_ARRAY_COUNT(L_GUID_ID)
66
67/**
68 Formats a GUID and places it into buffer.
69 buffer should have space for at least GUID_ID_LEN wide characters.
70 The string will always be wchar null terminated.
71 XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX0
72 @return -1 if there was an error, > 0 if success.
73 */
74static int format_guid(const GUID& guid,
75 wchar_t* buffer, size_t bufferSize,
76 wchar_t sep = '-') {
77 SkASSERT(bufferSize >= GUID_ID_LEN);
78 return swprintf_s(buffer,
79 bufferSize,
80 L"%08lX%c%04X%c%04X%c%02X%02X%c%02X%02X%02X%02X%02X%02X",
81 guid.Data1,
82 sep,
83 guid.Data2,
84 sep,
85 guid.Data3,
86 sep,
87 guid.Data4[0],
88 guid.Data4[1],
89 sep,
90 guid.Data4[2],
91 guid.Data4[3],
92 guid.Data4[4],
93 guid.Data4[5],
94 guid.Data4[6],
95 guid.Data4[7]);
96}
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +000097
Ben Wagnerda5a1b82014-08-22 15:07:06 -040098HRESULT SkXPSDevice::createId(wchar_t* buffer, size_t bufferSize, wchar_t sep) {
bungeman@google.comb29c8832011-10-10 13:19:10 +000099 GUID guid = {};
Ben Wagnerda5a1b82014-08-22 15:07:06 -0400100#ifdef SK_XPS_USE_DETERMINISTIC_IDS
101 guid.Data1 = fNextId++;
102 // The following make this a valid Type4 UUID.
103 guid.Data3 = 0x4000;
104 guid.Data4[0] = 0x80;
105#else
bungeman@google.comb29c8832011-10-10 13:19:10 +0000106 HRM(CoCreateGuid(&guid), "Could not create GUID for id.");
Ben Wagnerda5a1b82014-08-22 15:07:06 -0400107#endif
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000108
bungeman@google.comb29c8832011-10-10 13:19:10 +0000109 if (format_guid(guid, buffer, bufferSize, sep) == -1) {
110 HRM(E_UNEXPECTED, "Could not format GUID into id.");
111 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000112
bungeman@google.comb29c8832011-10-10 13:19:10 +0000113 return S_OK;
114}
115
Hal Canaryb39b09e2017-02-01 17:04:44 -0500116SkXPSDevice::SkXPSDevice(SkISize s)
117 : INHERITED(SkImageInfo::MakeUnknown(s.width(), s.height()),
118 SkSurfaceProps(0, kUnknown_SkPixelGeometry))
Hal Canaryabc88d22017-02-06 09:26:49 -0500119 , fCurrentPage(0) {}
bungeman@google.comb29c8832011-10-10 13:19:10 +0000120
Hal Canaryabc88d22017-02-06 09:26:49 -0500121SkXPSDevice::~SkXPSDevice() {}
bungeman@google.comb29c8832011-10-10 13:19:10 +0000122
123SkXPSDevice::TypefaceUse::TypefaceUse()
124 : typefaceId(0xffffffff)
halcanary96fcdcc2015-08-27 07:41:13 -0700125 , fontData(nullptr)
126 , xpsFont(nullptr)
Hal Canaryabc88d22017-02-06 09:26:49 -0500127 , glyphsUsed(nullptr) {}
bungeman@google.comb29c8832011-10-10 13:19:10 +0000128
129SkXPSDevice::TypefaceUse::~TypefaceUse() {
130 //xpsFont owns fontData ref
131 this->xpsFont->Release();
132 delete this->glyphsUsed;
133}
134
Hal Canaryabc88d22017-02-06 09:26:49 -0500135bool SkXPSDevice::beginPortfolio(SkWStream* outputStream, IXpsOMObjectFactory* factory) {
136 SkASSERT(factory);
137 fXpsFactory.reset(SkRefComPtr(factory));
138 HRB(SkWIStream::CreateFromSkWStream(outputStream, &this->fOutputStream));
bungeman@google.comb29c8832011-10-10 13:19:10 +0000139 return true;
140}
141
142bool SkXPSDevice::beginSheet(
143 const SkVector& unitsPerMeter,
144 const SkVector& pixelsPerMeter,
145 const SkSize& trimSize,
146 const SkRect* mediaBox,
147 const SkRect* bleedBox,
148 const SkRect* artBox,
149 const SkRect* cropBox) {
150 ++this->fCurrentPage;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000151
bungeman@google.comb29c8832011-10-10 13:19:10 +0000152 //For simplicity, just write everything out in geometry units,
153 //then have a base canvas do the scale to physical units.
154 this->fCurrentCanvasSize = trimSize;
155 this->fCurrentUnitsPerMeter = unitsPerMeter;
156 this->fCurrentPixelsPerMeter = pixelsPerMeter;
Hal Canaryabc88d22017-02-06 09:26:49 -0500157 return this->createCanvasForLayer();
158}
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000159
Hal Canaryabc88d22017-02-06 09:26:49 -0500160bool SkXPSDevice::createCanvasForLayer() {
161 SkASSERT(fXpsFactory);
162 fCurrentXpsCanvas.reset();
163 HRB(fXpsFactory->CreateCanvas(&fCurrentXpsCanvas));
bungeman@google.comb29c8832011-10-10 13:19:10 +0000164 return true;
165}
166
halcanarybfa92752016-05-31 11:23:42 -0700167template <typename T> static constexpr size_t sk_digits_in() {
168 return static_cast<size_t>(std::numeric_limits<T>::digits10 + 1);
169}
170
bungeman@google.comb29c8832011-10-10 13:19:10 +0000171HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page,
172 const unsigned int pageNum,
173 IXpsOMImageResource** image) {
174 SkTScopedComPtr<IXpsOMThumbnailGenerator> thumbnailGenerator;
175 HRM(CoCreateInstance(
176 CLSID_XpsOMThumbnailGenerator,
halcanary96fcdcc2015-08-27 07:41:13 -0700177 nullptr,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000178 CLSCTX_INPROC_SERVER,
179 IID_PPV_ARGS(&thumbnailGenerator)),
180 "Could not create thumbnail generator.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000181
bungeman@google.comb29c8832011-10-10 13:19:10 +0000182 SkTScopedComPtr<IOpcPartUri> partUri;
halcanarybfa92752016-05-31 11:23:42 -0700183 constexpr size_t size = SkTMax(
184 SK_ARRAY_COUNT(L"/Documents/1/Metadata/.png") + sk_digits_in<decltype(pageNum)>(),
185 SK_ARRAY_COUNT(L"/Metadata/" L_GUID_ID L".png"));
bungeman@google.comb29c8832011-10-10 13:19:10 +0000186 wchar_t buffer[size];
187 if (pageNum > 0) {
188 swprintf_s(buffer, size, L"/Documents/1/Metadata/%u.png", pageNum);
189 } else {
190 wchar_t id[GUID_ID_LEN];
Ben Wagnerda5a1b82014-08-22 15:07:06 -0400191 HR(this->createId(id, GUID_ID_LEN));
bungeman@google.comb29c8832011-10-10 13:19:10 +0000192 swprintf_s(buffer, size, L"/Metadata/%s.png", id);
193 }
194 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri),
195 "Could not create thumbnail part uri.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000196
bungeman@google.comb29c8832011-10-10 13:19:10 +0000197 HRM(thumbnailGenerator->GenerateThumbnail(page,
198 XPS_IMAGE_TYPE_PNG,
199 XPS_THUMBNAIL_SIZE_LARGE,
200 partUri.get(),
201 image),
202 "Could not generate thumbnail.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000203
bungeman@google.comb29c8832011-10-10 13:19:10 +0000204 return S_OK;
205}
206
207HRESULT SkXPSDevice::createXpsPage(const XPS_SIZE& pageSize,
208 IXpsOMPage** page) {
halcanarybfa92752016-05-31 11:23:42 -0700209 constexpr size_t size =
210 SK_ARRAY_COUNT(L"/Documents/1/Pages/.fpage")
211 + sk_digits_in<decltype(fCurrentPage)>();
bungeman@google.comb29c8832011-10-10 13:19:10 +0000212 wchar_t buffer[size];
213 swprintf_s(buffer, size, L"/Documents/1/Pages/%u.fpage",
214 this->fCurrentPage);
215 SkTScopedComPtr<IOpcPartUri> partUri;
216 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri),
217 "Could not create page part uri.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000218
bungeman@google.comb29c8832011-10-10 13:19:10 +0000219 //If the language is unknown, use "und" (XPS Spec 2.3.5.1).
220 HRM(this->fXpsFactory->CreatePage(&pageSize,
221 L"und",
222 partUri.get(),
223 page),
224 "Could not create page.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000225
bungeman@google.comb29c8832011-10-10 13:19:10 +0000226 return S_OK;
227}
228
229HRESULT SkXPSDevice::initXpsDocumentWriter(IXpsOMImageResource* image) {
230 //Create package writer.
231 {
232 SkTScopedComPtr<IOpcPartUri> partUri;
233 HRM(this->fXpsFactory->CreatePartUri(L"/FixedDocumentSequence.fdseq",
234 &partUri),
235 "Could not create document sequence part uri.");
236 HRM(this->fXpsFactory->CreatePackageWriterOnStream(
237 this->fOutputStream.get(),
238 TRUE,
239 XPS_INTERLEAVING_OFF, //XPS_INTERLEAVING_ON,
240 partUri.get(),
halcanary96fcdcc2015-08-27 07:41:13 -0700241 nullptr,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000242 image,
halcanary96fcdcc2015-08-27 07:41:13 -0700243 nullptr,
244 nullptr,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000245 &this->fPackageWriter),
246 "Could not create package writer.");
247 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000248
bungeman@google.comb29c8832011-10-10 13:19:10 +0000249 //Begin the lone document.
250 {
251 SkTScopedComPtr<IOpcPartUri> partUri;
252 HRM(this->fXpsFactory->CreatePartUri(
253 L"/Documents/1/FixedDocument.fdoc",
254 &partUri),
255 "Could not create fixed document part uri.");
256 HRM(this->fPackageWriter->StartNewDocument(partUri.get(),
halcanary96fcdcc2015-08-27 07:41:13 -0700257 nullptr,
258 nullptr,
259 nullptr,
260 nullptr),
bungeman@google.comb29c8832011-10-10 13:19:10 +0000261 "Could not start document.");
262 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000263
bungeman@google.comb29c8832011-10-10 13:19:10 +0000264 return S_OK;
265}
266
267bool SkXPSDevice::endSheet() {
268 //XPS is fixed at 96dpi (XPS Spec 11.1).
269 static const float xpsDPI = 96.0f;
270 static const float inchesPerMeter = 10000.0f / 254.0f;
271 static const float targetUnitsPerMeter = xpsDPI * inchesPerMeter;
272 const float scaleX = targetUnitsPerMeter
273 / SkScalarToFLOAT(this->fCurrentUnitsPerMeter.fX);
274 const float scaleY = targetUnitsPerMeter
275 / SkScalarToFLOAT(this->fCurrentUnitsPerMeter.fY);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000276
bungeman@google.comb29c8832011-10-10 13:19:10 +0000277 //Create the scale canvas.
278 SkTScopedComPtr<IXpsOMCanvas> scaleCanvas;
279 HRBM(this->fXpsFactory->CreateCanvas(&scaleCanvas),
280 "Could not create scale canvas.");
281 SkTScopedComPtr<IXpsOMVisualCollection> scaleCanvasVisuals;
282 HRBM(scaleCanvas->GetVisuals(&scaleCanvasVisuals),
283 "Could not get scale canvas visuals.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000284
bungeman@google.comb29c8832011-10-10 13:19:10 +0000285 SkTScopedComPtr<IXpsOMMatrixTransform> geomToPhys;
286 XPS_MATRIX rawGeomToPhys = { scaleX, 0, 0, scaleY, 0, 0, };
287 HRBM(this->fXpsFactory->CreateMatrixTransform(&rawGeomToPhys, &geomToPhys),
288 "Could not create geometry to physical transform.");
289 HRBM(scaleCanvas->SetTransformLocal(geomToPhys.get()),
290 "Could not set transform on scale canvas.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000291
bungeman@google.comb29c8832011-10-10 13:19:10 +0000292 //Add the content canvas to the scale canvas.
293 HRBM(scaleCanvasVisuals->Append(this->fCurrentXpsCanvas.get()),
294 "Could not add base canvas to scale canvas.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000295
bungeman@google.comb29c8832011-10-10 13:19:10 +0000296 //Create the page.
297 XPS_SIZE pageSize = {
298 SkScalarToFLOAT(this->fCurrentCanvasSize.width()) * scaleX,
299 SkScalarToFLOAT(this->fCurrentCanvasSize.height()) * scaleY,
300 };
301 SkTScopedComPtr<IXpsOMPage> page;
302 HRB(this->createXpsPage(pageSize, &page));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000303
bungeman@google.comb29c8832011-10-10 13:19:10 +0000304 SkTScopedComPtr<IXpsOMVisualCollection> pageVisuals;
305 HRBM(page->GetVisuals(&pageVisuals), "Could not get page visuals.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000306
bungeman@google.comb29c8832011-10-10 13:19:10 +0000307 //Add the scale canvas to the page.
308 HRBM(pageVisuals->Append(scaleCanvas.get()),
309 "Could not add scale canvas to page.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000310
bungeman@google.comb29c8832011-10-10 13:19:10 +0000311 //Create the package writer if it hasn't been created yet.
halcanary96fcdcc2015-08-27 07:41:13 -0700312 if (nullptr == this->fPackageWriter.get()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000313 SkTScopedComPtr<IXpsOMImageResource> image;
314 //Ignore return, thumbnail is completely optional.
315 this->createXpsThumbnail(page.get(), 0, &image);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000316
bungeman@google.comb29c8832011-10-10 13:19:10 +0000317 HRB(this->initXpsDocumentWriter(image.get()));
318 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000319
bungeman@google.comb29c8832011-10-10 13:19:10 +0000320 HRBM(this->fPackageWriter->AddPage(page.get(),
321 &pageSize,
halcanary96fcdcc2015-08-27 07:41:13 -0700322 nullptr,
323 nullptr,
324 nullptr,
325 nullptr),
bungeman@google.comb29c8832011-10-10 13:19:10 +0000326 "Could not write the page.");
327 this->fCurrentXpsCanvas.reset();
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000328
bungeman@google.comb29c8832011-10-10 13:19:10 +0000329 return true;
330}
331
332static HRESULT subset_typeface(SkXPSDevice::TypefaceUse* current) {
333 //CreateFontPackage wants unsigned short.
334 //Microsoft, Y U NO stdint.h?
335 SkTDArray<unsigned short> keepList;
336 current->glyphsUsed->exportTo(&keepList);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000337
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000338 int ttcCount = (current->ttcIndex + 1);
339
bungeman@google.comb29c8832011-10-10 13:19:10 +0000340 //The following are declared with the types required by CreateFontPackage.
halcanary96fcdcc2015-08-27 07:41:13 -0700341 unsigned char *fontPackageBufferRaw = nullptr;
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000342 unsigned long fontPackageBufferSize;
343 unsigned long bytesWritten;
bungeman@google.comb29c8832011-10-10 13:19:10 +0000344 unsigned long result = CreateFontPackage(
345 (unsigned char *) current->fontData->getMemoryBase(),
346 (unsigned long) current->fontData->getLength(),
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000347 &fontPackageBufferRaw,
348 &fontPackageBufferSize,
349 &bytesWritten,
350 TTFCFP_FLAGS_SUBSET | TTFCFP_FLAGS_GLYPHLIST | (ttcCount > 0 ? TTFCFP_FLAGS_TTC : 0),
351 current->ttcIndex,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000352 TTFCFP_SUBSET,
353 0,
354 0,
355 0,
356 keepList.begin(),
357 keepList.count(),
358 sk_malloc_throw,
359 sk_realloc_throw,
360 sk_free,
halcanary96fcdcc2015-08-27 07:41:13 -0700361 nullptr);
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000362 SkAutoTMalloc<unsigned char> fontPackageBuffer(fontPackageBufferRaw);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000363 if (result != NO_ERROR) {
Hal Canary2b0e6cd2018-07-09 12:43:39 -0400364 SkDEBUGF("CreateFontPackage Error %lu", result);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000365 return E_UNEXPECTED;
366 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000367
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000368 // If it was originally a ttc, keep it a ttc.
369 // CreateFontPackage over-allocates, realloc usually decreases the size substantially.
370 size_t extra;
371 if (ttcCount > 0) {
372 // Create space for a ttc header.
373 extra = sizeof(SkTTCFHeader) + (ttcCount * sizeof(SK_OT_ULONG));
374 fontPackageBuffer.realloc(bytesWritten + extra);
375 //overlap is certain, use memmove
376 memmove(fontPackageBuffer.get() + extra, fontPackageBuffer.get(), bytesWritten);
377
378 // Write the ttc header.
379 SkTTCFHeader* ttcfHeader = reinterpret_cast<SkTTCFHeader*>(fontPackageBuffer.get());
380 ttcfHeader->ttcTag = SkTTCFHeader::TAG;
381 ttcfHeader->version = SkTTCFHeader::version_1;
382 ttcfHeader->numOffsets = SkEndian_SwapBE32(ttcCount);
383 SK_OT_ULONG* offsetPtr = SkTAfter<SK_OT_ULONG>(ttcfHeader);
384 for (int i = 0; i < ttcCount; ++i, ++offsetPtr) {
bsalomon0aa5cea2014-12-15 09:13:35 -0800385 *offsetPtr = SkEndian_SwapBE32(SkToU32(extra));
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000386 }
387
388 // Fix up offsets in sfnt table entries.
389 SkSFNTHeader* sfntHeader = SkTAddOffset<SkSFNTHeader>(fontPackageBuffer.get(), extra);
390 int numTables = SkEndian_SwapBE16(sfntHeader->numTables);
391 SkSFNTHeader::TableDirectoryEntry* tableDirectory =
392 SkTAfter<SkSFNTHeader::TableDirectoryEntry>(sfntHeader);
393 for (int i = 0; i < numTables; ++i, ++tableDirectory) {
394 tableDirectory->offset = SkEndian_SwapBE32(
bsalomon0aa5cea2014-12-15 09:13:35 -0800395 SkToU32(SkEndian_SwapBE32(SkToU32(tableDirectory->offset)) + extra));
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000396 }
397 } else {
398 extra = 0;
399 fontPackageBuffer.realloc(bytesWritten);
400 }
401
Ben Wagner145dbcd2016-11-03 14:40:50 -0400402 std::unique_ptr<SkMemoryStream> newStream(new SkMemoryStream());
mtklein18300a32016-03-16 13:53:35 -0700403 newStream->setMemoryOwned(fontPackageBuffer.release(), bytesWritten + extra);
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000404
bungeman@google.comb29c8832011-10-10 13:19:10 +0000405 SkTScopedComPtr<IStream> newIStream;
mtklein18300a32016-03-16 13:53:35 -0700406 SkIStream::CreateFromSkStream(newStream.release(), true, &newIStream);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000407
bungeman@google.comb29c8832011-10-10 13:19:10 +0000408 XPS_FONT_EMBEDDING embedding;
409 HRM(current->xpsFont->GetEmbeddingOption(&embedding),
410 "Could not get embedding option from font.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000411
bungeman@google.comb29c8832011-10-10 13:19:10 +0000412 SkTScopedComPtr<IOpcPartUri> partUri;
413 HRM(current->xpsFont->GetPartName(&partUri),
414 "Could not get part uri from font.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000415
bungeman@google.comb29c8832011-10-10 13:19:10 +0000416 HRM(current->xpsFont->SetContent(
417 newIStream.get(),
418 embedding,
419 partUri.get()),
420 "Could not set new stream for subsetted font.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000421
bungeman@google.comb29c8832011-10-10 13:19:10 +0000422 return S_OK;
423}
424
425bool SkXPSDevice::endPortfolio() {
426 //Subset fonts
427 if (!this->fTypefaces.empty()) {
428 SkXPSDevice::TypefaceUse* current = &this->fTypefaces.front();
429 const TypefaceUse* last = &this->fTypefaces.back();
430 for (; current <= last; ++current) {
431 //Ignore return for now, if it didn't subset, let it be.
432 subset_typeface(current);
433 }
434 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000435
bungeman@google.comb29c8832011-10-10 13:19:10 +0000436 HRBM(this->fPackageWriter->Close(), "Could not close writer.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000437
bungeman@google.comb29c8832011-10-10 13:19:10 +0000438 return true;
439}
440
441static XPS_COLOR xps_color(const SkColor skColor) {
442 //XPS uses non-pre-multiplied alpha (XPS Spec 11.4).
443 XPS_COLOR xpsColor;
444 xpsColor.colorType = XPS_COLOR_TYPE_SRGB;
445 xpsColor.value.sRGB.alpha = SkColorGetA(skColor);
446 xpsColor.value.sRGB.red = SkColorGetR(skColor);
447 xpsColor.value.sRGB.green = SkColorGetG(skColor);
448 xpsColor.value.sRGB.blue = SkColorGetB(skColor);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000449
bungeman@google.comb29c8832011-10-10 13:19:10 +0000450 return xpsColor;
451}
452
453static XPS_POINT xps_point(const SkPoint& point) {
454 XPS_POINT xpsPoint = {
455 SkScalarToFLOAT(point.fX),
456 SkScalarToFLOAT(point.fY),
457 };
458 return xpsPoint;
459}
460
461static XPS_POINT xps_point(const SkPoint& point, const SkMatrix& matrix) {
462 SkPoint skTransformedPoint;
463 matrix.mapXY(point.fX, point.fY, &skTransformedPoint);
464 return xps_point(skTransformedPoint);
465}
466
467static XPS_SPREAD_METHOD xps_spread_method(SkShader::TileMode tileMode) {
468 switch (tileMode) {
469 case SkShader::kClamp_TileMode:
470 return XPS_SPREAD_METHOD_PAD;
471 case SkShader::kRepeat_TileMode:
472 return XPS_SPREAD_METHOD_REPEAT;
473 case SkShader::kMirror_TileMode:
474 return XPS_SPREAD_METHOD_REFLECT;
475 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000476 SkDEBUGFAIL("Unknown tile mode.");
bungeman@google.comb29c8832011-10-10 13:19:10 +0000477 }
478 return XPS_SPREAD_METHOD_PAD;
479}
480
481static void transform_offsets(SkScalar* stopOffsets, const int numOffsets,
482 const SkPoint& start, const SkPoint& end,
483 const SkMatrix& transform) {
484 SkPoint startTransformed;
485 transform.mapXY(start.fX, start.fY, &startTransformed);
486 SkPoint endTransformed;
487 transform.mapXY(end.fX, end.fY, &endTransformed);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000488
bungeman@google.comb29c8832011-10-10 13:19:10 +0000489 //Manhattan distance between transformed start and end.
490 SkScalar startToEnd = (endTransformed.fX - startTransformed.fX)
491 + (endTransformed.fY - startTransformed.fY);
492 if (SkScalarNearlyZero(startToEnd)) {
493 for (int i = 0; i < numOffsets; ++i) {
494 stopOffsets[i] = 0;
495 }
496 return;
497 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000498
bungeman@google.comb29c8832011-10-10 13:19:10 +0000499 for (int i = 0; i < numOffsets; ++i) {
500 SkPoint stop;
Mike Reed8be952a2017-02-13 20:44:33 -0500501 stop.fX = (end.fX - start.fX) * stopOffsets[i];
502 stop.fY = (end.fY - start.fY) * stopOffsets[i];
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000503
bungeman@google.comb29c8832011-10-10 13:19:10 +0000504 SkPoint stopTransformed;
505 transform.mapXY(stop.fX, stop.fY, &stopTransformed);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000506
bungeman@google.comb29c8832011-10-10 13:19:10 +0000507 //Manhattan distance between transformed start and stop.
508 SkScalar startToStop = (stopTransformed.fX - startTransformed.fX)
509 + (stopTransformed.fY - startTransformed.fY);
510 //Percentage along transformed line.
reed80ea19c2015-05-12 10:37:34 -0700511 stopOffsets[i] = startToStop / startToEnd;
bungeman@google.comb29c8832011-10-10 13:19:10 +0000512 }
513}
514
515HRESULT SkXPSDevice::createXpsTransform(const SkMatrix& matrix,
516 IXpsOMMatrixTransform** xpsTransform) {
517 SkScalar affine[6];
518 if (!matrix.asAffine(affine)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700519 *xpsTransform = nullptr;
bungeman@google.comb29c8832011-10-10 13:19:10 +0000520 return S_FALSE;
521 }
522 XPS_MATRIX rawXpsMatrix = {
Mike Reedf0cb7a02017-10-13 13:26:00 +0000523 SkScalarToFLOAT(affine[SkMatrix::kAScaleX]),
524 SkScalarToFLOAT(affine[SkMatrix::kASkewY]),
525 SkScalarToFLOAT(affine[SkMatrix::kASkewX]),
526 SkScalarToFLOAT(affine[SkMatrix::kAScaleY]),
527 SkScalarToFLOAT(affine[SkMatrix::kATransX]),
528 SkScalarToFLOAT(affine[SkMatrix::kATransY]),
bungeman@google.comb29c8832011-10-10 13:19:10 +0000529 };
530 HRM(this->fXpsFactory->CreateMatrixTransform(&rawXpsMatrix, xpsTransform),
531 "Could not create transform.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000532
bungeman@google.comb29c8832011-10-10 13:19:10 +0000533 return S_OK;
534}
535
536HRESULT SkXPSDevice::createPath(IXpsOMGeometryFigure* figure,
537 IXpsOMVisualCollection* visuals,
538 IXpsOMPath** path) {
539 SkTScopedComPtr<IXpsOMGeometry> geometry;
540 HRM(this->fXpsFactory->CreateGeometry(&geometry),
541 "Could not create geometry.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000542
bungeman@google.comb29c8832011-10-10 13:19:10 +0000543 SkTScopedComPtr<IXpsOMGeometryFigureCollection> figureCollection;
544 HRM(geometry->GetFigures(&figureCollection), "Could not get figures.");
545 HRM(figureCollection->Append(figure), "Could not add figure.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000546
bungeman@google.comb29c8832011-10-10 13:19:10 +0000547 HRM(this->fXpsFactory->CreatePath(path), "Could not create path.");
548 HRM((*path)->SetGeometryLocal(geometry.get()), "Could not set geometry");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000549
bungeman@google.comb29c8832011-10-10 13:19:10 +0000550 HRM(visuals->Append(*path), "Could not add path to visuals.");
551 return S_OK;
552}
553
554HRESULT SkXPSDevice::createXpsSolidColorBrush(const SkColor skColor,
555 const SkAlpha alpha,
556 IXpsOMBrush** xpsBrush) {
557 XPS_COLOR xpsColor = xps_color(skColor);
558 SkTScopedComPtr<IXpsOMSolidColorBrush> solidBrush;
halcanary96fcdcc2015-08-27 07:41:13 -0700559 HRM(this->fXpsFactory->CreateSolidColorBrush(&xpsColor, nullptr, &solidBrush),
bungeman@google.comb29c8832011-10-10 13:19:10 +0000560 "Could not create solid color brush.");
561 HRM(solidBrush->SetOpacity(alpha / 255.0f), "Could not set opacity.");
562 HRM(solidBrush->QueryInterface<IXpsOMBrush>(xpsBrush), "QI Fail.");
563 return S_OK;
564}
565
566HRESULT SkXPSDevice::sideOfClamp(const SkRect& areaToFill,
567 const XPS_RECT& imageViewBox,
568 IXpsOMImageResource* image,
569 IXpsOMVisualCollection* visuals) {
570 SkTScopedComPtr<IXpsOMGeometryFigure> areaToFillFigure;
571 HR(this->createXpsRect(areaToFill, FALSE, TRUE, &areaToFillFigure));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000572
bungeman@google.comb29c8832011-10-10 13:19:10 +0000573 SkTScopedComPtr<IXpsOMPath> areaToFillPath;
574 HR(this->createPath(areaToFillFigure.get(), visuals, &areaToFillPath));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000575
bungeman@google.comb29c8832011-10-10 13:19:10 +0000576 SkTScopedComPtr<IXpsOMImageBrush> areaToFillBrush;
577 HRM(this->fXpsFactory->CreateImageBrush(image,
578 &imageViewBox,
579 &imageViewBox,
580 &areaToFillBrush),
581 "Could not create brush for side of clamp.");
582 HRM(areaToFillBrush->SetTileMode(XPS_TILE_MODE_FLIPXY),
583 "Could not set tile mode for side of clamp.");
584 HRM(areaToFillPath->SetFillBrushLocal(areaToFillBrush.get()),
585 "Could not set brush for side of clamp");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000586
bungeman@google.comb29c8832011-10-10 13:19:10 +0000587 return S_OK;
588}
589
590HRESULT SkXPSDevice::cornerOfClamp(const SkRect& areaToFill,
591 const SkColor color,
592 IXpsOMVisualCollection* visuals) {
593 SkTScopedComPtr<IXpsOMGeometryFigure> areaToFillFigure;
594 HR(this->createXpsRect(areaToFill, FALSE, TRUE, &areaToFillFigure));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000595
bungeman@google.comb29c8832011-10-10 13:19:10 +0000596 SkTScopedComPtr<IXpsOMPath> areaToFillPath;
597 HR(this->createPath(areaToFillFigure.get(), visuals, &areaToFillPath));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000598
bungeman@google.comb29c8832011-10-10 13:19:10 +0000599 SkTScopedComPtr<IXpsOMBrush> areaToFillBrush;
600 HR(this->createXpsSolidColorBrush(color, 0xFF, &areaToFillBrush));
601 HRM(areaToFillPath->SetFillBrushLocal(areaToFillBrush.get()),
602 "Could not set brush for corner of clamp.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000603
bungeman@google.comb29c8832011-10-10 13:19:10 +0000604 return S_OK;
605}
606
607static const XPS_TILE_MODE XTM_N = XPS_TILE_MODE_NONE;
608static const XPS_TILE_MODE XTM_T = XPS_TILE_MODE_TILE;
609static const XPS_TILE_MODE XTM_X = XPS_TILE_MODE_FLIPX;
610static const XPS_TILE_MODE XTM_Y = XPS_TILE_MODE_FLIPY;
611static const XPS_TILE_MODE XTM_XY = XPS_TILE_MODE_FLIPXY;
612
613//TODO(bungeman): In the future, should skia add None,
614//handle None+Mirror and None+Repeat correctly.
615//None is currently an internal hack so masks don't repeat (None+None only).
616static XPS_TILE_MODE SkToXpsTileMode[SkShader::kTileModeCount+1]
617 [SkShader::kTileModeCount+1] = {
halcanarya634b742016-10-13 08:44:11 -0700618 //Clamp //Repeat //Mirror //None
619 /*Clamp */ {XTM_N, XTM_T, XTM_Y, XTM_N},
620 /*Repeat*/ {XTM_T, XTM_T, XTM_Y, XTM_N},
621 /*Mirror*/ {XTM_X, XTM_X, XTM_XY, XTM_X},
622 /*None */ {XTM_N, XTM_N, XTM_Y, XTM_N},
bungeman@google.comb29c8832011-10-10 13:19:10 +0000623};
624
625HRESULT SkXPSDevice::createXpsImageBrush(
626 const SkBitmap& bitmap,
627 const SkMatrix& localMatrix,
628 const SkShader::TileMode (&xy)[2],
629 const SkAlpha alpha,
630 IXpsOMTileBrush** xpsBrush) {
631 SkDynamicMemoryWStream write;
Hal Canarydb683012016-11-23 08:55:18 -0700632 if (!SkEncodeImage(&write, bitmap, SkEncodedImageFormat::kPNG, 100)) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000633 HRM(E_FAIL, "Unable to encode bitmap as png.");
634 }
635 SkMemoryStream* read = new SkMemoryStream;
reed42943c82016-09-12 12:01:44 -0700636 read->setData(write.detachAsData());
bungeman@google.comb29c8832011-10-10 13:19:10 +0000637 SkTScopedComPtr<IStream> readWrapper;
638 HRM(SkIStream::CreateFromSkStream(read, true, &readWrapper),
639 "Could not create stream from png data.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000640
bungeman@google.comb29c8832011-10-10 13:19:10 +0000641 const size_t size =
642 SK_ARRAY_COUNT(L"/Documents/1/Resources/Images/" L_GUID_ID L".png");
643 wchar_t buffer[size];
644 wchar_t id[GUID_ID_LEN];
Ben Wagnerda5a1b82014-08-22 15:07:06 -0400645 HR(this->createId(id, GUID_ID_LEN));
bungeman@google.comb29c8832011-10-10 13:19:10 +0000646 swprintf_s(buffer, size, L"/Documents/1/Resources/Images/%s.png", id);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000647
bungeman@google.comb29c8832011-10-10 13:19:10 +0000648 SkTScopedComPtr<IOpcPartUri> imagePartUri;
649 HRM(this->fXpsFactory->CreatePartUri(buffer, &imagePartUri),
650 "Could not create image part uri.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000651
bungeman@google.comb29c8832011-10-10 13:19:10 +0000652 SkTScopedComPtr<IXpsOMImageResource> imageResource;
653 HRM(this->fXpsFactory->CreateImageResource(
654 readWrapper.get(),
655 XPS_IMAGE_TYPE_PNG,
656 imagePartUri.get(),
657 &imageResource),
658 "Could not create image resource.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000659
bungeman@google.comb29c8832011-10-10 13:19:10 +0000660 XPS_RECT bitmapRect = {
661 0.0, 0.0,
662 static_cast<FLOAT>(bitmap.width()), static_cast<FLOAT>(bitmap.height())
663 };
664 SkTScopedComPtr<IXpsOMImageBrush> xpsImageBrush;
665 HRM(this->fXpsFactory->CreateImageBrush(imageResource.get(),
666 &bitmapRect, &bitmapRect,
667 &xpsImageBrush),
668 "Could not create image brush.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000669
bungeman@google.comb29c8832011-10-10 13:19:10 +0000670 if (SkShader::kClamp_TileMode != xy[0] &&
671 SkShader::kClamp_TileMode != xy[1]) {
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000672
bungeman@google.comb29c8832011-10-10 13:19:10 +0000673 HRM(xpsImageBrush->SetTileMode(SkToXpsTileMode[xy[0]][xy[1]]),
674 "Could not set image tile mode");
675 HRM(xpsImageBrush->SetOpacity(alpha / 255.0f),
676 "Could not set image opacity.");
677 HRM(xpsImageBrush->QueryInterface(xpsBrush), "QI failed.");
678 } else {
679 //TODO(bungeman): compute how big this really needs to be.
680 const SkScalar BIG = SkIntToScalar(1000); //SK_ScalarMax;
681 const FLOAT BIG_F = SkScalarToFLOAT(BIG);
682 const SkScalar bWidth = SkIntToScalar(bitmap.width());
683 const SkScalar bHeight = SkIntToScalar(bitmap.height());
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000684
bungeman@google.comb29c8832011-10-10 13:19:10 +0000685 //create brush canvas
686 SkTScopedComPtr<IXpsOMCanvas> brushCanvas;
687 HRM(this->fXpsFactory->CreateCanvas(&brushCanvas),
688 "Could not create image brush canvas.");
689 SkTScopedComPtr<IXpsOMVisualCollection> brushVisuals;
690 HRM(brushCanvas->GetVisuals(&brushVisuals),
691 "Could not get image brush canvas visuals collection.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000692
bungeman@google.comb29c8832011-10-10 13:19:10 +0000693 //create central figure
694 const SkRect bitmapPoints = SkRect::MakeLTRB(0, 0, bWidth, bHeight);
695 SkTScopedComPtr<IXpsOMGeometryFigure> centralFigure;
696 HR(this->createXpsRect(bitmapPoints, FALSE, TRUE, &centralFigure));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000697
bungeman@google.comb29c8832011-10-10 13:19:10 +0000698 SkTScopedComPtr<IXpsOMPath> centralPath;
699 HR(this->createPath(centralFigure.get(),
700 brushVisuals.get(),
701 &centralPath));
702 HRM(xpsImageBrush->SetTileMode(XPS_TILE_MODE_FLIPXY),
703 "Could not set tile mode for image brush central path.");
704 HRM(centralPath->SetFillBrushLocal(xpsImageBrush.get()),
705 "Could not set fill brush for image brush central path.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000706
bungeman@google.comb29c8832011-10-10 13:19:10 +0000707 //add left/right
708 if (SkShader::kClamp_TileMode == xy[0]) {
709 SkRect leftArea = SkRect::MakeLTRB(-BIG, 0, 0, bHeight);
710 XPS_RECT leftImageViewBox = {
711 0.0, 0.0,
712 1.0, static_cast<FLOAT>(bitmap.height()),
713 };
714 HR(this->sideOfClamp(leftArea, leftImageViewBox,
715 imageResource.get(),
716 brushVisuals.get()));
717
718 SkRect rightArea = SkRect::MakeLTRB(bWidth, 0, BIG, bHeight);
719 XPS_RECT rightImageViewBox = {
720 bitmap.width() - 1.0f, 0.0f,
721 1.0f, static_cast<FLOAT>(bitmap.height()),
722 };
723 HR(this->sideOfClamp(rightArea, rightImageViewBox,
724 imageResource.get(),
725 brushVisuals.get()));
726 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000727
bungeman@google.comb29c8832011-10-10 13:19:10 +0000728 //add top/bottom
729 if (SkShader::kClamp_TileMode == xy[1]) {
730 SkRect topArea = SkRect::MakeLTRB(0, -BIG, bWidth, 0);
731 XPS_RECT topImageViewBox = {
732 0.0, 0.0,
733 static_cast<FLOAT>(bitmap.width()), 1.0,
734 };
735 HR(this->sideOfClamp(topArea, topImageViewBox,
736 imageResource.get(),
737 brushVisuals.get()));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000738
bungeman@google.comb29c8832011-10-10 13:19:10 +0000739 SkRect bottomArea = SkRect::MakeLTRB(0, bHeight, bWidth, BIG);
740 XPS_RECT bottomImageViewBox = {
741 0.0f, bitmap.height() - 1.0f,
742 static_cast<FLOAT>(bitmap.width()), 1.0f,
743 };
744 HR(this->sideOfClamp(bottomArea, bottomImageViewBox,
745 imageResource.get(),
746 brushVisuals.get()));
747 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000748
bungeman@google.comb29c8832011-10-10 13:19:10 +0000749 //add tl, tr, bl, br
750 if (SkShader::kClamp_TileMode == xy[0] &&
751 SkShader::kClamp_TileMode == xy[1]) {
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000752
bungeman@google.comb29c8832011-10-10 13:19:10 +0000753 const SkColor tlColor = bitmap.getColor(0,0);
754 const SkRect tlArea = SkRect::MakeLTRB(-BIG, -BIG, 0, 0);
755 HR(this->cornerOfClamp(tlArea, tlColor, brushVisuals.get()));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000756
bungeman@google.comb29c8832011-10-10 13:19:10 +0000757 const SkColor trColor = bitmap.getColor(bitmap.width()-1,0);
758 const SkRect trArea = SkRect::MakeLTRB(bWidth, -BIG, BIG, 0);
759 HR(this->cornerOfClamp(trArea, trColor, brushVisuals.get()));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000760
bungeman@google.comb29c8832011-10-10 13:19:10 +0000761 const SkColor brColor = bitmap.getColor(bitmap.width()-1,
762 bitmap.height()-1);
763 const SkRect brArea = SkRect::MakeLTRB(bWidth, bHeight, BIG, BIG);
764 HR(this->cornerOfClamp(brArea, brColor, brushVisuals.get()));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000765
bungeman@google.comb29c8832011-10-10 13:19:10 +0000766 const SkColor blColor = bitmap.getColor(0,bitmap.height()-1);
767 const SkRect blArea = SkRect::MakeLTRB(-BIG, bHeight, 0, BIG);
768 HR(this->cornerOfClamp(blArea, blColor, brushVisuals.get()));
769 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000770
bungeman@google.comb29c8832011-10-10 13:19:10 +0000771 //create visual brush from canvas
772 XPS_RECT bound = {};
773 if (SkShader::kClamp_TileMode == xy[0] &&
774 SkShader::kClamp_TileMode == xy[1]) {
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000775
bungeman@google.comb29c8832011-10-10 13:19:10 +0000776 bound.x = BIG_F / -2;
777 bound.y = BIG_F / -2;
778 bound.width = BIG_F;
779 bound.height = BIG_F;
780 } else if (SkShader::kClamp_TileMode == xy[0]) {
781 bound.x = BIG_F / -2;
782 bound.y = 0.0f;
783 bound.width = BIG_F;
784 bound.height = static_cast<FLOAT>(bitmap.height());
785 } else if (SkShader::kClamp_TileMode == xy[1]) {
786 bound.x = 0;
787 bound.y = BIG_F / -2;
788 bound.width = static_cast<FLOAT>(bitmap.width());
789 bound.height = BIG_F;
790 }
791 SkTScopedComPtr<IXpsOMVisualBrush> clampBrush;
792 HRM(this->fXpsFactory->CreateVisualBrush(&bound, &bound, &clampBrush),
793 "Could not create visual brush for image brush.");
794 HRM(clampBrush->SetVisualLocal(brushCanvas.get()),
795 "Could not set canvas on visual brush for image brush.");
796 HRM(clampBrush->SetTileMode(SkToXpsTileMode[xy[0]][xy[1]]),
797 "Could not set tile mode on visual brush for image brush.");
798 HRM(clampBrush->SetOpacity(alpha / 255.0f),
799 "Could not set opacity on visual brush for image brush.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000800
bungeman@google.comb29c8832011-10-10 13:19:10 +0000801 HRM(clampBrush->QueryInterface(xpsBrush), "QI failed.");
802 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000803
bungeman@google.comb29c8832011-10-10 13:19:10 +0000804 SkTScopedComPtr<IXpsOMMatrixTransform> xpsMatrixToUse;
805 HR(this->createXpsTransform(localMatrix, &xpsMatrixToUse));
bsalomon49f085d2014-09-05 13:34:00 -0700806 if (xpsMatrixToUse.get()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000807 HRM((*xpsBrush)->SetTransformLocal(xpsMatrixToUse.get()),
808 "Could not set transform for image brush.");
809 } else {
810 //TODO(bungeman): perspective bitmaps in general.
811 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000812
bungeman@google.comb29c8832011-10-10 13:19:10 +0000813 return S_OK;
814}
815
816HRESULT SkXPSDevice::createXpsGradientStop(const SkColor skColor,
817 const SkScalar offset,
818 IXpsOMGradientStop** xpsGradStop) {
819 XPS_COLOR gradStopXpsColor = xps_color(skColor);
820 HRM(this->fXpsFactory->CreateGradientStop(&gradStopXpsColor,
halcanary96fcdcc2015-08-27 07:41:13 -0700821 nullptr,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000822 SkScalarToFLOAT(offset),
823 xpsGradStop),
824 "Could not create gradient stop.");
825 return S_OK;
826}
827
828HRESULT SkXPSDevice::createXpsLinearGradient(SkShader::GradientInfo info,
829 const SkAlpha alpha,
830 const SkMatrix& localMatrix,
831 IXpsOMMatrixTransform* xpsMatrix,
832 IXpsOMBrush** xpsBrush) {
833 XPS_POINT startPoint;
834 XPS_POINT endPoint;
bsalomon49f085d2014-09-05 13:34:00 -0700835 if (xpsMatrix) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000836 startPoint = xps_point(info.fPoint[0]);
837 endPoint = xps_point(info.fPoint[1]);
838 } else {
839 transform_offsets(info.fColorOffsets, info.fColorCount,
840 info.fPoint[0], info.fPoint[1],
841 localMatrix);
842 startPoint = xps_point(info.fPoint[0], localMatrix);
843 endPoint = xps_point(info.fPoint[1], localMatrix);
844 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000845
bungeman@google.comb29c8832011-10-10 13:19:10 +0000846 SkTScopedComPtr<IXpsOMGradientStop> gradStop0;
847 HR(createXpsGradientStop(info.fColors[0],
848 info.fColorOffsets[0],
849 &gradStop0));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000850
bungeman@google.comb29c8832011-10-10 13:19:10 +0000851 SkTScopedComPtr<IXpsOMGradientStop> gradStop1;
852 HR(createXpsGradientStop(info.fColors[1],
853 info.fColorOffsets[1],
854 &gradStop1));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000855
bungeman@google.comb29c8832011-10-10 13:19:10 +0000856 SkTScopedComPtr<IXpsOMLinearGradientBrush> gradientBrush;
857 HRM(this->fXpsFactory->CreateLinearGradientBrush(gradStop0.get(),
858 gradStop1.get(),
859 &startPoint,
860 &endPoint,
861 &gradientBrush),
862 "Could not create linear gradient brush.");
bsalomon49f085d2014-09-05 13:34:00 -0700863 if (xpsMatrix) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000864 HRM(gradientBrush->SetTransformLocal(xpsMatrix),
865 "Could not set transform on linear gradient brush.");
866 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000867
bungeman@google.comb29c8832011-10-10 13:19:10 +0000868 SkTScopedComPtr<IXpsOMGradientStopCollection> gradStopCollection;
869 HRM(gradientBrush->GetGradientStops(&gradStopCollection),
870 "Could not get linear gradient stop collection.");
871 for (int i = 2; i < info.fColorCount; ++i) {
872 SkTScopedComPtr<IXpsOMGradientStop> gradStop;
873 HR(createXpsGradientStop(info.fColors[i],
874 info.fColorOffsets[i],
875 &gradStop));
876 HRM(gradStopCollection->Append(gradStop.get()),
877 "Could not add linear gradient stop.");
878 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000879
bungeman@google.comb29c8832011-10-10 13:19:10 +0000880 HRM(gradientBrush->SetSpreadMethod(xps_spread_method(info.fTileMode)),
881 "Could not set spread method of linear gradient.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000882
bungeman@google.comb29c8832011-10-10 13:19:10 +0000883 HRM(gradientBrush->SetOpacity(alpha / 255.0f),
884 "Could not set opacity of linear gradient brush.");
885 HRM(gradientBrush->QueryInterface<IXpsOMBrush>(xpsBrush), "QI failed");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000886
bungeman@google.comb29c8832011-10-10 13:19:10 +0000887 return S_OK;
888}
889
890HRESULT SkXPSDevice::createXpsRadialGradient(SkShader::GradientInfo info,
891 const SkAlpha alpha,
892 const SkMatrix& localMatrix,
893 IXpsOMMatrixTransform* xpsMatrix,
894 IXpsOMBrush** xpsBrush) {
895 SkTScopedComPtr<IXpsOMGradientStop> gradStop0;
896 HR(createXpsGradientStop(info.fColors[0],
897 info.fColorOffsets[0],
898 &gradStop0));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000899
bungeman@google.comb29c8832011-10-10 13:19:10 +0000900 SkTScopedComPtr<IXpsOMGradientStop> gradStop1;
901 HR(createXpsGradientStop(info.fColors[1],
902 info.fColorOffsets[1],
903 &gradStop1));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000904
bungeman@google.comb29c8832011-10-10 13:19:10 +0000905 //TODO: figure out how to fake better if not affine
906 XPS_POINT centerPoint;
907 XPS_POINT gradientOrigin;
908 XPS_SIZE radiiSizes;
bsalomon49f085d2014-09-05 13:34:00 -0700909 if (xpsMatrix) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000910 centerPoint = xps_point(info.fPoint[0]);
911 gradientOrigin = xps_point(info.fPoint[0]);
912 radiiSizes.width = SkScalarToFLOAT(info.fRadius[0]);
913 radiiSizes.height = SkScalarToFLOAT(info.fRadius[0]);
914 } else {
915 centerPoint = xps_point(info.fPoint[0], localMatrix);
916 gradientOrigin = xps_point(info.fPoint[0], localMatrix);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000917
bungeman@google.comb29c8832011-10-10 13:19:10 +0000918 SkScalar radius = info.fRadius[0];
919 SkVector vec[2];
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000920
bungeman@google.comb29c8832011-10-10 13:19:10 +0000921 vec[0].set(radius, 0);
922 vec[1].set(0, radius);
923 localMatrix.mapVectors(vec, 2);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000924
bungeman@google.comb29c8832011-10-10 13:19:10 +0000925 SkScalar d0 = vec[0].length();
926 SkScalar d1 = vec[1].length();
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000927
bungeman@google.comb29c8832011-10-10 13:19:10 +0000928 radiiSizes.width = SkScalarToFLOAT(d0);
929 radiiSizes.height = SkScalarToFLOAT(d1);
930 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000931
bungeman@google.comb29c8832011-10-10 13:19:10 +0000932 SkTScopedComPtr<IXpsOMRadialGradientBrush> gradientBrush;
933 HRM(this->fXpsFactory->CreateRadialGradientBrush(gradStop0.get(),
934 gradStop1.get(),
935 &centerPoint,
936 &gradientOrigin,
937 &radiiSizes,
938 &gradientBrush),
939 "Could not create radial gradient brush.");
bsalomon49f085d2014-09-05 13:34:00 -0700940 if (xpsMatrix) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000941 HRM(gradientBrush->SetTransformLocal(xpsMatrix),
942 "Could not set transform on radial gradient brush.");
943 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000944
bungeman@google.comb29c8832011-10-10 13:19:10 +0000945 SkTScopedComPtr<IXpsOMGradientStopCollection> gradStopCollection;
946 HRM(gradientBrush->GetGradientStops(&gradStopCollection),
947 "Could not get radial gradient stop collection.");
948 for (int i = 2; i < info.fColorCount; ++i) {
949 SkTScopedComPtr<IXpsOMGradientStop> gradStop;
950 HR(createXpsGradientStop(info.fColors[i],
951 info.fColorOffsets[i],
952 &gradStop));
953 HRM(gradStopCollection->Append(gradStop.get()),
954 "Could not add radial gradient stop.");
955 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000956
bungeman@google.comb29c8832011-10-10 13:19:10 +0000957 HRM(gradientBrush->SetSpreadMethod(xps_spread_method(info.fTileMode)),
958 "Could not set spread method of radial gradient.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000959
bungeman@google.comb29c8832011-10-10 13:19:10 +0000960 HRM(gradientBrush->SetOpacity(alpha / 255.0f),
961 "Could not set opacity of radial gradient brush.");
962 HRM(gradientBrush->QueryInterface<IXpsOMBrush>(xpsBrush), "QI failed.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000963
bungeman@google.comb29c8832011-10-10 13:19:10 +0000964 return S_OK;
965}
966
967HRESULT SkXPSDevice::createXpsBrush(const SkPaint& skPaint,
968 IXpsOMBrush** brush,
969 const SkMatrix* parentTransform) {
970 const SkShader *shader = skPaint.getShader();
halcanary96fcdcc2015-08-27 07:41:13 -0700971 if (nullptr == shader) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000972 HR(this->createXpsSolidColorBrush(skPaint.getColor(), 0xFF, brush));
973 return S_OK;
974 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000975
bungeman@google.comb29c8832011-10-10 13:19:10 +0000976 //Gradient shaders.
977 SkShader::GradientInfo info;
978 info.fColorCount = 0;
halcanary96fcdcc2015-08-27 07:41:13 -0700979 info.fColors = nullptr;
980 info.fColorOffsets = nullptr;
bungeman@google.comb29c8832011-10-10 13:19:10 +0000981 SkShader::GradientType gradientType = shader->asAGradient(&info);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000982
bungeman@google.comb29c8832011-10-10 13:19:10 +0000983 if (SkShader::kNone_GradientType == gradientType) {
984 //Nothing to see, move along.
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000985
bungeman@google.comb29c8832011-10-10 13:19:10 +0000986 } else if (SkShader::kColor_GradientType == gradientType) {
987 SkASSERT(1 == info.fColorCount);
988 SkColor color;
989 info.fColors = &color;
bsalomon@google.comb58a6392013-03-21 20:29:05 +0000990 shader->asAGradient(&info);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000991 SkAlpha alpha = skPaint.getAlpha();
992 HR(this->createXpsSolidColorBrush(color, alpha, brush));
993 return S_OK;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000994
bungeman@google.comb29c8832011-10-10 13:19:10 +0000995 } else {
996 if (info.fColorCount == 0) {
997 const SkColor color = skPaint.getColor();
998 HR(this->createXpsSolidColorBrush(color, 0xFF, brush));
999 return S_OK;
1000 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001001
bungeman@google.comb29c8832011-10-10 13:19:10 +00001002 SkAutoTArray<SkColor> colors(info.fColorCount);
1003 SkAutoTArray<SkScalar> colorOffsets(info.fColorCount);
1004 info.fColors = colors.get();
1005 info.fColorOffsets = colorOffsets.get();
1006 shader->asAGradient(&info);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001007
bungeman@google.comb29c8832011-10-10 13:19:10 +00001008 if (1 == info.fColorCount) {
1009 SkColor color = info.fColors[0];
1010 SkAlpha alpha = skPaint.getAlpha();
1011 HR(this->createXpsSolidColorBrush(color, alpha, brush));
1012 return S_OK;
1013 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001014
bsalomon@google.comf94b3a42012-10-31 18:09:01 +00001015 SkMatrix localMatrix = shader->getLocalMatrix();
bsalomon49f085d2014-09-05 13:34:00 -07001016 if (parentTransform) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001017 localMatrix.preConcat(*parentTransform);
1018 }
1019 SkTScopedComPtr<IXpsOMMatrixTransform> xpsMatrixToUse;
1020 HR(this->createXpsTransform(localMatrix, &xpsMatrixToUse));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001021
bungeman@google.comb29c8832011-10-10 13:19:10 +00001022 if (SkShader::kLinear_GradientType == gradientType) {
1023 HR(this->createXpsLinearGradient(info,
1024 skPaint.getAlpha(),
1025 localMatrix,
1026 xpsMatrixToUse.get(),
1027 brush));
1028 return S_OK;
1029 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001030
bungeman@google.comb29c8832011-10-10 13:19:10 +00001031 if (SkShader::kRadial_GradientType == gradientType) {
1032 HR(this->createXpsRadialGradient(info,
1033 skPaint.getAlpha(),
1034 localMatrix,
1035 xpsMatrixToUse.get(),
1036 brush));
1037 return S_OK;
1038 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001039
reed71a6cbf2015-05-04 08:32:51 -07001040 if (SkShader::kConical_GradientType == gradientType) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001041 //simple if affine and one is 0, otherwise will have to fake
1042 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001043
bungeman@google.comb29c8832011-10-10 13:19:10 +00001044 if (SkShader::kSweep_GradientType == gradientType) {
1045 //have to fake
1046 }
1047 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001048
bungeman@google.comb29c8832011-10-10 13:19:10 +00001049 SkBitmap outTexture;
1050 SkMatrix outMatrix;
1051 SkShader::TileMode xy[2];
Mike Reed627778d2016-09-28 17:13:38 -04001052 SkImage* image = shader->isAImage(&outMatrix, xy);
Cary Clark4f5a79c2018-02-07 15:51:00 -05001053 if (image && image->asLegacyBitmap(&outTexture)) {
reedf5822822015-08-19 11:46:38 -07001054 //TODO: outMatrix??
1055 SkMatrix localMatrix = shader->getLocalMatrix();
1056 if (parentTransform) {
Hal Canarybc212432017-03-17 11:48:59 -04001057 localMatrix.postConcat(*parentTransform);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001058 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001059
reedf5822822015-08-19 11:46:38 -07001060 SkTScopedComPtr<IXpsOMTileBrush> tileBrush;
1061 HR(this->createXpsImageBrush(outTexture,
1062 localMatrix,
1063 xy,
1064 skPaint.getAlpha(),
1065 &tileBrush));
1066
1067 HRM(tileBrush->QueryInterface<IXpsOMBrush>(brush), "QI failed.");
1068 } else {
1069 HR(this->createXpsSolidColorBrush(skPaint.getColor(), 0xFF, brush));
1070 }
bungeman@google.comb29c8832011-10-10 13:19:10 +00001071 return S_OK;
1072}
1073
1074static bool rect_must_be_pathed(const SkPaint& paint, const SkMatrix& matrix) {
1075 const bool zeroWidth = (0 == paint.getStrokeWidth());
1076 const bool stroke = (SkPaint::kFill_Style != paint.getStyle());
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001077
bungeman@google.comb29c8832011-10-10 13:19:10 +00001078 return paint.getPathEffect() ||
1079 paint.getMaskFilter() ||
bungeman@google.comb29c8832011-10-10 13:19:10 +00001080 (stroke && (
1081 (matrix.hasPerspective() && !zeroWidth) ||
1082 SkPaint::kMiter_Join != paint.getStrokeJoin() ||
1083 (SkPaint::kMiter_Join == paint.getStrokeJoin() &&
1084 paint.getStrokeMiter() < SK_ScalarSqrt2)
1085 ))
1086 ;
1087}
1088
1089HRESULT SkXPSDevice::createXpsRect(const SkRect& rect, BOOL stroke, BOOL fill,
1090 IXpsOMGeometryFigure** xpsRect) {
1091 const SkPoint points[4] = {
1092 { rect.fLeft, rect.fTop },
1093 { rect.fRight, rect.fTop },
1094 { rect.fRight, rect.fBottom },
1095 { rect.fLeft, rect.fBottom },
1096 };
1097 return this->createXpsQuad(points, stroke, fill, xpsRect);
1098}
1099HRESULT SkXPSDevice::createXpsQuad(const SkPoint (&points)[4],
1100 BOOL stroke, BOOL fill,
1101 IXpsOMGeometryFigure** xpsQuad) {
1102 // Define the start point.
1103 XPS_POINT startPoint = xps_point(points[0]);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001104
bungeman@google.comb29c8832011-10-10 13:19:10 +00001105 // Create the figure.
1106 HRM(this->fXpsFactory->CreateGeometryFigure(&startPoint, xpsQuad),
1107 "Could not create quad geometry figure.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001108
bungeman@google.comb29c8832011-10-10 13:19:10 +00001109 // Define the type of each segment.
1110 XPS_SEGMENT_TYPE segmentTypes[3] = {
1111 XPS_SEGMENT_TYPE_LINE,
1112 XPS_SEGMENT_TYPE_LINE,
1113 XPS_SEGMENT_TYPE_LINE,
1114 };
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001115
bungeman@google.comb29c8832011-10-10 13:19:10 +00001116 // Define the x and y coordinates of each corner of the figure.
1117 FLOAT segmentData[6] = {
1118 SkScalarToFLOAT(points[1].fX), SkScalarToFLOAT(points[1].fY),
1119 SkScalarToFLOAT(points[2].fX), SkScalarToFLOAT(points[2].fY),
1120 SkScalarToFLOAT(points[3].fX), SkScalarToFLOAT(points[3].fY),
1121 };
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001122
bungeman@google.comb29c8832011-10-10 13:19:10 +00001123 // Describe if the segments are stroked.
1124 BOOL segmentStrokes[3] = {
1125 stroke, stroke, stroke,
1126 };
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001127
bungeman@google.comb29c8832011-10-10 13:19:10 +00001128 // Add the segment data to the figure.
1129 HRM((*xpsQuad)->SetSegments(
1130 3, 6,
1131 segmentTypes , segmentData, segmentStrokes),
1132 "Could not add segment data to quad.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001133
bungeman@google.comb29c8832011-10-10 13:19:10 +00001134 // Set the closed and filled properties of the figure.
1135 HRM((*xpsQuad)->SetIsClosed(stroke), "Could not set quad close.");
1136 HRM((*xpsQuad)->SetIsFilled(fill), "Could not set quad fill.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001137
bungeman@google.comb29c8832011-10-10 13:19:10 +00001138 return S_OK;
1139}
1140
Mike Reeda1361362017-03-07 09:37:29 -05001141template <typename F, typename... Args>
1142void draw(SkClipStackDevice* dev, F f, Args&&... args) {
1143 SkIRect r = dev->devClipBounds();
1144 SkRasterClip rc(r);
1145 SkDraw draw;
1146 draw.fMatrix = &dev->ctm();
1147 draw.fDst = SkPixmap(SkImageInfo::MakeUnknown(r.right(), r.bottom()), nullptr, 0);
1148 draw.fRC = &rc;
1149 (draw.*f)(std::forward<Args>(args)...);
1150}
1151
1152
1153void SkXPSDevice::drawPoints(SkCanvas::PointMode mode,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001154 size_t count, const SkPoint points[],
1155 const SkPaint& paint) {
Mike Reeda1361362017-03-07 09:37:29 -05001156 draw(this, &SkDraw::drawPoints, mode, count, points, paint, this);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001157}
1158
Ruiqi Maoc97a3392018-08-15 10:44:19 -04001159void SkXPSDevice::drawVertices(const SkVertices* v, const SkVertices::Bone bones[], int boneCount,
Ruiqi Maof5101492018-06-29 14:32:21 -04001160 SkBlendMode blendMode, const SkPaint& paint) {
Mike Reed2f6b5a42017-03-19 15:04:17 -04001161 draw(this, &SkDraw::drawVertices, v->mode(), v->vertexCount(), v->positions(), v->texCoords(),
Ruiqi Maof5101492018-06-29 14:32:21 -04001162 v->colors(), v->boneIndices(), v->boneWeights(), blendMode, v->indices(), v->indexCount(),
1163 paint, bones, boneCount);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001164}
1165
Mike Reeda1361362017-03-07 09:37:29 -05001166void SkXPSDevice::drawPaint(const SkPaint& origPaint) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001167 const SkRect r = SkRect::MakeSize(this->fCurrentCanvasSize);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001168
bungeman@google.comb29c8832011-10-10 13:19:10 +00001169 //If trying to paint with a stroke, ignore that and fill.
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001170 SkPaint* fillPaint = const_cast<SkPaint*>(&origPaint);
1171 SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
1172 if (paint->getStyle() != SkPaint::kFill_Style) {
1173 paint.writable()->setStyle(SkPaint::kFill_Style);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001174 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001175
Mike Reeda1361362017-03-07 09:37:29 -05001176 this->internalDrawRect(r, false, *fillPaint);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001177}
1178
Mike Reeda1361362017-03-07 09:37:29 -05001179void SkXPSDevice::drawRect(const SkRect& r,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001180 const SkPaint& paint) {
Mike Reeda1361362017-03-07 09:37:29 -05001181 this->internalDrawRect(r, true, paint);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001182}
1183
Mike Reeda1361362017-03-07 09:37:29 -05001184void SkXPSDevice::drawRRect(const SkRRect& rr,
scroggo@google.comcac8d012013-11-12 17:10:02 +00001185 const SkPaint& paint) {
1186 SkPath path;
1187 path.addRRect(rr);
Robert Phillips137ca522018-08-15 10:14:33 -04001188 this->drawPath(path, paint, true);
scroggo@google.comcac8d012013-11-12 17:10:02 +00001189}
1190
Mike Reeda1361362017-03-07 09:37:29 -05001191static SkIRect size(const SkBaseDevice& dev) { return {0, 0, dev.width(), dev.height()}; }
1192
1193void SkXPSDevice::internalDrawRect(const SkRect& r,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001194 bool transformRect,
1195 const SkPaint& paint) {
1196 //Exit early if there is nothing to draw.
Mike Reeda1361362017-03-07 09:37:29 -05001197 if (this->cs().isEmpty(size(*this)) ||
reed374772b2016-10-05 17:33:02 -07001198 (paint.getAlpha() == 0 && paint.isSrcOver())) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001199 return;
1200 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001201
bungeman@google.comb29c8832011-10-10 13:19:10 +00001202 //Path the rect if we can't optimize it.
Mike Reeda1361362017-03-07 09:37:29 -05001203 if (rect_must_be_pathed(paint, this->ctm())) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001204 SkPath tmp;
1205 tmp.addRect(r);
1206 tmp.setFillType(SkPath::kWinding_FillType);
Robert Phillips137ca522018-08-15 10:14:33 -04001207 this->drawPath(tmp, paint, true);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001208 return;
1209 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001210
bungeman@google.comb29c8832011-10-10 13:19:10 +00001211 //Create the shaded path.
1212 SkTScopedComPtr<IXpsOMPath> shadedPath;
1213 HRVM(this->fXpsFactory->CreatePath(&shadedPath),
1214 "Could not create shaded path for rect.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001215
bungeman@google.comb29c8832011-10-10 13:19:10 +00001216 //Create the shaded geometry.
1217 SkTScopedComPtr<IXpsOMGeometry> shadedGeometry;
1218 HRVM(this->fXpsFactory->CreateGeometry(&shadedGeometry),
1219 "Could not create shaded geometry for rect.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001220
bungeman@google.comb29c8832011-10-10 13:19:10 +00001221 //Add the geometry to the shaded path.
1222 HRVM(shadedPath->SetGeometryLocal(shadedGeometry.get()),
1223 "Could not set shaded geometry for rect.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001224
bungeman@google.comb29c8832011-10-10 13:19:10 +00001225 //Set the brushes.
1226 BOOL fill = FALSE;
1227 BOOL stroke = FALSE;
Mike Reeda1361362017-03-07 09:37:29 -05001228 HRV(this->shadePath(shadedPath.get(), paint, this->ctm(), &fill, &stroke));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001229
bungeman@google.comb29c8832011-10-10 13:19:10 +00001230 bool xpsTransformsPath = true;
1231 //Transform the geometry.
1232 if (transformRect && xpsTransformsPath) {
1233 SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform;
Mike Reeda1361362017-03-07 09:37:29 -05001234 HRV(this->createXpsTransform(this->ctm(), &xpsTransform));
bungeman@google.comb29c8832011-10-10 13:19:10 +00001235 if (xpsTransform.get()) {
1236 HRVM(shadedGeometry->SetTransformLocal(xpsTransform.get()),
1237 "Could not set transform for rect.");
1238 } else {
1239 xpsTransformsPath = false;
1240 }
1241 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001242
bungeman@google.comb29c8832011-10-10 13:19:10 +00001243 //Create the figure.
1244 SkTScopedComPtr<IXpsOMGeometryFigure> rectFigure;
1245 {
1246 SkPoint points[4] = {
1247 { r.fLeft, r.fTop },
1248 { r.fLeft, r.fBottom },
1249 { r.fRight, r.fBottom },
1250 { r.fRight, r.fTop },
1251 };
1252 if (!xpsTransformsPath && transformRect) {
Mike Reeda1361362017-03-07 09:37:29 -05001253 this->ctm().mapPoints(points, SK_ARRAY_COUNT(points));
bungeman@google.comb29c8832011-10-10 13:19:10 +00001254 }
1255 HRV(this->createXpsQuad(points, stroke, fill, &rectFigure));
1256 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001257
bungeman@google.comb29c8832011-10-10 13:19:10 +00001258 //Get the figures of the shaded geometry.
1259 SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures;
1260 HRVM(shadedGeometry->GetFigures(&shadedFigures),
1261 "Could not get shaded figures for rect.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001262
bungeman@google.comb29c8832011-10-10 13:19:10 +00001263 //Add the figure to the shaded geometry figures.
1264 HRVM(shadedFigures->Append(rectFigure.get()),
1265 "Could not add shaded figure for rect.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001266
Mike Reeda1361362017-03-07 09:37:29 -05001267 HRV(this->clip(shadedPath.get()));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001268
bungeman@google.comb29c8832011-10-10 13:19:10 +00001269 //Add the shaded path to the current visuals.
1270 SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals;
1271 HRVM(this->fCurrentXpsCanvas->GetVisuals(&currentVisuals),
1272 "Could not get current visuals for rect.");
1273 HRVM(currentVisuals->Append(shadedPath.get()),
1274 "Could not add rect to current visuals.");
1275}
1276
1277static HRESULT close_figure(const SkTDArray<XPS_SEGMENT_TYPE>& segmentTypes,
1278 const SkTDArray<BOOL>& segmentStrokes,
1279 const SkTDArray<FLOAT>& segmentData,
1280 BOOL stroke, BOOL fill,
1281 IXpsOMGeometryFigure* figure,
1282 IXpsOMGeometryFigureCollection* figures) {
1283 // Add the segment data to the figure.
1284 HRM(figure->SetSegments(segmentTypes.count(), segmentData.count(),
1285 segmentTypes.begin() , segmentData.begin(),
1286 segmentStrokes.begin()),
1287 "Could not set path segments.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001288
bungeman@google.comb29c8832011-10-10 13:19:10 +00001289 // Set the closed and filled properties of the figure.
1290 HRM(figure->SetIsClosed(stroke), "Could not set path closed.");
1291 HRM(figure->SetIsFilled(fill), "Could not set path fill.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001292
bungeman@google.comb29c8832011-10-10 13:19:10 +00001293 // Add the figure created above to this geometry.
1294 HRM(figures->Append(figure), "Could not add path to geometry.");
1295 return S_OK;
1296}
1297
1298HRESULT SkXPSDevice::addXpsPathGeometry(
1299 IXpsOMGeometryFigureCollection* xpsFigures,
1300 BOOL stroke, BOOL fill, const SkPath& path) {
1301 SkTDArray<XPS_SEGMENT_TYPE> segmentTypes;
1302 SkTDArray<BOOL> segmentStrokes;
1303 SkTDArray<FLOAT> segmentData;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001304
bungeman@google.comb29c8832011-10-10 13:19:10 +00001305 SkTScopedComPtr<IXpsOMGeometryFigure> xpsFigure;
1306 SkPath::Iter iter(path, true);
1307 SkPoint points[4];
1308 SkPath::Verb verb;
1309 while ((verb = iter.next(points)) != SkPath::kDone_Verb) {
1310 switch (verb) {
1311 case SkPath::kMove_Verb: {
bsalomon49f085d2014-09-05 13:34:00 -07001312 if (xpsFigure.get()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001313 HR(close_figure(segmentTypes, segmentStrokes, segmentData,
1314 stroke, fill,
1315 xpsFigure.get() , xpsFigures));
1316 xpsFigure.reset();
1317 segmentTypes.rewind();
1318 segmentStrokes.rewind();
1319 segmentData.rewind();
1320 }
1321 // Define the start point.
1322 XPS_POINT startPoint = xps_point(points[0]);
1323 // Create the figure.
1324 HRM(this->fXpsFactory->CreateGeometryFigure(&startPoint,
1325 &xpsFigure),
1326 "Could not create path geometry figure.");
1327 break;
1328 }
1329 case SkPath::kLine_Verb:
1330 if (iter.isCloseLine()) break; //ignore the line, auto-closed
Mike Reedb5475792018-08-08 16:17:42 -04001331 segmentTypes.push_back(XPS_SEGMENT_TYPE_LINE);
1332 segmentStrokes.push_back(stroke);
1333 segmentData.push_back(SkScalarToFLOAT(points[1].fX));
1334 segmentData.push_back(SkScalarToFLOAT(points[1].fY));
bungeman@google.comb29c8832011-10-10 13:19:10 +00001335 break;
1336 case SkPath::kQuad_Verb:
Mike Reedb5475792018-08-08 16:17:42 -04001337 segmentTypes.push_back(XPS_SEGMENT_TYPE_QUADRATIC_BEZIER);
1338 segmentStrokes.push_back(stroke);
1339 segmentData.push_back(SkScalarToFLOAT(points[1].fX));
1340 segmentData.push_back(SkScalarToFLOAT(points[1].fY));
1341 segmentData.push_back(SkScalarToFLOAT(points[2].fX));
1342 segmentData.push_back(SkScalarToFLOAT(points[2].fY));
bungeman@google.comb29c8832011-10-10 13:19:10 +00001343 break;
1344 case SkPath::kCubic_Verb:
Mike Reedb5475792018-08-08 16:17:42 -04001345 segmentTypes.push_back(XPS_SEGMENT_TYPE_BEZIER);
1346 segmentStrokes.push_back(stroke);
1347 segmentData.push_back(SkScalarToFLOAT(points[1].fX));
1348 segmentData.push_back(SkScalarToFLOAT(points[1].fY));
1349 segmentData.push_back(SkScalarToFLOAT(points[2].fX));
1350 segmentData.push_back(SkScalarToFLOAT(points[2].fY));
1351 segmentData.push_back(SkScalarToFLOAT(points[3].fX));
1352 segmentData.push_back(SkScalarToFLOAT(points[3].fY));
bungeman@google.comb29c8832011-10-10 13:19:10 +00001353 break;
halcanary47ef4d52015-03-03 09:13:09 -08001354 case SkPath::kConic_Verb: {
1355 const SkScalar tol = SK_Scalar1 / 4;
1356 SkAutoConicToQuads converter;
1357 const SkPoint* quads =
1358 converter.computeQuads(points, iter.conicWeight(), tol);
1359 for (int i = 0; i < converter.countQuads(); ++i) {
Mike Reedb5475792018-08-08 16:17:42 -04001360 segmentTypes.push_back(XPS_SEGMENT_TYPE_QUADRATIC_BEZIER);
1361 segmentStrokes.push_back(stroke);
1362 segmentData.push_back(SkScalarToFLOAT(quads[2 * i + 1].fX));
1363 segmentData.push_back(SkScalarToFLOAT(quads[2 * i + 1].fY));
1364 segmentData.push_back(SkScalarToFLOAT(quads[2 * i + 2].fX));
1365 segmentData.push_back(SkScalarToFLOAT(quads[2 * i + 2].fY));
halcanary47ef4d52015-03-03 09:13:09 -08001366 }
1367 break;
1368 }
bungeman@google.comb29c8832011-10-10 13:19:10 +00001369 case SkPath::kClose_Verb:
1370 // we ignore these, and just get the whole segment from
1371 // the corresponding line/quad/cubic verbs
1372 break;
1373 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00001374 SkDEBUGFAIL("unexpected verb");
bungeman@google.comb29c8832011-10-10 13:19:10 +00001375 break;
1376 }
1377 }
bsalomon49f085d2014-09-05 13:34:00 -07001378 if (xpsFigure.get()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001379 HR(close_figure(segmentTypes, segmentStrokes, segmentData,
1380 stroke, fill,
1381 xpsFigure.get(), xpsFigures));
1382 }
1383 return S_OK;
1384}
1385
bungeman@google.comb29c8832011-10-10 13:19:10 +00001386void SkXPSDevice::convertToPpm(const SkMaskFilter* filter,
1387 SkMatrix* matrix,
1388 SkVector* ppuScale,
1389 const SkIRect& clip, SkIRect* clipIRect) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001390 //This action is in unit space, but the ppm is specified in physical space.
reed80ea19c2015-05-12 10:37:34 -07001391 ppuScale->set(fCurrentPixelsPerMeter.fX / fCurrentUnitsPerMeter.fX,
1392 fCurrentPixelsPerMeter.fY / fCurrentUnitsPerMeter.fY);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001393
bungeman@google.comb29c8832011-10-10 13:19:10 +00001394 matrix->postScale(ppuScale->fX, ppuScale->fY);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001395
bungeman@google.comb29c8832011-10-10 13:19:10 +00001396 const SkIRect& irect = clip;
Mike Reed8be952a2017-02-13 20:44:33 -05001397 SkRect clipRect = SkRect::MakeLTRB(SkIntToScalar(irect.fLeft) * ppuScale->fX,
1398 SkIntToScalar(irect.fTop) * ppuScale->fY,
1399 SkIntToScalar(irect.fRight) * ppuScale->fX,
1400 SkIntToScalar(irect.fBottom) * ppuScale->fY);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001401 clipRect.roundOut(clipIRect);
1402}
1403
Mike Reeda1361362017-03-07 09:37:29 -05001404HRESULT SkXPSDevice::applyMask(const SkMask& mask,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001405 const SkVector& ppuScale,
1406 IXpsOMPath* shadedPath) {
1407 //Get the geometry object.
1408 SkTScopedComPtr<IXpsOMGeometry> shadedGeometry;
1409 HRM(shadedPath->GetGeometry(&shadedGeometry),
1410 "Could not get mask shaded geometry.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001411
bungeman@google.comb29c8832011-10-10 13:19:10 +00001412 //Get the figures from the geometry.
1413 SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures;
1414 HRM(shadedGeometry->GetFigures(&shadedFigures),
1415 "Could not get mask shaded figures.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001416
bungeman@google.comb29c8832011-10-10 13:19:10 +00001417 SkMatrix m;
1418 m.reset();
1419 m.setTranslate(SkIntToScalar(mask.fBounds.fLeft),
1420 SkIntToScalar(mask.fBounds.fTop));
1421 m.postScale(SkScalarInvert(ppuScale.fX), SkScalarInvert(ppuScale.fY));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001422
bungeman@google.comb29c8832011-10-10 13:19:10 +00001423 SkShader::TileMode xy[2];
1424 xy[0] = (SkShader::TileMode)3;
1425 xy[1] = (SkShader::TileMode)3;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001426
bungeman@google.comb29c8832011-10-10 13:19:10 +00001427 SkBitmap bm;
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +00001428 bm.installMaskPixels(mask);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001429
bungeman@google.comb29c8832011-10-10 13:19:10 +00001430 SkTScopedComPtr<IXpsOMTileBrush> maskBrush;
1431 HR(this->createXpsImageBrush(bm, m, xy, 0xFF, &maskBrush));
1432 HRM(shadedPath->SetOpacityMaskBrushLocal(maskBrush.get()),
1433 "Could not set mask.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001434
bungeman@google.comb29c8832011-10-10 13:19:10 +00001435 const SkRect universeRect = SkRect::MakeLTRB(0, 0,
1436 this->fCurrentCanvasSize.fWidth, this->fCurrentCanvasSize.fHeight);
1437 SkTScopedComPtr<IXpsOMGeometryFigure> shadedFigure;
1438 HRM(this->createXpsRect(universeRect, FALSE, TRUE, &shadedFigure),
1439 "Could not create mask shaded figure.");
1440 HRM(shadedFigures->Append(shadedFigure.get()),
1441 "Could not add mask shaded figure.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001442
Mike Reeda1361362017-03-07 09:37:29 -05001443 HR(this->clip(shadedPath));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001444
bungeman@google.comb29c8832011-10-10 13:19:10 +00001445 //Add the path to the active visual collection.
1446 SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals;
1447 HRM(this->fCurrentXpsCanvas->GetVisuals(&currentVisuals),
1448 "Could not get mask current visuals.");
1449 HRM(currentVisuals->Append(shadedPath),
1450 "Could not add masked shaded path to current visuals.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001451
bungeman@google.comb29c8832011-10-10 13:19:10 +00001452 return S_OK;
1453}
1454
1455HRESULT SkXPSDevice::shadePath(IXpsOMPath* shadedPath,
1456 const SkPaint& shaderPaint,
1457 const SkMatrix& matrix,
1458 BOOL* fill, BOOL* stroke) {
1459 *fill = FALSE;
1460 *stroke = FALSE;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001461
bungeman@google.comb29c8832011-10-10 13:19:10 +00001462 const SkPaint::Style style = shaderPaint.getStyle();
1463 const bool hasFill = SkPaint::kFill_Style == style
1464 || SkPaint::kStrokeAndFill_Style == style;
1465 const bool hasStroke = SkPaint::kStroke_Style == style
1466 || SkPaint::kStrokeAndFill_Style == style;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001467
bungeman@google.comb29c8832011-10-10 13:19:10 +00001468 //TODO(bungeman): use dictionaries and lookups.
1469 if (hasFill) {
1470 *fill = TRUE;
1471 SkTScopedComPtr<IXpsOMBrush> fillBrush;
1472 HR(this->createXpsBrush(shaderPaint, &fillBrush, &matrix));
1473 HRM(shadedPath->SetFillBrushLocal(fillBrush.get()),
1474 "Could not set fill for shaded path.");
1475 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001476
bungeman@google.comb29c8832011-10-10 13:19:10 +00001477 if (hasStroke) {
1478 *stroke = TRUE;
1479 SkTScopedComPtr<IXpsOMBrush> strokeBrush;
1480 HR(this->createXpsBrush(shaderPaint, &strokeBrush, &matrix));
1481 HRM(shadedPath->SetStrokeBrushLocal(strokeBrush.get()),
1482 "Could not set stroke brush for shaded path.");
1483 HRM(shadedPath->SetStrokeThickness(
1484 SkScalarToFLOAT(shaderPaint.getStrokeWidth())),
1485 "Could not set shaded path stroke thickness.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001486
bungeman@google.comb29c8832011-10-10 13:19:10 +00001487 if (0 == shaderPaint.getStrokeWidth()) {
1488 //XPS hair width is a hack. (XPS Spec 11.6.12).
1489 SkTScopedComPtr<IXpsOMDashCollection> dashes;
1490 HRM(shadedPath->GetStrokeDashes(&dashes),
1491 "Could not set dashes for shaded path.");
1492 XPS_DASH dash;
1493 dash.length = 1.0;
1494 dash.gap = 0.0;
1495 HRM(dashes->Append(&dash), "Could not add dashes to shaded path.");
1496 HRM(shadedPath->SetStrokeDashOffset(-2.0),
1497 "Could not set dash offset for shaded path.");
1498 }
1499 }
1500 return S_OK;
1501}
1502
Mike Reeda1361362017-03-07 09:37:29 -05001503void SkXPSDevice::drawPath(const SkPath& platonicPath,
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001504 const SkPaint& origPaint,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001505 bool pathIsMutable) {
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001506 SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
1507
bungeman@google.comb29c8832011-10-10 13:19:10 +00001508 // nothing to draw
Mike Reeda1361362017-03-07 09:37:29 -05001509 if (this->cs().isEmpty(size(*this)) ||
reed374772b2016-10-05 17:33:02 -07001510 (paint->getAlpha() == 0 && paint->isSrcOver())) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001511 return;
1512 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001513
bungeman@google.comb29c8832011-10-10 13:19:10 +00001514 SkPath modifiedPath;
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001515 const bool paintHasPathEffect = paint->getPathEffect()
1516 || paint->getStyle() != SkPaint::kFill_Style;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001517
bungeman@google.comb29c8832011-10-10 13:19:10 +00001518 //Apply pre-path matrix [Platonic-path -> Skeletal-path].
Mike Reeda1361362017-03-07 09:37:29 -05001519 SkMatrix matrix = this->ctm();
bungeman@google.comb29c8832011-10-10 13:19:10 +00001520 SkPath* skeletalPath = const_cast<SkPath*>(&platonicPath);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001521
bungeman@google.comb29c8832011-10-10 13:19:10 +00001522 //Apply path effect [Skeletal-path -> Fillable-path].
1523 SkPath* fillablePath = skeletalPath;
1524 if (paintHasPathEffect) {
1525 if (!pathIsMutable) {
1526 fillablePath = &modifiedPath;
1527 pathIsMutable = true;
1528 }
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001529 bool fill = paint->getFillPath(*skeletalPath, fillablePath);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001530
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001531 SkPaint* writablePaint = paint.writable();
halcanary96fcdcc2015-08-27 07:41:13 -07001532 writablePaint->setPathEffect(nullptr);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001533 if (fill) {
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001534 writablePaint->setStyle(SkPaint::kFill_Style);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001535 } else {
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001536 writablePaint->setStyle(SkPaint::kStroke_Style);
1537 writablePaint->setStrokeWidth(0);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001538 }
1539 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001540
bungeman@google.comb29c8832011-10-10 13:19:10 +00001541 //Create the shaded path. This will be the path which is painted.
1542 SkTScopedComPtr<IXpsOMPath> shadedPath;
1543 HRVM(this->fXpsFactory->CreatePath(&shadedPath),
1544 "Could not create shaded path for path.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001545
bungeman@google.comb29c8832011-10-10 13:19:10 +00001546 //Create the geometry for the shaded path.
1547 SkTScopedComPtr<IXpsOMGeometry> shadedGeometry;
1548 HRVM(this->fXpsFactory->CreateGeometry(&shadedGeometry),
1549 "Could not create shaded geometry for path.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001550
bungeman@google.comb29c8832011-10-10 13:19:10 +00001551 //Add the geometry to the shaded path.
1552 HRVM(shadedPath->SetGeometryLocal(shadedGeometry.get()),
1553 "Could not add the shaded geometry to shaded path.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001554
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001555 SkMaskFilter* filter = paint->getMaskFilter();
bungeman@google.comd998cbd2012-04-05 18:57:53 +00001556
1557 //Determine if we will draw or shade and mask.
Mike Reed8ad91a92018-01-19 19:09:32 -05001558 if (filter) {
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001559 if (paint->getStyle() != SkPaint::kFill_Style) {
1560 paint.writable()->setStyle(SkPaint::kFill_Style);
bungeman@google.comd998cbd2012-04-05 18:57:53 +00001561 }
1562 }
1563
bungeman@google.comb29c8832011-10-10 13:19:10 +00001564 //Set the brushes.
1565 BOOL fill;
1566 BOOL stroke;
1567 HRV(this->shadePath(shadedPath.get(),
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001568 *paint,
Mike Reeda1361362017-03-07 09:37:29 -05001569 this->ctm(),
bungeman@google.comb29c8832011-10-10 13:19:10 +00001570 &fill,
1571 &stroke));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001572
bungeman@google.comb29c8832011-10-10 13:19:10 +00001573 //Mask filter
1574 if (filter) {
1575 SkIRect clipIRect;
1576 SkVector ppuScale;
1577 this->convertToPpm(filter,
1578 &matrix,
1579 &ppuScale,
Mike Reeda1361362017-03-07 09:37:29 -05001580 this->cs().bounds(size(*this)).roundOut(),
bungeman@google.comb29c8832011-10-10 13:19:10 +00001581 &clipIRect);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001582
bungeman@google.comb29c8832011-10-10 13:19:10 +00001583 //[Fillable-path -> Pixel-path]
1584 SkPath* pixelPath = pathIsMutable ? fillablePath : &modifiedPath;
1585 fillablePath->transform(matrix, pixelPath);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001586
halcanary96fcdcc2015-08-27 07:41:13 -07001587 SkMask* mask = nullptr;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001588
bsalomon055e1922016-05-06 07:22:58 -07001589 SkASSERT(SkPaint::kFill_Style == paint->getStyle() ||
1590 (SkPaint::kStroke_Style == paint->getStyle() && 0 == paint->getStrokeWidth()));
1591 SkStrokeRec::InitStyle style = (SkPaint::kFill_Style == paint->getStyle())
1592 ? SkStrokeRec::kFill_InitStyle
1593 : SkStrokeRec::kHairline_InitStyle;
bungeman@google.comb29c8832011-10-10 13:19:10 +00001594 //[Pixel-path -> Mask]
1595 SkMask rasteredMask;
1596 if (SkDraw::DrawToMask(
1597 *pixelPath,
1598 &clipIRect,
1599 filter, //just to compute how much to draw.
1600 &matrix,
1601 &rasteredMask,
junov@chromium.org2ac4ef52012-04-04 15:16:51 +00001602 SkMask::kComputeBoundsAndRenderImage_CreateMode,
bsalomon055e1922016-05-06 07:22:58 -07001603 style)) {
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001604
bungeman@google.comb29c8832011-10-10 13:19:10 +00001605 SkAutoMaskFreeImage rasteredAmi(rasteredMask.fImage);
1606 mask = &rasteredMask;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001607
bungeman@google.comb29c8832011-10-10 13:19:10 +00001608 //[Mask -> Mask]
1609 SkMask filteredMask;
Mike Reed80747ef2018-01-23 15:29:32 -05001610 if (as_MFB(filter)->filterMask(&filteredMask, rasteredMask, matrix, nullptr)) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001611 mask = &filteredMask;
bungeman@google.comb29c8832011-10-10 13:19:10 +00001612 }
1613 SkAutoMaskFreeImage filteredAmi(filteredMask.fImage);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001614
bungeman@google.comb29c8832011-10-10 13:19:10 +00001615 //Draw mask.
Mike Reeda1361362017-03-07 09:37:29 -05001616 HRV(this->applyMask(*mask, ppuScale, shadedPath.get()));
bungeman@google.comb29c8832011-10-10 13:19:10 +00001617 }
1618 return;
1619 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001620
bungeman@google.comb29c8832011-10-10 13:19:10 +00001621 //Get the figures from the shaded geometry.
1622 SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures;
1623 HRVM(shadedGeometry->GetFigures(&shadedFigures),
1624 "Could not get shaded figures for shaded path.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001625
bungeman@google.comb29c8832011-10-10 13:19:10 +00001626 bool xpsTransformsPath = true;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001627
bungeman@google.comb29c8832011-10-10 13:19:10 +00001628 //Set the fill rule.
bungeman76db31a2014-08-25 07:31:53 -07001629 SkPath* xpsCompatiblePath = fillablePath;
bungeman@google.comb29c8832011-10-10 13:19:10 +00001630 XPS_FILL_RULE xpsFillRule;
bungeman76db31a2014-08-25 07:31:53 -07001631 switch (fillablePath->getFillType()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001632 case SkPath::kWinding_FillType:
1633 xpsFillRule = XPS_FILL_RULE_NONZERO;
1634 break;
1635 case SkPath::kEvenOdd_FillType:
1636 xpsFillRule = XPS_FILL_RULE_EVENODD;
1637 break;
1638 case SkPath::kInverseWinding_FillType: {
bungeman76db31a2014-08-25 07:31:53 -07001639 //[Fillable-path (inverse winding) -> XPS-path (inverse even odd)]
1640 if (!pathIsMutable) {
1641 xpsCompatiblePath = &modifiedPath;
1642 pathIsMutable = true;
1643 }
1644 if (!Simplify(*fillablePath, xpsCompatiblePath)) {
Hal Canary2b0e6cd2018-07-09 12:43:39 -04001645 SkDEBUGF("Could not simplify inverse winding path.");
bungeman76db31a2014-08-25 07:31:53 -07001646 return;
1647 }
bungeman@google.comb29c8832011-10-10 13:19:10 +00001648 }
bungeman76db31a2014-08-25 07:31:53 -07001649 // The xpsCompatiblePath is noW inverse even odd, so fall through.
bungeman@google.comb29c8832011-10-10 13:19:10 +00001650 case SkPath::kInverseEvenOdd_FillType: {
1651 const SkRect universe = SkRect::MakeLTRB(
1652 0, 0,
1653 this->fCurrentCanvasSize.fWidth,
1654 this->fCurrentCanvasSize.fHeight);
1655 SkTScopedComPtr<IXpsOMGeometryFigure> addOneFigure;
1656 HRV(this->createXpsRect(universe, FALSE, TRUE, &addOneFigure));
1657 HRVM(shadedFigures->Append(addOneFigure.get()),
1658 "Could not add even-odd flip figure to shaded path.");
1659 xpsTransformsPath = false;
1660 xpsFillRule = XPS_FILL_RULE_EVENODD;
1661 break;
1662 }
1663 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00001664 SkDEBUGFAIL("Unknown SkPath::FillType.");
bungeman@google.comb29c8832011-10-10 13:19:10 +00001665 }
1666 HRVM(shadedGeometry->SetFillRule(xpsFillRule),
1667 "Could not set fill rule for shaded path.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001668
bungeman@google.comb29c8832011-10-10 13:19:10 +00001669 //Create the XPS transform, if possible.
1670 if (xpsTransformsPath) {
1671 SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform;
1672 HRV(this->createXpsTransform(matrix, &xpsTransform));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001673
bungeman@google.comb29c8832011-10-10 13:19:10 +00001674 if (xpsTransform.get()) {
1675 HRVM(shadedGeometry->SetTransformLocal(xpsTransform.get()),
1676 "Could not set transform on shaded path.");
1677 } else {
1678 xpsTransformsPath = false;
1679 }
1680 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001681
bungeman76db31a2014-08-25 07:31:53 -07001682 SkPath* devicePath = xpsCompatiblePath;
bungeman@google.comb29c8832011-10-10 13:19:10 +00001683 if (!xpsTransformsPath) {
1684 //[Fillable-path -> Device-path]
bungeman76db31a2014-08-25 07:31:53 -07001685 devicePath = pathIsMutable ? xpsCompatiblePath : &modifiedPath;
1686 xpsCompatiblePath->transform(matrix, devicePath);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001687 }
1688 HRV(this->addXpsPathGeometry(shadedFigures.get(),
1689 stroke, fill, *devicePath));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001690
Mike Reeda1361362017-03-07 09:37:29 -05001691 HRV(this->clip(shadedPath.get()));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001692
bungeman@google.comb29c8832011-10-10 13:19:10 +00001693 //Add the path to the active visual collection.
1694 SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals;
1695 HRVM(this->fCurrentXpsCanvas->GetVisuals(&currentVisuals),
1696 "Could not get current visuals for shaded path.");
1697 HRVM(currentVisuals->Append(shadedPath.get()),
1698 "Could not add shaded path to current visuals.");
1699}
1700
Mike Reeda1361362017-03-07 09:37:29 -05001701HRESULT SkXPSDevice::clip(IXpsOMVisual* xpsVisual) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001702 SkPath clipPath;
Mike Reeda1361362017-03-07 09:37:29 -05001703 // clipPath.addRect(this->cs().bounds(size(*this)));
1704 (void)this->cs().asPath(&clipPath);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001705 return this->clipToPath(xpsVisual, clipPath, XPS_FILL_RULE_EVENODD);
1706}
1707HRESULT SkXPSDevice::clipToPath(IXpsOMVisual* xpsVisual,
1708 const SkPath& clipPath,
1709 XPS_FILL_RULE fillRule) {
1710 //Create the geometry.
1711 SkTScopedComPtr<IXpsOMGeometry> clipGeometry;
1712 HRM(this->fXpsFactory->CreateGeometry(&clipGeometry),
1713 "Could not create clip geometry.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001714
bungeman@google.comb29c8832011-10-10 13:19:10 +00001715 //Get the figure collection of the geometry.
1716 SkTScopedComPtr<IXpsOMGeometryFigureCollection> clipFigures;
1717 HRM(clipGeometry->GetFigures(&clipFigures),
1718 "Could not get the clip figures.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001719
bungeman@google.comb29c8832011-10-10 13:19:10 +00001720 //Create the figures into the geometry.
1721 HR(this->addXpsPathGeometry(
1722 clipFigures.get(),
1723 FALSE, TRUE, clipPath));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001724
bungeman@google.comb29c8832011-10-10 13:19:10 +00001725 HRM(clipGeometry->SetFillRule(fillRule),
1726 "Could not set fill rule.");
1727 HRM(xpsVisual->SetClipGeometryLocal(clipGeometry.get()),
1728 "Could not set clip geometry.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001729
bungeman@google.comb29c8832011-10-10 13:19:10 +00001730 return S_OK;
1731}
1732
Mike Reeda1361362017-03-07 09:37:29 -05001733void SkXPSDevice::drawBitmap(const SkBitmap& bitmap,
Hal Canaryb9642382017-06-27 09:58:56 -04001734 SkScalar x,
1735 SkScalar y,
1736 const SkPaint& paint) {
Mike Reeda1361362017-03-07 09:37:29 -05001737 if (this->cs().isEmpty(size(*this))) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001738 return;
1739 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001740
bungeman@google.comb29c8832011-10-10 13:19:10 +00001741 SkIRect srcRect;
robertphillips@google.com9bf380c2013-07-25 12:10:42 +00001742 srcRect.set(0, 0, bitmap.width(), bitmap.height());
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001743
bungeman@google.comb29c8832011-10-10 13:19:10 +00001744 //Create the new shaded path.
1745 SkTScopedComPtr<IXpsOMPath> shadedPath;
1746 HRVM(this->fXpsFactory->CreatePath(&shadedPath),
1747 "Could not create path for bitmap.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001748
bungeman@google.comb29c8832011-10-10 13:19:10 +00001749 //Create the shaded geometry.
1750 SkTScopedComPtr<IXpsOMGeometry> shadedGeometry;
1751 HRVM(this->fXpsFactory->CreateGeometry(&shadedGeometry),
1752 "Could not create geometry for bitmap.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001753
bungeman@google.comb29c8832011-10-10 13:19:10 +00001754 //Add the shaded geometry to the shaded path.
1755 HRVM(shadedPath->SetGeometryLocal(shadedGeometry.get()),
1756 "Could not set the geometry for bitmap.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001757
bungeman@google.comb29c8832011-10-10 13:19:10 +00001758 //Get the shaded figures from the shaded geometry.
1759 SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures;
1760 HRVM(shadedGeometry->GetFigures(&shadedFigures),
1761 "Could not get the figures for bitmap.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001762
Hal Canaryb9642382017-06-27 09:58:56 -04001763 SkMatrix transform = SkMatrix::MakeTrans(x, y);
Mike Reeda1361362017-03-07 09:37:29 -05001764 transform.postConcat(this->ctm());
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001765
bungeman@google.comb29c8832011-10-10 13:19:10 +00001766 SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform;
1767 HRV(this->createXpsTransform(transform, &xpsTransform));
1768 if (xpsTransform.get()) {
1769 HRVM(shadedGeometry->SetTransformLocal(xpsTransform.get()),
1770 "Could not set transform for bitmap.");
1771 } else {
1772 //TODO: perspective that bitmap!
1773 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001774
bungeman@google.comb29c8832011-10-10 13:19:10 +00001775 SkTScopedComPtr<IXpsOMGeometryFigure> rectFigure;
bsalomon49f085d2014-09-05 13:34:00 -07001776 if (xpsTransform.get()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001777 const SkShader::TileMode xy[2] = {
1778 SkShader::kClamp_TileMode,
1779 SkShader::kClamp_TileMode,
1780 };
1781 SkTScopedComPtr<IXpsOMTileBrush> xpsImageBrush;
robertphillips@google.com9bf380c2013-07-25 12:10:42 +00001782 HRV(this->createXpsImageBrush(bitmap,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001783 transform,
1784 xy,
1785 paint.getAlpha(),
1786 &xpsImageBrush));
1787 HRVM(shadedPath->SetFillBrushLocal(xpsImageBrush.get()),
1788 "Could not set bitmap brush.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001789
bungeman@google.comb29c8832011-10-10 13:19:10 +00001790 const SkRect bitmapRect = SkRect::MakeLTRB(0, 0,
1791 SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height()));
1792 HRV(this->createXpsRect(bitmapRect, FALSE, TRUE, &rectFigure));
1793 }
1794 HRVM(shadedFigures->Append(rectFigure.get()),
1795 "Could not add bitmap figure.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001796
bungeman@google.comb29c8832011-10-10 13:19:10 +00001797 //Get the current visual collection and add the shaded path to it.
1798 SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals;
1799 HRVM(this->fCurrentXpsCanvas->GetVisuals(&currentVisuals),
1800 "Could not get current visuals for bitmap");
1801 HRVM(currentVisuals->Append(shadedPath.get()),
1802 "Could not add bitmap to current visuals.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001803
Mike Reeda1361362017-03-07 09:37:29 -05001804 HRV(this->clip(shadedPath.get()));
bungeman@google.comb29c8832011-10-10 13:19:10 +00001805}
1806
Mike Reeda1361362017-03-07 09:37:29 -05001807void SkXPSDevice::drawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint& paint) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001808 //TODO: override this for XPS
Hal Canary2b0e6cd2018-07-09 12:43:39 -04001809 SkDEBUGF("XPS drawSprite not yet implemented.");
bungeman@google.comb29c8832011-10-10 13:19:10 +00001810}
1811
1812HRESULT SkXPSDevice::CreateTypefaceUse(const SkPaint& paint,
1813 TypefaceUse** typefaceUse) {
reed@google.com398de9a2013-03-21 21:43:51 +00001814 SkAutoResolveDefaultTypeface typeface(paint.getTypeface());
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001815
bungeman@google.comb29c8832011-10-10 13:19:10 +00001816 //Check cache.
reed@google.com398de9a2013-03-21 21:43:51 +00001817 const SkFontID typefaceID = typeface->uniqueID();
bungeman@google.comb29c8832011-10-10 13:19:10 +00001818 if (!this->fTypefaces.empty()) {
1819 TypefaceUse* current = &this->fTypefaces.front();
1820 const TypefaceUse* last = &this->fTypefaces.back();
1821 for (; current <= last; ++current) {
1822 if (current->typefaceId == typefaceID) {
1823 *typefaceUse = current;
1824 return S_OK;
1825 }
1826 }
1827 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001828
bungeman@google.comb29c8832011-10-10 13:19:10 +00001829 //TODO: create glyph only fonts
1830 //and let the host deal with what kind of font we're looking at.
1831 XPS_FONT_EMBEDDING embedding = XPS_FONT_EMBEDDING_RESTRICTED;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001832
bungeman@google.comb29c8832011-10-10 13:19:10 +00001833 SkTScopedComPtr<IStream> fontStream;
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00001834 int ttcIndex;
1835 SkStream* fontData = typeface->openStream(&ttcIndex);
bungeman@google.com635091f2013-10-01 15:03:18 +00001836 //TODO: cannot handle FON fonts.
bungeman@google.com8cddc8d2012-01-03 22:36:33 +00001837 HRM(SkIStream::CreateFromSkStream(fontData, true, &fontStream),
bungeman@google.comb29c8832011-10-10 13:19:10 +00001838 "Could not create font stream.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001839
bungeman@google.comb29c8832011-10-10 13:19:10 +00001840 const size_t size =
1841 SK_ARRAY_COUNT(L"/Resources/Fonts/" L_GUID_ID L".odttf");
1842 wchar_t buffer[size];
1843 wchar_t id[GUID_ID_LEN];
Ben Wagnerda5a1b82014-08-22 15:07:06 -04001844 HR(this->createId(id, GUID_ID_LEN));
bungeman@google.comb29c8832011-10-10 13:19:10 +00001845 swprintf_s(buffer, size, L"/Resources/Fonts/%s.odttf", id);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001846
bungeman@google.comb29c8832011-10-10 13:19:10 +00001847 SkTScopedComPtr<IOpcPartUri> partUri;
1848 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri),
1849 "Could not create font resource part uri.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001850
bungeman@google.comb29c8832011-10-10 13:19:10 +00001851 SkTScopedComPtr<IXpsOMFontResource> xpsFontResource;
1852 HRM(this->fXpsFactory->CreateFontResource(fontStream.get(),
1853 embedding,
1854 partUri.get(),
1855 FALSE,
1856 &xpsFontResource),
1857 "Could not create font resource.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001858
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00001859 //TODO: change openStream to return -1 for non-ttc, get rid of this.
1860 uint8_t* data = (uint8_t*)fontData->getMemoryBase();
1861 bool isTTC = (data &&
1862 fontData->getLength() >= sizeof(SkTTCFHeader) &&
1863 ((SkTTCFHeader*)data)->ttcTag == SkTTCFHeader::TAG);
1864
bungeman@google.comb29c8832011-10-10 13:19:10 +00001865 TypefaceUse& newTypefaceUse = this->fTypefaces.push_back();
1866 newTypefaceUse.typefaceId = typefaceID;
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00001867 newTypefaceUse.ttcIndex = isTTC ? ttcIndex : -1;
bungeman@google.comb29c8832011-10-10 13:19:10 +00001868 newTypefaceUse.fontData = fontData;
1869 newTypefaceUse.xpsFont = xpsFontResource.release();
Herb Derbyf9e12df2018-03-26 15:42:44 -04001870 auto glyphCache =
Herb Derbyfa996902018-04-18 11:36:12 -04001871 SkStrikeCache::FindOrCreateStrikeExclusive(
Herb Derbyf9e12df2018-03-26 15:42:44 -04001872 paint, &this->surfaceProps(),
1873 SkScalerContextFlags::kNone, nullptr);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001874 unsigned int glyphCount = glyphCache->getGlyphCount();
1875 newTypefaceUse.glyphsUsed = new SkBitSet(glyphCount);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001876
bungeman@google.comb29c8832011-10-10 13:19:10 +00001877 *typefaceUse = &newTypefaceUse;
1878 return S_OK;
1879}
1880
Mike Reeda1361362017-03-07 09:37:29 -05001881HRESULT SkXPSDevice::AddGlyphs(IXpsOMObjectFactory* xpsFactory,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001882 IXpsOMCanvas* canvas,
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00001883 TypefaceUse* font,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001884 LPCWSTR text,
1885 XPS_GLYPH_INDEX* xpsGlyphs,
1886 UINT32 xpsGlyphsLen,
1887 XPS_POINT *origin,
1888 FLOAT fontSize,
1889 XPS_STYLE_SIMULATION sims,
1890 const SkMatrix& transform,
1891 const SkPaint& paint) {
1892 SkTScopedComPtr<IXpsOMGlyphs> glyphs;
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00001893 HRM(xpsFactory->CreateGlyphs(font->xpsFont, &glyphs), "Could not create glyphs.");
1894 HRM(glyphs->SetFontFaceIndex(font->ttcIndex), "Could not set glyph font face index.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001895
bungeman@google.comb29c8832011-10-10 13:19:10 +00001896 //XPS uses affine transformations for everything...
1897 //...except positioning text.
1898 bool useCanvasForClip;
1899 if ((transform.getType() & ~SkMatrix::kTranslate_Mask) == 0) {
1900 origin->x += SkScalarToFLOAT(transform.getTranslateX());
1901 origin->y += SkScalarToFLOAT(transform.getTranslateY());
1902 useCanvasForClip = false;
1903 } else {
1904 SkTScopedComPtr<IXpsOMMatrixTransform> xpsMatrixToUse;
1905 HR(this->createXpsTransform(transform, &xpsMatrixToUse));
1906 if (xpsMatrixToUse.get()) {
1907 HRM(glyphs->SetTransformLocal(xpsMatrixToUse.get()),
1908 "Could not set transform matrix.");
1909 useCanvasForClip = true;
1910 } else {
mtklein@google.com330313a2013-08-22 15:37:26 +00001911 SkDEBUGFAIL("Attempt to add glyphs in perspective.");
bungeman@google.comb29c8832011-10-10 13:19:10 +00001912 useCanvasForClip = false;
1913 }
1914 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001915
bungeman@google.comb29c8832011-10-10 13:19:10 +00001916 SkTScopedComPtr<IXpsOMGlyphsEditor> glyphsEditor;
1917 HRM(glyphs->GetGlyphsEditor(&glyphsEditor), "Could not get glyph editor.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001918
bsalomon49f085d2014-09-05 13:34:00 -07001919 if (text) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001920 HRM(glyphsEditor->SetUnicodeString(text),
1921 "Could not set unicode string.");
1922 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001923
bsalomon49f085d2014-09-05 13:34:00 -07001924 if (xpsGlyphs) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001925 HRM(glyphsEditor->SetGlyphIndices(xpsGlyphsLen, xpsGlyphs),
1926 "Could not set glyphs.");
1927 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001928
bungeman@google.comb29c8832011-10-10 13:19:10 +00001929 HRM(glyphsEditor->ApplyEdits(), "Could not apply glyph edits.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001930
bungeman@google.comb29c8832011-10-10 13:19:10 +00001931 SkTScopedComPtr<IXpsOMBrush> xpsFillBrush;
1932 HR(this->createXpsBrush(
1933 paint,
1934 &xpsFillBrush,
halcanary96fcdcc2015-08-27 07:41:13 -07001935 useCanvasForClip ? nullptr : &transform));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001936
bungeman@google.comb29c8832011-10-10 13:19:10 +00001937 HRM(glyphs->SetFillBrushLocal(xpsFillBrush.get()),
1938 "Could not set fill brush.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001939
bungeman@google.comb29c8832011-10-10 13:19:10 +00001940 HRM(glyphs->SetOrigin(origin), "Could not set glyph origin.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001941
bungeman@google.comb29c8832011-10-10 13:19:10 +00001942 HRM(glyphs->SetFontRenderingEmSize(fontSize),
1943 "Could not set font size.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001944
bungeman@google.comb29c8832011-10-10 13:19:10 +00001945 HRM(glyphs->SetStyleSimulations(sims),
1946 "Could not set style simulations.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001947
bungeman@google.comb29c8832011-10-10 13:19:10 +00001948 SkTScopedComPtr<IXpsOMVisualCollection> visuals;
1949 HRM(canvas->GetVisuals(&visuals), "Could not get glyph canvas visuals.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001950
bungeman@google.comb29c8832011-10-10 13:19:10 +00001951 if (!useCanvasForClip) {
Mike Reeda1361362017-03-07 09:37:29 -05001952 HR(this->clip(glyphs.get()));
bungeman@google.comb29c8832011-10-10 13:19:10 +00001953 HRM(visuals->Append(glyphs.get()), "Could not add glyphs to canvas.");
1954 } else {
1955 SkTScopedComPtr<IXpsOMCanvas> glyphCanvas;
1956 HRM(this->fXpsFactory->CreateCanvas(&glyphCanvas),
1957 "Could not create glyph canvas.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001958
bungeman@google.comb29c8832011-10-10 13:19:10 +00001959 SkTScopedComPtr<IXpsOMVisualCollection> glyphCanvasVisuals;
1960 HRM(glyphCanvas->GetVisuals(&glyphCanvasVisuals),
1961 "Could not get glyph visuals collection.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001962
bungeman@google.comb29c8832011-10-10 13:19:10 +00001963 HRM(glyphCanvasVisuals->Append(glyphs.get()),
1964 "Could not add glyphs to page.");
Mike Reeda1361362017-03-07 09:37:29 -05001965 HR(this->clip(glyphCanvas.get()));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001966
bungeman@google.comb29c8832011-10-10 13:19:10 +00001967 HRM(visuals->Append(glyphCanvas.get()),
1968 "Could not add glyph canvas to page.");
1969 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001970
bungeman@google.comb29c8832011-10-10 13:19:10 +00001971 return S_OK;
1972}
1973
herbbda26432015-11-24 08:37:01 -08001974static int num_glyph_guess(SkPaint::TextEncoding encoding, const void* text, size_t byteLength) {
Hal Canaryf107a2f2018-07-25 16:52:48 -04001975 static_assert((int)SkTypeface::kUTF8_Encoding == (int)SkPaint::kUTF8_TextEncoding, "");
1976 static_assert((int)SkTypeface::kUTF16_Encoding == (int)SkPaint::kUTF16_TextEncoding, "");
1977 static_assert((int)SkTypeface::kUTF32_Encoding == (int)SkPaint::kUTF32_TextEncoding, "");
1978 if (encoding == SkPaint::kGlyphID_TextEncoding) {
herbbda26432015-11-24 08:37:01 -08001979 return SkToInt(byteLength / 2);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001980 }
Hal Canaryf107a2f2018-07-25 16:52:48 -04001981 return SkUTFN_CountUnichars((SkTypeface::Encoding)encoding, text, byteLength);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001982}
1983
1984static bool text_must_be_pathed(const SkPaint& paint, const SkMatrix& matrix) {
1985 const SkPaint::Style style = paint.getStyle();
1986 return matrix.hasPerspective()
1987 || SkPaint::kStroke_Style == style
1988 || SkPaint::kStrokeAndFill_Style == style
1989 || paint.getMaskFilter()
bungeman@google.comb29c8832011-10-10 13:19:10 +00001990 ;
1991}
1992
herbbda26432015-11-24 08:37:01 -08001993typedef SkTDArray<XPS_GLYPH_INDEX> GlyphRun;
1994
1995class ProcessOneGlyph {
1996public:
1997 ProcessOneGlyph(FLOAT centemPerUnit, SkBitSet* glyphUse, GlyphRun* xpsGlyphs)
1998 : fCentemPerUnit(centemPerUnit)
1999 , fGlyphUse(glyphUse)
2000 , fXpsGlyphs(xpsGlyphs) { }
2001
2002 void operator()(const SkGlyph& glyph, SkPoint position, SkPoint) {
2003 SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0);
2004
2005 SkScalar x = position.fX;
2006 SkScalar y = position.fY;
2007
2008 XPS_GLYPH_INDEX* xpsGlyph = fXpsGlyphs->append();
2009 uint16_t glyphID = glyph.getGlyphID();
halcanarye2348cc2016-08-19 16:23:23 -07002010 fGlyphUse->set(glyphID);
herbbda26432015-11-24 08:37:01 -08002011 xpsGlyph->index = glyphID;
2012 if (1 == fXpsGlyphs->count()) {
2013 xpsGlyph->advanceWidth = 0.0f;
2014 xpsGlyph->horizontalOffset = SkScalarToFloat(x) * fCentemPerUnit;
2015 xpsGlyph->verticalOffset = SkScalarToFloat(y) * -fCentemPerUnit;
2016 }
2017 else {
2018 const XPS_GLYPH_INDEX& first = (*fXpsGlyphs)[0];
2019 xpsGlyph->advanceWidth = 0.0f;
2020 xpsGlyph->horizontalOffset = (SkScalarToFloat(x) * fCentemPerUnit)
2021 - first.horizontalOffset;
2022 xpsGlyph->verticalOffset = (SkScalarToFloat(y) * -fCentemPerUnit)
2023 - first.verticalOffset;
2024 }
2025 }
2026
2027private:
2028 /** [in] Advance width and offsets for glyphs measured in
2029 hundredths of the font em size (XPS Spec 5.1.3). */
2030 const FLOAT fCentemPerUnit;
2031 /** [in,out] The accumulated glyphs used in the current typeface. */
2032 SkBitSet* const fGlyphUse;
2033 /** [out] The glyphs to draw. */
2034 GlyphRun* const fXpsGlyphs;
2035};
2036
Mike Reeda1361362017-03-07 09:37:29 -05002037void SkXPSDevice::drawPosText(const void* text, size_t byteLen,
fmalita05c4a432014-09-29 06:29:53 -07002038 const SkScalar pos[], int scalarsPerPos,
2039 const SkPoint& offset, const SkPaint& paint) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00002040 if (byteLen < 1) return;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002041
Mike Reeda1361362017-03-07 09:37:29 -05002042 if (text_must_be_pathed(paint, this->ctm())) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00002043 SkPath path;
2044 //TODO: make this work, Draw currently does not handle as well.
2045 //paint.getTextPath(text, byteLength, x, y, &path);
Mike Reeda1361362017-03-07 09:37:29 -05002046 //this->drawPath(path, paint, nullptr, true);
bungeman@google.comb29c8832011-10-10 13:19:10 +00002047 //TODO: add automation "text"
2048 return;
2049 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002050
bungeman@google.comb29c8832011-10-10 13:19:10 +00002051 TypefaceUse* typeface;
2052 HRV(CreateTypefaceUse(paint, &typeface));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002053
Herb Derbyf9e12df2018-03-26 15:42:44 -04002054 auto cache =
Herb Derbyfa996902018-04-18 11:36:12 -04002055 SkStrikeCache::FindOrCreateStrikeExclusive(
Herb Derbyf9e12df2018-03-26 15:42:44 -04002056 paint, &this->surfaceProps(),
2057 SkScalerContextFlags::kNone, nullptr);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002058
herbbda26432015-11-24 08:37:01 -08002059 // Advance width and offsets for glyphs measured in hundredths of the font em size
2060 // (XPS Spec 5.1.3).
2061 FLOAT centemPerUnit = 100.0f / SkScalarToFLOAT(paint.getTextSize());
2062 GlyphRun xpsGlyphs;
2063 xpsGlyphs.setReserve(num_glyph_guess(paint.getTextEncoding(),
2064 static_cast<const char*>(text), byteLen));
2065
2066 ProcessOneGlyph processOneGlyph(centemPerUnit, typeface->glyphsUsed, &xpsGlyphs);
2067
2068 SkFindAndPlaceGlyph::ProcessPosText(
2069 paint.getTextEncoding(), static_cast<const char*>(text), byteLen,
Herb Derby1e7c6582018-05-21 16:10:17 -04002070 offset, SkMatrix::I(), pos, scalarsPerPos, cache.get(), processOneGlyph);
herbbda26432015-11-24 08:37:01 -08002071
2072 if (xpsGlyphs.count() == 0) {
reed@google.com089130c2011-12-12 21:52:18 +00002073 return;
2074 }
2075
bungeman@google.comb29c8832011-10-10 13:19:10 +00002076 XPS_POINT origin = {
herbbda26432015-11-24 08:37:01 -08002077 xpsGlyphs[0].horizontalOffset / centemPerUnit,
2078 xpsGlyphs[0].verticalOffset / -centemPerUnit,
bungeman@google.comb29c8832011-10-10 13:19:10 +00002079 };
herbbda26432015-11-24 08:37:01 -08002080 xpsGlyphs[0].horizontalOffset = 0.0f;
2081 xpsGlyphs[0].verticalOffset = 0.0f;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002082
Mike Reeda1361362017-03-07 09:37:29 -05002083 HRV(AddGlyphs(this->fXpsFactory.get(),
bungeman@google.comb29c8832011-10-10 13:19:10 +00002084 this->fCurrentXpsCanvas.get(),
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00002085 typeface,
halcanary96fcdcc2015-08-27 07:41:13 -07002086 nullptr,
herbbda26432015-11-24 08:37:01 -08002087 xpsGlyphs.begin(), xpsGlyphs.count(),
bungeman@google.comb29c8832011-10-10 13:19:10 +00002088 &origin,
2089 SkScalarToFLOAT(paint.getTextSize()),
2090 XPS_STYLE_SIMULATION_NONE,
Mike Reeda1361362017-03-07 09:37:29 -05002091 this->ctm(),
bungeman@google.comb29c8832011-10-10 13:19:10 +00002092 paint));
2093}
2094
Mike Reeda1361362017-03-07 09:37:29 -05002095void SkXPSDevice::drawDevice( SkBaseDevice* dev,
bungeman@google.comb29c8832011-10-10 13:19:10 +00002096 int x, int y,
2097 const SkPaint&) {
2098 SkXPSDevice* that = static_cast<SkXPSDevice*>(dev);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002099
bungeman@google.comb29c8832011-10-10 13:19:10 +00002100 SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform;
Mike Reeda1361362017-03-07 09:37:29 -05002101 // TODO(halcanary): assert that current transform is identity rather than calling setter.
2102 XPS_MATRIX rawTransform = {1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f};
bungeman@google.comb29c8832011-10-10 13:19:10 +00002103 HRVM(this->fXpsFactory->CreateMatrixTransform(&rawTransform, &xpsTransform),
2104 "Could not create layer transform.");
2105 HRVM(that->fCurrentXpsCanvas->SetTransformLocal(xpsTransform.get()),
2106 "Could not set layer transform.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002107
bungeman@google.comb29c8832011-10-10 13:19:10 +00002108 //Get the current visual collection and add the layer to it.
2109 SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals;
2110 HRVM(this->fCurrentXpsCanvas->GetVisuals(&currentVisuals),
2111 "Could not get current visuals for layer.");
2112 HRVM(currentVisuals->Append(that->fCurrentXpsCanvas.get()),
2113 "Could not add layer to current visuals.");
2114}
2115
reed76033be2015-03-14 10:54:31 -07002116SkBaseDevice* SkXPSDevice::onCreateDevice(const CreateInfo& info, const SkPaint*) {
bungeman@google.com635091f2013-10-01 15:03:18 +00002117//Conditional for bug compatibility with PDF device.
2118#if 0
fmalita6987dca2014-11-13 08:33:37 -08002119 if (SkBaseDevice::kGeneral_Usage == info.fUsage) {
halcanary96fcdcc2015-08-27 07:41:13 -07002120 return nullptr;
bungeman@google.comb29c8832011-10-10 13:19:10 +00002121 //To what stream do we write?
2122 //SkXPSDevice* dev = new SkXPSDevice(this);
2123 //SkSize s = SkSize::Make(width, height);
2124 //dev->BeginCanvas(s, s, SkMatrix::I());
2125 //return dev;
2126 }
bungeman@google.com635091f2013-10-01 15:03:18 +00002127#endif
Hal Canaryabc88d22017-02-06 09:26:49 -05002128 SkXPSDevice* dev = new SkXPSDevice(info.fInfo.dimensions());
2129 // TODO(halcanary) implement copy constructor on SkTScopedCOmPtr
2130 dev->fXpsFactory.reset(SkRefComPtr(fXpsFactory.get()));
2131 SkAssertResult(dev->createCanvasForLayer());
2132 return dev;
bungeman@google.comb29c8832011-10-10 13:19:10 +00002133}
2134
Mike Reeda1361362017-03-07 09:37:29 -05002135void SkXPSDevice::drawOval( const SkRect& o, const SkPaint& p) {
Hal Canaryb39b09e2017-02-01 17:04:44 -05002136 SkPath path;
2137 path.addOval(o);
Robert Phillips137ca522018-08-15 10:14:33 -04002138 this->drawPath(path, p, true);
Hal Canaryb39b09e2017-02-01 17:04:44 -05002139}
2140
Mike Reeda1361362017-03-07 09:37:29 -05002141void SkXPSDevice::drawBitmapRect(const SkBitmap& bitmap,
2142 const SkRect* src,
2143 const SkRect& dst,
2144 const SkPaint& paint,
2145 SkCanvas::SrcRectConstraint constraint) {
Hal Canary7da8d642017-03-17 15:16:21 -04002146 SkRect bitmapBounds = SkRect::Make(bitmap.bounds());
2147 SkRect srcBounds = src ? *src : bitmapBounds;
Hal Canaryb39b09e2017-02-01 17:04:44 -05002148 SkMatrix matrix = SkMatrix::MakeRectToRect(srcBounds, dst, SkMatrix::kFill_ScaleToFit);
Hal Canary7da8d642017-03-17 15:16:21 -04002149 SkRect actualDst;
2150 if (!src || bitmapBounds.contains(*src)) {
2151 actualDst = dst;
2152 } else {
2153 if (!srcBounds.intersect(bitmapBounds)) {
2154 return;
2155 }
2156 matrix.mapRect(&actualDst, srcBounds);
2157 }
Hal Canaryb39b09e2017-02-01 17:04:44 -05002158 auto bitmapShader = SkMakeBitmapShader(bitmap, SkShader::kClamp_TileMode,
2159 SkShader::kClamp_TileMode, &matrix,
Herb Derbybfdc87a2017-02-14 15:06:23 +00002160 kNever_SkCopyPixelsMode);
Hal Canaryb39b09e2017-02-01 17:04:44 -05002161 SkASSERT(bitmapShader);
2162 if (!bitmapShader) { return; }
2163 SkPaint paintWithShader(paint);
2164 paintWithShader.setStyle(SkPaint::kFill_Style);
2165 paintWithShader.setShader(std::move(bitmapShader));
Hal Canary7da8d642017-03-17 15:16:21 -04002166 this->drawRect(actualDst, paintWithShader);
Hal Canaryb39b09e2017-02-01 17:04:44 -05002167}
Mike Klein8f11d4d2018-01-24 12:42:55 -05002168#endif//defined(SK_BUILD_FOR_WIN)