diff options
author | edisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-08-06 21:48:44 +0000 |
---|---|---|
committer | edisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-08-06 21:48:44 +0000 |
commit | 2273f9b45fb78b0cc7df81f96f74b0c3c0e6cc37 (patch) | |
tree | 272ed793ffbbb0294d80da2bc361ba3a3eb25935 | |
parent | 9c8b4eaf280630438d32fee8acd04edad2414d54 (diff) |
pdfviewer: load image pain settings (like transparency), pass the page number, report failure if at least one render fails, and check that xref section starts with xref keyword.
Review URL: https://codereview.chromium.org/22465006
git-svn-id: http://skia.googlecode.com/svn/trunk@10588 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | experimental/PdfViewer/SkPdfRenderer.cpp | 8 | ||||
-rw-r--r-- | experimental/PdfViewer/pdf_viewer_main.cpp | 17 | ||||
-rw-r--r-- | experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp | 7 |
3 files changed, 18 insertions, 14 deletions
diff --git a/experimental/PdfViewer/SkPdfRenderer.cpp b/experimental/PdfViewer/SkPdfRenderer.cpp index 4d9b964748..c68eb5c99d 100644 --- a/experimental/PdfViewer/SkPdfRenderer.cpp +++ b/experimental/PdfViewer/SkPdfRenderer.cpp @@ -658,13 +658,15 @@ static PdfResult doXObject_Image(PdfContext* pdfContext, SkCanvas* canvas, SkPdf SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0), SkDoubleToScalar(1.0), SkDoubleToScalar(1.0)); // TODO(edisonn): soft mask type? alpha/luminosity. + SkPaint paint; + pdfContext->fGraphicsState.applyGraphicsState(&paint, false); + if (!sMask || sMask->empty()) { - canvas->drawBitmapRect(*image, dst, NULL); + canvas->drawBitmapRect(*image, dst, &paint); } else { - canvas->saveLayer(&dst, NULL); + canvas->saveLayer(&dst, &paint); canvas->drawBitmapRect(*image, dst, NULL); SkPaint xfer; - pdfContext->fGraphicsState.applyGraphicsState(&xfer, false); // TODO(edisonn): is the blend mode specified already implicitly/explicitly in pdf? xfer.setXfermodeMode(SkXfermode::kSrcOut_Mode); // SkXfermode::kSdtOut_Mode canvas->drawBitmapRect(*sMask, dst, &xfer); diff --git a/experimental/PdfViewer/pdf_viewer_main.cpp b/experimental/PdfViewer/pdf_viewer_main.cpp index f3176b9940..99506e914f 100644 --- a/experimental/PdfViewer/pdf_viewer_main.cpp +++ b/experimental/PdfViewer/pdf_viewer_main.cpp @@ -216,14 +216,7 @@ static bool process_pdf(const SkString& inputPath, const SkString& outputDir, SkString inputFilename; get_basename(&inputFilename, inputPath); - SkFILEStream inputStream; - inputStream.setPath(inputPath.c_str()); - if (!inputStream.isValid()) { - SkDebugf("Could not open file %s\n", inputPath.c_str()); - return false; - } - - bool success = false; + bool success = true; success = renderer.load(inputPath); if (FLAGS_showMemoryUsage) { @@ -233,7 +226,7 @@ static bool process_pdf(const SkString& inputPath, const SkString& outputDir, // TODO(edisonn): bench timers if (FLAGS_benchLoad > 0) { for (int i = 0 ; i < FLAGS_benchLoad; i++) { - success = renderer.load(inputPath); + success = renderer.load(inputPath) && success; if (FLAGS_showMemoryUsage) { SkDebugf("Memory usage after load %i number : %u\n", i, (unsigned int)renderer.bytesUsed()); } @@ -262,12 +255,16 @@ static bool process_pdf(const SkString& inputPath, const SkString& outputDir, success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() - 1) && success; } else { int pn = atoi(FLAGS_pages[0]); - success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() - 1) && pn; + success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success; } } } } + if (!success) { + SkDebugf("Failures for file %s\n", inputPath.c_str()); + } + return success; } diff --git a/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp b/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp index 6386f988e3..333b0a25db 100644 --- a/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp +++ b/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp @@ -225,7 +225,12 @@ SkNativeParsedPDF::~SkNativeParsedPDF() { } const unsigned char* SkNativeParsedPDF::readCrossReferenceSection(const unsigned char* xrefStart, const unsigned char* trailerEnd) { - const unsigned char* current = ignoreLine(xrefStart, trailerEnd); // TODO(edisonn): verify next keyord is "xref", use nextObject here + SkPdfObject xref; + const unsigned char* current = nextObject(0, xrefStart, trailerEnd, &xref, NULL, NULL); + + if (!xref.isKeyword("xref")) { + return trailerEnd; + } SkPdfObject token; while (current < trailerEnd) { |