blob: 90fc68091cb0bc5283cbb0d720fee0baa54d5698 [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"
mtklein1ee76512015-11-02 10:20:27 -08009#if defined(SK_BUILD_FOR_WIN32)
halcanary47ef4d52015-03-03 09:13:09 -080010
bungeman@google.comb29c8832011-10-10 13:19:10 +000011#ifndef UNICODE
12#define UNICODE
13#endif
14#ifndef _UNICODE
15#define _UNICODE
16#endif
bungeman@google.comb29c8832011-10-10 13:19:10 +000017#include <ObjBase.h>
18#include <XpsObjectModel.h>
19#include <T2EmbApi.h>
20#include <FontSub.h>
21
22#include "SkColor.h"
23#include "SkConstexprMath.h"
24#include "SkData.h"
25#include "SkDraw.h"
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +000026#include "SkEndian.h"
herbbda26432015-11-24 08:37:01 -080027#include "SkFindAndPlaceGlyph.h"
halcanary47ef4d52015-03-03 09:13:09 -080028#include "SkGeometry.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000029#include "SkGlyphCache.h"
30#include "SkHRESULT.h"
31#include "SkImageEncoder.h"
32#include "SkIStream.h"
33#include "SkMaskFilter.h"
34#include "SkPaint.h"
reeda4393342016-03-18 11:22:57 -070035#include "SkPathEffect.h"
Ben Wagnerda5a1b82014-08-22 15:07:06 -040036#include "SkPathOps.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000037#include "SkPoint.h"
reed1e7f5e72016-04-27 07:49:17 -070038#include "SkRasterClip.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000039#include "SkRasterizer.h"
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +000040#include "SkSFNTHeader.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000041#include "SkShader.h"
42#include "SkSize.h"
43#include "SkStream.h"
44#include "SkTDArray.h"
45#include "SkTLazy.h"
46#include "SkTScopedComPtr.h"
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +000047#include "SkTTCFHeader.h"
reed@google.com398de9a2013-03-21 21:43:51 +000048#include "SkTypefacePriv.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000049#include "SkUtils.h"
50#include "SkXPSDevice.h"
51
52//Windows defines a FLOAT type,
53//make it clear when converting a scalar that this is what is wanted.
54#define SkScalarToFLOAT(n) SkScalarToFloat(n)
55
Ben Wagnerda5a1b82014-08-22 15:07:06 -040056//Dummy representation of a GUID from createId.
bungeman@google.comb29c8832011-10-10 13:19:10 +000057#define L_GUID_ID L"XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX"
halcanary96fcdcc2015-08-27 07:41:13 -070058//Length of GUID representation from createId, including nullptr terminator.
bungeman@google.comb29c8832011-10-10 13:19:10 +000059#define GUID_ID_LEN SK_ARRAY_COUNT(L_GUID_ID)
60
61/**
62 Formats a GUID and places it into buffer.
63 buffer should have space for at least GUID_ID_LEN wide characters.
64 The string will always be wchar null terminated.
65 XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX0
66 @return -1 if there was an error, > 0 if success.
67 */
68static int format_guid(const GUID& guid,
69 wchar_t* buffer, size_t bufferSize,
70 wchar_t sep = '-') {
71 SkASSERT(bufferSize >= GUID_ID_LEN);
72 return swprintf_s(buffer,
73 bufferSize,
74 L"%08lX%c%04X%c%04X%c%02X%02X%c%02X%02X%02X%02X%02X%02X",
75 guid.Data1,
76 sep,
77 guid.Data2,
78 sep,
79 guid.Data3,
80 sep,
81 guid.Data4[0],
82 guid.Data4[1],
83 sep,
84 guid.Data4[2],
85 guid.Data4[3],
86 guid.Data4[4],
87 guid.Data4[5],
88 guid.Data4[6],
89 guid.Data4[7]);
90}
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +000091
Ben Wagnerda5a1b82014-08-22 15:07:06 -040092HRESULT SkXPSDevice::createId(wchar_t* buffer, size_t bufferSize, wchar_t sep) {
bungeman@google.comb29c8832011-10-10 13:19:10 +000093 GUID guid = {};
Ben Wagnerda5a1b82014-08-22 15:07:06 -040094#ifdef SK_XPS_USE_DETERMINISTIC_IDS
95 guid.Data1 = fNextId++;
96 // The following make this a valid Type4 UUID.
97 guid.Data3 = 0x4000;
98 guid.Data4[0] = 0x80;
99#else
bungeman@google.comb29c8832011-10-10 13:19:10 +0000100 HRM(CoCreateGuid(&guid), "Could not create GUID for id.");
Ben Wagnerda5a1b82014-08-22 15:07:06 -0400101#endif
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000102
bungeman@google.comb29c8832011-10-10 13:19:10 +0000103 if (format_guid(guid, buffer, bufferSize, sep) == -1) {
104 HRM(E_UNEXPECTED, "Could not format GUID into id.");
105 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000106
bungeman@google.comb29c8832011-10-10 13:19:10 +0000107 return S_OK;
108}
109
110static SkBitmap make_fake_bitmap(int width, int height) {
111 SkBitmap bitmap;
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +0000112 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height));
bungeman@google.comb29c8832011-10-10 13:19:10 +0000113 return bitmap;
114}
115
reed@google.com900ecf22014-02-20 20:55:37 +0000116// TODO: should inherit from SkBaseDevice instead of SkBitmapDevice...
bungeman@google.comb29c8832011-10-10 13:19:10 +0000117SkXPSDevice::SkXPSDevice()
robertphillips9a53fd72015-06-22 09:46:59 -0700118 : INHERITED(make_fake_bitmap(10000, 10000), SkSurfaceProps(0, kUnknown_SkPixelGeometry))
bungeman@google.comb29c8832011-10-10 13:19:10 +0000119 , fCurrentPage(0) {
120}
121
robertphillips9a53fd72015-06-22 09:46:59 -0700122SkXPSDevice::SkXPSDevice(IXpsOMObjectFactory* xpsFactory)
123 : INHERITED(make_fake_bitmap(10000, 10000), SkSurfaceProps(0, kUnknown_SkPixelGeometry))
124 , fCurrentPage(0) {
125
126 HRVM(CoCreateInstance(
127 CLSID_XpsOMObjectFactory,
halcanary96fcdcc2015-08-27 07:41:13 -0700128 nullptr,
robertphillips9a53fd72015-06-22 09:46:59 -0700129 CLSCTX_INPROC_SERVER,
130 IID_PPV_ARGS(&this->fXpsFactory)),
131 "Could not create factory for layer.");
132
133 HRVM(this->fXpsFactory->CreateCanvas(&this->fCurrentXpsCanvas),
134 "Could not create canvas for layer.");
135}
136
bungeman@google.comb29c8832011-10-10 13:19:10 +0000137SkXPSDevice::~SkXPSDevice() {
138}
139
140SkXPSDevice::TypefaceUse::TypefaceUse()
141 : typefaceId(0xffffffff)
halcanary96fcdcc2015-08-27 07:41:13 -0700142 , fontData(nullptr)
143 , xpsFont(nullptr)
144 , glyphsUsed(nullptr) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000145}
146
147SkXPSDevice::TypefaceUse::~TypefaceUse() {
148 //xpsFont owns fontData ref
149 this->xpsFont->Release();
150 delete this->glyphsUsed;
151}
152
153bool SkXPSDevice::beginPortfolio(SkWStream* outputStream) {
154 if (!this->fAutoCo.succeeded()) return false;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000155
bungeman@google.comb29c8832011-10-10 13:19:10 +0000156 //Create XPS Factory.
157 HRBM(CoCreateInstance(
158 CLSID_XpsOMObjectFactory,
halcanary96fcdcc2015-08-27 07:41:13 -0700159 nullptr,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000160 CLSCTX_INPROC_SERVER,
161 IID_PPV_ARGS(&this->fXpsFactory)),
162 "Could not create XPS factory.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000163
bungeman@google.comb29c8832011-10-10 13:19:10 +0000164 HRBM(SkWIStream::CreateFromSkWStream(outputStream, &this->fOutputStream),
165 "Could not convert SkStream to IStream.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000166
bungeman@google.comb29c8832011-10-10 13:19:10 +0000167 return true;
168}
169
170bool SkXPSDevice::beginSheet(
171 const SkVector& unitsPerMeter,
172 const SkVector& pixelsPerMeter,
173 const SkSize& trimSize,
174 const SkRect* mediaBox,
175 const SkRect* bleedBox,
176 const SkRect* artBox,
177 const SkRect* cropBox) {
178 ++this->fCurrentPage;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000179
bungeman@google.comb29c8832011-10-10 13:19:10 +0000180 //For simplicity, just write everything out in geometry units,
181 //then have a base canvas do the scale to physical units.
182 this->fCurrentCanvasSize = trimSize;
183 this->fCurrentUnitsPerMeter = unitsPerMeter;
184 this->fCurrentPixelsPerMeter = pixelsPerMeter;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000185
bungeman@google.comb29c8832011-10-10 13:19:10 +0000186 this->fCurrentXpsCanvas.reset();
187 HRBM(this->fXpsFactory->CreateCanvas(&this->fCurrentXpsCanvas),
188 "Could not create base canvas.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000189
bungeman@google.comb29c8832011-10-10 13:19:10 +0000190 return true;
191}
192
193HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page,
194 const unsigned int pageNum,
195 IXpsOMImageResource** image) {
196 SkTScopedComPtr<IXpsOMThumbnailGenerator> thumbnailGenerator;
197 HRM(CoCreateInstance(
198 CLSID_XpsOMThumbnailGenerator,
halcanary96fcdcc2015-08-27 07:41:13 -0700199 nullptr,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000200 CLSCTX_INPROC_SERVER,
201 IID_PPV_ARGS(&thumbnailGenerator)),
202 "Could not create thumbnail generator.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000203
bungeman@google.comb29c8832011-10-10 13:19:10 +0000204 SkTScopedComPtr<IOpcPartUri> partUri;
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000205 static const size_t size = SkTUMax<
bungeman@google.comb29c8832011-10-10 13:19:10 +0000206 SK_ARRAY_COUNT(L"/Documents/1/Metadata/.png") + SK_DIGITS_IN(pageNum),
207 SK_ARRAY_COUNT(L"/Metadata/" L_GUID_ID L".png")
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000208 >::value;
bungeman@google.comb29c8832011-10-10 13:19:10 +0000209 wchar_t buffer[size];
210 if (pageNum > 0) {
211 swprintf_s(buffer, size, L"/Documents/1/Metadata/%u.png", pageNum);
212 } else {
213 wchar_t id[GUID_ID_LEN];
Ben Wagnerda5a1b82014-08-22 15:07:06 -0400214 HR(this->createId(id, GUID_ID_LEN));
bungeman@google.comb29c8832011-10-10 13:19:10 +0000215 swprintf_s(buffer, size, L"/Metadata/%s.png", id);
216 }
217 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri),
218 "Could not create thumbnail part uri.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000219
bungeman@google.comb29c8832011-10-10 13:19:10 +0000220 HRM(thumbnailGenerator->GenerateThumbnail(page,
221 XPS_IMAGE_TYPE_PNG,
222 XPS_THUMBNAIL_SIZE_LARGE,
223 partUri.get(),
224 image),
225 "Could not generate thumbnail.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000226
bungeman@google.comb29c8832011-10-10 13:19:10 +0000227 return S_OK;
228}
229
230HRESULT SkXPSDevice::createXpsPage(const XPS_SIZE& pageSize,
231 IXpsOMPage** page) {
232 static const size_t size = SK_ARRAY_COUNT(L"/Documents/1/Pages/.fpage")
233 + SK_DIGITS_IN(fCurrentPage);
234 wchar_t buffer[size];
235 swprintf_s(buffer, size, L"/Documents/1/Pages/%u.fpage",
236 this->fCurrentPage);
237 SkTScopedComPtr<IOpcPartUri> partUri;
238 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri),
239 "Could not create page part uri.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000240
bungeman@google.comb29c8832011-10-10 13:19:10 +0000241 //If the language is unknown, use "und" (XPS Spec 2.3.5.1).
242 HRM(this->fXpsFactory->CreatePage(&pageSize,
243 L"und",
244 partUri.get(),
245 page),
246 "Could not create page.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000247
bungeman@google.comb29c8832011-10-10 13:19:10 +0000248 return S_OK;
249}
250
251HRESULT SkXPSDevice::initXpsDocumentWriter(IXpsOMImageResource* image) {
252 //Create package writer.
253 {
254 SkTScopedComPtr<IOpcPartUri> partUri;
255 HRM(this->fXpsFactory->CreatePartUri(L"/FixedDocumentSequence.fdseq",
256 &partUri),
257 "Could not create document sequence part uri.");
258 HRM(this->fXpsFactory->CreatePackageWriterOnStream(
259 this->fOutputStream.get(),
260 TRUE,
261 XPS_INTERLEAVING_OFF, //XPS_INTERLEAVING_ON,
262 partUri.get(),
halcanary96fcdcc2015-08-27 07:41:13 -0700263 nullptr,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000264 image,
halcanary96fcdcc2015-08-27 07:41:13 -0700265 nullptr,
266 nullptr,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000267 &this->fPackageWriter),
268 "Could not create package writer.");
269 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000270
bungeman@google.comb29c8832011-10-10 13:19:10 +0000271 //Begin the lone document.
272 {
273 SkTScopedComPtr<IOpcPartUri> partUri;
274 HRM(this->fXpsFactory->CreatePartUri(
275 L"/Documents/1/FixedDocument.fdoc",
276 &partUri),
277 "Could not create fixed document part uri.");
278 HRM(this->fPackageWriter->StartNewDocument(partUri.get(),
halcanary96fcdcc2015-08-27 07:41:13 -0700279 nullptr,
280 nullptr,
281 nullptr,
282 nullptr),
bungeman@google.comb29c8832011-10-10 13:19:10 +0000283 "Could not start document.");
284 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000285
bungeman@google.comb29c8832011-10-10 13:19:10 +0000286 return S_OK;
287}
288
289bool SkXPSDevice::endSheet() {
290 //XPS is fixed at 96dpi (XPS Spec 11.1).
291 static const float xpsDPI = 96.0f;
292 static const float inchesPerMeter = 10000.0f / 254.0f;
293 static const float targetUnitsPerMeter = xpsDPI * inchesPerMeter;
294 const float scaleX = targetUnitsPerMeter
295 / SkScalarToFLOAT(this->fCurrentUnitsPerMeter.fX);
296 const float scaleY = targetUnitsPerMeter
297 / SkScalarToFLOAT(this->fCurrentUnitsPerMeter.fY);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000298
bungeman@google.comb29c8832011-10-10 13:19:10 +0000299 //Create the scale canvas.
300 SkTScopedComPtr<IXpsOMCanvas> scaleCanvas;
301 HRBM(this->fXpsFactory->CreateCanvas(&scaleCanvas),
302 "Could not create scale canvas.");
303 SkTScopedComPtr<IXpsOMVisualCollection> scaleCanvasVisuals;
304 HRBM(scaleCanvas->GetVisuals(&scaleCanvasVisuals),
305 "Could not get scale canvas visuals.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000306
bungeman@google.comb29c8832011-10-10 13:19:10 +0000307 SkTScopedComPtr<IXpsOMMatrixTransform> geomToPhys;
308 XPS_MATRIX rawGeomToPhys = { scaleX, 0, 0, scaleY, 0, 0, };
309 HRBM(this->fXpsFactory->CreateMatrixTransform(&rawGeomToPhys, &geomToPhys),
310 "Could not create geometry to physical transform.");
311 HRBM(scaleCanvas->SetTransformLocal(geomToPhys.get()),
312 "Could not set transform on scale canvas.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000313
bungeman@google.comb29c8832011-10-10 13:19:10 +0000314 //Add the content canvas to the scale canvas.
315 HRBM(scaleCanvasVisuals->Append(this->fCurrentXpsCanvas.get()),
316 "Could not add base canvas to scale canvas.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000317
bungeman@google.comb29c8832011-10-10 13:19:10 +0000318 //Create the page.
319 XPS_SIZE pageSize = {
320 SkScalarToFLOAT(this->fCurrentCanvasSize.width()) * scaleX,
321 SkScalarToFLOAT(this->fCurrentCanvasSize.height()) * scaleY,
322 };
323 SkTScopedComPtr<IXpsOMPage> page;
324 HRB(this->createXpsPage(pageSize, &page));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000325
bungeman@google.comb29c8832011-10-10 13:19:10 +0000326 SkTScopedComPtr<IXpsOMVisualCollection> pageVisuals;
327 HRBM(page->GetVisuals(&pageVisuals), "Could not get page visuals.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000328
bungeman@google.comb29c8832011-10-10 13:19:10 +0000329 //Add the scale canvas to the page.
330 HRBM(pageVisuals->Append(scaleCanvas.get()),
331 "Could not add scale canvas to page.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000332
bungeman@google.comb29c8832011-10-10 13:19:10 +0000333 //Create the package writer if it hasn't been created yet.
halcanary96fcdcc2015-08-27 07:41:13 -0700334 if (nullptr == this->fPackageWriter.get()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000335 SkTScopedComPtr<IXpsOMImageResource> image;
336 //Ignore return, thumbnail is completely optional.
337 this->createXpsThumbnail(page.get(), 0, &image);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000338
bungeman@google.comb29c8832011-10-10 13:19:10 +0000339 HRB(this->initXpsDocumentWriter(image.get()));
340 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000341
bungeman@google.comb29c8832011-10-10 13:19:10 +0000342 HRBM(this->fPackageWriter->AddPage(page.get(),
343 &pageSize,
halcanary96fcdcc2015-08-27 07:41:13 -0700344 nullptr,
345 nullptr,
346 nullptr,
347 nullptr),
bungeman@google.comb29c8832011-10-10 13:19:10 +0000348 "Could not write the page.");
349 this->fCurrentXpsCanvas.reset();
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000350
bungeman@google.comb29c8832011-10-10 13:19:10 +0000351 return true;
352}
353
354static HRESULT subset_typeface(SkXPSDevice::TypefaceUse* current) {
355 //CreateFontPackage wants unsigned short.
356 //Microsoft, Y U NO stdint.h?
357 SkTDArray<unsigned short> keepList;
358 current->glyphsUsed->exportTo(&keepList);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000359
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000360 int ttcCount = (current->ttcIndex + 1);
361
bungeman@google.comb29c8832011-10-10 13:19:10 +0000362 //The following are declared with the types required by CreateFontPackage.
halcanary96fcdcc2015-08-27 07:41:13 -0700363 unsigned char *fontPackageBufferRaw = nullptr;
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000364 unsigned long fontPackageBufferSize;
365 unsigned long bytesWritten;
bungeman@google.comb29c8832011-10-10 13:19:10 +0000366 unsigned long result = CreateFontPackage(
367 (unsigned char *) current->fontData->getMemoryBase(),
368 (unsigned long) current->fontData->getLength(),
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000369 &fontPackageBufferRaw,
370 &fontPackageBufferSize,
371 &bytesWritten,
372 TTFCFP_FLAGS_SUBSET | TTFCFP_FLAGS_GLYPHLIST | (ttcCount > 0 ? TTFCFP_FLAGS_TTC : 0),
373 current->ttcIndex,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000374 TTFCFP_SUBSET,
375 0,
376 0,
377 0,
378 keepList.begin(),
379 keepList.count(),
380 sk_malloc_throw,
381 sk_realloc_throw,
382 sk_free,
halcanary96fcdcc2015-08-27 07:41:13 -0700383 nullptr);
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000384 SkAutoTMalloc<unsigned char> fontPackageBuffer(fontPackageBufferRaw);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000385 if (result != NO_ERROR) {
386 SkDEBUGF(("CreateFontPackage Error %lu", result));
387 return E_UNEXPECTED;
388 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000389
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000390 // If it was originally a ttc, keep it a ttc.
391 // CreateFontPackage over-allocates, realloc usually decreases the size substantially.
392 size_t extra;
393 if (ttcCount > 0) {
394 // Create space for a ttc header.
395 extra = sizeof(SkTTCFHeader) + (ttcCount * sizeof(SK_OT_ULONG));
396 fontPackageBuffer.realloc(bytesWritten + extra);
397 //overlap is certain, use memmove
398 memmove(fontPackageBuffer.get() + extra, fontPackageBuffer.get(), bytesWritten);
399
400 // Write the ttc header.
401 SkTTCFHeader* ttcfHeader = reinterpret_cast<SkTTCFHeader*>(fontPackageBuffer.get());
402 ttcfHeader->ttcTag = SkTTCFHeader::TAG;
403 ttcfHeader->version = SkTTCFHeader::version_1;
404 ttcfHeader->numOffsets = SkEndian_SwapBE32(ttcCount);
405 SK_OT_ULONG* offsetPtr = SkTAfter<SK_OT_ULONG>(ttcfHeader);
406 for (int i = 0; i < ttcCount; ++i, ++offsetPtr) {
bsalomon0aa5cea2014-12-15 09:13:35 -0800407 *offsetPtr = SkEndian_SwapBE32(SkToU32(extra));
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000408 }
409
410 // Fix up offsets in sfnt table entries.
411 SkSFNTHeader* sfntHeader = SkTAddOffset<SkSFNTHeader>(fontPackageBuffer.get(), extra);
412 int numTables = SkEndian_SwapBE16(sfntHeader->numTables);
413 SkSFNTHeader::TableDirectoryEntry* tableDirectory =
414 SkTAfter<SkSFNTHeader::TableDirectoryEntry>(sfntHeader);
415 for (int i = 0; i < numTables; ++i, ++tableDirectory) {
416 tableDirectory->offset = SkEndian_SwapBE32(
bsalomon0aa5cea2014-12-15 09:13:35 -0800417 SkToU32(SkEndian_SwapBE32(SkToU32(tableDirectory->offset)) + extra));
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000418 }
419 } else {
420 extra = 0;
421 fontPackageBuffer.realloc(bytesWritten);
422 }
423
scroggoa1193e42015-01-21 12:09:53 -0800424 SkAutoTDelete<SkMemoryStream> newStream(new SkMemoryStream());
mtklein18300a32016-03-16 13:53:35 -0700425 newStream->setMemoryOwned(fontPackageBuffer.release(), bytesWritten + extra);
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +0000426
bungeman@google.comb29c8832011-10-10 13:19:10 +0000427 SkTScopedComPtr<IStream> newIStream;
mtklein18300a32016-03-16 13:53:35 -0700428 SkIStream::CreateFromSkStream(newStream.release(), true, &newIStream);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000429
bungeman@google.comb29c8832011-10-10 13:19:10 +0000430 XPS_FONT_EMBEDDING embedding;
431 HRM(current->xpsFont->GetEmbeddingOption(&embedding),
432 "Could not get embedding option from font.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000433
bungeman@google.comb29c8832011-10-10 13:19:10 +0000434 SkTScopedComPtr<IOpcPartUri> partUri;
435 HRM(current->xpsFont->GetPartName(&partUri),
436 "Could not get part uri from font.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000437
bungeman@google.comb29c8832011-10-10 13:19:10 +0000438 HRM(current->xpsFont->SetContent(
439 newIStream.get(),
440 embedding,
441 partUri.get()),
442 "Could not set new stream for subsetted font.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000443
bungeman@google.comb29c8832011-10-10 13:19:10 +0000444 return S_OK;
445}
446
447bool SkXPSDevice::endPortfolio() {
448 //Subset fonts
449 if (!this->fTypefaces.empty()) {
450 SkXPSDevice::TypefaceUse* current = &this->fTypefaces.front();
451 const TypefaceUse* last = &this->fTypefaces.back();
452 for (; current <= last; ++current) {
453 //Ignore return for now, if it didn't subset, let it be.
454 subset_typeface(current);
455 }
456 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000457
bungeman@google.comb29c8832011-10-10 13:19:10 +0000458 HRBM(this->fPackageWriter->Close(), "Could not close writer.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000459
bungeman@google.comb29c8832011-10-10 13:19:10 +0000460 return true;
461}
462
463static XPS_COLOR xps_color(const SkColor skColor) {
464 //XPS uses non-pre-multiplied alpha (XPS Spec 11.4).
465 XPS_COLOR xpsColor;
466 xpsColor.colorType = XPS_COLOR_TYPE_SRGB;
467 xpsColor.value.sRGB.alpha = SkColorGetA(skColor);
468 xpsColor.value.sRGB.red = SkColorGetR(skColor);
469 xpsColor.value.sRGB.green = SkColorGetG(skColor);
470 xpsColor.value.sRGB.blue = SkColorGetB(skColor);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000471
bungeman@google.comb29c8832011-10-10 13:19:10 +0000472 return xpsColor;
473}
474
475static XPS_POINT xps_point(const SkPoint& point) {
476 XPS_POINT xpsPoint = {
477 SkScalarToFLOAT(point.fX),
478 SkScalarToFLOAT(point.fY),
479 };
480 return xpsPoint;
481}
482
483static XPS_POINT xps_point(const SkPoint& point, const SkMatrix& matrix) {
484 SkPoint skTransformedPoint;
485 matrix.mapXY(point.fX, point.fY, &skTransformedPoint);
486 return xps_point(skTransformedPoint);
487}
488
489static XPS_SPREAD_METHOD xps_spread_method(SkShader::TileMode tileMode) {
490 switch (tileMode) {
491 case SkShader::kClamp_TileMode:
492 return XPS_SPREAD_METHOD_PAD;
493 case SkShader::kRepeat_TileMode:
494 return XPS_SPREAD_METHOD_REPEAT;
495 case SkShader::kMirror_TileMode:
496 return XPS_SPREAD_METHOD_REFLECT;
497 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000498 SkDEBUGFAIL("Unknown tile mode.");
bungeman@google.comb29c8832011-10-10 13:19:10 +0000499 }
500 return XPS_SPREAD_METHOD_PAD;
501}
502
503static void transform_offsets(SkScalar* stopOffsets, const int numOffsets,
504 const SkPoint& start, const SkPoint& end,
505 const SkMatrix& transform) {
506 SkPoint startTransformed;
507 transform.mapXY(start.fX, start.fY, &startTransformed);
508 SkPoint endTransformed;
509 transform.mapXY(end.fX, end.fY, &endTransformed);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000510
bungeman@google.comb29c8832011-10-10 13:19:10 +0000511 //Manhattan distance between transformed start and end.
512 SkScalar startToEnd = (endTransformed.fX - startTransformed.fX)
513 + (endTransformed.fY - startTransformed.fY);
514 if (SkScalarNearlyZero(startToEnd)) {
515 for (int i = 0; i < numOffsets; ++i) {
516 stopOffsets[i] = 0;
517 }
518 return;
519 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000520
bungeman@google.comb29c8832011-10-10 13:19:10 +0000521 for (int i = 0; i < numOffsets; ++i) {
522 SkPoint stop;
523 stop.fX = SkScalarMul(end.fX - start.fX, stopOffsets[i]);
524 stop.fY = SkScalarMul(end.fY - start.fY, stopOffsets[i]);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000525
bungeman@google.comb29c8832011-10-10 13:19:10 +0000526 SkPoint stopTransformed;
527 transform.mapXY(stop.fX, stop.fY, &stopTransformed);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000528
bungeman@google.comb29c8832011-10-10 13:19:10 +0000529 //Manhattan distance between transformed start and stop.
530 SkScalar startToStop = (stopTransformed.fX - startTransformed.fX)
531 + (stopTransformed.fY - startTransformed.fY);
532 //Percentage along transformed line.
reed80ea19c2015-05-12 10:37:34 -0700533 stopOffsets[i] = startToStop / startToEnd;
bungeman@google.comb29c8832011-10-10 13:19:10 +0000534 }
535}
536
537HRESULT SkXPSDevice::createXpsTransform(const SkMatrix& matrix,
538 IXpsOMMatrixTransform** xpsTransform) {
539 SkScalar affine[6];
540 if (!matrix.asAffine(affine)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700541 *xpsTransform = nullptr;
bungeman@google.comb29c8832011-10-10 13:19:10 +0000542 return S_FALSE;
543 }
544 XPS_MATRIX rawXpsMatrix = {
545 SkScalarToFLOAT(affine[SkMatrix::kAScaleX]),
546 SkScalarToFLOAT(affine[SkMatrix::kASkewY]),
547 SkScalarToFLOAT(affine[SkMatrix::kASkewX]),
548 SkScalarToFLOAT(affine[SkMatrix::kAScaleY]),
549 SkScalarToFLOAT(affine[SkMatrix::kATransX]),
550 SkScalarToFLOAT(affine[SkMatrix::kATransY]),
551 };
552 HRM(this->fXpsFactory->CreateMatrixTransform(&rawXpsMatrix, xpsTransform),
553 "Could not create transform.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000554
bungeman@google.comb29c8832011-10-10 13:19:10 +0000555 return S_OK;
556}
557
558HRESULT SkXPSDevice::createPath(IXpsOMGeometryFigure* figure,
559 IXpsOMVisualCollection* visuals,
560 IXpsOMPath** path) {
561 SkTScopedComPtr<IXpsOMGeometry> geometry;
562 HRM(this->fXpsFactory->CreateGeometry(&geometry),
563 "Could not create geometry.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000564
bungeman@google.comb29c8832011-10-10 13:19:10 +0000565 SkTScopedComPtr<IXpsOMGeometryFigureCollection> figureCollection;
566 HRM(geometry->GetFigures(&figureCollection), "Could not get figures.");
567 HRM(figureCollection->Append(figure), "Could not add figure.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000568
bungeman@google.comb29c8832011-10-10 13:19:10 +0000569 HRM(this->fXpsFactory->CreatePath(path), "Could not create path.");
570 HRM((*path)->SetGeometryLocal(geometry.get()), "Could not set geometry");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000571
bungeman@google.comb29c8832011-10-10 13:19:10 +0000572 HRM(visuals->Append(*path), "Could not add path to visuals.");
573 return S_OK;
574}
575
576HRESULT SkXPSDevice::createXpsSolidColorBrush(const SkColor skColor,
577 const SkAlpha alpha,
578 IXpsOMBrush** xpsBrush) {
579 XPS_COLOR xpsColor = xps_color(skColor);
580 SkTScopedComPtr<IXpsOMSolidColorBrush> solidBrush;
halcanary96fcdcc2015-08-27 07:41:13 -0700581 HRM(this->fXpsFactory->CreateSolidColorBrush(&xpsColor, nullptr, &solidBrush),
bungeman@google.comb29c8832011-10-10 13:19:10 +0000582 "Could not create solid color brush.");
583 HRM(solidBrush->SetOpacity(alpha / 255.0f), "Could not set opacity.");
584 HRM(solidBrush->QueryInterface<IXpsOMBrush>(xpsBrush), "QI Fail.");
585 return S_OK;
586}
587
588HRESULT SkXPSDevice::sideOfClamp(const SkRect& areaToFill,
589 const XPS_RECT& imageViewBox,
590 IXpsOMImageResource* image,
591 IXpsOMVisualCollection* visuals) {
592 SkTScopedComPtr<IXpsOMGeometryFigure> areaToFillFigure;
593 HR(this->createXpsRect(areaToFill, FALSE, TRUE, &areaToFillFigure));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000594
bungeman@google.comb29c8832011-10-10 13:19:10 +0000595 SkTScopedComPtr<IXpsOMPath> areaToFillPath;
596 HR(this->createPath(areaToFillFigure.get(), visuals, &areaToFillPath));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000597
bungeman@google.comb29c8832011-10-10 13:19:10 +0000598 SkTScopedComPtr<IXpsOMImageBrush> areaToFillBrush;
599 HRM(this->fXpsFactory->CreateImageBrush(image,
600 &imageViewBox,
601 &imageViewBox,
602 &areaToFillBrush),
603 "Could not create brush for side of clamp.");
604 HRM(areaToFillBrush->SetTileMode(XPS_TILE_MODE_FLIPXY),
605 "Could not set tile mode for side of clamp.");
606 HRM(areaToFillPath->SetFillBrushLocal(areaToFillBrush.get()),
607 "Could not set brush for side of clamp");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000608
bungeman@google.comb29c8832011-10-10 13:19:10 +0000609 return S_OK;
610}
611
612HRESULT SkXPSDevice::cornerOfClamp(const SkRect& areaToFill,
613 const SkColor color,
614 IXpsOMVisualCollection* visuals) {
615 SkTScopedComPtr<IXpsOMGeometryFigure> areaToFillFigure;
616 HR(this->createXpsRect(areaToFill, FALSE, TRUE, &areaToFillFigure));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000617
bungeman@google.comb29c8832011-10-10 13:19:10 +0000618 SkTScopedComPtr<IXpsOMPath> areaToFillPath;
619 HR(this->createPath(areaToFillFigure.get(), visuals, &areaToFillPath));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000620
bungeman@google.comb29c8832011-10-10 13:19:10 +0000621 SkTScopedComPtr<IXpsOMBrush> areaToFillBrush;
622 HR(this->createXpsSolidColorBrush(color, 0xFF, &areaToFillBrush));
623 HRM(areaToFillPath->SetFillBrushLocal(areaToFillBrush.get()),
624 "Could not set brush for corner of clamp.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000625
bungeman@google.comb29c8832011-10-10 13:19:10 +0000626 return S_OK;
627}
628
629static const XPS_TILE_MODE XTM_N = XPS_TILE_MODE_NONE;
630static const XPS_TILE_MODE XTM_T = XPS_TILE_MODE_TILE;
631static const XPS_TILE_MODE XTM_X = XPS_TILE_MODE_FLIPX;
632static const XPS_TILE_MODE XTM_Y = XPS_TILE_MODE_FLIPY;
633static const XPS_TILE_MODE XTM_XY = XPS_TILE_MODE_FLIPXY;
634
635//TODO(bungeman): In the future, should skia add None,
636//handle None+Mirror and None+Repeat correctly.
637//None is currently an internal hack so masks don't repeat (None+None only).
638static XPS_TILE_MODE SkToXpsTileMode[SkShader::kTileModeCount+1]
639 [SkShader::kTileModeCount+1] = {
640 //Clamp //Repeat //Mirror //None
641/*Clamp */ XTM_N, XTM_T, XTM_Y, XTM_N,
642/*Repeat*/ XTM_T, XTM_T, XTM_Y, XTM_N,
643/*Mirror*/ XTM_X, XTM_X, XTM_XY, XTM_X,
644/*None */ XTM_N, XTM_N, XTM_Y, XTM_N,
645};
646
647HRESULT SkXPSDevice::createXpsImageBrush(
648 const SkBitmap& bitmap,
649 const SkMatrix& localMatrix,
650 const SkShader::TileMode (&xy)[2],
651 const SkAlpha alpha,
652 IXpsOMTileBrush** xpsBrush) {
653 SkDynamicMemoryWStream write;
654 if (!SkImageEncoder::EncodeStream(&write, bitmap,
655 SkImageEncoder::kPNG_Type, 100)) {
656 HRM(E_FAIL, "Unable to encode bitmap as png.");
657 }
658 SkMemoryStream* read = new SkMemoryStream;
659 read->setData(write.copyToData())->unref();
660 SkTScopedComPtr<IStream> readWrapper;
661 HRM(SkIStream::CreateFromSkStream(read, true, &readWrapper),
662 "Could not create stream from png data.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000663
bungeman@google.comb29c8832011-10-10 13:19:10 +0000664 const size_t size =
665 SK_ARRAY_COUNT(L"/Documents/1/Resources/Images/" L_GUID_ID L".png");
666 wchar_t buffer[size];
667 wchar_t id[GUID_ID_LEN];
Ben Wagnerda5a1b82014-08-22 15:07:06 -0400668 HR(this->createId(id, GUID_ID_LEN));
bungeman@google.comb29c8832011-10-10 13:19:10 +0000669 swprintf_s(buffer, size, L"/Documents/1/Resources/Images/%s.png", id);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000670
bungeman@google.comb29c8832011-10-10 13:19:10 +0000671 SkTScopedComPtr<IOpcPartUri> imagePartUri;
672 HRM(this->fXpsFactory->CreatePartUri(buffer, &imagePartUri),
673 "Could not create image part uri.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000674
bungeman@google.comb29c8832011-10-10 13:19:10 +0000675 SkTScopedComPtr<IXpsOMImageResource> imageResource;
676 HRM(this->fXpsFactory->CreateImageResource(
677 readWrapper.get(),
678 XPS_IMAGE_TYPE_PNG,
679 imagePartUri.get(),
680 &imageResource),
681 "Could not create image resource.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000682
bungeman@google.comb29c8832011-10-10 13:19:10 +0000683 XPS_RECT bitmapRect = {
684 0.0, 0.0,
685 static_cast<FLOAT>(bitmap.width()), static_cast<FLOAT>(bitmap.height())
686 };
687 SkTScopedComPtr<IXpsOMImageBrush> xpsImageBrush;
688 HRM(this->fXpsFactory->CreateImageBrush(imageResource.get(),
689 &bitmapRect, &bitmapRect,
690 &xpsImageBrush),
691 "Could not create image brush.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000692
bungeman@google.comb29c8832011-10-10 13:19:10 +0000693 if (SkShader::kClamp_TileMode != xy[0] &&
694 SkShader::kClamp_TileMode != xy[1]) {
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000695
bungeman@google.comb29c8832011-10-10 13:19:10 +0000696 HRM(xpsImageBrush->SetTileMode(SkToXpsTileMode[xy[0]][xy[1]]),
697 "Could not set image tile mode");
698 HRM(xpsImageBrush->SetOpacity(alpha / 255.0f),
699 "Could not set image opacity.");
700 HRM(xpsImageBrush->QueryInterface(xpsBrush), "QI failed.");
701 } else {
702 //TODO(bungeman): compute how big this really needs to be.
703 const SkScalar BIG = SkIntToScalar(1000); //SK_ScalarMax;
704 const FLOAT BIG_F = SkScalarToFLOAT(BIG);
705 const SkScalar bWidth = SkIntToScalar(bitmap.width());
706 const SkScalar bHeight = SkIntToScalar(bitmap.height());
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000707
bungeman@google.comb29c8832011-10-10 13:19:10 +0000708 //create brush canvas
709 SkTScopedComPtr<IXpsOMCanvas> brushCanvas;
710 HRM(this->fXpsFactory->CreateCanvas(&brushCanvas),
711 "Could not create image brush canvas.");
712 SkTScopedComPtr<IXpsOMVisualCollection> brushVisuals;
713 HRM(brushCanvas->GetVisuals(&brushVisuals),
714 "Could not get image brush canvas visuals collection.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000715
bungeman@google.comb29c8832011-10-10 13:19:10 +0000716 //create central figure
717 const SkRect bitmapPoints = SkRect::MakeLTRB(0, 0, bWidth, bHeight);
718 SkTScopedComPtr<IXpsOMGeometryFigure> centralFigure;
719 HR(this->createXpsRect(bitmapPoints, FALSE, TRUE, &centralFigure));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000720
bungeman@google.comb29c8832011-10-10 13:19:10 +0000721 SkTScopedComPtr<IXpsOMPath> centralPath;
722 HR(this->createPath(centralFigure.get(),
723 brushVisuals.get(),
724 &centralPath));
725 HRM(xpsImageBrush->SetTileMode(XPS_TILE_MODE_FLIPXY),
726 "Could not set tile mode for image brush central path.");
727 HRM(centralPath->SetFillBrushLocal(xpsImageBrush.get()),
728 "Could not set fill brush for image brush central path.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000729
bungeman@google.comb29c8832011-10-10 13:19:10 +0000730 //add left/right
731 if (SkShader::kClamp_TileMode == xy[0]) {
732 SkRect leftArea = SkRect::MakeLTRB(-BIG, 0, 0, bHeight);
733 XPS_RECT leftImageViewBox = {
734 0.0, 0.0,
735 1.0, static_cast<FLOAT>(bitmap.height()),
736 };
737 HR(this->sideOfClamp(leftArea, leftImageViewBox,
738 imageResource.get(),
739 brushVisuals.get()));
740
741 SkRect rightArea = SkRect::MakeLTRB(bWidth, 0, BIG, bHeight);
742 XPS_RECT rightImageViewBox = {
743 bitmap.width() - 1.0f, 0.0f,
744 1.0f, static_cast<FLOAT>(bitmap.height()),
745 };
746 HR(this->sideOfClamp(rightArea, rightImageViewBox,
747 imageResource.get(),
748 brushVisuals.get()));
749 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000750
bungeman@google.comb29c8832011-10-10 13:19:10 +0000751 //add top/bottom
752 if (SkShader::kClamp_TileMode == xy[1]) {
753 SkRect topArea = SkRect::MakeLTRB(0, -BIG, bWidth, 0);
754 XPS_RECT topImageViewBox = {
755 0.0, 0.0,
756 static_cast<FLOAT>(bitmap.width()), 1.0,
757 };
758 HR(this->sideOfClamp(topArea, topImageViewBox,
759 imageResource.get(),
760 brushVisuals.get()));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000761
bungeman@google.comb29c8832011-10-10 13:19:10 +0000762 SkRect bottomArea = SkRect::MakeLTRB(0, bHeight, bWidth, BIG);
763 XPS_RECT bottomImageViewBox = {
764 0.0f, bitmap.height() - 1.0f,
765 static_cast<FLOAT>(bitmap.width()), 1.0f,
766 };
767 HR(this->sideOfClamp(bottomArea, bottomImageViewBox,
768 imageResource.get(),
769 brushVisuals.get()));
770 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000771
bungeman@google.comb29c8832011-10-10 13:19:10 +0000772 //add tl, tr, bl, br
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 SkAutoLockPixels alp(bitmap);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000777
bungeman@google.comb29c8832011-10-10 13:19:10 +0000778 const SkColor tlColor = bitmap.getColor(0,0);
779 const SkRect tlArea = SkRect::MakeLTRB(-BIG, -BIG, 0, 0);
780 HR(this->cornerOfClamp(tlArea, tlColor, brushVisuals.get()));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000781
bungeman@google.comb29c8832011-10-10 13:19:10 +0000782 const SkColor trColor = bitmap.getColor(bitmap.width()-1,0);
783 const SkRect trArea = SkRect::MakeLTRB(bWidth, -BIG, BIG, 0);
784 HR(this->cornerOfClamp(trArea, trColor, brushVisuals.get()));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000785
bungeman@google.comb29c8832011-10-10 13:19:10 +0000786 const SkColor brColor = bitmap.getColor(bitmap.width()-1,
787 bitmap.height()-1);
788 const SkRect brArea = SkRect::MakeLTRB(bWidth, bHeight, BIG, BIG);
789 HR(this->cornerOfClamp(brArea, brColor, brushVisuals.get()));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000790
bungeman@google.comb29c8832011-10-10 13:19:10 +0000791 const SkColor blColor = bitmap.getColor(0,bitmap.height()-1);
792 const SkRect blArea = SkRect::MakeLTRB(-BIG, bHeight, 0, BIG);
793 HR(this->cornerOfClamp(blArea, blColor, brushVisuals.get()));
794 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000795
bungeman@google.comb29c8832011-10-10 13:19:10 +0000796 //create visual brush from canvas
797 XPS_RECT bound = {};
798 if (SkShader::kClamp_TileMode == xy[0] &&
799 SkShader::kClamp_TileMode == xy[1]) {
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000800
bungeman@google.comb29c8832011-10-10 13:19:10 +0000801 bound.x = BIG_F / -2;
802 bound.y = BIG_F / -2;
803 bound.width = BIG_F;
804 bound.height = BIG_F;
805 } else if (SkShader::kClamp_TileMode == xy[0]) {
806 bound.x = BIG_F / -2;
807 bound.y = 0.0f;
808 bound.width = BIG_F;
809 bound.height = static_cast<FLOAT>(bitmap.height());
810 } else if (SkShader::kClamp_TileMode == xy[1]) {
811 bound.x = 0;
812 bound.y = BIG_F / -2;
813 bound.width = static_cast<FLOAT>(bitmap.width());
814 bound.height = BIG_F;
815 }
816 SkTScopedComPtr<IXpsOMVisualBrush> clampBrush;
817 HRM(this->fXpsFactory->CreateVisualBrush(&bound, &bound, &clampBrush),
818 "Could not create visual brush for image brush.");
819 HRM(clampBrush->SetVisualLocal(brushCanvas.get()),
820 "Could not set canvas on visual brush for image brush.");
821 HRM(clampBrush->SetTileMode(SkToXpsTileMode[xy[0]][xy[1]]),
822 "Could not set tile mode on visual brush for image brush.");
823 HRM(clampBrush->SetOpacity(alpha / 255.0f),
824 "Could not set opacity on visual brush for image brush.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000825
bungeman@google.comb29c8832011-10-10 13:19:10 +0000826 HRM(clampBrush->QueryInterface(xpsBrush), "QI failed.");
827 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000828
bungeman@google.comb29c8832011-10-10 13:19:10 +0000829 SkTScopedComPtr<IXpsOMMatrixTransform> xpsMatrixToUse;
830 HR(this->createXpsTransform(localMatrix, &xpsMatrixToUse));
bsalomon49f085d2014-09-05 13:34:00 -0700831 if (xpsMatrixToUse.get()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000832 HRM((*xpsBrush)->SetTransformLocal(xpsMatrixToUse.get()),
833 "Could not set transform for image brush.");
834 } else {
835 //TODO(bungeman): perspective bitmaps in general.
836 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000837
bungeman@google.comb29c8832011-10-10 13:19:10 +0000838 return S_OK;
839}
840
841HRESULT SkXPSDevice::createXpsGradientStop(const SkColor skColor,
842 const SkScalar offset,
843 IXpsOMGradientStop** xpsGradStop) {
844 XPS_COLOR gradStopXpsColor = xps_color(skColor);
845 HRM(this->fXpsFactory->CreateGradientStop(&gradStopXpsColor,
halcanary96fcdcc2015-08-27 07:41:13 -0700846 nullptr,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000847 SkScalarToFLOAT(offset),
848 xpsGradStop),
849 "Could not create gradient stop.");
850 return S_OK;
851}
852
853HRESULT SkXPSDevice::createXpsLinearGradient(SkShader::GradientInfo info,
854 const SkAlpha alpha,
855 const SkMatrix& localMatrix,
856 IXpsOMMatrixTransform* xpsMatrix,
857 IXpsOMBrush** xpsBrush) {
858 XPS_POINT startPoint;
859 XPS_POINT endPoint;
bsalomon49f085d2014-09-05 13:34:00 -0700860 if (xpsMatrix) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000861 startPoint = xps_point(info.fPoint[0]);
862 endPoint = xps_point(info.fPoint[1]);
863 } else {
864 transform_offsets(info.fColorOffsets, info.fColorCount,
865 info.fPoint[0], info.fPoint[1],
866 localMatrix);
867 startPoint = xps_point(info.fPoint[0], localMatrix);
868 endPoint = xps_point(info.fPoint[1], localMatrix);
869 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000870
bungeman@google.comb29c8832011-10-10 13:19:10 +0000871 SkTScopedComPtr<IXpsOMGradientStop> gradStop0;
872 HR(createXpsGradientStop(info.fColors[0],
873 info.fColorOffsets[0],
874 &gradStop0));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000875
bungeman@google.comb29c8832011-10-10 13:19:10 +0000876 SkTScopedComPtr<IXpsOMGradientStop> gradStop1;
877 HR(createXpsGradientStop(info.fColors[1],
878 info.fColorOffsets[1],
879 &gradStop1));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000880
bungeman@google.comb29c8832011-10-10 13:19:10 +0000881 SkTScopedComPtr<IXpsOMLinearGradientBrush> gradientBrush;
882 HRM(this->fXpsFactory->CreateLinearGradientBrush(gradStop0.get(),
883 gradStop1.get(),
884 &startPoint,
885 &endPoint,
886 &gradientBrush),
887 "Could not create linear gradient brush.");
bsalomon49f085d2014-09-05 13:34:00 -0700888 if (xpsMatrix) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000889 HRM(gradientBrush->SetTransformLocal(xpsMatrix),
890 "Could not set transform on linear gradient brush.");
891 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000892
bungeman@google.comb29c8832011-10-10 13:19:10 +0000893 SkTScopedComPtr<IXpsOMGradientStopCollection> gradStopCollection;
894 HRM(gradientBrush->GetGradientStops(&gradStopCollection),
895 "Could not get linear gradient stop collection.");
896 for (int i = 2; i < info.fColorCount; ++i) {
897 SkTScopedComPtr<IXpsOMGradientStop> gradStop;
898 HR(createXpsGradientStop(info.fColors[i],
899 info.fColorOffsets[i],
900 &gradStop));
901 HRM(gradStopCollection->Append(gradStop.get()),
902 "Could not add linear gradient stop.");
903 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000904
bungeman@google.comb29c8832011-10-10 13:19:10 +0000905 HRM(gradientBrush->SetSpreadMethod(xps_spread_method(info.fTileMode)),
906 "Could not set spread method of linear gradient.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000907
bungeman@google.comb29c8832011-10-10 13:19:10 +0000908 HRM(gradientBrush->SetOpacity(alpha / 255.0f),
909 "Could not set opacity of linear gradient brush.");
910 HRM(gradientBrush->QueryInterface<IXpsOMBrush>(xpsBrush), "QI failed");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000911
bungeman@google.comb29c8832011-10-10 13:19:10 +0000912 return S_OK;
913}
914
915HRESULT SkXPSDevice::createXpsRadialGradient(SkShader::GradientInfo info,
916 const SkAlpha alpha,
917 const SkMatrix& localMatrix,
918 IXpsOMMatrixTransform* xpsMatrix,
919 IXpsOMBrush** xpsBrush) {
920 SkTScopedComPtr<IXpsOMGradientStop> gradStop0;
921 HR(createXpsGradientStop(info.fColors[0],
922 info.fColorOffsets[0],
923 &gradStop0));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000924
bungeman@google.comb29c8832011-10-10 13:19:10 +0000925 SkTScopedComPtr<IXpsOMGradientStop> gradStop1;
926 HR(createXpsGradientStop(info.fColors[1],
927 info.fColorOffsets[1],
928 &gradStop1));
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000929
bungeman@google.comb29c8832011-10-10 13:19:10 +0000930 //TODO: figure out how to fake better if not affine
931 XPS_POINT centerPoint;
932 XPS_POINT gradientOrigin;
933 XPS_SIZE radiiSizes;
bsalomon49f085d2014-09-05 13:34:00 -0700934 if (xpsMatrix) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000935 centerPoint = xps_point(info.fPoint[0]);
936 gradientOrigin = xps_point(info.fPoint[0]);
937 radiiSizes.width = SkScalarToFLOAT(info.fRadius[0]);
938 radiiSizes.height = SkScalarToFLOAT(info.fRadius[0]);
939 } else {
940 centerPoint = xps_point(info.fPoint[0], localMatrix);
941 gradientOrigin = xps_point(info.fPoint[0], localMatrix);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000942
bungeman@google.comb29c8832011-10-10 13:19:10 +0000943 SkScalar radius = info.fRadius[0];
944 SkVector vec[2];
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000945
bungeman@google.comb29c8832011-10-10 13:19:10 +0000946 vec[0].set(radius, 0);
947 vec[1].set(0, radius);
948 localMatrix.mapVectors(vec, 2);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000949
bungeman@google.comb29c8832011-10-10 13:19:10 +0000950 SkScalar d0 = vec[0].length();
951 SkScalar d1 = vec[1].length();
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000952
bungeman@google.comb29c8832011-10-10 13:19:10 +0000953 radiiSizes.width = SkScalarToFLOAT(d0);
954 radiiSizes.height = SkScalarToFLOAT(d1);
955 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000956
bungeman@google.comb29c8832011-10-10 13:19:10 +0000957 SkTScopedComPtr<IXpsOMRadialGradientBrush> gradientBrush;
958 HRM(this->fXpsFactory->CreateRadialGradientBrush(gradStop0.get(),
959 gradStop1.get(),
960 &centerPoint,
961 &gradientOrigin,
962 &radiiSizes,
963 &gradientBrush),
964 "Could not create radial gradient brush.");
bsalomon49f085d2014-09-05 13:34:00 -0700965 if (xpsMatrix) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000966 HRM(gradientBrush->SetTransformLocal(xpsMatrix),
967 "Could not set transform on radial gradient brush.");
968 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000969
bungeman@google.comb29c8832011-10-10 13:19:10 +0000970 SkTScopedComPtr<IXpsOMGradientStopCollection> gradStopCollection;
971 HRM(gradientBrush->GetGradientStops(&gradStopCollection),
972 "Could not get radial gradient stop collection.");
973 for (int i = 2; i < info.fColorCount; ++i) {
974 SkTScopedComPtr<IXpsOMGradientStop> gradStop;
975 HR(createXpsGradientStop(info.fColors[i],
976 info.fColorOffsets[i],
977 &gradStop));
978 HRM(gradStopCollection->Append(gradStop.get()),
979 "Could not add radial gradient stop.");
980 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000981
bungeman@google.comb29c8832011-10-10 13:19:10 +0000982 HRM(gradientBrush->SetSpreadMethod(xps_spread_method(info.fTileMode)),
983 "Could not set spread method of radial gradient.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000984
bungeman@google.comb29c8832011-10-10 13:19:10 +0000985 HRM(gradientBrush->SetOpacity(alpha / 255.0f),
986 "Could not set opacity of radial gradient brush.");
987 HRM(gradientBrush->QueryInterface<IXpsOMBrush>(xpsBrush), "QI failed.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000988
bungeman@google.comb29c8832011-10-10 13:19:10 +0000989 return S_OK;
990}
991
992HRESULT SkXPSDevice::createXpsBrush(const SkPaint& skPaint,
993 IXpsOMBrush** brush,
994 const SkMatrix* parentTransform) {
995 const SkShader *shader = skPaint.getShader();
halcanary96fcdcc2015-08-27 07:41:13 -0700996 if (nullptr == shader) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000997 HR(this->createXpsSolidColorBrush(skPaint.getColor(), 0xFF, brush));
998 return S_OK;
999 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001000
bungeman@google.comb29c8832011-10-10 13:19:10 +00001001 //Gradient shaders.
1002 SkShader::GradientInfo info;
1003 info.fColorCount = 0;
halcanary96fcdcc2015-08-27 07:41:13 -07001004 info.fColors = nullptr;
1005 info.fColorOffsets = nullptr;
bungeman@google.comb29c8832011-10-10 13:19:10 +00001006 SkShader::GradientType gradientType = shader->asAGradient(&info);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001007
bungeman@google.comb29c8832011-10-10 13:19:10 +00001008 if (SkShader::kNone_GradientType == gradientType) {
1009 //Nothing to see, move along.
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001010
bungeman@google.comb29c8832011-10-10 13:19:10 +00001011 } else if (SkShader::kColor_GradientType == gradientType) {
1012 SkASSERT(1 == info.fColorCount);
1013 SkColor color;
1014 info.fColors = &color;
bsalomon@google.comb58a6392013-03-21 20:29:05 +00001015 shader->asAGradient(&info);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001016 SkAlpha alpha = skPaint.getAlpha();
1017 HR(this->createXpsSolidColorBrush(color, alpha, brush));
1018 return S_OK;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001019
bungeman@google.comb29c8832011-10-10 13:19:10 +00001020 } else {
1021 if (info.fColorCount == 0) {
1022 const SkColor color = skPaint.getColor();
1023 HR(this->createXpsSolidColorBrush(color, 0xFF, brush));
1024 return S_OK;
1025 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001026
bungeman@google.comb29c8832011-10-10 13:19:10 +00001027 SkAutoTArray<SkColor> colors(info.fColorCount);
1028 SkAutoTArray<SkScalar> colorOffsets(info.fColorCount);
1029 info.fColors = colors.get();
1030 info.fColorOffsets = colorOffsets.get();
1031 shader->asAGradient(&info);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001032
bungeman@google.comb29c8832011-10-10 13:19:10 +00001033 if (1 == info.fColorCount) {
1034 SkColor color = info.fColors[0];
1035 SkAlpha alpha = skPaint.getAlpha();
1036 HR(this->createXpsSolidColorBrush(color, alpha, brush));
1037 return S_OK;
1038 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001039
bsalomon@google.comf94b3a42012-10-31 18:09:01 +00001040 SkMatrix localMatrix = shader->getLocalMatrix();
bsalomon49f085d2014-09-05 13:34:00 -07001041 if (parentTransform) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001042 localMatrix.preConcat(*parentTransform);
1043 }
1044 SkTScopedComPtr<IXpsOMMatrixTransform> xpsMatrixToUse;
1045 HR(this->createXpsTransform(localMatrix, &xpsMatrixToUse));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001046
bungeman@google.comb29c8832011-10-10 13:19:10 +00001047 if (SkShader::kLinear_GradientType == gradientType) {
1048 HR(this->createXpsLinearGradient(info,
1049 skPaint.getAlpha(),
1050 localMatrix,
1051 xpsMatrixToUse.get(),
1052 brush));
1053 return S_OK;
1054 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001055
bungeman@google.comb29c8832011-10-10 13:19:10 +00001056 if (SkShader::kRadial_GradientType == gradientType) {
1057 HR(this->createXpsRadialGradient(info,
1058 skPaint.getAlpha(),
1059 localMatrix,
1060 xpsMatrixToUse.get(),
1061 brush));
1062 return S_OK;
1063 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001064
reed71a6cbf2015-05-04 08:32:51 -07001065 if (SkShader::kConical_GradientType == gradientType) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001066 //simple if affine and one is 0, otherwise will have to fake
1067 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001068
bungeman@google.comb29c8832011-10-10 13:19:10 +00001069 if (SkShader::kSweep_GradientType == gradientType) {
1070 //have to fake
1071 }
1072 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001073
bungeman@google.comb29c8832011-10-10 13:19:10 +00001074 SkBitmap outTexture;
1075 SkMatrix outMatrix;
1076 SkShader::TileMode xy[2];
reedf5822822015-08-19 11:46:38 -07001077 if (shader->isABitmap(&outTexture, &outMatrix, xy)) {
1078 //TODO: outMatrix??
1079 SkMatrix localMatrix = shader->getLocalMatrix();
1080 if (parentTransform) {
1081 localMatrix.preConcat(*parentTransform);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001082 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001083
reedf5822822015-08-19 11:46:38 -07001084 SkTScopedComPtr<IXpsOMTileBrush> tileBrush;
1085 HR(this->createXpsImageBrush(outTexture,
1086 localMatrix,
1087 xy,
1088 skPaint.getAlpha(),
1089 &tileBrush));
1090
1091 HRM(tileBrush->QueryInterface<IXpsOMBrush>(brush), "QI failed.");
1092 } else {
1093 HR(this->createXpsSolidColorBrush(skPaint.getColor(), 0xFF, brush));
1094 }
bungeman@google.comb29c8832011-10-10 13:19:10 +00001095 return S_OK;
1096}
1097
1098static bool rect_must_be_pathed(const SkPaint& paint, const SkMatrix& matrix) {
1099 const bool zeroWidth = (0 == paint.getStrokeWidth());
1100 const bool stroke = (SkPaint::kFill_Style != paint.getStyle());
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001101
bungeman@google.comb29c8832011-10-10 13:19:10 +00001102 return paint.getPathEffect() ||
1103 paint.getMaskFilter() ||
1104 paint.getRasterizer() ||
1105 (stroke && (
1106 (matrix.hasPerspective() && !zeroWidth) ||
1107 SkPaint::kMiter_Join != paint.getStrokeJoin() ||
1108 (SkPaint::kMiter_Join == paint.getStrokeJoin() &&
1109 paint.getStrokeMiter() < SK_ScalarSqrt2)
1110 ))
1111 ;
1112}
1113
1114HRESULT SkXPSDevice::createXpsRect(const SkRect& rect, BOOL stroke, BOOL fill,
1115 IXpsOMGeometryFigure** xpsRect) {
1116 const SkPoint points[4] = {
1117 { rect.fLeft, rect.fTop },
1118 { rect.fRight, rect.fTop },
1119 { rect.fRight, rect.fBottom },
1120 { rect.fLeft, rect.fBottom },
1121 };
1122 return this->createXpsQuad(points, stroke, fill, xpsRect);
1123}
1124HRESULT SkXPSDevice::createXpsQuad(const SkPoint (&points)[4],
1125 BOOL stroke, BOOL fill,
1126 IXpsOMGeometryFigure** xpsQuad) {
1127 // Define the start point.
1128 XPS_POINT startPoint = xps_point(points[0]);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001129
bungeman@google.comb29c8832011-10-10 13:19:10 +00001130 // Create the figure.
1131 HRM(this->fXpsFactory->CreateGeometryFigure(&startPoint, xpsQuad),
1132 "Could not create quad geometry figure.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001133
bungeman@google.comb29c8832011-10-10 13:19:10 +00001134 // Define the type of each segment.
1135 XPS_SEGMENT_TYPE segmentTypes[3] = {
1136 XPS_SEGMENT_TYPE_LINE,
1137 XPS_SEGMENT_TYPE_LINE,
1138 XPS_SEGMENT_TYPE_LINE,
1139 };
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001140
bungeman@google.comb29c8832011-10-10 13:19:10 +00001141 // Define the x and y coordinates of each corner of the figure.
1142 FLOAT segmentData[6] = {
1143 SkScalarToFLOAT(points[1].fX), SkScalarToFLOAT(points[1].fY),
1144 SkScalarToFLOAT(points[2].fX), SkScalarToFLOAT(points[2].fY),
1145 SkScalarToFLOAT(points[3].fX), SkScalarToFLOAT(points[3].fY),
1146 };
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001147
bungeman@google.comb29c8832011-10-10 13:19:10 +00001148 // Describe if the segments are stroked.
1149 BOOL segmentStrokes[3] = {
1150 stroke, stroke, stroke,
1151 };
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001152
bungeman@google.comb29c8832011-10-10 13:19:10 +00001153 // Add the segment data to the figure.
1154 HRM((*xpsQuad)->SetSegments(
1155 3, 6,
1156 segmentTypes , segmentData, segmentStrokes),
1157 "Could not add segment data to quad.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001158
bungeman@google.comb29c8832011-10-10 13:19:10 +00001159 // Set the closed and filled properties of the figure.
1160 HRM((*xpsQuad)->SetIsClosed(stroke), "Could not set quad close.");
1161 HRM((*xpsQuad)->SetIsFilled(fill), "Could not set quad fill.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001162
bungeman@google.comb29c8832011-10-10 13:19:10 +00001163 return S_OK;
1164}
1165
bungeman@google.comb29c8832011-10-10 13:19:10 +00001166void SkXPSDevice::drawPoints(const SkDraw& d, SkCanvas::PointMode mode,
1167 size_t count, const SkPoint points[],
1168 const SkPaint& paint) {
1169 //This will call back into the device to do the drawing.
1170 d.drawPoints(mode, count, points, paint, true);
1171}
1172
1173void SkXPSDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode,
1174 int vertexCount, const SkPoint verts[],
1175 const SkPoint texs[], const SkColor colors[],
1176 SkXfermode* xmode, const uint16_t indices[],
1177 int indexCount, const SkPaint& paint) {
1178 //TODO: override this for XPS
1179 SkDEBUGF(("XPS drawVertices not yet implemented."));
1180}
1181
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001182void SkXPSDevice::drawPaint(const SkDraw& d, const SkPaint& origPaint) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001183 const SkRect r = SkRect::MakeSize(this->fCurrentCanvasSize);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001184
bungeman@google.comb29c8832011-10-10 13:19:10 +00001185 //If trying to paint with a stroke, ignore that and fill.
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001186 SkPaint* fillPaint = const_cast<SkPaint*>(&origPaint);
1187 SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
1188 if (paint->getStyle() != SkPaint::kFill_Style) {
1189 paint.writable()->setStyle(SkPaint::kFill_Style);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001190 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001191
bungeman@google.comb29c8832011-10-10 13:19:10 +00001192 this->internalDrawRect(d, r, false, *fillPaint);
1193}
1194
1195void SkXPSDevice::drawRect(const SkDraw& d,
1196 const SkRect& r,
1197 const SkPaint& paint) {
1198 this->internalDrawRect(d, r, true, paint);
1199}
1200
scroggo@google.comcac8d012013-11-12 17:10:02 +00001201void SkXPSDevice::drawRRect(const SkDraw& d,
1202 const SkRRect& rr,
1203 const SkPaint& paint) {
1204 SkPath path;
1205 path.addRRect(rr);
halcanary96fcdcc2015-08-27 07:41:13 -07001206 this->drawPath(d, path, paint, nullptr, true);
scroggo@google.comcac8d012013-11-12 17:10:02 +00001207}
1208
bungeman@google.comb29c8832011-10-10 13:19:10 +00001209void SkXPSDevice::internalDrawRect(const SkDraw& d,
1210 const SkRect& r,
1211 bool transformRect,
1212 const SkPaint& paint) {
1213 //Exit early if there is nothing to draw.
reed1e7f5e72016-04-27 07:49:17 -07001214 if (d.fRC->isEmpty() ||
halcanary96fcdcc2015-08-27 07:41:13 -07001215 (paint.getAlpha() == 0 && paint.getXfermode() == nullptr)) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001216 return;
1217 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001218
bungeman@google.comb29c8832011-10-10 13:19:10 +00001219 //Path the rect if we can't optimize it.
1220 if (rect_must_be_pathed(paint, *d.fMatrix)) {
1221 SkPath tmp;
1222 tmp.addRect(r);
1223 tmp.setFillType(SkPath::kWinding_FillType);
halcanary96fcdcc2015-08-27 07:41:13 -07001224 this->drawPath(d, tmp, paint, nullptr, true);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001225 return;
1226 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001227
bungeman@google.comb29c8832011-10-10 13:19:10 +00001228 //Create the shaded path.
1229 SkTScopedComPtr<IXpsOMPath> shadedPath;
1230 HRVM(this->fXpsFactory->CreatePath(&shadedPath),
1231 "Could not create shaded path for rect.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001232
bungeman@google.comb29c8832011-10-10 13:19:10 +00001233 //Create the shaded geometry.
1234 SkTScopedComPtr<IXpsOMGeometry> shadedGeometry;
1235 HRVM(this->fXpsFactory->CreateGeometry(&shadedGeometry),
1236 "Could not create shaded geometry for rect.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001237
bungeman@google.comb29c8832011-10-10 13:19:10 +00001238 //Add the geometry to the shaded path.
1239 HRVM(shadedPath->SetGeometryLocal(shadedGeometry.get()),
1240 "Could not set shaded geometry for rect.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001241
bungeman@google.comb29c8832011-10-10 13:19:10 +00001242 //Set the brushes.
1243 BOOL fill = FALSE;
1244 BOOL stroke = FALSE;
1245 HRV(this->shadePath(shadedPath.get(), paint, *d.fMatrix, &fill, &stroke));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001246
bungeman@google.comb29c8832011-10-10 13:19:10 +00001247 bool xpsTransformsPath = true;
1248 //Transform the geometry.
1249 if (transformRect && xpsTransformsPath) {
1250 SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform;
1251 HRV(this->createXpsTransform(*d.fMatrix, &xpsTransform));
1252 if (xpsTransform.get()) {
1253 HRVM(shadedGeometry->SetTransformLocal(xpsTransform.get()),
1254 "Could not set transform for rect.");
1255 } else {
1256 xpsTransformsPath = false;
1257 }
1258 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001259
bungeman@google.comb29c8832011-10-10 13:19:10 +00001260 //Create the figure.
1261 SkTScopedComPtr<IXpsOMGeometryFigure> rectFigure;
1262 {
1263 SkPoint points[4] = {
1264 { r.fLeft, r.fTop },
1265 { r.fLeft, r.fBottom },
1266 { r.fRight, r.fBottom },
1267 { r.fRight, r.fTop },
1268 };
1269 if (!xpsTransformsPath && transformRect) {
1270 d.fMatrix->mapPoints(points, SK_ARRAY_COUNT(points));
1271 }
1272 HRV(this->createXpsQuad(points, stroke, fill, &rectFigure));
1273 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001274
bungeman@google.comb29c8832011-10-10 13:19:10 +00001275 //Get the figures of the shaded geometry.
1276 SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures;
1277 HRVM(shadedGeometry->GetFigures(&shadedFigures),
1278 "Could not get shaded figures for rect.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001279
bungeman@google.comb29c8832011-10-10 13:19:10 +00001280 //Add the figure to the shaded geometry figures.
1281 HRVM(shadedFigures->Append(rectFigure.get()),
1282 "Could not add shaded figure for rect.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001283
bungeman@google.comb29c8832011-10-10 13:19:10 +00001284 HRV(this->clip(shadedPath.get(), d));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001285
bungeman@google.comb29c8832011-10-10 13:19:10 +00001286 //Add the shaded path to the current visuals.
1287 SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals;
1288 HRVM(this->fCurrentXpsCanvas->GetVisuals(&currentVisuals),
1289 "Could not get current visuals for rect.");
1290 HRVM(currentVisuals->Append(shadedPath.get()),
1291 "Could not add rect to current visuals.");
1292}
1293
1294static HRESULT close_figure(const SkTDArray<XPS_SEGMENT_TYPE>& segmentTypes,
1295 const SkTDArray<BOOL>& segmentStrokes,
1296 const SkTDArray<FLOAT>& segmentData,
1297 BOOL stroke, BOOL fill,
1298 IXpsOMGeometryFigure* figure,
1299 IXpsOMGeometryFigureCollection* figures) {
1300 // Add the segment data to the figure.
1301 HRM(figure->SetSegments(segmentTypes.count(), segmentData.count(),
1302 segmentTypes.begin() , segmentData.begin(),
1303 segmentStrokes.begin()),
1304 "Could not set path segments.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001305
bungeman@google.comb29c8832011-10-10 13:19:10 +00001306 // Set the closed and filled properties of the figure.
1307 HRM(figure->SetIsClosed(stroke), "Could not set path closed.");
1308 HRM(figure->SetIsFilled(fill), "Could not set path fill.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001309
bungeman@google.comb29c8832011-10-10 13:19:10 +00001310 // Add the figure created above to this geometry.
1311 HRM(figures->Append(figure), "Could not add path to geometry.");
1312 return S_OK;
1313}
1314
1315HRESULT SkXPSDevice::addXpsPathGeometry(
1316 IXpsOMGeometryFigureCollection* xpsFigures,
1317 BOOL stroke, BOOL fill, const SkPath& path) {
1318 SkTDArray<XPS_SEGMENT_TYPE> segmentTypes;
1319 SkTDArray<BOOL> segmentStrokes;
1320 SkTDArray<FLOAT> segmentData;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001321
bungeman@google.comb29c8832011-10-10 13:19:10 +00001322 SkTScopedComPtr<IXpsOMGeometryFigure> xpsFigure;
1323 SkPath::Iter iter(path, true);
1324 SkPoint points[4];
1325 SkPath::Verb verb;
1326 while ((verb = iter.next(points)) != SkPath::kDone_Verb) {
1327 switch (verb) {
1328 case SkPath::kMove_Verb: {
bsalomon49f085d2014-09-05 13:34:00 -07001329 if (xpsFigure.get()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001330 HR(close_figure(segmentTypes, segmentStrokes, segmentData,
1331 stroke, fill,
1332 xpsFigure.get() , xpsFigures));
1333 xpsFigure.reset();
1334 segmentTypes.rewind();
1335 segmentStrokes.rewind();
1336 segmentData.rewind();
1337 }
1338 // Define the start point.
1339 XPS_POINT startPoint = xps_point(points[0]);
1340 // Create the figure.
1341 HRM(this->fXpsFactory->CreateGeometryFigure(&startPoint,
1342 &xpsFigure),
1343 "Could not create path geometry figure.");
1344 break;
1345 }
1346 case SkPath::kLine_Verb:
1347 if (iter.isCloseLine()) break; //ignore the line, auto-closed
1348 segmentTypes.push(XPS_SEGMENT_TYPE_LINE);
1349 segmentStrokes.push(stroke);
1350 segmentData.push(SkScalarToFLOAT(points[1].fX));
1351 segmentData.push(SkScalarToFLOAT(points[1].fY));
1352 break;
1353 case SkPath::kQuad_Verb:
1354 segmentTypes.push(XPS_SEGMENT_TYPE_QUADRATIC_BEZIER);
1355 segmentStrokes.push(stroke);
1356 segmentData.push(SkScalarToFLOAT(points[1].fX));
1357 segmentData.push(SkScalarToFLOAT(points[1].fY));
1358 segmentData.push(SkScalarToFLOAT(points[2].fX));
1359 segmentData.push(SkScalarToFLOAT(points[2].fY));
1360 break;
1361 case SkPath::kCubic_Verb:
1362 segmentTypes.push(XPS_SEGMENT_TYPE_BEZIER);
1363 segmentStrokes.push(stroke);
1364 segmentData.push(SkScalarToFLOAT(points[1].fX));
1365 segmentData.push(SkScalarToFLOAT(points[1].fY));
1366 segmentData.push(SkScalarToFLOAT(points[2].fX));
1367 segmentData.push(SkScalarToFLOAT(points[2].fY));
1368 segmentData.push(SkScalarToFLOAT(points[3].fX));
1369 segmentData.push(SkScalarToFLOAT(points[3].fY));
1370 break;
halcanary47ef4d52015-03-03 09:13:09 -08001371 case SkPath::kConic_Verb: {
1372 const SkScalar tol = SK_Scalar1 / 4;
1373 SkAutoConicToQuads converter;
1374 const SkPoint* quads =
1375 converter.computeQuads(points, iter.conicWeight(), tol);
1376 for (int i = 0; i < converter.countQuads(); ++i) {
1377 segmentTypes.push(XPS_SEGMENT_TYPE_QUADRATIC_BEZIER);
1378 segmentStrokes.push(stroke);
1379 segmentData.push(SkScalarToFLOAT(quads[2 * i + 1].fX));
1380 segmentData.push(SkScalarToFLOAT(quads[2 * i + 1].fY));
1381 segmentData.push(SkScalarToFLOAT(quads[2 * i + 2].fX));
1382 segmentData.push(SkScalarToFLOAT(quads[2 * i + 2].fY));
1383 }
1384 break;
1385 }
bungeman@google.comb29c8832011-10-10 13:19:10 +00001386 case SkPath::kClose_Verb:
1387 // we ignore these, and just get the whole segment from
1388 // the corresponding line/quad/cubic verbs
1389 break;
1390 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00001391 SkDEBUGFAIL("unexpected verb");
bungeman@google.comb29c8832011-10-10 13:19:10 +00001392 break;
1393 }
1394 }
bsalomon49f085d2014-09-05 13:34:00 -07001395 if (xpsFigure.get()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001396 HR(close_figure(segmentTypes, segmentStrokes, segmentData,
1397 stroke, fill,
1398 xpsFigure.get(), xpsFigures));
1399 }
1400 return S_OK;
1401}
1402
bungeman@google.comb29c8832011-10-10 13:19:10 +00001403void SkXPSDevice::convertToPpm(const SkMaskFilter* filter,
1404 SkMatrix* matrix,
1405 SkVector* ppuScale,
1406 const SkIRect& clip, SkIRect* clipIRect) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001407 //This action is in unit space, but the ppm is specified in physical space.
reed80ea19c2015-05-12 10:37:34 -07001408 ppuScale->set(fCurrentPixelsPerMeter.fX / fCurrentUnitsPerMeter.fX,
1409 fCurrentPixelsPerMeter.fY / fCurrentUnitsPerMeter.fY);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001410
bungeman@google.comb29c8832011-10-10 13:19:10 +00001411 matrix->postScale(ppuScale->fX, ppuScale->fY);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001412
bungeman@google.comb29c8832011-10-10 13:19:10 +00001413 const SkIRect& irect = clip;
1414 SkRect clipRect = SkRect::MakeLTRB(
1415 SkScalarMul(SkIntToScalar(irect.fLeft), ppuScale->fX),
1416 SkScalarMul(SkIntToScalar(irect.fTop), ppuScale->fY),
1417 SkScalarMul(SkIntToScalar(irect.fRight), ppuScale->fX),
1418 SkScalarMul(SkIntToScalar(irect.fBottom), ppuScale->fY));
1419 clipRect.roundOut(clipIRect);
1420}
1421
1422HRESULT SkXPSDevice::applyMask(const SkDraw& d,
1423 const SkMask& mask,
1424 const SkVector& ppuScale,
1425 IXpsOMPath* shadedPath) {
1426 //Get the geometry object.
1427 SkTScopedComPtr<IXpsOMGeometry> shadedGeometry;
1428 HRM(shadedPath->GetGeometry(&shadedGeometry),
1429 "Could not get mask shaded geometry.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001430
bungeman@google.comb29c8832011-10-10 13:19:10 +00001431 //Get the figures from the geometry.
1432 SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures;
1433 HRM(shadedGeometry->GetFigures(&shadedFigures),
1434 "Could not get mask shaded figures.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001435
bungeman@google.comb29c8832011-10-10 13:19:10 +00001436 SkMatrix m;
1437 m.reset();
1438 m.setTranslate(SkIntToScalar(mask.fBounds.fLeft),
1439 SkIntToScalar(mask.fBounds.fTop));
1440 m.postScale(SkScalarInvert(ppuScale.fX), SkScalarInvert(ppuScale.fY));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001441
bungeman@google.comb29c8832011-10-10 13:19:10 +00001442 SkShader::TileMode xy[2];
1443 xy[0] = (SkShader::TileMode)3;
1444 xy[1] = (SkShader::TileMode)3;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001445
bungeman@google.comb29c8832011-10-10 13:19:10 +00001446 SkBitmap bm;
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +00001447 bm.installMaskPixels(mask);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001448
bungeman@google.comb29c8832011-10-10 13:19:10 +00001449 SkTScopedComPtr<IXpsOMTileBrush> maskBrush;
1450 HR(this->createXpsImageBrush(bm, m, xy, 0xFF, &maskBrush));
1451 HRM(shadedPath->SetOpacityMaskBrushLocal(maskBrush.get()),
1452 "Could not set mask.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001453
bungeman@google.comb29c8832011-10-10 13:19:10 +00001454 const SkRect universeRect = SkRect::MakeLTRB(0, 0,
1455 this->fCurrentCanvasSize.fWidth, this->fCurrentCanvasSize.fHeight);
1456 SkTScopedComPtr<IXpsOMGeometryFigure> shadedFigure;
1457 HRM(this->createXpsRect(universeRect, FALSE, TRUE, &shadedFigure),
1458 "Could not create mask shaded figure.");
1459 HRM(shadedFigures->Append(shadedFigure.get()),
1460 "Could not add mask shaded figure.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001461
bungeman@google.comb29c8832011-10-10 13:19:10 +00001462 HR(this->clip(shadedPath, d));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001463
bungeman@google.comb29c8832011-10-10 13:19:10 +00001464 //Add the path to the active visual collection.
1465 SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals;
1466 HRM(this->fCurrentXpsCanvas->GetVisuals(&currentVisuals),
1467 "Could not get mask current visuals.");
1468 HRM(currentVisuals->Append(shadedPath),
1469 "Could not add masked shaded path to current visuals.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001470
bungeman@google.comb29c8832011-10-10 13:19:10 +00001471 return S_OK;
1472}
1473
1474HRESULT SkXPSDevice::shadePath(IXpsOMPath* shadedPath,
1475 const SkPaint& shaderPaint,
1476 const SkMatrix& matrix,
1477 BOOL* fill, BOOL* stroke) {
1478 *fill = FALSE;
1479 *stroke = FALSE;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001480
bungeman@google.comb29c8832011-10-10 13:19:10 +00001481 const SkPaint::Style style = shaderPaint.getStyle();
1482 const bool hasFill = SkPaint::kFill_Style == style
1483 || SkPaint::kStrokeAndFill_Style == style;
1484 const bool hasStroke = SkPaint::kStroke_Style == style
1485 || SkPaint::kStrokeAndFill_Style == style;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001486
bungeman@google.comb29c8832011-10-10 13:19:10 +00001487 //TODO(bungeman): use dictionaries and lookups.
1488 if (hasFill) {
1489 *fill = TRUE;
1490 SkTScopedComPtr<IXpsOMBrush> fillBrush;
1491 HR(this->createXpsBrush(shaderPaint, &fillBrush, &matrix));
1492 HRM(shadedPath->SetFillBrushLocal(fillBrush.get()),
1493 "Could not set fill for shaded path.");
1494 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001495
bungeman@google.comb29c8832011-10-10 13:19:10 +00001496 if (hasStroke) {
1497 *stroke = TRUE;
1498 SkTScopedComPtr<IXpsOMBrush> strokeBrush;
1499 HR(this->createXpsBrush(shaderPaint, &strokeBrush, &matrix));
1500 HRM(shadedPath->SetStrokeBrushLocal(strokeBrush.get()),
1501 "Could not set stroke brush for shaded path.");
1502 HRM(shadedPath->SetStrokeThickness(
1503 SkScalarToFLOAT(shaderPaint.getStrokeWidth())),
1504 "Could not set shaded path stroke thickness.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001505
bungeman@google.comb29c8832011-10-10 13:19:10 +00001506 if (0 == shaderPaint.getStrokeWidth()) {
1507 //XPS hair width is a hack. (XPS Spec 11.6.12).
1508 SkTScopedComPtr<IXpsOMDashCollection> dashes;
1509 HRM(shadedPath->GetStrokeDashes(&dashes),
1510 "Could not set dashes for shaded path.");
1511 XPS_DASH dash;
1512 dash.length = 1.0;
1513 dash.gap = 0.0;
1514 HRM(dashes->Append(&dash), "Could not add dashes to shaded path.");
1515 HRM(shadedPath->SetStrokeDashOffset(-2.0),
1516 "Could not set dash offset for shaded path.");
1517 }
1518 }
1519 return S_OK;
1520}
1521
1522void SkXPSDevice::drawPath(const SkDraw& d,
1523 const SkPath& platonicPath,
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001524 const SkPaint& origPaint,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001525 const SkMatrix* prePathMatrix,
1526 bool pathIsMutable) {
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001527 SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
1528
bungeman@google.comb29c8832011-10-10 13:19:10 +00001529 // nothing to draw
reed1e7f5e72016-04-27 07:49:17 -07001530 if (d.fRC->isEmpty() ||
halcanary96fcdcc2015-08-27 07:41:13 -07001531 (paint->getAlpha() == 0 && paint->getXfermode() == nullptr)) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001532 return;
1533 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001534
bungeman@google.comb29c8832011-10-10 13:19:10 +00001535 SkPath modifiedPath;
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001536 const bool paintHasPathEffect = paint->getPathEffect()
1537 || paint->getStyle() != SkPaint::kFill_Style;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001538
bungeman@google.comb29c8832011-10-10 13:19:10 +00001539 //Apply pre-path matrix [Platonic-path -> Skeletal-path].
1540 SkMatrix matrix = *d.fMatrix;
1541 SkPath* skeletalPath = const_cast<SkPath*>(&platonicPath);
1542 if (prePathMatrix) {
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001543 if (paintHasPathEffect || paint->getRasterizer()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001544 if (!pathIsMutable) {
1545 skeletalPath = &modifiedPath;
1546 pathIsMutable = true;
1547 }
1548 platonicPath.transform(*prePathMatrix, skeletalPath);
1549 } else {
commit-bot@chromium.org92362382014-03-18 12:51:48 +00001550 matrix.preConcat(*prePathMatrix);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001551 }
1552 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001553
bungeman@google.comb29c8832011-10-10 13:19:10 +00001554 //Apply path effect [Skeletal-path -> Fillable-path].
1555 SkPath* fillablePath = skeletalPath;
1556 if (paintHasPathEffect) {
1557 if (!pathIsMutable) {
1558 fillablePath = &modifiedPath;
1559 pathIsMutable = true;
1560 }
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001561 bool fill = paint->getFillPath(*skeletalPath, fillablePath);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001562
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001563 SkPaint* writablePaint = paint.writable();
halcanary96fcdcc2015-08-27 07:41:13 -07001564 writablePaint->setPathEffect(nullptr);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001565 if (fill) {
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001566 writablePaint->setStyle(SkPaint::kFill_Style);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001567 } else {
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001568 writablePaint->setStyle(SkPaint::kStroke_Style);
1569 writablePaint->setStrokeWidth(0);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001570 }
1571 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001572
bungeman@google.comb29c8832011-10-10 13:19:10 +00001573 //Create the shaded path. This will be the path which is painted.
1574 SkTScopedComPtr<IXpsOMPath> shadedPath;
1575 HRVM(this->fXpsFactory->CreatePath(&shadedPath),
1576 "Could not create shaded path for path.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001577
bungeman@google.comb29c8832011-10-10 13:19:10 +00001578 //Create the geometry for the shaded path.
1579 SkTScopedComPtr<IXpsOMGeometry> shadedGeometry;
1580 HRVM(this->fXpsFactory->CreateGeometry(&shadedGeometry),
1581 "Could not create shaded geometry for path.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001582
bungeman@google.comb29c8832011-10-10 13:19:10 +00001583 //Add the geometry to the shaded path.
1584 HRVM(shadedPath->SetGeometryLocal(shadedGeometry.get()),
1585 "Could not add the shaded geometry to shaded path.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001586
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001587 SkRasterizer* rasterizer = paint->getRasterizer();
1588 SkMaskFilter* filter = paint->getMaskFilter();
bungeman@google.comd998cbd2012-04-05 18:57:53 +00001589
1590 //Determine if we will draw or shade and mask.
1591 if (rasterizer || filter) {
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001592 if (paint->getStyle() != SkPaint::kFill_Style) {
1593 paint.writable()->setStyle(SkPaint::kFill_Style);
bungeman@google.comd998cbd2012-04-05 18:57:53 +00001594 }
1595 }
1596
bungeman@google.comb29c8832011-10-10 13:19:10 +00001597 //Set the brushes.
1598 BOOL fill;
1599 BOOL stroke;
1600 HRV(this->shadePath(shadedPath.get(),
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001601 *paint,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001602 *d.fMatrix,
1603 &fill,
1604 &stroke));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001605
bungeman@google.comb29c8832011-10-10 13:19:10 +00001606 //Rasterizer
bungeman@google.comd998cbd2012-04-05 18:57:53 +00001607 if (rasterizer) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001608 SkIRect clipIRect;
1609 SkVector ppuScale;
1610 this->convertToPpm(filter,
1611 &matrix,
1612 &ppuScale,
reed1e7f5e72016-04-27 07:49:17 -07001613 d.fRC->getBounds(),
bungeman@google.comb29c8832011-10-10 13:19:10 +00001614 &clipIRect);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001615
halcanary96fcdcc2015-08-27 07:41:13 -07001616 SkMask* mask = nullptr;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001617
bungeman@google.comb29c8832011-10-10 13:19:10 +00001618 //[Fillable-path -> Mask]
1619 SkMask rasteredMask;
bungeman@google.comd998cbd2012-04-05 18:57:53 +00001620 if (rasterizer->rasterize(
bungeman@google.comb29c8832011-10-10 13:19:10 +00001621 *fillablePath,
1622 matrix,
1623 &clipIRect,
1624 filter, //just to compute how much to draw.
1625 &rasteredMask,
1626 SkMask::kComputeBoundsAndRenderImage_CreateMode)) {
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001627
bungeman@google.comb29c8832011-10-10 13:19:10 +00001628 SkAutoMaskFreeImage rasteredAmi(rasteredMask.fImage);
1629 mask = &rasteredMask;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001630
bungeman@google.comb29c8832011-10-10 13:19:10 +00001631 //[Mask -> Mask]
1632 SkMask filteredMask;
robertphillipse80eb922015-12-17 11:33:12 -08001633 if (filter && filter->filterMask(&filteredMask, *mask, *d.fMatrix, nullptr)) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001634 mask = &filteredMask;
bungeman@google.comb29c8832011-10-10 13:19:10 +00001635 }
1636 SkAutoMaskFreeImage filteredAmi(filteredMask.fImage);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001637
bungeman@google.comb29c8832011-10-10 13:19:10 +00001638 //Draw mask.
1639 HRV(this->applyMask(d, *mask, ppuScale, shadedPath.get()));
1640 }
1641 return;
1642 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001643
bungeman@google.comb29c8832011-10-10 13:19:10 +00001644 //Mask filter
1645 if (filter) {
1646 SkIRect clipIRect;
1647 SkVector ppuScale;
1648 this->convertToPpm(filter,
1649 &matrix,
1650 &ppuScale,
reed1e7f5e72016-04-27 07:49:17 -07001651 d.fRC->getBounds(),
bungeman@google.comb29c8832011-10-10 13:19:10 +00001652 &clipIRect);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001653
bungeman@google.comb29c8832011-10-10 13:19:10 +00001654 //[Fillable-path -> Pixel-path]
1655 SkPath* pixelPath = pathIsMutable ? fillablePath : &modifiedPath;
1656 fillablePath->transform(matrix, pixelPath);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001657
halcanary96fcdcc2015-08-27 07:41:13 -07001658 SkMask* mask = nullptr;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001659
bungeman@google.comb29c8832011-10-10 13:19:10 +00001660 //[Pixel-path -> Mask]
1661 SkMask rasteredMask;
1662 if (SkDraw::DrawToMask(
1663 *pixelPath,
1664 &clipIRect,
1665 filter, //just to compute how much to draw.
1666 &matrix,
1667 &rasteredMask,
junov@chromium.org2ac4ef52012-04-04 15:16:51 +00001668 SkMask::kComputeBoundsAndRenderImage_CreateMode,
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001669 paint->getStyle())) {
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001670
bungeman@google.comb29c8832011-10-10 13:19:10 +00001671 SkAutoMaskFreeImage rasteredAmi(rasteredMask.fImage);
1672 mask = &rasteredMask;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001673
bungeman@google.comb29c8832011-10-10 13:19:10 +00001674 //[Mask -> Mask]
1675 SkMask filteredMask;
robertphillipse80eb922015-12-17 11:33:12 -08001676 if (filter->filterMask(&filteredMask, rasteredMask, matrix, nullptr)) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001677 mask = &filteredMask;
bungeman@google.comb29c8832011-10-10 13:19:10 +00001678 }
1679 SkAutoMaskFreeImage filteredAmi(filteredMask.fImage);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001680
bungeman@google.comb29c8832011-10-10 13:19:10 +00001681 //Draw mask.
1682 HRV(this->applyMask(d, *mask, ppuScale, shadedPath.get()));
1683 }
1684 return;
1685 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001686
bungeman@google.comb29c8832011-10-10 13:19:10 +00001687 //Get the figures from the shaded geometry.
1688 SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures;
1689 HRVM(shadedGeometry->GetFigures(&shadedFigures),
1690 "Could not get shaded figures for shaded path.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001691
bungeman@google.comb29c8832011-10-10 13:19:10 +00001692 bool xpsTransformsPath = true;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001693
bungeman@google.comb29c8832011-10-10 13:19:10 +00001694 //Set the fill rule.
bungeman76db31a2014-08-25 07:31:53 -07001695 SkPath* xpsCompatiblePath = fillablePath;
bungeman@google.comb29c8832011-10-10 13:19:10 +00001696 XPS_FILL_RULE xpsFillRule;
bungeman76db31a2014-08-25 07:31:53 -07001697 switch (fillablePath->getFillType()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001698 case SkPath::kWinding_FillType:
1699 xpsFillRule = XPS_FILL_RULE_NONZERO;
1700 break;
1701 case SkPath::kEvenOdd_FillType:
1702 xpsFillRule = XPS_FILL_RULE_EVENODD;
1703 break;
1704 case SkPath::kInverseWinding_FillType: {
bungeman76db31a2014-08-25 07:31:53 -07001705 //[Fillable-path (inverse winding) -> XPS-path (inverse even odd)]
1706 if (!pathIsMutable) {
1707 xpsCompatiblePath = &modifiedPath;
1708 pathIsMutable = true;
1709 }
1710 if (!Simplify(*fillablePath, xpsCompatiblePath)) {
1711 SkDEBUGF(("Could not simplify inverse winding path."));
1712 return;
1713 }
bungeman@google.comb29c8832011-10-10 13:19:10 +00001714 }
bungeman76db31a2014-08-25 07:31:53 -07001715 // The xpsCompatiblePath is noW inverse even odd, so fall through.
bungeman@google.comb29c8832011-10-10 13:19:10 +00001716 case SkPath::kInverseEvenOdd_FillType: {
1717 const SkRect universe = SkRect::MakeLTRB(
1718 0, 0,
1719 this->fCurrentCanvasSize.fWidth,
1720 this->fCurrentCanvasSize.fHeight);
1721 SkTScopedComPtr<IXpsOMGeometryFigure> addOneFigure;
1722 HRV(this->createXpsRect(universe, FALSE, TRUE, &addOneFigure));
1723 HRVM(shadedFigures->Append(addOneFigure.get()),
1724 "Could not add even-odd flip figure to shaded path.");
1725 xpsTransformsPath = false;
1726 xpsFillRule = XPS_FILL_RULE_EVENODD;
1727 break;
1728 }
1729 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00001730 SkDEBUGFAIL("Unknown SkPath::FillType.");
bungeman@google.comb29c8832011-10-10 13:19:10 +00001731 }
1732 HRVM(shadedGeometry->SetFillRule(xpsFillRule),
1733 "Could not set fill rule for shaded path.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001734
bungeman@google.comb29c8832011-10-10 13:19:10 +00001735 //Create the XPS transform, if possible.
1736 if (xpsTransformsPath) {
1737 SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform;
1738 HRV(this->createXpsTransform(matrix, &xpsTransform));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001739
bungeman@google.comb29c8832011-10-10 13:19:10 +00001740 if (xpsTransform.get()) {
1741 HRVM(shadedGeometry->SetTransformLocal(xpsTransform.get()),
1742 "Could not set transform on shaded path.");
1743 } else {
1744 xpsTransformsPath = false;
1745 }
1746 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001747
bungeman76db31a2014-08-25 07:31:53 -07001748 SkPath* devicePath = xpsCompatiblePath;
bungeman@google.comb29c8832011-10-10 13:19:10 +00001749 if (!xpsTransformsPath) {
1750 //[Fillable-path -> Device-path]
bungeman76db31a2014-08-25 07:31:53 -07001751 devicePath = pathIsMutable ? xpsCompatiblePath : &modifiedPath;
1752 xpsCompatiblePath->transform(matrix, devicePath);
bungeman@google.comb29c8832011-10-10 13:19:10 +00001753 }
1754 HRV(this->addXpsPathGeometry(shadedFigures.get(),
1755 stroke, fill, *devicePath));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001756
bungeman@google.comb29c8832011-10-10 13:19:10 +00001757 HRV(this->clip(shadedPath.get(), d));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001758
bungeman@google.comb29c8832011-10-10 13:19:10 +00001759 //Add the path to the active visual collection.
1760 SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals;
1761 HRVM(this->fCurrentXpsCanvas->GetVisuals(&currentVisuals),
1762 "Could not get current visuals for shaded path.");
1763 HRVM(currentVisuals->Append(shadedPath.get()),
1764 "Could not add shaded path to current visuals.");
1765}
1766
1767HRESULT SkXPSDevice::clip(IXpsOMVisual* xpsVisual, const SkDraw& d) {
1768 SkPath clipPath;
reed1e7f5e72016-04-27 07:49:17 -07001769 if (d.fRC->isBW()) {
1770 SkAssertResult(d.fRC->bwRgn().getBoundaryPath(&clipPath));
1771 } else {
1772 // Don't have a way to turn a AAClip into a path, so we just use the bounds.
1773 // TODO: consider using fClipStack instead?
1774 clipPath.addRect(SkRect::Make(d.fRC->getBounds()));
1775 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001776
bungeman@google.comb29c8832011-10-10 13:19:10 +00001777 return this->clipToPath(xpsVisual, clipPath, XPS_FILL_RULE_EVENODD);
1778}
1779HRESULT SkXPSDevice::clipToPath(IXpsOMVisual* xpsVisual,
1780 const SkPath& clipPath,
1781 XPS_FILL_RULE fillRule) {
1782 //Create the geometry.
1783 SkTScopedComPtr<IXpsOMGeometry> clipGeometry;
1784 HRM(this->fXpsFactory->CreateGeometry(&clipGeometry),
1785 "Could not create clip geometry.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001786
bungeman@google.comb29c8832011-10-10 13:19:10 +00001787 //Get the figure collection of the geometry.
1788 SkTScopedComPtr<IXpsOMGeometryFigureCollection> clipFigures;
1789 HRM(clipGeometry->GetFigures(&clipFigures),
1790 "Could not get the clip figures.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001791
bungeman@google.comb29c8832011-10-10 13:19:10 +00001792 //Create the figures into the geometry.
1793 HR(this->addXpsPathGeometry(
1794 clipFigures.get(),
1795 FALSE, TRUE, clipPath));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001796
bungeman@google.comb29c8832011-10-10 13:19:10 +00001797 HRM(clipGeometry->SetFillRule(fillRule),
1798 "Could not set fill rule.");
1799 HRM(xpsVisual->SetClipGeometryLocal(clipGeometry.get()),
1800 "Could not set clip geometry.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001801
bungeman@google.comb29c8832011-10-10 13:19:10 +00001802 return S_OK;
1803}
1804
1805void SkXPSDevice::drawBitmap(const SkDraw& d, const SkBitmap& bitmap,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001806 const SkMatrix& matrix, const SkPaint& paint) {
reed1e7f5e72016-04-27 07:49:17 -07001807 if (d.fRC->isEmpty()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001808 return;
1809 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001810
bungeman@google.comb29c8832011-10-10 13:19:10 +00001811 SkIRect srcRect;
robertphillips@google.com9bf380c2013-07-25 12:10:42 +00001812 srcRect.set(0, 0, bitmap.width(), bitmap.height());
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001813
bungeman@google.comb29c8832011-10-10 13:19:10 +00001814 //Create the new shaded path.
1815 SkTScopedComPtr<IXpsOMPath> shadedPath;
1816 HRVM(this->fXpsFactory->CreatePath(&shadedPath),
1817 "Could not create path for bitmap.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001818
bungeman@google.comb29c8832011-10-10 13:19:10 +00001819 //Create the shaded geometry.
1820 SkTScopedComPtr<IXpsOMGeometry> shadedGeometry;
1821 HRVM(this->fXpsFactory->CreateGeometry(&shadedGeometry),
1822 "Could not create geometry for bitmap.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001823
bungeman@google.comb29c8832011-10-10 13:19:10 +00001824 //Add the shaded geometry to the shaded path.
1825 HRVM(shadedPath->SetGeometryLocal(shadedGeometry.get()),
1826 "Could not set the geometry for bitmap.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001827
bungeman@google.comb29c8832011-10-10 13:19:10 +00001828 //Get the shaded figures from the shaded geometry.
1829 SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures;
1830 HRVM(shadedGeometry->GetFigures(&shadedFigures),
1831 "Could not get the figures for bitmap.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001832
bungeman@google.comb29c8832011-10-10 13:19:10 +00001833 SkMatrix transform = matrix;
1834 transform.postConcat(*d.fMatrix);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001835
bungeman@google.comb29c8832011-10-10 13:19:10 +00001836 SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform;
1837 HRV(this->createXpsTransform(transform, &xpsTransform));
1838 if (xpsTransform.get()) {
1839 HRVM(shadedGeometry->SetTransformLocal(xpsTransform.get()),
1840 "Could not set transform for bitmap.");
1841 } else {
1842 //TODO: perspective that bitmap!
1843 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001844
bungeman@google.comb29c8832011-10-10 13:19:10 +00001845 SkTScopedComPtr<IXpsOMGeometryFigure> rectFigure;
bsalomon49f085d2014-09-05 13:34:00 -07001846 if (xpsTransform.get()) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001847 const SkShader::TileMode xy[2] = {
1848 SkShader::kClamp_TileMode,
1849 SkShader::kClamp_TileMode,
1850 };
1851 SkTScopedComPtr<IXpsOMTileBrush> xpsImageBrush;
robertphillips@google.com9bf380c2013-07-25 12:10:42 +00001852 HRV(this->createXpsImageBrush(bitmap,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001853 transform,
1854 xy,
1855 paint.getAlpha(),
1856 &xpsImageBrush));
1857 HRVM(shadedPath->SetFillBrushLocal(xpsImageBrush.get()),
1858 "Could not set bitmap brush.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001859
bungeman@google.comb29c8832011-10-10 13:19:10 +00001860 const SkRect bitmapRect = SkRect::MakeLTRB(0, 0,
1861 SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height()));
1862 HRV(this->createXpsRect(bitmapRect, FALSE, TRUE, &rectFigure));
1863 }
1864 HRVM(shadedFigures->Append(rectFigure.get()),
1865 "Could not add bitmap figure.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001866
bungeman@google.comb29c8832011-10-10 13:19:10 +00001867 //Get the current visual collection and add the shaded path to it.
1868 SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals;
1869 HRVM(this->fCurrentXpsCanvas->GetVisuals(&currentVisuals),
1870 "Could not get current visuals for bitmap");
1871 HRVM(currentVisuals->Append(shadedPath.get()),
1872 "Could not add bitmap to current visuals.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001873
bungeman@google.comb29c8832011-10-10 13:19:10 +00001874 HRV(this->clip(shadedPath.get(), d));
1875}
1876
1877void SkXPSDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap,
1878 int x, int y,
1879 const SkPaint& paint) {
1880 //TODO: override this for XPS
1881 SkDEBUGF(("XPS drawSprite not yet implemented."));
1882}
1883
1884HRESULT SkXPSDevice::CreateTypefaceUse(const SkPaint& paint,
1885 TypefaceUse** typefaceUse) {
reed@google.com398de9a2013-03-21 21:43:51 +00001886 SkAutoResolveDefaultTypeface typeface(paint.getTypeface());
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001887
bungeman@google.comb29c8832011-10-10 13:19:10 +00001888 //Check cache.
reed@google.com398de9a2013-03-21 21:43:51 +00001889 const SkFontID typefaceID = typeface->uniqueID();
bungeman@google.comb29c8832011-10-10 13:19:10 +00001890 if (!this->fTypefaces.empty()) {
1891 TypefaceUse* current = &this->fTypefaces.front();
1892 const TypefaceUse* last = &this->fTypefaces.back();
1893 for (; current <= last; ++current) {
1894 if (current->typefaceId == typefaceID) {
1895 *typefaceUse = current;
1896 return S_OK;
1897 }
1898 }
1899 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001900
bungeman@google.comb29c8832011-10-10 13:19:10 +00001901 //TODO: create glyph only fonts
1902 //and let the host deal with what kind of font we're looking at.
1903 XPS_FONT_EMBEDDING embedding = XPS_FONT_EMBEDDING_RESTRICTED;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001904
bungeman@google.comb29c8832011-10-10 13:19:10 +00001905 SkTScopedComPtr<IStream> fontStream;
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00001906 int ttcIndex;
1907 SkStream* fontData = typeface->openStream(&ttcIndex);
bungeman@google.com635091f2013-10-01 15:03:18 +00001908 //TODO: cannot handle FON fonts.
bungeman@google.com8cddc8d2012-01-03 22:36:33 +00001909 HRM(SkIStream::CreateFromSkStream(fontData, true, &fontStream),
bungeman@google.comb29c8832011-10-10 13:19:10 +00001910 "Could not create font stream.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001911
bungeman@google.comb29c8832011-10-10 13:19:10 +00001912 const size_t size =
1913 SK_ARRAY_COUNT(L"/Resources/Fonts/" L_GUID_ID L".odttf");
1914 wchar_t buffer[size];
1915 wchar_t id[GUID_ID_LEN];
Ben Wagnerda5a1b82014-08-22 15:07:06 -04001916 HR(this->createId(id, GUID_ID_LEN));
bungeman@google.comb29c8832011-10-10 13:19:10 +00001917 swprintf_s(buffer, size, L"/Resources/Fonts/%s.odttf", id);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001918
bungeman@google.comb29c8832011-10-10 13:19:10 +00001919 SkTScopedComPtr<IOpcPartUri> partUri;
1920 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri),
1921 "Could not create font resource part uri.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001922
bungeman@google.comb29c8832011-10-10 13:19:10 +00001923 SkTScopedComPtr<IXpsOMFontResource> xpsFontResource;
1924 HRM(this->fXpsFactory->CreateFontResource(fontStream.get(),
1925 embedding,
1926 partUri.get(),
1927 FALSE,
1928 &xpsFontResource),
1929 "Could not create font resource.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001930
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00001931 //TODO: change openStream to return -1 for non-ttc, get rid of this.
1932 uint8_t* data = (uint8_t*)fontData->getMemoryBase();
1933 bool isTTC = (data &&
1934 fontData->getLength() >= sizeof(SkTTCFHeader) &&
1935 ((SkTTCFHeader*)data)->ttcTag == SkTTCFHeader::TAG);
1936
bungeman@google.comb29c8832011-10-10 13:19:10 +00001937 TypefaceUse& newTypefaceUse = this->fTypefaces.push_back();
1938 newTypefaceUse.typefaceId = typefaceID;
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00001939 newTypefaceUse.ttcIndex = isTTC ? ttcIndex : -1;
bungeman@google.comb29c8832011-10-10 13:19:10 +00001940 newTypefaceUse.fontData = fontData;
1941 newTypefaceUse.xpsFont = xpsFontResource.release();
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001942
robertphillips8e0c1502015-07-07 10:28:43 -07001943 SkAutoGlyphCache agc(paint, &this->surfaceProps(), &SkMatrix::I());
bungeman@google.comb29c8832011-10-10 13:19:10 +00001944 SkGlyphCache* glyphCache = agc.getCache();
1945 unsigned int glyphCount = glyphCache->getGlyphCount();
1946 newTypefaceUse.glyphsUsed = new SkBitSet(glyphCount);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001947
bungeman@google.comb29c8832011-10-10 13:19:10 +00001948 *typefaceUse = &newTypefaceUse;
1949 return S_OK;
1950}
1951
1952HRESULT SkXPSDevice::AddGlyphs(const SkDraw& d,
1953 IXpsOMObjectFactory* xpsFactory,
1954 IXpsOMCanvas* canvas,
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00001955 TypefaceUse* font,
bungeman@google.comb29c8832011-10-10 13:19:10 +00001956 LPCWSTR text,
1957 XPS_GLYPH_INDEX* xpsGlyphs,
1958 UINT32 xpsGlyphsLen,
1959 XPS_POINT *origin,
1960 FLOAT fontSize,
1961 XPS_STYLE_SIMULATION sims,
1962 const SkMatrix& transform,
1963 const SkPaint& paint) {
1964 SkTScopedComPtr<IXpsOMGlyphs> glyphs;
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00001965 HRM(xpsFactory->CreateGlyphs(font->xpsFont, &glyphs), "Could not create glyphs.");
1966 HRM(glyphs->SetFontFaceIndex(font->ttcIndex), "Could not set glyph font face index.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001967
bungeman@google.comb29c8832011-10-10 13:19:10 +00001968 //XPS uses affine transformations for everything...
1969 //...except positioning text.
1970 bool useCanvasForClip;
1971 if ((transform.getType() & ~SkMatrix::kTranslate_Mask) == 0) {
1972 origin->x += SkScalarToFLOAT(transform.getTranslateX());
1973 origin->y += SkScalarToFLOAT(transform.getTranslateY());
1974 useCanvasForClip = false;
1975 } else {
1976 SkTScopedComPtr<IXpsOMMatrixTransform> xpsMatrixToUse;
1977 HR(this->createXpsTransform(transform, &xpsMatrixToUse));
1978 if (xpsMatrixToUse.get()) {
1979 HRM(glyphs->SetTransformLocal(xpsMatrixToUse.get()),
1980 "Could not set transform matrix.");
1981 useCanvasForClip = true;
1982 } else {
mtklein@google.com330313a2013-08-22 15:37:26 +00001983 SkDEBUGFAIL("Attempt to add glyphs in perspective.");
bungeman@google.comb29c8832011-10-10 13:19:10 +00001984 useCanvasForClip = false;
1985 }
1986 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001987
bungeman@google.comb29c8832011-10-10 13:19:10 +00001988 SkTScopedComPtr<IXpsOMGlyphsEditor> glyphsEditor;
1989 HRM(glyphs->GetGlyphsEditor(&glyphsEditor), "Could not get glyph editor.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001990
bsalomon49f085d2014-09-05 13:34:00 -07001991 if (text) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001992 HRM(glyphsEditor->SetUnicodeString(text),
1993 "Could not set unicode string.");
1994 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00001995
bsalomon49f085d2014-09-05 13:34:00 -07001996 if (xpsGlyphs) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00001997 HRM(glyphsEditor->SetGlyphIndices(xpsGlyphsLen, xpsGlyphs),
1998 "Could not set glyphs.");
1999 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002000
bungeman@google.comb29c8832011-10-10 13:19:10 +00002001 HRM(glyphsEditor->ApplyEdits(), "Could not apply glyph edits.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002002
bungeman@google.comb29c8832011-10-10 13:19:10 +00002003 SkTScopedComPtr<IXpsOMBrush> xpsFillBrush;
2004 HR(this->createXpsBrush(
2005 paint,
2006 &xpsFillBrush,
halcanary96fcdcc2015-08-27 07:41:13 -07002007 useCanvasForClip ? nullptr : &transform));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002008
bungeman@google.comb29c8832011-10-10 13:19:10 +00002009 HRM(glyphs->SetFillBrushLocal(xpsFillBrush.get()),
2010 "Could not set fill brush.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002011
bungeman@google.comb29c8832011-10-10 13:19:10 +00002012 HRM(glyphs->SetOrigin(origin), "Could not set glyph origin.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002013
bungeman@google.comb29c8832011-10-10 13:19:10 +00002014 HRM(glyphs->SetFontRenderingEmSize(fontSize),
2015 "Could not set font size.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002016
bungeman@google.comb29c8832011-10-10 13:19:10 +00002017 HRM(glyphs->SetStyleSimulations(sims),
2018 "Could not set style simulations.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002019
bungeman@google.comb29c8832011-10-10 13:19:10 +00002020 SkTScopedComPtr<IXpsOMVisualCollection> visuals;
2021 HRM(canvas->GetVisuals(&visuals), "Could not get glyph canvas visuals.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002022
bungeman@google.comb29c8832011-10-10 13:19:10 +00002023 if (!useCanvasForClip) {
2024 HR(this->clip(glyphs.get(), d));
2025 HRM(visuals->Append(glyphs.get()), "Could not add glyphs to canvas.");
2026 } else {
2027 SkTScopedComPtr<IXpsOMCanvas> glyphCanvas;
2028 HRM(this->fXpsFactory->CreateCanvas(&glyphCanvas),
2029 "Could not create glyph canvas.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002030
bungeman@google.comb29c8832011-10-10 13:19:10 +00002031 SkTScopedComPtr<IXpsOMVisualCollection> glyphCanvasVisuals;
2032 HRM(glyphCanvas->GetVisuals(&glyphCanvasVisuals),
2033 "Could not get glyph visuals collection.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002034
bungeman@google.comb29c8832011-10-10 13:19:10 +00002035 HRM(glyphCanvasVisuals->Append(glyphs.get()),
2036 "Could not add glyphs to page.");
2037 HR(this->clip(glyphCanvas.get(), d));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002038
bungeman@google.comb29c8832011-10-10 13:19:10 +00002039 HRM(visuals->Append(glyphCanvas.get()),
2040 "Could not add glyph canvas to page.");
2041 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002042
bungeman@google.comb29c8832011-10-10 13:19:10 +00002043 return S_OK;
2044}
2045
herbbda26432015-11-24 08:37:01 -08002046static int num_glyph_guess(SkPaint::TextEncoding encoding, const void* text, size_t byteLength) {
2047 switch (encoding) {
2048 case SkPaint::kUTF8_TextEncoding:
2049 return SkUTF8_CountUnichars(static_cast<const char *>(text), byteLength);
2050 case SkPaint::kUTF16_TextEncoding:
2051 return SkUTF16_CountUnichars(static_cast<const uint16_t *>(text), SkToInt(byteLength));
2052 case SkPaint::kGlyphID_TextEncoding:
2053 return SkToInt(byteLength / 2);
2054 default:
djsollenf2b340f2016-01-29 08:51:04 -08002055 SK_ABORT("Invalid Text Encoding");
bungeman@google.comb29c8832011-10-10 13:19:10 +00002056 }
herbbda26432015-11-24 08:37:01 -08002057 return 0;
bungeman@google.comb29c8832011-10-10 13:19:10 +00002058}
2059
2060static bool text_must_be_pathed(const SkPaint& paint, const SkMatrix& matrix) {
2061 const SkPaint::Style style = paint.getStyle();
2062 return matrix.hasPerspective()
2063 || SkPaint::kStroke_Style == style
2064 || SkPaint::kStrokeAndFill_Style == style
2065 || paint.getMaskFilter()
2066 || paint.getRasterizer()
2067 ;
2068}
2069
herbbda26432015-11-24 08:37:01 -08002070typedef SkTDArray<XPS_GLYPH_INDEX> GlyphRun;
2071
2072class ProcessOneGlyph {
2073public:
2074 ProcessOneGlyph(FLOAT centemPerUnit, SkBitSet* glyphUse, GlyphRun* xpsGlyphs)
2075 : fCentemPerUnit(centemPerUnit)
2076 , fGlyphUse(glyphUse)
2077 , fXpsGlyphs(xpsGlyphs) { }
2078
2079 void operator()(const SkGlyph& glyph, SkPoint position, SkPoint) {
2080 SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0);
2081
2082 SkScalar x = position.fX;
2083 SkScalar y = position.fY;
2084
2085 XPS_GLYPH_INDEX* xpsGlyph = fXpsGlyphs->append();
2086 uint16_t glyphID = glyph.getGlyphID();
2087 fGlyphUse->setBit(glyphID, true);
2088 xpsGlyph->index = glyphID;
2089 if (1 == fXpsGlyphs->count()) {
2090 xpsGlyph->advanceWidth = 0.0f;
2091 xpsGlyph->horizontalOffset = SkScalarToFloat(x) * fCentemPerUnit;
2092 xpsGlyph->verticalOffset = SkScalarToFloat(y) * -fCentemPerUnit;
2093 }
2094 else {
2095 const XPS_GLYPH_INDEX& first = (*fXpsGlyphs)[0];
2096 xpsGlyph->advanceWidth = 0.0f;
2097 xpsGlyph->horizontalOffset = (SkScalarToFloat(x) * fCentemPerUnit)
2098 - first.horizontalOffset;
2099 xpsGlyph->verticalOffset = (SkScalarToFloat(y) * -fCentemPerUnit)
2100 - first.verticalOffset;
2101 }
2102 }
2103
2104private:
2105 /** [in] Advance width and offsets for glyphs measured in
2106 hundredths of the font em size (XPS Spec 5.1.3). */
2107 const FLOAT fCentemPerUnit;
2108 /** [in,out] The accumulated glyphs used in the current typeface. */
2109 SkBitSet* const fGlyphUse;
2110 /** [out] The glyphs to draw. */
2111 GlyphRun* const fXpsGlyphs;
2112};
2113
bungeman@google.comb29c8832011-10-10 13:19:10 +00002114void SkXPSDevice::drawText(const SkDraw& d,
2115 const void* text, size_t byteLen,
2116 SkScalar x, SkScalar y,
2117 const SkPaint& paint) {
2118 if (byteLen < 1) return;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002119
bungeman@google.comb29c8832011-10-10 13:19:10 +00002120 if (text_must_be_pathed(paint, *d.fMatrix)) {
2121 SkPath path;
2122 paint.getTextPath(text, byteLen, x, y, &path);
halcanary96fcdcc2015-08-27 07:41:13 -07002123 this->drawPath(d, path, paint, nullptr, true);
bungeman@google.comb29c8832011-10-10 13:19:10 +00002124 //TODO: add automation "text"
2125 return;
2126 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002127
bungeman@google.comb29c8832011-10-10 13:19:10 +00002128 TypefaceUse* typeface;
2129 HRV(CreateTypefaceUse(paint, &typeface));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002130
herbbda26432015-11-24 08:37:01 -08002131 const SkMatrix& matrix = SkMatrix::I();
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002132
herbbda26432015-11-24 08:37:01 -08002133 SkAutoGlyphCache autoCache(paint, &this->surfaceProps(), &matrix);
2134 SkGlyphCache* cache = autoCache.getCache();
reed@google.com089130c2011-12-12 21:52:18 +00002135
herbbda26432015-11-24 08:37:01 -08002136 // Advance width and offsets for glyphs measured in hundredths of the font em size
2137 // (XPS Spec 5.1.3).
2138 FLOAT centemPerUnit = 100.0f / SkScalarToFLOAT(paint.getTextSize());
2139 GlyphRun xpsGlyphs;
2140 xpsGlyphs.setReserve(num_glyph_guess(paint.getTextEncoding(),
2141 static_cast<const char*>(text), byteLen));
2142
2143 ProcessOneGlyph processOneGlyph(centemPerUnit, typeface->glyphsUsed, &xpsGlyphs);
2144
2145 SkFindAndPlaceGlyph::ProcessText(
2146 paint.getTextEncoding(), static_cast<const char*>(text), byteLen,
2147 SkPoint{ x, y }, matrix, paint.getTextAlign(), cache, processOneGlyph);
2148
2149 if (xpsGlyphs.count() == 0) {
reed@google.com089130c2011-12-12 21:52:18 +00002150 return;
2151 }
2152
bungeman@google.comb29c8832011-10-10 13:19:10 +00002153 XPS_POINT origin = {
herbbda26432015-11-24 08:37:01 -08002154 xpsGlyphs[0].horizontalOffset / centemPerUnit,
2155 xpsGlyphs[0].verticalOffset / -centemPerUnit,
bungeman@google.comb29c8832011-10-10 13:19:10 +00002156 };
herbbda26432015-11-24 08:37:01 -08002157 xpsGlyphs[0].horizontalOffset = 0.0f;
2158 xpsGlyphs[0].verticalOffset = 0.0f;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002159
bungeman@google.comb29c8832011-10-10 13:19:10 +00002160 HRV(AddGlyphs(d,
2161 this->fXpsFactory.get(),
2162 this->fCurrentXpsCanvas.get(),
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00002163 typeface,
halcanary96fcdcc2015-08-27 07:41:13 -07002164 nullptr,
herbbda26432015-11-24 08:37:01 -08002165 xpsGlyphs.begin(), xpsGlyphs.count(),
bungeman@google.comb29c8832011-10-10 13:19:10 +00002166 &origin,
2167 SkScalarToFLOAT(paint.getTextSize()),
2168 XPS_STYLE_SIMULATION_NONE,
2169 *d.fMatrix,
2170 paint));
2171}
2172
2173void SkXPSDevice::drawPosText(const SkDraw& d,
2174 const void* text, size_t byteLen,
fmalita05c4a432014-09-29 06:29:53 -07002175 const SkScalar pos[], int scalarsPerPos,
2176 const SkPoint& offset, const SkPaint& paint) {
bungeman@google.comb29c8832011-10-10 13:19:10 +00002177 if (byteLen < 1) return;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002178
bungeman@google.comb29c8832011-10-10 13:19:10 +00002179 if (text_must_be_pathed(paint, *d.fMatrix)) {
2180 SkPath path;
2181 //TODO: make this work, Draw currently does not handle as well.
2182 //paint.getTextPath(text, byteLength, x, y, &path);
halcanary96fcdcc2015-08-27 07:41:13 -07002183 //this->drawPath(d, path, paint, nullptr, true);
bungeman@google.comb29c8832011-10-10 13:19:10 +00002184 //TODO: add automation "text"
2185 return;
2186 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002187
bungeman@google.comb29c8832011-10-10 13:19:10 +00002188 TypefaceUse* typeface;
2189 HRV(CreateTypefaceUse(paint, &typeface));
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002190
herbbda26432015-11-24 08:37:01 -08002191 const SkMatrix& matrix = SkMatrix::I();
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002192
herbbda26432015-11-24 08:37:01 -08002193 SkAutoGlyphCache autoCache(paint, &this->surfaceProps(), &matrix);
2194 SkGlyphCache* cache = autoCache.getCache();
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002195
herbbda26432015-11-24 08:37:01 -08002196 // Advance width and offsets for glyphs measured in hundredths of the font em size
2197 // (XPS Spec 5.1.3).
2198 FLOAT centemPerUnit = 100.0f / SkScalarToFLOAT(paint.getTextSize());
2199 GlyphRun xpsGlyphs;
2200 xpsGlyphs.setReserve(num_glyph_guess(paint.getTextEncoding(),
2201 static_cast<const char*>(text), byteLen));
2202
2203 ProcessOneGlyph processOneGlyph(centemPerUnit, typeface->glyphsUsed, &xpsGlyphs);
2204
2205 SkFindAndPlaceGlyph::ProcessPosText(
2206 paint.getTextEncoding(), static_cast<const char*>(text), byteLen,
2207 offset, matrix, pos, scalarsPerPos, paint.getTextAlign(), cache, processOneGlyph);
2208
2209 if (xpsGlyphs.count() == 0) {
reed@google.com089130c2011-12-12 21:52:18 +00002210 return;
2211 }
2212
bungeman@google.comb29c8832011-10-10 13:19:10 +00002213 XPS_POINT origin = {
herbbda26432015-11-24 08:37:01 -08002214 xpsGlyphs[0].horizontalOffset / centemPerUnit,
2215 xpsGlyphs[0].verticalOffset / -centemPerUnit,
bungeman@google.comb29c8832011-10-10 13:19:10 +00002216 };
herbbda26432015-11-24 08:37:01 -08002217 xpsGlyphs[0].horizontalOffset = 0.0f;
2218 xpsGlyphs[0].verticalOffset = 0.0f;
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002219
bungeman@google.comb29c8832011-10-10 13:19:10 +00002220 HRV(AddGlyphs(d,
2221 this->fXpsFactory.get(),
2222 this->fCurrentXpsCanvas.get(),
commit-bot@chromium.orgb5e34e22013-05-07 15:28:15 +00002223 typeface,
halcanary96fcdcc2015-08-27 07:41:13 -07002224 nullptr,
herbbda26432015-11-24 08:37:01 -08002225 xpsGlyphs.begin(), xpsGlyphs.count(),
bungeman@google.comb29c8832011-10-10 13:19:10 +00002226 &origin,
2227 SkScalarToFLOAT(paint.getTextSize()),
2228 XPS_STYLE_SIMULATION_NONE,
2229 *d.fMatrix,
2230 paint));
2231}
2232
robertphillips@google.com1f2f3382013-08-29 11:54:56 +00002233void SkXPSDevice::drawDevice(const SkDraw& d, SkBaseDevice* dev,
bungeman@google.comb29c8832011-10-10 13:19:10 +00002234 int x, int y,
2235 const SkPaint&) {
2236 SkXPSDevice* that = static_cast<SkXPSDevice*>(dev);
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002237
bungeman@google.comb29c8832011-10-10 13:19:10 +00002238 SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform;
2239 XPS_MATRIX rawTransform = {
2240 1.0f,
2241 0.0f,
2242 0.0f,
2243 1.0f,
2244 static_cast<FLOAT>(x),
2245 static_cast<FLOAT>(y),
2246 };
2247 HRVM(this->fXpsFactory->CreateMatrixTransform(&rawTransform, &xpsTransform),
2248 "Could not create layer transform.");
2249 HRVM(that->fCurrentXpsCanvas->SetTransformLocal(xpsTransform.get()),
2250 "Could not set layer transform.");
vandebo@chromium.org74b46192012-01-28 01:45:11 +00002251
bungeman@google.comb29c8832011-10-10 13:19:10 +00002252 //Get the current visual collection and add the layer to it.
2253 SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals;
2254 HRVM(this->fCurrentXpsCanvas->GetVisuals(&currentVisuals),
2255 "Could not get current visuals for layer.");
2256 HRVM(currentVisuals->Append(that->fCurrentXpsCanvas.get()),
2257 "Could not add layer to current visuals.");
2258}
2259
reed76033be2015-03-14 10:54:31 -07002260SkBaseDevice* SkXPSDevice::onCreateDevice(const CreateInfo& info, const SkPaint*) {
bungeman@google.com635091f2013-10-01 15:03:18 +00002261//Conditional for bug compatibility with PDF device.
2262#if 0
fmalita6987dca2014-11-13 08:33:37 -08002263 if (SkBaseDevice::kGeneral_Usage == info.fUsage) {
halcanary96fcdcc2015-08-27 07:41:13 -07002264 return nullptr;
bungeman@google.comb29c8832011-10-10 13:19:10 +00002265 //To what stream do we write?
2266 //SkXPSDevice* dev = new SkXPSDevice(this);
2267 //SkSize s = SkSize::Make(width, height);
2268 //dev->BeginCanvas(s, s, SkMatrix::I());
2269 //return dev;
2270 }
bungeman@google.com635091f2013-10-01 15:03:18 +00002271#endif
bungeman@google.comb29c8832011-10-10 13:19:10 +00002272 return new SkXPSDevice(this->fXpsFactory.get());
2273}
2274
mtklein1ee76512015-11-02 10:20:27 -08002275#endif//defined(SK_BUILD_FOR_WIN32)