bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 8 | #include "SkTypes.h" |
mtklein | 1ee7651 | 2015-11-02 10:20:27 -0800 | [diff] [blame] | 9 | #if defined(SK_BUILD_FOR_WIN32) |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 10 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 11 | #ifndef UNICODE |
| 12 | #define UNICODE |
| 13 | #endif |
| 14 | #ifndef _UNICODE |
| 15 | #define _UNICODE |
| 16 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 17 | #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.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 26 | #include "SkEndian.h" |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 27 | #include "SkFindAndPlaceGlyph.h" |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 28 | #include "SkGeometry.h" |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 29 | #include "SkGlyphCache.h" |
| 30 | #include "SkHRESULT.h" |
| 31 | #include "SkImageEncoder.h" |
| 32 | #include "SkIStream.h" |
| 33 | #include "SkMaskFilter.h" |
| 34 | #include "SkPaint.h" |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 35 | #include "SkPathEffect.h" |
Ben Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 36 | #include "SkPathOps.h" |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 37 | #include "SkPoint.h" |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 38 | #include "SkRasterClip.h" |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 39 | #include "SkRasterizer.h" |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 40 | #include "SkSFNTHeader.h" |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 41 | #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.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 47 | #include "SkTTCFHeader.h" |
reed@google.com | 398de9a | 2013-03-21 21:43:51 +0000 | [diff] [blame] | 48 | #include "SkTypefacePriv.h" |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 49 | #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 Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 56 | //Dummy representation of a GUID from createId. |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 57 | #define L_GUID_ID L"XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX" |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 58 | //Length of GUID representation from createId, including nullptr terminator. |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 59 | #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 | */ |
| 68 | static 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.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 91 | |
Ben Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 92 | HRESULT SkXPSDevice::createId(wchar_t* buffer, size_t bufferSize, wchar_t sep) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 93 | GUID guid = {}; |
Ben Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 94 | #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.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 100 | HRM(CoCreateGuid(&guid), "Could not create GUID for id."); |
Ben Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 101 | #endif |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 102 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 103 | if (format_guid(guid, buffer, bufferSize, sep) == -1) { |
| 104 | HRM(E_UNEXPECTED, "Could not format GUID into id."); |
| 105 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 106 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 107 | return S_OK; |
| 108 | } |
| 109 | |
| 110 | static SkBitmap make_fake_bitmap(int width, int height) { |
| 111 | SkBitmap bitmap; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 112 | bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 113 | return bitmap; |
| 114 | } |
| 115 | |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 116 | // TODO: should inherit from SkBaseDevice instead of SkBitmapDevice... |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 117 | SkXPSDevice::SkXPSDevice() |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 118 | : INHERITED(make_fake_bitmap(10000, 10000), SkSurfaceProps(0, kUnknown_SkPixelGeometry)) |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 119 | , fCurrentPage(0) { |
| 120 | } |
| 121 | |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 122 | SkXPSDevice::SkXPSDevice(IXpsOMObjectFactory* xpsFactory) |
| 123 | : INHERITED(make_fake_bitmap(10000, 10000), SkSurfaceProps(0, kUnknown_SkPixelGeometry)) |
| 124 | , fCurrentPage(0) { |
| 125 | |
| 126 | HRVM(CoCreateInstance( |
| 127 | CLSID_XpsOMObjectFactory, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 128 | nullptr, |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 129 | 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.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 137 | SkXPSDevice::~SkXPSDevice() { |
| 138 | } |
| 139 | |
| 140 | SkXPSDevice::TypefaceUse::TypefaceUse() |
| 141 | : typefaceId(0xffffffff) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 142 | , fontData(nullptr) |
| 143 | , xpsFont(nullptr) |
| 144 | , glyphsUsed(nullptr) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | SkXPSDevice::TypefaceUse::~TypefaceUse() { |
| 148 | //xpsFont owns fontData ref |
| 149 | this->xpsFont->Release(); |
| 150 | delete this->glyphsUsed; |
| 151 | } |
| 152 | |
| 153 | bool SkXPSDevice::beginPortfolio(SkWStream* outputStream) { |
| 154 | if (!this->fAutoCo.succeeded()) return false; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 155 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 156 | //Create XPS Factory. |
| 157 | HRBM(CoCreateInstance( |
| 158 | CLSID_XpsOMObjectFactory, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 159 | nullptr, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 160 | CLSCTX_INPROC_SERVER, |
| 161 | IID_PPV_ARGS(&this->fXpsFactory)), |
| 162 | "Could not create XPS factory."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 163 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 164 | HRBM(SkWIStream::CreateFromSkWStream(outputStream, &this->fOutputStream), |
| 165 | "Could not convert SkStream to IStream."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 166 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 167 | return true; |
| 168 | } |
| 169 | |
| 170 | bool 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 179 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 180 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 185 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 186 | this->fCurrentXpsCanvas.reset(); |
| 187 | HRBM(this->fXpsFactory->CreateCanvas(&this->fCurrentXpsCanvas), |
| 188 | "Could not create base canvas."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 189 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 190 | return true; |
| 191 | } |
| 192 | |
| 193 | HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page, |
| 194 | const unsigned int pageNum, |
| 195 | IXpsOMImageResource** image) { |
| 196 | SkTScopedComPtr<IXpsOMThumbnailGenerator> thumbnailGenerator; |
| 197 | HRM(CoCreateInstance( |
| 198 | CLSID_XpsOMThumbnailGenerator, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 199 | nullptr, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 200 | CLSCTX_INPROC_SERVER, |
| 201 | IID_PPV_ARGS(&thumbnailGenerator)), |
| 202 | "Could not create thumbnail generator."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 203 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 204 | SkTScopedComPtr<IOpcPartUri> partUri; |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 205 | static const size_t size = SkTUMax< |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 206 | 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.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 208 | >::value; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 209 | 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 Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 214 | HR(this->createId(id, GUID_ID_LEN)); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 215 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 219 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 220 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 226 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 227 | return S_OK; |
| 228 | } |
| 229 | |
| 230 | HRESULT 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 240 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 241 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 247 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 248 | return S_OK; |
| 249 | } |
| 250 | |
| 251 | HRESULT 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(), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 263 | nullptr, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 264 | image, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 265 | nullptr, |
| 266 | nullptr, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 267 | &this->fPackageWriter), |
| 268 | "Could not create package writer."); |
| 269 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 270 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 271 | //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(), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 279 | nullptr, |
| 280 | nullptr, |
| 281 | nullptr, |
| 282 | nullptr), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 283 | "Could not start document."); |
| 284 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 285 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 286 | return S_OK; |
| 287 | } |
| 288 | |
| 289 | bool 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 298 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 299 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 306 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 307 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 313 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 314 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 317 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 318 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 325 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 326 | SkTScopedComPtr<IXpsOMVisualCollection> pageVisuals; |
| 327 | HRBM(page->GetVisuals(&pageVisuals), "Could not get page visuals."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 328 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 329 | //Add the scale canvas to the page. |
| 330 | HRBM(pageVisuals->Append(scaleCanvas.get()), |
| 331 | "Could not add scale canvas to page."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 332 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 333 | //Create the package writer if it hasn't been created yet. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 334 | if (nullptr == this->fPackageWriter.get()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 335 | SkTScopedComPtr<IXpsOMImageResource> image; |
| 336 | //Ignore return, thumbnail is completely optional. |
| 337 | this->createXpsThumbnail(page.get(), 0, &image); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 338 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 339 | HRB(this->initXpsDocumentWriter(image.get())); |
| 340 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 341 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 342 | HRBM(this->fPackageWriter->AddPage(page.get(), |
| 343 | &pageSize, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 344 | nullptr, |
| 345 | nullptr, |
| 346 | nullptr, |
| 347 | nullptr), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 348 | "Could not write the page."); |
| 349 | this->fCurrentXpsCanvas.reset(); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 350 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 351 | return true; |
| 352 | } |
| 353 | |
| 354 | static 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 359 | |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 360 | int ttcCount = (current->ttcIndex + 1); |
| 361 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 362 | //The following are declared with the types required by CreateFontPackage. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 363 | unsigned char *fontPackageBufferRaw = nullptr; |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 364 | unsigned long fontPackageBufferSize; |
| 365 | unsigned long bytesWritten; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 366 | unsigned long result = CreateFontPackage( |
| 367 | (unsigned char *) current->fontData->getMemoryBase(), |
| 368 | (unsigned long) current->fontData->getLength(), |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 369 | &fontPackageBufferRaw, |
| 370 | &fontPackageBufferSize, |
| 371 | &bytesWritten, |
| 372 | TTFCFP_FLAGS_SUBSET | TTFCFP_FLAGS_GLYPHLIST | (ttcCount > 0 ? TTFCFP_FLAGS_TTC : 0), |
| 373 | current->ttcIndex, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 374 | 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, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 383 | nullptr); |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 384 | SkAutoTMalloc<unsigned char> fontPackageBuffer(fontPackageBufferRaw); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 385 | if (result != NO_ERROR) { |
| 386 | SkDEBUGF(("CreateFontPackage Error %lu", result)); |
| 387 | return E_UNEXPECTED; |
| 388 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 389 | |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 390 | // 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) { |
bsalomon | 0aa5cea | 2014-12-15 09:13:35 -0800 | [diff] [blame] | 407 | *offsetPtr = SkEndian_SwapBE32(SkToU32(extra)); |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 408 | } |
| 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( |
bsalomon | 0aa5cea | 2014-12-15 09:13:35 -0800 | [diff] [blame] | 417 | SkToU32(SkEndian_SwapBE32(SkToU32(tableDirectory->offset)) + extra)); |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 418 | } |
| 419 | } else { |
| 420 | extra = 0; |
| 421 | fontPackageBuffer.realloc(bytesWritten); |
| 422 | } |
| 423 | |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 424 | SkAutoTDelete<SkMemoryStream> newStream(new SkMemoryStream()); |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 425 | newStream->setMemoryOwned(fontPackageBuffer.release(), bytesWritten + extra); |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 426 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 427 | SkTScopedComPtr<IStream> newIStream; |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 428 | SkIStream::CreateFromSkStream(newStream.release(), true, &newIStream); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 429 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 430 | XPS_FONT_EMBEDDING embedding; |
| 431 | HRM(current->xpsFont->GetEmbeddingOption(&embedding), |
| 432 | "Could not get embedding option from font."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 433 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 434 | SkTScopedComPtr<IOpcPartUri> partUri; |
| 435 | HRM(current->xpsFont->GetPartName(&partUri), |
| 436 | "Could not get part uri from font."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 437 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 438 | HRM(current->xpsFont->SetContent( |
| 439 | newIStream.get(), |
| 440 | embedding, |
| 441 | partUri.get()), |
| 442 | "Could not set new stream for subsetted font."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 443 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 444 | return S_OK; |
| 445 | } |
| 446 | |
| 447 | bool 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 457 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 458 | HRBM(this->fPackageWriter->Close(), "Could not close writer."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 459 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 460 | return true; |
| 461 | } |
| 462 | |
| 463 | static 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 471 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 472 | return xpsColor; |
| 473 | } |
| 474 | |
| 475 | static 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 | |
| 483 | static 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 | |
| 489 | static 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.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 498 | SkDEBUGFAIL("Unknown tile mode."); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 499 | } |
| 500 | return XPS_SPREAD_METHOD_PAD; |
| 501 | } |
| 502 | |
| 503 | static 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 510 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 511 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 520 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 521 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 525 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 526 | SkPoint stopTransformed; |
| 527 | transform.mapXY(stop.fX, stop.fY, &stopTransformed); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 528 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 529 | //Manhattan distance between transformed start and stop. |
| 530 | SkScalar startToStop = (stopTransformed.fX - startTransformed.fX) |
| 531 | + (stopTransformed.fY - startTransformed.fY); |
| 532 | //Percentage along transformed line. |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 533 | stopOffsets[i] = startToStop / startToEnd; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | |
| 537 | HRESULT SkXPSDevice::createXpsTransform(const SkMatrix& matrix, |
| 538 | IXpsOMMatrixTransform** xpsTransform) { |
| 539 | SkScalar affine[6]; |
| 540 | if (!matrix.asAffine(affine)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 541 | *xpsTransform = nullptr; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 542 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 554 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 555 | return S_OK; |
| 556 | } |
| 557 | |
| 558 | HRESULT 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 564 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 565 | SkTScopedComPtr<IXpsOMGeometryFigureCollection> figureCollection; |
| 566 | HRM(geometry->GetFigures(&figureCollection), "Could not get figures."); |
| 567 | HRM(figureCollection->Append(figure), "Could not add figure."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 568 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 569 | HRM(this->fXpsFactory->CreatePath(path), "Could not create path."); |
| 570 | HRM((*path)->SetGeometryLocal(geometry.get()), "Could not set geometry"); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 571 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 572 | HRM(visuals->Append(*path), "Could not add path to visuals."); |
| 573 | return S_OK; |
| 574 | } |
| 575 | |
| 576 | HRESULT SkXPSDevice::createXpsSolidColorBrush(const SkColor skColor, |
| 577 | const SkAlpha alpha, |
| 578 | IXpsOMBrush** xpsBrush) { |
| 579 | XPS_COLOR xpsColor = xps_color(skColor); |
| 580 | SkTScopedComPtr<IXpsOMSolidColorBrush> solidBrush; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 581 | HRM(this->fXpsFactory->CreateSolidColorBrush(&xpsColor, nullptr, &solidBrush), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 582 | "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 | |
| 588 | HRESULT 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 594 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 595 | SkTScopedComPtr<IXpsOMPath> areaToFillPath; |
| 596 | HR(this->createPath(areaToFillFigure.get(), visuals, &areaToFillPath)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 597 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 598 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 608 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 609 | return S_OK; |
| 610 | } |
| 611 | |
| 612 | HRESULT 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 617 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 618 | SkTScopedComPtr<IXpsOMPath> areaToFillPath; |
| 619 | HR(this->createPath(areaToFillFigure.get(), visuals, &areaToFillPath)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 620 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 621 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 625 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 626 | return S_OK; |
| 627 | } |
| 628 | |
| 629 | static const XPS_TILE_MODE XTM_N = XPS_TILE_MODE_NONE; |
| 630 | static const XPS_TILE_MODE XTM_T = XPS_TILE_MODE_TILE; |
| 631 | static const XPS_TILE_MODE XTM_X = XPS_TILE_MODE_FLIPX; |
| 632 | static const XPS_TILE_MODE XTM_Y = XPS_TILE_MODE_FLIPY; |
| 633 | static 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). |
| 638 | static 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 | |
| 647 | HRESULT 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 663 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 664 | 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 Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 668 | HR(this->createId(id, GUID_ID_LEN)); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 669 | swprintf_s(buffer, size, L"/Documents/1/Resources/Images/%s.png", id); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 670 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 671 | SkTScopedComPtr<IOpcPartUri> imagePartUri; |
| 672 | HRM(this->fXpsFactory->CreatePartUri(buffer, &imagePartUri), |
| 673 | "Could not create image part uri."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 674 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 675 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 682 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 683 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 692 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 693 | if (SkShader::kClamp_TileMode != xy[0] && |
| 694 | SkShader::kClamp_TileMode != xy[1]) { |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 695 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 696 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 707 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 708 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 715 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 716 | //create central figure |
| 717 | const SkRect bitmapPoints = SkRect::MakeLTRB(0, 0, bWidth, bHeight); |
| 718 | SkTScopedComPtr<IXpsOMGeometryFigure> centralFigure; |
| 719 | HR(this->createXpsRect(bitmapPoints, FALSE, TRUE, ¢ralFigure)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 720 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 721 | SkTScopedComPtr<IXpsOMPath> centralPath; |
| 722 | HR(this->createPath(centralFigure.get(), |
| 723 | brushVisuals.get(), |
| 724 | ¢ralPath)); |
| 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 729 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 730 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 750 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 751 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 761 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 762 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 771 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 772 | //add tl, tr, bl, br |
| 773 | if (SkShader::kClamp_TileMode == xy[0] && |
| 774 | SkShader::kClamp_TileMode == xy[1]) { |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 775 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 776 | SkAutoLockPixels alp(bitmap); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 777 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 778 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 781 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 782 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 785 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 786 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 790 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 791 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 795 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 796 | //create visual brush from canvas |
| 797 | XPS_RECT bound = {}; |
| 798 | if (SkShader::kClamp_TileMode == xy[0] && |
| 799 | SkShader::kClamp_TileMode == xy[1]) { |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 800 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 801 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 825 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 826 | HRM(clampBrush->QueryInterface(xpsBrush), "QI failed."); |
| 827 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 828 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 829 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsMatrixToUse; |
| 830 | HR(this->createXpsTransform(localMatrix, &xpsMatrixToUse)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 831 | if (xpsMatrixToUse.get()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 832 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 837 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 838 | return S_OK; |
| 839 | } |
| 840 | |
| 841 | HRESULT 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, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 846 | nullptr, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 847 | SkScalarToFLOAT(offset), |
| 848 | xpsGradStop), |
| 849 | "Could not create gradient stop."); |
| 850 | return S_OK; |
| 851 | } |
| 852 | |
| 853 | HRESULT 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; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 860 | if (xpsMatrix) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 861 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 870 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 871 | SkTScopedComPtr<IXpsOMGradientStop> gradStop0; |
| 872 | HR(createXpsGradientStop(info.fColors[0], |
| 873 | info.fColorOffsets[0], |
| 874 | &gradStop0)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 875 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 876 | SkTScopedComPtr<IXpsOMGradientStop> gradStop1; |
| 877 | HR(createXpsGradientStop(info.fColors[1], |
| 878 | info.fColorOffsets[1], |
| 879 | &gradStop1)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 880 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 881 | 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."); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 888 | if (xpsMatrix) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 889 | HRM(gradientBrush->SetTransformLocal(xpsMatrix), |
| 890 | "Could not set transform on linear gradient brush."); |
| 891 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 892 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 893 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 904 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 905 | HRM(gradientBrush->SetSpreadMethod(xps_spread_method(info.fTileMode)), |
| 906 | "Could not set spread method of linear gradient."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 907 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 908 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 911 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 912 | return S_OK; |
| 913 | } |
| 914 | |
| 915 | HRESULT 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 924 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 925 | SkTScopedComPtr<IXpsOMGradientStop> gradStop1; |
| 926 | HR(createXpsGradientStop(info.fColors[1], |
| 927 | info.fColorOffsets[1], |
| 928 | &gradStop1)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 929 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 930 | //TODO: figure out how to fake better if not affine |
| 931 | XPS_POINT centerPoint; |
| 932 | XPS_POINT gradientOrigin; |
| 933 | XPS_SIZE radiiSizes; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 934 | if (xpsMatrix) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 935 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 942 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 943 | SkScalar radius = info.fRadius[0]; |
| 944 | SkVector vec[2]; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 945 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 946 | vec[0].set(radius, 0); |
| 947 | vec[1].set(0, radius); |
| 948 | localMatrix.mapVectors(vec, 2); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 949 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 950 | SkScalar d0 = vec[0].length(); |
| 951 | SkScalar d1 = vec[1].length(); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 952 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 953 | radiiSizes.width = SkScalarToFLOAT(d0); |
| 954 | radiiSizes.height = SkScalarToFLOAT(d1); |
| 955 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 956 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 957 | SkTScopedComPtr<IXpsOMRadialGradientBrush> gradientBrush; |
| 958 | HRM(this->fXpsFactory->CreateRadialGradientBrush(gradStop0.get(), |
| 959 | gradStop1.get(), |
| 960 | ¢erPoint, |
| 961 | &gradientOrigin, |
| 962 | &radiiSizes, |
| 963 | &gradientBrush), |
| 964 | "Could not create radial gradient brush."); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 965 | if (xpsMatrix) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 966 | HRM(gradientBrush->SetTransformLocal(xpsMatrix), |
| 967 | "Could not set transform on radial gradient brush."); |
| 968 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 969 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 970 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 981 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 982 | HRM(gradientBrush->SetSpreadMethod(xps_spread_method(info.fTileMode)), |
| 983 | "Could not set spread method of radial gradient."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 984 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 985 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 988 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 989 | return S_OK; |
| 990 | } |
| 991 | |
| 992 | HRESULT SkXPSDevice::createXpsBrush(const SkPaint& skPaint, |
| 993 | IXpsOMBrush** brush, |
| 994 | const SkMatrix* parentTransform) { |
| 995 | const SkShader *shader = skPaint.getShader(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 996 | if (nullptr == shader) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 997 | HR(this->createXpsSolidColorBrush(skPaint.getColor(), 0xFF, brush)); |
| 998 | return S_OK; |
| 999 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1000 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1001 | //Gradient shaders. |
| 1002 | SkShader::GradientInfo info; |
| 1003 | info.fColorCount = 0; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1004 | info.fColors = nullptr; |
| 1005 | info.fColorOffsets = nullptr; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1006 | SkShader::GradientType gradientType = shader->asAGradient(&info); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1007 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1008 | if (SkShader::kNone_GradientType == gradientType) { |
| 1009 | //Nothing to see, move along. |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1010 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1011 | } else if (SkShader::kColor_GradientType == gradientType) { |
| 1012 | SkASSERT(1 == info.fColorCount); |
| 1013 | SkColor color; |
| 1014 | info.fColors = &color; |
bsalomon@google.com | b58a639 | 2013-03-21 20:29:05 +0000 | [diff] [blame] | 1015 | shader->asAGradient(&info); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1016 | SkAlpha alpha = skPaint.getAlpha(); |
| 1017 | HR(this->createXpsSolidColorBrush(color, alpha, brush)); |
| 1018 | return S_OK; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1019 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1020 | } 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1026 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1027 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1032 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1033 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1039 | |
bsalomon@google.com | f94b3a4 | 2012-10-31 18:09:01 +0000 | [diff] [blame] | 1040 | SkMatrix localMatrix = shader->getLocalMatrix(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1041 | if (parentTransform) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1042 | localMatrix.preConcat(*parentTransform); |
| 1043 | } |
| 1044 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsMatrixToUse; |
| 1045 | HR(this->createXpsTransform(localMatrix, &xpsMatrixToUse)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1046 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1047 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1055 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1056 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1064 | |
reed | 71a6cbf | 2015-05-04 08:32:51 -0700 | [diff] [blame] | 1065 | if (SkShader::kConical_GradientType == gradientType) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1066 | //simple if affine and one is 0, otherwise will have to fake |
| 1067 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1068 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1069 | if (SkShader::kSweep_GradientType == gradientType) { |
| 1070 | //have to fake |
| 1071 | } |
| 1072 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1073 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1074 | SkBitmap outTexture; |
| 1075 | SkMatrix outMatrix; |
| 1076 | SkShader::TileMode xy[2]; |
reed | f582282 | 2015-08-19 11:46:38 -0700 | [diff] [blame] | 1077 | if (shader->isABitmap(&outTexture, &outMatrix, xy)) { |
| 1078 | //TODO: outMatrix?? |
| 1079 | SkMatrix localMatrix = shader->getLocalMatrix(); |
| 1080 | if (parentTransform) { |
| 1081 | localMatrix.preConcat(*parentTransform); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1082 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1083 | |
reed | f582282 | 2015-08-19 11:46:38 -0700 | [diff] [blame] | 1084 | 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.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1095 | return S_OK; |
| 1096 | } |
| 1097 | |
| 1098 | static 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1101 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1102 | 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 | |
| 1114 | HRESULT 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 | } |
| 1124 | HRESULT 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1129 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1130 | // Create the figure. |
| 1131 | HRM(this->fXpsFactory->CreateGeometryFigure(&startPoint, xpsQuad), |
| 1132 | "Could not create quad geometry figure."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1133 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1134 | // 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1140 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1141 | // 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1147 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1148 | // Describe if the segments are stroked. |
| 1149 | BOOL segmentStrokes[3] = { |
| 1150 | stroke, stroke, stroke, |
| 1151 | }; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1152 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1153 | // 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1158 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1159 | // 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1162 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1163 | return S_OK; |
| 1164 | } |
| 1165 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1166 | void 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 | |
| 1173 | void 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.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1182 | void SkXPSDevice::drawPaint(const SkDraw& d, const SkPaint& origPaint) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1183 | const SkRect r = SkRect::MakeSize(this->fCurrentCanvasSize); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1184 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1185 | //If trying to paint with a stroke, ignore that and fill. |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1186 | 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.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1190 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1191 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1192 | this->internalDrawRect(d, r, false, *fillPaint); |
| 1193 | } |
| 1194 | |
| 1195 | void SkXPSDevice::drawRect(const SkDraw& d, |
| 1196 | const SkRect& r, |
| 1197 | const SkPaint& paint) { |
| 1198 | this->internalDrawRect(d, r, true, paint); |
| 1199 | } |
| 1200 | |
scroggo@google.com | cac8d01 | 2013-11-12 17:10:02 +0000 | [diff] [blame] | 1201 | void SkXPSDevice::drawRRect(const SkDraw& d, |
| 1202 | const SkRRect& rr, |
| 1203 | const SkPaint& paint) { |
| 1204 | SkPath path; |
| 1205 | path.addRRect(rr); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1206 | this->drawPath(d, path, paint, nullptr, true); |
scroggo@google.com | cac8d01 | 2013-11-12 17:10:02 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1209 | void 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. |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 1214 | if (d.fRC->isEmpty() || |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1215 | (paint.getAlpha() == 0 && paint.getXfermode() == nullptr)) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1216 | return; |
| 1217 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1218 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1219 | //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); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1224 | this->drawPath(d, tmp, paint, nullptr, true); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1225 | return; |
| 1226 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1227 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1228 | //Create the shaded path. |
| 1229 | SkTScopedComPtr<IXpsOMPath> shadedPath; |
| 1230 | HRVM(this->fXpsFactory->CreatePath(&shadedPath), |
| 1231 | "Could not create shaded path for rect."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1232 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1233 | //Create the shaded geometry. |
| 1234 | SkTScopedComPtr<IXpsOMGeometry> shadedGeometry; |
| 1235 | HRVM(this->fXpsFactory->CreateGeometry(&shadedGeometry), |
| 1236 | "Could not create shaded geometry for rect."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1237 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1238 | //Add the geometry to the shaded path. |
| 1239 | HRVM(shadedPath->SetGeometryLocal(shadedGeometry.get()), |
| 1240 | "Could not set shaded geometry for rect."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1241 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1242 | //Set the brushes. |
| 1243 | BOOL fill = FALSE; |
| 1244 | BOOL stroke = FALSE; |
| 1245 | HRV(this->shadePath(shadedPath.get(), paint, *d.fMatrix, &fill, &stroke)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1246 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1247 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1259 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1260 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1274 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1275 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1279 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1280 | //Add the figure to the shaded geometry figures. |
| 1281 | HRVM(shadedFigures->Append(rectFigure.get()), |
| 1282 | "Could not add shaded figure for rect."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1283 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1284 | HRV(this->clip(shadedPath.get(), d)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1285 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1286 | //Add the shaded path to the current visuals. |
| 1287 | SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals; |
| 1288 | HRVM(this->fCurrentXpsCanvas->GetVisuals(¤tVisuals), |
| 1289 | "Could not get current visuals for rect."); |
| 1290 | HRVM(currentVisuals->Append(shadedPath.get()), |
| 1291 | "Could not add rect to current visuals."); |
| 1292 | } |
| 1293 | |
| 1294 | static 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1305 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1306 | // 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1309 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1310 | // 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 | |
| 1315 | HRESULT 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1321 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1322 | 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: { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1329 | if (xpsFigure.get()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1330 | 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; |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 1371 | 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.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1386 | 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.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 1391 | SkDEBUGFAIL("unexpected verb"); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1392 | break; |
| 1393 | } |
| 1394 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1395 | if (xpsFigure.get()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1396 | HR(close_figure(segmentTypes, segmentStrokes, segmentData, |
| 1397 | stroke, fill, |
| 1398 | xpsFigure.get(), xpsFigures)); |
| 1399 | } |
| 1400 | return S_OK; |
| 1401 | } |
| 1402 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1403 | void SkXPSDevice::convertToPpm(const SkMaskFilter* filter, |
| 1404 | SkMatrix* matrix, |
| 1405 | SkVector* ppuScale, |
| 1406 | const SkIRect& clip, SkIRect* clipIRect) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1407 | //This action is in unit space, but the ppm is specified in physical space. |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 1408 | ppuScale->set(fCurrentPixelsPerMeter.fX / fCurrentUnitsPerMeter.fX, |
| 1409 | fCurrentPixelsPerMeter.fY / fCurrentUnitsPerMeter.fY); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1410 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1411 | matrix->postScale(ppuScale->fX, ppuScale->fY); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1412 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1413 | 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 | |
| 1422 | HRESULT 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1430 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1431 | //Get the figures from the geometry. |
| 1432 | SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures; |
| 1433 | HRM(shadedGeometry->GetFigures(&shadedFigures), |
| 1434 | "Could not get mask shaded figures."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1435 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1436 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1441 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1442 | SkShader::TileMode xy[2]; |
| 1443 | xy[0] = (SkShader::TileMode)3; |
| 1444 | xy[1] = (SkShader::TileMode)3; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1445 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1446 | SkBitmap bm; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 1447 | bm.installMaskPixels(mask); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1448 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1449 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1453 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1454 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1461 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1462 | HR(this->clip(shadedPath, d)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1463 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1464 | //Add the path to the active visual collection. |
| 1465 | SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals; |
| 1466 | HRM(this->fCurrentXpsCanvas->GetVisuals(¤tVisuals), |
| 1467 | "Could not get mask current visuals."); |
| 1468 | HRM(currentVisuals->Append(shadedPath), |
| 1469 | "Could not add masked shaded path to current visuals."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1470 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1471 | return S_OK; |
| 1472 | } |
| 1473 | |
| 1474 | HRESULT 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1480 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1481 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1486 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1487 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1495 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1496 | 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1505 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1506 | 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 | |
| 1522 | void SkXPSDevice::drawPath(const SkDraw& d, |
| 1523 | const SkPath& platonicPath, |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1524 | const SkPaint& origPaint, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1525 | const SkMatrix* prePathMatrix, |
| 1526 | bool pathIsMutable) { |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1527 | SkTCopyOnFirstWrite<SkPaint> paint(origPaint); |
| 1528 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1529 | // nothing to draw |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 1530 | if (d.fRC->isEmpty() || |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1531 | (paint->getAlpha() == 0 && paint->getXfermode() == nullptr)) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1532 | return; |
| 1533 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1534 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1535 | SkPath modifiedPath; |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1536 | const bool paintHasPathEffect = paint->getPathEffect() |
| 1537 | || paint->getStyle() != SkPaint::kFill_Style; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1538 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1539 | //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.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1543 | if (paintHasPathEffect || paint->getRasterizer()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1544 | if (!pathIsMutable) { |
| 1545 | skeletalPath = &modifiedPath; |
| 1546 | pathIsMutable = true; |
| 1547 | } |
| 1548 | platonicPath.transform(*prePathMatrix, skeletalPath); |
| 1549 | } else { |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1550 | matrix.preConcat(*prePathMatrix); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1551 | } |
| 1552 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1553 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1554 | //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.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1561 | bool fill = paint->getFillPath(*skeletalPath, fillablePath); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1562 | |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1563 | SkPaint* writablePaint = paint.writable(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1564 | writablePaint->setPathEffect(nullptr); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1565 | if (fill) { |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1566 | writablePaint->setStyle(SkPaint::kFill_Style); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1567 | } else { |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1568 | writablePaint->setStyle(SkPaint::kStroke_Style); |
| 1569 | writablePaint->setStrokeWidth(0); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1570 | } |
| 1571 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1572 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1573 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1577 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1578 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1582 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1583 | //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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1586 | |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1587 | SkRasterizer* rasterizer = paint->getRasterizer(); |
| 1588 | SkMaskFilter* filter = paint->getMaskFilter(); |
bungeman@google.com | d998cbd | 2012-04-05 18:57:53 +0000 | [diff] [blame] | 1589 | |
| 1590 | //Determine if we will draw or shade and mask. |
| 1591 | if (rasterizer || filter) { |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1592 | if (paint->getStyle() != SkPaint::kFill_Style) { |
| 1593 | paint.writable()->setStyle(SkPaint::kFill_Style); |
bungeman@google.com | d998cbd | 2012-04-05 18:57:53 +0000 | [diff] [blame] | 1594 | } |
| 1595 | } |
| 1596 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1597 | //Set the brushes. |
| 1598 | BOOL fill; |
| 1599 | BOOL stroke; |
| 1600 | HRV(this->shadePath(shadedPath.get(), |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1601 | *paint, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1602 | *d.fMatrix, |
| 1603 | &fill, |
| 1604 | &stroke)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1605 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1606 | //Rasterizer |
bungeman@google.com | d998cbd | 2012-04-05 18:57:53 +0000 | [diff] [blame] | 1607 | if (rasterizer) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1608 | SkIRect clipIRect; |
| 1609 | SkVector ppuScale; |
| 1610 | this->convertToPpm(filter, |
| 1611 | &matrix, |
| 1612 | &ppuScale, |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 1613 | d.fRC->getBounds(), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1614 | &clipIRect); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1615 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1616 | SkMask* mask = nullptr; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1617 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1618 | //[Fillable-path -> Mask] |
| 1619 | SkMask rasteredMask; |
bungeman@google.com | d998cbd | 2012-04-05 18:57:53 +0000 | [diff] [blame] | 1620 | if (rasterizer->rasterize( |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1621 | *fillablePath, |
| 1622 | matrix, |
| 1623 | &clipIRect, |
| 1624 | filter, //just to compute how much to draw. |
| 1625 | &rasteredMask, |
| 1626 | SkMask::kComputeBoundsAndRenderImage_CreateMode)) { |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1627 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1628 | SkAutoMaskFreeImage rasteredAmi(rasteredMask.fImage); |
| 1629 | mask = &rasteredMask; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1630 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1631 | //[Mask -> Mask] |
| 1632 | SkMask filteredMask; |
robertphillips | e80eb92 | 2015-12-17 11:33:12 -0800 | [diff] [blame] | 1633 | if (filter && filter->filterMask(&filteredMask, *mask, *d.fMatrix, nullptr)) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1634 | mask = &filteredMask; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1635 | } |
| 1636 | SkAutoMaskFreeImage filteredAmi(filteredMask.fImage); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1637 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1638 | //Draw mask. |
| 1639 | HRV(this->applyMask(d, *mask, ppuScale, shadedPath.get())); |
| 1640 | } |
| 1641 | return; |
| 1642 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1643 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1644 | //Mask filter |
| 1645 | if (filter) { |
| 1646 | SkIRect clipIRect; |
| 1647 | SkVector ppuScale; |
| 1648 | this->convertToPpm(filter, |
| 1649 | &matrix, |
| 1650 | &ppuScale, |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 1651 | d.fRC->getBounds(), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1652 | &clipIRect); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1653 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1654 | //[Fillable-path -> Pixel-path] |
| 1655 | SkPath* pixelPath = pathIsMutable ? fillablePath : &modifiedPath; |
| 1656 | fillablePath->transform(matrix, pixelPath); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1657 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1658 | SkMask* mask = nullptr; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1659 | |
bsalomon | 055e192 | 2016-05-06 07:22:58 -0700 | [diff] [blame^] | 1660 | SkASSERT(SkPaint::kFill_Style == paint->getStyle() || |
| 1661 | (SkPaint::kStroke_Style == paint->getStyle() && 0 == paint->getStrokeWidth())); |
| 1662 | SkStrokeRec::InitStyle style = (SkPaint::kFill_Style == paint->getStyle()) |
| 1663 | ? SkStrokeRec::kFill_InitStyle |
| 1664 | : SkStrokeRec::kHairline_InitStyle; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1665 | //[Pixel-path -> Mask] |
| 1666 | SkMask rasteredMask; |
| 1667 | if (SkDraw::DrawToMask( |
| 1668 | *pixelPath, |
| 1669 | &clipIRect, |
| 1670 | filter, //just to compute how much to draw. |
| 1671 | &matrix, |
| 1672 | &rasteredMask, |
junov@chromium.org | 2ac4ef5 | 2012-04-04 15:16:51 +0000 | [diff] [blame] | 1673 | SkMask::kComputeBoundsAndRenderImage_CreateMode, |
bsalomon | 055e192 | 2016-05-06 07:22:58 -0700 | [diff] [blame^] | 1674 | style)) { |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1675 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1676 | SkAutoMaskFreeImage rasteredAmi(rasteredMask.fImage); |
| 1677 | mask = &rasteredMask; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1678 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1679 | //[Mask -> Mask] |
| 1680 | SkMask filteredMask; |
robertphillips | e80eb92 | 2015-12-17 11:33:12 -0800 | [diff] [blame] | 1681 | if (filter->filterMask(&filteredMask, rasteredMask, matrix, nullptr)) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1682 | mask = &filteredMask; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1683 | } |
| 1684 | SkAutoMaskFreeImage filteredAmi(filteredMask.fImage); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1685 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1686 | //Draw mask. |
| 1687 | HRV(this->applyMask(d, *mask, ppuScale, shadedPath.get())); |
| 1688 | } |
| 1689 | return; |
| 1690 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1691 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1692 | //Get the figures from the shaded geometry. |
| 1693 | SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures; |
| 1694 | HRVM(shadedGeometry->GetFigures(&shadedFigures), |
| 1695 | "Could not get shaded figures for shaded path."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1696 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1697 | bool xpsTransformsPath = true; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1698 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1699 | //Set the fill rule. |
bungeman | 76db31a | 2014-08-25 07:31:53 -0700 | [diff] [blame] | 1700 | SkPath* xpsCompatiblePath = fillablePath; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1701 | XPS_FILL_RULE xpsFillRule; |
bungeman | 76db31a | 2014-08-25 07:31:53 -0700 | [diff] [blame] | 1702 | switch (fillablePath->getFillType()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1703 | case SkPath::kWinding_FillType: |
| 1704 | xpsFillRule = XPS_FILL_RULE_NONZERO; |
| 1705 | break; |
| 1706 | case SkPath::kEvenOdd_FillType: |
| 1707 | xpsFillRule = XPS_FILL_RULE_EVENODD; |
| 1708 | break; |
| 1709 | case SkPath::kInverseWinding_FillType: { |
bungeman | 76db31a | 2014-08-25 07:31:53 -0700 | [diff] [blame] | 1710 | //[Fillable-path (inverse winding) -> XPS-path (inverse even odd)] |
| 1711 | if (!pathIsMutable) { |
| 1712 | xpsCompatiblePath = &modifiedPath; |
| 1713 | pathIsMutable = true; |
| 1714 | } |
| 1715 | if (!Simplify(*fillablePath, xpsCompatiblePath)) { |
| 1716 | SkDEBUGF(("Could not simplify inverse winding path.")); |
| 1717 | return; |
| 1718 | } |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1719 | } |
bungeman | 76db31a | 2014-08-25 07:31:53 -0700 | [diff] [blame] | 1720 | // The xpsCompatiblePath is noW inverse even odd, so fall through. |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1721 | case SkPath::kInverseEvenOdd_FillType: { |
| 1722 | const SkRect universe = SkRect::MakeLTRB( |
| 1723 | 0, 0, |
| 1724 | this->fCurrentCanvasSize.fWidth, |
| 1725 | this->fCurrentCanvasSize.fHeight); |
| 1726 | SkTScopedComPtr<IXpsOMGeometryFigure> addOneFigure; |
| 1727 | HRV(this->createXpsRect(universe, FALSE, TRUE, &addOneFigure)); |
| 1728 | HRVM(shadedFigures->Append(addOneFigure.get()), |
| 1729 | "Could not add even-odd flip figure to shaded path."); |
| 1730 | xpsTransformsPath = false; |
| 1731 | xpsFillRule = XPS_FILL_RULE_EVENODD; |
| 1732 | break; |
| 1733 | } |
| 1734 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 1735 | SkDEBUGFAIL("Unknown SkPath::FillType."); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1736 | } |
| 1737 | HRVM(shadedGeometry->SetFillRule(xpsFillRule), |
| 1738 | "Could not set fill rule for shaded path."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1739 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1740 | //Create the XPS transform, if possible. |
| 1741 | if (xpsTransformsPath) { |
| 1742 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform; |
| 1743 | HRV(this->createXpsTransform(matrix, &xpsTransform)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1744 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1745 | if (xpsTransform.get()) { |
| 1746 | HRVM(shadedGeometry->SetTransformLocal(xpsTransform.get()), |
| 1747 | "Could not set transform on shaded path."); |
| 1748 | } else { |
| 1749 | xpsTransformsPath = false; |
| 1750 | } |
| 1751 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1752 | |
bungeman | 76db31a | 2014-08-25 07:31:53 -0700 | [diff] [blame] | 1753 | SkPath* devicePath = xpsCompatiblePath; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1754 | if (!xpsTransformsPath) { |
| 1755 | //[Fillable-path -> Device-path] |
bungeman | 76db31a | 2014-08-25 07:31:53 -0700 | [diff] [blame] | 1756 | devicePath = pathIsMutable ? xpsCompatiblePath : &modifiedPath; |
| 1757 | xpsCompatiblePath->transform(matrix, devicePath); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1758 | } |
| 1759 | HRV(this->addXpsPathGeometry(shadedFigures.get(), |
| 1760 | stroke, fill, *devicePath)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1761 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1762 | HRV(this->clip(shadedPath.get(), d)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1763 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1764 | //Add the path to the active visual collection. |
| 1765 | SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals; |
| 1766 | HRVM(this->fCurrentXpsCanvas->GetVisuals(¤tVisuals), |
| 1767 | "Could not get current visuals for shaded path."); |
| 1768 | HRVM(currentVisuals->Append(shadedPath.get()), |
| 1769 | "Could not add shaded path to current visuals."); |
| 1770 | } |
| 1771 | |
| 1772 | HRESULT SkXPSDevice::clip(IXpsOMVisual* xpsVisual, const SkDraw& d) { |
| 1773 | SkPath clipPath; |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 1774 | if (d.fRC->isBW()) { |
| 1775 | SkAssertResult(d.fRC->bwRgn().getBoundaryPath(&clipPath)); |
| 1776 | } else { |
| 1777 | // Don't have a way to turn a AAClip into a path, so we just use the bounds. |
| 1778 | // TODO: consider using fClipStack instead? |
| 1779 | clipPath.addRect(SkRect::Make(d.fRC->getBounds())); |
| 1780 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1781 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1782 | return this->clipToPath(xpsVisual, clipPath, XPS_FILL_RULE_EVENODD); |
| 1783 | } |
| 1784 | HRESULT SkXPSDevice::clipToPath(IXpsOMVisual* xpsVisual, |
| 1785 | const SkPath& clipPath, |
| 1786 | XPS_FILL_RULE fillRule) { |
| 1787 | //Create the geometry. |
| 1788 | SkTScopedComPtr<IXpsOMGeometry> clipGeometry; |
| 1789 | HRM(this->fXpsFactory->CreateGeometry(&clipGeometry), |
| 1790 | "Could not create clip geometry."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1791 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1792 | //Get the figure collection of the geometry. |
| 1793 | SkTScopedComPtr<IXpsOMGeometryFigureCollection> clipFigures; |
| 1794 | HRM(clipGeometry->GetFigures(&clipFigures), |
| 1795 | "Could not get the clip figures."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1796 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1797 | //Create the figures into the geometry. |
| 1798 | HR(this->addXpsPathGeometry( |
| 1799 | clipFigures.get(), |
| 1800 | FALSE, TRUE, clipPath)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1801 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1802 | HRM(clipGeometry->SetFillRule(fillRule), |
| 1803 | "Could not set fill rule."); |
| 1804 | HRM(xpsVisual->SetClipGeometryLocal(clipGeometry.get()), |
| 1805 | "Could not set clip geometry."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1806 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1807 | return S_OK; |
| 1808 | } |
| 1809 | |
| 1810 | void SkXPSDevice::drawBitmap(const SkDraw& d, const SkBitmap& bitmap, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1811 | const SkMatrix& matrix, const SkPaint& paint) { |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 1812 | if (d.fRC->isEmpty()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1813 | return; |
| 1814 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1815 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1816 | SkIRect srcRect; |
robertphillips@google.com | 9bf380c | 2013-07-25 12:10:42 +0000 | [diff] [blame] | 1817 | srcRect.set(0, 0, bitmap.width(), bitmap.height()); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1818 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1819 | //Create the new shaded path. |
| 1820 | SkTScopedComPtr<IXpsOMPath> shadedPath; |
| 1821 | HRVM(this->fXpsFactory->CreatePath(&shadedPath), |
| 1822 | "Could not create path for bitmap."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1823 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1824 | //Create the shaded geometry. |
| 1825 | SkTScopedComPtr<IXpsOMGeometry> shadedGeometry; |
| 1826 | HRVM(this->fXpsFactory->CreateGeometry(&shadedGeometry), |
| 1827 | "Could not create geometry for bitmap."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1828 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1829 | //Add the shaded geometry to the shaded path. |
| 1830 | HRVM(shadedPath->SetGeometryLocal(shadedGeometry.get()), |
| 1831 | "Could not set the geometry for bitmap."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1832 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1833 | //Get the shaded figures from the shaded geometry. |
| 1834 | SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures; |
| 1835 | HRVM(shadedGeometry->GetFigures(&shadedFigures), |
| 1836 | "Could not get the figures for bitmap."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1837 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1838 | SkMatrix transform = matrix; |
| 1839 | transform.postConcat(*d.fMatrix); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1840 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1841 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform; |
| 1842 | HRV(this->createXpsTransform(transform, &xpsTransform)); |
| 1843 | if (xpsTransform.get()) { |
| 1844 | HRVM(shadedGeometry->SetTransformLocal(xpsTransform.get()), |
| 1845 | "Could not set transform for bitmap."); |
| 1846 | } else { |
| 1847 | //TODO: perspective that bitmap! |
| 1848 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1849 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1850 | SkTScopedComPtr<IXpsOMGeometryFigure> rectFigure; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1851 | if (xpsTransform.get()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1852 | const SkShader::TileMode xy[2] = { |
| 1853 | SkShader::kClamp_TileMode, |
| 1854 | SkShader::kClamp_TileMode, |
| 1855 | }; |
| 1856 | SkTScopedComPtr<IXpsOMTileBrush> xpsImageBrush; |
robertphillips@google.com | 9bf380c | 2013-07-25 12:10:42 +0000 | [diff] [blame] | 1857 | HRV(this->createXpsImageBrush(bitmap, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1858 | transform, |
| 1859 | xy, |
| 1860 | paint.getAlpha(), |
| 1861 | &xpsImageBrush)); |
| 1862 | HRVM(shadedPath->SetFillBrushLocal(xpsImageBrush.get()), |
| 1863 | "Could not set bitmap brush."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1864 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1865 | const SkRect bitmapRect = SkRect::MakeLTRB(0, 0, |
| 1866 | SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height())); |
| 1867 | HRV(this->createXpsRect(bitmapRect, FALSE, TRUE, &rectFigure)); |
| 1868 | } |
| 1869 | HRVM(shadedFigures->Append(rectFigure.get()), |
| 1870 | "Could not add bitmap figure."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1871 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1872 | //Get the current visual collection and add the shaded path to it. |
| 1873 | SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals; |
| 1874 | HRVM(this->fCurrentXpsCanvas->GetVisuals(¤tVisuals), |
| 1875 | "Could not get current visuals for bitmap"); |
| 1876 | HRVM(currentVisuals->Append(shadedPath.get()), |
| 1877 | "Could not add bitmap to current visuals."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1878 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1879 | HRV(this->clip(shadedPath.get(), d)); |
| 1880 | } |
| 1881 | |
| 1882 | void SkXPSDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap, |
| 1883 | int x, int y, |
| 1884 | const SkPaint& paint) { |
| 1885 | //TODO: override this for XPS |
| 1886 | SkDEBUGF(("XPS drawSprite not yet implemented.")); |
| 1887 | } |
| 1888 | |
| 1889 | HRESULT SkXPSDevice::CreateTypefaceUse(const SkPaint& paint, |
| 1890 | TypefaceUse** typefaceUse) { |
reed@google.com | 398de9a | 2013-03-21 21:43:51 +0000 | [diff] [blame] | 1891 | SkAutoResolveDefaultTypeface typeface(paint.getTypeface()); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1892 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1893 | //Check cache. |
reed@google.com | 398de9a | 2013-03-21 21:43:51 +0000 | [diff] [blame] | 1894 | const SkFontID typefaceID = typeface->uniqueID(); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1895 | if (!this->fTypefaces.empty()) { |
| 1896 | TypefaceUse* current = &this->fTypefaces.front(); |
| 1897 | const TypefaceUse* last = &this->fTypefaces.back(); |
| 1898 | for (; current <= last; ++current) { |
| 1899 | if (current->typefaceId == typefaceID) { |
| 1900 | *typefaceUse = current; |
| 1901 | return S_OK; |
| 1902 | } |
| 1903 | } |
| 1904 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1905 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1906 | //TODO: create glyph only fonts |
| 1907 | //and let the host deal with what kind of font we're looking at. |
| 1908 | XPS_FONT_EMBEDDING embedding = XPS_FONT_EMBEDDING_RESTRICTED; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1909 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1910 | SkTScopedComPtr<IStream> fontStream; |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 1911 | int ttcIndex; |
| 1912 | SkStream* fontData = typeface->openStream(&ttcIndex); |
bungeman@google.com | 635091f | 2013-10-01 15:03:18 +0000 | [diff] [blame] | 1913 | //TODO: cannot handle FON fonts. |
bungeman@google.com | 8cddc8d | 2012-01-03 22:36:33 +0000 | [diff] [blame] | 1914 | HRM(SkIStream::CreateFromSkStream(fontData, true, &fontStream), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1915 | "Could not create font stream."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1916 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1917 | const size_t size = |
| 1918 | SK_ARRAY_COUNT(L"/Resources/Fonts/" L_GUID_ID L".odttf"); |
| 1919 | wchar_t buffer[size]; |
| 1920 | wchar_t id[GUID_ID_LEN]; |
Ben Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 1921 | HR(this->createId(id, GUID_ID_LEN)); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1922 | swprintf_s(buffer, size, L"/Resources/Fonts/%s.odttf", id); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1923 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1924 | SkTScopedComPtr<IOpcPartUri> partUri; |
| 1925 | HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri), |
| 1926 | "Could not create font resource part uri."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1927 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1928 | SkTScopedComPtr<IXpsOMFontResource> xpsFontResource; |
| 1929 | HRM(this->fXpsFactory->CreateFontResource(fontStream.get(), |
| 1930 | embedding, |
| 1931 | partUri.get(), |
| 1932 | FALSE, |
| 1933 | &xpsFontResource), |
| 1934 | "Could not create font resource."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1935 | |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 1936 | //TODO: change openStream to return -1 for non-ttc, get rid of this. |
| 1937 | uint8_t* data = (uint8_t*)fontData->getMemoryBase(); |
| 1938 | bool isTTC = (data && |
| 1939 | fontData->getLength() >= sizeof(SkTTCFHeader) && |
| 1940 | ((SkTTCFHeader*)data)->ttcTag == SkTTCFHeader::TAG); |
| 1941 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1942 | TypefaceUse& newTypefaceUse = this->fTypefaces.push_back(); |
| 1943 | newTypefaceUse.typefaceId = typefaceID; |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 1944 | newTypefaceUse.ttcIndex = isTTC ? ttcIndex : -1; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1945 | newTypefaceUse.fontData = fontData; |
| 1946 | newTypefaceUse.xpsFont = xpsFontResource.release(); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1947 | |
robertphillips | 8e0c150 | 2015-07-07 10:28:43 -0700 | [diff] [blame] | 1948 | SkAutoGlyphCache agc(paint, &this->surfaceProps(), &SkMatrix::I()); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1949 | SkGlyphCache* glyphCache = agc.getCache(); |
| 1950 | unsigned int glyphCount = glyphCache->getGlyphCount(); |
| 1951 | newTypefaceUse.glyphsUsed = new SkBitSet(glyphCount); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1952 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1953 | *typefaceUse = &newTypefaceUse; |
| 1954 | return S_OK; |
| 1955 | } |
| 1956 | |
| 1957 | HRESULT SkXPSDevice::AddGlyphs(const SkDraw& d, |
| 1958 | IXpsOMObjectFactory* xpsFactory, |
| 1959 | IXpsOMCanvas* canvas, |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 1960 | TypefaceUse* font, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1961 | LPCWSTR text, |
| 1962 | XPS_GLYPH_INDEX* xpsGlyphs, |
| 1963 | UINT32 xpsGlyphsLen, |
| 1964 | XPS_POINT *origin, |
| 1965 | FLOAT fontSize, |
| 1966 | XPS_STYLE_SIMULATION sims, |
| 1967 | const SkMatrix& transform, |
| 1968 | const SkPaint& paint) { |
| 1969 | SkTScopedComPtr<IXpsOMGlyphs> glyphs; |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 1970 | HRM(xpsFactory->CreateGlyphs(font->xpsFont, &glyphs), "Could not create glyphs."); |
| 1971 | HRM(glyphs->SetFontFaceIndex(font->ttcIndex), "Could not set glyph font face index."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1972 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1973 | //XPS uses affine transformations for everything... |
| 1974 | //...except positioning text. |
| 1975 | bool useCanvasForClip; |
| 1976 | if ((transform.getType() & ~SkMatrix::kTranslate_Mask) == 0) { |
| 1977 | origin->x += SkScalarToFLOAT(transform.getTranslateX()); |
| 1978 | origin->y += SkScalarToFLOAT(transform.getTranslateY()); |
| 1979 | useCanvasForClip = false; |
| 1980 | } else { |
| 1981 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsMatrixToUse; |
| 1982 | HR(this->createXpsTransform(transform, &xpsMatrixToUse)); |
| 1983 | if (xpsMatrixToUse.get()) { |
| 1984 | HRM(glyphs->SetTransformLocal(xpsMatrixToUse.get()), |
| 1985 | "Could not set transform matrix."); |
| 1986 | useCanvasForClip = true; |
| 1987 | } else { |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 1988 | SkDEBUGFAIL("Attempt to add glyphs in perspective."); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1989 | useCanvasForClip = false; |
| 1990 | } |
| 1991 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1992 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1993 | SkTScopedComPtr<IXpsOMGlyphsEditor> glyphsEditor; |
| 1994 | HRM(glyphs->GetGlyphsEditor(&glyphsEditor), "Could not get glyph editor."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1995 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1996 | if (text) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1997 | HRM(glyphsEditor->SetUnicodeString(text), |
| 1998 | "Could not set unicode string."); |
| 1999 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2000 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2001 | if (xpsGlyphs) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2002 | HRM(glyphsEditor->SetGlyphIndices(xpsGlyphsLen, xpsGlyphs), |
| 2003 | "Could not set glyphs."); |
| 2004 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2005 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2006 | HRM(glyphsEditor->ApplyEdits(), "Could not apply glyph edits."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2007 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2008 | SkTScopedComPtr<IXpsOMBrush> xpsFillBrush; |
| 2009 | HR(this->createXpsBrush( |
| 2010 | paint, |
| 2011 | &xpsFillBrush, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2012 | useCanvasForClip ? nullptr : &transform)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2013 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2014 | HRM(glyphs->SetFillBrushLocal(xpsFillBrush.get()), |
| 2015 | "Could not set fill brush."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2016 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2017 | HRM(glyphs->SetOrigin(origin), "Could not set glyph origin."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2018 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2019 | HRM(glyphs->SetFontRenderingEmSize(fontSize), |
| 2020 | "Could not set font size."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2021 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2022 | HRM(glyphs->SetStyleSimulations(sims), |
| 2023 | "Could not set style simulations."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2024 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2025 | SkTScopedComPtr<IXpsOMVisualCollection> visuals; |
| 2026 | HRM(canvas->GetVisuals(&visuals), "Could not get glyph canvas visuals."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2027 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2028 | if (!useCanvasForClip) { |
| 2029 | HR(this->clip(glyphs.get(), d)); |
| 2030 | HRM(visuals->Append(glyphs.get()), "Could not add glyphs to canvas."); |
| 2031 | } else { |
| 2032 | SkTScopedComPtr<IXpsOMCanvas> glyphCanvas; |
| 2033 | HRM(this->fXpsFactory->CreateCanvas(&glyphCanvas), |
| 2034 | "Could not create glyph canvas."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2035 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2036 | SkTScopedComPtr<IXpsOMVisualCollection> glyphCanvasVisuals; |
| 2037 | HRM(glyphCanvas->GetVisuals(&glyphCanvasVisuals), |
| 2038 | "Could not get glyph visuals collection."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2039 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2040 | HRM(glyphCanvasVisuals->Append(glyphs.get()), |
| 2041 | "Could not add glyphs to page."); |
| 2042 | HR(this->clip(glyphCanvas.get(), d)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2043 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2044 | HRM(visuals->Append(glyphCanvas.get()), |
| 2045 | "Could not add glyph canvas to page."); |
| 2046 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2047 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2048 | return S_OK; |
| 2049 | } |
| 2050 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2051 | static int num_glyph_guess(SkPaint::TextEncoding encoding, const void* text, size_t byteLength) { |
| 2052 | switch (encoding) { |
| 2053 | case SkPaint::kUTF8_TextEncoding: |
| 2054 | return SkUTF8_CountUnichars(static_cast<const char *>(text), byteLength); |
| 2055 | case SkPaint::kUTF16_TextEncoding: |
| 2056 | return SkUTF16_CountUnichars(static_cast<const uint16_t *>(text), SkToInt(byteLength)); |
| 2057 | case SkPaint::kGlyphID_TextEncoding: |
| 2058 | return SkToInt(byteLength / 2); |
| 2059 | default: |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 2060 | SK_ABORT("Invalid Text Encoding"); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2061 | } |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2062 | return 0; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | static bool text_must_be_pathed(const SkPaint& paint, const SkMatrix& matrix) { |
| 2066 | const SkPaint::Style style = paint.getStyle(); |
| 2067 | return matrix.hasPerspective() |
| 2068 | || SkPaint::kStroke_Style == style |
| 2069 | || SkPaint::kStrokeAndFill_Style == style |
| 2070 | || paint.getMaskFilter() |
| 2071 | || paint.getRasterizer() |
| 2072 | ; |
| 2073 | } |
| 2074 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2075 | typedef SkTDArray<XPS_GLYPH_INDEX> GlyphRun; |
| 2076 | |
| 2077 | class ProcessOneGlyph { |
| 2078 | public: |
| 2079 | ProcessOneGlyph(FLOAT centemPerUnit, SkBitSet* glyphUse, GlyphRun* xpsGlyphs) |
| 2080 | : fCentemPerUnit(centemPerUnit) |
| 2081 | , fGlyphUse(glyphUse) |
| 2082 | , fXpsGlyphs(xpsGlyphs) { } |
| 2083 | |
| 2084 | void operator()(const SkGlyph& glyph, SkPoint position, SkPoint) { |
| 2085 | SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); |
| 2086 | |
| 2087 | SkScalar x = position.fX; |
| 2088 | SkScalar y = position.fY; |
| 2089 | |
| 2090 | XPS_GLYPH_INDEX* xpsGlyph = fXpsGlyphs->append(); |
| 2091 | uint16_t glyphID = glyph.getGlyphID(); |
| 2092 | fGlyphUse->setBit(glyphID, true); |
| 2093 | xpsGlyph->index = glyphID; |
| 2094 | if (1 == fXpsGlyphs->count()) { |
| 2095 | xpsGlyph->advanceWidth = 0.0f; |
| 2096 | xpsGlyph->horizontalOffset = SkScalarToFloat(x) * fCentemPerUnit; |
| 2097 | xpsGlyph->verticalOffset = SkScalarToFloat(y) * -fCentemPerUnit; |
| 2098 | } |
| 2099 | else { |
| 2100 | const XPS_GLYPH_INDEX& first = (*fXpsGlyphs)[0]; |
| 2101 | xpsGlyph->advanceWidth = 0.0f; |
| 2102 | xpsGlyph->horizontalOffset = (SkScalarToFloat(x) * fCentemPerUnit) |
| 2103 | - first.horizontalOffset; |
| 2104 | xpsGlyph->verticalOffset = (SkScalarToFloat(y) * -fCentemPerUnit) |
| 2105 | - first.verticalOffset; |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | private: |
| 2110 | /** [in] Advance width and offsets for glyphs measured in |
| 2111 | hundredths of the font em size (XPS Spec 5.1.3). */ |
| 2112 | const FLOAT fCentemPerUnit; |
| 2113 | /** [in,out] The accumulated glyphs used in the current typeface. */ |
| 2114 | SkBitSet* const fGlyphUse; |
| 2115 | /** [out] The glyphs to draw. */ |
| 2116 | GlyphRun* const fXpsGlyphs; |
| 2117 | }; |
| 2118 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2119 | void SkXPSDevice::drawText(const SkDraw& d, |
| 2120 | const void* text, size_t byteLen, |
| 2121 | SkScalar x, SkScalar y, |
| 2122 | const SkPaint& paint) { |
| 2123 | if (byteLen < 1) return; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2124 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2125 | if (text_must_be_pathed(paint, *d.fMatrix)) { |
| 2126 | SkPath path; |
| 2127 | paint.getTextPath(text, byteLen, x, y, &path); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2128 | this->drawPath(d, path, paint, nullptr, true); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2129 | //TODO: add automation "text" |
| 2130 | return; |
| 2131 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2132 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2133 | TypefaceUse* typeface; |
| 2134 | HRV(CreateTypefaceUse(paint, &typeface)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2135 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2136 | const SkMatrix& matrix = SkMatrix::I(); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2137 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2138 | SkAutoGlyphCache autoCache(paint, &this->surfaceProps(), &matrix); |
| 2139 | SkGlyphCache* cache = autoCache.getCache(); |
reed@google.com | 089130c | 2011-12-12 21:52:18 +0000 | [diff] [blame] | 2140 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2141 | // Advance width and offsets for glyphs measured in hundredths of the font em size |
| 2142 | // (XPS Spec 5.1.3). |
| 2143 | FLOAT centemPerUnit = 100.0f / SkScalarToFLOAT(paint.getTextSize()); |
| 2144 | GlyphRun xpsGlyphs; |
| 2145 | xpsGlyphs.setReserve(num_glyph_guess(paint.getTextEncoding(), |
| 2146 | static_cast<const char*>(text), byteLen)); |
| 2147 | |
| 2148 | ProcessOneGlyph processOneGlyph(centemPerUnit, typeface->glyphsUsed, &xpsGlyphs); |
| 2149 | |
| 2150 | SkFindAndPlaceGlyph::ProcessText( |
| 2151 | paint.getTextEncoding(), static_cast<const char*>(text), byteLen, |
| 2152 | SkPoint{ x, y }, matrix, paint.getTextAlign(), cache, processOneGlyph); |
| 2153 | |
| 2154 | if (xpsGlyphs.count() == 0) { |
reed@google.com | 089130c | 2011-12-12 21:52:18 +0000 | [diff] [blame] | 2155 | return; |
| 2156 | } |
| 2157 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2158 | XPS_POINT origin = { |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2159 | xpsGlyphs[0].horizontalOffset / centemPerUnit, |
| 2160 | xpsGlyphs[0].verticalOffset / -centemPerUnit, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2161 | }; |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2162 | xpsGlyphs[0].horizontalOffset = 0.0f; |
| 2163 | xpsGlyphs[0].verticalOffset = 0.0f; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2164 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2165 | HRV(AddGlyphs(d, |
| 2166 | this->fXpsFactory.get(), |
| 2167 | this->fCurrentXpsCanvas.get(), |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 2168 | typeface, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2169 | nullptr, |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2170 | xpsGlyphs.begin(), xpsGlyphs.count(), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2171 | &origin, |
| 2172 | SkScalarToFLOAT(paint.getTextSize()), |
| 2173 | XPS_STYLE_SIMULATION_NONE, |
| 2174 | *d.fMatrix, |
| 2175 | paint)); |
| 2176 | } |
| 2177 | |
| 2178 | void SkXPSDevice::drawPosText(const SkDraw& d, |
| 2179 | const void* text, size_t byteLen, |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 2180 | const SkScalar pos[], int scalarsPerPos, |
| 2181 | const SkPoint& offset, const SkPaint& paint) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2182 | if (byteLen < 1) return; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2183 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2184 | if (text_must_be_pathed(paint, *d.fMatrix)) { |
| 2185 | SkPath path; |
| 2186 | //TODO: make this work, Draw currently does not handle as well. |
| 2187 | //paint.getTextPath(text, byteLength, x, y, &path); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2188 | //this->drawPath(d, path, paint, nullptr, true); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2189 | //TODO: add automation "text" |
| 2190 | return; |
| 2191 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2192 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2193 | TypefaceUse* typeface; |
| 2194 | HRV(CreateTypefaceUse(paint, &typeface)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2195 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2196 | const SkMatrix& matrix = SkMatrix::I(); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2197 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2198 | SkAutoGlyphCache autoCache(paint, &this->surfaceProps(), &matrix); |
| 2199 | SkGlyphCache* cache = autoCache.getCache(); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2200 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2201 | // Advance width and offsets for glyphs measured in hundredths of the font em size |
| 2202 | // (XPS Spec 5.1.3). |
| 2203 | FLOAT centemPerUnit = 100.0f / SkScalarToFLOAT(paint.getTextSize()); |
| 2204 | GlyphRun xpsGlyphs; |
| 2205 | xpsGlyphs.setReserve(num_glyph_guess(paint.getTextEncoding(), |
| 2206 | static_cast<const char*>(text), byteLen)); |
| 2207 | |
| 2208 | ProcessOneGlyph processOneGlyph(centemPerUnit, typeface->glyphsUsed, &xpsGlyphs); |
| 2209 | |
| 2210 | SkFindAndPlaceGlyph::ProcessPosText( |
| 2211 | paint.getTextEncoding(), static_cast<const char*>(text), byteLen, |
| 2212 | offset, matrix, pos, scalarsPerPos, paint.getTextAlign(), cache, processOneGlyph); |
| 2213 | |
| 2214 | if (xpsGlyphs.count() == 0) { |
reed@google.com | 089130c | 2011-12-12 21:52:18 +0000 | [diff] [blame] | 2215 | return; |
| 2216 | } |
| 2217 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2218 | XPS_POINT origin = { |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2219 | xpsGlyphs[0].horizontalOffset / centemPerUnit, |
| 2220 | xpsGlyphs[0].verticalOffset / -centemPerUnit, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2221 | }; |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2222 | xpsGlyphs[0].horizontalOffset = 0.0f; |
| 2223 | xpsGlyphs[0].verticalOffset = 0.0f; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2224 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2225 | HRV(AddGlyphs(d, |
| 2226 | this->fXpsFactory.get(), |
| 2227 | this->fCurrentXpsCanvas.get(), |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 2228 | typeface, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2229 | nullptr, |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2230 | xpsGlyphs.begin(), xpsGlyphs.count(), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2231 | &origin, |
| 2232 | SkScalarToFLOAT(paint.getTextSize()), |
| 2233 | XPS_STYLE_SIMULATION_NONE, |
| 2234 | *d.fMatrix, |
| 2235 | paint)); |
| 2236 | } |
| 2237 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 2238 | void SkXPSDevice::drawDevice(const SkDraw& d, SkBaseDevice* dev, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2239 | int x, int y, |
| 2240 | const SkPaint&) { |
| 2241 | SkXPSDevice* that = static_cast<SkXPSDevice*>(dev); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2242 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2243 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform; |
| 2244 | XPS_MATRIX rawTransform = { |
| 2245 | 1.0f, |
| 2246 | 0.0f, |
| 2247 | 0.0f, |
| 2248 | 1.0f, |
| 2249 | static_cast<FLOAT>(x), |
| 2250 | static_cast<FLOAT>(y), |
| 2251 | }; |
| 2252 | HRVM(this->fXpsFactory->CreateMatrixTransform(&rawTransform, &xpsTransform), |
| 2253 | "Could not create layer transform."); |
| 2254 | HRVM(that->fCurrentXpsCanvas->SetTransformLocal(xpsTransform.get()), |
| 2255 | "Could not set layer transform."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2256 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2257 | //Get the current visual collection and add the layer to it. |
| 2258 | SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals; |
| 2259 | HRVM(this->fCurrentXpsCanvas->GetVisuals(¤tVisuals), |
| 2260 | "Could not get current visuals for layer."); |
| 2261 | HRVM(currentVisuals->Append(that->fCurrentXpsCanvas.get()), |
| 2262 | "Could not add layer to current visuals."); |
| 2263 | } |
| 2264 | |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 2265 | SkBaseDevice* SkXPSDevice::onCreateDevice(const CreateInfo& info, const SkPaint*) { |
bungeman@google.com | 635091f | 2013-10-01 15:03:18 +0000 | [diff] [blame] | 2266 | //Conditional for bug compatibility with PDF device. |
| 2267 | #if 0 |
fmalita | 6987dca | 2014-11-13 08:33:37 -0800 | [diff] [blame] | 2268 | if (SkBaseDevice::kGeneral_Usage == info.fUsage) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2269 | return nullptr; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2270 | //To what stream do we write? |
| 2271 | //SkXPSDevice* dev = new SkXPSDevice(this); |
| 2272 | //SkSize s = SkSize::Make(width, height); |
| 2273 | //dev->BeginCanvas(s, s, SkMatrix::I()); |
| 2274 | //return dev; |
| 2275 | } |
bungeman@google.com | 635091f | 2013-10-01 15:03:18 +0000 | [diff] [blame] | 2276 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2277 | return new SkXPSDevice(this->fXpsFactory.get()); |
| 2278 | } |
| 2279 | |
mtklein | 1ee7651 | 2015-11-02 10:20:27 -0800 | [diff] [blame] | 2280 | #endif//defined(SK_BUILD_FOR_WIN32) |