OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkPDFDevice.h" | 8 #include "SkPDFDevice.h" |
9 | 9 |
10 #include "SkAnnotationKeys.h" | 10 #include "SkAnnotationKeys.h" |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 static bool not_supported_for_layers(const SkPaint& layerPaint) { | 534 static bool not_supported_for_layers(const SkPaint& layerPaint) { |
535 // PDF does not support image filters, so render them on CPU. | 535 // PDF does not support image filters, so render them on CPU. |
536 // Note that this rendering is done at "screen" resolution (100dpi), not | 536 // Note that this rendering is done at "screen" resolution (100dpi), not |
537 // printer resolution. | 537 // printer resolution. |
538 // TODO: It may be possible to express some filters natively using PDF | 538 // TODO: It may be possible to express some filters natively using PDF |
539 // to improve quality and file size (https://bug.skia.org/3043) | 539 // to improve quality and file size (https://bug.skia.org/3043) |
540 | 540 |
541 // TODO: should we return true if there is a colorfilter? | 541 // TODO: should we return true if there is a colorfilter? |
542 return layerPaint.getImageFilter() != nullptr; | 542 return layerPaint.getImageFilter() != nullptr; |
543 } | 543 } |
544 | 544 |
robertphillips
2016/07/15 15:07:22
Move this to the top ?
reed1
2016/07/15 16:46:31
Done.
| |
545 #include "SkBitmapDevice.h" | |
546 | |
545 SkBaseDevice* SkPDFDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint * layerPaint) { | 547 SkBaseDevice* SkPDFDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint * layerPaint) { |
546 if (cinfo.fForImageFilter || | 548 if (cinfo.fForImageFilter || (layerPaint && not_supported_for_layers(*layerP aint))) { |
547 (layerPaint && not_supported_for_layers(*layerPaint))) { | 549 // need to return a raster device, which we will detect in drawDevice() |
548 return nullptr; | 550 return SkBitmapDevice::Create(cinfo.fInfo, SkSurfaceProps(0, kUnknown_Sk PixelGeometry)); |
549 } | 551 } |
550 SkISize size = SkISize::Make(cinfo.fInfo.width(), cinfo.fInfo.height()); | 552 SkISize size = SkISize::Make(cinfo.fInfo.width(), cinfo.fInfo.height()); |
551 return SkPDFDevice::Create(size, fRasterDpi, fDocument); | 553 return SkPDFDevice::Create(size, fRasterDpi, fDocument); |
552 } | 554 } |
553 | 555 |
554 SkPDFCanon* SkPDFDevice::getCanon() const { return fDocument->canon(); } | 556 SkPDFCanon* SkPDFDevice::getCanon() const { return fDocument->canon(); } |
555 | 557 |
556 | 558 |
557 | 559 |
558 // A helper class to automatically finish a ContentEntry at the end of a | 560 // A helper class to automatically finish a ContentEntry at the end of a |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1265 SkXfermode* xmode, const uint16_t indices[], | 1267 SkXfermode* xmode, const uint16_t indices[], |
1266 int indexCount, const SkPaint& paint) { | 1268 int indexCount, const SkPaint& paint) { |
1267 if (d.fRC->isEmpty()) { | 1269 if (d.fRC->isEmpty()) { |
1268 return; | 1270 return; |
1269 } | 1271 } |
1270 // TODO: implement drawVertices | 1272 // TODO: implement drawVertices |
1271 } | 1273 } |
1272 | 1274 |
1273 void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device, | 1275 void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device, |
1274 int x, int y, const SkPaint& paint) { | 1276 int x, int y, const SkPaint& paint) { |
1277 // Check if the source device is really a bitmapdevice (because that's what we returned | |
1278 // from createDevice (likely due to an imagefilter) | |
1279 SkPixmap pmap; | |
1280 if (device->peekPixels(&pmap)) { | |
1281 SkBitmap bitmap; | |
1282 bitmap.installPixels(pmap); | |
1283 if (paint.getImageFilter()) { | |
1284 this->drawSpriteWithFilter(d, bitmap, x, y, paint); | |
1285 } else { | |
1286 this->drawSprite(d, bitmap, x, y, paint); | |
1287 } | |
1288 return; | |
1289 } | |
1290 | |
1275 // our onCreateCompatibleDevice() always creates SkPDFDevice subclasses. | 1291 // our onCreateCompatibleDevice() always creates SkPDFDevice subclasses. |
1276 SkPDFDevice* pdfDevice = static_cast<SkPDFDevice*>(device); | 1292 SkPDFDevice* pdfDevice = static_cast<SkPDFDevice*>(device); |
1277 | 1293 |
1278 SkScalar scalarX = SkIntToScalar(x); | 1294 SkScalar scalarX = SkIntToScalar(x); |
1279 SkScalar scalarY = SkIntToScalar(y); | 1295 SkScalar scalarY = SkIntToScalar(y); |
1280 for (const RectWithData& l : pdfDevice->fLinkToURLs) { | 1296 for (const RectWithData& l : pdfDevice->fLinkToURLs) { |
1281 SkRect r = l.rect.makeOffset(scalarX, scalarY); | 1297 SkRect r = l.rect.makeOffset(scalarX, scalarY); |
1282 fLinkToURLs.emplace_back(r, l.data.get()); | 1298 fLinkToURLs.emplace_back(r, l.data.get()); |
1283 } | 1299 } |
1284 for (const RectWithData& l : pdfDevice->fLinkToDestinations) { | 1300 for (const RectWithData& l : pdfDevice->fLinkToDestinations) { |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2122 if (!pdfimage) { | 2138 if (!pdfimage) { |
2123 return; | 2139 return; |
2124 } | 2140 } |
2125 fDocument->serialize(pdfimage); // serialize images early. | 2141 fDocument->serialize(pdfimage); // serialize images early. |
2126 fDocument->canon()->addPDFBitmap(key, pdfimage); | 2142 fDocument->canon()->addPDFBitmap(key, pdfimage); |
2127 } | 2143 } |
2128 // TODO(halcanary): addXObjectResource() should take a sk_sp<SkPDFObject> | 2144 // TODO(halcanary): addXObjectResource() should take a sk_sp<SkPDFObject> |
2129 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), | 2145 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), |
2130 &content.entry()->fContent); | 2146 &content.entry()->fContent); |
2131 } | 2147 } |
OLD | NEW |