| 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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 return true; | 491 return true; |
| 492 } | 492 } |
| 493 return (fFontInfo->fFlags & | 493 return (fFontInfo->fFlags & |
| 494 SkAdvancedTypefaceMetrics::kNotSubsettable_FontFlag) == 0; | 494 SkAdvancedTypefaceMetrics::kNotSubsettable_FontFlag) == 0; |
| 495 } | 495 } |
| 496 | 496 |
| 497 bool SkPDFFont::hasGlyph(uint16_t id) { | 497 bool SkPDFFont::hasGlyph(uint16_t id) { |
| 498 return (id >= fFirstGlyphID && id <= fLastGlyphID) || id == 0; | 498 return (id >= fFirstGlyphID && id <= fLastGlyphID) || id == 0; |
| 499 } | 499 } |
| 500 | 500 |
| 501 int SkPDFFont::glyphsToPDFFontEncoding(uint16_t* glyphIDs, int numGlyphs) { | 501 int SkPDFFont::glyphsToPDFFontEncoding(SkGlyphID* glyphIDs, int numGlyphs) const
{ |
| 502 // A font with multibyte glyphs will support all glyph IDs in a single font. | 502 // A font with multibyte glyphs will support all glyph IDs in a single font. |
| 503 if (this->multiByteGlyphs()) { | 503 if (this->multiByteGlyphs()) { |
| 504 return numGlyphs; | 504 return numGlyphs; |
| 505 } | 505 } |
| 506 | 506 |
| 507 for (int i = 0; i < numGlyphs; i++) { | 507 for (int i = 0; i < numGlyphs; i++) { |
| 508 if (glyphIDs[i] == 0) { | 508 if (glyphIDs[i] == 0) { |
| 509 continue; | 509 continue; |
| 510 } | 510 } |
| 511 if (glyphIDs[i] < fFirstGlyphID || glyphIDs[i] > fLastGlyphID) { | 511 if (glyphIDs[i] < fFirstGlyphID || glyphIDs[i] > fLastGlyphID) { |
| 512 return i; | 512 return i; |
| 513 } | 513 } |
| 514 glyphIDs[i] -= (fFirstGlyphID - 1); | 514 glyphIDs[i] -= (fFirstGlyphID - 1); |
| 515 } | 515 } |
| 516 | 516 |
| 517 return numGlyphs; | 517 return numGlyphs; |
| 518 } | 518 } |
| 519 | 519 |
| 520 int SkPDFFont::glyphsToPDFFontEncodingCount(const SkGlyphID* glyphIDs, |
| 521 int numGlyphs) const { |
| 522 if (this->multiByteGlyphs()) { // A font with multibyte glyphs will |
| 523 return numGlyphs; // support all glyph IDs in a single font. |
| 524 } |
| 525 for (int i = 0; i < numGlyphs; i++) { |
| 526 if (glyphIDs[i] != 0 && |
| 527 (glyphIDs[i] < fFirstGlyphID || glyphIDs[i] > fLastGlyphID)) { |
| 528 return i; |
| 529 } |
| 530 } |
| 531 return numGlyphs; |
| 532 } |
| 533 |
| 520 // static | 534 // static |
| 521 SkPDFFont* SkPDFFont::GetFontResource(SkPDFCanon* canon, | 535 SkPDFFont* SkPDFFont::GetFontResource(SkPDFCanon* canon, |
| 522 SkTypeface* typeface, | 536 SkTypeface* typeface, |
| 523 uint16_t glyphID) { | 537 uint16_t glyphID) { |
| 524 SkASSERT(canon); | 538 SkASSERT(canon); |
| 525 const uint32_t fontID = SkTypeface::UniqueID(typeface); | 539 const uint32_t fontID = SkTypeface::UniqueID(typeface); |
| 526 SkPDFFont* relatedFont; | 540 SkPDFFont* relatedFont; |
| 527 if (SkPDFFont* pdfFont = canon->findFont(fontID, glyphID, &relatedFont)) { | 541 if (SkPDFFont* pdfFont = canon->findFont(fontID, glyphID, &relatedFont)) { |
| 528 return SkRef(pdfFont); | 542 return SkRef(pdfFont); |
| 529 } | 543 } |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 searchGlyphID <= existingFont->fLastGlyphID) | 1274 searchGlyphID <= existingFont->fLastGlyphID) |
| 1261 ? SkPDFFont::kExact_Match | 1275 ? SkPDFFont::kExact_Match |
| 1262 : SkPDFFont::kRelated_Match; | 1276 : SkPDFFont::kRelated_Match; |
| 1263 } | 1277 } |
| 1264 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match | 1278 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match |
| 1265 : SkPDFFont::kRelated_Match; | 1279 : SkPDFFont::kRelated_Match; |
| 1266 } | 1280 } |
| 1267 | 1281 |
| 1268 // Since getAdvancedTypefaceMetrics is expensive, cache the result. | 1282 // Since getAdvancedTypefaceMetrics is expensive, cache the result. |
| 1269 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) { | 1283 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) { |
| 1270 SkAutoResolveDefaultTypeface face(typeface); | 1284 SkFontID id = SkTypeface::UniqueID(typeface); |
| 1271 uint32_t id = face->uniqueID(); | |
| 1272 if (bool* value = canon->fCanEmbedTypeface.find(id)) { | 1285 if (bool* value = canon->fCanEmbedTypeface.find(id)) { |
| 1273 return *value; | 1286 return *value; |
| 1274 } | 1287 } |
| 1288 SkAutoResolveDefaultTypeface face(typeface); |
| 1275 bool canEmbed = true; | 1289 bool canEmbed = true; |
| 1276 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics( | 1290 sk_sp<const SkAdvancedTypefaceMetrics> fontMetrics( |
| 1277 face->getAdvancedTypefaceMetrics( | 1291 face->getAdvancedTypefaceMetrics( |
| 1278 SkTypeface::kNo_PerGlyphInfo, nullptr, 0)); | 1292 SkTypeface::kNo_PerGlyphInfo, nullptr, 0)); |
| 1279 if (fontMetrics) { | 1293 if (fontMetrics) { |
| 1280 canEmbed = !SkToBool( | 1294 canEmbed = !SkToBool( |
| 1281 fontMetrics->fFlags & | 1295 fontMetrics->fFlags & |
| 1282 SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag); | 1296 SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag); |
| 1283 } | 1297 } |
| 1284 return *canon->fCanEmbedTypeface.set(id, canEmbed); | 1298 return *canon->fCanEmbedTypeface.set(id, canEmbed); |
| 1285 } | 1299 } |
| 1286 | 1300 |
| 1287 void SkPDFFont::drop() { | 1301 void SkPDFFont::drop() { |
| 1288 fTypeface = nullptr; | 1302 fTypeface = nullptr; |
| 1289 fFontInfo = nullptr; | 1303 fFontInfo = nullptr; |
| 1290 fDescriptor = nullptr; | 1304 fDescriptor = nullptr; |
| 1291 this->SkPDFDict::drop(); | 1305 this->SkPDFDict::drop(); |
| 1292 } | 1306 } |
| OLD | NEW |