| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #ifndef SkPDFFont_DEFINED | 9 #ifndef SkPDFFont_DEFINED |
| 10 #define SkPDFFont_DEFINED | 10 #define SkPDFFont_DEFINED |
| 11 | 11 |
| 12 #include "SkAdvancedTypefaceMetrics.h" | 12 #include "SkAdvancedTypefaceMetrics.h" |
| 13 #include "SkBitSet.h" | 13 #include "SkBitSet.h" |
| 14 #include "SkPDFTypes.h" | 14 #include "SkPDFTypes.h" |
| 15 #include "SkTDArray.h" | 15 #include "SkTDArray.h" |
| 16 #include "SkTypeface.h" | 16 #include "SkTypeface.h" |
| 17 | 17 |
| 18 class SkPDFCanon; | 18 class SkPDFCanon; |
| 19 class SkPDFFont; | 19 class SkPDFFont; |
| 20 | 20 |
| 21 class SkPDFGlyphSet : SkNoncopyable { | |
| 22 public: | |
| 23 SkPDFGlyphSet(); | |
| 24 SkPDFGlyphSet(SkPDFGlyphSet&& o) : fBitSet(std::move(o.fBitSet)) {} | |
| 25 | |
| 26 void set(const uint16_t* glyphIDs, int numGlyphs); | |
| 27 bool has(uint16_t glyphID) const; | |
| 28 void exportTo(SkTDArray<uint32_t>* glyphIDs) const; | |
| 29 const SkBitSet& bitSet() const { return fBitSet; } | |
| 30 | |
| 31 private: | |
| 32 SkBitSet fBitSet; | |
| 33 }; | |
| 34 | |
| 35 class SkPDFGlyphSetMap : SkNoncopyable { | |
| 36 public: | |
| 37 struct FontGlyphSetPair : SkNoncopyable { | |
| 38 FontGlyphSetPair() : fFont(nullptr) {} | |
| 39 FontGlyphSetPair(FontGlyphSetPair&& o) | |
| 40 : fFont(o.fFont) | |
| 41 , fGlyphSet(std::move(o.fGlyphSet)) { | |
| 42 o.fFont = nullptr; | |
| 43 } | |
| 44 SkPDFFont* fFont; | |
| 45 SkPDFGlyphSet fGlyphSet; | |
| 46 }; | |
| 47 | |
| 48 SkPDFGlyphSetMap(); | |
| 49 ~SkPDFGlyphSetMap(); | |
| 50 | |
| 51 const FontGlyphSetPair* begin() const { return fMap.begin(); } | |
| 52 const FontGlyphSetPair* end() const { return fMap.end(); } | |
| 53 | |
| 54 void noteGlyphUsage(SkPDFFont* font, const uint16_t* glyphIDs, | |
| 55 int numGlyphs); | |
| 56 | |
| 57 private: | |
| 58 SkPDFGlyphSet* getGlyphSetForFont(SkPDFFont* font); | |
| 59 | |
| 60 SkTArray<FontGlyphSetPair> fMap; | |
| 61 }; | |
| 62 | |
| 63 /** \class SkPDFFont | 21 /** \class SkPDFFont |
| 64 A PDF Object class representing a font. The font may have resources | 22 A PDF Object class representing a font. The font may have resources |
| 65 attached to it in order to embed the font. SkPDFFonts are canonicalized | 23 attached to it in order to embed the font. SkPDFFonts are canonicalized |
| 66 so that resource deduplication will only include one copy of a font. | 24 so that resource deduplication will only include one copy of a font. |
| 67 This class uses the same pattern as SkPDFGraphicState, a static weak | 25 This class uses the same pattern as SkPDFGraphicState, a static weak |
| 68 reference to each instantiated class. | 26 reference to each instantiated class. |
| 69 */ | 27 */ |
| 70 class SkPDFFont : public SkPDFDict { | 28 class SkPDFFont : public SkPDFDict { |
| 71 | 29 |
| 72 public: | 30 public: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 * @param numGlyphs The number of input glyphs. | 63 * @param numGlyphs The number of input glyphs. |
| 106 * @return Returns the number of glyphs consumed. | 64 * @return Returns the number of glyphs consumed. |
| 107 */ | 65 */ |
| 108 int glyphsToPDFFontEncoding(SkGlyphID* glyphIDs, int numGlyphs) const; | 66 int glyphsToPDFFontEncoding(SkGlyphID* glyphIDs, int numGlyphs) const; |
| 109 /** | 67 /** |
| 110 * Like above, but does not modify glyphIDs array. | 68 * Like above, but does not modify glyphIDs array. |
| 111 */ | 69 */ |
| 112 int glyphsToPDFFontEncodingCount(const SkGlyphID* glyphIDs, | 70 int glyphsToPDFFontEncodingCount(const SkGlyphID* glyphIDs, |
| 113 int numGlyphs) const; | 71 int numGlyphs) const; |
| 114 | 72 |
| 73 void noteGlyphUsage(const SkGlyphID* glyphs, int count) { |
| 74 fGlyphUsage.setAll(glyphs, count); |
| 75 } |
| 76 |
| 115 /** Get the font resource for the passed typeface and glyphID. The | 77 /** Get the font resource for the passed typeface and glyphID. The |
| 116 * reference count of the object is incremented and it is the caller's | 78 * reference count of the object is incremented and it is the caller's |
| 117 * responsibility to unreference it when done. This is needed to | 79 * responsibility to unreference it when done. This is needed to |
| 118 * accommodate the weak reference pattern used when the returned object | 80 * accommodate the weak reference pattern used when the returned object |
| 119 * is new and has no other references. | 81 * is new and has no other references. |
| 120 * @param typeface The typeface to find. | 82 * @param typeface The typeface to find. |
| 121 * @param glyphID Specify which section of a large font is of interest. | 83 * @param glyphID Specify which section of a large font is of interest. |
| 122 */ | 84 */ |
| 123 static SkPDFFont* GetFontResource(SkPDFCanon* canon, | 85 static SkPDFFont* GetFontResource(SkPDFCanon* canon, |
| 124 SkTypeface* typeface, | 86 SkTypeface* typeface, |
| 125 SkGlyphID glyphID); | 87 SkGlyphID glyphID); |
| 126 | 88 |
| 127 // Uses (kGlyphNames_PerGlyphInfo | kToUnicode_PerGlyphInfo). | 89 // Uses (kGlyphNames_PerGlyphInfo | kToUnicode_PerGlyphInfo). |
| 128 static const SkAdvancedTypefaceMetrics* GetMetrics(SkTypeface* typeface, | 90 static const SkAdvancedTypefaceMetrics* GetMetrics(SkTypeface* typeface, |
| 129 SkPDFCanon* canon); | 91 SkPDFCanon* canon); |
| 130 | 92 |
| 131 /** Subset the font based on usage set. Returns a SkPDFFont instance with | 93 /** Subset the font based on current usage. |
| 132 * subset. | 94 * Must be called before emitObject(). |
| 133 * @param usage Glyph subset requested. | |
| 134 * @return nullptr if font does not support subsetting, a new instanc
e | |
| 135 * of SkPDFFont otherwise. | |
| 136 */ | 95 */ |
| 137 virtual sk_sp<SkPDFObject> getFontSubset(SkPDFCanon* canon, | 96 virtual void getFontSubset(SkPDFCanon*) = 0; |
| 138 const SkPDFGlyphSet* usage); | |
| 139 | 97 |
| 140 /** | 98 /** |
| 141 * Return false iff the typeface has its NotEmbeddable flag set. | 99 * Return false iff the typeface has its NotEmbeddable flag set. |
| 142 * If typeface is NULL, the default typeface is checked. | 100 * If typeface is NULL, the default typeface is checked. |
| 143 */ | 101 */ |
| 144 static bool CanEmbedTypeface(SkTypeface*, SkPDFCanon*); | 102 static bool CanEmbedTypeface(SkTypeface*, SkPDFCanon*); |
| 145 | 103 |
| 146 protected: | 104 protected: |
| 147 // Common constructor to handle common members. | 105 // Common constructor to handle common members. |
| 148 SkPDFFont(sk_sp<SkTypeface> typeface, | 106 struct Info { |
| 149 SkAdvancedTypefaceMetrics::FontType fontType); | 107 sk_sp<SkTypeface> fTypeface; |
| 108 SkGlyphID fFirstGlyphID; |
| 109 SkGlyphID fLastGlyphID; |
| 110 SkAdvancedTypefaceMetrics::FontType fFontType; |
| 111 }; |
| 112 SkPDFFont(Info); |
| 150 | 113 |
| 151 SkGlyphID firstGlyphID() const { return fFirstGlyphID; } | 114 SkGlyphID firstGlyphID() const { return fFirstGlyphID; } |
| 152 SkGlyphID lastGlyphID() const { return fLastGlyphID; } | 115 SkGlyphID lastGlyphID() const { return fLastGlyphID; } |
| 153 | 116 const SkBitSet& glyphUsage() const { return fGlyphUsage; } |
| 154 sk_sp<SkTypeface> refTypeface() const { return fTypeface; } | 117 sk_sp<SkTypeface> refTypeface() const { return fTypeface; } |
| 155 | 118 |
| 156 /** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs, | |
| 157 * including the passed glyphID. | |
| 158 */ | |
| 159 void adjustGlyphRangeForSingleByteEncoding(SkGlyphID glyphID); | |
| 160 | |
| 161 void drop() override; | 119 void drop() override; |
| 162 | 120 |
| 163 private: | 121 private: |
| 164 sk_sp<SkTypeface> fTypeface; | 122 sk_sp<SkTypeface> fTypeface; |
| 123 SkBitSet fGlyphUsage; |
| 165 | 124 |
| 166 // The glyph IDs accessible with this font. For Type1 (non CID) fonts, | 125 // The glyph IDs accessible with this font. For Type1 (non CID) fonts, |
| 167 // this will be a subset if the font has more than 255 glyphs. | 126 // this will be a subset if the font has more than 255 glyphs. |
| 168 SkGlyphID fFirstGlyphID; | 127 SkGlyphID fFirstGlyphID; |
| 169 SkGlyphID fLastGlyphID; | 128 SkGlyphID fLastGlyphID; |
| 170 SkAdvancedTypefaceMetrics::FontType fFontType; | 129 SkAdvancedTypefaceMetrics::FontType fFontType; |
| 171 | 130 |
| 172 typedef SkPDFDict INHERITED; | 131 typedef SkPDFDict INHERITED; |
| 173 }; | 132 }; |
| 174 | 133 |
| 175 #endif | 134 #endif |
| OLD | NEW |