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.

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

mercurial