| OLD | NEW |
| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "pdf_auto_gen.h" | 47 #include "pdf_auto_gen.h" |
| 48 | 48 |
| 49 /* | 49 /* |
| 50 * TODO(edisonn): ASAP so skp -> pdf -> png looks greap | 50 * TODO(edisonn): ASAP so skp -> pdf -> png looks greap |
| 51 * - load gs/ especially smask and already known prop | 51 * - load gs/ especially smask and already known prop |
| 52 * - use transparency (I think ca and CA ops) | 52 * - use transparency (I think ca and CA ops) |
| 53 * - load font for baidu.pdf | 53 * - load font for baidu.pdf |
| 54 * - load font for youtube.pdf | 54 * - load font for youtube.pdf |
| 55 */ | 55 */ |
| 56 | 56 |
| 57 #define PDF_TRACE | 57 //#define PDF_TRACE |
| 58 //#define PDF_TRACE_DIFF_IN_PNG | 58 //#define PDF_TRACE_DIFF_IN_PNG |
| 59 //#define PDF_DEBUG_NO_CLIPING | 59 //#define PDF_DEBUG_NO_CLIPING |
| 60 //#define PDF_DEBUG_NO_PAGE_CLIPING | 60 //#define PDF_DEBUG_NO_PAGE_CLIPING |
| 61 //#define PDF_DEBUG_3X | 61 //#define PDF_DEBUG_3X |
| 62 | 62 |
| 63 // TODO(edisonn): move in trace util. | 63 // TODO(edisonn): move in trace util. |
| 64 #ifdef PDF_TRACE | 64 #ifdef PDF_TRACE |
| 65 static void SkTraceMatrix(const SkMatrix& matrix, const char* sz = "") { | 65 static void SkTraceMatrix(const SkMatrix& matrix, const char* sz = "") { |
| 66 printf("SkMatrix %s ", sz); | 66 printf("SkMatrix %s ", sz); |
| 67 for (int i = 0 ; i < 9 ; i++) { | 67 for (int i = 0 ; i < 9 ; i++) { |
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 (unsigned char*)uncompressedStream, uncompressedStreamLength, | 1012 (unsigned char*)uncompressedStream, uncompressedStreamLength, |
| 1013 width, height, bytesPerLine, | 1013 width, height, bytesPerLine, |
| 1014 bpc, colorSpace, | 1014 bpc, colorSpace, |
| 1015 transparencyMask); | 1015 transparencyMask); |
| 1016 | 1016 |
| 1017 free(uncompressedStream); | 1017 free(uncompressedStream); |
| 1018 | 1018 |
| 1019 return bitmap; | 1019 return bitmap; |
| 1020 } | 1020 } |
| 1021 | 1021 |
| 1022 SkBitmap getImageFromObjectOld(PdfContext* pdfContext, const PdfObject& obj, boo
l transparencyMask) { | |
| 1023 if (!obj.HasStream() || obj.GetStream() == NULL || obj.GetStream()->GetLengt
h() == 0 || | |
| 1024 !obj.IsDictionary()) { | |
| 1025 // TODO(edisonn): report warning to be used in testing. | |
| 1026 return SkBitmap(); | |
| 1027 } | |
| 1028 | |
| 1029 const PdfObject* value = resolveReferenceObject(pdfContext->fPdfDoc, | |
| 1030 obj.GetDictionary().GetKey(PdfName
("Filter"))); | |
| 1031 | |
| 1032 if (value && value->IsArray() && value->GetArray().GetSize() == 1) { | |
| 1033 value = resolveReferenceObject(pdfContext->fPdfDoc, | |
| 1034 &value->GetArray()[0]); | |
| 1035 } | |
| 1036 | |
| 1037 // TODO (edisonn): Fast Jpeg(DCTDecode) draw, or fast PNG(FlateDecode) draw
... | |
| 1038 // if (value && value->IsName() && value->GetName().GetName() == "DCTDecode")
{ | |
| 1039 // SkStream stream = SkStream:: | |
| 1040 // SkImageDecoder::Factory() | |
| 1041 // } | |
| 1042 | |
| 1043 // Get color space | |
| 1044 // translate | |
| 1045 | |
| 1046 long bpc = 0; | |
| 1047 LongFromDictionary(pdfContext->fPdfDoc, obj.GetDictionary(), "BitsPerCompone
nt", "BPC", &bpc); | |
| 1048 | |
| 1049 bool imageMask = false; | |
| 1050 BoolFromDictionary(pdfContext->fPdfDoc, obj.GetDictionary(), "ImageMask", ""
, &imageMask); | |
| 1051 | |
| 1052 if (imageMask) { | |
| 1053 if (bpc != 0 && bpc != 1) { | |
| 1054 // TODO(edisonn): report warning to be used in testing. | |
| 1055 return SkBitmap(); | |
| 1056 } | |
| 1057 bpc = 1; | |
| 1058 } | |
| 1059 | |
| 1060 long width; | |
| 1061 if (!LongFromDictionary(pdfContext->fPdfDoc, obj.GetDictionary(), "Width", &
width)) { | |
| 1062 // TODO(edisonn): report warning to be used in testing. | |
| 1063 return SkBitmap(); | |
| 1064 } | |
| 1065 | |
| 1066 long height; | |
| 1067 if (!LongFromDictionary(pdfContext->fPdfDoc, obj.GetDictionary(), "Height",
&height)) { | |
| 1068 // TODO(edisonn): report warning to be used in testing. | |
| 1069 return SkBitmap(); | |
| 1070 } | |
| 1071 | |
| 1072 std::string colorSpace; // TODO(edisonn): load others than names, for more
complicated | |
| 1073 if (!NameFromDictionary(pdfContext->fPdfDoc, obj.GetDictionary(), "ColorSpac
e", &colorSpace)) { | |
| 1074 // TODO(edisonn): report warning to be used in testing. | |
| 1075 return SkBitmap(); | |
| 1076 } | |
| 1077 | |
| 1078 char* uncompressedStream = NULL; | |
| 1079 pdf_long uncompressedStreamLength = 0; | |
| 1080 | |
| 1081 PdfResult ret = kPartial_PdfResult; | |
| 1082 // TODO(edisonn): get rid of try/catch exceptions! We should not throw on us
er data! | |
| 1083 try { | |
| 1084 obj.GetStream()->GetFilteredCopy(&uncompressedStream, &uncompressedStrea
mLength); | |
| 1085 } catch (PdfError& e) { | |
| 1086 // TODO(edisonn): report warning to be used in testing. | |
| 1087 return SkBitmap(); | |
| 1088 } | |
| 1089 | |
| 1090 int bytesPerLine = uncompressedStreamLength / height; | |
| 1091 #ifdef PDF_TRACE | |
| 1092 if (uncompressedStreamLength % height != 0) { | |
| 1093 printf("Warning uncompressedStreamLength % height != 0 !!!\n"); | |
| 1094 } | |
| 1095 #endif | |
| 1096 | |
| 1097 SkBitmap bitmap = transferImageStreamToBitmap( | |
| 1098 (unsigned char*)uncompressedStream, uncompressedStreamLength, | |
| 1099 width, height, bytesPerLine, | |
| 1100 bpc, colorSpace, | |
| 1101 transparencyMask); | |
| 1102 | |
| 1103 free(uncompressedStream); | |
| 1104 | |
| 1105 return bitmap; | |
| 1106 } | |
| 1107 | |
| 1108 SkBitmap getSmaskFromObject(PdfContext* pdfContext, const SkPdfImage* obj) { | 1022 SkBitmap getSmaskFromObject(PdfContext* pdfContext, const SkPdfImage* obj) { |
| 1109 const PdfObject* sMask = resolveReferenceObject(pdfContext->fPdfDoc, | 1023 const PdfObject* sMask = resolveReferenceObject(pdfContext->fPdfDoc, |
| 1110 obj->podofo()->GetDictionary().Get
Key(PdfName("SMask"))); | 1024 obj->podofo()->GetDictionary().Get
Key(PdfName("SMask"))); |
| 1111 | 1025 |
| 1112 #ifdef PDF_TRACE | 1026 #ifdef PDF_TRACE |
| 1113 std::string str; | 1027 std::string str; |
| 1114 if (sMask) { | 1028 if (sMask) { |
| 1115 sMask->ToString(str); | 1029 sMask->ToString(str); |
| 1116 printf("/SMask of /Subtype /Image: %s\n", str.c_str()); | 1030 printf("/SMask of /Subtype /Image: %s\n", str.c_str()); |
| 1117 } | 1031 } |
| 1118 #endif | 1032 #endif |
| 1119 | 1033 |
| 1120 if (sMask) { | 1034 if (sMask) { |
| 1121 SkPdfImage skxobjmask(pdfContext->fPdfDoc, sMask); | 1035 SkPdfImage skxobjmask(pdfContext->fPdfDoc, sMask); |
| 1122 return getImageFromObject(pdfContext, &skxobjmask, true); | 1036 return getImageFromObject(pdfContext, &skxobjmask, true); |
| 1123 } | 1037 } |
| 1124 | 1038 |
| 1125 // TODO(edisonn): implement GS SMask. Default to empty right now. | 1039 // TODO(edisonn): implement GS SMask. Default to empty right now. |
| 1126 return pdfContext->fGraphicsState.fSMask; | 1040 return pdfContext->fGraphicsState.fSMask; |
| 1127 } | 1041 } |
| 1128 | 1042 |
| 1129 SkBitmap getSmaskFromObjectOld(PdfContext* pdfContext, const PdfObject& obj) { | |
| 1130 const PdfObject* sMask = resolveReferenceObject(pdfContext->fPdfDoc, | |
| 1131 obj.GetDictionary().GetKey(PdfName
("SMask"))); | |
| 1132 | |
| 1133 #ifdef PDF_TRACE | |
| 1134 std::string str; | |
| 1135 if (sMask) { | |
| 1136 sMask->ToString(str); | |
| 1137 printf("/SMask of /Subtype /Image: %s\n", str.c_str()); | |
| 1138 } | |
| 1139 #endif | |
| 1140 | |
| 1141 if (sMask) { | |
| 1142 return getImageFromObjectOld(pdfContext, *sMask, true); | |
| 1143 } | |
| 1144 | |
| 1145 // TODO(edisonn): implement GS SMask. Default to empty right now. | |
| 1146 return pdfContext->fGraphicsState.fSMask; | |
| 1147 } | |
| 1148 | |
| 1149 | |
| 1150 PdfResult doXObject_Image(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfI
mage* skpdfimage) { | 1043 PdfResult doXObject_Image(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfI
mage* skpdfimage) { |
| 1151 if (skpdfimage == NULL || !skpdfimage->valid()) { | 1044 if (skpdfimage == NULL || !skpdfimage->valid()) { |
| 1152 return kIgnoreError_PdfResult; | 1045 return kIgnoreError_PdfResult; |
| 1153 } | 1046 } |
| 1154 | 1047 |
| 1155 SkBitmap image = getImageFromObject(pdfContext, skpdfimage, false); | 1048 SkBitmap image = getImageFromObject(pdfContext, skpdfimage, false); |
| 1156 SkBitmap sMask = getSmaskFromObject(pdfContext, skpdfimage); | 1049 SkBitmap sMask = getSmaskFromObject(pdfContext, skpdfimage); |
| 1157 | 1050 |
| 1158 canvas->save(); | 1051 canvas->save(); |
| 1159 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix); | 1052 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix); |
| 1160 SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0),
SkDoubleToScalar(1.0), SkDoubleToScalar(1.0)); | 1053 SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0),
SkDoubleToScalar(1.0), SkDoubleToScalar(1.0)); |
| 1161 | 1054 |
| 1162 if (sMask.empty()) { | 1055 if (sMask.empty()) { |
| 1163 canvas->drawBitmapRect(image, dst, NULL); | 1056 canvas->drawBitmapRect(image, dst, NULL); |
| 1164 } else { | 1057 } else { |
| 1165 canvas->saveLayer(&dst, NULL); | 1058 canvas->saveLayer(&dst, NULL); |
| 1166 canvas->drawBitmapRect(image, dst, NULL); | 1059 canvas->drawBitmapRect(image, dst, NULL); |
| 1167 SkPaint xfer; | 1060 SkPaint xfer; |
| 1168 xfer.setXfermodeMode(SkXfermode::kSrcOut_Mode); // SkXfermode::kSdtOut_M
ode | 1061 xfer.setXfermodeMode(SkXfermode::kSrcOut_Mode); // SkXfermode::kSdtOut_M
ode |
| 1169 canvas->drawBitmapRect(sMask, dst, &xfer); | 1062 canvas->drawBitmapRect(sMask, dst, &xfer); |
| 1170 canvas->restore(); | 1063 canvas->restore(); |
| 1171 } | 1064 } |
| 1172 | 1065 |
| 1173 canvas->restore(); | 1066 canvas->restore(); |
| 1174 | 1067 |
| 1175 return kPartial_PdfResult; | 1068 return kPartial_PdfResult; |
| 1176 } | 1069 } |
| 1177 | 1070 |
| 1178 PdfResult doXObject_ImageOld(PdfContext* pdfContext, SkCanvas* canvas, const Pdf
Object& obj) { | |
| 1179 if (!obj.HasStream() || obj.GetStream() == NULL || obj.GetStream()->GetLengt
h() == 0 || | |
| 1180 !obj.IsDictionary()) { | |
| 1181 return kIgnoreError_PdfResult; | |
| 1182 } | |
| 1183 | |
| 1184 SkBitmap image = getImageFromObjectOld(pdfContext, obj, false); | |
| 1185 SkBitmap sMask = getSmaskFromObjectOld(pdfContext, obj); | |
| 1186 | |
| 1187 canvas->save(); | |
| 1188 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix); | |
| 1189 SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0),
SkDoubleToScalar(1.0), SkDoubleToScalar(1.0)); | |
| 1190 | |
| 1191 if (sMask.empty()) { | |
| 1192 canvas->drawBitmapRect(image, dst, NULL); | |
| 1193 } else { | |
| 1194 canvas->saveLayer(&dst, NULL); | |
| 1195 canvas->drawBitmapRect(image, dst, NULL); | |
| 1196 SkPaint xfer; | |
| 1197 xfer.setXfermodeMode(SkXfermode::kSrcOut_Mode); // SkXfermode::kSdtOut_M
ode | |
| 1198 canvas->drawBitmapRect(sMask, dst, &xfer); | |
| 1199 canvas->restore(); | |
| 1200 } | |
| 1201 | |
| 1202 canvas->restore(); | |
| 1203 | |
| 1204 return kPartial_PdfResult; | |
| 1205 } | |
| 1206 | |
| 1207 | |
| 1208 PdfResult doXObject_ImageOld2(PdfContext* pdfContext, SkCanvas* canvas, const Pd
fObject& obj) { | |
| 1209 if (!obj.HasStream() || obj.GetStream() == NULL || obj.GetStream()->GetLengt
h() == 0 || | |
| 1210 !obj.IsDictionary()) { | |
| 1211 return kIgnoreError_PdfResult; | |
| 1212 } | |
| 1213 | |
| 1214 const PdfObject* sMask = resolveReferenceObject(pdfContext->fPdfDoc, | |
| 1215 obj.GetDictionary().GetKey(PdfName
("SMask"))); | |
| 1216 // TODO(edisonn): else get smask from graphi state | |
| 1217 // TODO(edisonn): add utility, SkBitmap loadBitmap(PdfObject& obj, bool no_s
mask); | |
| 1218 // TODO(edisonn): add utility, SkBitmap loadSmask(state, PdfObject& obj); | |
| 1219 | |
| 1220 #ifdef PDF_TRACE | |
| 1221 std::string str; | |
| 1222 if (sMask) { | |
| 1223 sMask->ToString(str); | |
| 1224 printf("/SMask of /Subtype /Image: %s\n", str.c_str()); | |
| 1225 } | |
| 1226 #endif | |
| 1227 | |
| 1228 /* | |
| 1229 // TODO (edisonn): Fast Jpeg(DCTDecode) draw, or fast PNG(FlateDecode) draw
... | |
| 1230 PdfObject* value = resolveReferenceObject(pdfContext->fPdfDoc, | |
| 1231 obj.GetDictionary().GetKey(PdfName
("Filter"))); | |
| 1232 | |
| 1233 if (value && value->IsArray() && value->GetArray().GetSize() == 1) { | |
| 1234 value = resolveReferenceObject(pdfContext->fPdfDoc, | |
| 1235 &value->GetArray()[0]); | |
| 1236 } | |
| 1237 | |
| 1238 if (value && value->IsName() && value->GetName().GetName() == "DCTDecode") { | |
| 1239 SkStream stream = SkStream:: | |
| 1240 SkImageDecoder::Factory() | |
| 1241 } | |
| 1242 */ | |
| 1243 // Get color space | |
| 1244 // trasnlate | |
| 1245 | |
| 1246 long bpc = 0; | |
| 1247 LongFromDictionary(pdfContext->fPdfDoc, obj.GetDictionary(), "BitsPerCompone
nt", "BPC", &bpc); | |
| 1248 | |
| 1249 bool imageMask = false; | |
| 1250 BoolFromDictionary(pdfContext->fPdfDoc, obj.GetDictionary(), "ImageMask", ""
, &imageMask); | |
| 1251 | |
| 1252 if (imageMask) { | |
| 1253 if (bpc != 0 && bpc != 1) { | |
| 1254 return kIgnoreError_PdfResult; | |
| 1255 } | |
| 1256 bpc = 1; | |
| 1257 } | |
| 1258 | |
| 1259 long width; | |
| 1260 if (!LongFromDictionary(pdfContext->fPdfDoc, obj.GetDictionary(), "Width", "
W", &width)) { | |
| 1261 return kIgnoreError_PdfResult; | |
| 1262 } | |
| 1263 | |
| 1264 long height; | |
| 1265 if (!LongFromDictionary(pdfContext->fPdfDoc, obj.GetDictionary(), "Height",
"H", &height)) { | |
| 1266 return kIgnoreError_PdfResult; | |
| 1267 } | |
| 1268 | |
| 1269 std::string colorSpace; // TODO(edisonn): load others than names, for more
complicated | |
| 1270 if (!NameFromDictionary(pdfContext->fPdfDoc, obj.GetDictionary(), "ColorSpac
e", "", &colorSpace)) { | |
| 1271 return kIgnoreError_PdfResult; | |
| 1272 } | |
| 1273 | |
| 1274 char* uncompressedStream = NULL; | |
| 1275 pdf_long uncompressedStreamLength = 0; | |
| 1276 | |
| 1277 PdfResult ret = kPartial_PdfResult; | |
| 1278 // TODO(edisonn): get rid of try/catch exceptions! We should not throw on us
er data! | |
| 1279 try { | |
| 1280 obj.GetStream()->GetFilteredCopy(&uncompressedStream, &uncompressedStrea
mLength); | |
| 1281 } catch (PdfError& e) { | |
| 1282 return kIgnoreError_PdfResult; | |
| 1283 } | |
| 1284 | |
| 1285 SkColor* uncompressedStreamArgb = NULL; | |
| 1286 pdf_long uncompressedStreamLengthInBytesArgb = 0; | |
| 1287 | |
| 1288 int bytesPerLine = uncompressedStreamLength / height; | |
| 1289 #ifdef PDF_TRACE | |
| 1290 if (uncompressedStreamLength % height != 0) { | |
| 1291 printf("Warning uncompressedStreamLength % height != 0 !!!\n"); | |
| 1292 } | |
| 1293 #endif | |
| 1294 | |
| 1295 if (!transferImageStreamToARGB((unsigned char*)uncompressedStream, uncompres
sedStreamLength, | |
| 1296 width, bytesPerLine, | |
| 1297 bpc, colorSpace, | |
| 1298 &uncompressedStreamArgb, | |
| 1299 &uncompressedStreamLengthInBytesArgb)) { | |
| 1300 free(uncompressedStream); // TODO(edisonn): avoid freeing the stream in
2 places! | |
| 1301 return kIgnoreError_PdfResult; | |
| 1302 } | |
| 1303 free(uncompressedStream); | |
| 1304 | |
| 1305 SkBitmap::Config config = SkBitmap::kARGB_8888_Config; | |
| 1306 | |
| 1307 SkBitmap bitmap; | |
| 1308 bitmap.setConfig(config, width, height); | |
| 1309 bitmap.setPixels(uncompressedStreamArgb); | |
| 1310 | |
| 1311 canvas->save(); | |
| 1312 canvas->setMatrix(pdfContext->fGraphicsState.fMatrix); | |
| 1313 SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0),
SkDoubleToScalar(1.0), SkDoubleToScalar(1.0)); | |
| 1314 canvas->drawBitmapRect(bitmap, dst, NULL); | |
| 1315 canvas->restore(); | |
| 1316 | |
| 1317 return kPartial_PdfResult; | |
| 1318 } | |
| 1319 | |
| 1320 bool SkMatrixFromDictionary(PdfContext* pdfContext, | 1071 bool SkMatrixFromDictionary(PdfContext* pdfContext, |
| 1321 const PdfDictionary& dict, | 1072 const PdfDictionary& dict, |
| 1322 const char* key, | 1073 const char* key, |
| 1323 SkMatrix* matrix) { | 1074 SkMatrix* matrix) { |
| 1324 const PdfObject* value = resolveReferenceObject(pdfContext->fPdfDoc, | 1075 const PdfObject* value = resolveReferenceObject(pdfContext->fPdfDoc, |
| 1325 dict.GetKey(PdfName(key))); | 1076 dict.GetKey(PdfName(key))); |
| 1326 | 1077 |
| 1327 if (value == NULL || !value->IsArray()) { | 1078 if (value == NULL || !value->IsArray()) { |
| 1328 return false; | 1079 return false; |
| 1329 } | 1080 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 SkPdfObject* skobj = NULL; | 1220 SkPdfObject* skobj = NULL; |
| 1470 if (!PodofoMapper::mapObject(*pdfContext->fPdfDoc, obj, &skobj)) return kIgn
oreError_PdfResult; | 1221 if (!PodofoMapper::mapObject(*pdfContext->fPdfDoc, obj, &skobj)) return kIgn
oreError_PdfResult; |
| 1471 | 1222 |
| 1472 if (!skobj || !skobj->valid()) return kIgnoreError_PdfResult; | 1223 if (!skobj || !skobj->valid()) return kIgnoreError_PdfResult; |
| 1473 | 1224 |
| 1474 PdfResult ret = kIgnoreError_PdfResult; | 1225 PdfResult ret = kIgnoreError_PdfResult; |
| 1475 switch (skobj->getType()) | 1226 switch (skobj->getType()) |
| 1476 { | 1227 { |
| 1477 case kObjectDictionaryXObjectImage_SkPdfObjectType: | 1228 case kObjectDictionaryXObjectImage_SkPdfObjectType: |
| 1478 ret = doXObject_Image(pdfContext, canvas, skobj->asImage()); | 1229 ret = doXObject_Image(pdfContext, canvas, skobj->asImage()); |
| 1479 //case kObjectDictionaryXObjectForm_SkPdfObjectType: | 1230 break; |
| 1480 //return doXObject_Form(skxobj.asForm()); | 1231 case kObjectDictionaryXObjectForm_SkPdfObjectType: |
| 1232 ret = doXObject_Form(pdfContext, canvas, obj); |
| 1233 break; |
| 1481 //case kObjectDictionaryXObjectPS_SkPdfObjectType: | 1234 //case kObjectDictionaryXObjectPS_SkPdfObjectType: |
| 1482 //return doXObject_PS(skxobj.asPS()); | 1235 //return doXObject_PS(skxobj.asPS()); |
| 1483 } | 1236 } |
| 1484 | 1237 |
| 1485 delete skobj; | 1238 delete skobj; |
| 1486 return ret; | 1239 return ret; |
| 1487 } | 1240 } |
| 1488 | 1241 |
| 1489 PdfResult doXObjectOld(PdfContext* pdfContext, SkCanvas* canvas, const PdfObject
& obj) { | |
| 1490 if (CheckRecursiveRendering::IsInRendering(obj)) { | |
| 1491 // Oops, corrupt PDF! | |
| 1492 return kIgnoreError_PdfResult; | |
| 1493 } | |
| 1494 | |
| 1495 CheckRecursiveRendering checkRecursion(obj); | |
| 1496 | |
| 1497 if (!obj.IsDictionary()) { | |
| 1498 return kIgnoreError_PdfResult; | |
| 1499 } | |
| 1500 | |
| 1501 const PdfObject* type = resolveReferenceObject(pdfContext->fPdfDoc, | |
| 1502 obj.GetDictionary().GetKey(Pd
fName("Type"))); | |
| 1503 | |
| 1504 if (type == NULL || !type->IsName()) { | |
| 1505 return kIgnoreError_PdfResult; | |
| 1506 } | |
| 1507 | |
| 1508 if (type->GetName().GetName() != "XObject") { | |
| 1509 return kIgnoreError_PdfResult; | |
| 1510 } | |
| 1511 | |
| 1512 const PdfObject* subtype = | |
| 1513 resolveReferenceObject(pdfContext->fPdfDoc, | |
| 1514 obj.GetDictionary().GetKey(PdfName("Subtype")
)); | |
| 1515 | |
| 1516 if (subtype == NULL || !subtype->IsName()) { | |
| 1517 return kIgnoreError_PdfResult; | |
| 1518 } | |
| 1519 | |
| 1520 if (subtype->GetName().GetName() == "Image") { | |
| 1521 return doXObject_ImageOld(pdfContext, canvas, obj); | |
| 1522 } else if (subtype->GetName().GetName() == "Form") { | |
| 1523 return doXObject_Form(pdfContext, canvas, obj); | |
| 1524 } else if (subtype->GetName().GetName() == "PS") { | |
| 1525 return doXObject_PS(pdfContext, canvas, obj); | |
| 1526 } | |
| 1527 return kIgnoreError_PdfResult; | |
| 1528 } | |
| 1529 | |
| 1530 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per) { | 1242 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per) { |
| 1531 pdfContext->fStateStack.push(pdfContext->fGraphicsState); | 1243 pdfContext->fStateStack.push(pdfContext->fGraphicsState); |
| 1532 canvas->save(); | 1244 canvas->save(); |
| 1533 return kOK_PdfResult; | 1245 return kOK_PdfResult; |
| 1534 } | 1246 } |
| 1535 | 1247 |
| 1536 PdfResult PdfOp_Q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per) { | 1248 PdfResult PdfOp_Q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per) { |
| 1537 pdfContext->fGraphicsState = pdfContext->fStateStack.top(); | 1249 pdfContext->fGraphicsState = pdfContext->fStateStack.top(); |
| 1538 pdfContext->fStateStack.pop(); | 1250 pdfContext->fStateStack.pop(); |
| 1539 canvas->restore(); | 1251 canvas->restore(); |
| (...skipping 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3064 } | 2776 } |
| 3065 | 2777 |
| 3066 return 0; | 2778 return 0; |
| 3067 } | 2779 } |
| 3068 | 2780 |
| 3069 #if !defined SK_BUILD_FOR_IOS | 2781 #if !defined SK_BUILD_FOR_IOS |
| 3070 int main(int argc, char * const argv[]) { | 2782 int main(int argc, char * const argv[]) { |
| 3071 return tool_main(argc, (char**) argv); | 2783 return tool_main(argc, (char**) argv); |
| 3072 } | 2784 } |
| 3073 #endif | 2785 #endif |
| OLD | NEW |