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 <ctype.h> | 8 #include <ctype.h> |
9 | 9 |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 } | 583 } |
584 #endif | 584 #endif |
585 | 585 |
586 #if defined(SK_SFNTLY_SUBSETTER) | 586 #if defined(SK_SFNTLY_SUBSETTER) |
587 static size_t get_subset_font_stream(const char* fontName, | 587 static size_t get_subset_font_stream(const char* fontName, |
588 const SkTypeface* typeface, | 588 const SkTypeface* typeface, |
589 const SkTDArray<uint32_t>& subset, | 589 const SkTDArray<uint32_t>& subset, |
590 SkPDFStream** fontStream) { | 590 SkPDFStream** fontStream) { |
591 int ttcIndex; | 591 int ttcIndex; |
592 std::unique_ptr<SkStream> fontData(typeface->openStream(&ttcIndex)); | 592 std::unique_ptr<SkStream> fontData(typeface->openStream(&ttcIndex)); |
593 SkASSERT(fontData.get()); | 593 SkASSERT(fontData); |
| 594 if (!fontData) { |
| 595 return 0; |
| 596 } |
594 | 597 |
595 size_t fontSize = fontData->getLength(); | 598 size_t fontSize = fontData->getLength(); |
596 | 599 |
597 // Read font into buffer. | 600 // Read font into buffer. |
598 SkPDFStream* subsetFontStream = nullptr; | 601 SkPDFStream* subsetFontStream = nullptr; |
599 SkTDArray<unsigned char> originalFont; | 602 SkTDArray<unsigned char> originalFont; |
600 originalFont.setCount(SkToInt(fontSize)); | 603 originalFont.setCount(SkToInt(fontSize)); |
601 if (fontData->read(originalFont.begin(), fontSize) == fontSize) { | 604 if (fontData->read(originalFont.begin(), fontSize) == fontSize) { |
602 unsigned char* subsetFont = nullptr; | 605 unsigned char* subsetFont = nullptr; |
603 // sfntly requires unsigned int* to be passed in, as far as we know, | 606 // sfntly requires unsigned int* to be passed in, as far as we know, |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 case SkAdvancedTypefaceMetrics::kTrueType_Font: { | 1043 case SkAdvancedTypefaceMetrics::kTrueType_Font: { |
1041 size_t fontSize = 0; | 1044 size_t fontSize = 0; |
1042 #if defined(SK_SFNTLY_SUBSETTER) | 1045 #if defined(SK_SFNTLY_SUBSETTER) |
1043 if (this->canSubset()) { | 1046 if (this->canSubset()) { |
1044 sk_sp<SkPDFStream> fontStream; | 1047 sk_sp<SkPDFStream> fontStream; |
1045 SkPDFStream* rawStream = nullptr; | 1048 SkPDFStream* rawStream = nullptr; |
1046 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), | 1049 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), |
1047 typeface(), | 1050 typeface(), |
1048 *subset, | 1051 *subset, |
1049 &rawStream); | 1052 &rawStream); |
| 1053 if (0 == fontSize) { |
| 1054 return false; |
| 1055 } |
1050 if (rawStream) { | 1056 if (rawStream) { |
1051 fontStream.reset(rawStream); | 1057 fontStream.reset(rawStream); |
1052 fontStream->insertInt("Length1", fontSize); | 1058 fontStream->insertInt("Length1", fontSize); |
1053 descriptor->insertObjRef("FontFile2", std::move(fontStream))
; | 1059 descriptor->insertObjRef("FontFile2", std::move(fontStream))
; |
1054 break; | 1060 break; |
1055 } | 1061 } |
1056 } | 1062 } |
1057 #endif | 1063 #endif |
1058 sk_sp<SkPDFSharedStream> fontStream; | 1064 sk_sp<SkPDFSharedStream> fontStream; |
1059 std::unique_ptr<SkStreamAsset> fontData( | 1065 std::unique_ptr<SkStreamAsset> fontData( |
1060 this->typeface()->openStream(nullptr)); | 1066 this->typeface()->openStream(nullptr)); |
1061 SkASSERT(fontData); | 1067 SkASSERT(fontData); |
| 1068 if (!fontData || 0 == fontData->getLength()) { |
| 1069 return false; |
| 1070 } |
1062 fontSize = fontData->getLength(); | 1071 fontSize = fontData->getLength(); |
1063 SkASSERT(fontSize > 0); | 1072 SkASSERT(fontSize > 0); |
1064 fontStream.reset(new SkPDFSharedStream(fontData.release())); | 1073 fontStream.reset(new SkPDFSharedStream(fontData.release())); |
1065 fontStream->dict()->insertInt("Length1", fontSize); | 1074 fontStream->dict()->insertInt("Length1", fontSize); |
1066 descriptor->insertObjRef("FontFile2", std::move(fontStream)); | 1075 descriptor->insertObjRef("FontFile2", std::move(fontStream)); |
1067 break; | 1076 break; |
1068 } | 1077 } |
1069 case SkAdvancedTypefaceMetrics::kCFF_Font: | 1078 case SkAdvancedTypefaceMetrics::kCFF_Font: |
1070 case SkAdvancedTypefaceMetrics::kType1CID_Font: { | 1079 case SkAdvancedTypefaceMetrics::kType1CID_Font: { |
| 1080 std::unique_ptr<SkStreamAsset> fontData( |
| 1081 this->typeface()->openStream(nullptr)); |
| 1082 SkASSERT(fontData); |
| 1083 SkASSERT(fontData->getLength() > 0); |
| 1084 if (!fontData || 0 == fontData->getLength()) { |
| 1085 return false; |
| 1086 } |
1071 sk_sp<SkPDFSharedStream> fontStream( | 1087 sk_sp<SkPDFSharedStream> fontStream( |
1072 new SkPDFSharedStream(this->typeface()->openStream(nullptr))
); | 1088 new SkPDFSharedStream(fontData.release())); |
1073 | |
1074 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { | 1089 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { |
1075 fontStream->dict()->insertName("Subtype", "Type1C"); | 1090 fontStream->dict()->insertName("Subtype", "Type1C"); |
1076 } else { | 1091 } else { |
1077 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); | 1092 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); |
1078 } | 1093 } |
1079 descriptor->insertObjRef("FontFile3", std::move(fontStream)); | 1094 descriptor->insertObjRef("FontFile3", std::move(fontStream)); |
1080 break; | 1095 break; |
1081 } | 1096 } |
1082 default: | 1097 default: |
1083 SkASSERT(false); | 1098 SkASSERT(false); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 return true; | 1206 return true; |
1192 } | 1207 } |
1193 | 1208 |
1194 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); | 1209 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); |
1195 setFontDescriptor(descriptor.get()); | 1210 setFontDescriptor(descriptor.get()); |
1196 | 1211 |
1197 int ttcIndex; | 1212 int ttcIndex; |
1198 size_t header SK_INIT_TO_AVOID_WARNING; | 1213 size_t header SK_INIT_TO_AVOID_WARNING; |
1199 size_t data SK_INIT_TO_AVOID_WARNING; | 1214 size_t data SK_INIT_TO_AVOID_WARNING; |
1200 size_t trailer SK_INIT_TO_AVOID_WARNING; | 1215 size_t trailer SK_INIT_TO_AVOID_WARNING; |
1201 std::unique_ptr<SkStream> rawFontData(typeface()->openStream(&ttcIndex)); | 1216 std::unique_ptr<SkStreamAsset> rawFontData(typeface()->openStream(&ttcIndex)
); |
| 1217 SkASSERT(rawFontData); |
| 1218 SkASSERT(rawFontData->getLength() > 0); |
| 1219 if (!rawFontData || 0 == rawFontData->getLength()) { |
| 1220 return false; |
| 1221 } |
1202 sk_sp<SkData> fontData(handle_type1_stream(rawFontData.get(), &header, | 1222 sk_sp<SkData> fontData(handle_type1_stream(rawFontData.get(), &header, |
1203 &data, &trailer)); | 1223 &data, &trailer)); |
1204 if (fontData.get() == nullptr) { | 1224 if (fontData.get() == nullptr) { |
1205 return false; | 1225 return false; |
1206 } | 1226 } |
1207 SkASSERT(this->canEmbed()); | 1227 SkASSERT(this->canEmbed()); |
1208 auto fontStream = sk_make_sp<SkPDFStream>(fontData.get()); | 1228 auto fontStream = sk_make_sp<SkPDFStream>(fontData.get()); |
1209 fontStream->insertInt("Length1", header); | 1229 fontStream->insertInt("Length1", header); |
1210 fontStream->insertInt("Length2", data); | 1230 fontStream->insertInt("Length2", data); |
1211 fontStream->insertInt("Length3", trailer); | 1231 fontStream->insertInt("Length3", trailer); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 } | 1438 } |
1419 return *canon->fCanEmbedTypeface.set(id, canEmbed); | 1439 return *canon->fCanEmbedTypeface.set(id, canEmbed); |
1420 } | 1440 } |
1421 | 1441 |
1422 void SkPDFFont::drop() { | 1442 void SkPDFFont::drop() { |
1423 fTypeface = nullptr; | 1443 fTypeface = nullptr; |
1424 fFontInfo = nullptr; | 1444 fFontInfo = nullptr; |
1425 fDescriptor = nullptr; | 1445 fDescriptor = nullptr; |
1426 this->SkPDFDict::drop(); | 1446 this->SkPDFDict::drop(); |
1427 } | 1447 } |
OLD | NEW |