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

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

Issue 2278703002: SkPDF: Glyph validation change (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix comment 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 /** Returns true if this font encoding supports glyph IDs above 255. 48 /** Returns true if this font encoding supports glyph IDs above 255.
49 */ 49 */
50 bool multiByteGlyphs() const { return SkPDFFont::IsMultiByte(this->getType() ); } 50 bool multiByteGlyphs() const { return SkPDFFont::IsMultiByte(this->getType() ); }
51 51
52 /** Return true if this font has an encoding for the passed glyph id. 52 /** Return true if this font has an encoding for the passed glyph id.
53 */ 53 */
54 bool hasGlyph(SkGlyphID gid) { 54 bool hasGlyph(SkGlyphID gid) {
55 return (gid >= fFirstGlyphID && gid <= fLastGlyphID) || gid == 0; 55 return (gid >= fFirstGlyphID && gid <= fLastGlyphID) || gid == 0;
56 } 56 }
57 57
58 /** Convert (in place) the input glyph IDs into the font encoding. If the 58 /** Convert the input glyph ID into the font encoding. */
59 * font has more glyphs than can be encoded (like a type 1 font with more 59 SkGlyphID glyphToPDFFontEncoding(SkGlyphID gid) const {
60 * than 255 glyphs) this method only converts up to the first out of range 60 if (this->multiByteGlyphs() || gid == 0) {
61 * glyph ID. 61 return gid;
62 * @param glyphIDs The input text as glyph IDs. 62 }
63 * @param numGlyphs The number of input glyphs. 63 SkASSERT(gid >= fFirstGlyphID && gid <= fLastGlyphID);
64 * @return Returns the number of glyphs consumed. 64 SkASSERT(fFirstGlyphID > 0);
65 */ 65 return gid - fFirstGlyphID + 1;
66 int glyphsToPDFFontEncoding(SkGlyphID* glyphIDs, int numGlyphs) const; 66 }
67 /**
68 * Like above, but does not modify glyphIDs array.
69 */
70 int glyphsToPDFFontEncodingCount(const SkGlyphID* glyphIDs,
71 int numGlyphs) const;
72 67
73 void noteGlyphUsage(const SkGlyphID* glyphs, int count) { 68 /** Count the number of glyphIDs that can be encoded with this font.
74 fGlyphUsage.setAll(glyphs, count); 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) {
87 SkASSERT(this->hasGlyph(glyph));
88 fGlyphUsage.set(glyph);
75 } 89 }
76 90
77 /** Get the font resource for the passed typeface and glyphID. The 91 /** Get the font resource for the passed typeface and glyphID. The
78 * reference count of the object is incremented and it is the caller's 92 * reference count of the object is incremented and it is the caller's
79 * responsibility to unreference it when done. This is needed to 93 * responsibility to unreference it when done. This is needed to
80 * accommodate the weak reference pattern used when the returned object 94 * accommodate the weak reference pattern used when the returned object
81 * is new and has no other references. 95 * is new and has no other references.
82 * @param typeface The typeface to find. 96 * @param typeface The typeface to find, not nullptr.
83 * @param glyphID Specify which section of a large font is of interest. 97 * @param glyphID Specify which section of a large font is of interest.
84 */ 98 */
85 static SkPDFFont* GetFontResource(SkPDFCanon* canon, 99 static SkPDFFont* GetFontResource(SkPDFCanon* canon,
86 SkTypeface* typeface, 100 SkTypeface* typeface,
87 SkGlyphID glyphID); 101 SkGlyphID glyphID);
88 102
89 // Uses (kGlyphNames_PerGlyphInfo | kToUnicode_PerGlyphInfo). 103 /** Uses (kGlyphNames_PerGlyphInfo | kToUnicode_PerGlyphInfo) to get
104 * SkAdvancedTypefaceMetrics, and caches the result.
105 * @param typeface can not be nullptr.
106 * @return nullptr only when typeface is bad.
107 */
90 static const SkAdvancedTypefaceMetrics* GetMetrics(SkTypeface* typeface, 108 static const SkAdvancedTypefaceMetrics* GetMetrics(SkTypeface* typeface,
91 SkPDFCanon* canon); 109 SkPDFCanon* canon);
92 110
93 /** Subset the font based on current usage. 111 /** Subset the font based on current usage.
94 * Must be called before emitObject(). 112 * Must be called before emitObject().
95 */ 113 */
96 virtual void getFontSubset(SkPDFCanon*) = 0; 114 virtual void getFontSubset(SkPDFCanon*) = 0;
97 115
98 /** 116 /**
99 * Return false iff the typeface has its NotEmbeddable flag set. 117 * Return false iff the typeface has its NotEmbeddable flag set.
100 * If typeface is NULL, the default typeface is checked. 118 * typeface is not nullptr
101 */ 119 */
102 static bool CanEmbedTypeface(SkTypeface*, SkPDFCanon*); 120 static bool CanEmbedTypeface(SkTypeface*, SkPDFCanon*);
103 121
104 protected: 122 protected:
105 // Common constructor to handle common members. 123 // Common constructor to handle common members.
106 struct Info { 124 struct Info {
107 sk_sp<SkTypeface> fTypeface; 125 sk_sp<SkTypeface> fTypeface;
108 SkGlyphID fFirstGlyphID; 126 SkGlyphID fFirstGlyphID;
109 SkGlyphID fLastGlyphID; 127 SkGlyphID fLastGlyphID;
110 SkAdvancedTypefaceMetrics::FontType fFontType; 128 SkAdvancedTypefaceMetrics::FontType fFontType;
111 }; 129 };
112 SkPDFFont(Info); 130 SkPDFFont(Info);
113 131
114 SkGlyphID firstGlyphID() const { return fFirstGlyphID; } 132 SkGlyphID firstGlyphID() const { return fFirstGlyphID; }
115 SkGlyphID lastGlyphID() const { return fLastGlyphID; } 133 SkGlyphID lastGlyphID() const { return fLastGlyphID; }
116 const SkBitSet& glyphUsage() const { return fGlyphUsage; } 134 const SkBitSet& glyphUsage() const { return fGlyphUsage; }
117 sk_sp<SkTypeface> refTypeface() const { return fTypeface; } 135 sk_sp<SkTypeface> refTypeface() const { return fTypeface; }
118 136
119 void drop() override; 137 void drop() override;
120 138
121 private: 139 private:
122 sk_sp<SkTypeface> fTypeface; 140 sk_sp<SkTypeface> fTypeface;
123 SkBitSet fGlyphUsage; 141 SkBitSet fGlyphUsage;
124 142
125 // The glyph IDs accessible with this font. For Type1 (non CID) fonts, 143 // The glyph IDs accessible with this font. For Type1 (non CID) fonts,
126 // this will be a subset if the font has more than 255 glyphs. 144 // this will be a subset if the font has more than 255 glyphs.
127 SkGlyphID fFirstGlyphID; 145 const SkGlyphID fFirstGlyphID;
128 SkGlyphID fLastGlyphID; 146 const SkGlyphID fLastGlyphID;
129 SkAdvancedTypefaceMetrics::FontType fFontType; 147 const SkAdvancedTypefaceMetrics::FontType fFontType;
130 148
131 typedef SkPDFDict INHERITED; 149 typedef SkPDFDict INHERITED;
132 }; 150 };
133 151
134 #endif 152 #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