OLD | NEW |
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 #include "SkData.h" | 8 #include "SkData.h" |
9 #include "SkGlyphCache.h" | 9 #include "SkGlyphCache.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 SkTypeface::kGlyphNames_PerGlyphInfo | SkTypeface::kToUnicod
e_PerGlyphInfo, | 154 SkTypeface::kGlyphNames_PerGlyphInfo | SkTypeface::kToUnicod
e_PerGlyphInfo, |
155 nullptr, 0)); | 155 nullptr, 0)); |
156 if (!metrics) { | 156 if (!metrics) { |
157 metrics = sk_make_sp<SkAdvancedTypefaceMetrics>(); | 157 metrics = sk_make_sp<SkAdvancedTypefaceMetrics>(); |
158 metrics->fLastGlyphID = SkToU16(count - 1); | 158 metrics->fLastGlyphID = SkToU16(count - 1); |
159 } | 159 } |
160 SkASSERT(metrics->fLastGlyphID == SkToU16(count - 1)); | 160 SkASSERT(metrics->fLastGlyphID == SkToU16(count - 1)); |
161 return *canon->fTypefaceMetrics.set(id, metrics.release()); | 161 return *canon->fTypefaceMetrics.set(id, metrics.release()); |
162 } | 162 } |
163 | 163 |
164 SkAdvancedTypefaceMetrics::FontType font_type(const SkAdvancedTypefaceMetrics& m
etrics) { | 164 SkAdvancedTypefaceMetrics::FontType SkPDFFont::FontType(const SkAdvancedTypeface
Metrics& metrics) { |
165 if (SkToBool(metrics.fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFl
ag)) { | 165 if (SkToBool(metrics.fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFl
ag)) { |
166 // force Type3 fallback. | 166 // force Type3 fallback. |
167 return SkAdvancedTypefaceMetrics::kOther_Font; | 167 return SkAdvancedTypefaceMetrics::kOther_Font; |
168 } | 168 } |
169 return metrics.fType; | 169 return metrics.fType; |
170 } | 170 } |
171 | 171 |
172 static SkGlyphID first_nonzero_glyph_for_single_byte_encoding(SkGlyphID gid) { | 172 static SkGlyphID first_nonzero_glyph_for_single_byte_encoding(SkGlyphID gid) { |
173 return gid != 0 ? gid - (gid - 1) % 255 : 1; | 173 return gid != 0 ? gid - (gid - 1) % 255 : 1; |
174 } | 174 } |
175 | 175 |
176 SkPDFFont* SkPDFFont::GetFontResource(SkPDFCanon* canon, | 176 SkPDFFont* SkPDFFont::GetFontResource(SkPDFCanon* canon, |
177 SkTypeface* face, | 177 SkTypeface* face, |
178 SkGlyphID glyphID) { | 178 SkGlyphID glyphID) { |
179 SkASSERT(canon); | 179 SkASSERT(canon); |
180 SkASSERT(face); // All SkPDFDevice::internalDrawText ensures this. | 180 SkASSERT(face); // All SkPDFDevice::internalDrawText ensures this. |
181 const SkAdvancedTypefaceMetrics* fontMetrics = SkPDFFont::GetMetrics(face, c
anon); | 181 const SkAdvancedTypefaceMetrics* fontMetrics = SkPDFFont::GetMetrics(face, c
anon); |
182 SkASSERT(fontMetrics); // SkPDFDevice::internalDrawText ensures the typefac
e is good. | 182 SkASSERT(fontMetrics); // SkPDFDevice::internalDrawText ensures the typefac
e is good. |
183 // GetMetrics only returns null to signify a bad typ
eface. | 183 // GetMetrics only returns null to signify a bad typ
eface. |
184 const SkAdvancedTypefaceMetrics& metrics = *fontMetrics; | 184 const SkAdvancedTypefaceMetrics& metrics = *fontMetrics; |
185 SkAdvancedTypefaceMetrics::FontType type = font_type(metrics); | 185 SkAdvancedTypefaceMetrics::FontType type = SkPDFFont::FontType(metrics); |
186 bool multibyte = SkPDFFont::IsMultiByte(type); | 186 bool multibyte = SkPDFFont::IsMultiByte(type); |
187 SkGlyphID subsetCode = multibyte ? 0 : first_nonzero_glyph_for_single_byte_e
ncoding(glyphID); | 187 SkGlyphID subsetCode = multibyte ? 0 : first_nonzero_glyph_for_single_byte_e
ncoding(glyphID); |
188 uint64_t fontID = (SkTypeface::UniqueID(face) << 16) | subsetCode; | 188 uint64_t fontID = (SkTypeface::UniqueID(face) << 16) | subsetCode; |
189 | 189 |
190 if (SkPDFFont** found = canon->fFontMap.find(fontID)) { | 190 if (SkPDFFont** found = canon->fFontMap.find(fontID)) { |
191 SkPDFFont* foundFont = *found; | 191 SkPDFFont* foundFont = *found; |
192 SkASSERT(foundFont && multibyte == foundFont->multiByteGlyphs()); | 192 SkASSERT(foundFont && multibyte == foundFont->multiByteGlyphs()); |
193 return SkRef(foundFont); | 193 return SkRef(foundFont); |
194 } | 194 } |
195 | 195 |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 | 722 |
723 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) { | 723 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) { |
724 const SkAdvancedTypefaceMetrics* metrics = SkPDFFont::GetMetrics(typeface, c
anon); | 724 const SkAdvancedTypefaceMetrics* metrics = SkPDFFont::GetMetrics(typeface, c
anon); |
725 return metrics && can_embed(*metrics); | 725 return metrics && can_embed(*metrics); |
726 } | 726 } |
727 | 727 |
728 void SkPDFFont::drop() { | 728 void SkPDFFont::drop() { |
729 fTypeface = nullptr; | 729 fTypeface = nullptr; |
730 this->SkPDFDict::drop(); | 730 this->SkPDFDict::drop(); |
731 } | 731 } |
OLD | NEW |