| 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 |
| 11 #define SkPDFFont_DEFINED | 11 #define SkPDFFont_DEFINED |
| 12 | 12 |
| 13 #include "SkAdvancedTypefaceMetrics.h" | 13 #include "SkAdvancedTypefaceMetrics.h" |
| 14 #include "SkBitSet.h" | 14 #include "SkBitSet.h" |
| 15 #include "SkPDFTypes.h" | 15 #include "SkPDFTypes.h" |
| 16 #include "SkTDArray.h" | 16 #include "SkTDArray.h" |
| 17 #include "SkThread.h" | 17 #include "SkThread.h" |
| 18 #include "SkTypeface.h" | 18 #include "SkTypeface.h" |
| 19 | 19 |
| 20 class SkPaint; | 20 class SkPaint; |
| 21 class SkPDFCanon; |
| 21 class SkPDFCatalog; | 22 class SkPDFCatalog; |
| 22 class SkPDFFont; | 23 class SkPDFFont; |
| 23 | 24 |
| 24 class SkPDFGlyphSet : SkNoncopyable { | 25 class SkPDFGlyphSet : SkNoncopyable { |
| 25 public: | 26 public: |
| 26 SkPDFGlyphSet(); | 27 SkPDFGlyphSet(); |
| 27 | 28 |
| 28 void set(const uint16_t* glyphIDs, int numGlyphs); | 29 void set(const uint16_t* glyphIDs, int numGlyphs); |
| 29 bool has(uint16_t glyphID) const; | 30 bool has(uint16_t glyphID) const; |
| 30 void merge(const SkPDFGlyphSet& usage); | 31 void merge(const SkPDFGlyphSet& usage); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 int glyphsToPDFFontEncoding(uint16_t* glyphIDs, int numGlyphs); | 120 int glyphsToPDFFontEncoding(uint16_t* glyphIDs, int numGlyphs); |
| 120 | 121 |
| 121 /** Get the font resource for the passed typeface and glyphID. The | 122 /** Get the font resource for the passed typeface and glyphID. The |
| 122 * reference count of the object is incremented and it is the caller's | 123 * reference count of the object is incremented and it is the caller's |
| 123 * responsibility to unreference it when done. This is needed to | 124 * responsibility to unreference it when done. This is needed to |
| 124 * accommodate the weak reference pattern used when the returned object | 125 * accommodate the weak reference pattern used when the returned object |
| 125 * is new and has no other references. | 126 * is new and has no other references. |
| 126 * @param typeface The typeface to find. | 127 * @param typeface The typeface to find. |
| 127 * @param glyphID Specify which section of a large font is of interest. | 128 * @param glyphID Specify which section of a large font is of interest. |
| 128 */ | 129 */ |
| 129 static SkPDFFont* GetFontResource(SkTypeface* typeface, uint16_t glyphID); | 130 static SkPDFFont* GetFontResource(SkPDFCanon* canon, |
| 131 SkTypeface* typeface, |
| 132 uint16_t glyphID); |
| 130 | 133 |
| 131 /** 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 |
| 132 * subset. | 135 * subset. |
| 133 * @param usage Glyph subset requested. | 136 * @param usage Glyph subset requested. |
| 134 * @return NULL if font does not support subsetting, a new instance | 137 * @return NULL if font does not support subsetting, a new instance |
| 135 * of SkPDFFont otherwise. | 138 * of SkPDFFont otherwise. |
| 136 */ | 139 */ |
| 137 virtual SkPDFFont* getFontSubset(const SkPDFGlyphSet* usage); | 140 virtual SkPDFFont* getFontSubset(const SkPDFGlyphSet* usage); |
| 138 | 141 |
| 139 enum Match { | 142 enum Match { |
| 140 kExact_Match, | 143 kExact_Match, |
| 141 kRelated_Match, | 144 kRelated_Match, |
| 142 kNot_Match, | 145 kNot_Match, |
| 143 }; | 146 }; |
| 144 static Match IsMatch(SkPDFFont* existingFont, | 147 static Match IsMatch(SkPDFFont* existingFont, |
| 145 uint32_t existingFontID, | 148 uint32_t existingFontID, |
| 146 uint16_t existingGlyphID, | 149 uint16_t existingGlyphID, |
| 147 uint32_t searchFontID, | 150 uint32_t searchFontID, |
| 148 uint16_t searchGlyphID); | 151 uint16_t searchGlyphID); |
| 149 | 152 |
| 150 protected: | 153 protected: |
| 154 SkPDFCanon* const fCanon; |
| 155 |
| 151 // Common constructor to handle common members. | 156 // Common constructor to handle common members. |
| 152 SkPDFFont(const SkAdvancedTypefaceMetrics* fontInfo, SkTypeface* typeface, | 157 SkPDFFont(SkPDFCanon* canon, |
| 158 const SkAdvancedTypefaceMetrics* fontInfo, |
| 159 SkTypeface* typeface, |
| 153 SkPDFDict* relatedFontDescriptor); | 160 SkPDFDict* relatedFontDescriptor); |
| 154 | 161 |
| 155 // Accessors for subclass. | 162 // Accessors for subclass. |
| 156 const SkAdvancedTypefaceMetrics* fontInfo(); | 163 const SkAdvancedTypefaceMetrics* fontInfo(); |
| 157 void setFontInfo(const SkAdvancedTypefaceMetrics* info); | 164 void setFontInfo(const SkAdvancedTypefaceMetrics* info); |
| 158 uint16_t firstGlyphID() const; | 165 uint16_t firstGlyphID() const; |
| 159 uint16_t lastGlyphID() const; | 166 uint16_t lastGlyphID() const; |
| 160 void setLastGlyphID(uint16_t glyphID); | 167 void setLastGlyphID(uint16_t glyphID); |
| 161 | 168 |
| 162 // Accessors for FontDescriptor associated with this object. | 169 // Accessors for FontDescriptor associated with this object. |
| 163 SkPDFDict* getFontDescriptor(); | 170 SkPDFDict* getFontDescriptor(); |
| 164 void setFontDescriptor(SkPDFDict* descriptor); | 171 void setFontDescriptor(SkPDFDict* descriptor); |
| 165 | 172 |
| 166 // Add common entries to FontDescriptor. | 173 // Add common entries to FontDescriptor. |
| 167 bool addCommonFontDescriptorEntries(int16_t defaultWidth); | 174 bool addCommonFontDescriptorEntries(int16_t defaultWidth); |
| 168 | 175 |
| 169 /** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs, | 176 /** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs, |
| 170 * including the passed glyphID. | 177 * including the passed glyphID. |
| 171 */ | 178 */ |
| 172 void adjustGlyphRangeForSingleByteEncoding(uint16_t glyphID); | 179 void adjustGlyphRangeForSingleByteEncoding(uint16_t glyphID); |
| 173 | 180 |
| 174 // Generate ToUnicode table according to glyph usage subset. | 181 // Generate ToUnicode table according to glyph usage subset. |
| 175 // If subset is NULL, all available glyph ids will be used. | 182 // If subset is NULL, all available glyph ids will be used. |
| 176 void populateToUnicodeTable(const SkPDFGlyphSet* subset); | 183 void populateToUnicodeTable(const SkPDFGlyphSet* subset); |
| 177 | 184 |
| 178 // Create instances of derived types based on fontInfo. | 185 // Create instances of derived types based on fontInfo. |
| 179 static SkPDFFont* Create(const SkAdvancedTypefaceMetrics* fontInfo, | 186 static SkPDFFont* Create(SkPDFCanon* canon, |
| 180 SkTypeface* typeface, uint16_t glyphID, | 187 const SkAdvancedTypefaceMetrics* fontInfo, |
| 188 SkTypeface* typeface, |
| 189 uint16_t glyphID, |
| 181 SkPDFDict* relatedFontDescriptor); | 190 SkPDFDict* relatedFontDescriptor); |
| 182 | 191 |
| 183 static bool Find(uint32_t fontID, uint16_t glyphID, int* index); | 192 static bool Find(uint32_t fontID, uint16_t glyphID, int* index); |
| 184 | 193 |
| 185 private: | 194 private: |
| 186 SkAutoTUnref<SkTypeface> fTypeface; | 195 SkAutoTUnref<SkTypeface> fTypeface; |
| 187 | 196 |
| 188 // The glyph IDs accessible with this font. For Type1 (non CID) fonts, | 197 // The glyph IDs accessible with this font. For Type1 (non CID) fonts, |
| 189 // this will be a subset if the font has more than 255 glyphs. | 198 // this will be a subset if the font has more than 255 glyphs. |
| 190 uint16_t fFirstGlyphID; | 199 uint16_t fFirstGlyphID; |
| 191 uint16_t fLastGlyphID; | 200 uint16_t fLastGlyphID; |
| 192 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fFontInfo; | 201 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fFontInfo; |
| 193 SkAutoTUnref<SkPDFDict> fDescriptor; | 202 SkAutoTUnref<SkPDFDict> fDescriptor; |
| 194 | 203 |
| 195 SkAdvancedTypefaceMetrics::FontType fFontType; | 204 SkAdvancedTypefaceMetrics::FontType fFontType; |
| 196 | 205 |
| 197 typedef SkPDFDict INHERITED; | 206 typedef SkPDFDict INHERITED; |
| 198 }; | 207 }; |
| 199 | 208 |
| 200 #endif | 209 #endif |
| OLD | NEW |