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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 canon->fTypefaceMetrics.set(id, nullptr); | 160 canon->fTypefaceMetrics.set(id, nullptr); |
161 return nullptr; | 161 return nullptr; |
162 } | 162 } |
163 sk_sp<SkAdvancedTypefaceMetrics> metrics( | 163 sk_sp<SkAdvancedTypefaceMetrics> metrics( |
164 typeface->getAdvancedTypefaceMetrics( | 164 typeface->getAdvancedTypefaceMetrics( |
165 SkTypeface::kGlyphNames_PerGlyphInfo | SkTypeface::kToUnicod
e_PerGlyphInfo, | 165 SkTypeface::kGlyphNames_PerGlyphInfo | SkTypeface::kToUnicod
e_PerGlyphInfo, |
166 nullptr, 0)); | 166 nullptr, 0)); |
167 if (!metrics) { | 167 if (!metrics) { |
168 metrics = sk_make_sp<SkAdvancedTypefaceMetrics>(); | 168 metrics = sk_make_sp<SkAdvancedTypefaceMetrics>(); |
169 metrics->fLastGlyphID = SkToU16(count - 1); | 169 metrics->fLastGlyphID = SkToU16(count - 1); |
170 } | 170 } |
171 SkASSERT(metrics->fLastGlyphID == SkToU16(count - 1)); | 171 SkASSERT(metrics->fLastGlyphID == SkToU16(count - 1)); |
172 return *canon->fTypefaceMetrics.set(id, metrics.release()); | 172 return *canon->fTypefaceMetrics.set(id, metrics.release()); |
173 } | 173 } |
174 | 174 |
175 SkAdvancedTypefaceMetrics::FontType font_type(const SkAdvancedTypefaceMetrics& m
etrics) { | 175 SkAdvancedTypefaceMetrics::FontType font_type(const SkAdvancedTypefaceMetrics& m
etrics) { |
176 if (SkToBool(metrics.fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFl
ag)) { | 176 if (SkToBool(metrics.fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFl
ag)) { |
177 // force Type3 fallback. | 177 // force Type3 fallback. |
178 return SkAdvancedTypefaceMetrics::kOther_Font; | 178 return SkAdvancedTypefaceMetrics::kOther_Font; |
179 } | 179 } |
180 return metrics.fType; | 180 return metrics.fType; |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 } | 596 } |
597 | 597 |
598 static void add_type3_font_info(SkPDFCanon* canon, | 598 static void add_type3_font_info(SkPDFCanon* canon, |
599 SkPDFDict* font, | 599 SkPDFDict* font, |
600 SkTypeface* typeface, | 600 SkTypeface* typeface, |
601 SkScalar emSize, | 601 SkScalar emSize, |
602 const SkBitSet& subset, | 602 const SkBitSet& subset, |
603 SkGlyphID firstGlyphID, | 603 SkGlyphID firstGlyphID, |
604 SkGlyphID lastGlyphID) { | 604 SkGlyphID lastGlyphID) { |
605 SkASSERT(lastGlyphID >= firstGlyphID); | 605 SkASSERT(lastGlyphID >= firstGlyphID); |
| 606 // Remove unused glyphs at the end of the range. |
| 607 // Keep the lastGlyphID >= firstGlyphID invariant true. |
| 608 while (lastGlyphID > firstGlyphID && !subset.has(lastGlyphID)) { |
| 609 --lastGlyphID; |
| 610 } |
606 SkASSERT(emSize > 0.0f); | 611 SkASSERT(emSize > 0.0f); |
607 SkAutoGlyphCache cache = vector_cache(typeface, emSize); | 612 SkAutoGlyphCache cache = vector_cache(typeface, emSize); |
608 font->insertName("Subtype", "Type3"); | 613 font->insertName("Subtype", "Type3"); |
609 // Flip about the x-axis and scale by 1/emSize. | 614 // Flip about the x-axis and scale by 1/emSize. |
610 SkMatrix fontMatrix; | 615 SkMatrix fontMatrix; |
611 fontMatrix.setScale(SkScalarInvert(emSize), -SkScalarInvert(emSize)); | 616 fontMatrix.setScale(SkScalarInvert(emSize), -SkScalarInvert(emSize)); |
612 font->insertObject("FontMatrix", SkPDFUtils::MatrixToArray(fontMatrix)); | 617 font->insertObject("FontMatrix", SkPDFUtils::MatrixToArray(fontMatrix)); |
613 | 618 |
614 auto charProcs = sk_make_sp<SkPDFDict>(); | 619 auto charProcs = sk_make_sp<SkPDFDict>(); |
615 auto encoding = sk_make_sp<SkPDFDict>("Encoding"); | 620 auto encoding = sk_make_sp<SkPDFDict>("Encoding"); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 | 721 |
717 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) { | 722 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) { |
718 const SkAdvancedTypefaceMetrics* metrics = SkPDFFont::GetMetrics(typeface, c
anon); | 723 const SkAdvancedTypefaceMetrics* metrics = SkPDFFont::GetMetrics(typeface, c
anon); |
719 return metrics && can_embed(*metrics); | 724 return metrics && can_embed(*metrics); |
720 } | 725 } |
721 | 726 |
722 void SkPDFFont::drop() { | 727 void SkPDFFont::drop() { |
723 fTypeface = nullptr; | 728 fTypeface = nullptr; |
724 this->SkPDFDict::drop(); | 729 this->SkPDFDict::drop(); |
725 } | 730 } |
OLD | NEW |