Chromium Code Reviews| Index: trunk/src/pdf/SkPDFFont.cpp |
| =================================================================== |
| --- trunk/src/pdf/SkPDFFont.cpp (revision 8138) |
| +++ trunk/src/pdf/SkPDFFont.cpp (working copy) |
| @@ -31,6 +31,31 @@ |
| #include SK_SFNTLY_SUBSETTER |
| #endif |
| +static SkTypeface* refOrDefault(SkTypeface* face) { |
| + return face ? SkRef(face) : SkTypeface::RefDefault(); |
| +} |
| + |
| +/** |
| + * Always resolves to a non-null typeface, either the value passed to its |
| + * constructor, or the default typeface if null was passed. |
| + */ |
| +class SkAutoResolveDefaultTypeface { |
| +public: |
| + SkAutoResolveDefaultTypeface() : fFace(SkTypeface::RefDefault()) {} |
| + |
| + SkAutoResolveDefaultTypeface(SkTypeface* face) |
| + : fFace(refOrDefault(face)) {} |
| + |
| + ~SkAutoResolveDefaultTypeface() { fFace->unref(); } |
| + |
| + SkTypeface* get() const { return fFace; } |
| + SkTypeface* operator->() { return fFace; } |
|
bungeman-skia
2013/03/13 21:33:25
Doe we want operator-> and operator SkTypeface* ?
|
| + operator SkTypeface*() { return fFace; } |
| + |
| +private: |
| + SkTypeface* fFace; |
| +}; |
| + |
| // PDF's notion of symbolic vs non-symbolic is related to the character set, not |
| // symbols vs. characters. Rarely is a font the right character set to call it |
| // non-symbolic, so always call it symbolic. (PDF 1.4 spec, section 5.7.1) |
| @@ -549,8 +574,8 @@ |
| const SkTypeface* typeface, |
| const SkTDArray<uint32_t>& subset, |
| SkPDFStream** fontStream) { |
| - SkAutoTUnref<SkStream> fontData( |
| - SkFontHost::OpenStream(SkTypeface::UniqueID(typeface))); |
| + int ttcIndex; |
| + SkAutoTUnref<SkStream> fontData(typeface->openStream(&ttcIndex)); |
| int fontSize = fontData->getLength(); |
| @@ -714,7 +739,7 @@ |
| SkDEBUGCODE(int indexFound;) |
| SkASSERT(index == -1 || |
| - (Find(SkTypeface::UniqueID(fTypeface.get()), |
| + (Find(fTypeface->uniqueID(), |
| fFirstGlyphID, |
| &indexFound) && |
| index == indexFound)); |
| @@ -763,7 +788,11 @@ |
| // static |
| SkPDFFont* SkPDFFont::GetFontResource(SkTypeface* typeface, uint16_t glyphID) { |
| SkAutoMutexAcquire lock(CanonicalFontsMutex()); |
| - const uint32_t fontID = SkTypeface::UniqueID(typeface); |
| + |
| + SkAutoResolveDefaultTypeface autoResolve(typeface); |
| + typeface = autoResolve.get(); |
| + |
| + const uint32_t fontID = typeface->uniqueID(); |
| int relatedFontIndex; |
| if (Find(fontID, glyphID, &relatedFontIndex)) { |
| CanonicalFonts()[relatedFontIndex].fFont->ref(); |
| @@ -800,7 +829,7 @@ |
| info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo); |
| #endif |
| fontMetrics.reset( |
| - SkFontHost::GetAdvancedTypefaceMetrics(fontID, info, NULL, 0)); |
| + typeface->getAdvancedTypefaceMetrics(info, NULL, 0)); |
| #if defined (SK_SFNTLY_SUBSETTER) |
| if (fontMetrics.get() && |
| fontMetrics->fType != SkAdvancedTypefaceMetrics::kTrueType_Font) { |
| @@ -808,7 +837,7 @@ |
| info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>( |
| info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo); |
| fontMetrics.reset( |
| - SkFontHost::GetAdvancedTypefaceMetrics(fontID, info, NULL, 0)); |
| + typeface->getAdvancedTypefaceMetrics(info, NULL, 0)); |
| } |
| #endif |
| } |
| @@ -855,7 +884,7 @@ |
| SkPDFFont::SkPDFFont(SkAdvancedTypefaceMetrics* info, SkTypeface* typeface, |
| SkPDFDict* relatedFontDescriptor) |
| : SkPDFDict("Font"), |
| - fTypeface(typeface), |
| + fTypeface(refOrDefault(typeface)), |
| fFirstGlyphID(1), |
| fLastGlyphID(info ? info->fLastGlyphID : 0), |
| fFontInfo(info), |
| @@ -1099,8 +1128,8 @@ |
| } |
| case SkAdvancedTypefaceMetrics::kCFF_Font: |
| case SkAdvancedTypefaceMetrics::kType1CID_Font: { |
| - SkAutoTUnref<SkStream> fontData( |
| - SkFontHost::OpenStream(SkTypeface::UniqueID(typeface()))); |
| + int ttcIndex; |
| + SkAutoTUnref<SkStream> fontData(typeface()->openStream(&ttcIndex)); |
| SkAutoTUnref<SkPDFStream> fontStream( |
| new SkPDFStream(fontData.get())); |
| addResource(fontStream.get()); |
| @@ -1139,11 +1168,7 @@ |
| uint32_t* glyphs = (glyphIDs.count() == 1) ? NULL : glyphIDs.begin(); |
| uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0; |
| SkAutoTUnref<SkAdvancedTypefaceMetrics> fontMetrics( |
| - SkFontHost::GetAdvancedTypefaceMetrics( |
| - SkTypeface::UniqueID(typeface()), |
| - info, |
| - glyphs, |
| - glyphsCount)); |
| + typeface()->getAdvancedTypefaceMetrics(info, glyphs, glyphsCount)); |
| setFontInfo(fontMetrics.get()); |
| addFontDescriptor(0, &glyphIDs); |
| } else { |
| @@ -1229,11 +1254,11 @@ |
| SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); |
| setFontDescriptor(descriptor.get()); |
| + int ttcIndex; |
| size_t header SK_INIT_TO_AVOID_WARNING; |
| size_t data SK_INIT_TO_AVOID_WARNING; |
| size_t trailer SK_INIT_TO_AVOID_WARNING; |
| - SkAutoTUnref<SkStream> rawFontData( |
| - SkFontHost::OpenStream(SkTypeface::UniqueID(typeface()))); |
| + SkAutoTUnref<SkStream> rawFontData(typeface()->openStream(&ttcIndex)); |
| SkStream* fontData = handleType1Stream(rawFontData.get(), &header, &data, |
| &trailer); |
| if (fontData == NULL) { |