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> |
halcanary | bfa9275 | 2016-05-31 11:23:42 -0700 | [diff] [blame] | 21 | #include <limits> |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 22 | |
| 23 | #include "SkColor.h" |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 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 | |
halcanary | bfa9275 | 2016-05-31 11:23:42 -0700 | [diff] [blame] | 193 | template <typename T> static constexpr size_t sk_digits_in() { |
| 194 | return static_cast<size_t>(std::numeric_limits<T>::digits10 + 1); |
| 195 | } |
| 196 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 197 | HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page, |
| 198 | const unsigned int pageNum, |
| 199 | IXpsOMImageResource** image) { |
| 200 | SkTScopedComPtr<IXpsOMThumbnailGenerator> thumbnailGenerator; |
| 201 | HRM(CoCreateInstance( |
| 202 | CLSID_XpsOMThumbnailGenerator, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 203 | nullptr, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 204 | CLSCTX_INPROC_SERVER, |
| 205 | IID_PPV_ARGS(&thumbnailGenerator)), |
| 206 | "Could not create thumbnail generator."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 207 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 208 | SkTScopedComPtr<IOpcPartUri> partUri; |
halcanary | bfa9275 | 2016-05-31 11:23:42 -0700 | [diff] [blame] | 209 | constexpr size_t size = SkTMax( |
| 210 | SK_ARRAY_COUNT(L"/Documents/1/Metadata/.png") + sk_digits_in<decltype(pageNum)>(), |
| 211 | SK_ARRAY_COUNT(L"/Metadata/" L_GUID_ID L".png")); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 212 | wchar_t buffer[size]; |
| 213 | if (pageNum > 0) { |
| 214 | swprintf_s(buffer, size, L"/Documents/1/Metadata/%u.png", pageNum); |
| 215 | } else { |
| 216 | wchar_t id[GUID_ID_LEN]; |
Ben Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 217 | HR(this->createId(id, GUID_ID_LEN)); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 218 | swprintf_s(buffer, size, L"/Metadata/%s.png", id); |
| 219 | } |
| 220 | HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri), |
| 221 | "Could not create thumbnail part uri."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 222 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 223 | HRM(thumbnailGenerator->GenerateThumbnail(page, |
| 224 | XPS_IMAGE_TYPE_PNG, |
| 225 | XPS_THUMBNAIL_SIZE_LARGE, |
| 226 | partUri.get(), |
| 227 | image), |
| 228 | "Could not generate thumbnail."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 229 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 230 | return S_OK; |
| 231 | } |
| 232 | |
| 233 | HRESULT SkXPSDevice::createXpsPage(const XPS_SIZE& pageSize, |
| 234 | IXpsOMPage** page) { |
halcanary | bfa9275 | 2016-05-31 11:23:42 -0700 | [diff] [blame] | 235 | constexpr size_t size = |
| 236 | SK_ARRAY_COUNT(L"/Documents/1/Pages/.fpage") |
| 237 | + sk_digits_in<decltype(fCurrentPage)>(); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 238 | wchar_t buffer[size]; |
| 239 | swprintf_s(buffer, size, L"/Documents/1/Pages/%u.fpage", |
| 240 | this->fCurrentPage); |
| 241 | SkTScopedComPtr<IOpcPartUri> partUri; |
| 242 | HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri), |
| 243 | "Could not create page part uri."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 244 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 245 | //If the language is unknown, use "und" (XPS Spec 2.3.5.1). |
| 246 | HRM(this->fXpsFactory->CreatePage(&pageSize, |
| 247 | L"und", |
| 248 | partUri.get(), |
| 249 | page), |
| 250 | "Could not create page."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 251 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 252 | return S_OK; |
| 253 | } |
| 254 | |
| 255 | HRESULT SkXPSDevice::initXpsDocumentWriter(IXpsOMImageResource* image) { |
| 256 | //Create package writer. |
| 257 | { |
| 258 | SkTScopedComPtr<IOpcPartUri> partUri; |
| 259 | HRM(this->fXpsFactory->CreatePartUri(L"/FixedDocumentSequence.fdseq", |
| 260 | &partUri), |
| 261 | "Could not create document sequence part uri."); |
| 262 | HRM(this->fXpsFactory->CreatePackageWriterOnStream( |
| 263 | this->fOutputStream.get(), |
| 264 | TRUE, |
| 265 | XPS_INTERLEAVING_OFF, //XPS_INTERLEAVING_ON, |
| 266 | partUri.get(), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 267 | nullptr, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 268 | image, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 269 | nullptr, |
| 270 | nullptr, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 271 | &this->fPackageWriter), |
| 272 | "Could not create package writer."); |
| 273 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 274 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 275 | //Begin the lone document. |
| 276 | { |
| 277 | SkTScopedComPtr<IOpcPartUri> partUri; |
| 278 | HRM(this->fXpsFactory->CreatePartUri( |
| 279 | L"/Documents/1/FixedDocument.fdoc", |
| 280 | &partUri), |
| 281 | "Could not create fixed document part uri."); |
| 282 | HRM(this->fPackageWriter->StartNewDocument(partUri.get(), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 283 | nullptr, |
| 284 | nullptr, |
| 285 | nullptr, |
| 286 | nullptr), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 287 | "Could not start document."); |
| 288 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 289 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 290 | return S_OK; |
| 291 | } |
| 292 | |
| 293 | bool SkXPSDevice::endSheet() { |
| 294 | //XPS is fixed at 96dpi (XPS Spec 11.1). |
| 295 | static const float xpsDPI = 96.0f; |
| 296 | static const float inchesPerMeter = 10000.0f / 254.0f; |
| 297 | static const float targetUnitsPerMeter = xpsDPI * inchesPerMeter; |
| 298 | const float scaleX = targetUnitsPerMeter |
| 299 | / SkScalarToFLOAT(this->fCurrentUnitsPerMeter.fX); |
| 300 | const float scaleY = targetUnitsPerMeter |
| 301 | / SkScalarToFLOAT(this->fCurrentUnitsPerMeter.fY); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 302 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 303 | //Create the scale canvas. |
| 304 | SkTScopedComPtr<IXpsOMCanvas> scaleCanvas; |
| 305 | HRBM(this->fXpsFactory->CreateCanvas(&scaleCanvas), |
| 306 | "Could not create scale canvas."); |
| 307 | SkTScopedComPtr<IXpsOMVisualCollection> scaleCanvasVisuals; |
| 308 | HRBM(scaleCanvas->GetVisuals(&scaleCanvasVisuals), |
| 309 | "Could not get scale canvas visuals."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 310 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 311 | SkTScopedComPtr<IXpsOMMatrixTransform> geomToPhys; |
| 312 | XPS_MATRIX rawGeomToPhys = { scaleX, 0, 0, scaleY, 0, 0, }; |
| 313 | HRBM(this->fXpsFactory->CreateMatrixTransform(&rawGeomToPhys, &geomToPhys), |
| 314 | "Could not create geometry to physical transform."); |
| 315 | HRBM(scaleCanvas->SetTransformLocal(geomToPhys.get()), |
| 316 | "Could not set transform on 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 | //Add the content canvas to the scale canvas. |
| 319 | HRBM(scaleCanvasVisuals->Append(this->fCurrentXpsCanvas.get()), |
| 320 | "Could not add base canvas to scale canvas."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 321 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 322 | //Create the page. |
| 323 | XPS_SIZE pageSize = { |
| 324 | SkScalarToFLOAT(this->fCurrentCanvasSize.width()) * scaleX, |
| 325 | SkScalarToFLOAT(this->fCurrentCanvasSize.height()) * scaleY, |
| 326 | }; |
| 327 | SkTScopedComPtr<IXpsOMPage> page; |
| 328 | HRB(this->createXpsPage(pageSize, &page)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 329 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 330 | SkTScopedComPtr<IXpsOMVisualCollection> pageVisuals; |
| 331 | HRBM(page->GetVisuals(&pageVisuals), "Could not get page visuals."); |
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 | //Add the scale canvas to the page. |
| 334 | HRBM(pageVisuals->Append(scaleCanvas.get()), |
| 335 | "Could not add scale canvas to page."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 336 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 337 | //Create the package writer if it hasn't been created yet. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 338 | if (nullptr == this->fPackageWriter.get()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 339 | SkTScopedComPtr<IXpsOMImageResource> image; |
| 340 | //Ignore return, thumbnail is completely optional. |
| 341 | this->createXpsThumbnail(page.get(), 0, &image); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 342 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 343 | HRB(this->initXpsDocumentWriter(image.get())); |
| 344 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 345 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 346 | HRBM(this->fPackageWriter->AddPage(page.get(), |
| 347 | &pageSize, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 348 | nullptr, |
| 349 | nullptr, |
| 350 | nullptr, |
| 351 | nullptr), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 352 | "Could not write the page."); |
| 353 | this->fCurrentXpsCanvas.reset(); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 354 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 355 | return true; |
| 356 | } |
| 357 | |
| 358 | static HRESULT subset_typeface(SkXPSDevice::TypefaceUse* current) { |
| 359 | //CreateFontPackage wants unsigned short. |
| 360 | //Microsoft, Y U NO stdint.h? |
| 361 | SkTDArray<unsigned short> keepList; |
| 362 | current->glyphsUsed->exportTo(&keepList); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 363 | |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 364 | int ttcCount = (current->ttcIndex + 1); |
| 365 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 366 | //The following are declared with the types required by CreateFontPackage. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 367 | unsigned char *fontPackageBufferRaw = nullptr; |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 368 | unsigned long fontPackageBufferSize; |
| 369 | unsigned long bytesWritten; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 370 | unsigned long result = CreateFontPackage( |
| 371 | (unsigned char *) current->fontData->getMemoryBase(), |
| 372 | (unsigned long) current->fontData->getLength(), |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 373 | &fontPackageBufferRaw, |
| 374 | &fontPackageBufferSize, |
| 375 | &bytesWritten, |
| 376 | TTFCFP_FLAGS_SUBSET | TTFCFP_FLAGS_GLYPHLIST | (ttcCount > 0 ? TTFCFP_FLAGS_TTC : 0), |
| 377 | current->ttcIndex, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 378 | TTFCFP_SUBSET, |
| 379 | 0, |
| 380 | 0, |
| 381 | 0, |
| 382 | keepList.begin(), |
| 383 | keepList.count(), |
| 384 | sk_malloc_throw, |
| 385 | sk_realloc_throw, |
| 386 | sk_free, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 387 | nullptr); |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 388 | SkAutoTMalloc<unsigned char> fontPackageBuffer(fontPackageBufferRaw); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 389 | if (result != NO_ERROR) { |
| 390 | SkDEBUGF(("CreateFontPackage Error %lu", result)); |
| 391 | return E_UNEXPECTED; |
| 392 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 393 | |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 394 | // If it was originally a ttc, keep it a ttc. |
| 395 | // CreateFontPackage over-allocates, realloc usually decreases the size substantially. |
| 396 | size_t extra; |
| 397 | if (ttcCount > 0) { |
| 398 | // Create space for a ttc header. |
| 399 | extra = sizeof(SkTTCFHeader) + (ttcCount * sizeof(SK_OT_ULONG)); |
| 400 | fontPackageBuffer.realloc(bytesWritten + extra); |
| 401 | //overlap is certain, use memmove |
| 402 | memmove(fontPackageBuffer.get() + extra, fontPackageBuffer.get(), bytesWritten); |
| 403 | |
| 404 | // Write the ttc header. |
| 405 | SkTTCFHeader* ttcfHeader = reinterpret_cast<SkTTCFHeader*>(fontPackageBuffer.get()); |
| 406 | ttcfHeader->ttcTag = SkTTCFHeader::TAG; |
| 407 | ttcfHeader->version = SkTTCFHeader::version_1; |
| 408 | ttcfHeader->numOffsets = SkEndian_SwapBE32(ttcCount); |
| 409 | SK_OT_ULONG* offsetPtr = SkTAfter<SK_OT_ULONG>(ttcfHeader); |
| 410 | for (int i = 0; i < ttcCount; ++i, ++offsetPtr) { |
bsalomon | 0aa5cea | 2014-12-15 09:13:35 -0800 | [diff] [blame] | 411 | *offsetPtr = SkEndian_SwapBE32(SkToU32(extra)); |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | // Fix up offsets in sfnt table entries. |
| 415 | SkSFNTHeader* sfntHeader = SkTAddOffset<SkSFNTHeader>(fontPackageBuffer.get(), extra); |
| 416 | int numTables = SkEndian_SwapBE16(sfntHeader->numTables); |
| 417 | SkSFNTHeader::TableDirectoryEntry* tableDirectory = |
| 418 | SkTAfter<SkSFNTHeader::TableDirectoryEntry>(sfntHeader); |
| 419 | for (int i = 0; i < numTables; ++i, ++tableDirectory) { |
| 420 | tableDirectory->offset = SkEndian_SwapBE32( |
bsalomon | 0aa5cea | 2014-12-15 09:13:35 -0800 | [diff] [blame] | 421 | SkToU32(SkEndian_SwapBE32(SkToU32(tableDirectory->offset)) + extra)); |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 422 | } |
| 423 | } else { |
| 424 | extra = 0; |
| 425 | fontPackageBuffer.realloc(bytesWritten); |
| 426 | } |
| 427 | |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 428 | SkAutoTDelete<SkMemoryStream> newStream(new SkMemoryStream()); |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 429 | newStream->setMemoryOwned(fontPackageBuffer.release(), bytesWritten + extra); |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 430 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 431 | SkTScopedComPtr<IStream> newIStream; |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 432 | SkIStream::CreateFromSkStream(newStream.release(), true, &newIStream); |
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 | XPS_FONT_EMBEDDING embedding; |
| 435 | HRM(current->xpsFont->GetEmbeddingOption(&embedding), |
| 436 | "Could not get embedding option 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 | SkTScopedComPtr<IOpcPartUri> partUri; |
| 439 | HRM(current->xpsFont->GetPartName(&partUri), |
| 440 | "Could not get part uri from font."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 441 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 442 | HRM(current->xpsFont->SetContent( |
| 443 | newIStream.get(), |
| 444 | embedding, |
| 445 | partUri.get()), |
| 446 | "Could not set new stream for subsetted font."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 447 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 448 | return S_OK; |
| 449 | } |
| 450 | |
| 451 | bool SkXPSDevice::endPortfolio() { |
| 452 | //Subset fonts |
| 453 | if (!this->fTypefaces.empty()) { |
| 454 | SkXPSDevice::TypefaceUse* current = &this->fTypefaces.front(); |
| 455 | const TypefaceUse* last = &this->fTypefaces.back(); |
| 456 | for (; current <= last; ++current) { |
| 457 | //Ignore return for now, if it didn't subset, let it be. |
| 458 | subset_typeface(current); |
| 459 | } |
| 460 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 461 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 462 | HRBM(this->fPackageWriter->Close(), "Could not close writer."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 463 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 464 | return true; |
| 465 | } |
| 466 | |
| 467 | static XPS_COLOR xps_color(const SkColor skColor) { |
| 468 | //XPS uses non-pre-multiplied alpha (XPS Spec 11.4). |
| 469 | XPS_COLOR xpsColor; |
| 470 | xpsColor.colorType = XPS_COLOR_TYPE_SRGB; |
| 471 | xpsColor.value.sRGB.alpha = SkColorGetA(skColor); |
| 472 | xpsColor.value.sRGB.red = SkColorGetR(skColor); |
| 473 | xpsColor.value.sRGB.green = SkColorGetG(skColor); |
| 474 | xpsColor.value.sRGB.blue = SkColorGetB(skColor); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 475 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 476 | return xpsColor; |
| 477 | } |
| 478 | |
| 479 | static XPS_POINT xps_point(const SkPoint& point) { |
| 480 | XPS_POINT xpsPoint = { |
| 481 | SkScalarToFLOAT(point.fX), |
| 482 | SkScalarToFLOAT(point.fY), |
| 483 | }; |
| 484 | return xpsPoint; |
| 485 | } |
| 486 | |
| 487 | static XPS_POINT xps_point(const SkPoint& point, const SkMatrix& matrix) { |
| 488 | SkPoint skTransformedPoint; |
| 489 | matrix.mapXY(point.fX, point.fY, &skTransformedPoint); |
| 490 | return xps_point(skTransformedPoint); |
| 491 | } |
| 492 | |
| 493 | static XPS_SPREAD_METHOD xps_spread_method(SkShader::TileMode tileMode) { |
| 494 | switch (tileMode) { |
| 495 | case SkShader::kClamp_TileMode: |
| 496 | return XPS_SPREAD_METHOD_PAD; |
| 497 | case SkShader::kRepeat_TileMode: |
| 498 | return XPS_SPREAD_METHOD_REPEAT; |
| 499 | case SkShader::kMirror_TileMode: |
| 500 | return XPS_SPREAD_METHOD_REFLECT; |
| 501 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 502 | SkDEBUGFAIL("Unknown tile mode."); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 503 | } |
| 504 | return XPS_SPREAD_METHOD_PAD; |
| 505 | } |
| 506 | |
| 507 | static void transform_offsets(SkScalar* stopOffsets, const int numOffsets, |
| 508 | const SkPoint& start, const SkPoint& end, |
| 509 | const SkMatrix& transform) { |
| 510 | SkPoint startTransformed; |
| 511 | transform.mapXY(start.fX, start.fY, &startTransformed); |
| 512 | SkPoint endTransformed; |
| 513 | transform.mapXY(end.fX, end.fY, &endTransformed); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 514 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 515 | //Manhattan distance between transformed start and end. |
| 516 | SkScalar startToEnd = (endTransformed.fX - startTransformed.fX) |
| 517 | + (endTransformed.fY - startTransformed.fY); |
| 518 | if (SkScalarNearlyZero(startToEnd)) { |
| 519 | for (int i = 0; i < numOffsets; ++i) { |
| 520 | stopOffsets[i] = 0; |
| 521 | } |
| 522 | return; |
| 523 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 524 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 525 | for (int i = 0; i < numOffsets; ++i) { |
| 526 | SkPoint stop; |
| 527 | stop.fX = SkScalarMul(end.fX - start.fX, stopOffsets[i]); |
| 528 | stop.fY = SkScalarMul(end.fY - start.fY, stopOffsets[i]); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 529 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 530 | SkPoint stopTransformed; |
| 531 | transform.mapXY(stop.fX, stop.fY, &stopTransformed); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 532 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 533 | //Manhattan distance between transformed start and stop. |
| 534 | SkScalar startToStop = (stopTransformed.fX - startTransformed.fX) |
| 535 | + (stopTransformed.fY - startTransformed.fY); |
| 536 | //Percentage along transformed line. |
reed | 80ea19c | 2015-05-12 10:37:34 -0700 | [diff] [blame] | 537 | stopOffsets[i] = startToStop / startToEnd; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
| 541 | HRESULT SkXPSDevice::createXpsTransform(const SkMatrix& matrix, |
| 542 | IXpsOMMatrixTransform** xpsTransform) { |
| 543 | SkScalar affine[6]; |
| 544 | if (!matrix.asAffine(affine)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 545 | *xpsTransform = nullptr; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 546 | return S_FALSE; |
| 547 | } |
| 548 | XPS_MATRIX rawXpsMatrix = { |
| 549 | SkScalarToFLOAT(affine[SkMatrix::kAScaleX]), |
| 550 | SkScalarToFLOAT(affine[SkMatrix::kASkewY]), |
| 551 | SkScalarToFLOAT(affine[SkMatrix::kASkewX]), |
| 552 | SkScalarToFLOAT(affine[SkMatrix::kAScaleY]), |
| 553 | SkScalarToFLOAT(affine[SkMatrix::kATransX]), |
| 554 | SkScalarToFLOAT(affine[SkMatrix::kATransY]), |
| 555 | }; |
| 556 | HRM(this->fXpsFactory->CreateMatrixTransform(&rawXpsMatrix, xpsTransform), |
| 557 | "Could not create transform."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 558 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 559 | return S_OK; |
| 560 | } |
| 561 | |
| 562 | HRESULT SkXPSDevice::createPath(IXpsOMGeometryFigure* figure, |
| 563 | IXpsOMVisualCollection* visuals, |
| 564 | IXpsOMPath** path) { |
| 565 | SkTScopedComPtr<IXpsOMGeometry> geometry; |
| 566 | HRM(this->fXpsFactory->CreateGeometry(&geometry), |
| 567 | "Could not create geometry."); |
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 | SkTScopedComPtr<IXpsOMGeometryFigureCollection> figureCollection; |
| 570 | HRM(geometry->GetFigures(&figureCollection), "Could not get figures."); |
| 571 | HRM(figureCollection->Append(figure), "Could not add figure."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 572 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 573 | HRM(this->fXpsFactory->CreatePath(path), "Could not create path."); |
| 574 | HRM((*path)->SetGeometryLocal(geometry.get()), "Could not set geometry"); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 575 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 576 | HRM(visuals->Append(*path), "Could not add path to visuals."); |
| 577 | return S_OK; |
| 578 | } |
| 579 | |
| 580 | HRESULT SkXPSDevice::createXpsSolidColorBrush(const SkColor skColor, |
| 581 | const SkAlpha alpha, |
| 582 | IXpsOMBrush** xpsBrush) { |
| 583 | XPS_COLOR xpsColor = xps_color(skColor); |
| 584 | SkTScopedComPtr<IXpsOMSolidColorBrush> solidBrush; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 585 | HRM(this->fXpsFactory->CreateSolidColorBrush(&xpsColor, nullptr, &solidBrush), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 586 | "Could not create solid color brush."); |
| 587 | HRM(solidBrush->SetOpacity(alpha / 255.0f), "Could not set opacity."); |
| 588 | HRM(solidBrush->QueryInterface<IXpsOMBrush>(xpsBrush), "QI Fail."); |
| 589 | return S_OK; |
| 590 | } |
| 591 | |
| 592 | HRESULT SkXPSDevice::sideOfClamp(const SkRect& areaToFill, |
| 593 | const XPS_RECT& imageViewBox, |
| 594 | IXpsOMImageResource* image, |
| 595 | IXpsOMVisualCollection* visuals) { |
| 596 | SkTScopedComPtr<IXpsOMGeometryFigure> areaToFillFigure; |
| 597 | HR(this->createXpsRect(areaToFill, FALSE, TRUE, &areaToFillFigure)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 598 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 599 | SkTScopedComPtr<IXpsOMPath> areaToFillPath; |
| 600 | HR(this->createPath(areaToFillFigure.get(), visuals, &areaToFillPath)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 601 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 602 | SkTScopedComPtr<IXpsOMImageBrush> areaToFillBrush; |
| 603 | HRM(this->fXpsFactory->CreateImageBrush(image, |
| 604 | &imageViewBox, |
| 605 | &imageViewBox, |
| 606 | &areaToFillBrush), |
| 607 | "Could not create brush for side of clamp."); |
| 608 | HRM(areaToFillBrush->SetTileMode(XPS_TILE_MODE_FLIPXY), |
| 609 | "Could not set tile mode for side of clamp."); |
| 610 | HRM(areaToFillPath->SetFillBrushLocal(areaToFillBrush.get()), |
| 611 | "Could not set brush for side of clamp"); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 612 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 613 | return S_OK; |
| 614 | } |
| 615 | |
| 616 | HRESULT SkXPSDevice::cornerOfClamp(const SkRect& areaToFill, |
| 617 | const SkColor color, |
| 618 | IXpsOMVisualCollection* visuals) { |
| 619 | SkTScopedComPtr<IXpsOMGeometryFigure> areaToFillFigure; |
| 620 | HR(this->createXpsRect(areaToFill, FALSE, TRUE, &areaToFillFigure)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 621 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 622 | SkTScopedComPtr<IXpsOMPath> areaToFillPath; |
| 623 | HR(this->createPath(areaToFillFigure.get(), visuals, &areaToFillPath)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 624 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 625 | SkTScopedComPtr<IXpsOMBrush> areaToFillBrush; |
| 626 | HR(this->createXpsSolidColorBrush(color, 0xFF, &areaToFillBrush)); |
| 627 | HRM(areaToFillPath->SetFillBrushLocal(areaToFillBrush.get()), |
| 628 | "Could not set brush for corner of clamp."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 629 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 630 | return S_OK; |
| 631 | } |
| 632 | |
| 633 | static const XPS_TILE_MODE XTM_N = XPS_TILE_MODE_NONE; |
| 634 | static const XPS_TILE_MODE XTM_T = XPS_TILE_MODE_TILE; |
| 635 | static const XPS_TILE_MODE XTM_X = XPS_TILE_MODE_FLIPX; |
| 636 | static const XPS_TILE_MODE XTM_Y = XPS_TILE_MODE_FLIPY; |
| 637 | static const XPS_TILE_MODE XTM_XY = XPS_TILE_MODE_FLIPXY; |
| 638 | |
| 639 | //TODO(bungeman): In the future, should skia add None, |
| 640 | //handle None+Mirror and None+Repeat correctly. |
| 641 | //None is currently an internal hack so masks don't repeat (None+None only). |
| 642 | static XPS_TILE_MODE SkToXpsTileMode[SkShader::kTileModeCount+1] |
| 643 | [SkShader::kTileModeCount+1] = { |
| 644 | //Clamp //Repeat //Mirror //None |
| 645 | /*Clamp */ XTM_N, XTM_T, XTM_Y, XTM_N, |
| 646 | /*Repeat*/ XTM_T, XTM_T, XTM_Y, XTM_N, |
| 647 | /*Mirror*/ XTM_X, XTM_X, XTM_XY, XTM_X, |
| 648 | /*None */ XTM_N, XTM_N, XTM_Y, XTM_N, |
| 649 | }; |
| 650 | |
| 651 | HRESULT SkXPSDevice::createXpsImageBrush( |
| 652 | const SkBitmap& bitmap, |
| 653 | const SkMatrix& localMatrix, |
| 654 | const SkShader::TileMode (&xy)[2], |
| 655 | const SkAlpha alpha, |
| 656 | IXpsOMTileBrush** xpsBrush) { |
| 657 | SkDynamicMemoryWStream write; |
| 658 | if (!SkImageEncoder::EncodeStream(&write, bitmap, |
| 659 | SkImageEncoder::kPNG_Type, 100)) { |
| 660 | HRM(E_FAIL, "Unable to encode bitmap as png."); |
| 661 | } |
| 662 | SkMemoryStream* read = new SkMemoryStream; |
| 663 | read->setData(write.copyToData())->unref(); |
| 664 | SkTScopedComPtr<IStream> readWrapper; |
| 665 | HRM(SkIStream::CreateFromSkStream(read, true, &readWrapper), |
| 666 | "Could not create stream from png data."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 667 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 668 | const size_t size = |
| 669 | SK_ARRAY_COUNT(L"/Documents/1/Resources/Images/" L_GUID_ID L".png"); |
| 670 | wchar_t buffer[size]; |
| 671 | wchar_t id[GUID_ID_LEN]; |
Ben Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 672 | HR(this->createId(id, GUID_ID_LEN)); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 673 | 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] | 674 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 675 | SkTScopedComPtr<IOpcPartUri> imagePartUri; |
| 676 | HRM(this->fXpsFactory->CreatePartUri(buffer, &imagePartUri), |
| 677 | "Could not create image part uri."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 678 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 679 | SkTScopedComPtr<IXpsOMImageResource> imageResource; |
| 680 | HRM(this->fXpsFactory->CreateImageResource( |
| 681 | readWrapper.get(), |
| 682 | XPS_IMAGE_TYPE_PNG, |
| 683 | imagePartUri.get(), |
| 684 | &imageResource), |
| 685 | "Could not create image resource."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 686 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 687 | XPS_RECT bitmapRect = { |
| 688 | 0.0, 0.0, |
| 689 | static_cast<FLOAT>(bitmap.width()), static_cast<FLOAT>(bitmap.height()) |
| 690 | }; |
| 691 | SkTScopedComPtr<IXpsOMImageBrush> xpsImageBrush; |
| 692 | HRM(this->fXpsFactory->CreateImageBrush(imageResource.get(), |
| 693 | &bitmapRect, &bitmapRect, |
| 694 | &xpsImageBrush), |
| 695 | "Could not create image brush."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 696 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 697 | if (SkShader::kClamp_TileMode != xy[0] && |
| 698 | SkShader::kClamp_TileMode != xy[1]) { |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 699 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 700 | HRM(xpsImageBrush->SetTileMode(SkToXpsTileMode[xy[0]][xy[1]]), |
| 701 | "Could not set image tile mode"); |
| 702 | HRM(xpsImageBrush->SetOpacity(alpha / 255.0f), |
| 703 | "Could not set image opacity."); |
| 704 | HRM(xpsImageBrush->QueryInterface(xpsBrush), "QI failed."); |
| 705 | } else { |
| 706 | //TODO(bungeman): compute how big this really needs to be. |
| 707 | const SkScalar BIG = SkIntToScalar(1000); //SK_ScalarMax; |
| 708 | const FLOAT BIG_F = SkScalarToFLOAT(BIG); |
| 709 | const SkScalar bWidth = SkIntToScalar(bitmap.width()); |
| 710 | const SkScalar bHeight = SkIntToScalar(bitmap.height()); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 711 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 712 | //create brush canvas |
| 713 | SkTScopedComPtr<IXpsOMCanvas> brushCanvas; |
| 714 | HRM(this->fXpsFactory->CreateCanvas(&brushCanvas), |
| 715 | "Could not create image brush canvas."); |
| 716 | SkTScopedComPtr<IXpsOMVisualCollection> brushVisuals; |
| 717 | HRM(brushCanvas->GetVisuals(&brushVisuals), |
| 718 | "Could not get image brush canvas visuals collection."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 719 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 720 | //create central figure |
| 721 | const SkRect bitmapPoints = SkRect::MakeLTRB(0, 0, bWidth, bHeight); |
| 722 | SkTScopedComPtr<IXpsOMGeometryFigure> centralFigure; |
| 723 | HR(this->createXpsRect(bitmapPoints, FALSE, TRUE, ¢ralFigure)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 724 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 725 | SkTScopedComPtr<IXpsOMPath> centralPath; |
| 726 | HR(this->createPath(centralFigure.get(), |
| 727 | brushVisuals.get(), |
| 728 | ¢ralPath)); |
| 729 | HRM(xpsImageBrush->SetTileMode(XPS_TILE_MODE_FLIPXY), |
| 730 | "Could not set tile mode for image brush central path."); |
| 731 | HRM(centralPath->SetFillBrushLocal(xpsImageBrush.get()), |
| 732 | "Could not set fill brush for image brush central path."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 733 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 734 | //add left/right |
| 735 | if (SkShader::kClamp_TileMode == xy[0]) { |
| 736 | SkRect leftArea = SkRect::MakeLTRB(-BIG, 0, 0, bHeight); |
| 737 | XPS_RECT leftImageViewBox = { |
| 738 | 0.0, 0.0, |
| 739 | 1.0, static_cast<FLOAT>(bitmap.height()), |
| 740 | }; |
| 741 | HR(this->sideOfClamp(leftArea, leftImageViewBox, |
| 742 | imageResource.get(), |
| 743 | brushVisuals.get())); |
| 744 | |
| 745 | SkRect rightArea = SkRect::MakeLTRB(bWidth, 0, BIG, bHeight); |
| 746 | XPS_RECT rightImageViewBox = { |
| 747 | bitmap.width() - 1.0f, 0.0f, |
| 748 | 1.0f, static_cast<FLOAT>(bitmap.height()), |
| 749 | }; |
| 750 | HR(this->sideOfClamp(rightArea, rightImageViewBox, |
| 751 | imageResource.get(), |
| 752 | brushVisuals.get())); |
| 753 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 754 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 755 | //add top/bottom |
| 756 | if (SkShader::kClamp_TileMode == xy[1]) { |
| 757 | SkRect topArea = SkRect::MakeLTRB(0, -BIG, bWidth, 0); |
| 758 | XPS_RECT topImageViewBox = { |
| 759 | 0.0, 0.0, |
| 760 | static_cast<FLOAT>(bitmap.width()), 1.0, |
| 761 | }; |
| 762 | HR(this->sideOfClamp(topArea, topImageViewBox, |
| 763 | imageResource.get(), |
| 764 | brushVisuals.get())); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 765 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 766 | SkRect bottomArea = SkRect::MakeLTRB(0, bHeight, bWidth, BIG); |
| 767 | XPS_RECT bottomImageViewBox = { |
| 768 | 0.0f, bitmap.height() - 1.0f, |
| 769 | static_cast<FLOAT>(bitmap.width()), 1.0f, |
| 770 | }; |
| 771 | HR(this->sideOfClamp(bottomArea, bottomImageViewBox, |
| 772 | imageResource.get(), |
| 773 | brushVisuals.get())); |
| 774 | } |
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 | //add tl, tr, bl, br |
| 777 | if (SkShader::kClamp_TileMode == xy[0] && |
| 778 | SkShader::kClamp_TileMode == xy[1]) { |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 779 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 780 | SkAutoLockPixels alp(bitmap); |
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 tlColor = bitmap.getColor(0,0); |
| 783 | const SkRect tlArea = SkRect::MakeLTRB(-BIG, -BIG, 0, 0); |
| 784 | HR(this->cornerOfClamp(tlArea, tlColor, 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 trColor = bitmap.getColor(bitmap.width()-1,0); |
| 787 | const SkRect trArea = SkRect::MakeLTRB(bWidth, -BIG, BIG, 0); |
| 788 | HR(this->cornerOfClamp(trArea, trColor, brushVisuals.get())); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 789 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 790 | const SkColor brColor = bitmap.getColor(bitmap.width()-1, |
| 791 | bitmap.height()-1); |
| 792 | const SkRect brArea = SkRect::MakeLTRB(bWidth, bHeight, BIG, BIG); |
| 793 | HR(this->cornerOfClamp(brArea, brColor, brushVisuals.get())); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 794 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 795 | const SkColor blColor = bitmap.getColor(0,bitmap.height()-1); |
| 796 | const SkRect blArea = SkRect::MakeLTRB(-BIG, bHeight, 0, BIG); |
| 797 | HR(this->cornerOfClamp(blArea, blColor, brushVisuals.get())); |
| 798 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 799 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 800 | //create visual brush from canvas |
| 801 | XPS_RECT bound = {}; |
| 802 | if (SkShader::kClamp_TileMode == xy[0] && |
| 803 | SkShader::kClamp_TileMode == xy[1]) { |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 804 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 805 | bound.x = BIG_F / -2; |
| 806 | bound.y = BIG_F / -2; |
| 807 | bound.width = BIG_F; |
| 808 | bound.height = BIG_F; |
| 809 | } else if (SkShader::kClamp_TileMode == xy[0]) { |
| 810 | bound.x = BIG_F / -2; |
| 811 | bound.y = 0.0f; |
| 812 | bound.width = BIG_F; |
| 813 | bound.height = static_cast<FLOAT>(bitmap.height()); |
| 814 | } else if (SkShader::kClamp_TileMode == xy[1]) { |
| 815 | bound.x = 0; |
| 816 | bound.y = BIG_F / -2; |
| 817 | bound.width = static_cast<FLOAT>(bitmap.width()); |
| 818 | bound.height = BIG_F; |
| 819 | } |
| 820 | SkTScopedComPtr<IXpsOMVisualBrush> clampBrush; |
| 821 | HRM(this->fXpsFactory->CreateVisualBrush(&bound, &bound, &clampBrush), |
| 822 | "Could not create visual brush for image brush."); |
| 823 | HRM(clampBrush->SetVisualLocal(brushCanvas.get()), |
| 824 | "Could not set canvas on visual brush for image brush."); |
| 825 | HRM(clampBrush->SetTileMode(SkToXpsTileMode[xy[0]][xy[1]]), |
| 826 | "Could not set tile mode on visual brush for image brush."); |
| 827 | HRM(clampBrush->SetOpacity(alpha / 255.0f), |
| 828 | "Could not set opacity on visual brush for image brush."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 829 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 830 | HRM(clampBrush->QueryInterface(xpsBrush), "QI failed."); |
| 831 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 832 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 833 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsMatrixToUse; |
| 834 | HR(this->createXpsTransform(localMatrix, &xpsMatrixToUse)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 835 | if (xpsMatrixToUse.get()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 836 | HRM((*xpsBrush)->SetTransformLocal(xpsMatrixToUse.get()), |
| 837 | "Could not set transform for image brush."); |
| 838 | } else { |
| 839 | //TODO(bungeman): perspective bitmaps in general. |
| 840 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 841 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 842 | return S_OK; |
| 843 | } |
| 844 | |
| 845 | HRESULT SkXPSDevice::createXpsGradientStop(const SkColor skColor, |
| 846 | const SkScalar offset, |
| 847 | IXpsOMGradientStop** xpsGradStop) { |
| 848 | XPS_COLOR gradStopXpsColor = xps_color(skColor); |
| 849 | HRM(this->fXpsFactory->CreateGradientStop(&gradStopXpsColor, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 850 | nullptr, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 851 | SkScalarToFLOAT(offset), |
| 852 | xpsGradStop), |
| 853 | "Could not create gradient stop."); |
| 854 | return S_OK; |
| 855 | } |
| 856 | |
| 857 | HRESULT SkXPSDevice::createXpsLinearGradient(SkShader::GradientInfo info, |
| 858 | const SkAlpha alpha, |
| 859 | const SkMatrix& localMatrix, |
| 860 | IXpsOMMatrixTransform* xpsMatrix, |
| 861 | IXpsOMBrush** xpsBrush) { |
| 862 | XPS_POINT startPoint; |
| 863 | XPS_POINT endPoint; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 864 | if (xpsMatrix) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 865 | startPoint = xps_point(info.fPoint[0]); |
| 866 | endPoint = xps_point(info.fPoint[1]); |
| 867 | } else { |
| 868 | transform_offsets(info.fColorOffsets, info.fColorCount, |
| 869 | info.fPoint[0], info.fPoint[1], |
| 870 | localMatrix); |
| 871 | startPoint = xps_point(info.fPoint[0], localMatrix); |
| 872 | endPoint = xps_point(info.fPoint[1], localMatrix); |
| 873 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 874 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 875 | SkTScopedComPtr<IXpsOMGradientStop> gradStop0; |
| 876 | HR(createXpsGradientStop(info.fColors[0], |
| 877 | info.fColorOffsets[0], |
| 878 | &gradStop0)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 879 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 880 | SkTScopedComPtr<IXpsOMGradientStop> gradStop1; |
| 881 | HR(createXpsGradientStop(info.fColors[1], |
| 882 | info.fColorOffsets[1], |
| 883 | &gradStop1)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 884 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 885 | SkTScopedComPtr<IXpsOMLinearGradientBrush> gradientBrush; |
| 886 | HRM(this->fXpsFactory->CreateLinearGradientBrush(gradStop0.get(), |
| 887 | gradStop1.get(), |
| 888 | &startPoint, |
| 889 | &endPoint, |
| 890 | &gradientBrush), |
| 891 | "Could not create linear gradient brush."); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 892 | if (xpsMatrix) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 893 | HRM(gradientBrush->SetTransformLocal(xpsMatrix), |
| 894 | "Could not set transform on linear gradient brush."); |
| 895 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 896 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 897 | SkTScopedComPtr<IXpsOMGradientStopCollection> gradStopCollection; |
| 898 | HRM(gradientBrush->GetGradientStops(&gradStopCollection), |
| 899 | "Could not get linear gradient stop collection."); |
| 900 | for (int i = 2; i < info.fColorCount; ++i) { |
| 901 | SkTScopedComPtr<IXpsOMGradientStop> gradStop; |
| 902 | HR(createXpsGradientStop(info.fColors[i], |
| 903 | info.fColorOffsets[i], |
| 904 | &gradStop)); |
| 905 | HRM(gradStopCollection->Append(gradStop.get()), |
| 906 | "Could not add linear gradient stop."); |
| 907 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 908 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 909 | HRM(gradientBrush->SetSpreadMethod(xps_spread_method(info.fTileMode)), |
| 910 | "Could not set spread method of linear gradient."); |
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 | HRM(gradientBrush->SetOpacity(alpha / 255.0f), |
| 913 | "Could not set opacity of linear gradient brush."); |
| 914 | HRM(gradientBrush->QueryInterface<IXpsOMBrush>(xpsBrush), "QI failed"); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 915 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 916 | return S_OK; |
| 917 | } |
| 918 | |
| 919 | HRESULT SkXPSDevice::createXpsRadialGradient(SkShader::GradientInfo info, |
| 920 | const SkAlpha alpha, |
| 921 | const SkMatrix& localMatrix, |
| 922 | IXpsOMMatrixTransform* xpsMatrix, |
| 923 | IXpsOMBrush** xpsBrush) { |
| 924 | SkTScopedComPtr<IXpsOMGradientStop> gradStop0; |
| 925 | HR(createXpsGradientStop(info.fColors[0], |
| 926 | info.fColorOffsets[0], |
| 927 | &gradStop0)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 928 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 929 | SkTScopedComPtr<IXpsOMGradientStop> gradStop1; |
| 930 | HR(createXpsGradientStop(info.fColors[1], |
| 931 | info.fColorOffsets[1], |
| 932 | &gradStop1)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 933 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 934 | //TODO: figure out how to fake better if not affine |
| 935 | XPS_POINT centerPoint; |
| 936 | XPS_POINT gradientOrigin; |
| 937 | XPS_SIZE radiiSizes; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 938 | if (xpsMatrix) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 939 | centerPoint = xps_point(info.fPoint[0]); |
| 940 | gradientOrigin = xps_point(info.fPoint[0]); |
| 941 | radiiSizes.width = SkScalarToFLOAT(info.fRadius[0]); |
| 942 | radiiSizes.height = SkScalarToFLOAT(info.fRadius[0]); |
| 943 | } else { |
| 944 | centerPoint = xps_point(info.fPoint[0], localMatrix); |
| 945 | gradientOrigin = xps_point(info.fPoint[0], localMatrix); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 946 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 947 | SkScalar radius = info.fRadius[0]; |
| 948 | SkVector 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 | vec[0].set(radius, 0); |
| 951 | vec[1].set(0, radius); |
| 952 | localMatrix.mapVectors(vec, 2); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 953 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 954 | SkScalar d0 = vec[0].length(); |
| 955 | SkScalar d1 = vec[1].length(); |
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 | radiiSizes.width = SkScalarToFLOAT(d0); |
| 958 | radiiSizes.height = SkScalarToFLOAT(d1); |
| 959 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 960 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 961 | SkTScopedComPtr<IXpsOMRadialGradientBrush> gradientBrush; |
| 962 | HRM(this->fXpsFactory->CreateRadialGradientBrush(gradStop0.get(), |
| 963 | gradStop1.get(), |
| 964 | ¢erPoint, |
| 965 | &gradientOrigin, |
| 966 | &radiiSizes, |
| 967 | &gradientBrush), |
| 968 | "Could not create radial gradient brush."); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 969 | if (xpsMatrix) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 970 | HRM(gradientBrush->SetTransformLocal(xpsMatrix), |
| 971 | "Could not set transform on radial gradient brush."); |
| 972 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 973 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 974 | SkTScopedComPtr<IXpsOMGradientStopCollection> gradStopCollection; |
| 975 | HRM(gradientBrush->GetGradientStops(&gradStopCollection), |
| 976 | "Could not get radial gradient stop collection."); |
| 977 | for (int i = 2; i < info.fColorCount; ++i) { |
| 978 | SkTScopedComPtr<IXpsOMGradientStop> gradStop; |
| 979 | HR(createXpsGradientStop(info.fColors[i], |
| 980 | info.fColorOffsets[i], |
| 981 | &gradStop)); |
| 982 | HRM(gradStopCollection->Append(gradStop.get()), |
| 983 | "Could not add radial gradient stop."); |
| 984 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 985 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 986 | HRM(gradientBrush->SetSpreadMethod(xps_spread_method(info.fTileMode)), |
| 987 | "Could not set spread method of radial gradient."); |
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 | HRM(gradientBrush->SetOpacity(alpha / 255.0f), |
| 990 | "Could not set opacity of radial gradient brush."); |
| 991 | HRM(gradientBrush->QueryInterface<IXpsOMBrush>(xpsBrush), "QI failed."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 992 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 993 | return S_OK; |
| 994 | } |
| 995 | |
| 996 | HRESULT SkXPSDevice::createXpsBrush(const SkPaint& skPaint, |
| 997 | IXpsOMBrush** brush, |
| 998 | const SkMatrix* parentTransform) { |
| 999 | const SkShader *shader = skPaint.getShader(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1000 | if (nullptr == shader) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1001 | HR(this->createXpsSolidColorBrush(skPaint.getColor(), 0xFF, brush)); |
| 1002 | return S_OK; |
| 1003 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1004 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1005 | //Gradient shaders. |
| 1006 | SkShader::GradientInfo info; |
| 1007 | info.fColorCount = 0; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1008 | info.fColors = nullptr; |
| 1009 | info.fColorOffsets = nullptr; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1010 | SkShader::GradientType gradientType = shader->asAGradient(&info); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1011 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1012 | if (SkShader::kNone_GradientType == gradientType) { |
| 1013 | //Nothing to see, move along. |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1014 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1015 | } else if (SkShader::kColor_GradientType == gradientType) { |
| 1016 | SkASSERT(1 == info.fColorCount); |
| 1017 | SkColor color; |
| 1018 | info.fColors = &color; |
bsalomon@google.com | b58a639 | 2013-03-21 20:29:05 +0000 | [diff] [blame] | 1019 | shader->asAGradient(&info); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1020 | SkAlpha alpha = skPaint.getAlpha(); |
| 1021 | HR(this->createXpsSolidColorBrush(color, alpha, brush)); |
| 1022 | return S_OK; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1023 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1024 | } else { |
| 1025 | if (info.fColorCount == 0) { |
| 1026 | const SkColor color = skPaint.getColor(); |
| 1027 | HR(this->createXpsSolidColorBrush(color, 0xFF, brush)); |
| 1028 | return S_OK; |
| 1029 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1030 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1031 | SkAutoTArray<SkColor> colors(info.fColorCount); |
| 1032 | SkAutoTArray<SkScalar> colorOffsets(info.fColorCount); |
| 1033 | info.fColors = colors.get(); |
| 1034 | info.fColorOffsets = colorOffsets.get(); |
| 1035 | shader->asAGradient(&info); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1036 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1037 | if (1 == info.fColorCount) { |
| 1038 | SkColor color = info.fColors[0]; |
| 1039 | SkAlpha alpha = skPaint.getAlpha(); |
| 1040 | HR(this->createXpsSolidColorBrush(color, alpha, brush)); |
| 1041 | return S_OK; |
| 1042 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1043 | |
bsalomon@google.com | f94b3a4 | 2012-10-31 18:09:01 +0000 | [diff] [blame] | 1044 | SkMatrix localMatrix = shader->getLocalMatrix(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1045 | if (parentTransform) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1046 | localMatrix.preConcat(*parentTransform); |
| 1047 | } |
| 1048 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsMatrixToUse; |
| 1049 | HR(this->createXpsTransform(localMatrix, &xpsMatrixToUse)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1050 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1051 | if (SkShader::kLinear_GradientType == gradientType) { |
| 1052 | HR(this->createXpsLinearGradient(info, |
| 1053 | skPaint.getAlpha(), |
| 1054 | localMatrix, |
| 1055 | xpsMatrixToUse.get(), |
| 1056 | brush)); |
| 1057 | return S_OK; |
| 1058 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1059 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1060 | if (SkShader::kRadial_GradientType == gradientType) { |
| 1061 | HR(this->createXpsRadialGradient(info, |
| 1062 | skPaint.getAlpha(), |
| 1063 | localMatrix, |
| 1064 | xpsMatrixToUse.get(), |
| 1065 | brush)); |
| 1066 | return S_OK; |
| 1067 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1068 | |
reed | 71a6cbf | 2015-05-04 08:32:51 -0700 | [diff] [blame] | 1069 | if (SkShader::kConical_GradientType == gradientType) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1070 | //simple if affine and one is 0, otherwise will have to fake |
| 1071 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1072 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1073 | if (SkShader::kSweep_GradientType == gradientType) { |
| 1074 | //have to fake |
| 1075 | } |
| 1076 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1077 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1078 | SkBitmap outTexture; |
| 1079 | SkMatrix outMatrix; |
| 1080 | SkShader::TileMode xy[2]; |
reed | f582282 | 2015-08-19 11:46:38 -0700 | [diff] [blame] | 1081 | if (shader->isABitmap(&outTexture, &outMatrix, xy)) { |
| 1082 | //TODO: outMatrix?? |
| 1083 | SkMatrix localMatrix = shader->getLocalMatrix(); |
| 1084 | if (parentTransform) { |
| 1085 | localMatrix.preConcat(*parentTransform); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1086 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1087 | |
reed | f582282 | 2015-08-19 11:46:38 -0700 | [diff] [blame] | 1088 | SkTScopedComPtr<IXpsOMTileBrush> tileBrush; |
| 1089 | HR(this->createXpsImageBrush(outTexture, |
| 1090 | localMatrix, |
| 1091 | xy, |
| 1092 | skPaint.getAlpha(), |
| 1093 | &tileBrush)); |
| 1094 | |
| 1095 | HRM(tileBrush->QueryInterface<IXpsOMBrush>(brush), "QI failed."); |
| 1096 | } else { |
| 1097 | HR(this->createXpsSolidColorBrush(skPaint.getColor(), 0xFF, brush)); |
| 1098 | } |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1099 | return S_OK; |
| 1100 | } |
| 1101 | |
| 1102 | static bool rect_must_be_pathed(const SkPaint& paint, const SkMatrix& matrix) { |
| 1103 | const bool zeroWidth = (0 == paint.getStrokeWidth()); |
| 1104 | const bool stroke = (SkPaint::kFill_Style != paint.getStyle()); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1105 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1106 | return paint.getPathEffect() || |
| 1107 | paint.getMaskFilter() || |
| 1108 | paint.getRasterizer() || |
| 1109 | (stroke && ( |
| 1110 | (matrix.hasPerspective() && !zeroWidth) || |
| 1111 | SkPaint::kMiter_Join != paint.getStrokeJoin() || |
| 1112 | (SkPaint::kMiter_Join == paint.getStrokeJoin() && |
| 1113 | paint.getStrokeMiter() < SK_ScalarSqrt2) |
| 1114 | )) |
| 1115 | ; |
| 1116 | } |
| 1117 | |
| 1118 | HRESULT SkXPSDevice::createXpsRect(const SkRect& rect, BOOL stroke, BOOL fill, |
| 1119 | IXpsOMGeometryFigure** xpsRect) { |
| 1120 | const SkPoint points[4] = { |
| 1121 | { rect.fLeft, rect.fTop }, |
| 1122 | { rect.fRight, rect.fTop }, |
| 1123 | { rect.fRight, rect.fBottom }, |
| 1124 | { rect.fLeft, rect.fBottom }, |
| 1125 | }; |
| 1126 | return this->createXpsQuad(points, stroke, fill, xpsRect); |
| 1127 | } |
| 1128 | HRESULT SkXPSDevice::createXpsQuad(const SkPoint (&points)[4], |
| 1129 | BOOL stroke, BOOL fill, |
| 1130 | IXpsOMGeometryFigure** xpsQuad) { |
| 1131 | // Define the start point. |
| 1132 | XPS_POINT startPoint = xps_point(points[0]); |
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 | // Create the figure. |
| 1135 | HRM(this->fXpsFactory->CreateGeometryFigure(&startPoint, xpsQuad), |
| 1136 | "Could not create quad geometry figure."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1137 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1138 | // Define the type of each segment. |
| 1139 | XPS_SEGMENT_TYPE segmentTypes[3] = { |
| 1140 | XPS_SEGMENT_TYPE_LINE, |
| 1141 | XPS_SEGMENT_TYPE_LINE, |
| 1142 | XPS_SEGMENT_TYPE_LINE, |
| 1143 | }; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1144 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1145 | // Define the x and y coordinates of each corner of the figure. |
| 1146 | FLOAT segmentData[6] = { |
| 1147 | SkScalarToFLOAT(points[1].fX), SkScalarToFLOAT(points[1].fY), |
| 1148 | SkScalarToFLOAT(points[2].fX), SkScalarToFLOAT(points[2].fY), |
| 1149 | SkScalarToFLOAT(points[3].fX), SkScalarToFLOAT(points[3].fY), |
| 1150 | }; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1151 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1152 | // Describe if the segments are stroked. |
| 1153 | BOOL segmentStrokes[3] = { |
| 1154 | stroke, stroke, stroke, |
| 1155 | }; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1156 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1157 | // Add the segment data to the figure. |
| 1158 | HRM((*xpsQuad)->SetSegments( |
| 1159 | 3, 6, |
| 1160 | segmentTypes , segmentData, segmentStrokes), |
| 1161 | "Could not add segment data to quad."); |
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 | // Set the closed and filled properties of the figure. |
| 1164 | HRM((*xpsQuad)->SetIsClosed(stroke), "Could not set quad close."); |
| 1165 | HRM((*xpsQuad)->SetIsFilled(fill), "Could not set quad fill."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1166 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1167 | return S_OK; |
| 1168 | } |
| 1169 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1170 | void SkXPSDevice::drawPoints(const SkDraw& d, SkCanvas::PointMode mode, |
| 1171 | size_t count, const SkPoint points[], |
| 1172 | const SkPaint& paint) { |
| 1173 | //This will call back into the device to do the drawing. |
| 1174 | d.drawPoints(mode, count, points, paint, true); |
| 1175 | } |
| 1176 | |
| 1177 | void SkXPSDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode, |
| 1178 | int vertexCount, const SkPoint verts[], |
| 1179 | const SkPoint texs[], const SkColor colors[], |
| 1180 | SkXfermode* xmode, const uint16_t indices[], |
| 1181 | int indexCount, const SkPaint& paint) { |
| 1182 | //TODO: override this for XPS |
| 1183 | SkDEBUGF(("XPS drawVertices not yet implemented.")); |
| 1184 | } |
| 1185 | |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1186 | void SkXPSDevice::drawPaint(const SkDraw& d, const SkPaint& origPaint) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1187 | const SkRect r = SkRect::MakeSize(this->fCurrentCanvasSize); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1188 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1189 | //If trying to paint with a stroke, ignore that and fill. |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1190 | SkPaint* fillPaint = const_cast<SkPaint*>(&origPaint); |
| 1191 | SkTCopyOnFirstWrite<SkPaint> paint(origPaint); |
| 1192 | if (paint->getStyle() != SkPaint::kFill_Style) { |
| 1193 | paint.writable()->setStyle(SkPaint::kFill_Style); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1194 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1195 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1196 | this->internalDrawRect(d, r, false, *fillPaint); |
| 1197 | } |
| 1198 | |
| 1199 | void SkXPSDevice::drawRect(const SkDraw& d, |
| 1200 | const SkRect& r, |
| 1201 | const SkPaint& paint) { |
| 1202 | this->internalDrawRect(d, r, true, paint); |
| 1203 | } |
| 1204 | |
scroggo@google.com | cac8d01 | 2013-11-12 17:10:02 +0000 | [diff] [blame] | 1205 | void SkXPSDevice::drawRRect(const SkDraw& d, |
| 1206 | const SkRRect& rr, |
| 1207 | const SkPaint& paint) { |
| 1208 | SkPath path; |
| 1209 | path.addRRect(rr); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1210 | this->drawPath(d, path, paint, nullptr, true); |
scroggo@google.com | cac8d01 | 2013-11-12 17:10:02 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1213 | void SkXPSDevice::internalDrawRect(const SkDraw& d, |
| 1214 | const SkRect& r, |
| 1215 | bool transformRect, |
| 1216 | const SkPaint& paint) { |
| 1217 | //Exit early if there is nothing to draw. |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 1218 | if (d.fRC->isEmpty() || |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1219 | (paint.getAlpha() == 0 && paint.getXfermode() == nullptr)) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1220 | return; |
| 1221 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1222 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1223 | //Path the rect if we can't optimize it. |
| 1224 | if (rect_must_be_pathed(paint, *d.fMatrix)) { |
| 1225 | SkPath tmp; |
| 1226 | tmp.addRect(r); |
| 1227 | tmp.setFillType(SkPath::kWinding_FillType); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1228 | this->drawPath(d, tmp, paint, nullptr, true); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1229 | return; |
| 1230 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1231 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1232 | //Create the shaded path. |
| 1233 | SkTScopedComPtr<IXpsOMPath> shadedPath; |
| 1234 | HRVM(this->fXpsFactory->CreatePath(&shadedPath), |
| 1235 | "Could not create shaded path for rect."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1236 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1237 | //Create the shaded geometry. |
| 1238 | SkTScopedComPtr<IXpsOMGeometry> shadedGeometry; |
| 1239 | HRVM(this->fXpsFactory->CreateGeometry(&shadedGeometry), |
| 1240 | "Could not create 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 | //Add the geometry to the shaded path. |
| 1243 | HRVM(shadedPath->SetGeometryLocal(shadedGeometry.get()), |
| 1244 | "Could not set shaded geometry for rect."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1245 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1246 | //Set the brushes. |
| 1247 | BOOL fill = FALSE; |
| 1248 | BOOL stroke = FALSE; |
| 1249 | HRV(this->shadePath(shadedPath.get(), paint, *d.fMatrix, &fill, &stroke)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1250 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1251 | bool xpsTransformsPath = true; |
| 1252 | //Transform the geometry. |
| 1253 | if (transformRect && xpsTransformsPath) { |
| 1254 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform; |
| 1255 | HRV(this->createXpsTransform(*d.fMatrix, &xpsTransform)); |
| 1256 | if (xpsTransform.get()) { |
| 1257 | HRVM(shadedGeometry->SetTransformLocal(xpsTransform.get()), |
| 1258 | "Could not set transform for rect."); |
| 1259 | } else { |
| 1260 | xpsTransformsPath = false; |
| 1261 | } |
| 1262 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1263 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1264 | //Create the figure. |
| 1265 | SkTScopedComPtr<IXpsOMGeometryFigure> rectFigure; |
| 1266 | { |
| 1267 | SkPoint points[4] = { |
| 1268 | { r.fLeft, r.fTop }, |
| 1269 | { r.fLeft, r.fBottom }, |
| 1270 | { r.fRight, r.fBottom }, |
| 1271 | { r.fRight, r.fTop }, |
| 1272 | }; |
| 1273 | if (!xpsTransformsPath && transformRect) { |
| 1274 | d.fMatrix->mapPoints(points, SK_ARRAY_COUNT(points)); |
| 1275 | } |
| 1276 | HRV(this->createXpsQuad(points, stroke, fill, &rectFigure)); |
| 1277 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1278 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1279 | //Get the figures of the shaded geometry. |
| 1280 | SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures; |
| 1281 | HRVM(shadedGeometry->GetFigures(&shadedFigures), |
| 1282 | "Could not get shaded figures 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 | //Add the figure to the shaded geometry figures. |
| 1285 | HRVM(shadedFigures->Append(rectFigure.get()), |
| 1286 | "Could not add shaded figure for rect."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1287 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1288 | HRV(this->clip(shadedPath.get(), d)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1289 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1290 | //Add the shaded path to the current visuals. |
| 1291 | SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals; |
| 1292 | HRVM(this->fCurrentXpsCanvas->GetVisuals(¤tVisuals), |
| 1293 | "Could not get current visuals for rect."); |
| 1294 | HRVM(currentVisuals->Append(shadedPath.get()), |
| 1295 | "Could not add rect to current visuals."); |
| 1296 | } |
| 1297 | |
| 1298 | static HRESULT close_figure(const SkTDArray<XPS_SEGMENT_TYPE>& segmentTypes, |
| 1299 | const SkTDArray<BOOL>& segmentStrokes, |
| 1300 | const SkTDArray<FLOAT>& segmentData, |
| 1301 | BOOL stroke, BOOL fill, |
| 1302 | IXpsOMGeometryFigure* figure, |
| 1303 | IXpsOMGeometryFigureCollection* figures) { |
| 1304 | // Add the segment data to the figure. |
| 1305 | HRM(figure->SetSegments(segmentTypes.count(), segmentData.count(), |
| 1306 | segmentTypes.begin() , segmentData.begin(), |
| 1307 | segmentStrokes.begin()), |
| 1308 | "Could not set path segments."); |
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 | // Set the closed and filled properties of the figure. |
| 1311 | HRM(figure->SetIsClosed(stroke), "Could not set path closed."); |
| 1312 | HRM(figure->SetIsFilled(fill), "Could not set path fill."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1313 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1314 | // Add the figure created above to this geometry. |
| 1315 | HRM(figures->Append(figure), "Could not add path to geometry."); |
| 1316 | return S_OK; |
| 1317 | } |
| 1318 | |
| 1319 | HRESULT SkXPSDevice::addXpsPathGeometry( |
| 1320 | IXpsOMGeometryFigureCollection* xpsFigures, |
| 1321 | BOOL stroke, BOOL fill, const SkPath& path) { |
| 1322 | SkTDArray<XPS_SEGMENT_TYPE> segmentTypes; |
| 1323 | SkTDArray<BOOL> segmentStrokes; |
| 1324 | SkTDArray<FLOAT> segmentData; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1325 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1326 | SkTScopedComPtr<IXpsOMGeometryFigure> xpsFigure; |
| 1327 | SkPath::Iter iter(path, true); |
| 1328 | SkPoint points[4]; |
| 1329 | SkPath::Verb verb; |
| 1330 | while ((verb = iter.next(points)) != SkPath::kDone_Verb) { |
| 1331 | switch (verb) { |
| 1332 | case SkPath::kMove_Verb: { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1333 | if (xpsFigure.get()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1334 | HR(close_figure(segmentTypes, segmentStrokes, segmentData, |
| 1335 | stroke, fill, |
| 1336 | xpsFigure.get() , xpsFigures)); |
| 1337 | xpsFigure.reset(); |
| 1338 | segmentTypes.rewind(); |
| 1339 | segmentStrokes.rewind(); |
| 1340 | segmentData.rewind(); |
| 1341 | } |
| 1342 | // Define the start point. |
| 1343 | XPS_POINT startPoint = xps_point(points[0]); |
| 1344 | // Create the figure. |
| 1345 | HRM(this->fXpsFactory->CreateGeometryFigure(&startPoint, |
| 1346 | &xpsFigure), |
| 1347 | "Could not create path geometry figure."); |
| 1348 | break; |
| 1349 | } |
| 1350 | case SkPath::kLine_Verb: |
| 1351 | if (iter.isCloseLine()) break; //ignore the line, auto-closed |
| 1352 | segmentTypes.push(XPS_SEGMENT_TYPE_LINE); |
| 1353 | segmentStrokes.push(stroke); |
| 1354 | segmentData.push(SkScalarToFLOAT(points[1].fX)); |
| 1355 | segmentData.push(SkScalarToFLOAT(points[1].fY)); |
| 1356 | break; |
| 1357 | case SkPath::kQuad_Verb: |
| 1358 | segmentTypes.push(XPS_SEGMENT_TYPE_QUADRATIC_BEZIER); |
| 1359 | segmentStrokes.push(stroke); |
| 1360 | segmentData.push(SkScalarToFLOAT(points[1].fX)); |
| 1361 | segmentData.push(SkScalarToFLOAT(points[1].fY)); |
| 1362 | segmentData.push(SkScalarToFLOAT(points[2].fX)); |
| 1363 | segmentData.push(SkScalarToFLOAT(points[2].fY)); |
| 1364 | break; |
| 1365 | case SkPath::kCubic_Verb: |
| 1366 | segmentTypes.push(XPS_SEGMENT_TYPE_BEZIER); |
| 1367 | segmentStrokes.push(stroke); |
| 1368 | segmentData.push(SkScalarToFLOAT(points[1].fX)); |
| 1369 | segmentData.push(SkScalarToFLOAT(points[1].fY)); |
| 1370 | segmentData.push(SkScalarToFLOAT(points[2].fX)); |
| 1371 | segmentData.push(SkScalarToFLOAT(points[2].fY)); |
| 1372 | segmentData.push(SkScalarToFLOAT(points[3].fX)); |
| 1373 | segmentData.push(SkScalarToFLOAT(points[3].fY)); |
| 1374 | break; |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 1375 | case SkPath::kConic_Verb: { |
| 1376 | const SkScalar tol = SK_Scalar1 / 4; |
| 1377 | SkAutoConicToQuads converter; |
| 1378 | const SkPoint* quads = |
| 1379 | converter.computeQuads(points, iter.conicWeight(), tol); |
| 1380 | for (int i = 0; i < converter.countQuads(); ++i) { |
| 1381 | segmentTypes.push(XPS_SEGMENT_TYPE_QUADRATIC_BEZIER); |
| 1382 | segmentStrokes.push(stroke); |
| 1383 | segmentData.push(SkScalarToFLOAT(quads[2 * i + 1].fX)); |
| 1384 | segmentData.push(SkScalarToFLOAT(quads[2 * i + 1].fY)); |
| 1385 | segmentData.push(SkScalarToFLOAT(quads[2 * i + 2].fX)); |
| 1386 | segmentData.push(SkScalarToFLOAT(quads[2 * i + 2].fY)); |
| 1387 | } |
| 1388 | break; |
| 1389 | } |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1390 | case SkPath::kClose_Verb: |
| 1391 | // we ignore these, and just get the whole segment from |
| 1392 | // the corresponding line/quad/cubic verbs |
| 1393 | break; |
| 1394 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 1395 | SkDEBUGFAIL("unexpected verb"); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1396 | break; |
| 1397 | } |
| 1398 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1399 | if (xpsFigure.get()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1400 | HR(close_figure(segmentTypes, segmentStrokes, segmentData, |
| 1401 | stroke, fill, |
| 1402 | xpsFigure.get(), xpsFigures)); |
| 1403 | } |
| 1404 | return S_OK; |
| 1405 | } |
| 1406 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1407 | void SkXPSDevice::convertToPpm(const SkMaskFilter* filter, |
| 1408 | SkMatrix* matrix, |
| 1409 | SkVector* ppuScale, |
| 1410 | const SkIRect& clip, SkIRect* clipIRect) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1411 | //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] | 1412 | ppuScale->set(fCurrentPixelsPerMeter.fX / fCurrentUnitsPerMeter.fX, |
| 1413 | fCurrentPixelsPerMeter.fY / fCurrentUnitsPerMeter.fY); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1414 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1415 | matrix->postScale(ppuScale->fX, ppuScale->fY); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1416 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1417 | const SkIRect& irect = clip; |
| 1418 | SkRect clipRect = SkRect::MakeLTRB( |
| 1419 | SkScalarMul(SkIntToScalar(irect.fLeft), ppuScale->fX), |
| 1420 | SkScalarMul(SkIntToScalar(irect.fTop), ppuScale->fY), |
| 1421 | SkScalarMul(SkIntToScalar(irect.fRight), ppuScale->fX), |
| 1422 | SkScalarMul(SkIntToScalar(irect.fBottom), ppuScale->fY)); |
| 1423 | clipRect.roundOut(clipIRect); |
| 1424 | } |
| 1425 | |
| 1426 | HRESULT SkXPSDevice::applyMask(const SkDraw& d, |
| 1427 | const SkMask& mask, |
| 1428 | const SkVector& ppuScale, |
| 1429 | IXpsOMPath* shadedPath) { |
| 1430 | //Get the geometry object. |
| 1431 | SkTScopedComPtr<IXpsOMGeometry> shadedGeometry; |
| 1432 | HRM(shadedPath->GetGeometry(&shadedGeometry), |
| 1433 | "Could not get mask shaded geometry."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1434 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1435 | //Get the figures from the geometry. |
| 1436 | SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures; |
| 1437 | HRM(shadedGeometry->GetFigures(&shadedFigures), |
| 1438 | "Could not get mask shaded figures."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1439 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1440 | SkMatrix m; |
| 1441 | m.reset(); |
| 1442 | m.setTranslate(SkIntToScalar(mask.fBounds.fLeft), |
| 1443 | SkIntToScalar(mask.fBounds.fTop)); |
| 1444 | m.postScale(SkScalarInvert(ppuScale.fX), SkScalarInvert(ppuScale.fY)); |
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 | SkShader::TileMode xy[2]; |
| 1447 | xy[0] = (SkShader::TileMode)3; |
| 1448 | xy[1] = (SkShader::TileMode)3; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1449 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1450 | SkBitmap bm; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 1451 | bm.installMaskPixels(mask); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1452 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1453 | SkTScopedComPtr<IXpsOMTileBrush> maskBrush; |
| 1454 | HR(this->createXpsImageBrush(bm, m, xy, 0xFF, &maskBrush)); |
| 1455 | HRM(shadedPath->SetOpacityMaskBrushLocal(maskBrush.get()), |
| 1456 | "Could not set mask."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1457 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1458 | const SkRect universeRect = SkRect::MakeLTRB(0, 0, |
| 1459 | this->fCurrentCanvasSize.fWidth, this->fCurrentCanvasSize.fHeight); |
| 1460 | SkTScopedComPtr<IXpsOMGeometryFigure> shadedFigure; |
| 1461 | HRM(this->createXpsRect(universeRect, FALSE, TRUE, &shadedFigure), |
| 1462 | "Could not create mask shaded figure."); |
| 1463 | HRM(shadedFigures->Append(shadedFigure.get()), |
| 1464 | "Could not add mask shaded figure."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1465 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1466 | HR(this->clip(shadedPath, d)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1467 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1468 | //Add the path to the active visual collection. |
| 1469 | SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals; |
| 1470 | HRM(this->fCurrentXpsCanvas->GetVisuals(¤tVisuals), |
| 1471 | "Could not get mask current visuals."); |
| 1472 | HRM(currentVisuals->Append(shadedPath), |
| 1473 | "Could not add masked shaded path to current visuals."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1474 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1475 | return S_OK; |
| 1476 | } |
| 1477 | |
| 1478 | HRESULT SkXPSDevice::shadePath(IXpsOMPath* shadedPath, |
| 1479 | const SkPaint& shaderPaint, |
| 1480 | const SkMatrix& matrix, |
| 1481 | BOOL* fill, BOOL* stroke) { |
| 1482 | *fill = FALSE; |
| 1483 | *stroke = FALSE; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1484 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1485 | const SkPaint::Style style = shaderPaint.getStyle(); |
| 1486 | const bool hasFill = SkPaint::kFill_Style == style |
| 1487 | || SkPaint::kStrokeAndFill_Style == style; |
| 1488 | const bool hasStroke = SkPaint::kStroke_Style == style |
| 1489 | || SkPaint::kStrokeAndFill_Style == style; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1490 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1491 | //TODO(bungeman): use dictionaries and lookups. |
| 1492 | if (hasFill) { |
| 1493 | *fill = TRUE; |
| 1494 | SkTScopedComPtr<IXpsOMBrush> fillBrush; |
| 1495 | HR(this->createXpsBrush(shaderPaint, &fillBrush, &matrix)); |
| 1496 | HRM(shadedPath->SetFillBrushLocal(fillBrush.get()), |
| 1497 | "Could not set fill for shaded path."); |
| 1498 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1499 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1500 | if (hasStroke) { |
| 1501 | *stroke = TRUE; |
| 1502 | SkTScopedComPtr<IXpsOMBrush> strokeBrush; |
| 1503 | HR(this->createXpsBrush(shaderPaint, &strokeBrush, &matrix)); |
| 1504 | HRM(shadedPath->SetStrokeBrushLocal(strokeBrush.get()), |
| 1505 | "Could not set stroke brush for shaded path."); |
| 1506 | HRM(shadedPath->SetStrokeThickness( |
| 1507 | SkScalarToFLOAT(shaderPaint.getStrokeWidth())), |
| 1508 | "Could not set shaded path stroke thickness."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1509 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1510 | if (0 == shaderPaint.getStrokeWidth()) { |
| 1511 | //XPS hair width is a hack. (XPS Spec 11.6.12). |
| 1512 | SkTScopedComPtr<IXpsOMDashCollection> dashes; |
| 1513 | HRM(shadedPath->GetStrokeDashes(&dashes), |
| 1514 | "Could not set dashes for shaded path."); |
| 1515 | XPS_DASH dash; |
| 1516 | dash.length = 1.0; |
| 1517 | dash.gap = 0.0; |
| 1518 | HRM(dashes->Append(&dash), "Could not add dashes to shaded path."); |
| 1519 | HRM(shadedPath->SetStrokeDashOffset(-2.0), |
| 1520 | "Could not set dash offset for shaded path."); |
| 1521 | } |
| 1522 | } |
| 1523 | return S_OK; |
| 1524 | } |
| 1525 | |
| 1526 | void SkXPSDevice::drawPath(const SkDraw& d, |
| 1527 | const SkPath& platonicPath, |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1528 | const SkPaint& origPaint, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1529 | const SkMatrix* prePathMatrix, |
| 1530 | bool pathIsMutable) { |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1531 | SkTCopyOnFirstWrite<SkPaint> paint(origPaint); |
| 1532 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1533 | // nothing to draw |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 1534 | if (d.fRC->isEmpty() || |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1535 | (paint->getAlpha() == 0 && paint->getXfermode() == nullptr)) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1536 | return; |
| 1537 | } |
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 | SkPath modifiedPath; |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1540 | const bool paintHasPathEffect = paint->getPathEffect() |
| 1541 | || paint->getStyle() != SkPaint::kFill_Style; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1542 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1543 | //Apply pre-path matrix [Platonic-path -> Skeletal-path]. |
| 1544 | SkMatrix matrix = *d.fMatrix; |
| 1545 | SkPath* skeletalPath = const_cast<SkPath*>(&platonicPath); |
| 1546 | if (prePathMatrix) { |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1547 | if (paintHasPathEffect || paint->getRasterizer()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1548 | if (!pathIsMutable) { |
| 1549 | skeletalPath = &modifiedPath; |
| 1550 | pathIsMutable = true; |
| 1551 | } |
| 1552 | platonicPath.transform(*prePathMatrix, skeletalPath); |
| 1553 | } else { |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1554 | matrix.preConcat(*prePathMatrix); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1555 | } |
| 1556 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1557 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1558 | //Apply path effect [Skeletal-path -> Fillable-path]. |
| 1559 | SkPath* fillablePath = skeletalPath; |
| 1560 | if (paintHasPathEffect) { |
| 1561 | if (!pathIsMutable) { |
| 1562 | fillablePath = &modifiedPath; |
| 1563 | pathIsMutable = true; |
| 1564 | } |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1565 | bool fill = paint->getFillPath(*skeletalPath, fillablePath); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1566 | |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1567 | SkPaint* writablePaint = paint.writable(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1568 | writablePaint->setPathEffect(nullptr); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1569 | if (fill) { |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1570 | writablePaint->setStyle(SkPaint::kFill_Style); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1571 | } else { |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1572 | writablePaint->setStyle(SkPaint::kStroke_Style); |
| 1573 | writablePaint->setStrokeWidth(0); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1574 | } |
| 1575 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1576 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1577 | //Create the shaded path. This will be the path which is painted. |
| 1578 | SkTScopedComPtr<IXpsOMPath> shadedPath; |
| 1579 | HRVM(this->fXpsFactory->CreatePath(&shadedPath), |
| 1580 | "Could not create shaded path for path."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1581 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1582 | //Create the geometry for the shaded path. |
| 1583 | SkTScopedComPtr<IXpsOMGeometry> shadedGeometry; |
| 1584 | HRVM(this->fXpsFactory->CreateGeometry(&shadedGeometry), |
| 1585 | "Could not create shaded geometry for path."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1586 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1587 | //Add the geometry to the shaded path. |
| 1588 | HRVM(shadedPath->SetGeometryLocal(shadedGeometry.get()), |
| 1589 | "Could not add the shaded geometry to shaded path."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1590 | |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1591 | SkRasterizer* rasterizer = paint->getRasterizer(); |
| 1592 | SkMaskFilter* filter = paint->getMaskFilter(); |
bungeman@google.com | d998cbd | 2012-04-05 18:57:53 +0000 | [diff] [blame] | 1593 | |
| 1594 | //Determine if we will draw or shade and mask. |
| 1595 | if (rasterizer || filter) { |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1596 | if (paint->getStyle() != SkPaint::kFill_Style) { |
| 1597 | paint.writable()->setStyle(SkPaint::kFill_Style); |
bungeman@google.com | d998cbd | 2012-04-05 18:57:53 +0000 | [diff] [blame] | 1598 | } |
| 1599 | } |
| 1600 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1601 | //Set the brushes. |
| 1602 | BOOL fill; |
| 1603 | BOOL stroke; |
| 1604 | HRV(this->shadePath(shadedPath.get(), |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1605 | *paint, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1606 | *d.fMatrix, |
| 1607 | &fill, |
| 1608 | &stroke)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1609 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1610 | //Rasterizer |
bungeman@google.com | d998cbd | 2012-04-05 18:57:53 +0000 | [diff] [blame] | 1611 | if (rasterizer) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1612 | SkIRect clipIRect; |
| 1613 | SkVector ppuScale; |
| 1614 | this->convertToPpm(filter, |
| 1615 | &matrix, |
| 1616 | &ppuScale, |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 1617 | d.fRC->getBounds(), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1618 | &clipIRect); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1619 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1620 | SkMask* mask = nullptr; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1621 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1622 | //[Fillable-path -> Mask] |
| 1623 | SkMask rasteredMask; |
bungeman@google.com | d998cbd | 2012-04-05 18:57:53 +0000 | [diff] [blame] | 1624 | if (rasterizer->rasterize( |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1625 | *fillablePath, |
| 1626 | matrix, |
| 1627 | &clipIRect, |
| 1628 | filter, //just to compute how much to draw. |
| 1629 | &rasteredMask, |
| 1630 | SkMask::kComputeBoundsAndRenderImage_CreateMode)) { |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1631 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1632 | SkAutoMaskFreeImage rasteredAmi(rasteredMask.fImage); |
| 1633 | mask = &rasteredMask; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1634 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1635 | //[Mask -> Mask] |
| 1636 | SkMask filteredMask; |
robertphillips | e80eb92 | 2015-12-17 11:33:12 -0800 | [diff] [blame] | 1637 | if (filter && filter->filterMask(&filteredMask, *mask, *d.fMatrix, nullptr)) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1638 | mask = &filteredMask; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1639 | } |
| 1640 | SkAutoMaskFreeImage filteredAmi(filteredMask.fImage); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1641 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1642 | //Draw mask. |
| 1643 | HRV(this->applyMask(d, *mask, ppuScale, shadedPath.get())); |
| 1644 | } |
| 1645 | return; |
| 1646 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1647 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1648 | //Mask filter |
| 1649 | if (filter) { |
| 1650 | SkIRect clipIRect; |
| 1651 | SkVector ppuScale; |
| 1652 | this->convertToPpm(filter, |
| 1653 | &matrix, |
| 1654 | &ppuScale, |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 1655 | d.fRC->getBounds(), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1656 | &clipIRect); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1657 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1658 | //[Fillable-path -> Pixel-path] |
| 1659 | SkPath* pixelPath = pathIsMutable ? fillablePath : &modifiedPath; |
| 1660 | fillablePath->transform(matrix, pixelPath); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1661 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1662 | SkMask* mask = nullptr; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1663 | |
bsalomon | 055e192 | 2016-05-06 07:22:58 -0700 | [diff] [blame] | 1664 | SkASSERT(SkPaint::kFill_Style == paint->getStyle() || |
| 1665 | (SkPaint::kStroke_Style == paint->getStyle() && 0 == paint->getStrokeWidth())); |
| 1666 | SkStrokeRec::InitStyle style = (SkPaint::kFill_Style == paint->getStyle()) |
| 1667 | ? SkStrokeRec::kFill_InitStyle |
| 1668 | : SkStrokeRec::kHairline_InitStyle; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1669 | //[Pixel-path -> Mask] |
| 1670 | SkMask rasteredMask; |
| 1671 | if (SkDraw::DrawToMask( |
| 1672 | *pixelPath, |
| 1673 | &clipIRect, |
| 1674 | filter, //just to compute how much to draw. |
| 1675 | &matrix, |
| 1676 | &rasteredMask, |
junov@chromium.org | 2ac4ef5 | 2012-04-04 15:16:51 +0000 | [diff] [blame] | 1677 | SkMask::kComputeBoundsAndRenderImage_CreateMode, |
bsalomon | 055e192 | 2016-05-06 07:22:58 -0700 | [diff] [blame] | 1678 | style)) { |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1679 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1680 | SkAutoMaskFreeImage rasteredAmi(rasteredMask.fImage); |
| 1681 | mask = &rasteredMask; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1682 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1683 | //[Mask -> Mask] |
| 1684 | SkMask filteredMask; |
robertphillips | e80eb92 | 2015-12-17 11:33:12 -0800 | [diff] [blame] | 1685 | if (filter->filterMask(&filteredMask, rasteredMask, matrix, nullptr)) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1686 | mask = &filteredMask; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1687 | } |
| 1688 | SkAutoMaskFreeImage filteredAmi(filteredMask.fImage); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1689 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1690 | //Draw mask. |
| 1691 | HRV(this->applyMask(d, *mask, ppuScale, shadedPath.get())); |
| 1692 | } |
| 1693 | return; |
| 1694 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1695 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1696 | //Get the figures from the shaded geometry. |
| 1697 | SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures; |
| 1698 | HRVM(shadedGeometry->GetFigures(&shadedFigures), |
| 1699 | "Could not get shaded figures for shaded path."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1700 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1701 | bool xpsTransformsPath = true; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1702 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1703 | //Set the fill rule. |
bungeman | 76db31a | 2014-08-25 07:31:53 -0700 | [diff] [blame] | 1704 | SkPath* xpsCompatiblePath = fillablePath; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1705 | XPS_FILL_RULE xpsFillRule; |
bungeman | 76db31a | 2014-08-25 07:31:53 -0700 | [diff] [blame] | 1706 | switch (fillablePath->getFillType()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1707 | case SkPath::kWinding_FillType: |
| 1708 | xpsFillRule = XPS_FILL_RULE_NONZERO; |
| 1709 | break; |
| 1710 | case SkPath::kEvenOdd_FillType: |
| 1711 | xpsFillRule = XPS_FILL_RULE_EVENODD; |
| 1712 | break; |
| 1713 | case SkPath::kInverseWinding_FillType: { |
bungeman | 76db31a | 2014-08-25 07:31:53 -0700 | [diff] [blame] | 1714 | //[Fillable-path (inverse winding) -> XPS-path (inverse even odd)] |
| 1715 | if (!pathIsMutable) { |
| 1716 | xpsCompatiblePath = &modifiedPath; |
| 1717 | pathIsMutable = true; |
| 1718 | } |
| 1719 | if (!Simplify(*fillablePath, xpsCompatiblePath)) { |
| 1720 | SkDEBUGF(("Could not simplify inverse winding path.")); |
| 1721 | return; |
| 1722 | } |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1723 | } |
bungeman | 76db31a | 2014-08-25 07:31:53 -0700 | [diff] [blame] | 1724 | // The xpsCompatiblePath is noW inverse even odd, so fall through. |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1725 | case SkPath::kInverseEvenOdd_FillType: { |
| 1726 | const SkRect universe = SkRect::MakeLTRB( |
| 1727 | 0, 0, |
| 1728 | this->fCurrentCanvasSize.fWidth, |
| 1729 | this->fCurrentCanvasSize.fHeight); |
| 1730 | SkTScopedComPtr<IXpsOMGeometryFigure> addOneFigure; |
| 1731 | HRV(this->createXpsRect(universe, FALSE, TRUE, &addOneFigure)); |
| 1732 | HRVM(shadedFigures->Append(addOneFigure.get()), |
| 1733 | "Could not add even-odd flip figure to shaded path."); |
| 1734 | xpsTransformsPath = false; |
| 1735 | xpsFillRule = XPS_FILL_RULE_EVENODD; |
| 1736 | break; |
| 1737 | } |
| 1738 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 1739 | SkDEBUGFAIL("Unknown SkPath::FillType."); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1740 | } |
| 1741 | HRVM(shadedGeometry->SetFillRule(xpsFillRule), |
| 1742 | "Could not set fill rule for shaded path."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1743 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1744 | //Create the XPS transform, if possible. |
| 1745 | if (xpsTransformsPath) { |
| 1746 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform; |
| 1747 | HRV(this->createXpsTransform(matrix, &xpsTransform)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1748 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1749 | if (xpsTransform.get()) { |
| 1750 | HRVM(shadedGeometry->SetTransformLocal(xpsTransform.get()), |
| 1751 | "Could not set transform on shaded path."); |
| 1752 | } else { |
| 1753 | xpsTransformsPath = false; |
| 1754 | } |
| 1755 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1756 | |
bungeman | 76db31a | 2014-08-25 07:31:53 -0700 | [diff] [blame] | 1757 | SkPath* devicePath = xpsCompatiblePath; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1758 | if (!xpsTransformsPath) { |
| 1759 | //[Fillable-path -> Device-path] |
bungeman | 76db31a | 2014-08-25 07:31:53 -0700 | [diff] [blame] | 1760 | devicePath = pathIsMutable ? xpsCompatiblePath : &modifiedPath; |
| 1761 | xpsCompatiblePath->transform(matrix, devicePath); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1762 | } |
| 1763 | HRV(this->addXpsPathGeometry(shadedFigures.get(), |
| 1764 | stroke, fill, *devicePath)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1765 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1766 | HRV(this->clip(shadedPath.get(), d)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1767 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1768 | //Add the path to the active visual collection. |
| 1769 | SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals; |
| 1770 | HRVM(this->fCurrentXpsCanvas->GetVisuals(¤tVisuals), |
| 1771 | "Could not get current visuals for shaded path."); |
| 1772 | HRVM(currentVisuals->Append(shadedPath.get()), |
| 1773 | "Could not add shaded path to current visuals."); |
| 1774 | } |
| 1775 | |
| 1776 | HRESULT SkXPSDevice::clip(IXpsOMVisual* xpsVisual, const SkDraw& d) { |
| 1777 | SkPath clipPath; |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 1778 | if (d.fRC->isBW()) { |
| 1779 | SkAssertResult(d.fRC->bwRgn().getBoundaryPath(&clipPath)); |
| 1780 | } else { |
| 1781 | // Don't have a way to turn a AAClip into a path, so we just use the bounds. |
| 1782 | // TODO: consider using fClipStack instead? |
| 1783 | clipPath.addRect(SkRect::Make(d.fRC->getBounds())); |
| 1784 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1785 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1786 | return this->clipToPath(xpsVisual, clipPath, XPS_FILL_RULE_EVENODD); |
| 1787 | } |
| 1788 | HRESULT SkXPSDevice::clipToPath(IXpsOMVisual* xpsVisual, |
| 1789 | const SkPath& clipPath, |
| 1790 | XPS_FILL_RULE fillRule) { |
| 1791 | //Create the geometry. |
| 1792 | SkTScopedComPtr<IXpsOMGeometry> clipGeometry; |
| 1793 | HRM(this->fXpsFactory->CreateGeometry(&clipGeometry), |
| 1794 | "Could not create clip geometry."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1795 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1796 | //Get the figure collection of the geometry. |
| 1797 | SkTScopedComPtr<IXpsOMGeometryFigureCollection> clipFigures; |
| 1798 | HRM(clipGeometry->GetFigures(&clipFigures), |
| 1799 | "Could not get the clip figures."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1800 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1801 | //Create the figures into the geometry. |
| 1802 | HR(this->addXpsPathGeometry( |
| 1803 | clipFigures.get(), |
| 1804 | FALSE, TRUE, clipPath)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1805 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1806 | HRM(clipGeometry->SetFillRule(fillRule), |
| 1807 | "Could not set fill rule."); |
| 1808 | HRM(xpsVisual->SetClipGeometryLocal(clipGeometry.get()), |
| 1809 | "Could not set clip geometry."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1810 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1811 | return S_OK; |
| 1812 | } |
| 1813 | |
| 1814 | void SkXPSDevice::drawBitmap(const SkDraw& d, const SkBitmap& bitmap, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1815 | const SkMatrix& matrix, const SkPaint& paint) { |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 1816 | if (d.fRC->isEmpty()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1817 | return; |
| 1818 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1819 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1820 | SkIRect srcRect; |
robertphillips@google.com | 9bf380c | 2013-07-25 12:10:42 +0000 | [diff] [blame] | 1821 | srcRect.set(0, 0, bitmap.width(), bitmap.height()); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1822 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1823 | //Create the new shaded path. |
| 1824 | SkTScopedComPtr<IXpsOMPath> shadedPath; |
| 1825 | HRVM(this->fXpsFactory->CreatePath(&shadedPath), |
| 1826 | "Could not create path for bitmap."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1827 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1828 | //Create the shaded geometry. |
| 1829 | SkTScopedComPtr<IXpsOMGeometry> shadedGeometry; |
| 1830 | HRVM(this->fXpsFactory->CreateGeometry(&shadedGeometry), |
| 1831 | "Could not create 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 | //Add the shaded geometry to the shaded path. |
| 1834 | HRVM(shadedPath->SetGeometryLocal(shadedGeometry.get()), |
| 1835 | "Could not set the geometry for bitmap."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1836 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1837 | //Get the shaded figures from the shaded geometry. |
| 1838 | SkTScopedComPtr<IXpsOMGeometryFigureCollection> shadedFigures; |
| 1839 | HRVM(shadedGeometry->GetFigures(&shadedFigures), |
| 1840 | "Could not get the figures for bitmap."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1841 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1842 | SkMatrix transform = matrix; |
| 1843 | transform.postConcat(*d.fMatrix); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1844 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1845 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform; |
| 1846 | HRV(this->createXpsTransform(transform, &xpsTransform)); |
| 1847 | if (xpsTransform.get()) { |
| 1848 | HRVM(shadedGeometry->SetTransformLocal(xpsTransform.get()), |
| 1849 | "Could not set transform for bitmap."); |
| 1850 | } else { |
| 1851 | //TODO: perspective that bitmap! |
| 1852 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1853 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1854 | SkTScopedComPtr<IXpsOMGeometryFigure> rectFigure; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1855 | if (xpsTransform.get()) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1856 | const SkShader::TileMode xy[2] = { |
| 1857 | SkShader::kClamp_TileMode, |
| 1858 | SkShader::kClamp_TileMode, |
| 1859 | }; |
| 1860 | SkTScopedComPtr<IXpsOMTileBrush> xpsImageBrush; |
robertphillips@google.com | 9bf380c | 2013-07-25 12:10:42 +0000 | [diff] [blame] | 1861 | HRV(this->createXpsImageBrush(bitmap, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1862 | transform, |
| 1863 | xy, |
| 1864 | paint.getAlpha(), |
| 1865 | &xpsImageBrush)); |
| 1866 | HRVM(shadedPath->SetFillBrushLocal(xpsImageBrush.get()), |
| 1867 | "Could not set bitmap brush."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1868 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1869 | const SkRect bitmapRect = SkRect::MakeLTRB(0, 0, |
| 1870 | SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height())); |
| 1871 | HRV(this->createXpsRect(bitmapRect, FALSE, TRUE, &rectFigure)); |
| 1872 | } |
| 1873 | HRVM(shadedFigures->Append(rectFigure.get()), |
| 1874 | "Could not add bitmap figure."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1875 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1876 | //Get the current visual collection and add the shaded path to it. |
| 1877 | SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals; |
| 1878 | HRVM(this->fCurrentXpsCanvas->GetVisuals(¤tVisuals), |
| 1879 | "Could not get current visuals for bitmap"); |
| 1880 | HRVM(currentVisuals->Append(shadedPath.get()), |
| 1881 | "Could not add bitmap to current visuals."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1882 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1883 | HRV(this->clip(shadedPath.get(), d)); |
| 1884 | } |
| 1885 | |
| 1886 | void SkXPSDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap, |
| 1887 | int x, int y, |
| 1888 | const SkPaint& paint) { |
| 1889 | //TODO: override this for XPS |
| 1890 | SkDEBUGF(("XPS drawSprite not yet implemented.")); |
| 1891 | } |
| 1892 | |
| 1893 | HRESULT SkXPSDevice::CreateTypefaceUse(const SkPaint& paint, |
| 1894 | TypefaceUse** typefaceUse) { |
reed@google.com | 398de9a | 2013-03-21 21:43:51 +0000 | [diff] [blame] | 1895 | SkAutoResolveDefaultTypeface typeface(paint.getTypeface()); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1896 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1897 | //Check cache. |
reed@google.com | 398de9a | 2013-03-21 21:43:51 +0000 | [diff] [blame] | 1898 | const SkFontID typefaceID = typeface->uniqueID(); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1899 | if (!this->fTypefaces.empty()) { |
| 1900 | TypefaceUse* current = &this->fTypefaces.front(); |
| 1901 | const TypefaceUse* last = &this->fTypefaces.back(); |
| 1902 | for (; current <= last; ++current) { |
| 1903 | if (current->typefaceId == typefaceID) { |
| 1904 | *typefaceUse = current; |
| 1905 | return S_OK; |
| 1906 | } |
| 1907 | } |
| 1908 | } |
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 | //TODO: create glyph only fonts |
| 1911 | //and let the host deal with what kind of font we're looking at. |
| 1912 | XPS_FONT_EMBEDDING embedding = XPS_FONT_EMBEDDING_RESTRICTED; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1913 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1914 | SkTScopedComPtr<IStream> fontStream; |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 1915 | int ttcIndex; |
| 1916 | SkStream* fontData = typeface->openStream(&ttcIndex); |
bungeman@google.com | 635091f | 2013-10-01 15:03:18 +0000 | [diff] [blame] | 1917 | //TODO: cannot handle FON fonts. |
bungeman@google.com | 8cddc8d | 2012-01-03 22:36:33 +0000 | [diff] [blame] | 1918 | HRM(SkIStream::CreateFromSkStream(fontData, true, &fontStream), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1919 | "Could not create font stream."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1920 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1921 | const size_t size = |
| 1922 | SK_ARRAY_COUNT(L"/Resources/Fonts/" L_GUID_ID L".odttf"); |
| 1923 | wchar_t buffer[size]; |
| 1924 | wchar_t id[GUID_ID_LEN]; |
Ben Wagner | da5a1b8 | 2014-08-22 15:07:06 -0400 | [diff] [blame] | 1925 | HR(this->createId(id, GUID_ID_LEN)); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1926 | swprintf_s(buffer, size, L"/Resources/Fonts/%s.odttf", id); |
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<IOpcPartUri> partUri; |
| 1929 | HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri), |
| 1930 | "Could not create font resource part uri."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1931 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1932 | SkTScopedComPtr<IXpsOMFontResource> xpsFontResource; |
| 1933 | HRM(this->fXpsFactory->CreateFontResource(fontStream.get(), |
| 1934 | embedding, |
| 1935 | partUri.get(), |
| 1936 | FALSE, |
| 1937 | &xpsFontResource), |
| 1938 | "Could not create font resource."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1939 | |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 1940 | //TODO: change openStream to return -1 for non-ttc, get rid of this. |
| 1941 | uint8_t* data = (uint8_t*)fontData->getMemoryBase(); |
| 1942 | bool isTTC = (data && |
| 1943 | fontData->getLength() >= sizeof(SkTTCFHeader) && |
| 1944 | ((SkTTCFHeader*)data)->ttcTag == SkTTCFHeader::TAG); |
| 1945 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1946 | TypefaceUse& newTypefaceUse = this->fTypefaces.push_back(); |
| 1947 | newTypefaceUse.typefaceId = typefaceID; |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 1948 | newTypefaceUse.ttcIndex = isTTC ? ttcIndex : -1; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1949 | newTypefaceUse.fontData = fontData; |
| 1950 | newTypefaceUse.xpsFont = xpsFontResource.release(); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1951 | |
robertphillips | 8e0c150 | 2015-07-07 10:28:43 -0700 | [diff] [blame] | 1952 | SkAutoGlyphCache agc(paint, &this->surfaceProps(), &SkMatrix::I()); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1953 | SkGlyphCache* glyphCache = agc.getCache(); |
| 1954 | unsigned int glyphCount = glyphCache->getGlyphCount(); |
| 1955 | newTypefaceUse.glyphsUsed = new SkBitSet(glyphCount); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1956 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1957 | *typefaceUse = &newTypefaceUse; |
| 1958 | return S_OK; |
| 1959 | } |
| 1960 | |
| 1961 | HRESULT SkXPSDevice::AddGlyphs(const SkDraw& d, |
| 1962 | IXpsOMObjectFactory* xpsFactory, |
| 1963 | IXpsOMCanvas* canvas, |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 1964 | TypefaceUse* font, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1965 | LPCWSTR text, |
| 1966 | XPS_GLYPH_INDEX* xpsGlyphs, |
| 1967 | UINT32 xpsGlyphsLen, |
| 1968 | XPS_POINT *origin, |
| 1969 | FLOAT fontSize, |
| 1970 | XPS_STYLE_SIMULATION sims, |
| 1971 | const SkMatrix& transform, |
| 1972 | const SkPaint& paint) { |
| 1973 | SkTScopedComPtr<IXpsOMGlyphs> glyphs; |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 1974 | HRM(xpsFactory->CreateGlyphs(font->xpsFont, &glyphs), "Could not create glyphs."); |
| 1975 | 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] | 1976 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1977 | //XPS uses affine transformations for everything... |
| 1978 | //...except positioning text. |
| 1979 | bool useCanvasForClip; |
| 1980 | if ((transform.getType() & ~SkMatrix::kTranslate_Mask) == 0) { |
| 1981 | origin->x += SkScalarToFLOAT(transform.getTranslateX()); |
| 1982 | origin->y += SkScalarToFLOAT(transform.getTranslateY()); |
| 1983 | useCanvasForClip = false; |
| 1984 | } else { |
| 1985 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsMatrixToUse; |
| 1986 | HR(this->createXpsTransform(transform, &xpsMatrixToUse)); |
| 1987 | if (xpsMatrixToUse.get()) { |
| 1988 | HRM(glyphs->SetTransformLocal(xpsMatrixToUse.get()), |
| 1989 | "Could not set transform matrix."); |
| 1990 | useCanvasForClip = true; |
| 1991 | } else { |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 1992 | SkDEBUGFAIL("Attempt to add glyphs in perspective."); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1993 | useCanvasForClip = false; |
| 1994 | } |
| 1995 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1996 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1997 | SkTScopedComPtr<IXpsOMGlyphsEditor> glyphsEditor; |
| 1998 | HRM(glyphs->GetGlyphsEditor(&glyphsEditor), "Could not get glyph editor."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 1999 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2000 | if (text) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2001 | HRM(glyphsEditor->SetUnicodeString(text), |
| 2002 | "Could not set unicode string."); |
| 2003 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2004 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2005 | if (xpsGlyphs) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2006 | HRM(glyphsEditor->SetGlyphIndices(xpsGlyphsLen, xpsGlyphs), |
| 2007 | "Could not set glyphs."); |
| 2008 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2009 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2010 | HRM(glyphsEditor->ApplyEdits(), "Could not apply glyph edits."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2011 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2012 | SkTScopedComPtr<IXpsOMBrush> xpsFillBrush; |
| 2013 | HR(this->createXpsBrush( |
| 2014 | paint, |
| 2015 | &xpsFillBrush, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2016 | useCanvasForClip ? nullptr : &transform)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2017 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2018 | HRM(glyphs->SetFillBrushLocal(xpsFillBrush.get()), |
| 2019 | "Could not set fill brush."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2020 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2021 | HRM(glyphs->SetOrigin(origin), "Could not set glyph origin."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2022 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2023 | HRM(glyphs->SetFontRenderingEmSize(fontSize), |
| 2024 | "Could not set font size."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2025 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2026 | HRM(glyphs->SetStyleSimulations(sims), |
| 2027 | "Could not set style simulations."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2028 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2029 | SkTScopedComPtr<IXpsOMVisualCollection> visuals; |
| 2030 | HRM(canvas->GetVisuals(&visuals), "Could not get glyph canvas visuals."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2031 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2032 | if (!useCanvasForClip) { |
| 2033 | HR(this->clip(glyphs.get(), d)); |
| 2034 | HRM(visuals->Append(glyphs.get()), "Could not add glyphs to canvas."); |
| 2035 | } else { |
| 2036 | SkTScopedComPtr<IXpsOMCanvas> glyphCanvas; |
| 2037 | HRM(this->fXpsFactory->CreateCanvas(&glyphCanvas), |
| 2038 | "Could not create glyph canvas."); |
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 | SkTScopedComPtr<IXpsOMVisualCollection> glyphCanvasVisuals; |
| 2041 | HRM(glyphCanvas->GetVisuals(&glyphCanvasVisuals), |
| 2042 | "Could not get glyph visuals collection."); |
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(glyphCanvasVisuals->Append(glyphs.get()), |
| 2045 | "Could not add glyphs to page."); |
| 2046 | HR(this->clip(glyphCanvas.get(), d)); |
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 | HRM(visuals->Append(glyphCanvas.get()), |
| 2049 | "Could not add glyph canvas to page."); |
| 2050 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2051 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2052 | return S_OK; |
| 2053 | } |
| 2054 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2055 | static int num_glyph_guess(SkPaint::TextEncoding encoding, const void* text, size_t byteLength) { |
| 2056 | switch (encoding) { |
| 2057 | case SkPaint::kUTF8_TextEncoding: |
| 2058 | return SkUTF8_CountUnichars(static_cast<const char *>(text), byteLength); |
| 2059 | case SkPaint::kUTF16_TextEncoding: |
| 2060 | return SkUTF16_CountUnichars(static_cast<const uint16_t *>(text), SkToInt(byteLength)); |
| 2061 | case SkPaint::kGlyphID_TextEncoding: |
| 2062 | return SkToInt(byteLength / 2); |
| 2063 | default: |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 2064 | SK_ABORT("Invalid Text Encoding"); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2065 | } |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2066 | return 0; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | static bool text_must_be_pathed(const SkPaint& paint, const SkMatrix& matrix) { |
| 2070 | const SkPaint::Style style = paint.getStyle(); |
| 2071 | return matrix.hasPerspective() |
| 2072 | || SkPaint::kStroke_Style == style |
| 2073 | || SkPaint::kStrokeAndFill_Style == style |
| 2074 | || paint.getMaskFilter() |
| 2075 | || paint.getRasterizer() |
| 2076 | ; |
| 2077 | } |
| 2078 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2079 | typedef SkTDArray<XPS_GLYPH_INDEX> GlyphRun; |
| 2080 | |
| 2081 | class ProcessOneGlyph { |
| 2082 | public: |
| 2083 | ProcessOneGlyph(FLOAT centemPerUnit, SkBitSet* glyphUse, GlyphRun* xpsGlyphs) |
| 2084 | : fCentemPerUnit(centemPerUnit) |
| 2085 | , fGlyphUse(glyphUse) |
| 2086 | , fXpsGlyphs(xpsGlyphs) { } |
| 2087 | |
| 2088 | void operator()(const SkGlyph& glyph, SkPoint position, SkPoint) { |
| 2089 | SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); |
| 2090 | |
| 2091 | SkScalar x = position.fX; |
| 2092 | SkScalar y = position.fY; |
| 2093 | |
| 2094 | XPS_GLYPH_INDEX* xpsGlyph = fXpsGlyphs->append(); |
| 2095 | uint16_t glyphID = glyph.getGlyphID(); |
| 2096 | fGlyphUse->setBit(glyphID, true); |
| 2097 | xpsGlyph->index = glyphID; |
| 2098 | if (1 == fXpsGlyphs->count()) { |
| 2099 | xpsGlyph->advanceWidth = 0.0f; |
| 2100 | xpsGlyph->horizontalOffset = SkScalarToFloat(x) * fCentemPerUnit; |
| 2101 | xpsGlyph->verticalOffset = SkScalarToFloat(y) * -fCentemPerUnit; |
| 2102 | } |
| 2103 | else { |
| 2104 | const XPS_GLYPH_INDEX& first = (*fXpsGlyphs)[0]; |
| 2105 | xpsGlyph->advanceWidth = 0.0f; |
| 2106 | xpsGlyph->horizontalOffset = (SkScalarToFloat(x) * fCentemPerUnit) |
| 2107 | - first.horizontalOffset; |
| 2108 | xpsGlyph->verticalOffset = (SkScalarToFloat(y) * -fCentemPerUnit) |
| 2109 | - first.verticalOffset; |
| 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | private: |
| 2114 | /** [in] Advance width and offsets for glyphs measured in |
| 2115 | hundredths of the font em size (XPS Spec 5.1.3). */ |
| 2116 | const FLOAT fCentemPerUnit; |
| 2117 | /** [in,out] The accumulated glyphs used in the current typeface. */ |
| 2118 | SkBitSet* const fGlyphUse; |
| 2119 | /** [out] The glyphs to draw. */ |
| 2120 | GlyphRun* const fXpsGlyphs; |
| 2121 | }; |
| 2122 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2123 | void SkXPSDevice::drawText(const SkDraw& d, |
| 2124 | const void* text, size_t byteLen, |
| 2125 | SkScalar x, SkScalar y, |
| 2126 | const SkPaint& paint) { |
| 2127 | if (byteLen < 1) return; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2128 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2129 | if (text_must_be_pathed(paint, *d.fMatrix)) { |
| 2130 | SkPath path; |
| 2131 | paint.getTextPath(text, byteLen, x, y, &path); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2132 | this->drawPath(d, path, paint, nullptr, true); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2133 | //TODO: add automation "text" |
| 2134 | return; |
| 2135 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2136 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2137 | TypefaceUse* typeface; |
| 2138 | HRV(CreateTypefaceUse(paint, &typeface)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2139 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2140 | const SkMatrix& matrix = SkMatrix::I(); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2141 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2142 | SkAutoGlyphCache autoCache(paint, &this->surfaceProps(), &matrix); |
| 2143 | SkGlyphCache* cache = autoCache.getCache(); |
reed@google.com | 089130c | 2011-12-12 21:52:18 +0000 | [diff] [blame] | 2144 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2145 | // Advance width and offsets for glyphs measured in hundredths of the font em size |
| 2146 | // (XPS Spec 5.1.3). |
| 2147 | FLOAT centemPerUnit = 100.0f / SkScalarToFLOAT(paint.getTextSize()); |
| 2148 | GlyphRun xpsGlyphs; |
| 2149 | xpsGlyphs.setReserve(num_glyph_guess(paint.getTextEncoding(), |
| 2150 | static_cast<const char*>(text), byteLen)); |
| 2151 | |
| 2152 | ProcessOneGlyph processOneGlyph(centemPerUnit, typeface->glyphsUsed, &xpsGlyphs); |
| 2153 | |
| 2154 | SkFindAndPlaceGlyph::ProcessText( |
| 2155 | paint.getTextEncoding(), static_cast<const char*>(text), byteLen, |
| 2156 | SkPoint{ x, y }, matrix, paint.getTextAlign(), cache, processOneGlyph); |
| 2157 | |
| 2158 | if (xpsGlyphs.count() == 0) { |
reed@google.com | 089130c | 2011-12-12 21:52:18 +0000 | [diff] [blame] | 2159 | return; |
| 2160 | } |
| 2161 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2162 | XPS_POINT origin = { |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2163 | xpsGlyphs[0].horizontalOffset / centemPerUnit, |
| 2164 | xpsGlyphs[0].verticalOffset / -centemPerUnit, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2165 | }; |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2166 | xpsGlyphs[0].horizontalOffset = 0.0f; |
| 2167 | xpsGlyphs[0].verticalOffset = 0.0f; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2168 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2169 | HRV(AddGlyphs(d, |
| 2170 | this->fXpsFactory.get(), |
| 2171 | this->fCurrentXpsCanvas.get(), |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 2172 | typeface, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2173 | nullptr, |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2174 | xpsGlyphs.begin(), xpsGlyphs.count(), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2175 | &origin, |
| 2176 | SkScalarToFLOAT(paint.getTextSize()), |
| 2177 | XPS_STYLE_SIMULATION_NONE, |
| 2178 | *d.fMatrix, |
| 2179 | paint)); |
| 2180 | } |
| 2181 | |
| 2182 | void SkXPSDevice::drawPosText(const SkDraw& d, |
| 2183 | const void* text, size_t byteLen, |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 2184 | const SkScalar pos[], int scalarsPerPos, |
| 2185 | const SkPoint& offset, const SkPaint& paint) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2186 | if (byteLen < 1) return; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2187 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2188 | if (text_must_be_pathed(paint, *d.fMatrix)) { |
| 2189 | SkPath path; |
| 2190 | //TODO: make this work, Draw currently does not handle as well. |
| 2191 | //paint.getTextPath(text, byteLength, x, y, &path); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2192 | //this->drawPath(d, path, paint, nullptr, true); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2193 | //TODO: add automation "text" |
| 2194 | return; |
| 2195 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2196 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2197 | TypefaceUse* typeface; |
| 2198 | HRV(CreateTypefaceUse(paint, &typeface)); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2199 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2200 | const SkMatrix& matrix = SkMatrix::I(); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2201 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2202 | SkAutoGlyphCache autoCache(paint, &this->surfaceProps(), &matrix); |
| 2203 | SkGlyphCache* cache = autoCache.getCache(); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2204 | |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2205 | // Advance width and offsets for glyphs measured in hundredths of the font em size |
| 2206 | // (XPS Spec 5.1.3). |
| 2207 | FLOAT centemPerUnit = 100.0f / SkScalarToFLOAT(paint.getTextSize()); |
| 2208 | GlyphRun xpsGlyphs; |
| 2209 | xpsGlyphs.setReserve(num_glyph_guess(paint.getTextEncoding(), |
| 2210 | static_cast<const char*>(text), byteLen)); |
| 2211 | |
| 2212 | ProcessOneGlyph processOneGlyph(centemPerUnit, typeface->glyphsUsed, &xpsGlyphs); |
| 2213 | |
| 2214 | SkFindAndPlaceGlyph::ProcessPosText( |
| 2215 | paint.getTextEncoding(), static_cast<const char*>(text), byteLen, |
| 2216 | offset, matrix, pos, scalarsPerPos, paint.getTextAlign(), cache, processOneGlyph); |
| 2217 | |
| 2218 | if (xpsGlyphs.count() == 0) { |
reed@google.com | 089130c | 2011-12-12 21:52:18 +0000 | [diff] [blame] | 2219 | return; |
| 2220 | } |
| 2221 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2222 | XPS_POINT origin = { |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2223 | xpsGlyphs[0].horizontalOffset / centemPerUnit, |
| 2224 | xpsGlyphs[0].verticalOffset / -centemPerUnit, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2225 | }; |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2226 | xpsGlyphs[0].horizontalOffset = 0.0f; |
| 2227 | xpsGlyphs[0].verticalOffset = 0.0f; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2228 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2229 | HRV(AddGlyphs(d, |
| 2230 | this->fXpsFactory.get(), |
| 2231 | this->fCurrentXpsCanvas.get(), |
commit-bot@chromium.org | b5e34e2 | 2013-05-07 15:28:15 +0000 | [diff] [blame] | 2232 | typeface, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2233 | nullptr, |
herb | bda2643 | 2015-11-24 08:37:01 -0800 | [diff] [blame] | 2234 | xpsGlyphs.begin(), xpsGlyphs.count(), |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2235 | &origin, |
| 2236 | SkScalarToFLOAT(paint.getTextSize()), |
| 2237 | XPS_STYLE_SIMULATION_NONE, |
| 2238 | *d.fMatrix, |
| 2239 | paint)); |
| 2240 | } |
| 2241 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 2242 | void SkXPSDevice::drawDevice(const SkDraw& d, SkBaseDevice* dev, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2243 | int x, int y, |
| 2244 | const SkPaint&) { |
| 2245 | SkXPSDevice* that = static_cast<SkXPSDevice*>(dev); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2246 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2247 | SkTScopedComPtr<IXpsOMMatrixTransform> xpsTransform; |
| 2248 | XPS_MATRIX rawTransform = { |
| 2249 | 1.0f, |
| 2250 | 0.0f, |
| 2251 | 0.0f, |
| 2252 | 1.0f, |
| 2253 | static_cast<FLOAT>(x), |
| 2254 | static_cast<FLOAT>(y), |
| 2255 | }; |
| 2256 | HRVM(this->fXpsFactory->CreateMatrixTransform(&rawTransform, &xpsTransform), |
| 2257 | "Could not create layer transform."); |
| 2258 | HRVM(that->fCurrentXpsCanvas->SetTransformLocal(xpsTransform.get()), |
| 2259 | "Could not set layer transform."); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 2260 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2261 | //Get the current visual collection and add the layer to it. |
| 2262 | SkTScopedComPtr<IXpsOMVisualCollection> currentVisuals; |
| 2263 | HRVM(this->fCurrentXpsCanvas->GetVisuals(¤tVisuals), |
| 2264 | "Could not get current visuals for layer."); |
| 2265 | HRVM(currentVisuals->Append(that->fCurrentXpsCanvas.get()), |
| 2266 | "Could not add layer to current visuals."); |
| 2267 | } |
| 2268 | |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 2269 | SkBaseDevice* SkXPSDevice::onCreateDevice(const CreateInfo& info, const SkPaint*) { |
bungeman@google.com | 635091f | 2013-10-01 15:03:18 +0000 | [diff] [blame] | 2270 | //Conditional for bug compatibility with PDF device. |
| 2271 | #if 0 |
fmalita | 6987dca | 2014-11-13 08:33:37 -0800 | [diff] [blame] | 2272 | if (SkBaseDevice::kGeneral_Usage == info.fUsage) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2273 | return nullptr; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2274 | //To what stream do we write? |
| 2275 | //SkXPSDevice* dev = new SkXPSDevice(this); |
| 2276 | //SkSize s = SkSize::Make(width, height); |
| 2277 | //dev->BeginCanvas(s, s, SkMatrix::I()); |
| 2278 | //return dev; |
| 2279 | } |
bungeman@google.com | 635091f | 2013-10-01 15:03:18 +0000 | [diff] [blame] | 2280 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 2281 | return new SkXPSDevice(this->fXpsFactory.get()); |
| 2282 | } |
| 2283 | |
mtklein | 1ee7651 | 2015-11-02 10:20:27 -0800 | [diff] [blame] | 2284 | #endif//defined(SK_BUILD_FOR_WIN32) |