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

Unified Diff: src/core/SkScalerContext.cpp

Issue 12699002: Upstream changes from Android. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: more fiex Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkScalerContext.h ('k') | src/effects/SkMagnifierImageFilter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkScalerContext.cpp
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index 690ee77b3f3addb1fb8448951d46bee490dc881d..9d13a6c1206e441b6bd4f7532f142771a2211c6f 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -178,7 +178,35 @@ SkScalerContext* SkScalerContext::getGlyphContext(const SkGlyph& glyph) {
return ctx;
}
+SkScalerContext* SkScalerContext::getContextFromChar(SkUnichar uni,
+ uint16_t* glyphID) {
+ SkScalerContext* ctx = this;
+ for (;;) {
+ const uint16_t glyph = ctx->generateCharToGlyph(uni);
+ if (glyph) {
+ if (NULL != glyphID) {
+ *glyphID = glyph;
+ }
+ break; // found it
+ }
+ ctx = ctx->getNextContext();
+ if (NULL == ctx) {
+ return NULL;
+ }
+ }
+ return ctx;
+}
+
#ifdef SK_BUILD_FOR_ANDROID
+SkFontID SkScalerContext::findTypefaceIdForChar(SkUnichar uni) {
+ SkScalerContext* ctx = this->getContextFromChar(uni, NULL);
+ if (NULL != 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.
@@ -186,21 +214,13 @@ 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 = this->getContextFromChar(uni, NULL);
+ if (NULL != ctx) {
+ return ctx->fBaseGlyphCount;
+ } else {
+ SkDEBUGF(("--- no context for char %x\n", uni));
+ return this->fBaseGlyphCount;
}
- return ctx->fBaseGlyphCount;
}
#endif
@@ -208,20 +228,14 @@ 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
- }
+
+ uint16_t tempID;
+ SkScalerContext* ctx = this->getContextFromChar(uni, &tempID);
+ if (NULL == ctx) {
+ return 0; // no more contexts, return missing glyph
}
// add the ctx's base, making glyphID unique for chain of contexts
- glyphID += ctx->fBaseGlyphCount;
+ unsigned glyphID = tempID + ctx->fBaseGlyphCount;
// check for overflow of 16bits, since our glyphID cannot exceed that
if (glyphID > 0xFFFF) {
glyphID = 0;
« no previous file with comments | « src/core/SkScalerContext.h ('k') | src/effects/SkMagnifierImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698