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

Side by Side Diff: experimental/PdfViewer/pdf_viewer_main.cpp

Issue 17286007: few steps in the direction of to encapsulating podofo, so the client is not aware podofo is used. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 6 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 | « experimental/PdfViewer/pdf_auto_gen.h ('k') | experimental/PdfViewer/pdfspec_autogen.py » ('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 2013 Google Inc. 2 * Copyright 2013 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkGraphics.h" 10 #include "SkGraphics.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 const char* abr, 54 const char* abr,
55 std::string* data); 55 std::string* data);
56 56
57 class SkPdfDictionary; 57 class SkPdfDictionary;
58 bool DictionaryFromDictionary(const PdfMemDocument* pdfDoc, 58 bool DictionaryFromDictionary(const PdfMemDocument* pdfDoc,
59 const PdfDictionary& dict, 59 const PdfDictionary& dict,
60 const char* key, 60 const char* key,
61 const char* abr, 61 const char* abr,
62 SkPdfDictionary** data); 62 SkPdfDictionary** data);
63 63
64 template <typename T>
65 bool DictionaryFromDictionary2(const PdfMemDocument* pdfDoc,
66 const PdfDictionary& dict,
67 const char* key,
68 const char* abr,
69 T** data);
70
64 class SkPdfObject; 71 class SkPdfObject;
65 bool ObjectFromDictionary(const PdfMemDocument* pdfDoc, 72 bool ObjectFromDictionary(const PdfMemDocument* pdfDoc,
66 const PdfDictionary& dict, 73 const PdfDictionary& dict,
67 const char* key, 74 const char* key,
68 const char* abr, 75 const char* abr,
69 SkPdfObject** data); 76 SkPdfObject** data);
70 77
71 78
72 #include "pdf_auto_gen.h" 79 #include "pdf_auto_gen.h"
73 80
74 /* 81 /*
75 * TODO(edisonn): ASAP so skp -> pdf -> png looks greap 82 * TODO(edisonn):
76 * - load gs/ especially smask and already known prop 83 * - encapsulate podofo in the pdf api so the skpdf does not know anything about podofo
77 * - use transparency (I think ca and CA ops) 84 * - ASAP so skp -> pdf -> png looks great
85 * - load gs/ especially smask and already known prop (skp)
86 * - use transparency (I think ca and CA ops) (skp)
87 * - all font types
88 * - word spacing
78 * - load font for baidu.pdf 89 * - load font for baidu.pdf
79 * - load font for youtube.pdf 90 * - load font for youtube.pdf
80 */ 91 */
81 92
82 //#define PDF_TRACE 93 //#define PDF_TRACE
83 //#define PDF_TRACE_DIFF_IN_PNG 94 //#define PDF_TRACE_DIFF_IN_PNG
84 //#define PDF_DEBUG_NO_CLIPING 95 //#define PDF_DEBUG_NO_CLIPING
85 //#define PDF_DEBUG_NO_PAGE_CLIPING 96 //#define PDF_DEBUG_NO_PAGE_CLIPING
86 //#define PDF_DEBUG_3X 97 //#define PDF_DEBUG_3X
87 98
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 SkPath fClipPath; 204 SkPath fClipPath;
194 205
195 PdfColorOperator fStroking; 206 PdfColorOperator fStroking;
196 PdfColorOperator fNonStroking; 207 PdfColorOperator fNonStroking;
197 208
198 double fLineWidth; 209 double fLineWidth;
199 double fTextLeading; 210 double fTextLeading;
200 double fWordSpace; 211 double fWordSpace;
201 double fCharSpace; 212 double fCharSpace;
202 213
203 const PdfObject* fObjectWithResources; 214 SkPdfResourceDictionary fResources;
204 215
205 SkBitmap fSMask; 216 SkBitmap fSMask;
206 217
207 PdfGraphicsState() { 218 PdfGraphicsState() {
208 fCurPosX = 0.0; 219 fCurPosX = 0.0;
209 fCurPosY = 0.0; 220 fCurPosY = 0.0;
210 fCurFontSize = 0.0; 221 fCurFontSize = 0.0;
211 fTextBlock = false; 222 fTextBlock = false;
212 fCurFont = NULL; 223 fCurFont = NULL;
213 fMatrix = SkMatrix::I(); 224 fMatrix = SkMatrix::I();
214 fMatrixTm = SkMatrix::I(); 225 fMatrixTm = SkMatrix::I();
215 fMatrixTlm = SkMatrix::I(); 226 fMatrixTlm = SkMatrix::I();
216 fPathClosed = true; 227 fPathClosed = true;
217 fLineWidth = 0; 228 fLineWidth = 0;
218 fTextLeading = 0; 229 fTextLeading = 0;
219 fWordSpace = 0; 230 fWordSpace = 0;
220 fCharSpace = 0; 231 fCharSpace = 0;
221 fObjectWithResources = NULL;
222 fHasClipPathToApply = false; 232 fHasClipPathToApply = false;
223 } 233 }
224 }; 234 };
225 235
226 // TODO(edisonn): better class design. 236 // TODO(edisonn): better class design.
227 struct PdfInlineImage { 237 struct PdfInlineImage {
228 std::map<std::string, std::string> fKeyValuePairs; 238 std::map<std::string, std::string> fKeyValuePairs;
229 std::string fImageData; 239 std::string fImageData;
230 240
231 }; 241 };
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 const PdfDictionary& dict, 916 const PdfDictionary& dict,
907 const char* key, 917 const char* key,
908 SkPdfDictionary** data) { 918 SkPdfDictionary** data) {
909 const PdfObject* value = resolveReferenceObject(pdfDoc, 919 const PdfObject* value = resolveReferenceObject(pdfDoc,
910 dict.GetKey(PdfName(key)), 920 dict.GetKey(PdfName(key)),
911 true); 921 true);
912 if (value == NULL || !value->IsDictionary()) { 922 if (value == NULL || !value->IsDictionary()) {
913 return false; 923 return false;
914 } 924 }
915 925
916 return PodofoMapper::mapDictionary(*pdfDoc, *value, (SkPdfObject**)data); 926 return PodofoMapper::map(*pdfDoc, *value, (SkPdfObject**)data);
917 } 927 }
918 928
919 bool DictionaryFromDictionary(const PdfMemDocument* pdfDoc, 929 bool DictionaryFromDictionary(const PdfMemDocument* pdfDoc,
920 const PdfDictionary& dict, 930 const PdfDictionary& dict,
921 const char* key, 931 const char* key,
922 const char* abr, 932 const char* abr,
923 SkPdfDictionary** data) { 933 SkPdfDictionary** data) {
924 if (DictionaryFromDictionary(pdfDoc, dict, key, data)) return true; 934 if (DictionaryFromDictionary(pdfDoc, dict, key, data)) return true;
925 if (abr == NULL || *abr == '\0') return false; 935 if (abr == NULL || *abr == '\0') return false;
926 return DictionaryFromDictionary(pdfDoc, dict, abr, data); 936 return DictionaryFromDictionary(pdfDoc, dict, abr, data);
927 } 937 }
928 938
939 template <typename T>
940 bool DictionaryFromDictionary2(const PdfMemDocument* pdfDoc,
941 const PdfDictionary& dict,
942 const char* key,
943 SkPdfDictionary** data) {
944 const PdfObject* value = resolveReferenceObject(pdfDoc,
945 dict.GetKey(PdfName(key)),
946 true);
947 if (value == NULL || !value->IsDictionary()) {
948 return false;
949 }
950
951 return PodofoMapper::map(*pdfDoc, *value, (T**)data);
952 }
953
954 template <typename T>
955 bool DictionaryFromDictionary2(const PdfMemDocument* pdfDoc,
956 const PdfDictionary& dict,
957 const char* key,
958 const char* abr,
959 T** data) {
960 if (DictionaryFromDictionary2<T>(pdfDoc, dict, key, data)) return true;
961 if (abr == NULL || *abr == '\0') return false;
962 return DictionaryFromDictionary2<T>(pdfDoc, dict, abr, data);
963 }
964
929 bool ObjectFromDictionary(const PdfMemDocument* pdfDoc, 965 bool ObjectFromDictionary(const PdfMemDocument* pdfDoc,
930 const PdfDictionary& dict, 966 const PdfDictionary& dict,
931 const char* key, 967 const char* key,
932 SkPdfObject** data) { 968 SkPdfObject** data) {
933 const PdfObject* value = resolveReferenceObject(pdfDoc, 969 const PdfObject* value = resolveReferenceObject(pdfDoc,
934 dict.GetKey(PdfName(key)), 970 dict.GetKey(PdfName(key)),
935 true); 971 true);
936 if (value == NULL) { 972 if (value == NULL) {
937 return false; 973 return false;
938 } 974 }
939 return PodofoMapper::mapObject(*pdfDoc, *value, data); 975 return PodofoMapper::map(*pdfDoc, *value, data);
940 } 976 }
941 977
942 bool ObjectFromDictionary(const PdfMemDocument* pdfDoc, 978 bool ObjectFromDictionary(const PdfMemDocument* pdfDoc,
943 const PdfDictionary& dict, 979 const PdfDictionary& dict,
944 const char* key, 980 const char* key,
945 const char* abr, 981 const char* abr,
946 SkPdfObject** data) { 982 SkPdfObject** data) {
947 if (ObjectFromDictionary(pdfDoc, dict, key, data)) return true; 983 if (ObjectFromDictionary(pdfDoc, dict, key, data)) return true;
948 if (abr == NULL || *abr == '\0') return false; 984 if (abr == NULL || *abr == '\0') return false;
949 return ObjectFromDictionary(pdfDoc, dict, abr, data); 985 return ObjectFromDictionary(pdfDoc, dict, abr, data);
950 } 986 }
951 987
952 988
989
953 // TODO(edisonn): perf!!! 990 // TODO(edisonn): perf!!!
954 991
955 static SkColorTable* getGrayColortable() { 992 static SkColorTable* getGrayColortable() {
956 static SkColorTable* grayColortable = NULL; 993 static SkColorTable* grayColortable = NULL;
957 if (grayColortable == NULL) { 994 if (grayColortable == NULL) {
958 SkPMColor* colors = new SkPMColor[256]; 995 SkPMColor* colors = new SkPMColor[256];
959 for (int i = 0 ; i < 256; i++) { 996 for (int i = 0 ; i < 256; i++) {
960 colors[i] = SkPreMultiplyARGB(255, i, i, i); 997 colors[i] = SkPreMultiplyARGB(255, i, i, i);
961 } 998 }
962 grayColortable = new SkColorTable(colors, 256); 999 grayColortable = new SkColorTable(colors, 256);
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 array[i] = elem->GetReal(); 1287 array[i] = elem->GetReal();
1251 } 1288 }
1252 1289
1253 *rect = SkRect::MakeLTRB(SkDoubleToScalar(array[0]), 1290 *rect = SkRect::MakeLTRB(SkDoubleToScalar(array[0]),
1254 SkDoubleToScalar(array[1]), 1291 SkDoubleToScalar(array[1]),
1255 SkDoubleToScalar(array[2]), 1292 SkDoubleToScalar(array[2]),
1256 SkDoubleToScalar(array[3])); 1293 SkDoubleToScalar(array[3]));
1257 return true; 1294 return true;
1258 } 1295 }
1259 1296
1260 PdfResult doXObject_Form(PdfContext* pdfContext, SkCanvas* canvas, const PdfObje ct& obj) { 1297 SkPdfObject* get(const SkPdfObject* obj, const char* key, const char* abr = "") {
1261 if (!obj.HasStream() || obj.GetStream() == NULL || obj.GetStream()->GetLengt h() == 0) { 1298 SkPdfObject* ret = NULL;
1299 if (obj == NULL) return NULL;
1300 const SkPdfDictionary* dict = obj->asDictionary();
1301 if (dict == NULL) return NULL;
1302 if (!dict->podofo()->IsDictionary()) return NULL;
1303 ObjectFromDictionary(dict->doc(), dict->podofo()->GetDictionary(), key, abr, &ret);
1304 return ret;
1305 }
1306
1307 PdfResult doXObject_Form(PdfContext* pdfContext, SkCanvas* canvas, SkPdfType1For mDictionary* skobj) {
1308 if (!skobj || !skobj->podofo() || !skobj->podofo()->HasStream() || skobj->po dofo()->GetStream() == NULL || skobj->podofo()->GetStream()->GetLength() == 0) {
1262 return kOK_PdfResult; 1309 return kOK_PdfResult;
1263 } 1310 }
1264 1311
1265 PdfOp_q(pdfContext, canvas, NULL); 1312 PdfOp_q(pdfContext, canvas, NULL);
1266 canvas->save(); 1313 canvas->save();
1267 1314
1268 pdfContext->fGraphicsState.fObjectWithResources = &obj; 1315 if (get(skobj, "Resources")) {
1316 SkPdfResourceDictionary* res = NULL;
1317
1318 PodofoMapper::map(*get(skobj, "Resources"), &res);
1319
1320 if (res) {
1321 pdfContext->fGraphicsState.fResources = *res;
1322 delete res;
1323 }
1324 }
1269 1325
1270 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix, "Current matrix"); 1326 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix, "Current matrix");
1271 1327
1272 SkMatrix matrix; 1328 SkMatrix matrix;
1273 if (SkMatrixFromDictionary(pdfContext, obj.GetDictionary(), "Matrix", &matri x)) { 1329 if (SkMatrixFromDictionary(pdfContext, skobj->podofo()->GetDictionary(), "Ma trix", &matrix)) {
1274 pdfContext->fGraphicsState.fMatrix.preConcat(matrix); 1330 pdfContext->fGraphicsState.fMatrix.preConcat(matrix);
1275 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fMatri x; 1331 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fMatri x;
1276 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatr ix; 1332 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatr ix;
1277 // TODO(edisonn) reset matrixTm and matricTlm also? 1333 // TODO(edisonn) reset matrixTm and matricTlm also?
1278 } 1334 }
1279 1335
1280 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix, "Total matrix"); 1336 SkTraceMatrix(pdfContext->fGraphicsState.fMatrix, "Total matrix");
1281 1337
1282 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix); 1338 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix);
1283 1339
1284 SkRect bbox; 1340 SkRect bbox;
1285 if (SkRectFromDictionary(pdfContext, obj.GetDictionary(), "BBox", &bbox)) { 1341 if (SkRectFromDictionary(pdfContext, skobj->podofo()->GetDictionary(), "BBox ", &bbox)) {
1286 canvas->clipRect(bbox, SkRegion::kIntersect_Op, true); // TODO(edisonn) : AA from settings. 1342 canvas->clipRect(bbox, SkRegion::kIntersect_Op, true); // TODO(edisonn) : AA from settings.
1287 } 1343 }
1288 1344
1289 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke nize it as we go. 1345 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke nize it as we go.
1290 // For this PdfContentsTokenizer needs to be extended. 1346 // For this PdfContentsTokenizer needs to be extended.
1291 1347
1292 char* uncompressedStream = NULL; 1348 char* uncompressedStream = NULL;
1293 pdf_long uncompressedStreamLength = 0; 1349 pdf_long uncompressedStreamLength = 0;
1294 1350
1295 PdfResult ret = kPartial_PdfResult; 1351 PdfResult ret = kPartial_PdfResult;
1296 1352
1297 // TODO(edisonn): get rid of try/catch exceptions! We should not throw on us er data! 1353 // TODO(edisonn): get rid of try/catch exceptions! We should not throw on us er data!
1298 try { 1354 try {
1299 obj.GetStream()->GetFilteredCopy(&uncompressedStream, &uncompressedStrea mLength); 1355 skobj->podofo()->GetStream()->GetFilteredCopy(&uncompressedStream, &unco mpressedStreamLength);
1300 if (uncompressedStream != NULL && uncompressedStreamLength != 0) { 1356 if (uncompressedStream != NULL && uncompressedStreamLength != 0) {
1301 PdfContentsTokenizer tokenizer(uncompressedStream, uncompressedStrea mLength); 1357 PdfContentsTokenizer tokenizer(uncompressedStream, uncompressedStrea mLength);
1302 PdfMainLooper looper(NULL, &tokenizer, pdfContext, canvas); 1358 PdfMainLooper looper(NULL, &tokenizer, pdfContext, canvas);
1303 looper.loop(); 1359 looper.loop();
1304 } 1360 }
1305 free(uncompressedStream); 1361 free(uncompressedStream);
1306 } catch (PdfError& e) { 1362 } catch (PdfError& e) {
1307 ret = kIgnoreError_PdfResult; 1363 ret = kIgnoreError_PdfResult;
1308 } 1364 }
1309 1365
(...skipping 30 matching lines...) Expand all
1340 1396
1341 PdfResult doXObject(PdfContext* pdfContext, SkCanvas* canvas, const PdfObject& o bj) { 1397 PdfResult doXObject(PdfContext* pdfContext, SkCanvas* canvas, const PdfObject& o bj) {
1342 if (CheckRecursiveRendering::IsInRendering(obj)) { 1398 if (CheckRecursiveRendering::IsInRendering(obj)) {
1343 // Oops, corrupt PDF! 1399 // Oops, corrupt PDF!
1344 return kIgnoreError_PdfResult; 1400 return kIgnoreError_PdfResult;
1345 } 1401 }
1346 1402
1347 CheckRecursiveRendering checkRecursion(obj); 1403 CheckRecursiveRendering checkRecursion(obj);
1348 1404
1349 // TODO(edisonn): check type 1405 // TODO(edisonn): check type
1350 SkPdfObject* skobj = NULL; 1406 SkPdfXObjectDictionary* skobj = NULL;
1351 if (!PodofoMapper::mapXObjectDictionary(*pdfContext->fPdfDoc, obj, &skobj)) return kIgnoreError_PdfResult; 1407 if (!PodofoMapper::map(*pdfContext->fPdfDoc, obj, &skobj)) return kIgnoreErr or_PdfResult;
1352 1408
1353 if (!skobj || !skobj->valid()) return kIgnoreError_PdfResult; 1409 if (!skobj || !skobj->valid()) return kIgnoreError_PdfResult;
1354 1410
1355 PdfResult ret = kIgnoreError_PdfResult; 1411 PdfResult ret = kIgnoreError_PdfResult;
1356 switch (skobj->getType()) 1412 switch (skobj->getType())
1357 { 1413 {
1358 case kObjectDictionaryXObjectDictionaryImageDictionary_SkPdfObjectType: 1414 case kObjectDictionaryXObjectDictionaryImageDictionary_SkPdfObjectType:
1359 ret = doXObject_Image(pdfContext, canvas, skobj->asImageDictionary() ); 1415 ret = doXObject_Image(pdfContext, canvas, skobj->asImageDictionary() );
1360 break; 1416 break;
1361 case kObjectDictionaryXObjectDictionaryType1FormDictionary_SkPdfObjectTy pe: 1417 case kObjectDictionaryXObjectDictionaryType1FormDictionary_SkPdfObjectTy pe:
1362 ret = doXObject_Form(pdfContext, canvas, obj);//skobj->asType1FormDi ctionary()); 1418 ret = doXObject_Form(pdfContext, canvas, skobj->asType1FormDictionar y());
1363 break; 1419 break;
1364 //case kObjectDictionaryXObjectPS_SkPdfObjectType: 1420 //case kObjectDictionaryXObjectPS_SkPdfObjectType:
1365 //return doXObject_PS(skxobj.asPS()); 1421 //return doXObject_PS(skxobj.asPS());
1366 } 1422 }
1367 1423
1368 delete skobj; 1424 delete skobj;
1369 return ret; 1425 return ret;
1370 } 1426 }
1371 1427
1372 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) { 1428 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per) {
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
2098 2154
2099 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN ame is 2155 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN ame is
2100 //the name of a graphics state parameter dictionary in the ExtGState subdictiona ry of the current resource dictionary (see the next section). 2156 //the name of a graphics state parameter dictionary in the ExtGState subdictiona ry of the current resource dictionary (see the next section).
2101 PdfResult PdfOp_gs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2157 PdfResult PdfOp_gs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2102 PdfName name = pdfContext->fVarStack.top().GetName(); pdfContext->fVarSta ck.pop(); 2158 PdfName name = pdfContext->fVarStack.top().GetName(); pdfContext->fVarSta ck.pop();
2103 2159
2104 #ifdef PDF_TRACE 2160 #ifdef PDF_TRACE
2105 std::string str; 2161 std::string str;
2106 #endif 2162 #endif
2107 2163
2108 const PdfDictionary& pageDict = pdfContext->fGraphicsState.fObjectWithResour ces->GetDictionary(); 2164 const PdfObject* resources = pdfContext->fGraphicsState.fResources.podofo();
2109
2110 #ifdef PDF_TRACE
2111 pdfContext->fGraphicsState.fObjectWithResources->ToString(str);
2112 printf("Print Object with resources: %s\n", str.c_str());
2113 #endif
2114
2115 const PdfObject* resources = resolveReferenceObject(pdfContext->fPdfDoc,
2116 pageDict.GetKey("Resourc es"));
2117 2165
2118 if (resources == NULL) { 2166 if (resources == NULL) {
2119 #ifdef PDF_TRACE 2167 #ifdef PDF_TRACE
2120 printf("WARNING: No Resources for a page with 'gs' operator!\n"); 2168 printf("WARNING: No Resources for a page with 'gs' operator!\n");
2121 #endif 2169 #endif
2122 return kIgnoreError_PdfResult; 2170 return kIgnoreError_PdfResult;
2123 } 2171 }
2124 2172
2125 #ifdef PDF_TRACE 2173 #ifdef PDF_TRACE
2126 resources->ToString(str); 2174 resources->ToString(str);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2162 printf("Named object not found!\n"); 2210 printf("Named object not found!\n");
2163 #endif 2211 #endif
2164 return kIgnoreError_PdfResult; 2212 return kIgnoreError_PdfResult;
2165 } 2213 }
2166 2214
2167 #ifdef PDF_TRACE 2215 #ifdef PDF_TRACE
2168 value->ToString(str); 2216 value->ToString(str);
2169 printf("gs object value: %s\n", str.c_str()); 2217 printf("gs object value: %s\n", str.c_str());
2170 #endif 2218 #endif
2171 2219
2220 SkPdfGraphicsStateDictionary gs(pdfContext->fPdfDoc, value);
2221 printf("caCA %f %f\n", gs.ca(), gs.CA());
2222
2172 // TODO(edisonn): now load all those properties in graphic state. 2223 // TODO(edisonn): now load all those properties in graphic state.
2173 2224
2174 return kNYI_PdfResult; 2225 return kNYI_PdfResult;
2175 } 2226 }
2176 2227
2177 //charSpace Tc Set the character spacing, Tc 2228 //charSpace Tc Set the character spacing, Tc
2178 //, to charSpace, which is a number expressed in unscaled text space units. Char acter spacing is used by the Tj, TJ, and ' operators. 2229 //, to charSpace, which is a number expressed in unscaled text space units. Char acter spacing is used by the Tj, TJ, and ' operators.
2179 //Initial value: 0. 2230 //Initial value: 0.
2180 PdfResult PdfOp_Tc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2231 PdfResult PdfOp_Tc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2181 double charSpace = pdfContext->fVarStack.top().GetReal(); pdfContext->fV arStack.pop(); 2232 double charSpace = pdfContext->fVarStack.top().GetReal(); pdfContext->fV arStack.pop();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 PdfResult PdfOp_sh(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2296 PdfResult PdfOp_sh(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2246 pdfContext->fVarStack.pop(); 2297 pdfContext->fVarStack.pop();
2247 2298
2248 return kNYI_PdfResult; 2299 return kNYI_PdfResult;
2249 } 2300 }
2250 2301
2251 //name Do 2302 //name Do
2252 PdfResult PdfOp_Do(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) { 2303 PdfResult PdfOp_Do(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper) {
2253 PdfName name = pdfContext->fVarStack.top().GetName(); pdfContext->fVarSta ck.pop(); 2304 PdfName name = pdfContext->fVarStack.top().GetName(); pdfContext->fVarSta ck.pop();
2254 2305
2255 const PdfDictionary& pageDict = pdfContext->fGraphicsState.fObjectWithResour ces->GetDictionary(); 2306 const PdfObject* resources = pdfContext->fGraphicsState.fResources.podofo();
2256 const PdfObject* resources = resolveReferenceObject(pdfContext->fPdfDoc,
2257 pageDict.GetKey("Resourc es"));
2258 2307
2259 if (resources == NULL) { 2308 if (resources == NULL) {
2260 #ifdef PDF_TRACE 2309 #ifdef PDF_TRACE
2261 printf("WARNING: No Resources for a page with 'Do' operator!s\n"); 2310 printf("WARNING: No Resources for a page with 'Do' operator!s\n");
2262 #endif 2311 #endif
2263 return kIgnoreError_PdfResult; 2312 return kIgnoreError_PdfResult;
2264 } 2313 }
2265 2314
2266 #ifdef PDF_TRACE 2315 #ifdef PDF_TRACE
2267 std::string str; 2316 std::string str;
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
2630 const char* pszToken = NULL; 2679 const char* pszToken = NULL;
2631 PdfVariant var; 2680 PdfVariant var;
2632 EPdfContentsType eType; 2681 EPdfContentsType eType;
2633 2682
2634 PdfContentsTokenizer tokenizer( page ); 2683 PdfContentsTokenizer tokenizer( page );
2635 2684
2636 PdfContext pdfContext; 2685 PdfContext pdfContext;
2637 pdfContext.fPdfPage = page; 2686 pdfContext.fPdfPage = page;
2638 pdfContext.fPdfDoc = &doc; 2687 pdfContext.fPdfDoc = &doc;
2639 pdfContext.fOriginalMatrix = SkMatrix::I(); 2688 pdfContext.fOriginalMatrix = SkMatrix::I();
2640 pdfContext.fGraphicsState.fObjectWithResources = pdfContext.fPdf Page->GetObject(); 2689 pdfContext.fGraphicsState.fResources = SkPdfResourceDictionary(p dfContext.fPdfDoc, resolveReferenceObject(pdfContext.fPdfDoc,
2690 pdfContext.fPdfPage->GetResources()));
2641 2691
2642 gPdfContext = &pdfContext; 2692 gPdfContext = &pdfContext;
2643 gDumpBitmap = &bitmap; 2693 gDumpBitmap = &bitmap;
2644 gDumpCanvas = &canvas; 2694 gDumpCanvas = &canvas;
2645 2695
2646 2696
2647 // TODO(edisonn): get matrix stuff right. 2697 // TODO(edisonn): get matrix stuff right.
2648 // TODO(edisonn): add DPI/scale/zoom. 2698 // TODO(edisonn): add DPI/scale/zoom.
2649 SkScalar z = SkIntToScalar(0); 2699 SkScalar z = SkIntToScalar(0);
2650 SkScalar w = SkDoubleToScalar(rect.GetWidth()); 2700 SkScalar w = SkDoubleToScalar(rect.GetWidth());
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
2915 } 2965 }
2916 2966
2917 return 0; 2967 return 0;
2918 } 2968 }
2919 2969
2920 #if !defined SK_BUILD_FOR_IOS 2970 #if !defined SK_BUILD_FOR_IOS
2921 int main(int argc, char * const argv[]) { 2971 int main(int argc, char * const argv[]) {
2922 return tool_main(argc, (char**) argv); 2972 return tool_main(argc, (char**) argv);
2923 } 2973 }
2924 #endif 2974 #endif
OLDNEW
« no previous file with comments | « experimental/PdfViewer/pdf_auto_gen.h ('k') | experimental/PdfViewer/pdfspec_autogen.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698