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

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

Issue 1069103003: SkPDF: Refactor SkPDFObject heiararchy. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-04-25 (Saturday) 09:40:48 EDT Created 5 years, 8 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/doc/SkDocument_PDF.cpp ('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 "SkAnnotation.h" 10 #include "SkAnnotation.h"
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 &fXObjectResources, 1292 &fXObjectResources,
1293 &fonts); 1293 &fonts);
1294 } 1294 }
1295 1295
1296 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const { 1296 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const {
1297 return fFontResources; 1297 return fFontResources;
1298 } 1298 }
1299 1299
1300 SkPDFArray* SkPDFDevice::copyMediaBox() const { 1300 SkPDFArray* SkPDFDevice::copyMediaBox() const {
1301 // should this be a singleton? 1301 // should this be a singleton?
1302 SkAutoTUnref<SkPDFInt> zero(SkNEW_ARGS(SkPDFInt, (0)));
1303 1302
1304 SkPDFArray* mediaBox = SkNEW(SkPDFArray); 1303 SkAutoTUnref<SkPDFArray> mediaBox(SkNEW(SkPDFArray));
1305 mediaBox->reserve(4); 1304 mediaBox->reserve(4);
1306 mediaBox->append(zero.get()); 1305 mediaBox->appendInt(0);
1307 mediaBox->append(zero.get()); 1306 mediaBox->appendInt(0);
1308 mediaBox->appendInt(fPageSize.fWidth); 1307 mediaBox->appendInt(fPageSize.fWidth);
1309 mediaBox->appendInt(fPageSize.fHeight); 1308 mediaBox->appendInt(fPageSize.fHeight);
1310 return mediaBox; 1309 return mediaBox.detach();
1311 } 1310 }
1312 1311
1313 SkStreamAsset* SkPDFDevice::content() const { 1312 SkStreamAsset* SkPDFDevice::content() const {
1314 SkDynamicMemoryWStream buffer; 1313 SkDynamicMemoryWStream buffer;
1315 this->writeContent(&buffer); 1314 this->writeContent(&buffer);
1316 return buffer.detachAsStream(); 1315 return buffer.detachAsStream();
1317 } 1316 }
1318 1317
1319 void SkPDFDevice::copyContentEntriesToData(ContentEntry* entry, 1318 void SkPDFDevice::copyContentEntriesToData(ContentEntry* entry,
1320 SkWStream* data) const { 1319 SkWStream* data) const {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 } 1497 }
1499 1498
1500 void SkPDFDevice::handleLinkToURL(SkData* urlData, const SkRect& r, 1499 void SkPDFDevice::handleLinkToURL(SkData* urlData, const SkRect& r,
1501 const SkMatrix& matrix) { 1500 const SkMatrix& matrix) {
1502 SkAutoTUnref<SkPDFDict> annotation(createLinkAnnotation(r, matrix)); 1501 SkAutoTUnref<SkPDFDict> annotation(createLinkAnnotation(r, matrix));
1503 1502
1504 SkString url(static_cast<const char *>(urlData->data()), 1503 SkString url(static_cast<const char *>(urlData->data()),
1505 urlData->size() - 1); 1504 urlData->size() - 1);
1506 SkAutoTUnref<SkPDFDict> action(SkNEW_ARGS(SkPDFDict, ("Action"))); 1505 SkAutoTUnref<SkPDFDict> action(SkNEW_ARGS(SkPDFDict, ("Action")));
1507 action->insertName("S", "URI"); 1506 action->insertName("S", "URI");
1508 action->insert("URI", SkNEW_ARGS(SkPDFString, (url)))->unref(); 1507 action->insertString("URI", url);
1509 annotation->insert("A", action.get()); 1508 annotation->insert("A", action.get());
1510 } 1509 }
1511 1510
1512 void SkPDFDevice::handleLinkToNamedDest(SkData* nameData, const SkRect& r, 1511 void SkPDFDevice::handleLinkToNamedDest(SkData* nameData, const SkRect& r,
1513 const SkMatrix& matrix) { 1512 const SkMatrix& matrix) {
1514 SkAutoTUnref<SkPDFDict> annotation(createLinkAnnotation(r, matrix)); 1513 SkAutoTUnref<SkPDFDict> annotation(createLinkAnnotation(r, matrix));
1515 SkString name(static_cast<const char *>(nameData->data()), 1514 SkString name(static_cast<const char *>(nameData->data()),
1516 nameData->size() - 1); 1515 nameData->size() - 1);
1517 annotation->insert("Dest", SkNEW_ARGS(SkPDFName, (name)))->unref(); 1516 annotation->insertName("Dest", name);
1518 } 1517 }
1519 1518
1520 struct NamedDestination { 1519 struct NamedDestination {
1521 const SkData* nameData; 1520 const SkData* nameData;
1522 SkPoint point; 1521 SkPoint point;
1523 1522
1524 NamedDestination(const SkData* nameData, const SkPoint& point) 1523 NamedDestination(const SkData* nameData, const SkPoint& point)
1525 : nameData(nameData), point(point) { 1524 : nameData(SkRef(nameData)), point(point) {}
1526 nameData->ref();
1527 }
1528 1525
1529 ~NamedDestination() { 1526 ~NamedDestination() {
1530 nameData->unref(); 1527 nameData->unref();
1531 } 1528 }
1532 }; 1529 };
1533 1530
1534 void SkPDFDevice::defineNamedDestination(SkData* nameData, const SkPoint& point, 1531 void SkPDFDevice::defineNamedDestination(SkData* nameData, const SkPoint& point,
1535 const SkMatrix& matrix) { 1532 const SkMatrix& matrix) {
1536 SkMatrix transform = matrix; 1533 SkMatrix transform = matrix;
1537 transform.postConcat(fInitialTransform); 1534 transform.postConcat(fInitialTransform);
1538 SkPoint translatedPoint; 1535 SkPoint translatedPoint;
1539 transform.mapXY(point.x(), point.y(), &translatedPoint); 1536 transform.mapXY(point.x(), point.y(), &translatedPoint);
1540 fNamedDestinations.push( 1537 fNamedDestinations.push(
1541 SkNEW_ARGS(NamedDestination, (nameData, translatedPoint))); 1538 SkNEW_ARGS(NamedDestination, (nameData, translatedPoint)));
1542 } 1539 }
1543 1540
1544 void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const { 1541 void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const {
1545 int nDest = fNamedDestinations.count(); 1542 int nDest = fNamedDestinations.count();
1546 for (int i = 0; i < nDest; i++) { 1543 for (int i = 0; i < nDest; i++) {
1547 NamedDestination* dest = fNamedDestinations[i]; 1544 NamedDestination* dest = fNamedDestinations[i];
1548 SkAutoTUnref<SkPDFArray> pdfDest(SkNEW(SkPDFArray)); 1545 SkAutoTUnref<SkPDFArray> pdfDest(SkNEW(SkPDFArray));
1549 pdfDest->reserve(5); 1546 pdfDest->reserve(5);
1550 pdfDest->append(SkNEW_ARGS(SkPDFObjRef, (page)))->unref(); 1547 pdfDest->appendObjRef(SkRef(page));
1551 pdfDest->appendName("XYZ"); 1548 pdfDest->appendName("XYZ");
1552 pdfDest->appendScalar(dest->point.x()); 1549 pdfDest->appendScalar(dest->point.x());
1553 pdfDest->appendScalar(dest->point.y()); 1550 pdfDest->appendScalar(dest->point.y());
1554 pdfDest->appendInt(0); // Leave zoom unchanged 1551 pdfDest->appendInt(0); // Leave zoom unchanged
1555 dict->insert(static_cast<const char *>(dest->nameData->data()), 1552 SkString name(static_cast<const char*>(dest->nameData->data()));
1556 pdfDest); 1553 dict->insertObject(name, pdfDest.detach());
1557 } 1554 }
1558 } 1555 }
1559 1556
1560 SkPDFFormXObject* SkPDFDevice::createFormXObjectFromDevice() { 1557 SkPDFFormXObject* SkPDFDevice::createFormXObjectFromDevice() {
1561 SkPDFFormXObject* xobject = SkNEW_ARGS(SkPDFFormXObject, (this)); 1558 SkPDFFormXObject* xobject = SkNEW_ARGS(SkPDFFormXObject, (this));
1562 // We always draw the form xobjects that we create back into the device, so 1559 // We always draw the form xobjects that we create back into the device, so
1563 // we simply preserve the font usage instead of pulling it out and merging 1560 // we simply preserve the font usage instead of pulling it out and merging
1564 // it back in later. 1561 // it back in later.
1565 cleanUp(false); // Reset this device to have no content. 1562 cleanUp(false); // Reset this device to have no content.
1566 init(); 1563 init();
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
2140 return; 2137 return;
2141 } 2138 }
2142 SkAutoTUnref<SkPDFObject> image(SkPDFBitmap::Create(fCanon, subsetBitmap)); 2139 SkAutoTUnref<SkPDFObject> image(SkPDFBitmap::Create(fCanon, subsetBitmap));
2143 if (!image) { 2140 if (!image) {
2144 return; 2141 return;
2145 } 2142 }
2146 2143
2147 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), 2144 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()),
2148 &content.entry()->fContent); 2145 &content.entry()->fContent);
2149 } 2146 }
OLDNEW
« no previous file with comments | « src/doc/SkDocument_PDF.cpp ('k') | src/pdf/SkPDFFont.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698