diff options
Diffstat (limited to 'src/core/SkScalerContext.cpp')
-rw-r--r-- | src/core/SkScalerContext.cpp | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp index 2921b1e..eee0dc5 100644 --- a/src/core/SkScalerContext.cpp +++ b/src/core/SkScalerContext.cpp @@ -118,7 +118,13 @@ static SkScalerContext* allocNextContext(const SkScalerContext::Rec& rec) { // fonthost will determine the next possible font to search, based // on the current font in fRec. It will return NULL if ctx is our // last font that can be searched (i.e. ultimate fallback font) - uint32_t newFontID = SkFontHost::NextLogicalFont(rec.fFontID, rec.fOrigFontID); +#ifdef SK_BUILD_FOR_ANDROID + // On Android, pass entire rec structure so that clients can change fallback behavior + uint32_t newFontID = SkFontHost::NextLogicalFont(rec); +#else + uint32_t newFontID = SkFontHost::NextLogicalFont(rec.fFontID, rec.fOrigFontID); +#endif + if (0 == newFontID) { return NULL; } @@ -156,6 +162,21 @@ SkScalerContext* SkScalerContext::getNextContext() { return next; } +SkScalerContext* SkScalerContext::getContextFromChar(SkUnichar uni, unsigned& glyphID) { + SkScalerContext* ctx = this; + for (;;) { + glyphID = ctx->generateCharToGlyph(uni); + if (glyphID) { + break; // found it + } + ctx = ctx->getNextContext(); + if (NULL == ctx) { + return NULL; + } + } + return ctx; +} + SkScalerContext* SkScalerContext::getGlyphContext(const SkGlyph& glyph) { unsigned glyphID = glyph.getGlyphID(); SkScalerContext* ctx = this; @@ -176,6 +197,16 @@ SkScalerContext* SkScalerContext::getGlyphContext(const SkGlyph& glyph) { } #ifdef SK_BUILD_FOR_ANDROID +SkFontID SkScalerContext::findTypefaceIdForChar(SkUnichar uni) { + unsigned glyphID; + SkScalerContext* ctx = getContextFromChar(uni, glyphID); + if (ctx) { + return ctx->fRec.fFontID; + } else { + return 0; + } +} + /* This loops through all available fallback contexts (if needed) until it finds some context that can handle the unichar and return it. @@ -183,21 +214,14 @@ SkScalerContext* SkScalerContext::getGlyphContext(const SkGlyph& glyph) { char of a run. */ unsigned SkScalerContext::getBaseGlyphCount(SkUnichar uni) { - SkScalerContext* ctx = this; unsigned glyphID; - for (;;) { - glyphID = ctx->generateCharToGlyph(uni); - if (glyphID) { - break; // found it - } - ctx = ctx->getNextContext(); - if (NULL == ctx) { - SkDebugf("--- no context for char %x\n", uni); - // just return the original context (this) - return this->fBaseGlyphCount; - } + SkScalerContext* ctx = getContextFromChar(uni, glyphID); + if (ctx) { + return ctx->fBaseGlyphCount; + } else { + SkDEBUGF(("--- no context for char %x\n", uni)); + return this->fBaseGlyphCount; } - return ctx->fBaseGlyphCount; } #endif @@ -205,17 +229,11 @@ unsigned SkScalerContext::getBaseGlyphCount(SkUnichar uni) { finds some context that can handle the unichar. If all fail, returns 0 */ uint16_t SkScalerContext::charToGlyphID(SkUnichar uni) { - SkScalerContext* ctx = this; + unsigned glyphID; - for (;;) { - glyphID = ctx->generateCharToGlyph(uni); - if (glyphID) { - break; // found it - } - ctx = ctx->getNextContext(); - if (NULL == ctx) { - return 0; // no more contexts, return missing glyph - } + SkScalerContext* ctx = getContextFromChar(uni, glyphID); + if (!ctx) { + return 0; // no more contexts, return missing glyph } // add the ctx's base, making glyphID unique for chain of contexts glyphID += ctx->fBaseGlyphCount; |