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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 protected: | 142 protected: |
143 // Common constructor to handle common members. | 143 // Common constructor to handle common members. |
144 SkPDFFont(SkAdvancedTypefaceMetrics* fontInfo, SkTypeface* typeface, | 144 SkPDFFont(const SkAdvancedTypefaceMetrics* fontInfo, SkTypeface* typeface, |
145 SkPDFDict* relatedFontDescriptor); | 145 SkPDFDict* relatedFontDescriptor); |
146 | 146 |
147 // Accessors for subclass. | 147 // Accessors for subclass. |
148 SkAdvancedTypefaceMetrics* fontInfo(); | 148 const SkAdvancedTypefaceMetrics* fontInfo(); |
149 void setFontInfo(SkAdvancedTypefaceMetrics* info); | 149 void setFontInfo(const SkAdvancedTypefaceMetrics* info); |
150 uint16_t firstGlyphID() const; | 150 uint16_t firstGlyphID() const; |
151 uint16_t lastGlyphID() const; | 151 uint16_t lastGlyphID() const; |
152 void setLastGlyphID(uint16_t glyphID); | 152 void setLastGlyphID(uint16_t glyphID); |
153 | 153 |
154 // Add object to resource list. | 154 // Add object to resource list. |
155 void addResource(SkPDFObject* object); | 155 void addResource(SkPDFObject* object); |
156 | 156 |
157 // Accessors for FontDescriptor associated with this object. | 157 // Accessors for FontDescriptor associated with this object. |
158 SkPDFDict* getFontDescriptor(); | 158 SkPDFDict* getFontDescriptor(); |
159 void setFontDescriptor(SkPDFDict* descriptor); | 159 void setFontDescriptor(SkPDFDict* descriptor); |
160 | 160 |
161 // Add common entries to FontDescriptor. | 161 // Add common entries to FontDescriptor. |
162 bool addCommonFontDescriptorEntries(int16_t defaultWidth); | 162 bool addCommonFontDescriptorEntries(int16_t defaultWidth); |
163 | 163 |
164 /** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs, | 164 /** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs, |
165 * including the passed glyphID. | 165 * including the passed glyphID. |
166 */ | 166 */ |
167 void adjustGlyphRangeForSingleByteEncoding(int16_t glyphID); | 167 void adjustGlyphRangeForSingleByteEncoding(int16_t glyphID); |
168 | 168 |
169 // Generate ToUnicode table according to glyph usage subset. | 169 // Generate ToUnicode table according to glyph usage subset. |
170 // If subset is NULL, all available glyph ids will be used. | 170 // If subset is NULL, all available glyph ids will be used. |
171 void populateToUnicodeTable(const SkPDFGlyphSet* subset); | 171 void populateToUnicodeTable(const SkPDFGlyphSet* subset); |
172 | 172 |
173 // Create instances of derived types based on fontInfo. | 173 // Create instances of derived types based on fontInfo. |
174 static SkPDFFont* Create(SkAdvancedTypefaceMetrics* fontInfo, | 174 static SkPDFFont* Create(const SkAdvancedTypefaceMetrics* fontInfo, |
175 SkTypeface* typeface, uint16_t glyphID, | 175 SkTypeface* typeface, uint16_t glyphID, |
176 SkPDFDict* relatedFontDescriptor); | 176 SkPDFDict* relatedFontDescriptor); |
177 | 177 |
178 static bool Find(uint32_t fontID, uint16_t glyphID, int* index); | 178 static bool Find(uint32_t fontID, uint16_t glyphID, int* index); |
179 | 179 |
180 private: | 180 private: |
181 class FontRec { | 181 class FontRec { |
182 public: | 182 public: |
183 SkPDFFont* fFont; | 183 SkPDFFont* fFont; |
184 uint32_t fFontID; | 184 uint32_t fFontID; |
185 uint16_t fGlyphID; | 185 uint16_t fGlyphID; |
186 | 186 |
187 // A fGlyphID of 0 with no fFont always matches. | 187 // A fGlyphID of 0 with no fFont always matches. |
188 bool operator==(const FontRec& b) const; | 188 bool operator==(const FontRec& b) const; |
189 FontRec(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID); | 189 FontRec(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID); |
190 }; | 190 }; |
191 | 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<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. | 204 // This should be made a hash table if performance is a problem. |
205 static SkTDArray<FontRec>& CanonicalFonts(); | 205 static SkTDArray<FontRec>& CanonicalFonts(); |
206 static SkBaseMutex& CanonicalFontsMutex(); | 206 static SkBaseMutex& CanonicalFontsMutex(); |
207 typedef SkPDFDict INHERITED; | 207 typedef SkPDFDict INHERITED; |
208 }; | 208 }; |
209 | 209 |
210 #endif | 210 #endif |
OLD | NEW |