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

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

Issue 19523007: Revert "Adds SkPDFResourceDict class, refactor existing code to use it." (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « include/pdf/SkPDFDevice.h ('k') | src/pdf/SkPDFFormXObject.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"
11 #include "SkColor.h" 11 #include "SkColor.h"
12 #include "SkClipStack.h" 12 #include "SkClipStack.h"
13 #include "SkData.h" 13 #include "SkData.h"
14 #include "SkDraw.h" 14 #include "SkDraw.h"
15 #include "SkFontHost.h" 15 #include "SkFontHost.h"
16 #include "SkGlyphCache.h" 16 #include "SkGlyphCache.h"
17 #include "SkPaint.h" 17 #include "SkPaint.h"
18 #include "SkPath.h" 18 #include "SkPath.h"
19 #include "SkPDFFont.h" 19 #include "SkPDFFont.h"
20 #include "SkPDFFormXObject.h" 20 #include "SkPDFFormXObject.h"
21 #include "SkPDFGraphicState.h" 21 #include "SkPDFGraphicState.h"
22 #include "SkPDFImage.h" 22 #include "SkPDFImage.h"
23 #include "SkPDFResourceDict.h"
24 #include "SkPDFShader.h" 23 #include "SkPDFShader.h"
25 #include "SkPDFStream.h" 24 #include "SkPDFStream.h"
26 #include "SkPDFTypes.h" 25 #include "SkPDFTypes.h"
27 #include "SkPDFUtils.h" 26 #include "SkPDFUtils.h"
28 #include "SkRect.h" 27 #include "SkRect.h"
29 #include "SkString.h" 28 #include "SkString.h"
30 #include "SkTextFormatParams.h" 29 #include "SkTextFormatParams.h"
31 #include "SkTemplates.h" 30 #include "SkTemplates.h"
32 #include "SkTypefacePriv.h" 31 #include "SkTypefacePriv.h"
33 #include "SkTSet.h" 32 #include "SkTSet.h"
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 417
419 push(); 418 push();
420 SkPDFUtils::AppendTransform(matrix, fContentStream); 419 SkPDFUtils::AppendTransform(matrix, fContentStream);
421 currentEntry()->fMatrix = matrix; 420 currentEntry()->fMatrix = matrix;
422 } 421 }
423 422
424 void GraphicStackState::updateDrawingState(const GraphicStateEntry& state) { 423 void GraphicStackState::updateDrawingState(const GraphicStateEntry& state) {
425 // PDF treats a shader as a color, so we only set one or the other. 424 // PDF treats a shader as a color, so we only set one or the other.
426 if (state.fShaderIndex >= 0) { 425 if (state.fShaderIndex >= 0) {
427 if (state.fShaderIndex != currentEntry()->fShaderIndex) { 426 if (state.fShaderIndex != currentEntry()->fShaderIndex) {
428 SkString resourceName = SkPDFResourceDict::getResourceName( 427 fContentStream->writeText("/Pattern CS /Pattern cs /P");
429 SkPDFResourceDict::kPattern_ResourceType, 428 fContentStream->writeDecAsText(state.fShaderIndex);
430 state.fShaderIndex); 429 fContentStream->writeText(" SCN /P");
431 fContentStream->writeText("/Pattern CS /Pattern cs /"); 430 fContentStream->writeDecAsText(state.fShaderIndex);
432 fContentStream->writeText(resourceName.c_str());
433 fContentStream->writeText(" SCN /");
434 fContentStream->writeText(resourceName.c_str());
435 fContentStream->writeText(" scn\n"); 431 fContentStream->writeText(" scn\n");
436 currentEntry()->fShaderIndex = state.fShaderIndex; 432 currentEntry()->fShaderIndex = state.fShaderIndex;
437 } 433 }
438 } else { 434 } else {
439 if (state.fColor != currentEntry()->fColor || 435 if (state.fColor != currentEntry()->fColor ||
440 currentEntry()->fShaderIndex >= 0) { 436 currentEntry()->fShaderIndex >= 0) {
441 emit_pdf_color(state.fColor, fContentStream); 437 emit_pdf_color(state.fColor, fContentStream);
442 fContentStream->writeText("RG "); 438 fContentStream->writeText("RG ");
443 emit_pdf_color(state.fColor, fContentStream); 439 emit_pdf_color(state.fColor, fContentStream);
444 fContentStream->writeText("rg\n"); 440 fContentStream->writeText("rg\n");
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 fLastMarginContentEntry = contentEntry; 1116 fLastMarginContentEntry = contentEntry;
1121 } 1117 }
1122 } 1118 }
1123 1119
1124 void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) { 1120 void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) {
1125 // A ScopedContentEntry only exists during the course of a draw call, so 1121 // A ScopedContentEntry only exists during the course of a draw call, so
1126 // this can't be called while a ScopedContentEntry exists. 1122 // this can't be called while a ScopedContentEntry exists.
1127 fDrawingArea = drawingArea; 1123 fDrawingArea = drawingArea;
1128 } 1124 }
1129 1125
1130 SkPDFResourceDict* SkPDFDevice::getResourceDict() { 1126 SkPDFDict* SkPDFDevice::getResourceDict() {
1131 if (NULL == fResourceDict) { 1127 if (NULL == fResourceDict) {
1132 fResourceDict = SkNEW(SkPDFResourceDict); 1128 fResourceDict = SkNEW(SkPDFDict);
1133 1129
1134 if (fGraphicStateResources.count()) { 1130 if (fGraphicStateResources.count()) {
1131 SkAutoTUnref<SkPDFDict> extGState(new SkPDFDict());
1135 for (int i = 0; i < fGraphicStateResources.count(); i++) { 1132 for (int i = 0; i < fGraphicStateResources.count(); i++) {
1136 fResourceDict->insertResourceAsRef( 1133 SkString nameString("G");
1137 SkPDFResourceDict::kExtGState_ResourceType, 1134 nameString.appendS32(i);
1138 i, fGraphicStateResources[i]); 1135 extGState->insert(
1136 nameString.c_str(),
1137 new SkPDFObjRef(fGraphicStateResources[i]))->unref();
1139 } 1138 }
1139 fResourceDict->insert("ExtGState", extGState.get());
1140 } 1140 }
1141 1141
1142 if (fXObjectResources.count()) { 1142 if (fXObjectResources.count()) {
1143 SkAutoTUnref<SkPDFDict> xObjects(new SkPDFDict());
1143 for (int i = 0; i < fXObjectResources.count(); i++) { 1144 for (int i = 0; i < fXObjectResources.count(); i++) {
1144 fResourceDict->insertResourceAsRef( 1145 SkString nameString("X");
1145 SkPDFResourceDict::kXObject_ResourceType, 1146 nameString.appendS32(i);
1146 i, fXObjectResources[i]); 1147 xObjects->insert(
1148 nameString.c_str(),
1149 new SkPDFObjRef(fXObjectResources[i]))->unref();
1147 } 1150 }
1151 fResourceDict->insert("XObject", xObjects.get());
1148 } 1152 }
1149 1153
1150 if (fFontResources.count()) { 1154 if (fFontResources.count()) {
1155 SkAutoTUnref<SkPDFDict> fonts(new SkPDFDict());
1151 for (int i = 0; i < fFontResources.count(); i++) { 1156 for (int i = 0; i < fFontResources.count(); i++) {
1152 fResourceDict->insertResourceAsRef( 1157 SkString nameString("F");
1153 SkPDFResourceDict::kFont_ResourceType, 1158 nameString.appendS32(i);
1154 i, fFontResources[i]); 1159 fonts->insert(nameString.c_str(),
1160 new SkPDFObjRef(fFontResources[i]))->unref();
1155 } 1161 }
1162 fResourceDict->insert("Font", fonts.get());
1156 } 1163 }
1157 1164
1158 if (fShaderResources.count()) { 1165 if (fShaderResources.count()) {
1159 SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict()); 1166 SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict());
1160 for (int i = 0; i < fShaderResources.count(); i++) { 1167 for (int i = 0; i < fShaderResources.count(); i++) {
1161 fResourceDict->insertResourceAsRef( 1168 SkString nameString("P");
1162 SkPDFResourceDict::kPattern_ResourceType, 1169 nameString.appendS32(i);
1163 i, fShaderResources[i]); 1170 patterns->insert(nameString.c_str(),
1171 new SkPDFObjRef(fShaderResources[i]))->unref();
1172 }
1173 fResourceDict->insert("Pattern", patterns.get());
1174 }
1175
1176 // For compatibility, add all proc sets (only used for output to PS
1177 // devices).
1178 const char procs[][7] = {"PDF", "Text", "ImageB", "ImageC", "ImageI"};
1179 SkAutoTUnref<SkPDFArray> procSets(new SkPDFArray());
1180 procSets->reserve(SK_ARRAY_COUNT(procs));
1181 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); i++)
1182 procSets->appendName(procs[i]);
1183 fResourceDict->insert("ProcSet", procSets.get());
1184 }
1185 return fResourceDict;
1186 }
1187
1188 void SkPDFDevice::getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
1189 SkTSet<SkPDFObject*>* newResourceObjects,
1190 bool recursive) const {
1191 // TODO: reserve not correct if we need to recursively explore.
1192 newResourceObjects->setReserve(newResourceObjects->count() +
1193 fGraphicStateResources.count() +
1194 fXObjectResources.count() +
1195 fFontResources.count() +
1196 fShaderResources.count());
1197 for (int i = 0; i < fGraphicStateResources.count(); i++) {
1198 if (!knownResourceObjects.contains(fGraphicStateResources[i]) &&
1199 !newResourceObjects->contains(fGraphicStateResources[i])) {
1200 newResourceObjects->add(fGraphicStateResources[i]);
1201 fGraphicStateResources[i]->ref();
1202 if (recursive) {
1203 fGraphicStateResources[i]->getResources(knownResourceObjects,
1204 newResourceObjects);
1164 } 1205 }
1165 } 1206 }
1166 } 1207 }
1167 return fResourceDict; 1208 for (int i = 0; i < fXObjectResources.count(); i++) {
1209 if (!knownResourceObjects.contains(fXObjectResources[i]) &&
1210 !newResourceObjects->contains(fXObjectResources[i])) {
1211 newResourceObjects->add(fXObjectResources[i]);
1212 fXObjectResources[i]->ref();
1213 if (recursive) {
1214 fXObjectResources[i]->getResources(knownResourceObjects,
1215 newResourceObjects);
1216 }
1217 }
1218 }
1219 for (int i = 0; i < fFontResources.count(); i++) {
1220 if (!knownResourceObjects.contains(fFontResources[i]) &&
1221 !newResourceObjects->contains(fFontResources[i])) {
1222 newResourceObjects->add(fFontResources[i]);
1223 fFontResources[i]->ref();
1224 if (recursive) {
1225 fFontResources[i]->getResources(knownResourceObjects,
1226 newResourceObjects);
1227 }
1228 }
1229 }
1230 for (int i = 0; i < fShaderResources.count(); i++) {
1231 if (!knownResourceObjects.contains(fShaderResources[i]) &&
1232 !newResourceObjects->contains(fShaderResources[i])) {
1233 newResourceObjects->add(fShaderResources[i]);
1234 fShaderResources[i]->ref();
1235 if (recursive) {
1236 fShaderResources[i]->getResources(knownResourceObjects,
1237 newResourceObjects);
1238 }
1239 }
1240 }
1168 } 1241 }
1169 1242
1170 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const { 1243 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const {
1171 return fFontResources; 1244 return fFontResources;
1172 } 1245 }
1173 1246
1174 SkPDFArray* SkPDFDevice::copyMediaBox() const { 1247 SkPDFArray* SkPDFDevice::copyMediaBox() const {
1175 // should this be a singleton? 1248 // should this be a singleton?
1176 SkAutoTUnref<SkPDFInt> zero(SkNEW_ARGS(SkPDFInt, (0))); 1249 SkAutoTUnref<SkPDFInt> zero(SkNEW_ARGS(SkPDFInt, (0)));
1177 1250
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 return result; 1764 return result;
1692 } 1765 }
1693 1766
1694 void SkPDFDevice::updateFont(const SkPaint& paint, uint16_t glyphID, 1767 void SkPDFDevice::updateFont(const SkPaint& paint, uint16_t glyphID,
1695 ContentEntry* contentEntry) { 1768 ContentEntry* contentEntry) {
1696 SkTypeface* typeface = paint.getTypeface(); 1769 SkTypeface* typeface = paint.getTypeface();
1697 if (contentEntry->fState.fFont == NULL || 1770 if (contentEntry->fState.fFont == NULL ||
1698 contentEntry->fState.fTextSize != paint.getTextSize() || 1771 contentEntry->fState.fTextSize != paint.getTextSize() ||
1699 !contentEntry->fState.fFont->hasGlyph(glyphID)) { 1772 !contentEntry->fState.fFont->hasGlyph(glyphID)) {
1700 int fontIndex = getFontResourceIndex(typeface, glyphID); 1773 int fontIndex = getFontResourceIndex(typeface, glyphID);
1701 contentEntry->fContent.writeText("/"); 1774 contentEntry->fContent.writeText("/F");
1702 contentEntry->fContent.writeText(SkPDFResourceDict::getResourceName( 1775 contentEntry->fContent.writeDecAsText(fontIndex);
1703 SkPDFResourceDict::kFont_ResourceType,
1704 fontIndex).c_str());
1705 contentEntry->fContent.writeText(" "); 1776 contentEntry->fContent.writeText(" ");
1706 SkPDFScalar::Append(paint.getTextSize(), &contentEntry->fContent); 1777 SkPDFScalar::Append(paint.getTextSize(), &contentEntry->fContent);
1707 contentEntry->fContent.writeText(" Tf\n"); 1778 contentEntry->fContent.writeText(" Tf\n");
1708 contentEntry->fState.fFont = fFontResources[fontIndex]; 1779 contentEntry->fState.fFont = fFontResources[fontIndex];
1709 } 1780 }
1710 } 1781 }
1711 1782
1712 int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) { 1783 int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) {
1713 SkAutoTUnref<SkPDFFont> newFont(SkPDFFont::GetFontResource(typeface, glyphID )); 1784 SkAutoTUnref<SkPDFFont> newFont(SkPDFFont::GetFontResource(typeface, glyphID ));
1714 int resourceIndex = fFontResources.find(newFont.get()); 1785 int resourceIndex = fFontResources.find(newFont.get());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 } 1826 }
1756 1827
1757 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, 1828 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y,
1758 SkCanvas::Config8888) { 1829 SkCanvas::Config8888) {
1759 return false; 1830 return false;
1760 } 1831 }
1761 1832
1762 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { 1833 bool SkPDFDevice::allowImageFilter(SkImageFilter*) {
1763 return false; 1834 return false;
1764 } 1835 }
OLDNEW
« no previous file with comments | « include/pdf/SkPDFDevice.h ('k') | src/pdf/SkPDFFormXObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698