pdfviewer: load image pain settings (like transparency), pass the page number, report...
authoredisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 6 Aug 2013 21:48:44 +0000 (21:48 +0000)
committeredisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 6 Aug 2013 21:48:44 +0000 (21:48 +0000)
Review URL: https://codereview.chromium.org/22465006

git-svn-id: http://skia.googlecode.com/svn/trunk@10588 2bbb7eff-a529-9590-31e7-b0007b416f81

experimental/PdfViewer/SkPdfRenderer.cpp
experimental/PdfViewer/pdf_viewer_main.cpp
experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp

index 4d9b9647482c5a954e9c54b8d00bc22ce4458660..c68eb5c99d6351e3c00560da3228632c782ec05f 100644 (file)
@@ -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);
index f3176b994077b7cb676b76d34494e8c0789568b5..99506e914fb867964dd40806de9fda644c5751a1 100644 (file)
@@ -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;
 }
 
index 6386f988e3d29510b65039a4e1782dc3a703c00d..333b0a25dbd010a00ab5dc386d8f6ac8a6182c89 100644 (file)
@@ -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) {