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" |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 // skia format, through a table | 472 // skia format, through a table |
473 | 473 |
474 // this functions returns the image, it does not look at the smask. | 474 // this functions returns the image, it does not look at the smask. |
475 | 475 |
476 static SkBitmap* getImageFromObjectCore(SkPdfContext* pdfContext, SkPdfImageDict
ionary* image, bool transparencyMask) { | 476 static SkBitmap* getImageFromObjectCore(SkPdfContext* pdfContext, SkPdfImageDict
ionary* image, bool transparencyMask) { |
477 if (image == NULL || !image->hasStream()) { | 477 if (image == NULL || !image->hasStream()) { |
478 // TODO(edisonn): report warning to be used in testing. | 478 // TODO(edisonn): report warning to be used in testing. |
479 return NULL; | 479 return NULL; |
480 } | 480 } |
481 | 481 |
482 int64_t bpc = image->BitsPerComponent(pdfContext->fPdfDoc); | 482 int bpc = (int)image->BitsPerComponent(pdfContext->fPdfDoc); |
483 int64_t width = image->Width(pdfContext->fPdfDoc); | 483 int width = (int)image->Width(pdfContext->fPdfDoc); |
484 int64_t height = image->Height(pdfContext->fPdfDoc); | 484 int height = (int)image->Height(pdfContext->fPdfDoc); |
485 std::string colorSpace = "DeviceRGB"; | 485 std::string colorSpace = "DeviceRGB"; |
486 | 486 |
487 bool indexed = false; | 487 bool indexed = false; |
488 SkPMColor colors[256]; | 488 SkPMColor colors[256]; |
489 int cnt = 0; | 489 int cnt = 0; |
490 | 490 |
491 // TODO(edisonn): color space can be an array too! | 491 // TODO(edisonn): color space can be an array too! |
492 if (image->isColorSpaceAName(pdfContext->fPdfDoc)) { | 492 if (image->isColorSpaceAName(pdfContext->fPdfDoc)) { |
493 colorSpace = image->getColorSpaceAsName(pdfContext->fPdfDoc); | 493 colorSpace = image->getColorSpaceAsName(pdfContext->fPdfDoc); |
494 } else if (image->isColorSpaceAArray(pdfContext->fPdfDoc)) { | 494 } else if (image->isColorSpaceAArray(pdfContext->fPdfDoc)) { |
495 SkPdfArray* array = image->getColorSpaceAsArray(pdfContext->fPdfDoc); | 495 SkPdfArray* array = image->getColorSpaceAsArray(pdfContext->fPdfDoc); |
496 if (array && array->size() == 4 && array->objAtAIndex(0)->isName("Indexe
d") && | 496 if (array && array->size() == 4 && array->objAtAIndex(0)->isName("Indexe
d") && |
497 (array->objAtAIndex(1)->isName("Devic
eRGB") || array->objAtAIndex(1)->isName("RGB")) && | 497 (array->objAtAIndex(1)->isName("Devic
eRGB") || array->objAtAIndex(1)->isName("RGB")) && |
498 array->objAtAIndex(2)->isInteger() && | 498 array->objAtAIndex(2)->isInteger() && |
499 array->objAtAIndex(3)->isHexString() | 499 array->objAtAIndex(3)->isHexString() |
500 ) { | 500 ) { |
501 // TODO(edisonn): suport only DeviceRGB for now. | 501 // TODO(edisonn): suport only DeviceRGB for now. |
502 indexed = true; | 502 indexed = true; |
503 cnt = array->objAtAIndex(2)->intValue() + 1; | 503 cnt = (int)array->objAtAIndex(2)->intValue() + 1; |
504 if (cnt > 256) { | 504 if (cnt > 256) { |
505 // TODO(edionn): report NYIs | 505 // TODO(edionn): report NYIs |
506 return NULL; | 506 return NULL; |
507 } | 507 } |
508 SkColorTable colorTable(cnt); | 508 SkColorTable colorTable(cnt); |
509 NotOwnedString data = array->objAtAIndex(3)->strRef(); | 509 NotOwnedString data = array->objAtAIndex(3)->strRef(); |
510 if (data.fBytes != (unsigned int)cnt * 3) { | 510 if (data.fBytes != (unsigned int)cnt * 3) { |
511 // TODO(edionn): report error/warning | 511 // TODO(edionn): report error/warning |
512 return NULL; | 512 return NULL; |
513 } | 513 } |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 pdfContext->fGraphicsState.fTextLeading = ty; | 1034 pdfContext->fGraphicsState.fTextLeading = ty; |
1035 | 1035 |
1036 return kOK_SkPdfResult; | 1036 return kOK_SkPdfResult; |
1037 } | 1037 } |
1038 | 1038 |
1039 static SkPdfResult PdfOp_Td(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1039 static SkPdfResult PdfOp_Td(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1040 #ifdef PDF_TRACE | 1040 #ifdef PDF_TRACE |
1041 printf("stack size = %i\n", (int)pdfContext->fObjectStack.size()); | 1041 printf("stack size = %i\n", (int)pdfContext->fObjectStack.size()); |
1042 #endif | 1042 #endif |
1043 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); | 1043 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); |
1044 SkPdfNativeObject* obj = pdfContext->fObjectStack.top(); | |
1045 obj = obj; | |
1046 double tx = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); | 1044 double tx = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); |
1047 | 1045 |
1048 double array[6] = {1, 0, 0, 1, tx, -ty}; | 1046 double array[6] = {1, 0, 0, 1, tx, -ty}; |
1049 SkMatrix matrix = SkMatrixFromPdfMatrix(array); | 1047 SkMatrix matrix = SkMatrixFromPdfMatrix(array); |
1050 | 1048 |
1051 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); | 1049 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); |
1052 pdfContext->fGraphicsState.fMatrixTlm.preConcat(matrix); | 1050 pdfContext->fGraphicsState.fMatrixTlm.preConcat(matrix); |
1053 | 1051 |
1054 return kPartial_SkPdfResult; | 1052 return kPartial_SkPdfResult; |
1055 } | 1053 } |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1438 } | 1436 } |
1439 | 1437 |
1440 static SkPdfResult PdfOp_ET(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1438 static SkPdfResult PdfOp_ET(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1441 if (!pdfContext->fGraphicsState.fTextBlock) { | 1439 if (!pdfContext->fGraphicsState.fTextBlock) { |
1442 return kIgnoreError_SkPdfResult; | 1440 return kIgnoreError_SkPdfResult; |
1443 } | 1441 } |
1444 // TODO(edisonn): anything else to be done once we are done with draw text?
Like restore stack? | 1442 // TODO(edisonn): anything else to be done once we are done with draw text?
Like restore stack? |
1445 return kOK_SkPdfResult; | 1443 return kOK_SkPdfResult; |
1446 } | 1444 } |
1447 | 1445 |
1448 SkPdfResult skpdfGraphicsStateApplyFontCore(SkPdfContext* pdfContext, const SkPd
fNativeObject* fontName, double fontSize) { | 1446 static SkPdfResult skpdfGraphicsStateApplyFontCore(SkPdfContext* pdfContext, con
st SkPdfNativeObject* fontName, double fontSize) { |
1449 #ifdef PDF_TRACE | 1447 #ifdef PDF_TRACE |
1450 printf("font name: %s\n", fontName->nameValue2().c_str()); | 1448 printf("font name: %s\n", fontName->nameValue2().c_str()); |
1451 #endif | 1449 #endif |
1452 | 1450 |
1453 if (!pdfContext->fGraphicsState.fResources->Font(pdfContext->fPdfDoc)) { | 1451 if (!pdfContext->fGraphicsState.fResources->Font(pdfContext->fPdfDoc)) { |
1454 // TODO(edisonn): try to recover and draw it any way? | 1452 // TODO(edisonn): try to recover and draw it any way? |
1455 return kIgnoreError_SkPdfResult; | 1453 return kIgnoreError_SkPdfResult; |
1456 } | 1454 } |
1457 | 1455 |
1458 SkPdfNativeObject* objFont = pdfContext->fGraphicsState.fResources->Font(pdf
Context->fPdfDoc)->get(fontName); | 1456 SkPdfNativeObject* objFont = pdfContext->fGraphicsState.fResources->Font(pdf
Context->fPdfDoc)->get(fontName); |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 static SkPdfResult PdfOp_EI(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1790 static SkPdfResult PdfOp_EI(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1793 #ifdef ASSERT_BAD_PDF_OPS | 1791 #ifdef ASSERT_BAD_PDF_OPS |
1794 SkASSERT(false); // must be processed in inline image looper, but let's | 1792 SkASSERT(false); // must be processed in inline image looper, but let's |
1795 // have the assert when testing good pdfs. | 1793 // have the assert when testing good pdfs. |
1796 #endif | 1794 #endif |
1797 return kIgnoreError_SkPdfResult; | 1795 return kIgnoreError_SkPdfResult; |
1798 } | 1796 } |
1799 | 1797 |
1800 | 1798 |
1801 // TODO(edisonn): security review here, make sure all parameters are valid, and
safe. | 1799 // TODO(edisonn): security review here, make sure all parameters are valid, and
safe. |
1802 SkPdfResult skpdfGraphicsStateApply_ca(SkPdfContext* pdfContext, double ca) { | 1800 static SkPdfResult skpdfGraphicsStateApply_ca(SkPdfContext* pdfContext, double c
a) { |
1803 pdfContext->fGraphicsState.fNonStroking.fOpacity = ca; | 1801 pdfContext->fGraphicsState.fNonStroking.fOpacity = ca; |
1804 return kOK_SkPdfResult; | 1802 return kOK_SkPdfResult; |
1805 } | 1803 } |
1806 | 1804 |
1807 SkPdfResult skpdfGraphicsStateApply_CA(SkPdfContext* pdfContext, double CA) { | 1805 static SkPdfResult skpdfGraphicsStateApply_CA(SkPdfContext* pdfContext, double C
A) { |
1808 pdfContext->fGraphicsState.fStroking.fOpacity = CA; | 1806 pdfContext->fGraphicsState.fStroking.fOpacity = CA; |
1809 return kOK_SkPdfResult; | 1807 return kOK_SkPdfResult; |
1810 } | 1808 } |
1811 | 1809 |
1812 SkPdfResult skpdfGraphicsStateApplyLW(SkPdfContext* pdfContext, double lineWidth
) { | 1810 static SkPdfResult skpdfGraphicsStateApplyLW(SkPdfContext* pdfContext, double li
neWidth) { |
1813 pdfContext->fGraphicsState.fLineWidth = lineWidth; | 1811 pdfContext->fGraphicsState.fLineWidth = lineWidth; |
1814 return kOK_SkPdfResult; | 1812 return kOK_SkPdfResult; |
1815 } | 1813 } |
1816 | 1814 |
1817 SkPdfResult skpdfGraphicsStateApplyLC(SkPdfContext* pdfContext, int64_t lineCap)
{ | 1815 static SkPdfResult skpdfGraphicsStateApplyLC(SkPdfContext* pdfContext, int64_t l
ineCap) { |
1818 pdfContext->fGraphicsState.fLineCap = (int)lineCap; | 1816 pdfContext->fGraphicsState.fLineCap = (int)lineCap; |
1819 return kOK_SkPdfResult; | 1817 return kOK_SkPdfResult; |
1820 } | 1818 } |
1821 | 1819 |
1822 SkPdfResult skpdfGraphicsStateApplyLJ(SkPdfContext* pdfContext, int64_t lineJoin
) { | 1820 static SkPdfResult skpdfGraphicsStateApplyLJ(SkPdfContext* pdfContext, int64_t l
ineJoin) { |
1823 pdfContext->fGraphicsState.fLineJoin = (int)lineJoin; | 1821 pdfContext->fGraphicsState.fLineJoin = (int)lineJoin; |
1824 return kOK_SkPdfResult; | 1822 return kOK_SkPdfResult; |
1825 } | 1823 } |
1826 | 1824 |
1827 SkPdfResult skpdfGraphicsStateApplyML(SkPdfContext* pdfContext, double miterLimi
t) { | 1825 static SkPdfResult skpdfGraphicsStateApplyML(SkPdfContext* pdfContext, double mi
terLimit) { |
1828 pdfContext->fGraphicsState.fMiterLimit = miterLimit; | 1826 pdfContext->fGraphicsState.fMiterLimit = miterLimit; |
1829 return kOK_SkPdfResult; | 1827 return kOK_SkPdfResult; |
1830 } | 1828 } |
1831 | 1829 |
1832 // TODO(edisonn): implement all rules, as of now 3) and 5) and 6) do not seem su
ported by skia, but I am not sure | 1830 // TODO(edisonn): implement all rules, as of now 3) and 5) and 6) do not seem su
ported by skia, but I am not sure |
1833 /* | 1831 /* |
1834 1) [ ] 0 No dash; solid, unbroken lines | 1832 1) [ ] 0 No dash; solid, unbroken lines |
1835 2) [3] 0 3 units on, 3 units off, … | 1833 2) [3] 0 3 units on, 3 units off, … |
1836 3) [2] 1 1 on, 2 off, 2 on, 2 off, … | 1834 3) [2] 1 1 on, 2 off, 2 on, 2 off, … |
1837 4) [2 1] 0 2 on, 1 off, 2 on, 1 off, … | 1835 4) [2 1] 0 2 on, 1 off, 2 on, 1 off, … |
1838 5) [3 5] 6 2 off, 3 on, 5 off, 3 on, 5 off, … | 1836 5) [3 5] 6 2 off, 3 on, 5 off, 3 on, 5 off, … |
1839 6) [2 3] 11 1 on, 3 off, 2 on, 3 off, 2 on, … | 1837 6) [2 3] 11 1 on, 3 off, 2 on, 3 off, 2 on, … |
1840 */ | 1838 */ |
1841 | 1839 |
1842 SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray* inter
vals, SkPdfNativeObject* phase) { | 1840 static SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray
* intervals, SkPdfNativeObject* phase) { |
1843 int cnt = intervals->size(); | 1841 int cnt = intervals->size(); |
1844 if (cnt >= 256) { | 1842 if (cnt >= 256) { |
1845 // TODO(edisonn): report error/warning, unsuported; | 1843 // TODO(edisonn): report error/warning, unsuported; |
1846 // TODO(edisonn): alloc memory | 1844 // TODO(edisonn): alloc memory |
1847 return kIgnoreError_SkPdfResult; | 1845 return kIgnoreError_SkPdfResult; |
1848 } | 1846 } |
1849 for (int i = 0; i < cnt; i++) { | 1847 for (int i = 0; i < cnt; i++) { |
1850 if (!intervals->objAtAIndex(i)->isNumber()) { | 1848 if (!intervals->objAtAIndex(i)->isNumber()) { |
1851 // TODO(edisonn): report error/warning | 1849 // TODO(edisonn): report error/warning |
1852 return kIgnoreError_SkPdfResult; | 1850 return kIgnoreError_SkPdfResult; |
(...skipping 17 matching lines...) Expand all Loading... |
1870 pdfContext->fGraphicsState.fDashArrayLength = cnt; | 1868 pdfContext->fGraphicsState.fDashArrayLength = cnt; |
1871 pdfContext->fGraphicsState.fDashPhase = phase->scalarValue(); | 1869 pdfContext->fGraphicsState.fDashPhase = phase->scalarValue(); |
1872 if (pdfContext->fGraphicsState.fDashPhase == 0) { | 1870 if (pdfContext->fGraphicsState.fDashPhase == 0) { |
1873 // other rules, changes? | 1871 // other rules, changes? |
1874 pdfContext->fGraphicsState.fDashPhase = total; | 1872 pdfContext->fGraphicsState.fDashPhase = total; |
1875 } | 1873 } |
1876 | 1874 |
1877 return kOK_SkPdfResult; | 1875 return kOK_SkPdfResult; |
1878 } | 1876 } |
1879 | 1877 |
1880 SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray* dash)
{ | 1878 static SkPdfResult skpdfGraphicsStateApplyD(SkPdfContext* pdfContext, SkPdfArray
* dash) { |
1881 // TODO(edisonn): verify input | 1879 // TODO(edisonn): verify input |
1882 if (!dash || dash->isArray() || dash->size() != 2 || !dash->objAtAIndex(0)->
isArray() || !dash->objAtAIndex(1)->isNumber()) { | 1880 if (!dash || dash->isArray() || dash->size() != 2 || !dash->objAtAIndex(0)->
isArray() || !dash->objAtAIndex(1)->isNumber()) { |
1883 // TODO(edisonn): report error/warning | 1881 // TODO(edisonn): report error/warning |
1884 return kIgnoreError_SkPdfResult; | 1882 return kIgnoreError_SkPdfResult; |
1885 } | 1883 } |
1886 return skpdfGraphicsStateApplyD(pdfContext, (SkPdfArray*)dash->objAtAIndex(0
), dash->objAtAIndex(1)); | 1884 return skpdfGraphicsStateApplyD(pdfContext, (SkPdfArray*)dash->objAtAIndex(0
), dash->objAtAIndex(1)); |
1887 } | 1885 } |
1888 | 1886 |
1889 void skpdfGraphicsStateApplyFont(SkPdfContext* pdfContext, SkPdfArray* fontAndSi
ze) { | 1887 static void skpdfGraphicsStateApplyFont(SkPdfContext* pdfContext, SkPdfArray* fo
ntAndSize) { |
1890 if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !f
ontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber()
) { | 1888 if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !f
ontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber()
) { |
1891 // TODO(edisonn): report error/warning | 1889 // TODO(edisonn): report error/warning |
1892 return; | 1890 return; |
1893 } | 1891 } |
1894 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon
tAndSize->objAtAIndex(1)->numberValue()); | 1892 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon
tAndSize->objAtAIndex(1)->numberValue()); |
1895 } | 1893 } |
1896 | 1894 |
1897 | 1895 |
1898 //lineWidth w Set the line width in the graphics state (see “Line Width” on page
152). | 1896 //lineWidth w Set the line width in the graphics state (see “Line Width” on page
152). |
1899 static SkPdfResult PdfOp_w(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { | 1897 static SkPdfResult PdfOp_w(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenL
ooper** looper) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1971 // TABLE 7.3 Standard nonseparable blend modes | 1969 // TABLE 7.3 Standard nonseparable blend modes |
1972 gPdfBlendModes.set("Hue", SkXfermode::kHue_Mode); | 1970 gPdfBlendModes.set("Hue", SkXfermode::kHue_Mode); |
1973 gPdfBlendModes.set("Saturation", SkXfermode::kSaturation_Mode); | 1971 gPdfBlendModes.set("Saturation", SkXfermode::kSaturation_Mode); |
1974 gPdfBlendModes.set("Color", SkXfermode::kColor_Mode); | 1972 gPdfBlendModes.set("Color", SkXfermode::kColor_Mode); |
1975 gPdfBlendModes.set("Luminosity", SkXfermode::kLuminosity_Mode); | 1973 gPdfBlendModes.set("Luminosity", SkXfermode::kLuminosity_Mode); |
1976 } | 1974 } |
1977 }; | 1975 }; |
1978 | 1976 |
1979 InitBlendModes _gDummyInniter; | 1977 InitBlendModes _gDummyInniter; |
1980 | 1978 |
1981 SkXfermode::Mode xferModeFromBlendMode(const char* blendMode, size_t len) { | 1979 static SkXfermode::Mode xferModeFromBlendMode(const char* blendMode, size_t len)
{ |
1982 SkXfermode::Mode mode = (SkXfermode::Mode)(SkXfermode::kLastMode + 1); | 1980 SkXfermode::Mode mode = (SkXfermode::Mode)(SkXfermode::kLastMode + 1); |
1983 if (gPdfBlendModes.find(blendMode, len, &mode)) { | 1981 if (gPdfBlendModes.find(blendMode, len, &mode)) { |
1984 return mode; | 1982 return mode; |
1985 } | 1983 } |
1986 | 1984 |
1987 return (SkXfermode::Mode)(SkXfermode::kLastMode + 1); | 1985 return (SkXfermode::Mode)(SkXfermode::kLastMode + 1); |
1988 } | 1986 } |
1989 | 1987 |
1990 void skpdfGraphicsStateApplyBM_name(SkPdfContext* pdfContext, const std::string&
blendMode) { | 1988 static void skpdfGraphicsStateApplyBM_name(SkPdfContext* pdfContext, const std::
string& blendMode) { |
1991 SkXfermode::Mode mode = xferModeFromBlendMode(blendMode.c_str(), blendMode.l
ength()); | 1989 SkXfermode::Mode mode = xferModeFromBlendMode(blendMode.c_str(), blendMode.l
ength()); |
1992 if (mode <= SkXfermode::kLastMode) { | 1990 if (mode <= SkXfermode::kLastMode) { |
1993 pdfContext->fGraphicsState.fBlendModesLength = 1; | 1991 pdfContext->fGraphicsState.fBlendModesLength = 1; |
1994 pdfContext->fGraphicsState.fBlendModes[0] = mode; | 1992 pdfContext->fGraphicsState.fBlendModes[0] = mode; |
1995 } else { | 1993 } else { |
1996 // TODO(edisonn): report unknown blend mode | 1994 // TODO(edisonn): report unknown blend mode |
1997 } | 1995 } |
1998 } | 1996 } |
1999 | 1997 |
2000 void skpdfGraphicsStateApplyBM_array(SkPdfContext* pdfContext, SkPdfArray* blend
Modes) { | 1998 static void skpdfGraphicsStateApplyBM_array(SkPdfContext* pdfContext, SkPdfArray
* blendModes) { |
2001 if (!blendModes || blendModes->isArray() || blendModes->size() == 0 || blend
Modes->size() > 256) { | 1999 if (!blendModes || blendModes->isArray() || blendModes->size() == 0 || blend
Modes->size() > 256) { |
2002 // TODO(edisonn): report error/warning | 2000 // TODO(edisonn): report error/warning |
2003 return; | 2001 return; |
2004 } | 2002 } |
2005 SkXfermode::Mode modes[256]; | 2003 SkXfermode::Mode modes[256]; |
2006 int cnt = blendModes->size(); | 2004 int cnt = blendModes->size(); |
2007 for (int i = 0; i < cnt; i++) { | 2005 for (int i = 0; i < cnt; i++) { |
2008 SkPdfNativeObject* name = blendModes->objAtAIndex(i); | 2006 SkPdfNativeObject* name = blendModes->objAtAIndex(i); |
2009 if (!name->isName()) { | 2007 if (!name->isName()) { |
2010 // TODO(edisonn): report error/warning | 2008 // TODO(edisonn): report error/warning |
2011 return; | 2009 return; |
2012 } | 2010 } |
2013 SkXfermode::Mode mode = xferModeFromBlendMode(name->c_str(), name->lenst
r()); | 2011 SkXfermode::Mode mode = xferModeFromBlendMode(name->c_str(), name->lenst
r()); |
2014 if (mode > SkXfermode::kLastMode) { | 2012 if (mode > SkXfermode::kLastMode) { |
2015 // TODO(edisonn): report error/warning | 2013 // TODO(edisonn): report error/warning |
2016 return; | 2014 return; |
2017 } | 2015 } |
2018 } | 2016 } |
2019 | 2017 |
2020 pdfContext->fGraphicsState.fBlendModesLength = cnt; | 2018 pdfContext->fGraphicsState.fBlendModesLength = cnt; |
2021 for (int i = 0; i < cnt; i++) { | 2019 for (int i = 0; i < cnt; i++) { |
2022 pdfContext->fGraphicsState.fBlendModes[i] = modes[i]; | 2020 pdfContext->fGraphicsState.fBlendModes[i] = modes[i]; |
2023 } | 2021 } |
2024 } | 2022 } |
2025 | 2023 |
2026 void skpdfGraphicsStateApplySMask_dict(SkPdfContext* pdfContext, SkPdfDictionary
* sMask) { | 2024 static void skpdfGraphicsStateApplySMask_dict(SkPdfContext* pdfContext, SkPdfDic
tionary* sMask) { |
2027 // TODO(edisonn): verify input | 2025 // TODO(edisonn): verify input |
2028 if (pdfContext->fPdfDoc->mapper()->mapSoftMaskDictionary(sMask)) { | 2026 if (pdfContext->fPdfDoc->mapper()->mapSoftMaskDictionary(sMask)) { |
2029 pdfContext->fGraphicsState.fSoftMaskDictionary = (SkPdfSoftMaskDictionar
y*)sMask; | 2027 pdfContext->fGraphicsState.fSoftMaskDictionary = (SkPdfSoftMaskDictionar
y*)sMask; |
2030 } else if (pdfContext->fPdfDoc->mapper()->mapSoftMaskImageDictionary(sMask))
{ | 2028 } else if (pdfContext->fPdfDoc->mapper()->mapSoftMaskImageDictionary(sMask))
{ |
2031 SkPdfSoftMaskImageDictionary* smid = (SkPdfSoftMaskImageDictionary*)sMas
k; | 2029 SkPdfSoftMaskImageDictionary* smid = (SkPdfSoftMaskImageDictionary*)sMas
k; |
2032 pdfContext->fGraphicsState.fSMask = getImageFromObject(pdfContext, smid,
true); | 2030 pdfContext->fGraphicsState.fSMask = getImageFromObject(pdfContext, smid,
true); |
2033 } else { | 2031 } else { |
2034 // TODO (edisonn): report error/warning | 2032 // TODO (edisonn): report error/warning |
2035 } | 2033 } |
2036 } | 2034 } |
2037 | 2035 |
2038 void skpdfGraphicsStateApplySMask_name(SkPdfContext* pdfContext, const std::stri
ng& sMask) { | 2036 static void skpdfGraphicsStateApplySMask_name(SkPdfContext* pdfContext, const st
d::string& sMask) { |
2039 if (sMask == "None") { | 2037 if (sMask == "None") { |
2040 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; | 2038 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; |
2041 pdfContext->fGraphicsState.fSMask = NULL; | 2039 pdfContext->fGraphicsState.fSMask = NULL; |
2042 return; | 2040 return; |
2043 } | 2041 } |
2044 | 2042 |
2045 //Next, get the ExtGState Dictionary from the Resource Dictionary: | 2043 //Next, get the ExtGState Dictionary from the Resource Dictionary: |
2046 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); | 2044 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); |
2047 | 2045 |
2048 if (extGStateDictionary == NULL) { | 2046 if (extGStateDictionary == NULL) { |
2049 #ifdef PDF_TRACE | 2047 #ifdef PDF_TRACE |
2050 printf("ExtGState is NULL!\n"); | 2048 printf("ExtGState is NULL!\n"); |
2051 #endif | 2049 #endif |
2052 // TODO (edisonn): report error/warning | 2050 // TODO (edisonn): report error/warning |
2053 return; | 2051 return; |
2054 } | 2052 } |
2055 | 2053 |
2056 SkPdfNativeObject* obj = pdfContext->fPdfDoc->resolveReference(extGStateDict
ionary->get(sMask.c_str())); | 2054 SkPdfNativeObject* obj = pdfContext->fPdfDoc->resolveReference(extGStateDict
ionary->get(sMask.c_str())); |
2057 if (!obj || !obj->isDictionary()) { | 2055 if (!obj || !obj->isDictionary()) { |
2058 // TODO (edisonn): report error/warning | 2056 // TODO (edisonn): report error/warning |
2059 return; | 2057 return; |
2060 } | 2058 } |
2061 | 2059 |
2062 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; | 2060 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; |
2063 pdfContext->fGraphicsState.fSMask = NULL; | 2061 pdfContext->fGraphicsState.fSMask = NULL; |
2064 | 2062 |
2065 skpdfGraphicsStateApplySMask_dict(pdfContext, obj->asDictionary()); | 2063 skpdfGraphicsStateApplySMask_dict(pdfContext, obj->asDictionary()); |
2066 } | 2064 } |
2067 | 2065 |
2068 void skpdfGraphicsStateApplyAIS(SkPdfContext* pdfContext, bool alphaSource) { | 2066 static void skpdfGraphicsStateApplyAIS(SkPdfContext* pdfContext, bool alphaSourc
e) { |
2069 pdfContext->fGraphicsState.fAlphaSource = alphaSource; | 2067 pdfContext->fGraphicsState.fAlphaSource = alphaSource; |
2070 } | 2068 } |
2071 | 2069 |
2072 | 2070 |
2073 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN
ame is | 2071 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN
ame is |
2074 //the name of a graphics state parameter dictionary in the ExtGState subdictiona
ry of the current resource dictionary (see the next section). | 2072 //the name of a graphics state parameter dictionary in the ExtGState subdictiona
ry of the current resource dictionary (see the next section). |
2075 static SkPdfResult PdfOp_gs(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 2073 static SkPdfResult PdfOp_gs(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
2076 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext->fOb
jectStack.pop(); | 2074 SkPdfNativeObject* name = pdfContext->fObjectStack.top(); pdfContext->fOb
jectStack.pop(); |
2077 | 2075 |
2078 #ifdef PDF_TRACE | 2076 #ifdef PDF_TRACE |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2649 | 2647 |
2650 rect = SkRect::MakeWH(width, height); | 2648 rect = SkRect::MakeWH(width, height); |
2651 | 2649 |
2652 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); | 2650 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); |
2653 | 2651 |
2654 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); | 2652 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); |
2655 SkCanvas canvas(device); | 2653 SkCanvas canvas(device); |
2656 | 2654 |
2657 return renderer.renderPage(page, &canvas, rect); | 2655 return renderer.renderPage(page, &canvas, rect); |
2658 } | 2656 } |
OLD | NEW |