From: edisonn@google.com Date: Tue, 23 Oct 2012 21:32:39 +0000 (+0000) Subject: Catch callers who pass invalid glyph ids and improve SkPdfFont desructor. X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~14498 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=022e857abc84a43dba0ab93be8680af9dd6f8bf7;p=platform%2Fupstream%2FlibSkiaSharp.git Catch callers who pass invalid glyph ids and improve SkPdfFont desructor. git-svn-id: http://skia.googlecode.com/svn/trunk@6066 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index 5cb801f..3971281 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -701,9 +701,20 @@ SkPDFGlyphSet* SkPDFGlyphSetMap::getGlyphSetForFont(SkPDFFont* font) { SkPDFFont::~SkPDFFont() { SkAutoMutexAcquire lock(CanonicalFontsMutex()); - int index; - if (Find(SkTypeface::UniqueID(fTypeface.get()), fFirstGlyphID, &index) && - CanonicalFonts()[index].fFont == this) { + int index = -1; + for (int i = 0 ; i < CanonicalFonts().count() ; i++) { + if (CanonicalFonts()[i].fFont == this) { + index = i; + } + } + + SkDEBUGCODE(int indexFound;) + SkASSERT(index == -1 || + (Find(SkTypeface::UniqueID(fTypeface.get()), + fFirstGlyphID, + &indexFound) && + index == indexFound)); + if (index >= 0) { CanonicalFonts().removeShuffle(index); } fResources.unrefAll(); @@ -761,6 +772,19 @@ SkPDFFont* SkPDFFont::GetFontResource(SkTypeface* typeface, uint16_t glyphID) { SkPDFFont* relatedFont = CanonicalFonts()[relatedFontIndex].fFont; fontMetrics = relatedFont->fontInfo(); relatedFontDescriptor = relatedFont->getFontDescriptor(); + + // This only is to catch callers who pass invalid glyph ids. + // If glyph id is invalid, then we will create duplicate entries + // for True Type fonts. + SkAdvancedTypefaceMetrics::FontType fontType = + fontMetrics.get() ? fontMetrics.get()->fType : + SkAdvancedTypefaceMetrics::kOther_Font; + + if (fontType == SkAdvancedTypefaceMetrics::kType1CID_Font || + fontType == SkAdvancedTypefaceMetrics::kTrueType_Font) { + CanonicalFonts()[relatedFontIndex].fFont->ref(); + return CanonicalFonts()[relatedFontIndex].fFont; + } } else { SkAdvancedTypefaceMetrics::PerGlyphInfo info; info = SkAdvancedTypefaceMetrics::kGlyphNames_PerGlyphInfo;