gfx/skia/trunk/src/pdf/SkPDFFont.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 2011 Google Inc.
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 SkPDFFont_DEFINED
michael@0 11 #define SkPDFFont_DEFINED
michael@0 12
michael@0 13 #include "SkAdvancedTypefaceMetrics.h"
michael@0 14 #include "SkBitSet.h"
michael@0 15 #include "SkPDFTypes.h"
michael@0 16 #include "SkTDArray.h"
michael@0 17 #include "SkThread.h"
michael@0 18 #include "SkTypeface.h"
michael@0 19
michael@0 20 class SkPaint;
michael@0 21 class SkPDFCatalog;
michael@0 22 class SkPDFFont;
michael@0 23
michael@0 24 class SkPDFGlyphSet : public SkNoncopyable {
michael@0 25 public:
michael@0 26 SkPDFGlyphSet();
michael@0 27
michael@0 28 void set(const uint16_t* glyphIDs, int numGlyphs);
michael@0 29 bool has(uint16_t glyphID) const;
michael@0 30 void merge(const SkPDFGlyphSet& usage);
michael@0 31 void exportTo(SkTDArray<uint32_t>* glyphIDs) const;
michael@0 32
michael@0 33 private:
michael@0 34 SkBitSet fBitSet;
michael@0 35 };
michael@0 36
michael@0 37 class SkPDFGlyphSetMap : public SkNoncopyable {
michael@0 38 public:
michael@0 39 struct FontGlyphSetPair {
michael@0 40 FontGlyphSetPair(SkPDFFont* font, SkPDFGlyphSet* glyphSet);
michael@0 41
michael@0 42 SkPDFFont* fFont;
michael@0 43 SkPDFGlyphSet* fGlyphSet;
michael@0 44 };
michael@0 45
michael@0 46 SkPDFGlyphSetMap();
michael@0 47 ~SkPDFGlyphSetMap();
michael@0 48
michael@0 49 class F2BIter {
michael@0 50 public:
michael@0 51 explicit F2BIter(const SkPDFGlyphSetMap& map);
michael@0 52 const FontGlyphSetPair* next() const;
michael@0 53 void reset(const SkPDFGlyphSetMap& map);
michael@0 54
michael@0 55 private:
michael@0 56 const SkTDArray<FontGlyphSetPair>* fMap;
michael@0 57 mutable int fIndex;
michael@0 58 };
michael@0 59
michael@0 60 void merge(const SkPDFGlyphSetMap& usage);
michael@0 61 void reset();
michael@0 62
michael@0 63 void noteGlyphUsage(SkPDFFont* font, const uint16_t* glyphIDs,
michael@0 64 int numGlyphs);
michael@0 65
michael@0 66 private:
michael@0 67 SkPDFGlyphSet* getGlyphSetForFont(SkPDFFont* font);
michael@0 68
michael@0 69 SkTDArray<FontGlyphSetPair> fMap;
michael@0 70 };
michael@0 71
michael@0 72
michael@0 73 /** \class SkPDFFont
michael@0 74 A PDF Object class representing a font. The font may have resources
michael@0 75 attached to it in order to embed the font. SkPDFFonts are canonicalized
michael@0 76 so that resource deduplication will only include one copy of a font.
michael@0 77 This class uses the same pattern as SkPDFGraphicState, a static weak
michael@0 78 reference to each instantiated class.
michael@0 79 */
michael@0 80 class SkPDFFont : public SkPDFDict {
michael@0 81 SK_DECLARE_INST_COUNT(SkPDFFont)
michael@0 82 public:
michael@0 83 virtual ~SkPDFFont();
michael@0 84
michael@0 85 virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
michael@0 86 SkTSet<SkPDFObject*>* newResourceObjects);
michael@0 87
michael@0 88 /** Returns the typeface represented by this class. Returns NULL for the
michael@0 89 * default typeface.
michael@0 90 */
michael@0 91 SkTypeface* typeface();
michael@0 92
michael@0 93 /** Returns the font type represented in this font. For Type0 fonts,
michael@0 94 * returns the type of the decendant font.
michael@0 95 */
michael@0 96 virtual SkAdvancedTypefaceMetrics::FontType getType();
michael@0 97
michael@0 98 /** Returns true if this font encoding supports glyph IDs above 255.
michael@0 99 */
michael@0 100 virtual bool multiByteGlyphs() const = 0;
michael@0 101
michael@0 102 /** Return true if this font has an encoding for the passed glyph id.
michael@0 103 */
michael@0 104 bool hasGlyph(uint16_t glyphID);
michael@0 105
michael@0 106 /** Convert (in place) the input glyph IDs into the font encoding. If the
michael@0 107 * font has more glyphs than can be encoded (like a type 1 font with more
michael@0 108 * than 255 glyphs) this method only converts up to the first out of range
michael@0 109 * glyph ID.
michael@0 110 * @param glyphIDs The input text as glyph IDs.
michael@0 111 * @param numGlyphs The number of input glyphs.
michael@0 112 * @return Returns the number of glyphs consumed.
michael@0 113 */
michael@0 114 size_t glyphsToPDFFontEncoding(uint16_t* glyphIDs, size_t numGlyphs);
michael@0 115
michael@0 116 /** Get the font resource for the passed typeface and glyphID. The
michael@0 117 * reference count of the object is incremented and it is the caller's
michael@0 118 * responsibility to unreference it when done. This is needed to
michael@0 119 * accommodate the weak reference pattern used when the returned object
michael@0 120 * is new and has no other references.
michael@0 121 * @param typeface The typeface to find.
michael@0 122 * @param glyphID Specify which section of a large font is of interest.
michael@0 123 */
michael@0 124 static SkPDFFont* GetFontResource(SkTypeface* typeface,
michael@0 125 uint16_t glyphID);
michael@0 126
michael@0 127 /** Subset the font based on usage set. Returns a SkPDFFont instance with
michael@0 128 * subset.
michael@0 129 * @param usage Glyph subset requested.
michael@0 130 * @return NULL if font does not support subsetting, a new instance
michael@0 131 * of SkPDFFont otherwise.
michael@0 132 */
michael@0 133 virtual SkPDFFont* getFontSubset(const SkPDFGlyphSet* usage);
michael@0 134
michael@0 135 protected:
michael@0 136 // Common constructor to handle common members.
michael@0 137 SkPDFFont(SkAdvancedTypefaceMetrics* fontInfo, SkTypeface* typeface,
michael@0 138 SkPDFDict* relatedFontDescriptor);
michael@0 139
michael@0 140 // Accessors for subclass.
michael@0 141 SkAdvancedTypefaceMetrics* fontInfo();
michael@0 142 void setFontInfo(SkAdvancedTypefaceMetrics* info);
michael@0 143 uint16_t firstGlyphID() const;
michael@0 144 uint16_t lastGlyphID() const;
michael@0 145 void setLastGlyphID(uint16_t glyphID);
michael@0 146
michael@0 147 // Add object to resource list.
michael@0 148 void addResource(SkPDFObject* object);
michael@0 149
michael@0 150 // Accessors for FontDescriptor associated with this object.
michael@0 151 SkPDFDict* getFontDescriptor();
michael@0 152 void setFontDescriptor(SkPDFDict* descriptor);
michael@0 153
michael@0 154 // Add common entries to FontDescriptor.
michael@0 155 bool addCommonFontDescriptorEntries(int16_t defaultWidth);
michael@0 156
michael@0 157 /** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs,
michael@0 158 * including the passed glyphID.
michael@0 159 */
michael@0 160 void adjustGlyphRangeForSingleByteEncoding(int16_t glyphID);
michael@0 161
michael@0 162 // Generate ToUnicode table according to glyph usage subset.
michael@0 163 // If subset is NULL, all available glyph ids will be used.
michael@0 164 void populateToUnicodeTable(const SkPDFGlyphSet* subset);
michael@0 165
michael@0 166 // Create instances of derived types based on fontInfo.
michael@0 167 static SkPDFFont* Create(SkAdvancedTypefaceMetrics* fontInfo,
michael@0 168 SkTypeface* typeface, uint16_t glyphID,
michael@0 169 SkPDFDict* relatedFontDescriptor);
michael@0 170
michael@0 171 static bool Find(uint32_t fontID, uint16_t glyphID, int* index);
michael@0 172
michael@0 173 private:
michael@0 174 class FontRec {
michael@0 175 public:
michael@0 176 SkPDFFont* fFont;
michael@0 177 uint32_t fFontID;
michael@0 178 uint16_t fGlyphID;
michael@0 179
michael@0 180 // A fGlyphID of 0 with no fFont always matches.
michael@0 181 bool operator==(const FontRec& b) const;
michael@0 182 FontRec(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID);
michael@0 183 };
michael@0 184
michael@0 185 SkAutoTUnref<SkTypeface> fTypeface;
michael@0 186
michael@0 187 // The glyph IDs accessible with this font. For Type1 (non CID) fonts,
michael@0 188 // this will be a subset if the font has more than 255 glyphs.
michael@0 189 uint16_t fFirstGlyphID;
michael@0 190 uint16_t fLastGlyphID;
michael@0 191 // The font info is only kept around after construction for large
michael@0 192 // Type1 (non CID) fonts that need multiple "fonts" to access all glyphs.
michael@0 193 SkAutoTUnref<SkAdvancedTypefaceMetrics> fFontInfo;
michael@0 194 SkTDArray<SkPDFObject*> fResources;
michael@0 195 SkAutoTUnref<SkPDFDict> fDescriptor;
michael@0 196
michael@0 197 SkAdvancedTypefaceMetrics::FontType fFontType;
michael@0 198
michael@0 199 // This should be made a hash table if performance is a problem.
michael@0 200 static SkTDArray<FontRec>& CanonicalFonts();
michael@0 201 static SkBaseMutex& CanonicalFontsMutex();
michael@0 202 typedef SkPDFDict INHERITED;
michael@0 203 };
michael@0 204
michael@0 205 #endif

mercurial