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

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

Issue 383063007: Make SkPDFFont::fFontInfo a const pointer. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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/SkPDFFont.h ('k') | src/pdf/SkPDFFontImpl.h » ('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 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 SkAutoResolveDefaultTypeface autoResolve(typeface); 824 SkAutoResolveDefaultTypeface autoResolve(typeface);
825 typeface = autoResolve.get(); 825 typeface = autoResolve.get();
826 826
827 const uint32_t fontID = typeface->uniqueID(); 827 const uint32_t fontID = typeface->uniqueID();
828 int relatedFontIndex; 828 int relatedFontIndex;
829 if (Find(fontID, glyphID, &relatedFontIndex)) { 829 if (Find(fontID, glyphID, &relatedFontIndex)) {
830 CanonicalFonts()[relatedFontIndex].fFont->ref(); 830 CanonicalFonts()[relatedFontIndex].fFont->ref();
831 return CanonicalFonts()[relatedFontIndex].fFont; 831 return CanonicalFonts()[relatedFontIndex].fFont;
832 } 832 }
833 833
834 SkAutoTUnref<SkAdvancedTypefaceMetrics> fontMetrics; 834 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fontMetrics;
835 SkPDFDict* relatedFontDescriptor = NULL; 835 SkPDFDict* relatedFontDescriptor = NULL;
836 if (relatedFontIndex >= 0) { 836 if (relatedFontIndex >= 0) {
837 SkPDFFont* relatedFont = CanonicalFonts()[relatedFontIndex].fFont; 837 SkPDFFont* relatedFont = CanonicalFonts()[relatedFontIndex].fFont;
838 fontMetrics.reset(relatedFont->fontInfo()); 838 fontMetrics.reset(relatedFont->fontInfo());
839 SkSafeRef(fontMetrics.get()); 839 SkSafeRef(fontMetrics.get());
840 relatedFontDescriptor = relatedFont->getFontDescriptor(); 840 relatedFontDescriptor = relatedFont->getFontDescriptor();
841 841
842 // This only is to catch callers who pass invalid glyph ids. 842 // This only is to catch callers who pass invalid glyph ids.
843 // If glyph id is invalid, then we will create duplicate entries 843 // If glyph id is invalid, then we will create duplicate entries
844 // for TrueType fonts. 844 // for TrueType fonts.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 FontRec search(NULL, fontID, glyphID); 904 FontRec search(NULL, fontID, glyphID);
905 *index = CanonicalFonts().find(search); 905 *index = CanonicalFonts().find(search);
906 if (*index >= 0) { 906 if (*index >= 0) {
907 return true; 907 return true;
908 } 908 }
909 search.fGlyphID = 0; 909 search.fGlyphID = 0;
910 *index = CanonicalFonts().find(search); 910 *index = CanonicalFonts().find(search);
911 return false; 911 return false;
912 } 912 }
913 913
914 SkPDFFont::SkPDFFont(SkAdvancedTypefaceMetrics* info, SkTypeface* typeface, 914 SkPDFFont::SkPDFFont(const SkAdvancedTypefaceMetrics* info,
915 SkTypeface* typeface,
915 SkPDFDict* relatedFontDescriptor) 916 SkPDFDict* relatedFontDescriptor)
916 : SkPDFDict("Font"), 917 : SkPDFDict("Font"),
917 fTypeface(ref_or_default(typeface)), 918 fTypeface(ref_or_default(typeface)),
918 fFirstGlyphID(1), 919 fFirstGlyphID(1),
919 fLastGlyphID(info ? info->fLastGlyphID : 0), 920 fLastGlyphID(info ? info->fLastGlyphID : 0),
920 fFontInfo(SkSafeRef(info)), 921 fFontInfo(SkSafeRef(info)),
921 fDescriptor(SkSafeRef(relatedFontDescriptor)) { 922 fDescriptor(SkSafeRef(relatedFontDescriptor)) {
922 if (info == NULL || 923 if (info == NULL ||
923 info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag) { 924 info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag) {
924 fFontType = SkAdvancedTypefaceMetrics::kOther_Font; 925 fFontType = SkAdvancedTypefaceMetrics::kOther_Font;
925 } else { 926 } else {
926 fFontType = info->fType; 927 fFontType = info->fType;
927 } 928 }
928 } 929 }
929 930
930 // static 931 // static
931 SkPDFFont* SkPDFFont::Create(SkAdvancedTypefaceMetrics* info, 932 SkPDFFont* SkPDFFont::Create(const SkAdvancedTypefaceMetrics* info,
932 SkTypeface* typeface, uint16_t glyphID, 933 SkTypeface* typeface, uint16_t glyphID,
933 SkPDFDict* relatedFontDescriptor) { 934 SkPDFDict* relatedFontDescriptor) {
934 SkAdvancedTypefaceMetrics::FontType type = 935 SkAdvancedTypefaceMetrics::FontType type =
935 info ? info->fType : SkAdvancedTypefaceMetrics::kOther_Font; 936 info ? info->fType : SkAdvancedTypefaceMetrics::kOther_Font;
936 937
937 if (info && 938 if (info &&
938 (info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag)) { 939 (info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag)) {
939 NOT_IMPLEMENTED(true, true); 940 NOT_IMPLEMENTED(true, true);
940 return new SkPDFType3Font(info, 941 return new SkPDFType3Font(info,
941 typeface, 942 typeface,
(...skipping 10 matching lines...) Expand all
952 glyphID, 953 glyphID,
953 relatedFontDescriptor); 954 relatedFontDescriptor);
954 } 955 }
955 956
956 SkASSERT(type == SkAdvancedTypefaceMetrics::kCFF_Font || 957 SkASSERT(type == SkAdvancedTypefaceMetrics::kCFF_Font ||
957 type == SkAdvancedTypefaceMetrics::kOther_Font); 958 type == SkAdvancedTypefaceMetrics::kOther_Font);
958 959
959 return new SkPDFType3Font(info, typeface, glyphID); 960 return new SkPDFType3Font(info, typeface, glyphID);
960 } 961 }
961 962
962 SkAdvancedTypefaceMetrics* SkPDFFont::fontInfo() { 963 const SkAdvancedTypefaceMetrics* SkPDFFont::fontInfo() {
963 return fFontInfo.get(); 964 return fFontInfo.get();
964 } 965 }
965 966
966 void SkPDFFont::setFontInfo(SkAdvancedTypefaceMetrics* info) { 967 void SkPDFFont::setFontInfo(const SkAdvancedTypefaceMetrics* info) {
967 if (info == NULL || info == fFontInfo.get()) { 968 if (info == NULL || info == fFontInfo.get()) {
968 return; 969 return;
969 } 970 }
970 fFontInfo.reset(info); 971 fFontInfo.reset(info);
971 SkSafeRef(info); 972 SkSafeRef(info);
972 } 973 }
973 974
974 uint16_t SkPDFFont::firstGlyphID() const { 975 uint16_t SkPDFFont::firstGlyphID() const {
975 return fFirstGlyphID; 976 return fFirstGlyphID;
976 } 977 }
(...skipping 29 matching lines...) Expand all
1006 const uint16_t emSize = fFontInfo->fEmSize; 1007 const uint16_t emSize = fFontInfo->fEmSize;
1007 1008
1008 fDescriptor->insertName("FontName", fFontInfo->fFontName); 1009 fDescriptor->insertName("FontName", fFontInfo->fFontName);
1009 fDescriptor->insertInt("Flags", fFontInfo->fStyle | kPdfSymbolic); 1010 fDescriptor->insertInt("Flags", fFontInfo->fStyle | kPdfSymbolic);
1010 fDescriptor->insertScalar("Ascent", 1011 fDescriptor->insertScalar("Ascent",
1011 scaleFromFontUnits(fFontInfo->fAscent, emSize)); 1012 scaleFromFontUnits(fFontInfo->fAscent, emSize));
1012 fDescriptor->insertScalar("Descent", 1013 fDescriptor->insertScalar("Descent",
1013 scaleFromFontUnits(fFontInfo->fDescent, emSize)); 1014 scaleFromFontUnits(fFontInfo->fDescent, emSize));
1014 fDescriptor->insertScalar("StemV", 1015 fDescriptor->insertScalar("StemV",
1015 scaleFromFontUnits(fFontInfo->fStemV, emSize)); 1016 scaleFromFontUnits(fFontInfo->fStemV, emSize));
1017
1016 fDescriptor->insertScalar("CapHeight", 1018 fDescriptor->insertScalar("CapHeight",
1017 scaleFromFontUnits(fFontInfo->fCapHeight, emSize)); 1019 scaleFromFontUnits(fFontInfo->fCapHeight, emSize));
1018 fDescriptor->insertInt("ItalicAngle", fFontInfo->fItalicAngle); 1020 fDescriptor->insertInt("ItalicAngle", fFontInfo->fItalicAngle);
1019 fDescriptor->insert("FontBBox", makeFontBBox(fFontInfo->fBBox, 1021 fDescriptor->insert("FontBBox", makeFontBBox(fFontInfo->fBBox,
1020 fFontInfo->fEmSize))->unref(); 1022 fFontInfo->fEmSize))->unref();
1021 1023
1022 if (defaultWidth > 0) { 1024 if (defaultWidth > 0) {
1023 fDescriptor->insertScalar("MissingWidth", 1025 fDescriptor->insertScalar("MissingWidth",
1024 scaleFromFontUnits(defaultWidth, emSize)); 1026 scaleFromFontUnits(defaultWidth, emSize));
1025 } 1027 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 multiByteGlyphs(), firstGlyphID(), 1073 multiByteGlyphs(), firstGlyphID(),
1072 lastGlyphID())); 1074 lastGlyphID()));
1073 addResource(pdfCmap.get()); 1075 addResource(pdfCmap.get());
1074 insert("ToUnicode", new SkPDFObjRef(pdfCmap.get()))->unref(); 1076 insert("ToUnicode", new SkPDFObjRef(pdfCmap.get()))->unref();
1075 } 1077 }
1076 1078
1077 /////////////////////////////////////////////////////////////////////////////// 1079 ///////////////////////////////////////////////////////////////////////////////
1078 // class SkPDFType0Font 1080 // class SkPDFType0Font
1079 /////////////////////////////////////////////////////////////////////////////// 1081 ///////////////////////////////////////////////////////////////////////////////
1080 1082
1081 SkPDFType0Font::SkPDFType0Font(SkAdvancedTypefaceMetrics* info, 1083 SkPDFType0Font::SkPDFType0Font(const SkAdvancedTypefaceMetrics* info,
1082 SkTypeface* typeface) 1084 SkTypeface* typeface)
1083 : SkPDFFont(info, typeface, NULL) { 1085 : SkPDFFont(info, typeface, NULL) {
1084 SkDEBUGCODE(fPopulated = false); 1086 SkDEBUGCODE(fPopulated = false);
1085 if (!canSubset()) { 1087 if (!canSubset()) {
1086 populate(NULL); 1088 populate(NULL);
1087 } 1089 }
1088 } 1090 }
1089 1091
1090 SkPDFType0Font::~SkPDFType0Font() {} 1092 SkPDFType0Font::~SkPDFType0Font() {}
1091 1093
(...skipping 29 matching lines...) Expand all
1121 populateToUnicodeTable(subset); 1123 populateToUnicodeTable(subset);
1122 1124
1123 SkDEBUGCODE(fPopulated = true); 1125 SkDEBUGCODE(fPopulated = true);
1124 return true; 1126 return true;
1125 } 1127 }
1126 1128
1127 /////////////////////////////////////////////////////////////////////////////// 1129 ///////////////////////////////////////////////////////////////////////////////
1128 // class SkPDFCIDFont 1130 // class SkPDFCIDFont
1129 /////////////////////////////////////////////////////////////////////////////// 1131 ///////////////////////////////////////////////////////////////////////////////
1130 1132
1131 SkPDFCIDFont::SkPDFCIDFont(SkAdvancedTypefaceMetrics* info, 1133 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info,
1132 SkTypeface* typeface, const SkPDFGlyphSet* subset) 1134 SkTypeface* typeface, const SkPDFGlyphSet* subset)
1133 : SkPDFFont(info, typeface, NULL) { 1135 : SkPDFFont(info, typeface, NULL) {
1134 populate(subset); 1136 populate(subset);
1135 } 1137 }
1136 1138
1137 SkPDFCIDFont::~SkPDFCIDFont() {} 1139 SkPDFCIDFont::~SkPDFCIDFont() {}
1138 1140
1139 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, 1141 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
1140 const SkTDArray<uint32_t>* subset) { 1142 const SkTDArray<uint32_t>* subset) {
1141 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); 1143 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor"));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 } 1213 }
1212 subset->exportTo(&glyphIDs); 1214 subset->exportTo(&glyphIDs);
1213 } 1215 }
1214 1216
1215 SkAdvancedTypefaceMetrics::PerGlyphInfo info; 1217 SkAdvancedTypefaceMetrics::PerGlyphInfo info;
1216 info = SkAdvancedTypefaceMetrics::kGlyphNames_PerGlyphInfo; 1218 info = SkAdvancedTypefaceMetrics::kGlyphNames_PerGlyphInfo;
1217 info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>( 1219 info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>(
1218 info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo); 1220 info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo);
1219 uint32_t* glyphs = (glyphIDs.count() == 0) ? NULL : glyphIDs.begin(); 1221 uint32_t* glyphs = (glyphIDs.count() == 0) ? NULL : glyphIDs.begin();
1220 uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0; 1222 uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0;
1221 SkAutoTUnref<SkAdvancedTypefaceMetrics> fontMetrics( 1223 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fontMetrics(
1222 typeface()->getAdvancedTypefaceMetrics(info, glyphs, glyphsCount)); 1224 typeface()->getAdvancedTypefaceMetrics(info, glyphs, glyphsCount));
1223 setFontInfo(fontMetrics.get()); 1225 setFontInfo(fontMetrics.get());
1224 addFontDescriptor(0, &glyphIDs); 1226 addFontDescriptor(0, &glyphIDs);
1225 } else { 1227 } else {
1226 // Other CID fonts 1228 // Other CID fonts
1227 addFontDescriptor(0, NULL); 1229 addFontDescriptor(0, NULL);
1228 } 1230 }
1229 1231
1230 insertName("BaseFont", fontInfo()->fFontName); 1232 insertName("BaseFont", fontInfo()->fFontName);
1231 1233
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 } 1279 }
1278 } 1280 }
1279 1281
1280 return true; 1282 return true;
1281 } 1283 }
1282 1284
1283 /////////////////////////////////////////////////////////////////////////////// 1285 ///////////////////////////////////////////////////////////////////////////////
1284 // class SkPDFType1Font 1286 // class SkPDFType1Font
1285 /////////////////////////////////////////////////////////////////////////////// 1287 ///////////////////////////////////////////////////////////////////////////////
1286 1288
1287 SkPDFType1Font::SkPDFType1Font(SkAdvancedTypefaceMetrics* info, 1289 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info,
1288 SkTypeface* typeface, 1290 SkTypeface* typeface,
1289 uint16_t glyphID, 1291 uint16_t glyphID,
1290 SkPDFDict* relatedFontDescriptor) 1292 SkPDFDict* relatedFontDescriptor)
1291 : SkPDFFont(info, typeface, relatedFontDescriptor) { 1293 : SkPDFFont(info, typeface, relatedFontDescriptor) {
1292 populate(glyphID); 1294 populate(glyphID);
1293 } 1295 }
1294 1296
1295 SkPDFType1Font::~SkPDFType1Font() {} 1297 SkPDFType1Font::~SkPDFType1Font() {}
1296 1298
1297 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { 1299 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 } 1409 }
1408 insertInt("FirstChar", firstChar); 1410 insertInt("FirstChar", firstChar);
1409 insertInt("LastChar", firstChar + widthArray->size() - 1); 1411 insertInt("LastChar", firstChar + widthArray->size() - 1);
1410 insert("Widths", widthArray.get()); 1412 insert("Widths", widthArray.get());
1411 } 1413 }
1412 1414
1413 /////////////////////////////////////////////////////////////////////////////// 1415 ///////////////////////////////////////////////////////////////////////////////
1414 // class SkPDFType3Font 1416 // class SkPDFType3Font
1415 /////////////////////////////////////////////////////////////////////////////// 1417 ///////////////////////////////////////////////////////////////////////////////
1416 1418
1417 SkPDFType3Font::SkPDFType3Font(SkAdvancedTypefaceMetrics* info, 1419 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info,
1418 SkTypeface* typeface, 1420 SkTypeface* typeface,
1419 uint16_t glyphID) 1421 uint16_t glyphID)
1420 : SkPDFFont(info, typeface, NULL) { 1422 : SkPDFFont(info, typeface, NULL) {
1421 populate(glyphID); 1423 populate(glyphID);
1422 } 1424 }
1423 1425
1424 SkPDFType3Font::~SkPDFType3Font() {} 1426 SkPDFType3Font::~SkPDFType3Font() {}
1425 1427
1426 bool SkPDFType3Font::populate(int16_t glyphID) { 1428 bool SkPDFType3Font::populate(int16_t glyphID) {
1427 SkPaint paint; 1429 SkPaint paint;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 1490
1489 insert("FontBBox", makeFontBBox(bbox, 1000))->unref(); 1491 insert("FontBBox", makeFontBBox(bbox, 1000))->unref();
1490 insertInt("FirstChar", 1); 1492 insertInt("FirstChar", 1);
1491 insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); 1493 insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1);
1492 insert("Widths", widthArray.get()); 1494 insert("Widths", widthArray.get());
1493 insertName("CIDToGIDMap", "Identity"); 1495 insertName("CIDToGIDMap", "Identity");
1494 1496
1495 populateToUnicodeTable(NULL); 1497 populateToUnicodeTable(NULL);
1496 return true; 1498 return true;
1497 } 1499 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFFont.h ('k') | src/pdf/SkPDFFontImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698