OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkPDFFont_DEFINED | 10 #ifndef SkPDFFont_DEFINED |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 static SkPDFFont* GetFontResource(SkTypeface* typeface, uint16_t glyphID); | 132 static SkPDFFont* GetFontResource(SkTypeface* typeface, uint16_t glyphID); |
133 | 133 |
134 /** Subset the font based on usage set. Returns a SkPDFFont instance with | 134 /** Subset the font based on usage set. Returns a SkPDFFont instance with |
135 * subset. | 135 * subset. |
136 * @param usage Glyph subset requested. | 136 * @param usage Glyph subset requested. |
137 * @return NULL if font does not support subsetting, a new instance | 137 * @return NULL if font does not support subsetting, a new instance |
138 * of SkPDFFont otherwise. | 138 * of SkPDFFont otherwise. |
139 */ | 139 */ |
140 virtual SkPDFFont* getFontSubset(const SkPDFGlyphSet* usage); | 140 virtual SkPDFFont* getFontSubset(const SkPDFGlyphSet* usage); |
141 | 141 |
| 142 enum Match { |
| 143 kExact_Match, |
| 144 kRelated_Match, |
| 145 kNot_Match, |
| 146 }; |
| 147 static Match IsMatch(SkPDFFont* existingFont, |
| 148 uint32_t existingFontID, |
| 149 uint16_t existingGlyphID, |
| 150 uint32_t searchFontID, |
| 151 uint16_t searchGlyphID); |
| 152 |
142 protected: | 153 protected: |
143 // Common constructor to handle common members. | 154 // Common constructor to handle common members. |
144 SkPDFFont(const SkAdvancedTypefaceMetrics* fontInfo, SkTypeface* typeface, | 155 SkPDFFont(const SkAdvancedTypefaceMetrics* fontInfo, SkTypeface* typeface, |
145 SkPDFDict* relatedFontDescriptor); | 156 SkPDFDict* relatedFontDescriptor); |
146 | 157 |
147 // Accessors for subclass. | 158 // Accessors for subclass. |
148 const SkAdvancedTypefaceMetrics* fontInfo(); | 159 const SkAdvancedTypefaceMetrics* fontInfo(); |
149 void setFontInfo(const SkAdvancedTypefaceMetrics* info); | 160 void setFontInfo(const SkAdvancedTypefaceMetrics* info); |
150 uint16_t firstGlyphID() const; | 161 uint16_t firstGlyphID() const; |
151 uint16_t lastGlyphID() const; | 162 uint16_t lastGlyphID() const; |
(...skipping 19 matching lines...) Expand all Loading... |
171 void populateToUnicodeTable(const SkPDFGlyphSet* subset); | 182 void populateToUnicodeTable(const SkPDFGlyphSet* subset); |
172 | 183 |
173 // Create instances of derived types based on fontInfo. | 184 // Create instances of derived types based on fontInfo. |
174 static SkPDFFont* Create(const SkAdvancedTypefaceMetrics* fontInfo, | 185 static SkPDFFont* Create(const SkAdvancedTypefaceMetrics* fontInfo, |
175 SkTypeface* typeface, uint16_t glyphID, | 186 SkTypeface* typeface, uint16_t glyphID, |
176 SkPDFDict* relatedFontDescriptor); | 187 SkPDFDict* relatedFontDescriptor); |
177 | 188 |
178 static bool Find(uint32_t fontID, uint16_t glyphID, int* index); | 189 static bool Find(uint32_t fontID, uint16_t glyphID, int* index); |
179 | 190 |
180 private: | 191 private: |
181 class FontRec { | |
182 public: | |
183 SkPDFFont* fFont; | |
184 uint32_t fFontID; | |
185 uint16_t fGlyphID; | |
186 | |
187 // A fGlyphID of 0 with no fFont always matches. | |
188 bool operator==(const FontRec& b) const; | |
189 FontRec(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID); | |
190 }; | |
191 | |
192 SkAutoTUnref<SkTypeface> fTypeface; | 192 SkAutoTUnref<SkTypeface> fTypeface; |
193 | 193 |
194 // The glyph IDs accessible with this font. For Type1 (non CID) fonts, | 194 // The glyph IDs accessible with this font. For Type1 (non CID) fonts, |
195 // this will be a subset if the font has more than 255 glyphs. | 195 // this will be a subset if the font has more than 255 glyphs. |
196 uint16_t fFirstGlyphID; | 196 uint16_t fFirstGlyphID; |
197 uint16_t fLastGlyphID; | 197 uint16_t fLastGlyphID; |
198 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fFontInfo; | 198 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fFontInfo; |
199 SkTDArray<SkPDFObject*> fResources; | 199 SkTDArray<SkPDFObject*> fResources; |
200 SkAutoTUnref<SkPDFDict> fDescriptor; | 200 SkAutoTUnref<SkPDFDict> fDescriptor; |
201 | 201 |
202 SkAdvancedTypefaceMetrics::FontType fFontType; | 202 SkAdvancedTypefaceMetrics::FontType fFontType; |
203 | 203 |
204 // This should be made a hash table if performance is a problem. | |
205 static SkTDArray<FontRec>& CanonicalFonts(); | |
206 static SkBaseMutex& CanonicalFontsMutex(); | |
207 typedef SkPDFDict INHERITED; | 204 typedef SkPDFDict INHERITED; |
208 }; | 205 }; |
209 | 206 |
210 #endif | 207 #endif |
OLD | NEW |