Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: src/pdf/SkPDFFont.h

Issue 2253993002: SkPDF: cache metrics once. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-08-18 (Thursday) 11:37:09 EDT Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFDocument.cpp ('k') | src/pdf/SkPDFFont.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 void noteGlyphUsage(SkPDFFont* font, const uint16_t* glyphIDs, 54 void noteGlyphUsage(SkPDFFont* font, const uint16_t* glyphIDs,
55 int numGlyphs); 55 int numGlyphs);
56 56
57 private: 57 private:
58 SkPDFGlyphSet* getGlyphSetForFont(SkPDFFont* font); 58 SkPDFGlyphSet* getGlyphSetForFont(SkPDFFont* font);
59 59
60 SkTArray<FontGlyphSetPair> fMap; 60 SkTArray<FontGlyphSetPair> fMap;
61 }; 61 };
62 62
63
64 /** \class SkPDFFont 63 /** \class SkPDFFont
65 A PDF Object class representing a font. The font may have resources 64 A PDF Object class representing a font. The font may have resources
66 attached to it in order to embed the font. SkPDFFonts are canonicalized 65 attached to it in order to embed the font. SkPDFFonts are canonicalized
67 so that resource deduplication will only include one copy of a font. 66 so that resource deduplication will only include one copy of a font.
68 This class uses the same pattern as SkPDFGraphicState, a static weak 67 This class uses the same pattern as SkPDFGraphicState, a static weak
69 reference to each instantiated class. 68 reference to each instantiated class.
70 */ 69 */
71 class SkPDFFont : public SkPDFDict { 70 class SkPDFFont : public SkPDFDict {
72 71
73 public: 72 public:
74 virtual ~SkPDFFont(); 73 virtual ~SkPDFFont();
75 74
76 /** Returns the typeface represented by this class. Returns nullptr for the 75 /** Returns the typeface represented by this class. Returns nullptr for the
77 * default typeface. 76 * default typeface.
78 */ 77 */
79 SkTypeface* typeface() { return fTypeface.get(); } 78 SkTypeface* typeface() const { return fTypeface.get(); }
80 79
81 /** Returns the font type represented in this font. For Type0 fonts, 80 /** Returns the font type represented in this font. For Type0 fonts,
82 * returns the type of the decendant font. 81 * returns the type of the decendant font.
83 */ 82 */
84 SkAdvancedTypefaceMetrics::FontType getType() { return fFontType; } 83 SkAdvancedTypefaceMetrics::FontType getType() const { return fFontType; }
84
85 static bool IsMultiByte(SkAdvancedTypefaceMetrics::FontType type) {
86 return type == SkAdvancedTypefaceMetrics::kType1CID_Font ||
87 type == SkAdvancedTypefaceMetrics::kTrueType_Font;
88 }
85 89
86 /** Returns true if this font encoding supports glyph IDs above 255. 90 /** Returns true if this font encoding supports glyph IDs above 255.
87 */ 91 */
88 bool multiByteGlyphs() const { return fMultiByteGlyphs; } 92 bool multiByteGlyphs() const { return SkPDFFont::IsMultiByte(this->getType() ); }
89
90 /** Returns true if the machine readable licensing bits allow embedding.
91 */
92 bool canEmbed() const;
93
94 /** Returns true if the machine readable licensing bits allow subsetting.
95 */
96 bool canSubset() const;
97 93
98 /** Return true if this font has an encoding for the passed glyph id. 94 /** Return true if this font has an encoding for the passed glyph id.
99 */ 95 */
100 bool hasGlyph(uint16_t glyphID); 96 bool hasGlyph(SkGlyphID gid) {
97 return (gid >= fFirstGlyphID && gid <= fLastGlyphID) || gid == 0;
98 }
101 99
102 /** Convert (in place) the input glyph IDs into the font encoding. If the 100 /** Convert (in place) the input glyph IDs into the font encoding. If the
103 * font has more glyphs than can be encoded (like a type 1 font with more 101 * font has more glyphs than can be encoded (like a type 1 font with more
104 * than 255 glyphs) this method only converts up to the first out of range 102 * than 255 glyphs) this method only converts up to the first out of range
105 * glyph ID. 103 * glyph ID.
106 * @param glyphIDs The input text as glyph IDs. 104 * @param glyphIDs The input text as glyph IDs.
107 * @param numGlyphs The number of input glyphs. 105 * @param numGlyphs The number of input glyphs.
108 * @return Returns the number of glyphs consumed. 106 * @return Returns the number of glyphs consumed.
109 */ 107 */
110 int glyphsToPDFFontEncoding(SkGlyphID* glyphIDs, int numGlyphs) const; 108 int glyphsToPDFFontEncoding(SkGlyphID* glyphIDs, int numGlyphs) const;
111 /** 109 /**
112 * Like above, but does not modify glyphIDs array. 110 * Like above, but does not modify glyphIDs array.
113 */ 111 */
114 int glyphsToPDFFontEncodingCount(const SkGlyphID* glyphIDs, 112 int glyphsToPDFFontEncodingCount(const SkGlyphID* glyphIDs,
115 int numGlyphs) const; 113 int numGlyphs) const;
116 114
117 /** Get the font resource for the passed typeface and glyphID. The 115 /** Get the font resource for the passed typeface and glyphID. The
118 * reference count of the object is incremented and it is the caller's 116 * reference count of the object is incremented and it is the caller's
119 * responsibility to unreference it when done. This is needed to 117 * responsibility to unreference it when done. This is needed to
120 * accommodate the weak reference pattern used when the returned object 118 * accommodate the weak reference pattern used when the returned object
121 * is new and has no other references. 119 * is new and has no other references.
122 * @param typeface The typeface to find. 120 * @param typeface The typeface to find.
123 * @param glyphID Specify which section of a large font is of interest. 121 * @param glyphID Specify which section of a large font is of interest.
124 */ 122 */
125 static SkPDFFont* GetFontResource(SkPDFCanon* canon, 123 static SkPDFFont* GetFontResource(SkPDFCanon* canon,
126 SkTypeface* typeface, 124 SkTypeface* typeface,
127 uint16_t glyphID); 125 SkGlyphID glyphID);
128 126
129 static sk_sp<const SkAdvancedTypefaceMetrics> GetFontMetricsWithToUnicode( 127 // Uses (kGlyphNames_PerGlyphInfo | kToUnicode_PerGlyphInfo).
130 SkTypeface*, uint32_t* glyphs, uint32_t glyphsCount); 128 static const SkAdvancedTypefaceMetrics* GetMetrics(SkTypeface* typeface,
129 SkPDFCanon* canon);
131 130
132 /** Subset the font based on usage set. Returns a SkPDFFont instance with 131 /** Subset the font based on usage set. Returns a SkPDFFont instance with
133 * subset. 132 * subset.
134 * @param usage Glyph subset requested. 133 * @param usage Glyph subset requested.
135 * @return nullptr if font does not support subsetting, a new instanc e 134 * @return nullptr if font does not support subsetting, a new instanc e
136 * of SkPDFFont otherwise. 135 * of SkPDFFont otherwise.
137 */ 136 */
138 virtual sk_sp<SkPDFObject> getFontSubset(const SkPDFGlyphSet* usage); 137 virtual sk_sp<SkPDFObject> getFontSubset(SkPDFCanon* canon,
139 138 const SkPDFGlyphSet* usage);
140 enum Match {
141 kExact_Match,
142 kRelated_Match,
143 kNot_Match,
144 };
145 static Match IsMatch(SkPDFFont* existingFont,
146 uint32_t existingFontID,
147 uint16_t existingGlyphID,
148 uint32_t searchFontID,
149 uint16_t searchGlyphID);
150 139
151 /** 140 /**
152 * Return false iff the typeface has its NotEmbeddable flag set. 141 * Return false iff the typeface has its NotEmbeddable flag set.
153 * If typeface is NULL, the default typeface is checked. 142 * If typeface is NULL, the default typeface is checked.
154 */ 143 */
155 static bool CanEmbedTypeface(SkTypeface*, SkPDFCanon*); 144 static bool CanEmbedTypeface(SkTypeface*, SkPDFCanon*);
156 145
157 protected: 146 protected:
158 // Common constructor to handle common members. 147 // Common constructor to handle common members.
159 SkPDFFont(sk_sp<const SkAdvancedTypefaceMetrics> fontInfo, 148 SkPDFFont(sk_sp<SkTypeface> typeface,
160 sk_sp<SkTypeface> typeface, 149 SkAdvancedTypefaceMetrics::FontType fontType);
161 sk_sp<SkPDFDict> relatedFontDescriptor,
162 SkAdvancedTypefaceMetrics::FontType fontType,
163 bool multiByteGlyphs);
164 150
165 // Accessors for subclass.
166 const SkAdvancedTypefaceMetrics* getFontInfo() const { return fFontInfo.get( ); }
167 sk_sp<const SkAdvancedTypefaceMetrics> refFontInfo() const { return fFontInf o; }
168
169 void setFontInfo(sk_sp<const SkAdvancedTypefaceMetrics> info);
170 SkGlyphID firstGlyphID() const { return fFirstGlyphID; } 151 SkGlyphID firstGlyphID() const { return fFirstGlyphID; }
171 SkGlyphID lastGlyphID() const { return fLastGlyphID; } 152 SkGlyphID lastGlyphID() const { return fLastGlyphID; }
172 void setLastGlyphID(uint16_t glyphID);
173
174 // Accessors for FontDescriptor associated with this object.
175 SkPDFDict* getFontDescriptor() const { return fDescriptor.get(); }
176 sk_sp<SkPDFDict> refFontDescriptor() const { return fDescriptor; }
177 void setFontDescriptor(sk_sp<SkPDFDict> descriptor);
178 153
179 sk_sp<SkTypeface> refTypeface() const { return fTypeface; } 154 sk_sp<SkTypeface> refTypeface() const { return fTypeface; }
180 155
181 /** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs, 156 /** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs,
182 * including the passed glyphID. 157 * including the passed glyphID.
183 */ 158 */
184 void adjustGlyphRangeForSingleByteEncoding(uint16_t glyphID); 159 void adjustGlyphRangeForSingleByteEncoding(SkGlyphID glyphID);
185
186 // Generate ToUnicode table according to glyph usage subset.
187 // If subset is nullptr, all available glyph ids will be used.
188 void populateToUnicodeTable(const SkPDFGlyphSet* subset);
189
190 static bool Find(uint32_t fontID, uint16_t glyphID, int* index);
191 160
192 void drop() override; 161 void drop() override;
193 162
194 private: 163 private:
195 sk_sp<SkTypeface> fTypeface; 164 sk_sp<SkTypeface> fTypeface;
196 sk_sp<const SkAdvancedTypefaceMetrics> fFontInfo;
197 sk_sp<SkPDFDict> fDescriptor;
198 165
199 // The glyph IDs accessible with this font. For Type1 (non CID) fonts, 166 // The glyph IDs accessible with this font. For Type1 (non CID) fonts,
200 // this will be a subset if the font has more than 255 glyphs. 167 // this will be a subset if the font has more than 255 glyphs.
201 SkGlyphID fFirstGlyphID; 168 SkGlyphID fFirstGlyphID;
202 SkGlyphID fLastGlyphID; 169 SkGlyphID fLastGlyphID;
203 SkAdvancedTypefaceMetrics::FontType fFontType; 170 SkAdvancedTypefaceMetrics::FontType fFontType;
204 bool fMultiByteGlyphs;
205 171
206 typedef SkPDFDict INHERITED; 172 typedef SkPDFDict INHERITED;
207 }; 173 };
208 174
209 #endif 175 #endif
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDocument.cpp ('k') | src/pdf/SkPDFFont.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698