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

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

Issue 2327953002: SkPDF: refactor & code cleanup ahead of https://crrev.com/2322403002 (Closed)
Patch Set: comments Created 4 years, 3 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/SkPDFDevice.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 22 matching lines...) Expand all
33 /** Returns the typeface represented by this class. Returns nullptr for the 33 /** Returns the typeface represented by this class. Returns nullptr for the
34 * default typeface. 34 * default typeface.
35 */ 35 */
36 SkTypeface* typeface() const { return fTypeface.get(); } 36 SkTypeface* typeface() const { return fTypeface.get(); }
37 37
38 /** Returns the font type represented in this font. For Type0 fonts, 38 /** Returns the font type represented in this font. For Type0 fonts,
39 * returns the type of the decendant font. 39 * returns the type of the decendant font.
40 */ 40 */
41 SkAdvancedTypefaceMetrics::FontType getType() const { return fFontType; } 41 SkAdvancedTypefaceMetrics::FontType getType() const { return fFontType; }
42 42
43 static SkAdvancedTypefaceMetrics::FontType FontType(const SkAdvancedTypeface Metrics&);
44
43 static bool IsMultiByte(SkAdvancedTypefaceMetrics::FontType type) { 45 static bool IsMultiByte(SkAdvancedTypefaceMetrics::FontType type) {
44 return type == SkAdvancedTypefaceMetrics::kType1CID_Font || 46 return type == SkAdvancedTypefaceMetrics::kType1CID_Font ||
45 type == SkAdvancedTypefaceMetrics::kTrueType_Font; 47 type == SkAdvancedTypefaceMetrics::kTrueType_Font;
46 } 48 }
47 49
48 /** Returns true if this font encoding supports glyph IDs above 255. 50 /** Returns true if this font encoding supports glyph IDs above 255.
49 */ 51 */
50 bool multiByteGlyphs() const { return SkPDFFont::IsMultiByte(this->getType() ); } 52 bool multiByteGlyphs() const { return SkPDFFont::IsMultiByte(this->getType() ); }
51 53
52 /** Return true if this font has an encoding for the passed glyph id. 54 /** Return true if this font has an encoding for the passed glyph id.
53 */ 55 */
54 bool hasGlyph(SkGlyphID gid) { 56 bool hasGlyph(SkGlyphID gid) {
55 return (gid >= fFirstGlyphID && gid <= fLastGlyphID) || gid == 0; 57 return (gid >= fFirstGlyphID && gid <= fLastGlyphID) || gid == 0;
56 } 58 }
57 59
58 /** Convert the input glyph ID into the font encoding. */ 60 /** Convert the input glyph ID into the font encoding. */
59 SkGlyphID glyphToPDFFontEncoding(SkGlyphID gid) const { 61 SkGlyphID glyphToPDFFontEncoding(SkGlyphID gid) const {
60 if (this->multiByteGlyphs() || gid == 0) { 62 if (this->multiByteGlyphs() || gid == 0) {
61 return gid; 63 return gid;
62 } 64 }
63 SkASSERT(gid >= fFirstGlyphID && gid <= fLastGlyphID); 65 SkASSERT(gid >= fFirstGlyphID && gid <= fLastGlyphID);
64 SkASSERT(fFirstGlyphID > 0); 66 SkASSERT(fFirstGlyphID > 0);
65 return gid - fFirstGlyphID + 1; 67 return gid - fFirstGlyphID + 1;
66 } 68 }
67 69
68 /** Count the number of glyphIDs that can be encoded with this font.
69 * glyphIDs > maxGlyphID are considered okay. */
70 int countStretch(const SkGlyphID* glyphIDs,
71 int numGlyphs,
72 SkGlyphID maxGlyphID) const {
73 if (this->multiByteGlyphs()) {
74 return numGlyphs;
75 }
76 for (int i = 0; i < numGlyphs; i++) {
77 SkGlyphID gid = glyphIDs[i];
78 if (gid != 0 && gid <= maxGlyphID &&
79 (gid < fFirstGlyphID || gid > fLastGlyphID)) {
80 return i;
81 }
82 }
83 return numGlyphs;
84 }
85
86 void noteGlyphUsage(SkGlyphID glyph) { 70 void noteGlyphUsage(SkGlyphID glyph) {
87 SkASSERT(this->hasGlyph(glyph)); 71 SkASSERT(this->hasGlyph(glyph));
88 fGlyphUsage.set(glyph); 72 fGlyphUsage.set(glyph);
89 } 73 }
90 74
91 /** Get the font resource for the passed typeface and glyphID. The 75 /** Get the font resource for the passed typeface and glyphID. The
92 * reference count of the object is incremented and it is the caller's 76 * reference count of the object is incremented and it is the caller's
93 * responsibility to unreference it when done. This is needed to 77 * responsibility to unreference it when done. This is needed to
94 * accommodate the weak reference pattern used when the returned object 78 * accommodate the weak reference pattern used when the returned object
95 * is new and has no other references. 79 * is new and has no other references.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // The glyph IDs accessible with this font. For Type1 (non CID) fonts, 127 // The glyph IDs accessible with this font. For Type1 (non CID) fonts,
144 // this will be a subset if the font has more than 255 glyphs. 128 // this will be a subset if the font has more than 255 glyphs.
145 const SkGlyphID fFirstGlyphID; 129 const SkGlyphID fFirstGlyphID;
146 const SkGlyphID fLastGlyphID; 130 const SkGlyphID fLastGlyphID;
147 const SkAdvancedTypefaceMetrics::FontType fFontType; 131 const SkAdvancedTypefaceMetrics::FontType fFontType;
148 132
149 typedef SkPDFDict INHERITED; 133 typedef SkPDFDict INHERITED;
150 }; 134 };
151 135
152 #endif 136 #endif
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | src/pdf/SkPDFFont.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698