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" |
11 #include "SkGlyphCache.h" | 11 #include "SkGlyphCache.h" |
12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
13 #include "SkPDFCanon.h" | 13 #include "SkPDFCanon.h" |
14 #include "SkPDFDevice.h" | 14 #include "SkPDFDevice.h" |
15 #include "SkPDFFont.h" | 15 #include "SkPDFFont.h" |
16 #include "SkPDFFontImpl.h" | 16 #include "SkPDFFontImpl.h" |
17 #include "SkPDFStream.h" | |
18 #include "SkPDFUtils.h" | 17 #include "SkPDFUtils.h" |
19 #include "SkRefCnt.h" | 18 #include "SkRefCnt.h" |
20 #include "SkScalar.h" | 19 #include "SkScalar.h" |
21 #include "SkStream.h" | 20 #include "SkStream.h" |
22 #include "SkTypefacePriv.h" | 21 #include "SkTypefacePriv.h" |
23 #include "SkTypes.h" | 22 #include "SkTypes.h" |
24 #include "SkUtils.h" | 23 #include "SkUtils.h" |
25 | 24 |
26 #if defined (SK_SFNTLY_SUBSETTER) | 25 #if defined (SK_SFNTLY_SUBSETTER) |
27 #if defined (GOOGLE3) | 26 #if defined (GOOGLE3) |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 SkASSERT(subsetFontSize > 0 || subsetFont == nullptr); | 998 SkASSERT(subsetFontSize > 0 || subsetFont == nullptr); |
1000 if (subsetFontSize < 1) { | 999 if (subsetFontSize < 1) { |
1001 return nullptr; | 1000 return nullptr; |
1002 } | 1001 } |
1003 SkASSERT(subsetFont != nullptr); | 1002 SkASSERT(subsetFont != nullptr); |
1004 auto subsetStream = sk_make_sp<SkPDFStream>( | 1003 auto subsetStream = sk_make_sp<SkPDFStream>( |
1005 SkData::MakeWithProc( | 1004 SkData::MakeWithProc( |
1006 subsetFont, subsetFontSize, | 1005 subsetFont, subsetFontSize, |
1007 [](const void* p, void*) { delete[] (unsigned char*)p; }, | 1006 [](const void* p, void*) { delete[] (unsigned char*)p; }, |
1008 nullptr)); | 1007 nullptr)); |
1009 subsetStream->insertInt("Length1", subsetFontSize); | 1008 subsetStream->dict()->insertInt("Length1", subsetFontSize); |
1010 return subsetStream; | 1009 return subsetStream; |
1011 } | 1010 } |
1012 #endif // SK_SFNTLY_SUBSETTER | 1011 #endif // SK_SFNTLY_SUBSETTER |
1013 | 1012 |
1014 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, | 1013 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, |
1015 const SkTDArray<uint32_t>* subset) { | 1014 const SkTDArray<uint32_t>* subset) { |
1016 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); | 1015 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); |
1017 setFontDescriptor(descriptor.get()); | 1016 setFontDescriptor(descriptor.get()); |
1018 if (!addCommonFontDescriptorEntries(defaultWidth)) { | 1017 if (!addCommonFontDescriptorEntries(defaultWidth)) { |
1019 this->insertObjRef("FontDescriptor", std::move(descriptor)); | 1018 this->insertObjRef("FontDescriptor", std::move(descriptor)); |
(...skipping 21 matching lines...) Expand all Loading... |
1041 sk_sp<SkPDFObject> subsetStream = get_subset_font_stream( | 1040 sk_sp<SkPDFObject> subsetStream = get_subset_font_stream( |
1042 std::move(fontAsset), *subset, fontInfo()->fFontName.c_s
tr()); | 1041 std::move(fontAsset), *subset, fontInfo()->fFontName.c_s
tr()); |
1043 if (subsetStream) { | 1042 if (subsetStream) { |
1044 descriptor->insertObjRef("FontFile2", std::move(subsetStream
)); | 1043 descriptor->insertObjRef("FontFile2", std::move(subsetStream
)); |
1045 break; | 1044 break; |
1046 } | 1045 } |
1047 // If subsetting fails, fall back to original font data. | 1046 // If subsetting fails, fall back to original font data. |
1048 fontAsset.reset(this->typeface()->openStream(&ttcIndex)); | 1047 fontAsset.reset(this->typeface()->openStream(&ttcIndex)); |
1049 } | 1048 } |
1050 #endif // SK_SFNTLY_SUBSETTER | 1049 #endif // SK_SFNTLY_SUBSETTER |
1051 auto fontStream = sk_make_sp<SkPDFSharedStream>(fontAsset.release())
; | 1050 auto fontStream = sk_make_sp<SkPDFSharedStream>(std::move(fontAsset)
); |
1052 fontStream->dict()->insertInt("Length1", fontSize); | 1051 fontStream->dict()->insertInt("Length1", fontSize); |
1053 descriptor->insertObjRef("FontFile2", std::move(fontStream)); | 1052 descriptor->insertObjRef("FontFile2", std::move(fontStream)); |
1054 break; | 1053 break; |
1055 } | 1054 } |
1056 case SkAdvancedTypefaceMetrics::kCFF_Font: | 1055 case SkAdvancedTypefaceMetrics::kCFF_Font: |
1057 case SkAdvancedTypefaceMetrics::kType1CID_Font: { | 1056 case SkAdvancedTypefaceMetrics::kType1CID_Font: { |
1058 std::unique_ptr<SkStreamAsset> fontData( | 1057 std::unique_ptr<SkStreamAsset> fontData( |
1059 this->typeface()->openStream(nullptr)); | 1058 this->typeface()->openStream(nullptr)); |
1060 SkASSERT(fontData); | 1059 SkASSERT(fontData); |
1061 SkASSERT(fontData->getLength() > 0); | 1060 SkASSERT(fontData->getLength() > 0); |
1062 if (!fontData || 0 == fontData->getLength()) { | 1061 if (!fontData || 0 == fontData->getLength()) { |
1063 return false; | 1062 return false; |
1064 } | 1063 } |
1065 sk_sp<SkPDFSharedStream> fontStream( | 1064 auto fontStream = sk_make_sp<SkPDFSharedStream>(std::move(fontData))
; |
1066 new SkPDFSharedStream(fontData.release())); | |
1067 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { | 1065 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { |
1068 fontStream->dict()->insertName("Subtype", "Type1C"); | 1066 fontStream->dict()->insertName("Subtype", "Type1C"); |
1069 } else { | 1067 } else { |
1070 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); | 1068 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); |
1071 } | 1069 } |
1072 descriptor->insertObjRef("FontFile3", std::move(fontStream)); | 1070 descriptor->insertObjRef("FontFile3", std::move(fontStream)); |
1073 break; | 1071 break; |
1074 } | 1072 } |
1075 default: | 1073 default: |
1076 SkASSERT(false); | 1074 SkASSERT(false); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 if (!rawFontData || 0 == rawFontData->getLength()) { | 1191 if (!rawFontData || 0 == rawFontData->getLength()) { |
1194 return false; | 1192 return false; |
1195 } | 1193 } |
1196 sk_sp<SkData> fontData(handle_type1_stream(rawFontData.get(), &header, | 1194 sk_sp<SkData> fontData(handle_type1_stream(rawFontData.get(), &header, |
1197 &data, &trailer)); | 1195 &data, &trailer)); |
1198 if (fontData.get() == nullptr) { | 1196 if (fontData.get() == nullptr) { |
1199 return false; | 1197 return false; |
1200 } | 1198 } |
1201 SkASSERT(this->canEmbed()); | 1199 SkASSERT(this->canEmbed()); |
1202 auto fontStream = sk_make_sp<SkPDFStream>(std::move(fontData)); | 1200 auto fontStream = sk_make_sp<SkPDFStream>(std::move(fontData)); |
1203 fontStream->insertInt("Length1", header); | 1201 fontStream->dict()->insertInt("Length1", header); |
1204 fontStream->insertInt("Length2", data); | 1202 fontStream->dict()->insertInt("Length2", data); |
1205 fontStream->insertInt("Length3", trailer); | 1203 fontStream->dict()->insertInt("Length3", trailer); |
1206 descriptor->insertObjRef("FontFile", std::move(fontStream)); | 1204 descriptor->insertObjRef("FontFile", std::move(fontStream)); |
1207 | 1205 |
1208 this->insertObjRef("FontDescriptor", std::move(descriptor)); | 1206 this->insertObjRef("FontDescriptor", std::move(descriptor)); |
1209 | 1207 |
1210 return addCommonFontDescriptorEntries(defaultWidth); | 1208 return addCommonFontDescriptorEntries(defaultWidth); |
1211 } | 1209 } |
1212 | 1210 |
1213 bool SkPDFType1Font::populate(int16_t glyphID) { | 1211 bool SkPDFType1Font::populate(int16_t glyphID) { |
1214 SkASSERT(fontInfo()->fVerticalMetrics.empty()); | 1212 SkASSERT(fontInfo()->fVerticalMetrics.empty()); |
1215 SkASSERT(!fontInfo()->fGlyphWidths.empty()); | 1213 SkASSERT(!fontInfo()->fGlyphWidths.empty()); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 } | 1405 } |
1408 return *canon->fCanEmbedTypeface.set(id, canEmbed); | 1406 return *canon->fCanEmbedTypeface.set(id, canEmbed); |
1409 } | 1407 } |
1410 | 1408 |
1411 void SkPDFFont::drop() { | 1409 void SkPDFFont::drop() { |
1412 fTypeface = nullptr; | 1410 fTypeface = nullptr; |
1413 fFontInfo = nullptr; | 1411 fFontInfo = nullptr; |
1414 fDescriptor = nullptr; | 1412 fDescriptor = nullptr; |
1415 this->SkPDFDict::drop(); | 1413 this->SkPDFDict::drop(); |
1416 } | 1414 } |
OLD | NEW |