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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 * page/pdf device. c) in the document, retrieve the per font glyph usage | 135 * page/pdf device. c) in the document, retrieve the per font glyph usage |
136 * from each page and combine it and ask for a resource with that subset. | 136 * from each page and combine it and ask for a resource with that subset. |
137 */ | 137 */ |
138 | 138 |
139 SkPDFFont::~SkPDFFont() {} | 139 SkPDFFont::~SkPDFFont() {} |
140 | 140 |
141 static bool can_embed(const SkAdvancedTypefaceMetrics& metrics) { | 141 static bool can_embed(const SkAdvancedTypefaceMetrics& metrics) { |
142 return !SkToBool(metrics.fFlags & SkAdvancedTypefaceMetrics::kNotEmbeddable_
FontFlag); | 142 return !SkToBool(metrics.fFlags & SkAdvancedTypefaceMetrics::kNotEmbeddable_
FontFlag); |
143 } | 143 } |
144 | 144 |
| 145 #ifdef SK_SFNTLY_SUBSETTER |
145 static bool can_subset(const SkAdvancedTypefaceMetrics& metrics) { | 146 static bool can_subset(const SkAdvancedTypefaceMetrics& metrics) { |
146 return !SkToBool(metrics.fFlags & SkAdvancedTypefaceMetrics::kNotSubsettable
_FontFlag); | 147 return !SkToBool(metrics.fFlags & SkAdvancedTypefaceMetrics::kNotSubsettable
_FontFlag); |
147 } | 148 } |
| 149 #endif |
148 | 150 |
149 int SkPDFFont::glyphsToPDFFontEncoding(SkGlyphID* glyphIDs, int numGlyphs) const
{ | 151 int SkPDFFont::glyphsToPDFFontEncoding(SkGlyphID* glyphIDs, int numGlyphs) const
{ |
150 // A font with multibyte glyphs will support all glyph IDs in a single font. | 152 // A font with multibyte glyphs will support all glyph IDs in a single font. |
151 if (this->multiByteGlyphs()) { | 153 if (this->multiByteGlyphs()) { |
152 return numGlyphs; | 154 return numGlyphs; |
153 } | 155 } |
154 | 156 |
155 for (int i = 0; i < numGlyphs; i++) { | 157 for (int i = 0; i < numGlyphs; i++) { |
156 if (glyphIDs[i] == 0) { | 158 if (glyphIDs[i] == 0) { |
157 continue; | 159 continue; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 SkASSERT(fontAsset); | 410 SkASSERT(fontAsset); |
409 if (!fontAsset) { | 411 if (!fontAsset) { |
410 return; | 412 return; |
411 } | 413 } |
412 size_t fontSize = fontAsset->getLength(); | 414 size_t fontSize = fontAsset->getLength(); |
413 SkASSERT(fontSize > 0); | 415 SkASSERT(fontSize > 0); |
414 if (fontSize == 0) { | 416 if (fontSize == 0) { |
415 return; | 417 return; |
416 } | 418 } |
417 | 419 |
418 #ifdef SK_SFNTLY_SUBSETTER | 420 #ifdef SK_SFNTLY_SUBSETTER |
419 if (can_subset(metrics)) { | 421 if (can_subset(metrics)) { |
420 // Generate glyph id array. in format needed by sfntly | 422 // Generate glyph id array. in format needed by sfntly |
421 SkTDArray<uint32_t> glyphIDs; | 423 SkTDArray<uint32_t> glyphIDs; |
422 if (!this->glyphUsage().has(0)) { | 424 if (!this->glyphUsage().has(0)) { |
423 glyphIDs.push(0); // Always include glyph 0. | 425 glyphIDs.push(0); // Always include glyph 0. |
424 } | 426 } |
425 this->glyphUsage().exportTo(&glyphIDs); | 427 this->glyphUsage().exportTo(&glyphIDs); |
426 sk_sp<SkPDFObject> subsetStream = get_subset_font_stream( | 428 sk_sp<SkPDFObject> subsetStream = get_subset_font_stream( |
427 std::move(fontAsset), glyphIDs, name.c_str()); | 429 std::move(fontAsset), glyphIDs, name.c_str()); |
428 if (subsetStream) { | 430 if (subsetStream) { |
429 descriptor->insertObjRef("FontFile2", std::move(subsetStream
)); | 431 descriptor->insertObjRef("FontFile2", std::move(subsetStream
)); |
430 break; | 432 break; |
431 } | 433 } |
432 // If subsetting fails, fall back to original font data. | 434 // If subsetting fails, fall back to original font data. |
433 fontAsset.reset(face->openStream(&ttcIndex)); | 435 fontAsset.reset(face->openStream(&ttcIndex)); |
434 } | 436 } |
435 #endif // SK_SFNTLY_SUBSETTER | 437 #endif // SK_SFNTLY_SUBSETTER |
436 auto fontStream = sk_make_sp<SkPDFSharedStream>(std::move(fontAsset)
); | 438 auto fontStream = sk_make_sp<SkPDFSharedStream>(std::move(fontAsset)
); |
437 fontStream->dict()->insertInt("Length1", fontSize); | 439 fontStream->dict()->insertInt("Length1", fontSize); |
438 descriptor->insertObjRef("FontFile2", std::move(fontStream)); | 440 descriptor->insertObjRef("FontFile2", std::move(fontStream)); |
439 break; | 441 break; |
440 } | 442 } |
441 case SkAdvancedTypefaceMetrics::kType1CID_Font: { | 443 case SkAdvancedTypefaceMetrics::kType1CID_Font: { |
442 std::unique_ptr<SkStreamAsset> fontData(face->openStream(nullptr)); | 444 std::unique_ptr<SkStreamAsset> fontData(face->openStream(nullptr)); |
443 SkASSERT(fontData); | 445 SkASSERT(fontData); |
444 SkASSERT(fontData->getLength() > 0); | 446 SkASSERT(fontData->getLength() > 0); |
445 if (!fontData || 0 == fontData->getLength()) { | 447 if (!fontData || 0 == fontData->getLength()) { |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 | 755 |
754 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) { | 756 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) { |
755 const SkAdvancedTypefaceMetrics* metrics = SkPDFFont::GetMetrics(typeface, c
anon); | 757 const SkAdvancedTypefaceMetrics* metrics = SkPDFFont::GetMetrics(typeface, c
anon); |
756 return metrics && can_embed(*metrics); | 758 return metrics && can_embed(*metrics); |
757 } | 759 } |
758 | 760 |
759 void SkPDFFont::drop() { | 761 void SkPDFFont::drop() { |
760 fTypeface = nullptr; | 762 fTypeface = nullptr; |
761 this->SkPDFDict::drop(); | 763 this->SkPDFDict::drop(); |
762 } | 764 } |
OLD | NEW |