gfx/skia/trunk/src/pdf/SkPDFCatalog.h

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.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2010 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #ifndef SkPDFCatalog_DEFINED
michael@0 11 #define SkPDFCatalog_DEFINED
michael@0 12
michael@0 13 #include <sys/types.h>
michael@0 14
michael@0 15 #include "SkPDFDocument.h"
michael@0 16 #include "SkPDFTypes.h"
michael@0 17 #include "SkRefCnt.h"
michael@0 18 #include "SkTDArray.h"
michael@0 19
michael@0 20 /** \class SkPDFCatalog
michael@0 21
michael@0 22 The PDF catalog manages object numbers and file offsets. It is used
michael@0 23 to create the PDF cross reference table.
michael@0 24 */
michael@0 25 class SkPDFCatalog {
michael@0 26 public:
michael@0 27 /** Create a PDF catalog.
michael@0 28 */
michael@0 29 explicit SkPDFCatalog(SkPDFDocument::Flags flags);
michael@0 30 ~SkPDFCatalog();
michael@0 31
michael@0 32 /** Add the passed object to the catalog. Refs obj.
michael@0 33 * @param obj The object to add.
michael@0 34 * @param onFirstPage Is the object on the first page.
michael@0 35 * @return The obj argument is returned.
michael@0 36 */
michael@0 37 SkPDFObject* addObject(SkPDFObject* obj, bool onFirstPage);
michael@0 38
michael@0 39 /** Inform the catalog of the object's position in the final stream.
michael@0 40 * The object should already have been added to the catalog. Returns
michael@0 41 * the object's size.
michael@0 42 * @param obj The object to add.
michael@0 43 * @param offset The byte offset in the output stream of this object.
michael@0 44 */
michael@0 45 size_t setFileOffset(SkPDFObject* obj, off_t offset);
michael@0 46
michael@0 47 /** Output the object number for the passed object.
michael@0 48 * @param obj The object of interest.
michael@0 49 * @param stream The writable output stream to send the output to.
michael@0 50 */
michael@0 51 void emitObjectNumber(SkWStream* stream, SkPDFObject* obj);
michael@0 52
michael@0 53 /** Return the number of bytes that would be emitted for the passed
michael@0 54 * object's object number.
michael@0 55 * @param obj The object of interest
michael@0 56 */
michael@0 57 size_t getObjectNumberSize(SkPDFObject* obj);
michael@0 58
michael@0 59 /** Return the document flags in effect for this catalog/document.
michael@0 60 */
michael@0 61 SkPDFDocument::Flags getDocumentFlags() const { return fDocumentFlags; }
michael@0 62
michael@0 63 /** Output the cross reference table for objects in the catalog.
michael@0 64 * Returns the total number of objects.
michael@0 65 * @param stream The writable output stream to send the output to.
michael@0 66 * @param firstPage If true, include first page objects only, otherwise
michael@0 67 * include all objects not on the first page.
michael@0 68 */
michael@0 69 int32_t emitXrefTable(SkWStream* stream, bool firstPage);
michael@0 70
michael@0 71 /** Set substitute object for the passed object.
michael@0 72 */
michael@0 73 void setSubstitute(SkPDFObject* original, SkPDFObject* substitute);
michael@0 74
michael@0 75 /** Find and return any substitute object set for the passed object. If
michael@0 76 * there is none, return the passed object.
michael@0 77 */
michael@0 78 SkPDFObject* getSubstituteObject(SkPDFObject* object);
michael@0 79
michael@0 80 /** Set file offsets for the resources of substitute objects.
michael@0 81 * @param fileOffset Accumulated offset of current document.
michael@0 82 * @param firstPage Indicate whether this is for the first page only.
michael@0 83 * @return Total size of resources of substitute objects.
michael@0 84 */
michael@0 85 off_t setSubstituteResourcesOffsets(off_t fileOffset, bool firstPage);
michael@0 86
michael@0 87 /** Emit the resources of substitute objects.
michael@0 88 */
michael@0 89 void emitSubstituteResources(SkWStream* stream, bool firstPage);
michael@0 90
michael@0 91 private:
michael@0 92 struct Rec {
michael@0 93 Rec(SkPDFObject* object, bool onFirstPage)
michael@0 94 : fObject(object),
michael@0 95 fFileOffset(0),
michael@0 96 fObjNumAssigned(false),
michael@0 97 fOnFirstPage(onFirstPage) {
michael@0 98 }
michael@0 99 SkPDFObject* fObject;
michael@0 100 off_t fFileOffset;
michael@0 101 bool fObjNumAssigned;
michael@0 102 bool fOnFirstPage;
michael@0 103 };
michael@0 104
michael@0 105 struct SubstituteMapping {
michael@0 106 SubstituteMapping(SkPDFObject* original, SkPDFObject* substitute)
michael@0 107 : fOriginal(original), fSubstitute(substitute) {
michael@0 108 }
michael@0 109 SkPDFObject* fOriginal;
michael@0 110 SkPDFObject* fSubstitute;
michael@0 111 };
michael@0 112
michael@0 113 // TODO(vandebo): Make this a hash if it's a performance problem.
michael@0 114 SkTDArray<struct Rec> fCatalog;
michael@0 115
michael@0 116 // TODO(arthurhsu): Make this a hash if it's a performance problem.
michael@0 117 SkTDArray<SubstituteMapping> fSubstituteMap;
michael@0 118 SkTSet<SkPDFObject*> fSubstituteResourcesFirstPage;
michael@0 119 SkTSet<SkPDFObject*> fSubstituteResourcesRemaining;
michael@0 120
michael@0 121 // Number of objects on the first page.
michael@0 122 uint32_t fFirstPageCount;
michael@0 123 // Next object number to assign (on page > 1).
michael@0 124 uint32_t fNextObjNum;
michael@0 125 // Next object number to assign on the first page.
michael@0 126 uint32_t fNextFirstPageObjNum;
michael@0 127
michael@0 128 SkPDFDocument::Flags fDocumentFlags;
michael@0 129
michael@0 130 int findObjectIndex(SkPDFObject* obj) const;
michael@0 131
michael@0 132 int assignObjNum(SkPDFObject* obj);
michael@0 133
michael@0 134 SkTSet<SkPDFObject*>* getSubstituteList(bool firstPage);
michael@0 135 };
michael@0 136
michael@0 137 #endif

mercurial