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 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 SkPDFUtils::ClosePath(&content.entry()->fContent); | 873 SkPDFUtils::ClosePath(&content.entry()->fContent); |
874 SkPDFUtils::StrokePath(&content.entry()->fContent); | 874 SkPDFUtils::StrokePath(&content.entry()->fContent); |
875 } | 875 } |
876 break; | 876 break; |
877 default: | 877 default: |
878 SkASSERT(false); | 878 SkASSERT(false); |
879 } | 879 } |
880 } | 880 } |
881 | 881 |
882 static SkPDFDict* create_link_annotation(const SkRect& translatedRect) { | 882 static SkPDFDict* create_link_annotation(const SkRect& translatedRect) { |
883 sk_sp<SkPDFDict> annotation(new SkPDFDict("Annot")); | 883 auto annotation = sk_make_sp<SkPDFDict>("Annot"); |
884 annotation->insertName("Subtype", "Link"); | 884 annotation->insertName("Subtype", "Link"); |
885 | 885 |
886 sk_sp<SkPDFArray> border(new SkPDFArray); | 886 auto border = sk_make_sp<SkPDFArray>(); |
887 border->reserve(3); | 887 border->reserve(3); |
888 border->appendInt(0); // Horizontal corner radius. | 888 border->appendInt(0); // Horizontal corner radius. |
889 border->appendInt(0); // Vertical corner radius. | 889 border->appendInt(0); // Vertical corner radius. |
890 border->appendInt(0); // Width, 0 = no border. | 890 border->appendInt(0); // Width, 0 = no border. |
891 annotation->insertObject("Border", border.release()); | 891 annotation->insertObject("Border", border.release()); |
892 | 892 |
893 sk_sp<SkPDFArray> rect(new SkPDFArray); | 893 auto rect = sk_make_sp<SkPDFArray>(); |
894 rect->reserve(4); | 894 rect->reserve(4); |
895 rect->appendScalar(translatedRect.fLeft); | 895 rect->appendScalar(translatedRect.fLeft); |
896 rect->appendScalar(translatedRect.fTop); | 896 rect->appendScalar(translatedRect.fTop); |
897 rect->appendScalar(translatedRect.fRight); | 897 rect->appendScalar(translatedRect.fRight); |
898 rect->appendScalar(translatedRect.fBottom); | 898 rect->appendScalar(translatedRect.fBottom); |
899 annotation->insertObject("Rect", rect.release()); | 899 annotation->insertObject("Rect", rect.release()); |
900 | 900 |
901 return annotation.release(); | 901 return annotation.release(); |
902 } | 902 } |
903 | 903 |
904 static SkPDFDict* create_link_to_url(const SkData* urlData, const SkRect& r) { | 904 static SkPDFDict* create_link_to_url(const SkData* urlData, const SkRect& r) { |
905 sk_sp<SkPDFDict> annotation(create_link_annotation(r)); | 905 sk_sp<SkPDFDict> annotation(create_link_annotation(r)); |
906 | 906 |
907 SkString url(static_cast<const char *>(urlData->data()), | 907 SkString url(static_cast<const char *>(urlData->data()), |
908 urlData->size() - 1); | 908 urlData->size() - 1); |
909 sk_sp<SkPDFDict> action(new SkPDFDict("Action")); | 909 auto action = sk_make_sp<SkPDFDict>("Action"); |
910 action->insertName("S", "URI"); | 910 action->insertName("S", "URI"); |
911 action->insertString("URI", url); | 911 action->insertString("URI", url); |
912 annotation->insertObject("A", action.release()); | 912 annotation->insertObject("A", action.release()); |
913 return annotation.release(); | 913 return annotation.release(); |
914 } | 914 } |
915 | 915 |
916 static SkPDFDict* create_link_named_dest(const SkData* nameData, | 916 static SkPDFDict* create_link_named_dest(const SkData* nameData, |
917 const SkRect& r) { | 917 const SkRect& r) { |
918 sk_sp<SkPDFDict> annotation(create_link_annotation(r)); | 918 sk_sp<SkPDFDict> annotation(create_link_annotation(r)); |
919 SkString name(static_cast<const char *>(nameData->data()), | 919 SkString name(static_cast<const char *>(nameData->data()), |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 SkPath shape; | 1441 SkPath shape; |
1442 shape.addRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), | 1442 shape.addRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), |
1443 SkIntToScalar(device->width()), | 1443 SkIntToScalar(device->width()), |
1444 SkIntToScalar(device->height()))); | 1444 SkIntToScalar(device->height()))); |
1445 content.setShape(shape); | 1445 content.setShape(shape); |
1446 } | 1446 } |
1447 if (!content.needSource()) { | 1447 if (!content.needSource()) { |
1448 return; | 1448 return; |
1449 } | 1449 } |
1450 | 1450 |
1451 sk_sp<SkPDFFormXObject> xObject(new SkPDFFormXObject(pdfDevice)); | 1451 auto xObject = sk_make_sp<SkPDFFormXObject>(pdfDevice); |
1452 SkPDFUtils::DrawFormXObject(this->addXObjectResource(xObject.get()), | 1452 SkPDFUtils::DrawFormXObject(this->addXObjectResource(xObject.get()), |
1453 &content.entry()->fContent); | 1453 &content.entry()->fContent); |
1454 | 1454 |
1455 // Merge glyph sets from the drawn device. | 1455 // Merge glyph sets from the drawn device. |
1456 fFontGlyphUsage->merge(pdfDevice->getFontGlyphUsage()); | 1456 fFontGlyphUsage->merge(pdfDevice->getFontGlyphUsage()); |
1457 } | 1457 } |
1458 | 1458 |
1459 SkImageInfo SkPDFDevice::imageInfo() const { | 1459 SkImageInfo SkPDFDevice::imageInfo() const { |
1460 return fLegacyBitmap.info(); | 1460 return fLegacyBitmap.info(); |
1461 } | 1461 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1520 &fonts); | 1520 &fonts); |
1521 } | 1521 } |
1522 | 1522 |
1523 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const { | 1523 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const { |
1524 return fFontResources; | 1524 return fFontResources; |
1525 } | 1525 } |
1526 | 1526 |
1527 SkPDFArray* SkPDFDevice::copyMediaBox() const { | 1527 SkPDFArray* SkPDFDevice::copyMediaBox() const { |
1528 // should this be a singleton? | 1528 // should this be a singleton? |
1529 | 1529 |
1530 sk_sp<SkPDFArray> mediaBox(new SkPDFArray); | 1530 auto mediaBox = sk_make_sp<SkPDFArray>(); |
1531 mediaBox->reserve(4); | 1531 mediaBox->reserve(4); |
1532 mediaBox->appendInt(0); | 1532 mediaBox->appendInt(0); |
1533 mediaBox->appendInt(0); | 1533 mediaBox->appendInt(0); |
1534 mediaBox->appendInt(fPageSize.fWidth); | 1534 mediaBox->appendInt(fPageSize.fWidth); |
1535 mediaBox->appendInt(fPageSize.fHeight); | 1535 mediaBox->appendInt(fPageSize.fHeight); |
1536 return mediaBox.release(); | 1536 return mediaBox.release(); |
1537 } | 1537 } |
1538 | 1538 |
1539 SkStreamAsset* SkPDFDevice::content() const { | 1539 SkStreamAsset* SkPDFDevice::content() const { |
1540 SkDynamicMemoryWStream buffer; | 1540 SkDynamicMemoryWStream buffer; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1704 for (const RectWithData& linkToDestination : fLinkToDestinations) { | 1704 for (const RectWithData& linkToDestination : fLinkToDestinations) { |
1705 SkRect r; | 1705 SkRect r; |
1706 fInitialTransform.mapRect(&r, linkToDestination.rect); | 1706 fInitialTransform.mapRect(&r, linkToDestination.rect); |
1707 array->appendObject( | 1707 array->appendObject( |
1708 create_link_named_dest(linkToDestination.data.get(), r)); | 1708 create_link_named_dest(linkToDestination.data.get(), r)); |
1709 } | 1709 } |
1710 } | 1710 } |
1711 | 1711 |
1712 void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const { | 1712 void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const { |
1713 for (const NamedDestination& dest : fNamedDestinations) { | 1713 for (const NamedDestination& dest : fNamedDestinations) { |
1714 sk_sp<SkPDFArray> pdfDest(new SkPDFArray); | 1714 auto pdfDest = sk_make_sp<SkPDFArray>(); |
1715 pdfDest->reserve(5); | 1715 pdfDest->reserve(5); |
1716 pdfDest->appendObjRef(SkRef(page)); | 1716 pdfDest->appendObjRef(SkRef(page)); |
1717 pdfDest->appendName("XYZ"); | 1717 pdfDest->appendName("XYZ"); |
1718 SkPoint p = fInitialTransform.mapXY(dest.point.x(), dest.point.y()); | 1718 SkPoint p = fInitialTransform.mapXY(dest.point.x(), dest.point.y()); |
1719 pdfDest->appendScalar(p.x()); | 1719 pdfDest->appendScalar(p.x()); |
1720 pdfDest->appendScalar(p.y()); | 1720 pdfDest->appendScalar(p.y()); |
1721 pdfDest->appendInt(0); // Leave zoom unchanged | 1721 pdfDest->appendInt(0); // Leave zoom unchanged |
1722 SkString name(static_cast<const char*>(dest.nameData->data())); | 1722 SkString name(static_cast<const char*>(dest.nameData->data())); |
1723 dict->insertObject(name, pdfDest.release()); | 1723 dict->insertObject(name, pdfDest.release()); |
1724 } | 1724 } |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2328 pdfimage.reset(SkPDFCreateBitmapObject( | 2328 pdfimage.reset(SkPDFCreateBitmapObject( |
2329 image, fCanon->getPixelSerializer())); | 2329 image, fCanon->getPixelSerializer())); |
2330 if (!pdfimage) { | 2330 if (!pdfimage) { |
2331 return; | 2331 return; |
2332 } | 2332 } |
2333 fCanon->addPDFBitmap(image->uniqueID(), pdfimage.get()); | 2333 fCanon->addPDFBitmap(image->uniqueID(), pdfimage.get()); |
2334 } | 2334 } |
2335 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), | 2335 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), |
2336 &content.entry()->fContent); | 2336 &content.entry()->fContent); |
2337 } | 2337 } |
OLD | NEW |