| 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 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 reference to each instantiated class. | 68 reference to each instantiated class. |
| 69 */ | 69 */ |
| 70 class SkPDFFont : public SkPDFDict { | 70 class SkPDFFont : public SkPDFDict { |
| 71 | 71 |
| 72 public: | 72 public: |
| 73 virtual ~SkPDFFont(); | 73 virtual ~SkPDFFont(); |
| 74 | 74 |
| 75 /** Returns the typeface represented by this class. Returns nullptr for the | 75 /** Returns the typeface represented by this class. Returns nullptr for the |
| 76 * default typeface. | 76 * default typeface. |
| 77 */ | 77 */ |
| 78 SkTypeface* typeface(); | 78 SkTypeface* typeface() { return fTypeface.get(); } |
| 79 | 79 |
| 80 /** Returns the font type represented in this font. For Type0 fonts, | 80 /** Returns the font type represented in this font. For Type0 fonts, |
| 81 * returns the type of the decendant font. | 81 * returns the type of the decendant font. |
| 82 */ | 82 */ |
| 83 virtual SkAdvancedTypefaceMetrics::FontType getType(); | 83 SkAdvancedTypefaceMetrics::FontType getType() { return fFontType; } |
| 84 | 84 |
| 85 /** Returns true if this font encoding supports glyph IDs above 255. | 85 /** Returns true if this font encoding supports glyph IDs above 255. |
| 86 */ | 86 */ |
| 87 virtual bool multiByteGlyphs() const = 0; | 87 bool multiByteGlyphs() const { return fMultiByteGlyphs; } |
| 88 | 88 |
| 89 /** Returns true if the machine readable licensing bits allow embedding. | 89 /** Returns true if the machine readable licensing bits allow embedding. |
| 90 */ | 90 */ |
| 91 bool canEmbed() const; | 91 bool canEmbed() const; |
| 92 | 92 |
| 93 /** Returns true if the machine readable licensing bits allow subsetting. | 93 /** Returns true if the machine readable licensing bits allow subsetting. |
| 94 */ | 94 */ |
| 95 bool canSubset() const; | 95 bool canSubset() const; |
| 96 | 96 |
| 97 /** Return true if this font has an encoding for the passed glyph id. | 97 /** Return true if this font has an encoding for the passed glyph id. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 uint16_t searchGlyphID); | 146 uint16_t searchGlyphID); |
| 147 | 147 |
| 148 /** | 148 /** |
| 149 * Return false iff the typeface has its NotEmbeddable flag set. | 149 * Return false iff the typeface has its NotEmbeddable flag set. |
| 150 * If typeface is NULL, the default typeface is checked. | 150 * If typeface is NULL, the default typeface is checked. |
| 151 */ | 151 */ |
| 152 static bool CanEmbedTypeface(SkTypeface*, SkPDFCanon*); | 152 static bool CanEmbedTypeface(SkTypeface*, SkPDFCanon*); |
| 153 | 153 |
| 154 protected: | 154 protected: |
| 155 // Common constructor to handle common members. | 155 // Common constructor to handle common members. |
| 156 SkPDFFont(const SkAdvancedTypefaceMetrics* fontInfo, | 156 SkPDFFont(sk_sp<const SkAdvancedTypefaceMetrics> fontInfo, |
| 157 SkTypeface* typeface, | 157 sk_sp<SkTypeface> typeface, |
| 158 SkPDFDict* relatedFontDescriptor); | 158 sk_sp<SkPDFDict> relatedFontDescriptor, |
| 159 SkAdvancedTypefaceMetrics::FontType fontType, |
| 160 bool multiByteGlyphs); |
| 159 | 161 |
| 160 // Accessors for subclass. | 162 // Accessors for subclass. |
| 161 const SkAdvancedTypefaceMetrics* fontInfo(); | 163 const SkAdvancedTypefaceMetrics* getFontInfo() const { return fFontInfo.get(
); } |
| 162 void setFontInfo(const SkAdvancedTypefaceMetrics* info); | 164 sk_sp<const SkAdvancedTypefaceMetrics> refFontInfo() const { return fFontInf
o; } |
| 163 uint16_t firstGlyphID() const; | 165 |
| 164 uint16_t lastGlyphID() const; | 166 void setFontInfo(sk_sp<const SkAdvancedTypefaceMetrics> info); |
| 167 SkGlyphID firstGlyphID() const { return fFirstGlyphID; } |
| 168 SkGlyphID lastGlyphID() const { return fLastGlyphID; } |
| 165 void setLastGlyphID(uint16_t glyphID); | 169 void setLastGlyphID(uint16_t glyphID); |
| 166 | 170 |
| 167 // Accessors for FontDescriptor associated with this object. | 171 // Accessors for FontDescriptor associated with this object. |
| 168 SkPDFDict* getFontDescriptor(); | 172 SkPDFDict* getFontDescriptor() const { return fDescriptor.get(); } |
| 169 void setFontDescriptor(SkPDFDict* descriptor); | 173 sk_sp<SkPDFDict> refFontDescriptor() const { return fDescriptor; } |
| 174 void setFontDescriptor(sk_sp<SkPDFDict> descriptor); |
| 175 |
| 176 sk_sp<SkTypeface> refTypeface() const { return fTypeface; } |
| 170 | 177 |
| 171 // Add common entries to FontDescriptor. | 178 // Add common entries to FontDescriptor. |
| 172 bool addCommonFontDescriptorEntries(int16_t defaultWidth); | 179 bool addCommonFontDescriptorEntries(int16_t defaultWidth); |
| 173 | 180 |
| 174 /** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs, | 181 /** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs, |
| 175 * including the passed glyphID. | 182 * including the passed glyphID. |
| 176 */ | 183 */ |
| 177 void adjustGlyphRangeForSingleByteEncoding(uint16_t glyphID); | 184 void adjustGlyphRangeForSingleByteEncoding(uint16_t glyphID); |
| 178 | 185 |
| 179 // Generate ToUnicode table according to glyph usage subset. | 186 // Generate ToUnicode table according to glyph usage subset. |
| 180 // If subset is nullptr, all available glyph ids will be used. | 187 // If subset is nullptr, all available glyph ids will be used. |
| 181 void populateToUnicodeTable(const SkPDFGlyphSet* subset); | 188 void populateToUnicodeTable(const SkPDFGlyphSet* subset); |
| 182 | 189 |
| 183 // Create instances of derived types based on fontInfo. | |
| 184 static SkPDFFont* Create(SkPDFCanon* canon, | |
| 185 const SkAdvancedTypefaceMetrics* fontInfo, | |
| 186 SkTypeface* typeface, | |
| 187 uint16_t glyphID, | |
| 188 SkPDFDict* relatedFontDescriptor); | |
| 189 | |
| 190 static bool Find(uint32_t fontID, uint16_t glyphID, int* index); | 190 static bool Find(uint32_t fontID, uint16_t glyphID, int* index); |
| 191 | 191 |
| 192 void drop() override; | 192 void drop() override; |
| 193 | 193 |
| 194 private: | 194 private: |
| 195 sk_sp<SkTypeface> fTypeface; | 195 sk_sp<SkTypeface> fTypeface; |
| 196 sk_sp<const SkAdvancedTypefaceMetrics> fFontInfo; |
| 197 sk_sp<SkPDFDict> fDescriptor; |
| 196 | 198 |
| 197 // The glyph IDs accessible with this font. For Type1 (non CID) fonts, | 199 // The glyph IDs accessible with this font. For Type1 (non CID) fonts, |
| 198 // this will be a subset if the font has more than 255 glyphs. | 200 // this will be a subset if the font has more than 255 glyphs. |
| 199 uint16_t fFirstGlyphID; | 201 SkGlyphID fFirstGlyphID; |
| 200 uint16_t fLastGlyphID; | 202 SkGlyphID fLastGlyphID; |
| 201 sk_sp<const SkAdvancedTypefaceMetrics> fFontInfo; | |
| 202 sk_sp<SkPDFDict> fDescriptor; | |
| 203 | |
| 204 SkAdvancedTypefaceMetrics::FontType fFontType; | 203 SkAdvancedTypefaceMetrics::FontType fFontType; |
| 204 bool fMultiByteGlyphs; |
| 205 | 205 |
| 206 typedef SkPDFDict INHERITED; | 206 typedef SkPDFDict INHERITED; |
| 207 }; | 207 }; |
| 208 | 208 |
| 209 #endif | 209 #endif |
| OLD | NEW |