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

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

Issue 1214853025: Propagate SkSurfaceProps when known (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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/SkPDFDevice.cpp ('k') | no next file » | 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 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 887
888 if (info && (info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag )) { 888 if (info && (info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag )) {
889 return new SkPDFType3Font(info, typeface, glyphID); 889 return new SkPDFType3Font(info, typeface, glyphID);
890 } 890 }
891 if (type == SkAdvancedTypefaceMetrics::kType1CID_Font || 891 if (type == SkAdvancedTypefaceMetrics::kType1CID_Font ||
892 type == SkAdvancedTypefaceMetrics::kTrueType_Font) { 892 type == SkAdvancedTypefaceMetrics::kTrueType_Font) {
893 SkASSERT(relatedFontDescriptor == NULL); 893 SkASSERT(relatedFontDescriptor == NULL);
894 return new SkPDFType0Font(info, typeface); 894 return new SkPDFType0Font(info, typeface);
895 } 895 }
896 if (type == SkAdvancedTypefaceMetrics::kType1_Font) { 896 if (type == SkAdvancedTypefaceMetrics::kType1_Font) {
897 return new SkPDFType1Font(info, typeface, glyphID, 897 return new SkPDFType1Font(info, typeface, glyphID, relatedFontDescriptor );
898 relatedFontDescriptor);
899 } 898 }
900 899
901 SkASSERT(type == SkAdvancedTypefaceMetrics::kCFF_Font || 900 SkASSERT(type == SkAdvancedTypefaceMetrics::kCFF_Font ||
902 type == SkAdvancedTypefaceMetrics::kOther_Font); 901 type == SkAdvancedTypefaceMetrics::kOther_Font);
903 902
904 return new SkPDFType3Font(info, typeface, glyphID); 903 return new SkPDFType3Font(info, typeface, glyphID);
905 } 904 }
906 905
907 const SkAdvancedTypefaceMetrics* SkPDFFont::fontInfo() { 906 const SkAdvancedTypefaceMetrics* SkPDFFont::fontInfo() {
908 return fFontInfo.get(); 907 return fFontInfo.get();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 subset, 982 subset,
984 multiByteGlyphs(), 983 multiByteGlyphs(),
985 firstGlyphID(), 984 firstGlyphID(),
986 lastGlyphID())); 985 lastGlyphID()));
987 } 986 }
988 987
989 /////////////////////////////////////////////////////////////////////////////// 988 ///////////////////////////////////////////////////////////////////////////////
990 // class SkPDFType0Font 989 // class SkPDFType0Font
991 /////////////////////////////////////////////////////////////////////////////// 990 ///////////////////////////////////////////////////////////////////////////////
992 991
993 SkPDFType0Font::SkPDFType0Font(const SkAdvancedTypefaceMetrics* info, 992 SkPDFType0Font::SkPDFType0Font(const SkAdvancedTypefaceMetrics* info, SkTypeface * typeface)
994 SkTypeface* typeface)
995 : SkPDFFont(info, typeface, NULL) { 993 : SkPDFFont(info, typeface, NULL) {
996 SkDEBUGCODE(fPopulated = false); 994 SkDEBUGCODE(fPopulated = false);
997 if (!canSubset()) { 995 if (!canSubset()) {
998 populate(NULL); 996 this->populate(NULL);
999 } 997 }
1000 } 998 }
1001 999
1002 SkPDFType0Font::~SkPDFType0Font() {} 1000 SkPDFType0Font::~SkPDFType0Font() {}
1003 1001
1004 SkPDFFont* SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) { 1002 SkPDFFont* SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) {
1005 if (!canSubset()) { 1003 if (!canSubset()) {
1006 return NULL; 1004 return NULL;
1007 } 1005 }
1008 SkPDFType0Font* newSubset = 1006 SkPDFType0Font* newSubset = new SkPDFType0Font(fontInfo(), typeface());
1009 new SkPDFType0Font(fontInfo(), typeface());
1010 newSubset->populate(subset); 1007 newSubset->populate(subset);
1011 return newSubset; 1008 return newSubset;
1012 } 1009 }
1013 1010
1014 #ifdef SK_DEBUG 1011 #ifdef SK_DEBUG
1015 void SkPDFType0Font::emitObject(SkWStream* stream, 1012 void SkPDFType0Font::emitObject(SkWStream* stream,
1016 const SkPDFObjNumMap& objNumMap, 1013 const SkPDFObjNumMap& objNumMap,
1017 const SkPDFSubstituteMap& substitutes) { 1014 const SkPDFSubstituteMap& substitutes) {
1018 SkASSERT(fPopulated); 1015 SkASSERT(fPopulated);
1019 return INHERITED::emitObject(stream, objNumMap, substitutes); 1016 return INHERITED::emitObject(stream, objNumMap, substitutes);
1020 } 1017 }
1021 #endif 1018 #endif
1022 1019
1023 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { 1020 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) {
1024 insertName("Subtype", "Type0"); 1021 insertName("Subtype", "Type0");
1025 insertName("BaseFont", fontInfo()->fFontName); 1022 insertName("BaseFont", fontInfo()->fFontName);
1026 insertName("Encoding", "Identity-H"); 1023 insertName("Encoding", "Identity-H");
1027 1024
1028 SkAutoTUnref<SkPDFCIDFont> newCIDFont( 1025 SkAutoTUnref<SkPDFCIDFont> newCIDFont(
1029 new SkPDFCIDFont(fontInfo(), typeface(), subset)); 1026 new SkPDFCIDFont(fontInfo(), typeface(), subset));
1030 SkAutoTUnref<SkPDFArray> descendantFonts(new SkPDFArray()); 1027 SkAutoTUnref<SkPDFArray> descendantFonts(new SkPDFArray());
1031 descendantFonts->appendObjRef(newCIDFont.detach()); 1028 descendantFonts->appendObjRef(newCIDFont.detach());
1032 this->insertObject("DescendantFonts", descendantFonts.detach()); 1029 this->insertObject("DescendantFonts", descendantFonts.detach());
1033 1030
1034 populateToUnicodeTable(subset); 1031 this->populateToUnicodeTable(subset);
1035 1032
1036 SkDEBUGCODE(fPopulated = true); 1033 SkDEBUGCODE(fPopulated = true);
1037 return true; 1034 return true;
1038 } 1035 }
1039 1036
1040 /////////////////////////////////////////////////////////////////////////////// 1037 ///////////////////////////////////////////////////////////////////////////////
1041 // class SkPDFCIDFont 1038 // class SkPDFCIDFont
1042 /////////////////////////////////////////////////////////////////////////////// 1039 ///////////////////////////////////////////////////////////////////////////////
1043 1040
1044 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, 1041 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info,
1045 SkTypeface* typeface, 1042 SkTypeface* typeface,
1046 const SkPDFGlyphSet* subset) 1043 const SkPDFGlyphSet* subset)
1047 : SkPDFFont(info, typeface, NULL) { 1044 : SkPDFFont(info, typeface, NULL) {
1048 populate(subset); 1045 this->populate(subset);
1049 } 1046 }
1050 1047
1051 SkPDFCIDFont::~SkPDFCIDFont() {} 1048 SkPDFCIDFont::~SkPDFCIDFont() {}
1052 1049
1053 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, 1050 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
1054 const SkTDArray<uint32_t>* subset) { 1051 const SkTDArray<uint32_t>* subset) {
1055 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); 1052 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor"));
1056 setFontDescriptor(descriptor.get()); 1053 setFontDescriptor(descriptor.get());
1057 if (!addCommonFontDescriptorEntries(defaultWidth)) { 1054 if (!addCommonFontDescriptorEntries(defaultWidth)) {
1058 this->insertObjRef("FontDescriptor", descriptor.detach()); 1055 this->insertObjRef("FontDescriptor", descriptor.detach());
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 1192
1196 /////////////////////////////////////////////////////////////////////////////// 1193 ///////////////////////////////////////////////////////////////////////////////
1197 // class SkPDFType1Font 1194 // class SkPDFType1Font
1198 /////////////////////////////////////////////////////////////////////////////// 1195 ///////////////////////////////////////////////////////////////////////////////
1199 1196
1200 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info, 1197 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info,
1201 SkTypeface* typeface, 1198 SkTypeface* typeface,
1202 uint16_t glyphID, 1199 uint16_t glyphID,
1203 SkPDFDict* relatedFontDescriptor) 1200 SkPDFDict* relatedFontDescriptor)
1204 : SkPDFFont(info, typeface, relatedFontDescriptor) { 1201 : SkPDFFont(info, typeface, relatedFontDescriptor) {
1205 populate(glyphID); 1202 this->populate(glyphID);
1206 } 1203 }
1207 1204
1208 SkPDFType1Font::~SkPDFType1Font() {} 1205 SkPDFType1Font::~SkPDFType1Font() {}
1209 1206
1210 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { 1207 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
1211 if (SkPDFDict* descriptor = getFontDescriptor()) { 1208 if (SkPDFDict* descriptor = getFontDescriptor()) {
1212 this->insertObjRef("FontDescriptor", SkRef(descriptor)); 1209 this->insertObjRef("FontDescriptor", SkRef(descriptor));
1213 return true; 1210 return true;
1214 } 1211 }
1215 1212
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 } 1315 }
1319 1316
1320 /////////////////////////////////////////////////////////////////////////////// 1317 ///////////////////////////////////////////////////////////////////////////////
1321 // class SkPDFType3Font 1318 // class SkPDFType3Font
1322 /////////////////////////////////////////////////////////////////////////////// 1319 ///////////////////////////////////////////////////////////////////////////////
1323 1320
1324 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info, 1321 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info,
1325 SkTypeface* typeface, 1322 SkTypeface* typeface,
1326 uint16_t glyphID) 1323 uint16_t glyphID)
1327 : SkPDFFont(info, typeface, NULL) { 1324 : SkPDFFont(info, typeface, NULL) {
1328 populate(glyphID); 1325 this->populate(glyphID);
1329 } 1326 }
1330 1327
1331 SkPDFType3Font::~SkPDFType3Font() {} 1328 SkPDFType3Font::~SkPDFType3Font() {}
1332 1329
1333 bool SkPDFType3Font::populate(uint16_t glyphID) { 1330 bool SkPDFType3Font::populate(uint16_t glyphID) {
1334 SkPaint paint; 1331 SkPaint paint;
1335 paint.setTypeface(typeface()); 1332 paint.setTypeface(typeface());
1336 paint.setTextSize(1000); 1333 paint.setTextSize(1000);
1337 SkAutoGlyphCache autoCache(paint, NULL, NULL); 1334 const SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
1335 SkAutoGlyphCache autoCache(paint, &props, NULL);
1338 SkGlyphCache* cache = autoCache.getCache(); 1336 SkGlyphCache* cache = autoCache.getCache();
1339 // If fLastGlyphID isn't set (because there is not fFontInfo), look it up. 1337 // If fLastGlyphID isn't set (because there is not fFontInfo), look it up.
1340 if (lastGlyphID() == 0) { 1338 if (lastGlyphID() == 0) {
1341 setLastGlyphID(cache->getGlyphCount() - 1); 1339 setLastGlyphID(cache->getGlyphCount() - 1);
1342 } 1340 }
1343 1341
1344 adjustGlyphRangeForSingleByteEncoding(glyphID); 1342 adjustGlyphRangeForSingleByteEncoding(glyphID);
1345 1343
1346 insertName("Subtype", "Type3"); 1344 insertName("Subtype", "Type3");
1347 // Flip about the x-axis and scale by 1/1000. 1345 // Flip about the x-axis and scale by 1/1000.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 1388
1391 this->insertObject("CharProcs", charProcs.detach()); 1389 this->insertObject("CharProcs", charProcs.detach());
1392 this->insertObject("Encoding", encoding.detach()); 1390 this->insertObject("Encoding", encoding.detach());
1393 1391
1394 this->insertObject("FontBBox", makeFontBBox(bbox, 1000)); 1392 this->insertObject("FontBBox", makeFontBBox(bbox, 1000));
1395 this->insertInt("FirstChar", 1); 1393 this->insertInt("FirstChar", 1);
1396 this->insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); 1394 this->insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1);
1397 this->insertObject("Widths", widthArray.detach()); 1395 this->insertObject("Widths", widthArray.detach());
1398 this->insertName("CIDToGIDMap", "Identity"); 1396 this->insertName("CIDToGIDMap", "Identity");
1399 1397
1400 populateToUnicodeTable(NULL); 1398 this->populateToUnicodeTable(NULL);
1401 return true; 1399 return true;
1402 } 1400 }
1403 1401
1404 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont, 1402 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont,
1405 uint32_t existingFontID, 1403 uint32_t existingFontID,
1406 uint16_t existingGlyphID, 1404 uint16_t existingGlyphID,
1407 uint32_t searchFontID, 1405 uint32_t searchFontID,
1408 uint16_t searchGlyphID) { 1406 uint16_t searchGlyphID) {
1409 if (existingFontID != searchFontID) { 1407 if (existingFontID != searchFontID) {
1410 return SkPDFFont::kNot_Match; 1408 return SkPDFFont::kNot_Match;
1411 } 1409 }
1412 if (existingGlyphID == 0 || searchGlyphID == 0) { 1410 if (existingGlyphID == 0 || searchGlyphID == 0) {
1413 return SkPDFFont::kExact_Match; 1411 return SkPDFFont::kExact_Match;
1414 } 1412 }
1415 if (existingFont != NULL) { 1413 if (existingFont != NULL) {
1416 return (existingFont->fFirstGlyphID <= searchGlyphID && 1414 return (existingFont->fFirstGlyphID <= searchGlyphID &&
1417 searchGlyphID <= existingFont->fLastGlyphID) 1415 searchGlyphID <= existingFont->fLastGlyphID)
1418 ? SkPDFFont::kExact_Match 1416 ? SkPDFFont::kExact_Match
1419 : SkPDFFont::kRelated_Match; 1417 : SkPDFFont::kRelated_Match;
1420 } 1418 }
1421 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match 1419 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match
1422 : SkPDFFont::kRelated_Match; 1420 : SkPDFFont::kRelated_Match;
1423 } 1421 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698