Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: src/pdf/SkPDFDevice.cpp

Issue 1775043002: SkPDF: Add sk_sp setters; .release() becomes std::move() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix -Wpessimizing-move Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFDevice.h ('k') | src/pdf/SkPDFFont.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 &content.entry()->fContent); 872 &content.entry()->fContent);
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 sk_sp<SkPDFDict> create_link_annotation(const SkRect& translatedRect) {
883 auto annotation = sk_make_sp<SkPDFDict>("Annot"); 883 auto annotation = sk_make_sp<SkPDFDict>("Annot");
884 annotation->insertName("Subtype", "Link"); 884 annotation->insertName("Subtype", "Link");
885 885
886 auto border = sk_make_sp<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", std::move(border));
892 892
893 auto rect = sk_make_sp<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", std::move(rect));
900 900
901 return annotation.release(); 901 return annotation;
902 } 902 }
903 903
904 static SkPDFDict* create_link_to_url(const SkData* urlData, const SkRect& r) { 904 static sk_sp<SkPDFDict> create_link_to_url(const SkData* urlData, const SkRect& r) {
905 sk_sp<SkPDFDict> annotation(create_link_annotation(r)); 905 auto annotation = create_link_annotation(r);
906
907 SkString url(static_cast<const char *>(urlData->data()), 906 SkString url(static_cast<const char *>(urlData->data()),
908 urlData->size() - 1); 907 urlData->size() - 1);
909 auto action = sk_make_sp<SkPDFDict>("Action"); 908 auto action = sk_make_sp<SkPDFDict>("Action");
910 action->insertName("S", "URI"); 909 action->insertName("S", "URI");
911 action->insertString("URI", url); 910 action->insertString("URI", url);
912 annotation->insertObject("A", action.release()); 911 annotation->insertObject("A", std::move(action));
913 return annotation.release(); 912 return annotation;
914 } 913 }
915 914
916 static SkPDFDict* create_link_named_dest(const SkData* nameData, 915 static sk_sp<SkPDFDict> create_link_named_dest(const SkData* nameData,
917 const SkRect& r) { 916 const SkRect& r) {
918 sk_sp<SkPDFDict> annotation(create_link_annotation(r)); 917 auto annotation = create_link_annotation(r);
919 SkString name(static_cast<const char *>(nameData->data()), 918 SkString name(static_cast<const char *>(nameData->data()),
920 nameData->size() - 1); 919 nameData->size() - 1);
921 annotation->insertName("Dest", name); 920 annotation->insertName("Dest", name);
922 return annotation.release(); 921 return annotation;
923 } 922 }
924 923
925 void SkPDFDevice::drawRect(const SkDraw& d, 924 void SkPDFDevice::drawRect(const SkDraw& d,
926 const SkRect& rect, 925 const SkRect& rect,
927 const SkPaint& srcPaint) { 926 const SkPaint& srcPaint) {
928 SkPaint paint = srcPaint; 927 SkPaint paint = srcPaint;
929 replace_srcmode_on_opaque_paint(&paint); 928 replace_srcmode_on_opaque_paint(&paint);
930 SkRect r = rect; 929 SkRect r = rect;
931 r.sort(); 930 r.sort();
932 931
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 fLastMarginContentEntry = contentEntry; 1499 fLastMarginContentEntry = contentEntry;
1501 } 1500 }
1502 } 1501 }
1503 1502
1504 void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) { 1503 void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) {
1505 // A ScopedContentEntry only exists during the course of a draw call, so 1504 // A ScopedContentEntry only exists during the course of a draw call, so
1506 // this can't be called while a ScopedContentEntry exists. 1505 // this can't be called while a ScopedContentEntry exists.
1507 fDrawingArea = drawingArea; 1506 fDrawingArea = drawingArea;
1508 } 1507 }
1509 1508
1510 SkPDFDict* SkPDFDevice::createResourceDict() const { 1509 sk_sp<SkPDFDict> SkPDFDevice::makeResourceDict() const {
1511 SkTDArray<SkPDFObject*> fonts; 1510 SkTDArray<SkPDFObject*> fonts;
1512 fonts.setReserve(fFontResources.count()); 1511 fonts.setReserve(fFontResources.count());
1513 for (SkPDFFont* font : fFontResources) { 1512 for (SkPDFFont* font : fFontResources) {
1514 fonts.push(font); 1513 fonts.push(font);
1515 } 1514 }
1516 return SkPDFResourceDict::Create( 1515 return SkPDFResourceDict::Make(
1517 &fGraphicStateResources, 1516 &fGraphicStateResources,
1518 &fShaderResources, 1517 &fShaderResources,
1519 &fXObjectResources, 1518 &fXObjectResources,
1520 &fonts); 1519 &fonts);
1521 } 1520 }
1522 1521
1523 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const { 1522 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const {
1524 return fFontResources; 1523 return fFontResources;
1525 } 1524 }
1526 1525
1527 SkPDFArray* SkPDFDevice::copyMediaBox() const { 1526 sk_sp<SkPDFArray> SkPDFDevice::copyMediaBox() const {
1528 // should this be a singleton?
1529
1530 auto mediaBox = sk_make_sp<SkPDFArray>(); 1527 auto mediaBox = sk_make_sp<SkPDFArray>();
1531 mediaBox->reserve(4); 1528 mediaBox->reserve(4);
1532 mediaBox->appendInt(0); 1529 mediaBox->appendInt(0);
1533 mediaBox->appendInt(0); 1530 mediaBox->appendInt(0);
1534 mediaBox->appendInt(fPageSize.fWidth); 1531 mediaBox->appendInt(fPageSize.width());
1535 mediaBox->appendInt(fPageSize.fHeight); 1532 mediaBox->appendInt(fPageSize.height());
1536 return mediaBox.release(); 1533 return mediaBox;
1537 } 1534 }
1538 1535
1539 SkStreamAsset* SkPDFDevice::content() const { 1536 skstd::unique_ptr<SkStreamAsset> SkPDFDevice::content() const {
1540 SkDynamicMemoryWStream buffer; 1537 SkDynamicMemoryWStream buffer;
1541 this->writeContent(&buffer); 1538 this->writeContent(&buffer);
1542 return buffer.bytesWritten() > 0 1539 return skstd::unique_ptr<SkStreamAsset>(
1543 ? buffer.detachAsStream() 1540 buffer.bytesWritten() > 0
1544 : new SkMemoryStream; 1541 ? buffer.detachAsStream()
1542 : new SkMemoryStream);
1545 } 1543 }
1546 1544
1547 void SkPDFDevice::copyContentEntriesToData(ContentEntry* entry, 1545 void SkPDFDevice::copyContentEntriesToData(ContentEntry* entry,
1548 SkWStream* data) const { 1546 SkWStream* data) const {
1549 // TODO(ctguil): For margins, I'm not sure fExistingClipStack/Region is the 1547 // TODO(ctguil): For margins, I'm not sure fExistingClipStack/Region is the
1550 // right thing to pass here. 1548 // right thing to pass here.
1551 GraphicStackState gsState(fExistingClipStack, fExistingClipRegion, data); 1549 GraphicStackState gsState(fExistingClipStack, fExistingClipRegion, data);
1552 while (entry != nullptr) { 1550 while (entry != nullptr) {
1553 SkPoint translation; 1551 SkPoint translation;
1554 translation.iset(this->getOrigin()); 1552 translation.iset(this->getOrigin());
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 fInitialTransform.mapRect(&r, linkToDestination.rect); 1704 fInitialTransform.mapRect(&r, linkToDestination.rect);
1707 array->appendObject( 1705 array->appendObject(
1708 create_link_named_dest(linkToDestination.data.get(), r)); 1706 create_link_named_dest(linkToDestination.data.get(), r));
1709 } 1707 }
1710 } 1708 }
1711 1709
1712 void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const { 1710 void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const {
1713 for (const NamedDestination& dest : fNamedDestinations) { 1711 for (const NamedDestination& dest : fNamedDestinations) {
1714 auto pdfDest = sk_make_sp<SkPDFArray>(); 1712 auto pdfDest = sk_make_sp<SkPDFArray>();
1715 pdfDest->reserve(5); 1713 pdfDest->reserve(5);
1716 pdfDest->appendObjRef(SkRef(page)); 1714 pdfDest->appendObjRef(sk_sp<SkPDFObject>(SkRef(page)));
1717 pdfDest->appendName("XYZ"); 1715 pdfDest->appendName("XYZ");
1718 SkPoint p = fInitialTransform.mapXY(dest.point.x(), dest.point.y()); 1716 SkPoint p = fInitialTransform.mapXY(dest.point.x(), dest.point.y());
1719 pdfDest->appendScalar(p.x()); 1717 pdfDest->appendScalar(p.x());
1720 pdfDest->appendScalar(p.y()); 1718 pdfDest->appendScalar(p.y());
1721 pdfDest->appendInt(0); // Leave zoom unchanged 1719 pdfDest->appendInt(0); // Leave zoom unchanged
1722 SkString name(static_cast<const char*>(dest.nameData->data())); 1720 SkString name(static_cast<const char*>(dest.nameData->data()));
1723 dict->insertObject(name, pdfDest.release()); 1721 dict->insertObject(name, std::move(pdfDest));
1724 } 1722 }
1725 } 1723 }
1726 1724
1727 SkPDFFormXObject* SkPDFDevice::createFormXObjectFromDevice() { 1725 SkPDFFormXObject* SkPDFDevice::createFormXObjectFromDevice() {
1728 SkPDFFormXObject* xobject = new SkPDFFormXObject(this); 1726 SkPDFFormXObject* xobject = new SkPDFFormXObject(this);
1729 // We always draw the form xobjects that we create back into the device, so 1727 // We always draw the form xobjects that we create back into the device, so
1730 // we simply preserve the font usage instead of pulling it out and merging 1728 // we simply preserve the font usage instead of pulling it out and merging
1731 // it back in later. 1729 // it back in later.
1732 cleanUp(false); // Reset this device to have no content. 1730 cleanUp(false); // Reset this device to have no content.
1733 init(); 1731 init();
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
2328 pdfimage.reset(SkPDFCreateBitmapObject( 2326 pdfimage.reset(SkPDFCreateBitmapObject(
2329 image, fCanon->getPixelSerializer())); 2327 image, fCanon->getPixelSerializer()));
2330 if (!pdfimage) { 2328 if (!pdfimage) {
2331 return; 2329 return;
2332 } 2330 }
2333 fCanon->addPDFBitmap(image->uniqueID(), pdfimage.get()); 2331 fCanon->addPDFBitmap(image->uniqueID(), pdfimage.get());
2334 } 2332 }
2335 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), 2333 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()),
2336 &content.entry()->fContent); 2334 &content.entry()->fContent);
2337 } 2335 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDevice.h ('k') | src/pdf/SkPDFFont.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698