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

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

Issue 18977002: Add SkPDFResourceDict class, refactor existing code (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
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"
23 #include "SkPDFShader.h" 24 #include "SkPDFShader.h"
24 #include "SkPDFStream.h" 25 #include "SkPDFStream.h"
25 #include "SkPDFTypes.h" 26 #include "SkPDFTypes.h"
26 #include "SkPDFUtils.h" 27 #include "SkPDFUtils.h"
27 #include "SkRect.h" 28 #include "SkRect.h"
28 #include "SkString.h" 29 #include "SkString.h"
29 #include "SkTextFormatParams.h" 30 #include "SkTextFormatParams.h"
30 #include "SkTemplates.h" 31 #include "SkTemplates.h"
31 #include "SkTypefacePriv.h" 32 #include "SkTypefacePriv.h"
32 #include "SkTSet.h" 33 #include "SkTSet.h"
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 fLastMarginContentEntry = contentEntry; 1128 fLastMarginContentEntry = contentEntry;
1128 } 1129 }
1129 } 1130 }
1130 1131
1131 void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) { 1132 void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) {
1132 // A ScopedContentEntry only exists during the course of a draw call, so 1133 // A ScopedContentEntry only exists during the course of a draw call, so
1133 // this can't be called while a ScopedContentEntry exists. 1134 // this can't be called while a ScopedContentEntry exists.
1134 fDrawingArea = drawingArea; 1135 fDrawingArea = drawingArea;
1135 } 1136 }
1136 1137
1137 SkPDFDict* SkPDFDevice::getResourceDict() { 1138 SkPDFResourceDict* SkPDFDevice::getResourceDict() {
1138 if (NULL == fResourceDict) { 1139 if (NULL == fResourceDict) {
1139 fResourceDict = SkNEW(SkPDFDict); 1140 fResourceDict = SkNEW_ARGS(SkPDFResourceDict, (true));
1140 1141
1141 if (fGraphicStateResources.count()) { 1142 if (fGraphicStateResources.count()) {
1142 SkAutoTUnref<SkPDFDict> extGState(new SkPDFDict());
1143 for (int i = 0; i < fGraphicStateResources.count(); i++) { 1143 for (int i = 0; i < fGraphicStateResources.count(); i++) {
1144 SkString nameString("G"); 1144 fResourceDict->insertResourceAsRef(
1145 nameString.appendS32(i); 1145 SkPDFResourceDict::kExtGState_ResourceType,
1146 extGState->insert( 1146 i, fGraphicStateResources[i]);
1147 nameString.c_str(),
1148 new SkPDFObjRef(fGraphicStateResources[i]))->unref();
1149 } 1147 }
1150 fResourceDict->insert("ExtGState", extGState.get());
1151 } 1148 }
1152 1149
1153 if (fXObjectResources.count()) { 1150 if (fXObjectResources.count()) {
1154 SkAutoTUnref<SkPDFDict> xObjects(new SkPDFDict());
1155 for (int i = 0; i < fXObjectResources.count(); i++) { 1151 for (int i = 0; i < fXObjectResources.count(); i++) {
1156 SkString nameString("X"); 1152 fResourceDict->insertResourceAsRef(
1157 nameString.appendS32(i); 1153 SkPDFResourceDict::kXObject_ResourceType,
1158 xObjects->insert( 1154 i, fXObjectResources[i]);
1159 nameString.c_str(),
1160 new SkPDFObjRef(fXObjectResources[i]))->unref();
1161 } 1155 }
1162 fResourceDict->insert("XObject", xObjects.get());
1163 } 1156 }
1164 1157
1165 if (fFontResources.count()) { 1158 if (fFontResources.count()) {
1166 SkAutoTUnref<SkPDFDict> fonts(new SkPDFDict());
1167 for (int i = 0; i < fFontResources.count(); i++) { 1159 for (int i = 0; i < fFontResources.count(); i++) {
1168 SkString nameString("F"); 1160 fResourceDict->insertResourceAsRef(
1169 nameString.appendS32(i); 1161 SkPDFResourceDict::kFont_ResourceType,
1170 fonts->insert(nameString.c_str(), 1162 i, fFontResources[i]);
1171 new SkPDFObjRef(fFontResources[i]))->unref();
1172 } 1163 }
1173 fResourceDict->insert("Font", fonts.get());
1174 } 1164 }
1175 1165
1176 if (fShaderResources.count()) { 1166 if (fShaderResources.count()) {
1177 SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict()); 1167 SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict());
1178 for (int i = 0; i < fShaderResources.count(); i++) { 1168 for (int i = 0; i < fShaderResources.count(); i++) {
1179 SkString nameString("P"); 1169 fResourceDict->insertResourceAsRef(
1180 nameString.appendS32(i); 1170 SkPDFResourceDict::kPattern_ResourceType,
1181 patterns->insert(nameString.c_str(), 1171 i, fShaderResources[i]);
1182 new SkPDFObjRef(fShaderResources[i]))->unref();
1183 }
1184 fResourceDict->insert("Pattern", patterns.get());
1185 }
1186
1187 // For compatibility, add all proc sets (only used for output to PS
1188 // devices).
1189 const char procs[][7] = {"PDF", "Text", "ImageB", "ImageC", "ImageI"};
1190 SkAutoTUnref<SkPDFArray> procSets(new SkPDFArray());
1191 procSets->reserve(SK_ARRAY_COUNT(procs));
1192 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); i++)
1193 procSets->appendName(procs[i]);
1194 fResourceDict->insert("ProcSet", procSets.get());
1195 }
1196 return fResourceDict;
1197 }
1198
1199 void SkPDFDevice::getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
1200 SkTSet<SkPDFObject*>* newResourceObjects,
1201 bool recursive) const {
1202 // TODO: reserve not correct if we need to recursively explore.
1203 newResourceObjects->setReserve(newResourceObjects->count() +
1204 fGraphicStateResources.count() +
1205 fXObjectResources.count() +
1206 fFontResources.count() +
1207 fShaderResources.count());
1208 for (int i = 0; i < fGraphicStateResources.count(); i++) {
1209 if (!knownResourceObjects.contains(fGraphicStateResources[i]) &&
1210 !newResourceObjects->contains(fGraphicStateResources[i])) {
1211 newResourceObjects->add(fGraphicStateResources[i]);
1212 fGraphicStateResources[i]->ref();
1213 if (recursive) {
1214 fGraphicStateResources[i]->getResources(knownResourceObjects,
1215 newResourceObjects);
1216 } 1172 }
1217 } 1173 }
1218 } 1174 }
1219 for (int i = 0; i < fXObjectResources.count(); i++) { 1175 return fResourceDict;
1220 if (!knownResourceObjects.contains(fXObjectResources[i]) &&
1221 !newResourceObjects->contains(fXObjectResources[i])) {
1222 newResourceObjects->add(fXObjectResources[i]);
1223 fXObjectResources[i]->ref();
1224 if (recursive) {
1225 fXObjectResources[i]->getResources(knownResourceObjects,
1226 newResourceObjects);
1227 }
1228 }
1229 }
1230 for (int i = 0; i < fFontResources.count(); i++) {
1231 if (!knownResourceObjects.contains(fFontResources[i]) &&
1232 !newResourceObjects->contains(fFontResources[i])) {
1233 newResourceObjects->add(fFontResources[i]);
1234 fFontResources[i]->ref();
1235 if (recursive) {
1236 fFontResources[i]->getResources(knownResourceObjects,
1237 newResourceObjects);
1238 }
1239 }
1240 }
1241 for (int i = 0; i < fShaderResources.count(); i++) {
1242 if (!knownResourceObjects.contains(fShaderResources[i]) &&
1243 !newResourceObjects->contains(fShaderResources[i])) {
1244 newResourceObjects->add(fShaderResources[i]);
1245 fShaderResources[i]->ref();
1246 if (recursive) {
1247 fShaderResources[i]->getResources(knownResourceObjects,
1248 newResourceObjects);
1249 }
1250 }
1251 }
1252 } 1176 }
1253 1177
1254 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const { 1178 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const {
1255 return fFontResources; 1179 return fFontResources;
1256 } 1180 }
1257 1181
1258 SkPDFArray* SkPDFDevice::copyMediaBox() const { 1182 SkPDFArray* SkPDFDevice::copyMediaBox() const {
1259 // should this be a singleton? 1183 // should this be a singleton?
1260 SkAutoTUnref<SkPDFInt> zero(SkNEW_ARGS(SkPDFInt, (0))); 1184 SkAutoTUnref<SkPDFInt> zero(SkNEW_ARGS(SkPDFInt, (0)));
1261 1185
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 } 1761 }
1838 1762
1839 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, 1763 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y,
1840 SkCanvas::Config8888) { 1764 SkCanvas::Config8888) {
1841 return false; 1765 return false;
1842 } 1766 }
1843 1767
1844 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { 1768 bool SkPDFDevice::allowImageFilter(SkImageFilter*) {
1845 return false; 1769 return false;
1846 } 1770 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698