gfx/skia/trunk/src/utils/SkPDFRasterizer.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     2 /*
     3  * Copyright 2013 Google Inc.
     4  *
     5  * Use of this source code is governed by a BSD-style license that can be
     6  * found in the LICENSE file.
     7  */
     9 #ifdef SK_BUILD_FOR_WIN32
    10 #pragma warning(push)
    11 #pragma warning(disable : 4530)
    12 #endif
    14 #include "SkPDFRasterizer.h"
    15 #include "SkColorPriv.h"
    17 #ifdef SK_BUILD_NATIVE_PDF_RENDERER
    18 #include "SkPdfRenderer.h"
    19 #endif  // SK_BUILD_NATIVE_PDF_RENDERER
    21 #ifdef SK_BUILD_POPPLER
    22 #include <poppler-document.h>
    23 #include <poppler-image.h>
    24 #include <poppler-page.h>
    25 #include <poppler-page-renderer.h>
    26 #endif  // SK_BUILD_POPPLER
    28 #ifdef SK_BUILD_POPPLER
    29 bool SkPopplerRasterizePDF(SkStream* pdf, SkBitmap* output) {
    30   size_t size = pdf->getLength();
    31   SkAutoFree buffer(sk_malloc_throw(size));
    32   pdf->read(buffer.get(), size);
    34   SkAutoTDelete<poppler::document> doc(
    35       poppler::document::load_from_raw_data((const char*)buffer.get(), size));
    36   if (!doc.get() || doc->is_locked()) {
    37     return false;
    38   }
    40   SkAutoTDelete<poppler::page> page(doc->create_page(0));
    41   poppler::page_renderer renderer;
    42   poppler::image image = renderer.render_page(page.get());
    44   if (!image.is_valid() || image.format() != poppler::image::format_argb32) {
    45     return false;
    46   }
    48   int width = image.width(), height = image.height();
    49   size_t rowSize = image.bytes_per_row();
    50   char *imgData = image.data();
    52   SkBitmap bitmap;
    53   if (!bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height))) {
    54     return false;
    55   }
    56   bitmap.eraseColor(SK_ColorWHITE);
    57   SkPMColor* bitmapPixels = (SkPMColor*)bitmap.getPixels();
    59   // do pixel-by-pixel copy to deal with RGBA ordering conversions
    60   for (int y = 0; y < height; y++) {
    61     char *rowData = imgData;
    62     for (int x = 0; x < width; x++) {
    63       uint8_t a = rowData[3];
    64       uint8_t r = rowData[2];
    65       uint8_t g = rowData[1];
    66       uint8_t b = rowData[0];
    68       *bitmapPixels = SkPreMultiplyARGB(a, r, g, b);
    70       bitmapPixels++;
    71       rowData += 4;
    72     }
    73     imgData += rowSize;
    74   }
    76   output->swap(bitmap);
    78   return true;
    79 }
    80 #endif  // SK_BUILD_POPPLER
    82 #ifdef SK_BUILD_NATIVE_PDF_RENDERER
    83 bool SkNativeRasterizePDF(SkStream* pdf, SkBitmap* output) {
    84     return SkPDFNativeRenderToBitmap(pdf, output);
    85 }
    86 #endif  // SK_BUILD_NATIVE_PDF_RENDERER

mercurial