| 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 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 | 661 |
| 662 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); | 662 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); |
| 663 | 663 |
| 664 if (skobj->has_BBox()) { | 664 if (skobj->has_BBox()) { |
| 665 canvas->clipRect(skobj->BBox(pdfContext->fPdfDoc), SkRegion::kIntersect_
Op, true); // TODO(edisonn): AA from settings. | 665 canvas->clipRect(skobj->BBox(pdfContext->fPdfDoc), SkRegion::kIntersect_
Op, true); // TODO(edisonn): AA from settings. |
| 666 } | 666 } |
| 667 | 667 |
| 668 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke
nize it as we go. | 668 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke
nize it as we go. |
| 669 // For this PdfContentsTokenizer needs to be extended. | 669 // For this PdfContentsTokenizer needs to be extended. |
| 670 | 670 |
| 671 // This is a group? |
| 672 if (skobj->has_Group()) { |
| 673 //TransparencyGroupDictionary* ... |
| 674 } |
| 675 |
| 671 SkPdfStream* stream = (SkPdfStream*)skobj; | 676 SkPdfStream* stream = (SkPdfStream*)skobj; |
| 672 | 677 |
| 673 SkPdfNativeTokenizer* tokenizer = | 678 SkPdfNativeTokenizer* tokenizer = |
| 674 pdfContext->fPdfDoc->tokenizerOfStream(stream, pdfContext->fTmpPageA
llocator); | 679 pdfContext->fPdfDoc->tokenizerOfStream(stream, pdfContext->fTmpPageA
llocator); |
| 675 if (tokenizer != NULL) { | 680 if (tokenizer != NULL) { |
| 676 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); | 681 PdfMainLooper looper(NULL, tokenizer, pdfContext, canvas); |
| 677 looper.loop(); | 682 looper.loop(); |
| 678 delete tokenizer; | 683 delete tokenizer; |
| 679 } | 684 } |
| 680 | 685 |
| (...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1575 } | 1580 } |
| 1576 | 1581 |
| 1577 void skpdfGraphicsStateApplyFont(PdfContext* pdfContext, SkPdfArray* fontAndSize
) { | 1582 void skpdfGraphicsStateApplyFont(PdfContext* pdfContext, SkPdfArray* fontAndSize
) { |
| 1578 if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !f
ontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber()
) { | 1583 if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !f
ontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber()
) { |
| 1579 // TODO(edisonn): report error/warning | 1584 // TODO(edisonn): report error/warning |
| 1580 return; | 1585 return; |
| 1581 } | 1586 } |
| 1582 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon
tAndSize->objAtAIndex(1)->numberValue()); | 1587 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon
tAndSize->objAtAIndex(1)->numberValue()); |
| 1583 } | 1588 } |
| 1584 | 1589 |
| 1590 SkTDict<SkXfermode::Mode> gPdfBlendModes(20); |
| 1591 |
| 1592 class InitBlendModes { |
| 1593 public: |
| 1594 InitBlendModes() { |
| 1595 // TODO(edisonn): use the python code generator? |
| 1596 // TABLE 7.2 Standard separable blend modes |
| 1597 gPdfBlendModes.set("Normal", SkXfermode::kSrc_Mode); |
| 1598 gPdfBlendModes.set("Multiply", SkXfermode::kMultiply_Mode); |
| 1599 gPdfBlendModes.set("Screen", SkXfermode::kScreen_Mode); |
| 1600 gPdfBlendModes.set("Overlay", SkXfermode::kOverlay_Mode); |
| 1601 gPdfBlendModes.set("Darken", SkXfermode::kDarken_Mode); |
| 1602 gPdfBlendModes.set("Lighten", SkXfermode::kLighten_Mode); |
| 1603 gPdfBlendModes.set("ColorDodge", SkXfermode::kColorDodge_Mode); |
| 1604 gPdfBlendModes.set("ColorBurn", SkXfermode::kColorBurn_Mode); |
| 1605 gPdfBlendModes.set("HardLight", SkXfermode::kHardLight_Mode); |
| 1606 gPdfBlendModes.set("SoftLight", SkXfermode::kSoftLight_Mode); |
| 1607 gPdfBlendModes.set("Difference", SkXfermode::kDifference_Mode); |
| 1608 gPdfBlendModes.set("Exclusion", SkXfermode::kExclusion_Mode); |
| 1609 |
| 1610 // TABLE 7.3 Standard nonseparable blend modes |
| 1611 gPdfBlendModes.set("Hue", SkXfermode::kHue_Mode); |
| 1612 gPdfBlendModes.set("Saturation", SkXfermode::kSaturation_Mode); |
| 1613 gPdfBlendModes.set("Color", SkXfermode::kColor_Mode); |
| 1614 gPdfBlendModes.set("Luminosity", SkXfermode::kLuminosity_Mode); |
| 1615 } |
| 1616 }; |
| 1617 |
| 1618 InitBlendModes _gDummyInniter; |
| 1619 |
| 1620 SkXfermode::Mode xferModeFromBlendMode(const char* blendMode, size_t len) { |
| 1621 SkXfermode::Mode mode = (SkXfermode::Mode)(SkXfermode::kLastMode + 1); |
| 1622 if (gPdfBlendModes.find(blendMode, len, &mode)) { |
| 1623 return mode; |
| 1624 } |
| 1625 |
| 1626 return (SkXfermode::Mode)(SkXfermode::kLastMode + 1); |
| 1627 } |
| 1628 |
| 1585 void skpdfGraphicsStateApplyBM_name(PdfContext* pdfContext, const std::string& b
lendMode) { | 1629 void skpdfGraphicsStateApplyBM_name(PdfContext* pdfContext, const std::string& b
lendMode) { |
| 1586 // TODO(edisonn): verify input | 1630 SkXfermode::Mode mode = xferModeFromBlendMode(blendMode.c_str(), blendMode.l
ength()); |
| 1631 if (mode <= SkXfermode::kLastMode) { |
| 1632 pdfContext->fGraphicsState.fBlendModesLength = 1; |
| 1633 pdfContext->fGraphicsState.fBlendModes[0] = mode; |
| 1634 } else { |
| 1635 // TODO(edisonn): report unknown blend mode |
| 1636 } |
| 1587 } | 1637 } |
| 1588 | 1638 |
| 1589 void skpdfGraphicsStateApplyBM_array(PdfContext* pdfContext, SkPdfArray* blendMo
des) { | 1639 void skpdfGraphicsStateApplyBM_array(PdfContext* pdfContext, SkPdfArray* blendMo
des) { |
| 1590 // TODO(edisonn): verify input | 1640 if (!blendModes || blendModes->isArray() || blendModes->size() == 0 || blend
Modes->size() > 256) { |
| 1591 } | 1641 // TODO(edisonn): report error/warning |
| 1642 return; |
| 1643 } |
| 1644 SkXfermode::Mode modes[256]; |
| 1645 int cnt = blendModes->size(); |
| 1646 for (int i = 0; i < cnt; i++) { |
| 1647 SkPdfObject* name = blendModes->objAtAIndex(i); |
| 1648 if (!name->isName()) { |
| 1649 // TODO(edisonn): report error/warning |
| 1650 return; |
| 1651 } |
| 1652 SkXfermode::Mode mode = xferModeFromBlendMode(name->c_str(), name->lenst
r()); |
| 1653 if (mode > SkXfermode::kLastMode) { |
| 1654 // TODO(edisonn): report error/warning |
| 1655 return; |
| 1656 } |
| 1657 } |
| 1592 | 1658 |
| 1593 void skpdfGraphicsStateApplySMask_name(PdfContext* pdfContext, const std::string
& sMask) { | 1659 pdfContext->fGraphicsState.fBlendModesLength = cnt; |
| 1594 // TODO(edisonn): verify input | 1660 for (int i = 0; i < cnt; i++) { |
| 1661 pdfContext->fGraphicsState.fBlendModes[i] = modes[i]; |
| 1662 } |
| 1595 } | 1663 } |
| 1596 | 1664 |
| 1597 void skpdfGraphicsStateApplySMask_dict(PdfContext* pdfContext, SkPdfDictionary*
sMask) { | 1665 void skpdfGraphicsStateApplySMask_dict(PdfContext* pdfContext, SkPdfDictionary*
sMask) { |
| 1598 // TODO(edisonn): verify input | 1666 // TODO(edisonn): verify input |
| 1667 if (pdfContext->fPdfDoc->mapper()->mapSoftMaskDictionary(sMask)) { |
| 1668 //SkPdfSoftMaskDictionary* smd = (SkPdfSoftMaskDictionary*)sMask; |
| 1669 // TODO(edisonn): load soft mask |
| 1670 } else if (pdfContext->fPdfDoc->mapper()->mapSoftMaskImageDictionary(sMask))
{ |
| 1671 SkPdfSoftMaskImageDictionary* smid = (SkPdfSoftMaskImageDictionary*)sMas
k; |
| 1672 pdfContext->fGraphicsState.fSMask = getImageFromObject(pdfContext, smid,
true); |
| 1673 // TODO(edisonn): load image soft mask |
| 1674 } else { |
| 1675 // TODO (edisonn): report error/warning |
| 1676 } |
| 1677 } |
| 1678 |
| 1679 void skpdfGraphicsStateApplySMask_name(PdfContext* pdfContext, const std::string
& sMask) { |
| 1680 //Next, get the ExtGState Dictionary from the Resource Dictionary: |
| 1681 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources
->ExtGState(pdfContext->fPdfDoc); |
| 1682 |
| 1683 if (extGStateDictionary == NULL) { |
| 1684 #ifdef PDF_TRACE |
| 1685 printf("ExtGState is NULL!\n"); |
| 1686 #endif |
| 1687 // TODO (edisonn): report error/warning |
| 1688 return; |
| 1689 } |
| 1690 |
| 1691 SkPdfObject* obj = pdfContext->fPdfDoc->resolveReference(extGStateDictionary
->get(sMask.c_str())); |
| 1692 if (!obj || !obj->isDictionary()) { |
| 1693 // TODO (edisonn): report error/warning |
| 1694 return; |
| 1695 } |
| 1696 skpdfGraphicsStateApplySMask_dict(pdfContext, obj->asDictionary()); |
| 1599 } | 1697 } |
| 1600 | 1698 |
| 1601 void skpdfGraphicsStateApplyAIS(PdfContext* pdfContext, bool alphaSource) { | 1699 void skpdfGraphicsStateApplyAIS(PdfContext* pdfContext, bool alphaSource) { |
| 1602 pdfContext->fGraphicsState.fAlphaSource = alphaSource; | 1700 pdfContext->fGraphicsState.fAlphaSource = alphaSource; |
| 1603 } | 1701 } |
| 1604 | 1702 |
| 1605 | 1703 |
| 1606 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN
ame is | 1704 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN
ame is |
| 1607 //the name of a graphics state parameter dictionary in the ExtGState subdictiona
ry of the current resource dictionary (see the next section). | 1705 //the name of a graphics state parameter dictionary in the ExtGState subdictiona
ry of the current resource dictionary (see the next section). |
| 1608 static PdfResult PdfOp_gs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1706 static PdfResult PdfOp_gs(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2209 | 2307 |
| 2210 rect = SkRect::MakeWH(width, height); | 2308 rect = SkRect::MakeWH(width, height); |
| 2211 | 2309 |
| 2212 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); | 2310 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); |
| 2213 | 2311 |
| 2214 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); | 2312 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); |
| 2215 SkCanvas canvas(device); | 2313 SkCanvas canvas(device); |
| 2216 | 2314 |
| 2217 return renderer.renderPage(page, &canvas, rect); | 2315 return renderer.renderPage(page, &canvas, rect); |
| 2218 } | 2316 } |
| OLD | NEW |