| Index: src/pdf/SkPDFDevice.cpp
|
| diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
|
| index f925980c94b5c0ea9497d076459c71791142e513..a8fc3990d8694197039e239a4546f2dbee831540 100644
|
| --- a/src/pdf/SkPDFDevice.cpp
|
| +++ b/src/pdf/SkPDFDevice.cpp
|
| @@ -20,7 +20,6 @@
|
| #include "SkPDFFormXObject.h"
|
| #include "SkPDFGraphicState.h"
|
| #include "SkPDFImage.h"
|
| -#include "SkPDFResourceDict.h"
|
| #include "SkPDFShader.h"
|
| #include "SkPDFStream.h"
|
| #include "SkPDFTypes.h"
|
| @@ -425,13 +424,10 @@ void GraphicStackState::updateDrawingState(const GraphicStateEntry& state) {
|
| // PDF treats a shader as a color, so we only set one or the other.
|
| if (state.fShaderIndex >= 0) {
|
| if (state.fShaderIndex != currentEntry()->fShaderIndex) {
|
| - SkString resourceName = SkPDFResourceDict::getResourceName(
|
| - SkPDFResourceDict::kPattern_ResourceType,
|
| - state.fShaderIndex);
|
| - fContentStream->writeText("/Pattern CS /Pattern cs /");
|
| - fContentStream->writeText(resourceName.c_str());
|
| - fContentStream->writeText(" SCN /");
|
| - fContentStream->writeText(resourceName.c_str());
|
| + fContentStream->writeText("/Pattern CS /Pattern cs /P");
|
| + fContentStream->writeDecAsText(state.fShaderIndex);
|
| + fContentStream->writeText(" SCN /P");
|
| + fContentStream->writeDecAsText(state.fShaderIndex);
|
| fContentStream->writeText(" scn\n");
|
| currentEntry()->fShaderIndex = state.fShaderIndex;
|
| }
|
| @@ -1127,46 +1123,123 @@ void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) {
|
| fDrawingArea = drawingArea;
|
| }
|
|
|
| -SkPDFResourceDict* SkPDFDevice::getResourceDict() {
|
| +SkPDFDict* SkPDFDevice::getResourceDict() {
|
| if (NULL == fResourceDict) {
|
| - fResourceDict = SkNEW(SkPDFResourceDict);
|
| + fResourceDict = SkNEW(SkPDFDict);
|
|
|
| if (fGraphicStateResources.count()) {
|
| + SkAutoTUnref<SkPDFDict> extGState(new SkPDFDict());
|
| for (int i = 0; i < fGraphicStateResources.count(); i++) {
|
| - fResourceDict->insertResourceAsRef(
|
| - SkPDFResourceDict::kExtGState_ResourceType,
|
| - i, fGraphicStateResources[i]);
|
| + SkString nameString("G");
|
| + nameString.appendS32(i);
|
| + extGState->insert(
|
| + nameString.c_str(),
|
| + new SkPDFObjRef(fGraphicStateResources[i]))->unref();
|
| }
|
| + fResourceDict->insert("ExtGState", extGState.get());
|
| }
|
|
|
| if (fXObjectResources.count()) {
|
| + SkAutoTUnref<SkPDFDict> xObjects(new SkPDFDict());
|
| for (int i = 0; i < fXObjectResources.count(); i++) {
|
| - fResourceDict->insertResourceAsRef(
|
| - SkPDFResourceDict::kXObject_ResourceType,
|
| - i, fXObjectResources[i]);
|
| + SkString nameString("X");
|
| + nameString.appendS32(i);
|
| + xObjects->insert(
|
| + nameString.c_str(),
|
| + new SkPDFObjRef(fXObjectResources[i]))->unref();
|
| }
|
| + fResourceDict->insert("XObject", xObjects.get());
|
| }
|
|
|
| if (fFontResources.count()) {
|
| + SkAutoTUnref<SkPDFDict> fonts(new SkPDFDict());
|
| for (int i = 0; i < fFontResources.count(); i++) {
|
| - fResourceDict->insertResourceAsRef(
|
| - SkPDFResourceDict::kFont_ResourceType,
|
| - i, fFontResources[i]);
|
| + SkString nameString("F");
|
| + nameString.appendS32(i);
|
| + fonts->insert(nameString.c_str(),
|
| + new SkPDFObjRef(fFontResources[i]))->unref();
|
| }
|
| + fResourceDict->insert("Font", fonts.get());
|
| }
|
|
|
| if (fShaderResources.count()) {
|
| SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict());
|
| for (int i = 0; i < fShaderResources.count(); i++) {
|
| - fResourceDict->insertResourceAsRef(
|
| - SkPDFResourceDict::kPattern_ResourceType,
|
| - i, fShaderResources[i]);
|
| + SkString nameString("P");
|
| + nameString.appendS32(i);
|
| + patterns->insert(nameString.c_str(),
|
| + new SkPDFObjRef(fShaderResources[i]))->unref();
|
| }
|
| + fResourceDict->insert("Pattern", patterns.get());
|
| }
|
| +
|
| + // For compatibility, add all proc sets (only used for output to PS
|
| + // devices).
|
| + const char procs[][7] = {"PDF", "Text", "ImageB", "ImageC", "ImageI"};
|
| + SkAutoTUnref<SkPDFArray> procSets(new SkPDFArray());
|
| + procSets->reserve(SK_ARRAY_COUNT(procs));
|
| + for (size_t i = 0; i < SK_ARRAY_COUNT(procs); i++)
|
| + procSets->appendName(procs[i]);
|
| + fResourceDict->insert("ProcSet", procSets.get());
|
| }
|
| return fResourceDict;
|
| }
|
|
|
| +void SkPDFDevice::getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
|
| + SkTSet<SkPDFObject*>* newResourceObjects,
|
| + bool recursive) const {
|
| + // TODO: reserve not correct if we need to recursively explore.
|
| + newResourceObjects->setReserve(newResourceObjects->count() +
|
| + fGraphicStateResources.count() +
|
| + fXObjectResources.count() +
|
| + fFontResources.count() +
|
| + fShaderResources.count());
|
| + for (int i = 0; i < fGraphicStateResources.count(); i++) {
|
| + if (!knownResourceObjects.contains(fGraphicStateResources[i]) &&
|
| + !newResourceObjects->contains(fGraphicStateResources[i])) {
|
| + newResourceObjects->add(fGraphicStateResources[i]);
|
| + fGraphicStateResources[i]->ref();
|
| + if (recursive) {
|
| + fGraphicStateResources[i]->getResources(knownResourceObjects,
|
| + newResourceObjects);
|
| + }
|
| + }
|
| + }
|
| + for (int i = 0; i < fXObjectResources.count(); i++) {
|
| + if (!knownResourceObjects.contains(fXObjectResources[i]) &&
|
| + !newResourceObjects->contains(fXObjectResources[i])) {
|
| + newResourceObjects->add(fXObjectResources[i]);
|
| + fXObjectResources[i]->ref();
|
| + if (recursive) {
|
| + fXObjectResources[i]->getResources(knownResourceObjects,
|
| + newResourceObjects);
|
| + }
|
| + }
|
| + }
|
| + for (int i = 0; i < fFontResources.count(); i++) {
|
| + if (!knownResourceObjects.contains(fFontResources[i]) &&
|
| + !newResourceObjects->contains(fFontResources[i])) {
|
| + newResourceObjects->add(fFontResources[i]);
|
| + fFontResources[i]->ref();
|
| + if (recursive) {
|
| + fFontResources[i]->getResources(knownResourceObjects,
|
| + newResourceObjects);
|
| + }
|
| + }
|
| + }
|
| + for (int i = 0; i < fShaderResources.count(); i++) {
|
| + if (!knownResourceObjects.contains(fShaderResources[i]) &&
|
| + !newResourceObjects->contains(fShaderResources[i])) {
|
| + newResourceObjects->add(fShaderResources[i]);
|
| + fShaderResources[i]->ref();
|
| + if (recursive) {
|
| + fShaderResources[i]->getResources(knownResourceObjects,
|
| + newResourceObjects);
|
| + }
|
| + }
|
| + }
|
| +}
|
| +
|
| const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const {
|
| return fFontResources;
|
| }
|
| @@ -1698,10 +1771,8 @@ void SkPDFDevice::updateFont(const SkPaint& paint, uint16_t glyphID,
|
| contentEntry->fState.fTextSize != paint.getTextSize() ||
|
| !contentEntry->fState.fFont->hasGlyph(glyphID)) {
|
| int fontIndex = getFontResourceIndex(typeface, glyphID);
|
| - contentEntry->fContent.writeText("/");
|
| - contentEntry->fContent.writeText(SkPDFResourceDict::getResourceName(
|
| - SkPDFResourceDict::kFont_ResourceType,
|
| - fontIndex).c_str());
|
| + contentEntry->fContent.writeText("/F");
|
| + contentEntry->fContent.writeDecAsText(fontIndex);
|
| contentEntry->fContent.writeText(" ");
|
| SkPDFScalar::Append(paint.getTextSize(), &contentEntry->fContent);
|
| contentEntry->fContent.writeText(" Tf\n");
|
|
|