diff options
Diffstat (limited to 'experimental/PdfViewer')
-rw-r--r-- | experimental/PdfViewer/SkPdfRenderer.cpp | 45 | ||||
-rw-r--r-- | experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp | 13 |
2 files changed, 56 insertions, 2 deletions
diff --git a/experimental/PdfViewer/SkPdfRenderer.cpp b/experimental/PdfViewer/SkPdfRenderer.cpp index e2197b0296..68501749ef 100644 --- a/experimental/PdfViewer/SkPdfRenderer.cpp +++ b/experimental/PdfViewer/SkPdfRenderer.cpp @@ -1586,8 +1586,49 @@ static PdfResult PdfOp_TJ(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop } static PdfResult PdfOp_CS_cs(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColorOperator* colorOperator) { - colorOperator->fColorSpace = pdfContext->fObjectStack.top()->strRef(); pdfContext->fObjectStack.pop(); - return kOK_PdfResult; + SkPdfObject* name = pdfContext->fObjectStack.top(); pdfContext->fObjectStack.pop(); + + //Next, get the ColorSpace Dictionary from the Resource Dictionary: + SkPdfDictionary* colorSpaceResource = pdfContext->fGraphicsState.fResources->ColorSpace(pdfContext->fPdfDoc); + + SkPdfObject* colorSpace = pdfContext->fPdfDoc->resolveReference(colorSpaceResource->get(name)); + + if (colorSpace == NULL) { + colorOperator->fColorSpace = name->strRef(); + } else { +#ifdef PDF_TRACE + printf("CS = %s\n", colorSpace->toString(0, 0).c_str()); +#endif // PDF_TRACE + if (colorSpace->isName()) { + colorOperator->fColorSpace = colorSpace->strRef(); + } else if (colorSpace->isArray()) { + int cnt = colorSpace->size(); + if (cnt == 0) { + return kIgnoreError_PdfResult; + } + SkPdfObject* type = colorSpace->objAtAIndex(0); + type = pdfContext->fPdfDoc->resolveReference(type); + + if (type->isName("ICCBased")) { + if (cnt != 2) { + return kIgnoreError_PdfResult; + } + SkPdfObject* prop = colorSpace->objAtAIndex(1); + prop = pdfContext->fPdfDoc->resolveReference(prop); +#ifdef PDF_TRACE + printf("ICCBased prop = %s\n", prop->toString(0, 0).c_str()); +#endif // PDF_TRACE + // TODO(edisonn): hack + if (prop && prop->isDictionary() && prop->get("N") && prop->get("N")->isInteger() && prop->get("N")->intValue() == 3) { + colorOperator->setColorSpace(&strings_DeviceRGB); + return kPartial_PdfResult; + } + return kNYI_PdfResult; + } + } + } + + return kPartial_PdfResult; } static PdfResult PdfOp_CS(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** looper) { diff --git a/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp b/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp index 2e7e670ce9..d9f680cc3e 100644 --- a/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp +++ b/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp @@ -207,6 +207,18 @@ void SkNativeParsedPDF::loadWithoutXRef() { current = skipPdfWhiteSpaces(0, current, end); } + // TODO(edisonn): hack, detect root catalog - we need to implement liniarized support, and remove this hack. + if (!fRootCatalogRef) { + for (unsigned int i = 0 ; i < objects(); i++) { + SkPdfObject* obj = object(i); + SkPdfObject* root = (obj && obj->isDictionary()) ? obj->get("Root") : NULL; + if (root && root->isReference()) { + fRootCatalogRef = root; + } + } + } + + if (fRootCatalogRef) { fRootCatalog = (SkPdfCatalogDictionary*)resolveReference(fRootCatalogRef); if (fRootCatalog->isDictionary() && fRootCatalog->valid()) { @@ -217,6 +229,7 @@ void SkNativeParsedPDF::loadWithoutXRef() { } } + } // TODO(edisonn): NYI |