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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 * | 740 * |
741 * Resources are canonicalized and uniqueified by pointer so there has to be | 741 * Resources are canonicalized and uniqueified by pointer so there has to be |
742 * some additional state indicating which subset of the font is used. It | 742 * some additional state indicating which subset of the font is used. It |
743 * must be maintained at the page granularity and then combined at the document | 743 * must be maintained at the page granularity and then combined at the document |
744 * granularity. a) change SkPDFFont to fill in its state on demand, kind of | 744 * granularity. a) change SkPDFFont to fill in its state on demand, kind of |
745 * like SkPDFGraphicState. b) maintain a per font glyph usage class in each | 745 * like SkPDFGraphicState. b) maintain a per font glyph usage class in each |
746 * page/pdf device. c) in the document, retrieve the per font glyph usage | 746 * page/pdf device. c) in the document, retrieve the per font glyph usage |
747 * from each page and combine it and ask for a resource with that subset. | 747 * from each page and combine it and ask for a resource with that subset. |
748 */ | 748 */ |
749 | 749 |
750 SkPDFFont::~SkPDFFont() { fCanon->removeFont(this); } | 750 SkPDFFont::~SkPDFFont() {} |
751 | 751 |
752 SkTypeface* SkPDFFont::typeface() { | 752 SkTypeface* SkPDFFont::typeface() { |
753 return fTypeface.get(); | 753 return fTypeface.get(); |
754 } | 754 } |
755 | 755 |
756 SkAdvancedTypefaceMetrics::FontType SkPDFFont::getType() { | 756 SkAdvancedTypefaceMetrics::FontType SkPDFFont::getType() { |
757 return fFontType; | 757 return fFontType; |
758 } | 758 } |
759 | 759 |
760 bool SkPDFFont::canEmbed() const { | 760 bool SkPDFFont::canEmbed() const { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 SkPDFFont* font = SkPDFFont::Create(canon, fontMetrics.get(), typeface, | 855 SkPDFFont* font = SkPDFFont::Create(canon, fontMetrics.get(), typeface, |
856 glyphID, relatedFontDescriptor); | 856 glyphID, relatedFontDescriptor); |
857 canon->addFont(font, fontID, font->fFirstGlyphID); | 857 canon->addFont(font, fontID, font->fFirstGlyphID); |
858 return font; | 858 return font; |
859 } | 859 } |
860 | 860 |
861 SkPDFFont* SkPDFFont::getFontSubset(const SkPDFGlyphSet*) { | 861 SkPDFFont* SkPDFFont::getFontSubset(const SkPDFGlyphSet*) { |
862 return NULL; // Default: no support. | 862 return NULL; // Default: no support. |
863 } | 863 } |
864 | 864 |
865 SkPDFFont::SkPDFFont(SkPDFCanon* canon, | 865 SkPDFFont::SkPDFFont(const SkAdvancedTypefaceMetrics* info, |
866 const SkAdvancedTypefaceMetrics* info, | |
867 SkTypeface* typeface, | 866 SkTypeface* typeface, |
868 SkPDFDict* relatedFontDescriptor) | 867 SkPDFDict* relatedFontDescriptor) |
869 : SkPDFDict("Font") | 868 : SkPDFDict("Font") |
870 , fCanon(canon) | |
871 , fTypeface(ref_or_default(typeface)) | 869 , fTypeface(ref_or_default(typeface)) |
872 , fFirstGlyphID(1) | 870 , fFirstGlyphID(1) |
873 , fLastGlyphID(info ? info->fLastGlyphID : 0) | 871 , fLastGlyphID(info ? info->fLastGlyphID : 0) |
874 , fFontInfo(SkSafeRef(info)) | 872 , fFontInfo(SkSafeRef(info)) |
875 , fDescriptor(SkSafeRef(relatedFontDescriptor)) { | 873 , fDescriptor(SkSafeRef(relatedFontDescriptor)) { |
876 if (info == NULL || | 874 if (info == NULL || |
877 info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag) { | 875 info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag) { |
878 fFontType = SkAdvancedTypefaceMetrics::kOther_Font; | 876 fFontType = SkAdvancedTypefaceMetrics::kOther_Font; |
879 } else { | 877 } else { |
880 fFontType = info->fType; | 878 fFontType = info->fType; |
881 } | 879 } |
882 } | 880 } |
883 | 881 |
884 // static | 882 // static |
885 SkPDFFont* SkPDFFont::Create(SkPDFCanon* canon, | 883 SkPDFFont* SkPDFFont::Create(SkPDFCanon* canon, |
886 const SkAdvancedTypefaceMetrics* info, | 884 const SkAdvancedTypefaceMetrics* info, |
887 SkTypeface* typeface, | 885 SkTypeface* typeface, |
888 uint16_t glyphID, | 886 uint16_t glyphID, |
889 SkPDFDict* relatedFontDescriptor) { | 887 SkPDFDict* relatedFontDescriptor) { |
890 SkAdvancedTypefaceMetrics::FontType type = | 888 SkAdvancedTypefaceMetrics::FontType type = |
891 info ? info->fType : SkAdvancedTypefaceMetrics::kOther_Font; | 889 info ? info->fType : SkAdvancedTypefaceMetrics::kOther_Font; |
892 | 890 |
893 if (info && | 891 if (info && |
894 (info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag)) { | 892 (info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag)) { |
895 NOT_IMPLEMENTED(true, true); | 893 NOT_IMPLEMENTED(true, true); |
896 return new SkPDFType3Font(canon, info, typeface, glyphID); | 894 return new SkPDFType3Font(info, typeface, glyphID); |
897 } | 895 } |
898 if (type == SkAdvancedTypefaceMetrics::kType1CID_Font || | 896 if (type == SkAdvancedTypefaceMetrics::kType1CID_Font || |
899 type == SkAdvancedTypefaceMetrics::kTrueType_Font) { | 897 type == SkAdvancedTypefaceMetrics::kTrueType_Font) { |
900 SkASSERT(relatedFontDescriptor == NULL); | 898 SkASSERT(relatedFontDescriptor == NULL); |
901 return new SkPDFType0Font(canon, info, typeface); | 899 return new SkPDFType0Font(info, typeface); |
902 } | 900 } |
903 if (type == SkAdvancedTypefaceMetrics::kType1_Font) { | 901 if (type == SkAdvancedTypefaceMetrics::kType1_Font) { |
904 return new SkPDFType1Font(canon, info, typeface, glyphID, | 902 return new SkPDFType1Font(info, typeface, glyphID, |
905 relatedFontDescriptor); | 903 relatedFontDescriptor); |
906 } | 904 } |
907 | 905 |
908 SkASSERT(type == SkAdvancedTypefaceMetrics::kCFF_Font || | 906 SkASSERT(type == SkAdvancedTypefaceMetrics::kCFF_Font || |
909 type == SkAdvancedTypefaceMetrics::kOther_Font); | 907 type == SkAdvancedTypefaceMetrics::kOther_Font); |
910 | 908 |
911 return new SkPDFType3Font(canon, info, typeface, glyphID); | 909 return new SkPDFType3Font(info, typeface, glyphID); |
912 } | 910 } |
913 | 911 |
914 const SkAdvancedTypefaceMetrics* SkPDFFont::fontInfo() { | 912 const SkAdvancedTypefaceMetrics* SkPDFFont::fontInfo() { |
915 return fFontInfo.get(); | 913 return fFontInfo.get(); |
916 } | 914 } |
917 | 915 |
918 void SkPDFFont::setFontInfo(const SkAdvancedTypefaceMetrics* info) { | 916 void SkPDFFont::setFontInfo(const SkAdvancedTypefaceMetrics* info) { |
919 if (info == NULL || info == fFontInfo.get()) { | 917 if (info == NULL || info == fFontInfo.get()) { |
920 return; | 918 return; |
921 } | 919 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 generate_tounicode_cmap(fFontInfo->fGlyphToUnicode, subset, | 987 generate_tounicode_cmap(fFontInfo->fGlyphToUnicode, subset, |
990 multiByteGlyphs(), firstGlyphID(), | 988 multiByteGlyphs(), firstGlyphID(), |
991 lastGlyphID())); | 989 lastGlyphID())); |
992 insert("ToUnicode", new SkPDFObjRef(pdfCmap.get()))->unref(); | 990 insert("ToUnicode", new SkPDFObjRef(pdfCmap.get()))->unref(); |
993 } | 991 } |
994 | 992 |
995 /////////////////////////////////////////////////////////////////////////////// | 993 /////////////////////////////////////////////////////////////////////////////// |
996 // class SkPDFType0Font | 994 // class SkPDFType0Font |
997 /////////////////////////////////////////////////////////////////////////////// | 995 /////////////////////////////////////////////////////////////////////////////// |
998 | 996 |
999 SkPDFType0Font::SkPDFType0Font(SkPDFCanon* canon, | 997 SkPDFType0Font::SkPDFType0Font(const SkAdvancedTypefaceMetrics* info, |
1000 const SkAdvancedTypefaceMetrics* info, | |
1001 SkTypeface* typeface) | 998 SkTypeface* typeface) |
1002 : SkPDFFont(canon, info, typeface, NULL) { | 999 : SkPDFFont(info, typeface, NULL) { |
1003 SkDEBUGCODE(fPopulated = false); | 1000 SkDEBUGCODE(fPopulated = false); |
1004 if (!canSubset()) { | 1001 if (!canSubset()) { |
1005 populate(NULL); | 1002 populate(NULL); |
1006 } | 1003 } |
1007 } | 1004 } |
1008 | 1005 |
1009 SkPDFType0Font::~SkPDFType0Font() {} | 1006 SkPDFType0Font::~SkPDFType0Font() {} |
1010 | 1007 |
1011 SkPDFFont* SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) { | 1008 SkPDFFont* SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) { |
1012 if (!canSubset()) { | 1009 if (!canSubset()) { |
1013 return NULL; | 1010 return NULL; |
1014 } | 1011 } |
1015 SkPDFType0Font* newSubset = | 1012 SkPDFType0Font* newSubset = |
1016 new SkPDFType0Font(fCanon, fontInfo(), typeface()); | 1013 new SkPDFType0Font(fontInfo(), typeface()); |
1017 newSubset->populate(subset); | 1014 newSubset->populate(subset); |
1018 return newSubset; | 1015 return newSubset; |
1019 } | 1016 } |
1020 | 1017 |
1021 #ifdef SK_DEBUG | 1018 #ifdef SK_DEBUG |
1022 void SkPDFType0Font::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { | 1019 void SkPDFType0Font::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { |
1023 SkASSERT(fPopulated); | 1020 SkASSERT(fPopulated); |
1024 return INHERITED::emitObject(stream, catalog); | 1021 return INHERITED::emitObject(stream, catalog); |
1025 } | 1022 } |
1026 #endif | 1023 #endif |
1027 | 1024 |
1028 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { | 1025 bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { |
1029 insertName("Subtype", "Type0"); | 1026 insertName("Subtype", "Type0"); |
1030 insertName("BaseFont", fontInfo()->fFontName); | 1027 insertName("BaseFont", fontInfo()->fFontName); |
1031 insertName("Encoding", "Identity-H"); | 1028 insertName("Encoding", "Identity-H"); |
1032 | 1029 |
1033 SkAutoTUnref<SkPDFCIDFont> newCIDFont( | 1030 SkAutoTUnref<SkPDFCIDFont> newCIDFont( |
1034 new SkPDFCIDFont(fCanon, fontInfo(), typeface(), subset)); | 1031 new SkPDFCIDFont(fontInfo(), typeface(), subset)); |
1035 SkAutoTUnref<SkPDFArray> descendantFonts(new SkPDFArray()); | 1032 SkAutoTUnref<SkPDFArray> descendantFonts(new SkPDFArray()); |
1036 descendantFonts->append(new SkPDFObjRef(newCIDFont.get()))->unref(); | 1033 descendantFonts->append(new SkPDFObjRef(newCIDFont.get()))->unref(); |
1037 insert("DescendantFonts", descendantFonts.get()); | 1034 insert("DescendantFonts", descendantFonts.get()); |
1038 | 1035 |
1039 populateToUnicodeTable(subset); | 1036 populateToUnicodeTable(subset); |
1040 | 1037 |
1041 SkDEBUGCODE(fPopulated = true); | 1038 SkDEBUGCODE(fPopulated = true); |
1042 return true; | 1039 return true; |
1043 } | 1040 } |
1044 | 1041 |
1045 /////////////////////////////////////////////////////////////////////////////// | 1042 /////////////////////////////////////////////////////////////////////////////// |
1046 // class SkPDFCIDFont | 1043 // class SkPDFCIDFont |
1047 /////////////////////////////////////////////////////////////////////////////// | 1044 /////////////////////////////////////////////////////////////////////////////// |
1048 | 1045 |
1049 SkPDFCIDFont::SkPDFCIDFont(SkPDFCanon* canon, | 1046 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, |
1050 const SkAdvancedTypefaceMetrics* info, | |
1051 SkTypeface* typeface, | 1047 SkTypeface* typeface, |
1052 const SkPDFGlyphSet* subset) | 1048 const SkPDFGlyphSet* subset) |
1053 : SkPDFFont(canon, info, typeface, NULL) { | 1049 : SkPDFFont(info, typeface, NULL) { |
1054 populate(subset); | 1050 populate(subset); |
1055 } | 1051 } |
1056 | 1052 |
1057 SkPDFCIDFont::~SkPDFCIDFont() {} | 1053 SkPDFCIDFont::~SkPDFCIDFont() {} |
1058 | 1054 |
1059 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, | 1055 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, |
1060 const SkTDArray<uint32_t>* subset) { | 1056 const SkTDArray<uint32_t>* subset) { |
1061 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); | 1057 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); |
1062 setFontDescriptor(descriptor.get()); | 1058 setFontDescriptor(descriptor.get()); |
1063 insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref(); | 1059 insert("FontDescriptor", new SkPDFObjRef(descriptor.get()))->unref(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 } | 1190 } |
1195 } | 1191 } |
1196 | 1192 |
1197 return true; | 1193 return true; |
1198 } | 1194 } |
1199 | 1195 |
1200 /////////////////////////////////////////////////////////////////////////////// | 1196 /////////////////////////////////////////////////////////////////////////////// |
1201 // class SkPDFType1Font | 1197 // class SkPDFType1Font |
1202 /////////////////////////////////////////////////////////////////////////////// | 1198 /////////////////////////////////////////////////////////////////////////////// |
1203 | 1199 |
1204 SkPDFType1Font::SkPDFType1Font(SkPDFCanon* canon, | 1200 SkPDFType1Font::SkPDFType1Font(const SkAdvancedTypefaceMetrics* info, |
1205 const SkAdvancedTypefaceMetrics* info, | |
1206 SkTypeface* typeface, | 1201 SkTypeface* typeface, |
1207 uint16_t glyphID, | 1202 uint16_t glyphID, |
1208 SkPDFDict* relatedFontDescriptor) | 1203 SkPDFDict* relatedFontDescriptor) |
1209 : SkPDFFont(canon, info, typeface, relatedFontDescriptor) { | 1204 : SkPDFFont(info, typeface, relatedFontDescriptor) { |
1210 populate(glyphID); | 1205 populate(glyphID); |
1211 } | 1206 } |
1212 | 1207 |
1213 SkPDFType1Font::~SkPDFType1Font() {} | 1208 SkPDFType1Font::~SkPDFType1Font() {} |
1214 | 1209 |
1215 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { | 1210 bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { |
1216 if (getFontDescriptor() != NULL) { | 1211 if (getFontDescriptor() != NULL) { |
1217 SkPDFDict* descriptor = getFontDescriptor(); | 1212 SkPDFDict* descriptor = getFontDescriptor(); |
1218 insert("FontDescriptor", new SkPDFObjRef(descriptor))->unref(); | 1213 insert("FontDescriptor", new SkPDFObjRef(descriptor))->unref(); |
1219 return true; | 1214 return true; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 } | 1317 } |
1323 insertInt("FirstChar", firstChar); | 1318 insertInt("FirstChar", firstChar); |
1324 insertInt("LastChar", firstChar + widthArray->size() - 1); | 1319 insertInt("LastChar", firstChar + widthArray->size() - 1); |
1325 insert("Widths", widthArray.get()); | 1320 insert("Widths", widthArray.get()); |
1326 } | 1321 } |
1327 | 1322 |
1328 /////////////////////////////////////////////////////////////////////////////// | 1323 /////////////////////////////////////////////////////////////////////////////// |
1329 // class SkPDFType3Font | 1324 // class SkPDFType3Font |
1330 /////////////////////////////////////////////////////////////////////////////// | 1325 /////////////////////////////////////////////////////////////////////////////// |
1331 | 1326 |
1332 SkPDFType3Font::SkPDFType3Font(SkPDFCanon* canon, | 1327 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info, |
1333 const SkAdvancedTypefaceMetrics* info, | |
1334 SkTypeface* typeface, | 1328 SkTypeface* typeface, |
1335 uint16_t glyphID) | 1329 uint16_t glyphID) |
1336 : SkPDFFont(canon, info, typeface, NULL) { | 1330 : SkPDFFont(info, typeface, NULL) { |
1337 populate(glyphID); | 1331 populate(glyphID); |
1338 } | 1332 } |
1339 | 1333 |
1340 SkPDFType3Font::~SkPDFType3Font() {} | 1334 SkPDFType3Font::~SkPDFType3Font() {} |
1341 | 1335 |
1342 bool SkPDFType3Font::populate(uint16_t glyphID) { | 1336 bool SkPDFType3Font::populate(uint16_t glyphID) { |
1343 SkPaint paint; | 1337 SkPaint paint; |
1344 paint.setTypeface(typeface()); | 1338 paint.setTypeface(typeface()); |
1345 paint.setTextSize(1000); | 1339 paint.setTextSize(1000); |
1346 SkAutoGlyphCache autoCache(paint, NULL, NULL); | 1340 SkAutoGlyphCache autoCache(paint, NULL, NULL); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1424 } | 1418 } |
1425 if (existingFont != NULL) { | 1419 if (existingFont != NULL) { |
1426 return (existingFont->fFirstGlyphID <= searchGlyphID && | 1420 return (existingFont->fFirstGlyphID <= searchGlyphID && |
1427 searchGlyphID <= existingFont->fLastGlyphID) | 1421 searchGlyphID <= existingFont->fLastGlyphID) |
1428 ? SkPDFFont::kExact_Match | 1422 ? SkPDFFont::kExact_Match |
1429 : SkPDFFont::kRelated_Match; | 1423 : SkPDFFont::kRelated_Match; |
1430 } | 1424 } |
1431 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match | 1425 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match |
1432 : SkPDFFont::kRelated_Match; | 1426 : SkPDFFont::kRelated_Match; |
1433 } | 1427 } |
OLD | NEW |