OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkPDFDevice.h" | 8 #include "SkPDFDevice.h" |
9 | 9 |
10 #include "SkAnnotation.h" | 10 #include "SkAnnotation.h" |
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1127 fLastMarginContentEntry = contentEntry; | 1127 fLastMarginContentEntry = contentEntry; |
1128 } | 1128 } |
1129 } | 1129 } |
1130 | 1130 |
1131 void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) { | 1131 void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) { |
1132 // A ScopedContentEntry only exists during the course of a draw call, so | 1132 // A ScopedContentEntry only exists during the course of a draw call, so |
1133 // this can't be called while a ScopedContentEntry exists. | 1133 // this can't be called while a ScopedContentEntry exists. |
1134 fDrawingArea = drawingArea; | 1134 fDrawingArea = drawingArea; |
1135 } | 1135 } |
1136 | 1136 |
1137 SkPDFDict* SkPDFDevice::getResourceDict() { | 1137 SkPDFDict* SkPDFDevice::getResourceDict() { |
vandebo (ex-Chrome)
2013/07/09 17:47:44
Should getResourceDict and getResources be combine
ducky
2013/07/10 21:42:26
Done.
| |
1138 if (NULL == fResourceDict) { | 1138 if (NULL == fResourceDict) { |
1139 fResourceDict = SkNEW(SkPDFDict); | 1139 fResourceDict = SkNEW(SkPDFDict); |
1140 | 1140 |
1141 if (fGraphicStateResources.count()) { | 1141 if (fGraphicStateResources.count()) { |
1142 SkAutoTUnref<SkPDFDict> extGState(new SkPDFDict()); | 1142 SkAutoTUnref<SkPDFDict> extGState(new SkPDFDict()); |
1143 for (int i = 0; i < fGraphicStateResources.count(); i++) { | 1143 for (int i = 0; i < fGraphicStateResources.count(); i++) { |
1144 SkString nameString("G"); | 1144 SkString nameString("G"); |
1145 nameString.appendS32(i); | 1145 nameString.appendS32(i); |
1146 extGState->insert( | 1146 extGState->insert( |
1147 nameString.c_str(), | 1147 nameString.c_str(), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1179 SkString nameString("P"); | 1179 SkString nameString("P"); |
1180 nameString.appendS32(i); | 1180 nameString.appendS32(i); |
1181 patterns->insert(nameString.c_str(), | 1181 patterns->insert(nameString.c_str(), |
1182 new SkPDFObjRef(fShaderResources[i]))->unref(); | 1182 new SkPDFObjRef(fShaderResources[i]))->unref(); |
1183 } | 1183 } |
1184 fResourceDict->insert("Pattern", patterns.get()); | 1184 fResourceDict->insert("Pattern", patterns.get()); |
1185 } | 1185 } |
1186 | 1186 |
1187 // For compatibility, add all proc sets (only used for output to PS | 1187 // For compatibility, add all proc sets (only used for output to PS |
1188 // devices). | 1188 // devices). |
1189 const char procs[][7] = {"PDF", "Text", "ImageB", "ImageC", "ImageI"}; | 1189 fResourceDict->insert("ProcSet", SkPDFUtils::CreateFullProcSetsArray())- >unref(); |
1190 SkAutoTUnref<SkPDFArray> procSets(new SkPDFArray()); | |
1191 procSets->reserve(SK_ARRAY_COUNT(procs)); | |
1192 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); i++) | |
1193 procSets->appendName(procs[i]); | |
1194 fResourceDict->insert("ProcSet", procSets.get()); | |
1195 } | 1190 } |
1196 return fResourceDict; | 1191 return fResourceDict; |
1197 } | 1192 } |
1198 | 1193 |
1199 void SkPDFDevice::getResources(const SkTSet<SkPDFObject*>& knownResourceObjects, | 1194 void SkPDFDevice::getResources(const SkTSet<SkPDFObject*>& knownResourceObjects, |
1200 SkTSet<SkPDFObject*>* newResourceObjects, | 1195 SkTSet<SkPDFObject*>* newResourceObjects, |
1201 bool recursive) const { | 1196 bool recursive) const { |
1202 // TODO: reserve not correct if we need to recursively explore. | 1197 // TODO: reserve not correct if we need to recursively explore. |
1203 newResourceObjects->setReserve(newResourceObjects->count() + | 1198 newResourceObjects->setReserve(newResourceObjects->count() + |
1204 fGraphicStateResources.count() + | 1199 fGraphicStateResources.count() + |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1484 SkMatrix identity; | 1479 SkMatrix identity; |
1485 identity.reset(); | 1480 identity.reset(); |
1486 SkDraw draw; | 1481 SkDraw draw; |
1487 draw.fMatrix = &identity; | 1482 draw.fMatrix = &identity; |
1488 draw.fClip = &clipRegion; | 1483 draw.fClip = &clipRegion; |
1489 draw.fClipStack = clipStack; | 1484 draw.fClipStack = clipStack; |
1490 SkPaint stockPaint; | 1485 SkPaint stockPaint; |
1491 this->drawPaint(draw, stockPaint); | 1486 this->drawPaint(draw, stockPaint); |
1492 SkAutoTUnref<SkPDFFormXObject> maskFormXObject(createFormXObjectFromDevice() ); | 1487 SkAutoTUnref<SkPDFFormXObject> maskFormXObject(createFormXObjectFromDevice() ); |
1493 SkAutoTUnref<SkPDFGraphicState> sMaskGS( | 1488 SkAutoTUnref<SkPDFGraphicState> sMaskGS( |
1494 SkPDFGraphicState::GetSMaskGraphicState(maskFormXObject, invertClip)); | 1489 SkPDFGraphicState::GetSMaskGraphicState(maskFormXObject, invertClip, |
1490 SkPDFGraphicState::kAlpha_SMaskM ode)); | |
1495 | 1491 |
1496 // Draw the xobject with the clip as a mask. | 1492 // Draw the xobject with the clip as a mask. |
1497 ScopedContentEntry content(this, &fExistingClipStack, fExistingClipRegion, | 1493 ScopedContentEntry content(this, &fExistingClipStack, fExistingClipRegion, |
1498 identity, stockPaint); | 1494 identity, stockPaint); |
1499 if (!content.entry()) { | 1495 if (!content.entry()) { |
1500 return; | 1496 return; |
1501 } | 1497 } |
1502 SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), | 1498 SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), |
1503 &content.entry()->fContent); | 1499 &content.entry()->fContent); |
1504 SkPDFUtils::DrawFormXObject(fXObjectResources.count(), | 1500 SkPDFUtils::DrawFormXObject(fXObjectResources.count(), |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1640 fExistingClipRegion, identity, | 1636 fExistingClipRegion, identity, |
1641 stockPaint); | 1637 stockPaint); |
1642 if (!inClipContentEntry.entry()) { | 1638 if (!inClipContentEntry.entry()) { |
1643 return; | 1639 return; |
1644 } | 1640 } |
1645 | 1641 |
1646 SkAutoTUnref<SkPDFGraphicState> sMaskGS; | 1642 SkAutoTUnref<SkPDFGraphicState> sMaskGS; |
1647 if (xfermode == SkXfermode::kSrcIn_Mode || | 1643 if (xfermode == SkXfermode::kSrcIn_Mode || |
1648 xfermode == SkXfermode::kSrcOut_Mode) { | 1644 xfermode == SkXfermode::kSrcOut_Mode) { |
1649 sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState( | 1645 sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState( |
1650 dst, xfermode == SkXfermode::kSrcOut_Mode)); | 1646 dst, |
1647 xfermode == SkXfermode::kSrcOut_Mode, | |
1648 SkPDFGraphicState::kAlpha_SMaskMode)); | |
1651 fXObjectResources.push(srcFormXObject.get()); | 1649 fXObjectResources.push(srcFormXObject.get()); |
1652 srcFormXObject.get()->ref(); | 1650 srcFormXObject.get()->ref(); |
1653 } else { | 1651 } else { |
1654 sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState( | 1652 sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState( |
1655 srcFormXObject.get(), xfermode == SkXfermode::kDstOut_Mode)); | 1653 srcFormXObject.get(), |
1654 xfermode == SkXfermode::kDstOut_Mode, | |
1655 SkPDFGraphicState::kAlpha_SMaskMode)); | |
1656 // dst already added to fXObjectResources in drawFormXObjectWithClip. | 1656 // dst already added to fXObjectResources in drawFormXObjectWithClip. |
1657 } | 1657 } |
1658 SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), | 1658 SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), |
1659 &inClipContentEntry.entry()->fContent); | 1659 &inClipContentEntry.entry()->fContent); |
1660 | 1660 |
1661 SkPDFUtils::DrawFormXObject(fXObjectResources.count() - 1, | 1661 SkPDFUtils::DrawFormXObject(fXObjectResources.count() - 1, |
1662 &inClipContentEntry.entry()->fContent); | 1662 &inClipContentEntry.entry()->fContent); |
1663 | 1663 |
1664 sMaskGS.reset(SkPDFGraphicState::GetNoSMaskGraphicState()); | 1664 sMaskGS.reset(SkPDFGraphicState::GetNoSMaskGraphicState()); |
1665 SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), | 1665 SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1837 } | 1837 } |
1838 | 1838 |
1839 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, | 1839 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, |
1840 SkCanvas::Config8888) { | 1840 SkCanvas::Config8888) { |
1841 return false; | 1841 return false; |
1842 } | 1842 } |
1843 | 1843 |
1844 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { | 1844 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { |
1845 return false; | 1845 return false; |
1846 } | 1846 } |
OLD | NEW |