gfx/skia/trunk/src/pdf/SkPDFFormXObject.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 2010 The Android Open Source Project
     4  *
     5  * Use of this source code is governed by a BSD-style license that can be
     6  * found in the LICENSE file.
     7  */
    10 #include "SkPDFFormXObject.h"
    12 #include "SkMatrix.h"
    13 #include "SkPDFCatalog.h"
    14 #include "SkPDFDevice.h"
    15 #include "SkPDFResourceDict.h"
    16 #include "SkPDFUtils.h"
    17 #include "SkStream.h"
    18 #include "SkTypes.h"
    20 SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) {
    21     // We don't want to keep around device because we'd have two copies
    22     // of content, so reference or copy everything we need (content and
    23     // resources).
    24     SkTSet<SkPDFObject*> emptySet;
    25     SkPDFResourceDict* resourceDict = device->getResourceDict();
    26     resourceDict->getReferencedResources(emptySet, &fResources, false);
    28     SkAutoTUnref<SkStream> content(device->content());
    29     setData(content.get());
    31     SkAutoTUnref<SkPDFArray> bboxArray(device->copyMediaBox());
    32     init(NULL, resourceDict, bboxArray);
    34     // We invert the initial transform and apply that to the xobject so that
    35     // it doesn't get applied twice. We can't just undo it because it's
    36     // embedded in things like shaders and images.
    37     if (!device->initialTransform().isIdentity()) {
    38         SkMatrix inverse;
    39         if (!device->initialTransform().invert(&inverse)) {
    40             // The initial transform should be invertible.
    41             SkASSERT(false);
    42             inverse.reset();
    43         }
    44         insert("Matrix", SkPDFUtils::MatrixToArray(inverse))->unref();
    45     }
    46 }
    48 /**
    49  * Creates a FormXObject from a content stream and associated resources.
    50  */
    51 SkPDFFormXObject::SkPDFFormXObject(SkStream* content, SkRect bbox,
    52                                    SkPDFResourceDict* resourceDict) {
    53     SkTSet<SkPDFObject*> emptySet;
    54     resourceDict->getReferencedResources(emptySet, &fResources, false);
    56     setData(content);
    58     SkAutoTUnref<SkPDFArray> bboxArray(SkPDFUtils::RectToArray(bbox));
    59     init("DeviceRGB", resourceDict, bboxArray);
    60 }
    62 /**
    63  * Common initialization code.
    64  * Note that bbox is unreferenced here, so calling code does not need worry.
    65  */
    66 void SkPDFFormXObject::init(const char* colorSpace,
    67                             SkPDFDict* resourceDict, SkPDFArray* bbox) {
    68     insertName("Type", "XObject");
    69     insertName("Subtype", "Form");
    70     insert("Resources", resourceDict);
    71     insert("BBox", bbox);
    73     // Right now SkPDFFormXObject is only used for saveLayer, which implies
    74     // isolated blending.  Do this conditionally if that changes.
    75     SkAutoTUnref<SkPDFDict> group(new SkPDFDict("Group"));
    76     group->insertName("S", "Transparency");
    78     if (colorSpace != NULL) {
    79         group->insertName("CS", colorSpace);
    80     }
    81     group->insert("I", new SkPDFBool(true))->unref();  // Isolated.
    82     insert("Group", group.get());
    83 }
    85 SkPDFFormXObject::~SkPDFFormXObject() {
    86     fResources.unrefAll();
    87 }
    89 void SkPDFFormXObject::getResources(
    90         const SkTSet<SkPDFObject*>& knownResourceObjects,
    91         SkTSet<SkPDFObject*>* newResourceObjects) {
    92     GetResourcesHelper(&fResources.toArray(),
    93                        knownResourceObjects,
    94                        newResourceObjects);
    95 }

mercurial