Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/pdf/SkPDFFont.cpp

Issue 1401763002: SkPDF: fall back on paths for unembeddable fonts. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-10-12 (Monday) 15:54:45 EDT Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFFont.h ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 SkPDFCIDFont::~SkPDFCIDFont() {} 1044 SkPDFCIDFont::~SkPDFCIDFont() {}
1045 1045
1046 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, 1046 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
1047 const SkTDArray<uint32_t>* subset) { 1047 const SkTDArray<uint32_t>* subset) {
1048 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); 1048 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor"));
1049 setFontDescriptor(descriptor.get()); 1049 setFontDescriptor(descriptor.get());
1050 if (!addCommonFontDescriptorEntries(defaultWidth)) { 1050 if (!addCommonFontDescriptorEntries(defaultWidth)) {
1051 this->insertObjRef("FontDescriptor", descriptor.detach()); 1051 this->insertObjRef("FontDescriptor", descriptor.detach());
1052 return false; 1052 return false;
1053 } 1053 }
1054 if (!canEmbed()) { 1054 SkASSERT(this->canEmbed());
1055 this->insertObjRef("FontDescriptor", descriptor.detach());
1056 return true;
1057 }
1058 1055
1059 switch (getType()) { 1056 switch (getType()) {
1060 case SkAdvancedTypefaceMetrics::kTrueType_Font: { 1057 case SkAdvancedTypefaceMetrics::kTrueType_Font: {
1061 size_t fontSize = 0; 1058 size_t fontSize = 0;
1062 #if defined(SK_SFNTLY_SUBSETTER) 1059 #if defined(SK_SFNTLY_SUBSETTER)
1063 if (this->canSubset()) { 1060 if (this->canSubset()) {
1064 SkAutoTUnref<SkPDFStream> fontStream; 1061 SkAutoTUnref<SkPDFStream> fontStream;
1065 SkPDFStream* rawStream = nullptr; 1062 SkPDFStream* rawStream = nullptr;
1066 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), 1063 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(),
1067 typeface(), 1064 typeface(),
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 int ttcIndex; 1212 int ttcIndex;
1216 size_t header SK_INIT_TO_AVOID_WARNING; 1213 size_t header SK_INIT_TO_AVOID_WARNING;
1217 size_t data SK_INIT_TO_AVOID_WARNING; 1214 size_t data SK_INIT_TO_AVOID_WARNING;
1218 size_t trailer SK_INIT_TO_AVOID_WARNING; 1215 size_t trailer SK_INIT_TO_AVOID_WARNING;
1219 SkAutoTDelete<SkStream> rawFontData(typeface()->openStream(&ttcIndex)); 1216 SkAutoTDelete<SkStream> rawFontData(typeface()->openStream(&ttcIndex));
1220 SkAutoTUnref<SkData> fontData(handle_type1_stream(rawFontData.get(), &header , 1217 SkAutoTUnref<SkData> fontData(handle_type1_stream(rawFontData.get(), &header ,
1221 &data, &trailer)); 1218 &data, &trailer));
1222 if (fontData.get() == nullptr) { 1219 if (fontData.get() == nullptr) {
1223 return false; 1220 return false;
1224 } 1221 }
1225 if (canEmbed()) { 1222 SkASSERT(this->canEmbed());
1226 SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get())); 1223 SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get()));
1227 fontStream->insertInt("Length1", header); 1224 fontStream->insertInt("Length1", header);
1228 fontStream->insertInt("Length2", data); 1225 fontStream->insertInt("Length2", data);
1229 fontStream->insertInt("Length3", trailer); 1226 fontStream->insertInt("Length3", trailer);
1230 descriptor->insertObjRef("FontFile", fontStream.detach()); 1227 descriptor->insertObjRef("FontFile", fontStream.detach());
1231 }
1232 1228
1233 this->insertObjRef("FontDescriptor", descriptor.detach()); 1229 this->insertObjRef("FontDescriptor", descriptor.detach());
1234 1230
1235 return addCommonFontDescriptorEntries(defaultWidth); 1231 return addCommonFontDescriptorEntries(defaultWidth);
1236 } 1232 }
1237 1233
1238 bool SkPDFType1Font::populate(int16_t glyphID) { 1234 bool SkPDFType1Font::populate(int16_t glyphID) {
1239 SkASSERT(!fontInfo()->fVerticalMetrics.get()); 1235 SkASSERT(!fontInfo()->fVerticalMetrics.get());
1240 SkASSERT(fontInfo()->fGlyphWidths.get()); 1236 SkASSERT(fontInfo()->fGlyphWidths.get());
1241 1237
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 } 1407 }
1412 if (existingFont != nullptr) { 1408 if (existingFont != nullptr) {
1413 return (existingFont->fFirstGlyphID <= searchGlyphID && 1409 return (existingFont->fFirstGlyphID <= searchGlyphID &&
1414 searchGlyphID <= existingFont->fLastGlyphID) 1410 searchGlyphID <= existingFont->fLastGlyphID)
1415 ? SkPDFFont::kExact_Match 1411 ? SkPDFFont::kExact_Match
1416 : SkPDFFont::kRelated_Match; 1412 : SkPDFFont::kRelated_Match;
1417 } 1413 }
1418 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match 1414 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match
1419 : SkPDFFont::kRelated_Match; 1415 : SkPDFFont::kRelated_Match;
1420 } 1416 }
1417
1418 // Since getAdvancedTypefaceMetrics is expensive, cache the result.
1419 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) {
1420 SkAutoResolveDefaultTypeface face(typeface);
1421 uint32_t id = face->uniqueID();
1422 if (bool* value = canon->fCanEmbedTypeface.find(id)) {
1423 return *value;
1424 }
1425 bool canEmbed = true;
1426 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fontMetrics(
1427 face->getAdvancedTypefaceMetrics(
1428 SkTypeface::kNo_PerGlyphInfo, nullptr, 0));
1429 if (fontMetrics) {
1430 canEmbed = !SkToBool(
1431 fontMetrics->fFlags &
1432 SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag);
1433 }
1434 return *canon->fCanEmbedTypeface.set(id, canEmbed);
1435 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFFont.h ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698