Chromium Code Reviews| Index: src/pdf/SkPDFFont.cpp |
| diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp |
| index d8755ae9a38572bfe9cca0a73864e479a6c40278..8783f385b65eba91f3860013e95f630e1a9e478d 100644 |
| --- a/src/pdf/SkPDFFont.cpp |
| +++ b/src/pdf/SkPDFFont.cpp |
| @@ -584,6 +584,7 @@ static void sk_delete_array(const void* ptr, void*) { |
| } |
| #endif |
| +#if defined(SK_SFNTLY_SUBSETTER) |
| static size_t get_subset_font_stream(const char* fontName, |
| const SkTypeface* typeface, |
| const SkTDArray<uint32_t>& subset, |
| @@ -594,7 +595,6 @@ static size_t get_subset_font_stream(const char* fontName, |
| size_t fontSize = fontData->getLength(); |
| -#if defined (SK_SFNTLY_SUBSETTER) |
| // Read font into buffer. |
| SkPDFStream* subsetFontStream = NULL; |
| SkTDArray<unsigned char> originalFont; |
| @@ -625,15 +625,12 @@ static size_t get_subset_font_stream(const char* fontName, |
| return fontSize; |
| } |
| fontData->rewind(); |
| -#else |
| - sk_ignore_unused_variable(fontName); |
| - sk_ignore_unused_variable(subset); |
| -#endif |
| // Fail over: just embed the whole font. |
| *fontStream = new SkPDFStream(fontData.get()); |
| return fontSize; |
| } |
| +#endif |
| /////////////////////////////////////////////////////////////////////////////// |
| // class SkPDFGlyphSet |
| @@ -1062,40 +1059,43 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, |
| switch (getType()) { |
| case SkAdvancedTypefaceMetrics::kTrueType_Font: { |
| - SkAutoTUnref<SkPDFStream> fontStream; |
| size_t fontSize = 0; |
| - if (canSubset()) { |
| +#if defined(SK_SFNTLY_SUBSETTER) |
| + if (this->canSubset()) { |
| + SkAutoTUnref<SkPDFStream> fontStream; |
| SkPDFStream* rawStream = NULL; |
| fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), |
| typeface(), |
| *subset, |
| &rawStream); |
| - fontStream.reset(rawStream); |
| - } else { |
| - int ttcIndex; |
| - SkAutoTDelete<SkStream> fontData( |
| - typeface()->openStream(&ttcIndex)); |
| - fontStream.reset(new SkPDFStream(fontData.get())); |
| - fontSize = fontData->getLength(); |
| + if (rawStream) { |
| + fontStream.reset(rawStream); |
| + fontStream->insertInt("Length1", fontSize); |
| + descriptor->insertObjRef("FontFile2", fontStream.detach()); |
| + break; |
| + } |
| } |
| - SkASSERT(fontSize); |
| - SkASSERT(fontStream.get()); |
| - |
| - fontStream->insertInt("Length1", fontSize); |
| +#endif |
| + SkAutoTUnref<SkPDFSharedStream> fontStream; |
| + SkAutoTDelete<SkStreamAsset> fontData( |
| + this->typeface()->openStream(NULL)); |
| + SkASSERT(fontData); |
| + fontSize = fontData->getLength(); |
| + SkASSERT(fontSize > 0); |
| + fontStream.reset(new SkPDFSharedStream(fontData.detach())); |
| + fontStream->dict()->insertInt("Length1", fontSize); |
| descriptor->insertObjRef("FontFile2", fontStream.detach()); |
|
tomhudson
2015/08/19 19:27:51
The code duplication between here and (canSubset()
|
| break; |
| } |
| case SkAdvancedTypefaceMetrics::kCFF_Font: |
| case SkAdvancedTypefaceMetrics::kType1CID_Font: { |
| - int ttcIndex; |
| - SkAutoTDelete<SkStream> fontData(typeface()->openStream(&ttcIndex)); |
| - SkAutoTUnref<SkPDFStream> fontStream( |
| - new SkPDFStream(fontData.get())); |
| + SkAutoTUnref<SkPDFSharedStream> fontStream( |
| + new SkPDFSharedStream(this->typeface()->openStream(NULL))); |
| if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { |
| - fontStream->insertName("Subtype", "Type1C"); |
| + fontStream->dict()->insertName("Subtype", "Type1C"); |
|
tomhudson
2015/08/19 19:27:51
Is the addition of dict() a bugfix? A noop? An int
hal.canary
2015/08/19 19:34:20
I intentionally do not inherit from SkPDFDict anym
|
| } else { |
| - fontStream->insertName("Subtype", "CIDFontType0c"); |
| + fontStream->dict()->insertName("Subtype", "CIDFontType0c"); |
| } |
| descriptor->insertObjRef("FontFile3", fontStream.detach()); |
| break; |