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 "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
11 #include "SkGraphics.h" | 11 #include "SkGraphics.h" |
12 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
13 #include "SkImageEncoder.h" | 13 #include "SkImageEncoder.h" |
14 #include "SkOSFile.h" | 14 #include "SkOSFile.h" |
15 #include "SkPicture.h" | 15 #include "SkPicture.h" |
16 #include "SkStream.h" | 16 #include "SkStream.h" |
17 #include "SkTypeface.h" | 17 #include "SkTypeface.h" |
18 #include "SkTArray.h" | 18 #include "SkTArray.h" |
19 #include "SkTDict.h" | 19 #include "SkTDict.h" |
20 | 20 |
21 #include "SkPdfGraphicsState.h" | 21 #include "SkPdfGraphicsState.h" |
22 #include "SkPdfNativeTokenizer.h" | 22 #include "SkPdfNativeTokenizer.h" |
23 #include <cstdio> | |
24 #include <stack> | |
25 #include <set> | |
26 | 23 |
27 extern "C" SkPdfContext* gPdfContext; | 24 extern "C" SkPdfContext* gPdfContext; |
28 extern "C" SkBitmap* gDumpBitmap; | 25 extern "C" SkBitmap* gDumpBitmap; |
29 extern "C" SkCanvas* gDumpCanvas; | 26 extern "C" SkCanvas* gDumpCanvas; |
30 | 27 |
31 __SK_FORCE_IMAGE_DECODER_LINKING; | 28 __SK_FORCE_IMAGE_DECODER_LINKING; |
32 | 29 |
33 // TODO(edisonn): tool, show what objects were read at least, show the ones not
even read | 30 // TODO(edisonn): tool, show what objects were read at least, show the ones not
even read |
34 // keep for each object pos in file | 31 // keep for each object pos in file |
35 // plug in for VS? syntax coloring, show selected object ... from the text, or f
rom rendered x,y | 32 // plug in for VS? syntax coloring, show selected object ... from the text, or f
rom rendered x,y |
36 | 33 |
37 // TODO(edisonn): security - validate all the user input, all pdf! | 34 // TODO(edisonn): security - validate all the user input, all pdf! |
38 | 35 |
39 // TODO(edisonn): put drawtext in #ifdefs, so comparations will ignore minor cha
nges in text positioning and font | 36 // TODO(edisonn): put drawtext in #ifdefs, so comparations will ignore minor cha
nges in text positioning and font |
40 // this way, we look more at other features and layout in diffs | 37 // this way, we look more at other features and layout in diffs |
41 | 38 |
42 // TODO(edisonn): move trace dump in the get functions, and mapper ones too so i
t ghappens automatically | 39 // TODO(edisonn): move trace dump in the get functions, and mapper ones too so i
t ghappens automatically |
43 /* | 40 /* |
44 #ifdef PDF_TRACE | 41 #ifdef PDF_TRACE |
45 std::string str; | 42 SkString str; |
46 pdfContext->fGraphicsState.fResources->native()->ToString(str); | 43 pdfContext->fGraphicsState.fResources->native()->ToString(str); |
47 printf("Print Tf Resources: %s\n", str.c_str()); | 44 printf("Print Tf Resources: %s\n", str.c_str()); |
48 #endif | 45 #endif |
49 */ | 46 */ |
50 | 47 |
51 #include "SkPdfHeaders_autogen.h" | 48 #include "SkPdfHeaders_autogen.h" |
52 #include "SkPdfMapper_autogen.h" | 49 #include "SkPdfMapper_autogen.h" |
53 #include "SkPdfRenderer.h" | 50 #include "SkPdfRenderer.h" |
54 | 51 |
55 #include "SkPdfUtils.h" | 52 #include "SkPdfUtils.h" |
(...skipping 11 matching lines...) Expand all Loading... |
67 * - encapsulate native in the pdf api so the skpdf does not know anything about
native ... in progress | 64 * - encapsulate native in the pdf api so the skpdf does not know anything about
native ... in progress |
68 * - load gs/ especially smask and already known prop (skp) ... in progress | 65 * - load gs/ especially smask and already known prop (skp) ... in progress |
69 * - wrapper on classes for customizations? e.g. | 66 * - wrapper on classes for customizations? e.g. |
70 * SkPdfPageObjectVanila - has only the basic loaders/getters | 67 * SkPdfPageObjectVanila - has only the basic loaders/getters |
71 * SkPdfPageObject : public SkPdfPageObjectVanila, extends, and I can add custom
izations here | 68 * SkPdfPageObject : public SkPdfPageObjectVanila, extends, and I can add custom
izations here |
72 * need to find a nice object model for all this with constructors and factories | 69 * need to find a nice object model for all this with constructors and factories |
73 * - deal with inheritable automatically ? | 70 * - deal with inheritable automatically ? |
74 * - deal with specific type in spec directly, add all dictionary types to known
types | 71 * - deal with specific type in spec directly, add all dictionary types to known
types |
75 */ | 72 */ |
76 | 73 |
77 using namespace std; | |
78 | |
79 NotOwnedString strings_DeviceRGB; | 74 NotOwnedString strings_DeviceRGB; |
80 NotOwnedString strings_DeviceCMYK; | 75 NotOwnedString strings_DeviceCMYK; |
81 | 76 |
82 class StringsInit { | 77 class StringsInit { |
83 public: | 78 public: |
84 StringsInit() { | 79 StringsInit() { |
85 NotOwnedString::init(&strings_DeviceRGB, "DeviceRGB"); | 80 NotOwnedString::init(&strings_DeviceRGB, "DeviceRGB"); |
86 NotOwnedString::init(&strings_DeviceCMYK, "DeviceCMYK"); | 81 NotOwnedString::init(&strings_DeviceCMYK, "DeviceCMYK"); |
87 } | 82 } |
88 }; | 83 }; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 for (int i = 0 ; i < 256; i++) { | 402 for (int i = 0 ; i < 256; i++) { |
408 colors[i] = SkPreMultiplyARGB(255, i, i, i); | 403 colors[i] = SkPreMultiplyARGB(255, i, i, i); |
409 } | 404 } |
410 grayColortable = new SkColorTable(colors, 256); | 405 grayColortable = new SkColorTable(colors, 256); |
411 } | 406 } |
412 return grayColortable; | 407 return grayColortable; |
413 } | 408 } |
414 | 409 |
415 static SkBitmap* transferImageStreamToBitmap(const unsigned char* uncompressedSt
ream, size_t uncompressedStreamLength, | 410 static SkBitmap* transferImageStreamToBitmap(const unsigned char* uncompressedSt
ream, size_t uncompressedStreamLength, |
416 int width, int height, int bytesPerLine, | 411 int width, int height, int bytesPerLine, |
417 int bpc, const std::string& colorSpace, | 412 int bpc, const SkString& colorSpace, |
418 bool transparencyMask) { | 413 bool transparencyMask) { |
419 SkBitmap* bitmap = new SkBitmap(); | 414 SkBitmap* bitmap = new SkBitmap(); |
420 | 415 |
421 //int components = GetColorSpaceComponents(colorSpace); | 416 //int components = GetColorSpaceComponents(colorSpace); |
422 //#define MAX_COMPONENTS 10 | 417 //#define MAX_COMPONENTS 10 |
423 | 418 |
424 // TODO(edisonn): assume start of lines are aligned at 32 bits? | 419 // TODO(edisonn): assume start of lines are aligned at 32 bits? |
425 // Is there a faster way to load the uncompressed stream into a bitmap? | 420 // Is there a faster way to load the uncompressed stream into a bitmap? |
426 | 421 |
427 // minimal support for now | 422 // minimal support for now |
428 if ((colorSpace == "DeviceRGB" || colorSpace == "RGB") && bpc == 8) { | 423 if ((colorSpace.equals("DeviceRGB") || colorSpace.equals("RGB")) && bpc == 8
) { |
429 SkColor* uncompressedStreamArgb = (SkColor*)malloc(width * height * size
of(SkColor)); | 424 SkColor* uncompressedStreamArgb = (SkColor*)malloc(width * height * size
of(SkColor)); |
430 | 425 |
431 for (int h = 0 ; h < height; h++) { | 426 for (int h = 0 ; h < height; h++) { |
432 long i = width * (h); | 427 long i = width * (h); |
433 for (int w = 0 ; w < width; w++) { | 428 for (int w = 0 ; w < width; w++) { |
434 uncompressedStreamArgb[i] = SkColorSetRGB(uncompressedStream[3 *
w], | 429 uncompressedStreamArgb[i] = SkColorSetRGB(uncompressedStream[3 *
w], |
435 uncompressedStream[3 *
w + 1], | 430 uncompressedStream[3 *
w + 1], |
436 uncompressedStream[3 *
w + 2]); | 431 uncompressedStream[3 *
w + 2]); |
437 i++; | 432 i++; |
438 } | 433 } |
439 uncompressedStream += bytesPerLine; | 434 uncompressedStream += bytesPerLine; |
440 } | 435 } |
441 | 436 |
442 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); | 437 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); |
443 bitmap->setPixels(uncompressedStreamArgb); | 438 bitmap->setPixels(uncompressedStreamArgb); |
444 } | 439 } |
445 else if ((colorSpace == "DeviceGray" || colorSpace == "Gray") && bpc == 8) { | 440 else if ((colorSpace.equals("DeviceGray") || colorSpace.equals("Gray")) && b
pc == 8) { |
446 unsigned char* uncompressedStreamA8 = (unsigned char*)malloc(width * hei
ght); | 441 unsigned char* uncompressedStreamA8 = (unsigned char*)malloc(width * hei
ght); |
447 | 442 |
448 for (int h = 0 ; h < height; h++) { | 443 for (int h = 0 ; h < height; h++) { |
449 long i = width * (h); | 444 long i = width * (h); |
450 for (int w = 0 ; w < width; w++) { | 445 for (int w = 0 ; w < width; w++) { |
451 uncompressedStreamA8[i] = transparencyMask ? 255 - uncompressedS
tream[w] : | 446 uncompressedStreamA8[i] = transparencyMask ? 255 - uncompressedS
tream[w] : |
452 uncompressedStream[
w]; | 447 uncompressedStream[
w]; |
453 i++; | 448 i++; |
454 } | 449 } |
455 uncompressedStream += bytesPerLine; | 450 uncompressedStream += bytesPerLine; |
(...skipping 19 matching lines...) Expand all Loading... |
475 | 470 |
476 static SkBitmap* getImageFromObjectCore(SkPdfContext* pdfContext, SkPdfImageDict
ionary* image, bool transparencyMask) { | 471 static SkBitmap* getImageFromObjectCore(SkPdfContext* pdfContext, SkPdfImageDict
ionary* image, bool transparencyMask) { |
477 if (image == NULL || !image->hasStream()) { | 472 if (image == NULL || !image->hasStream()) { |
478 // TODO(edisonn): report warning to be used in testing. | 473 // TODO(edisonn): report warning to be used in testing. |
479 return NULL; | 474 return NULL; |
480 } | 475 } |
481 | 476 |
482 int bpc = (int)image->BitsPerComponent(pdfContext->fPdfDoc); | 477 int bpc = (int)image->BitsPerComponent(pdfContext->fPdfDoc); |
483 int width = (int)image->Width(pdfContext->fPdfDoc); | 478 int width = (int)image->Width(pdfContext->fPdfDoc); |
484 int height = (int)image->Height(pdfContext->fPdfDoc); | 479 int height = (int)image->Height(pdfContext->fPdfDoc); |
485 std::string colorSpace = "DeviceRGB"; | 480 SkString colorSpace("DeviceRGB"); |
486 | 481 |
487 bool indexed = false; | 482 bool indexed = false; |
488 SkPMColor colors[256]; | 483 SkPMColor colors[256]; |
489 int cnt = 0; | 484 int cnt = 0; |
490 | 485 |
491 // TODO(edisonn): color space can be an array too! | 486 // TODO(edisonn): color space can be an array too! |
492 if (image->isColorSpaceAName(pdfContext->fPdfDoc)) { | 487 if (image->isColorSpaceAName(pdfContext->fPdfDoc)) { |
493 colorSpace = image->getColorSpaceAsName(pdfContext->fPdfDoc); | 488 colorSpace = image->getColorSpaceAsName(pdfContext->fPdfDoc); |
494 } else if (image->isColorSpaceAArray(pdfContext->fPdfDoc)) { | 489 } else if (image->isColorSpaceAArray(pdfContext->fPdfDoc)) { |
495 SkPdfArray* array = image->getColorSpaceAsArray(pdfContext->fPdfDoc); | 490 SkPdfArray* array = image->getColorSpaceAsArray(pdfContext->fPdfDoc); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 531 |
537 if (!stream || !stream->GetFilteredStreamRef(&uncompressedStream, &uncompres
sedStreamLength) || | 532 if (!stream || !stream->GetFilteredStreamRef(&uncompressedStream, &uncompres
sedStreamLength) || |
538 uncompressedStream == NULL || uncompressedStreamLength == 0) { | 533 uncompressedStream == NULL || uncompressedStreamLength == 0) { |
539 // TODO(edisonn): report warning to be used in testing. | 534 // TODO(edisonn): report warning to be used in testing. |
540 return NULL; | 535 return NULL; |
541 } | 536 } |
542 | 537 |
543 SkPdfStreamCommonDictionary* streamDict = (SkPdfStreamCommonDictionary*)stre
am; | 538 SkPdfStreamCommonDictionary* streamDict = (SkPdfStreamCommonDictionary*)stre
am; |
544 | 539 |
545 if (streamDict->has_Filter() && ((streamDict->isFilterAName(NULL) && | 540 if (streamDict->has_Filter() && ((streamDict->isFilterAName(NULL) && |
546 streamDict->getFilterAsName(NULL) == "
DCTDecode") || | 541 streamDict->getFilterAsName(NULL).equa
ls("DCTDecode")) || |
547 (streamDict->isFilterAArray(NULL) && | 542 (streamDict->isFilterAArray(NULL) && |
548 streamDict->getFilterAsArray(NULL)->si
ze() > 0 && | 543 streamDict->getFilterAsArray(NULL)->si
ze() > 0 && |
549 streamDict->getFilterAsArray(NULL)->ob
jAtAIndex(0)->isName() && | 544 streamDict->getFilterAsArray(NULL)->ob
jAtAIndex(0)->isName() && |
550 streamDict->getFilterAsArray(NULL)->ob
jAtAIndex(0)->nameValue2() == "DCTDecode"))) { | 545 streamDict->getFilterAsArray(NULL)->ob
jAtAIndex(0)->nameValue2().equals("DCTDecode")))) { |
551 SkBitmap* bitmap = new SkBitmap(); | 546 SkBitmap* bitmap = new SkBitmap(); |
552 SkImageDecoder::DecodeMemory(uncompressedStream, uncompressedStreamLengt
h, bitmap); | 547 SkImageDecoder::DecodeMemory(uncompressedStream, uncompressedStreamLengt
h, bitmap); |
553 return bitmap; | 548 return bitmap; |
554 } | 549 } |
555 | 550 |
556 | 551 |
557 | 552 |
558 // TODO (edisonn): Fast Jpeg(DCTDecode) draw, or fast PNG(FlateDecode) draw
... | 553 // TODO (edisonn): Fast Jpeg(DCTDecode) draw, or fast PNG(FlateDecode) draw
... |
559 // PdfObject* value = resolveReferenceObject(pdfContext->fPdfDoc, | 554 // PdfObject* value = resolveReferenceObject(pdfContext->fPdfDoc, |
560 // obj.GetDictionary().GetKey(PdfNa
me("Filter"))); | 555 // obj.GetDictionary().GetKey(PdfNa
me("Filter"))); |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 delete tokenizer; | 865 delete tokenizer; |
871 } | 866 } |
872 | 867 |
873 // TODO(edisonn): should we restore the variable stack at the same state? | 868 // TODO(edisonn): should we restore the variable stack at the same state? |
874 // There could be operands left, that could be consumed by a parent tokenize
r when we pop. | 869 // There could be operands left, that could be consumed by a parent tokenize
r when we pop. |
875 PdfOp_Q(pdfContext, canvas, NULL); | 870 PdfOp_Q(pdfContext, canvas, NULL); |
876 | 871 |
877 return kPartial_SkPdfResult; | 872 return kPartial_SkPdfResult; |
878 } | 873 } |
879 | 874 |
880 | |
881 // TODO(edisonn): make sure the pointer is unique | |
882 std::set<const SkPdfNativeObject*> gInRendering; | |
883 | |
884 class CheckRecursiveRendering { | 875 class CheckRecursiveRendering { |
885 const SkPdfNativeObject* fUniqueData; | 876 SkPdfNativeObject* fObj; |
886 public: | 877 public: |
887 CheckRecursiveRendering(const SkPdfNativeObject* obj) : fUniqueData(obj) { | 878 CheckRecursiveRendering(SkPdfNativeObject* obj) : fObj(obj) { |
888 gInRendering.insert(obj); | 879 SkASSERT(!obj->inRendering()); |
| 880 obj->startRendering(); |
889 } | 881 } |
890 | 882 |
891 ~CheckRecursiveRendering() { | 883 ~CheckRecursiveRendering() { |
892 //SkASSERT(fObj.fInRendering); | 884 SkASSERT(fObj->inRendering()); |
893 gInRendering.erase(fUniqueData); | 885 fObj->doneRendering(); |
894 } | 886 } |
895 | 887 |
896 static bool IsInRendering(const SkPdfNativeObject* obj) { | 888 static bool IsInRendering(const SkPdfNativeObject* obj) { |
897 return gInRendering.find(obj) != gInRendering.end(); | 889 return obj->inRendering(); |
898 } | 890 } |
899 }; | 891 }; |
900 | 892 |
901 static SkPdfResult doXObject(SkPdfContext* pdfContext, SkCanvas* canvas, const S
kPdfNativeObject* obj) { | 893 static SkPdfResult doXObject(SkPdfContext* pdfContext, SkCanvas* canvas, SkPdfNa
tiveObject* obj) { |
902 if (CheckRecursiveRendering::IsInRendering(obj)) { | 894 if (CheckRecursiveRendering::IsInRendering(obj)) { |
903 // Oops, corrupt PDF! | 895 // Oops, corrupt PDF! |
904 return kIgnoreError_SkPdfResult; | 896 return kIgnoreError_SkPdfResult; |
905 } | 897 } |
906 | 898 |
907 CheckRecursiveRendering checkRecursion(obj); | 899 CheckRecursiveRendering checkRecursion(obj); |
908 | 900 |
909 switch (pdfContext->fPdfDoc->mapper()->mapXObjectDictionary(obj)) | 901 switch (pdfContext->fPdfDoc->mapper()->mapXObjectDictionary(obj)) |
910 { | 902 { |
911 case kImageDictionary_SkPdfNativeObjectType: | 903 case kImageDictionary_SkPdfNativeObjectType: |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1862 cnt++; | 1854 cnt++; |
1863 } else { | 1855 } else { |
1864 // TODO(edisonn): report error/warning | 1856 // TODO(edisonn): report error/warning |
1865 return kNYI_SkPdfResult; | 1857 return kNYI_SkPdfResult; |
1866 } | 1858 } |
1867 } | 1859 } |
1868 pdfContext->fGraphicsState.fDashArrayLength = cnt; | 1860 pdfContext->fGraphicsState.fDashArrayLength = cnt; |
1869 pdfContext->fGraphicsState.fDashPhase = phase->scalarValue(); | 1861 pdfContext->fGraphicsState.fDashPhase = phase->scalarValue(); |
1870 if (pdfContext->fGraphicsState.fDashPhase == 0) { | 1862 if (pdfContext->fGraphicsState.fDashPhase == 0) { |
1871 // other rules, changes? | 1863 // other rules, changes? |
1872 pdfContext->fGraphicsState.fDashPhase = total; | 1864 pdfContext->fGraphicsState.fDashPhase = SkDoubleToScalar(total); |
1873 } | 1865 } |
1874 | 1866 |
1875 return kOK_SkPdfResult; | 1867 return kOK_SkPdfResult; |
1876 } | 1868 } |
1877 | 1869 |
1878 static SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray
* dash) { | 1870 static SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray
* dash) { |
1879 // TODO(edisonn): verify input | 1871 // TODO(edisonn): verify input |
1880 if (!dash || dash->isArray() || dash->size() != 2 || !dash->objAtAIndex(0)->
isArray() || !dash->objAtAIndex(1)->isNumber()) { | 1872 if (!dash || dash->isArray() || dash->size() != 2 || !dash->objAtAIndex(0)->
isArray() || !dash->objAtAIndex(1)->isNumber()) { |
1881 // TODO(edisonn): report error/warning | 1873 // TODO(edisonn): report error/warning |
1882 return kIgnoreError_SkPdfResult; | 1874 return kIgnoreError_SkPdfResult; |
(...skipping 11 matching lines...) Expand all Loading... |
1894 | 1886 |
1895 | 1887 |
1896 //lineWidth w Set the line width in the graphics state (see “Line Width” on page
152). | 1888 //lineWidth w Set the line width in the graphics state (see “Line Width” on page
152). |
1897 static SkPdfResult PdfOp_w(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1889 static SkPdfResult PdfOp_w(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1898 double lw = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1890 double lw = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1899 return skpdfGraphicsStateApplyLW(pdfContext, lw); | 1891 return skpdfGraphicsStateApplyLW(pdfContext, lw); |
1900 } | 1892 } |
1901 | 1893 |
1902 //lineCap J Set the line cap style in the graphics state (see “Line Cap Style” o
n page 153). | 1894 //lineCap J Set the line cap style in the graphics state (see “Line Cap Style” o
n page 153). |
1903 static SkPdfResult PdfOp_J(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1895 static SkPdfResult PdfOp_J(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1904 int64_t lc = pdfContext->fObjectStack.top()->numberValue(); pdfContext->f
ObjectStack.pop(); | 1896 // TODO(edisonn): round/ceil to int? |
| 1897 int lc = (int)pdfContext->fObjectStack.top()->numberValue(); pdfContext->
fObjectStack.pop(); |
1905 return skpdfGraphicsStateApplyLC(pdfContext, lc); | 1898 return skpdfGraphicsStateApplyLC(pdfContext, lc); |
1906 } | 1899 } |
1907 | 1900 |
1908 //lineJoin j Set the line join style in the graphics state (see “Line Join Style
” on page 153). | 1901 //lineJoin j Set the line join style in the graphics state (see “Line Join Style
” on page 153). |
1909 static SkPdfResult PdfOp_j(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1902 static SkPdfResult PdfOp_j(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1910 double lj = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1903 // TODO(edisonn): round/ceil to int? |
| 1904 int lj = (int)pdfContext->fObjectStack.top()->numberValue(); pdfContext->
fObjectStack.pop(); |
1911 return skpdfGraphicsStateApplyLJ(pdfContext, lj); | 1905 return skpdfGraphicsStateApplyLJ(pdfContext, lj); |
1912 } | 1906 } |
1913 | 1907 |
1914 //miterLimit M Set the miter limit in the graphics state (see “Miter Limit” on p
age 153). | 1908 //miterLimit M Set the miter limit in the graphics state (see “Miter Limit” on p
age 153). |
1915 static SkPdfResult PdfOp_M(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1909 static SkPdfResult PdfOp_M(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
1916 double ml = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); | 1910 double ml = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
1917 return skpdfGraphicsStateApplyML(pdfContext, ml); | 1911 return skpdfGraphicsStateApplyML(pdfContext, ml); |
1918 } | 1912 } |
1919 | 1913 |
1920 //dashArray dashPhase d Set the line dash pattern in the graphics state (see “Li
ne Dash Pattern” on | 1914 //dashArray dashPhase d Set the line dash pattern in the graphics state (see “Li
ne Dash Pattern” on |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1978 | 1972 |
1979 static SkXfermode::Mode xferModeFromBlendMode(const char* blendMode, size_t len)
{ | 1973 static SkXfermode::Mode xferModeFromBlendMode(const char* blendMode, size_t len)
{ |
1980 SkXfermode::Mode mode = (SkXfermode::Mode)(SkXfermode::kLastMode + 1); | 1974 SkXfermode::Mode mode = (SkXfermode::Mode)(SkXfermode::kLastMode + 1); |
1981 if (gPdfBlendModes.find(blendMode, len, &mode)) { | 1975 if (gPdfBlendModes.find(blendMode, len, &mode)) { |
1982 return mode; | 1976 return mode; |
1983 } | 1977 } |
1984 | 1978 |
1985 return (SkXfermode::Mode)(SkXfermode::kLastMode + 1); | 1979 return (SkXfermode::Mode)(SkXfermode::kLastMode + 1); |
1986 } | 1980 } |
1987 | 1981 |
1988 static void skpdfGraphicsStateApplyBM_name(SkPdfContext* pdfContext, const std::
string& blendMode) { | 1982 static void skpdfGraphicsStateApplyBM_name(SkPdfContext* pdfContext, const SkStr
ing& blendMode) { |
1989 SkXfermode::Mode mode = xferModeFromBlendMode(blendMode.c_str(), blendMode.l
ength()); | 1983 SkXfermode::Mode mode = xferModeFromBlendMode(blendMode.c_str(), blendMode.s
ize()); |
1990 if (mode <= SkXfermode::kLastMode) { | 1984 if (mode <= SkXfermode::kLastMode) { |
1991 pdfContext->fGraphicsState.fBlendModesLength = 1; | 1985 pdfContext->fGraphicsState.fBlendModesLength = 1; |
1992 pdfContext->fGraphicsState.fBlendModes[0] = mode; | 1986 pdfContext->fGraphicsState.fBlendModes[0] = mode; |
1993 } else { | 1987 } else { |
1994 // TODO(edisonn): report unknown blend mode | 1988 // TODO(edisonn): report unknown blend mode |
1995 } | 1989 } |
1996 } | 1990 } |
1997 | 1991 |
1998 static void skpdfGraphicsStateApplyBM_array(SkPdfContext* pdfContext, SkPdfArray
* blendModes) { | 1992 static void skpdfGraphicsStateApplyBM_array(SkPdfContext* pdfContext, SkPdfArray
* blendModes) { |
1999 if (!blendModes || blendModes->isArray() || blendModes->size() == 0 || blend
Modes->size() > 256) { | 1993 if (!blendModes || blendModes->isArray() || blendModes->size() == 0 || blend
Modes->size() > 256) { |
(...skipping 26 matching lines...) Expand all Loading... |
2026 if (pdfContext->fPdfDoc->mapper()->mapSoftMaskDictionary(sMask)) { | 2020 if (pdfContext->fPdfDoc->mapper()->mapSoftMaskDictionary(sMask)) { |
2027 pdfContext->fGraphicsState.fSoftMaskDictionary = (SkPdfSoftMaskDictionar
y*)sMask; | 2021 pdfContext->fGraphicsState.fSoftMaskDictionary = (SkPdfSoftMaskDictionar
y*)sMask; |
2028 } else if (pdfContext->fPdfDoc->mapper()->mapSoftMaskImageDictionary(sMask))
{ | 2022 } else if (pdfContext->fPdfDoc->mapper()->mapSoftMaskImageDictionary(sMask))
{ |
2029 SkPdfSoftMaskImageDictionary* smid = (SkPdfSoftMaskImageDictionary*)sMas
k; | 2023 SkPdfSoftMaskImageDictionary* smid = (SkPdfSoftMaskImageDictionary*)sMas
k; |
2030 pdfContext->fGraphicsState.fSMask = getImageFromObject(pdfContext, smid,
true); | 2024 pdfContext->fGraphicsState.fSMask = getImageFromObject(pdfContext, smid,
true); |
2031 } else { | 2025 } else { |
2032 // TODO (edisonn): report error/warning | 2026 // TODO (edisonn): report error/warning |
2033 } | 2027 } |
2034 } | 2028 } |
2035 | 2029 |
2036 static void skpdfGraphicsStateApplySMask_name(SkPdfContext* pdfContext, const st
d::string& sMask) { | 2030 static void skpdfGraphicsStateApplySMask_name(SkPdfContext* pdfContext, const Sk
String& sMask) { |
2037 if (sMask == "None") { | 2031 if (sMask.equals("None")) { |
2038 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; | 2032 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; |
2039 pdfContext->fGraphicsState.fSMask = NULL; | 2033 pdfContext->fGraphicsState.fSMask = NULL; |
2040 return; | 2034 return; |
2041 } | 2035 } |
2042 | 2036 |
2043 //Next, get the ExtGState Dictionary from the Resource Dictionary: | 2037 //Next, get the ExtGState Dictionary from the Resource Dictionary: |
2044 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); | 2038 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); |
2045 | 2039 |
2046 if (extGStateDictionary == NULL) { | 2040 if (extGStateDictionary == NULL) { |
2047 #ifdef PDF_TRACE | 2041 #ifdef PDF_TRACE |
(...skipping 19 matching lines...) Expand all Loading... |
2067 pdfContext->fGraphicsState.fAlphaSource = alphaSource; | 2061 pdfContext->fGraphicsState.fAlphaSource = alphaSource; |
2068 } | 2062 } |
2069 | 2063 |
2070 | 2064 |
2071 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN
ame is | 2065 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN
ame is |
2072 //the name of a graphics state parameter dictionary in the ExtGState subdictiona
ry of the current resource dictionary (see the next section). | 2066 //the name of a graphics state parameter dictionary in the ExtGState subdictiona
ry of the current resource dictionary (see the next section). |
2073 static SkPdfResult PdfOp_gs(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2067 static SkPdfResult PdfOp_gs(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2074 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext->fOb
jectStack.pop(); | 2068 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext->fOb
jectStack.pop(); |
2075 | 2069 |
2076 #ifdef PDF_TRACE | 2070 #ifdef PDF_TRACE |
2077 std::string str; | 2071 SkString str; |
2078 #endif | 2072 #endif |
2079 | 2073 |
2080 //Next, get the ExtGState Dictionary from the Resource Dictionary: | 2074 //Next, get the ExtGState Dictionary from the Resource Dictionary: |
2081 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); | 2075 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); |
2082 | 2076 |
2083 if (extGStateDictionary == NULL) { | 2077 if (extGStateDictionary == NULL) { |
2084 #ifdef PDF_TRACE | 2078 #ifdef PDF_TRACE |
2085 printf("ExtGState is NULL!\n"); | 2079 printf("ExtGState is NULL!\n"); |
2086 #endif | 2080 #endif |
2087 return kIgnoreError_SkPdfResult; | 2081 return kIgnoreError_SkPdfResult; |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2399 class InitPdfOps { | 2393 class InitPdfOps { |
2400 public: | 2394 public: |
2401 InitPdfOps() { | 2395 InitPdfOps() { |
2402 initPdfOperatorRenderes(); | 2396 initPdfOperatorRenderes(); |
2403 } | 2397 } |
2404 }; | 2398 }; |
2405 | 2399 |
2406 InitPdfOps gInitPdfOps; | 2400 InitPdfOps gInitPdfOps; |
2407 | 2401 |
2408 void reportPdfRenderStats() { | 2402 void reportPdfRenderStats() { |
2409 std::map<std::string, int>::iterator iter; | |
2410 | |
2411 for (int i = 0 ; i < kCount_SkPdfResult; i++) { | 2403 for (int i = 0 ; i < kCount_SkPdfResult; i++) { |
2412 SkTDict<int>::Iter iter(gRenderStats[i]); | 2404 SkTDict<int>::Iter iter(gRenderStats[i]); |
2413 const char* key; | 2405 const char* key; |
2414 int value = 0; | 2406 int value = 0; |
2415 while ((key = iter.next(&value)) != NULL) { | 2407 while ((key = iter.next(&value)) != NULL) { |
2416 printf("%s: %s -> count %i\n", gRenderStatsNames[i], key, value); | 2408 printf("%s: %s -> count %i\n", gRenderStatsNames[i], key, value); |
2417 } | 2409 } |
2418 } | 2410 } |
2419 } | 2411 } |
2420 | 2412 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2647 | 2639 |
2648 rect = SkRect::MakeWH(width, height); | 2640 rect = SkRect::MakeWH(width, height); |
2649 | 2641 |
2650 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); | 2642 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); |
2651 | 2643 |
2652 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); | 2644 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); |
2653 SkCanvas canvas(device); | 2645 SkCanvas canvas(device); |
2654 | 2646 |
2655 return renderer.renderPage(page, &canvas, rect); | 2647 return renderer.renderPage(page, &canvas, rect); |
2656 } | 2648 } |
OLD | NEW |