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

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

Issue 1035513003: SkPDF: skpdfdocument and skpdfpage use skpdfdevice in a const way (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 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/SkPDFDocument.h » ('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 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 //////////////////////////////////////////////////////////////////////////////// 698 ////////////////////////////////////////////////////////////////////////////////
699 699
700 SkPDFDevice::SkPDFDevice(SkISize pageSize, 700 SkPDFDevice::SkPDFDevice(SkISize pageSize,
701 SkScalar rasterDpi, 701 SkScalar rasterDpi,
702 SkPDFCanon* canon, 702 SkPDFCanon* canon,
703 bool flip) 703 bool flip)
704 : fPageSize(pageSize) 704 : fPageSize(pageSize)
705 , fContentSize(pageSize) 705 , fContentSize(pageSize)
706 , fExistingClipRegion(SkIRect::MakeSize(pageSize)) 706 , fExistingClipRegion(SkIRect::MakeSize(pageSize))
707 , fAnnotations(NULL) 707 , fAnnotations(NULL)
708 , fResourceDict(NULL)
709 , fLastContentEntry(NULL) 708 , fLastContentEntry(NULL)
710 , fLastMarginContentEntry(NULL) 709 , fLastMarginContentEntry(NULL)
711 , fDrawingArea(kContent_DrawingArea) 710 , fDrawingArea(kContent_DrawingArea)
712 , fClipStack(NULL) 711 , fClipStack(NULL)
713 , fFontGlyphUsage(SkNEW(SkPDFGlyphSetMap)) 712 , fFontGlyphUsage(SkNEW(SkPDFGlyphSetMap))
714 , fRasterDpi(rasterDpi) 713 , fRasterDpi(rasterDpi)
715 , fCanon(canon) { 714 , fCanon(canon) {
716 SkASSERT(pageSize.width() > 0); 715 SkASSERT(pageSize.width() > 0);
717 SkASSERT(pageSize.height() > 0); 716 SkASSERT(pageSize.height() > 0);
718 fLegacyBitmap.setInfo( 717 fLegacyBitmap.setInfo(
719 SkImageInfo::MakeUnknown(pageSize.width(), pageSize.height())); 718 SkImageInfo::MakeUnknown(pageSize.width(), pageSize.height()));
720 if (flip) { 719 if (flip) {
721 // Skia generally uses the top left as the origin but PDF 720 // Skia generally uses the top left as the origin but PDF
722 // natively has the origin at the bottom left. This matrix 721 // natively has the origin at the bottom left. This matrix
723 // corrects for that. But that only needs to be done once, we 722 // corrects for that. But that only needs to be done once, we
724 // don't do it when layering. 723 // don't do it when layering.
725 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); 724 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight));
726 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); 725 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1);
727 } else { 726 } else {
728 fInitialTransform.setIdentity(); 727 fInitialTransform.setIdentity();
729 } 728 }
730 } 729 }
731 730
732 SkPDFDevice::~SkPDFDevice() { 731 SkPDFDevice::~SkPDFDevice() {
733 this->cleanUp(true); 732 this->cleanUp(true);
734 } 733 }
735 734
736 void SkPDFDevice::init() { 735 void SkPDFDevice::init() {
737 fAnnotations = NULL; 736 fAnnotations = NULL;
738 fResourceDict = NULL;
739 fContentEntries.free(); 737 fContentEntries.free();
740 fLastContentEntry = NULL; 738 fLastContentEntry = NULL;
741 fMarginContentEntries.free(); 739 fMarginContentEntries.free();
742 fLastMarginContentEntry = NULL; 740 fLastMarginContentEntry = NULL;
743 fDrawingArea = kContent_DrawingArea; 741 fDrawingArea = kContent_DrawingArea;
744 if (fFontGlyphUsage.get() == NULL) { 742 if (fFontGlyphUsage.get() == NULL) {
745 fFontGlyphUsage.reset(SkNEW(SkPDFGlyphSetMap)); 743 fFontGlyphUsage.reset(SkNEW(SkPDFGlyphSetMap));
746 } 744 }
747 } 745 }
748 746
749 void SkPDFDevice::cleanUp(bool clearFontUsage) { 747 void SkPDFDevice::cleanUp(bool clearFontUsage) {
750 fGraphicStateResources.unrefAll(); 748 fGraphicStateResources.unrefAll();
751 fXObjectResources.unrefAll(); 749 fXObjectResources.unrefAll();
752 fFontResources.unrefAll(); 750 fFontResources.unrefAll();
753 fShaderResources.unrefAll(); 751 fShaderResources.unrefAll();
754 SkSafeUnref(fAnnotations); 752 SkSafeUnref(fAnnotations);
755 SkSafeUnref(fResourceDict);
756 fNamedDestinations.deleteAll(); 753 fNamedDestinations.deleteAll();
757 754
758 if (clearFontUsage) { 755 if (clearFontUsage) {
759 fFontGlyphUsage->reset(); 756 fFontGlyphUsage->reset();
760 } 757 }
761 } 758 }
762 759
763 void SkPDFDevice::drawPaint(const SkDraw& d, const SkPaint& paint) { 760 void SkPDFDevice::drawPaint(const SkDraw& d, const SkPaint& paint) {
764 SkPaint newPaint = paint; 761 SkPaint newPaint = paint;
765 newPaint.setStyle(SkPaint::kFill_Style); 762 newPaint.setStyle(SkPaint::kFill_Style);
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 fLastMarginContentEntry = contentEntry; 1239 fLastMarginContentEntry = contentEntry;
1243 } 1240 }
1244 } 1241 }
1245 1242
1246 void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) { 1243 void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) {
1247 // A ScopedContentEntry only exists during the course of a draw call, so 1244 // A ScopedContentEntry only exists during the course of a draw call, so
1248 // this can't be called while a ScopedContentEntry exists. 1245 // this can't be called while a ScopedContentEntry exists.
1249 fDrawingArea = drawingArea; 1246 fDrawingArea = drawingArea;
1250 } 1247 }
1251 1248
1252 SkPDFResourceDict* SkPDFDevice::getResourceDict() { 1249 SkPDFResourceDict* SkPDFDevice::createResourceDict() const {
1253 if (NULL == fResourceDict) { 1250 SkAutoTUnref<SkPDFResourceDict> resourceDict(SkNEW(SkPDFResourceDict));
1254 fResourceDict = SkNEW(SkPDFResourceDict); 1251 if (fGraphicStateResources.count()) {
1255 1252 for (int i = 0; i < fGraphicStateResources.count(); i++) {
1256 if (fGraphicStateResources.count()) { 1253 resourceDict->insertResourceAsReference(
1257 for (int i = 0; i < fGraphicStateResources.count(); i++) { 1254 SkPDFResourceDict::kExtGState_ResourceType,
1258 fResourceDict->insertResourceAsReference( 1255 i, fGraphicStateResources[i]);
1259 SkPDFResourceDict::kExtGState_ResourceType,
1260 i, fGraphicStateResources[i]);
1261 }
1262 }
1263
1264 if (fXObjectResources.count()) {
1265 for (int i = 0; i < fXObjectResources.count(); i++) {
1266 fResourceDict->insertResourceAsReference(
1267 SkPDFResourceDict::kXObject_ResourceType,
1268 i, fXObjectResources[i]);
1269 }
1270 }
1271
1272 if (fFontResources.count()) {
1273 for (int i = 0; i < fFontResources.count(); i++) {
1274 fResourceDict->insertResourceAsReference(
1275 SkPDFResourceDict::kFont_ResourceType,
1276 i, fFontResources[i]);
1277 }
1278 }
1279
1280 if (fShaderResources.count()) {
1281 SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict());
1282 for (int i = 0; i < fShaderResources.count(); i++) {
1283 fResourceDict->insertResourceAsReference(
1284 SkPDFResourceDict::kPattern_ResourceType,
1285 i, fShaderResources[i]);
1286 }
1287 } 1256 }
1288 } 1257 }
1289 return fResourceDict; 1258
1259 if (fXObjectResources.count()) {
1260 for (int i = 0; i < fXObjectResources.count(); i++) {
1261 resourceDict->insertResourceAsReference(
1262 SkPDFResourceDict::kXObject_ResourceType,
1263 i, fXObjectResources[i]);
1264 }
1265 }
1266
1267 if (fFontResources.count()) {
1268 for (int i = 0; i < fFontResources.count(); i++) {
1269 resourceDict->insertResourceAsReference(
1270 SkPDFResourceDict::kFont_ResourceType,
1271 i, fFontResources[i]);
1272 }
1273 }
1274
1275 if (fShaderResources.count()) {
1276 SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict());
1277 for (int i = 0; i < fShaderResources.count(); i++) {
1278 resourceDict->insertResourceAsReference(
1279 SkPDFResourceDict::kPattern_ResourceType,
1280 i, fShaderResources[i]);
1281 }
1282 }
1283 return resourceDict.detach();
1290 } 1284 }
1291 1285
1292 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const { 1286 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const {
1293 return fFontResources; 1287 return fFontResources;
1294 } 1288 }
1295 1289
1296 SkPDFArray* SkPDFDevice::copyMediaBox() const { 1290 SkPDFArray* SkPDFDevice::copyMediaBox() const {
1297 // should this be a singleton? 1291 // should this be a singleton?
1298 SkAutoTUnref<SkPDFInt> zero(SkNEW_ARGS(SkPDFInt, (0))); 1292 SkAutoTUnref<SkPDFInt> zero(SkNEW_ARGS(SkPDFInt, (0)));
1299 1293
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 void SkPDFDevice::defineNamedDestination(SkData* nameData, const SkPoint& point, 1526 void SkPDFDevice::defineNamedDestination(SkData* nameData, const SkPoint& point,
1533 const SkMatrix& matrix) { 1527 const SkMatrix& matrix) {
1534 SkMatrix transform = matrix; 1528 SkMatrix transform = matrix;
1535 transform.postConcat(fInitialTransform); 1529 transform.postConcat(fInitialTransform);
1536 SkPoint translatedPoint; 1530 SkPoint translatedPoint;
1537 transform.mapXY(point.x(), point.y(), &translatedPoint); 1531 transform.mapXY(point.x(), point.y(), &translatedPoint);
1538 fNamedDestinations.push( 1532 fNamedDestinations.push(
1539 SkNEW_ARGS(NamedDestination, (nameData, translatedPoint))); 1533 SkNEW_ARGS(NamedDestination, (nameData, translatedPoint)));
1540 } 1534 }
1541 1535
1542 void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) { 1536 void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const {
1543 int nDest = fNamedDestinations.count(); 1537 int nDest = fNamedDestinations.count();
1544 for (int i = 0; i < nDest; i++) { 1538 for (int i = 0; i < nDest; i++) {
1545 NamedDestination* dest = fNamedDestinations[i]; 1539 NamedDestination* dest = fNamedDestinations[i];
1546 SkAutoTUnref<SkPDFArray> pdfDest(SkNEW(SkPDFArray)); 1540 SkAutoTUnref<SkPDFArray> pdfDest(SkNEW(SkPDFArray));
1547 pdfDest->reserve(5); 1541 pdfDest->reserve(5);
1548 pdfDest->append(SkNEW_ARGS(SkPDFObjRef, (page)))->unref(); 1542 pdfDest->append(SkNEW_ARGS(SkPDFObjRef, (page)))->unref();
1549 pdfDest->appendName("XYZ"); 1543 pdfDest->appendName("XYZ");
1550 pdfDest->appendScalar(dest->point.x()); 1544 pdfDest->appendScalar(dest->point.x());
1551 pdfDest->appendScalar(dest->point.y()); 1545 pdfDest->appendScalar(dest->point.y());
1552 pdfDest->appendInt(0); // Leave zoom unchanged 1546 pdfDest->appendInt(0); // Leave zoom unchanged
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 return; 2133 return;
2140 } 2134 }
2141 SkAutoTUnref<SkPDFObject> image(SkPDFBitmap::Create(fCanon, subsetBitmap)); 2135 SkAutoTUnref<SkPDFObject> image(SkPDFBitmap::Create(fCanon, subsetBitmap));
2142 if (!image) { 2136 if (!image) {
2143 return; 2137 return;
2144 } 2138 }
2145 2139
2146 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), 2140 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()),
2147 &content.entry()->fContent); 2141 &content.entry()->fContent);
2148 } 2142 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDevice.h ('k') | src/pdf/SkPDFDocument.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698