aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar djsollen <djsollen@google.com>2014-08-06 06:58:06 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-06 06:58:06 -0700
commit1b27704eba15be4e9d1997faac42038493a30be5 (patch)
tree867cb1e568681cdb719c9c3771bbfadf222b3787 /src/core
parent847092c88be671c06bdf24aa02b5a66e7a593a15 (diff)
Remove ALL font fallback logic from Skia.
R=reed@google.com, bungeman@google.com, caryclark@google.com Author: djsollen@google.com Review URL: https://codereview.chromium.org/434623002
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkGlyph.h6
-rw-r--r--src/core/SkGlyphCache.h8
-rw-r--r--src/core/SkPaint.cpp6
-rw-r--r--src/core/SkPaintOptionsAndroid.cpp6
-rw-r--r--src/core/SkScalerContext.cpp170
-rw-r--r--src/core/SkScalerContext.h36
6 files changed, 14 insertions, 218 deletions
diff --git a/src/core/SkGlyph.h b/src/core/SkGlyph.h
index 73afb132d6..5e0ac7ec0b 100644
--- a/src/core/SkGlyph.h
+++ b/src/core/SkGlyph.h
@@ -76,12 +76,6 @@ struct SkGlyph {
return ID2Code(fID);
}
- unsigned getGlyphID(unsigned baseGlyphCount) const {
- unsigned code = ID2Code(fID);
- SkASSERT(code >= baseGlyphCount);
- return code - baseGlyphCount;
- }
-
unsigned getSubX() const {
return ID2SubX(fID);
}
diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h
index 4daf6b06b6..2939eaa678 100644
--- a/src/core/SkGlyphCache.h
+++ b/src/core/SkGlyphCache.h
@@ -76,14 +76,6 @@ public:
*/
unsigned getGlyphCount();
-#ifdef SK_BUILD_FOR_ANDROID
- /** Returns the base glyph count for this strike.
- */
- unsigned getBaseGlyphCount(SkUnichar charCode) const {
- return fScalerContext->getBaseGlyphCount(charCode);
- }
-#endif
-
/** Return the image associated with the glyph. If it has not been generated
this will trigger that.
*/
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 8fc7c19595..9e53d19e2a 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -242,12 +242,6 @@ void SkPaint::setGenerationID(uint32_t generationID) {
fGenerationID = generationID;
}
-unsigned SkPaint::getBaseGlyphCount(SkUnichar text) const {
- SkAutoGlyphCache autoCache(*this, NULL, NULL);
- SkGlyphCache* cache = autoCache.getCache();
- return cache->getBaseGlyphCount(text);
-}
-
void SkPaint::setPaintOptionsAndroid(const SkPaintOptionsAndroid& options) {
if (options != fPaintOptionsAndroid) {
fPaintOptionsAndroid = options;
diff --git a/src/core/SkPaintOptionsAndroid.cpp b/src/core/SkPaintOptionsAndroid.cpp
index 56f1bd1654..df71ca87a4 100644
--- a/src/core/SkPaintOptionsAndroid.cpp
+++ b/src/core/SkPaintOptionsAndroid.cpp
@@ -29,7 +29,8 @@ SkLanguage SkLanguage::getParent() const {
void SkPaintOptionsAndroid::flatten(SkWriteBuffer& buffer) const {
buffer.writeUInt(fFontVariant);
buffer.writeString(fLanguage.getTag().c_str());
- buffer.writeBool(fUseFontFallbacks);
+ // to maintain picture compatibility for the old fUseFontFallbacks variable
+ buffer.writeBool(false);
}
void SkPaintOptionsAndroid::unflatten(SkReadBuffer& buffer) {
@@ -37,5 +38,6 @@ void SkPaintOptionsAndroid::unflatten(SkReadBuffer& buffer) {
SkString tag;
buffer.readString(&tag);
fLanguage = SkLanguage(tag);
- fUseFontFallbacks = buffer.readBool();
+ // to maintain picture compatibility for the old fUseFontFallbacks variable
+ buffer.readBool();
}
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index b18dc1a79c..11208fec59 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -83,7 +83,6 @@ static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag,
SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc)
: fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, NULL)))
- , fBaseGlyphCount(0)
, fTypeface(SkRef(typeface))
, fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_SkDescriptorTag,
SkFlattenable::kSkPathEffect_Type)))
@@ -94,8 +93,6 @@ SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc)
// Initialize based on our settings. Subclasses can also force this.
, fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != NULL || fRasterizer != NULL)
- , fNextContext(NULL)
-
, fPreBlend(fMaskFilter ? SkMaskGamma::PreBlend() : SkScalerContext::GetMaskPreBlend(fRec))
, fPreBlendForFilter(fMaskFilter ? SkScalerContext::GetMaskPreBlend(fRec)
: SkMaskGamma::PreBlend())
@@ -126,180 +123,22 @@ SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc)
}
SkScalerContext::~SkScalerContext() {
- SkDELETE(fNextContext);
-
SkSafeUnref(fPathEffect);
SkSafeUnref(fMaskFilter);
SkSafeUnref(fRasterizer);
}
-// Return the context associated with the next logical typeface, or NULL if
-// there are no more entries in the fallback chain.
-SkScalerContext* SkScalerContext::allocNextContext() const {
-#ifdef SK_BUILD_FOR_ANDROID
- SkTypeface* newFace = SkAndroidNextLogicalTypeface(fRec.fFontID,
- fRec.fOrigFontID,
- fPaintOptionsAndroid);
- if (0 == newFace) {
- return NULL;
- }
-
- SkAutoTUnref<SkTypeface> aur(newFace);
- uint32_t newFontID = newFace->uniqueID();
-
- SkWriteBuffer androidBuffer;
- fPaintOptionsAndroid.flatten(androidBuffer);
-
- SkAutoDescriptor ad(sizeof(fRec) + androidBuffer.bytesWritten()
- + SkDescriptor::ComputeOverhead(2));
- SkDescriptor* desc = ad.getDesc();
-
- desc->init();
- SkScalerContext::Rec* newRec =
- (SkScalerContext::Rec*)desc->addEntry(kRec_SkDescriptorTag,
- sizeof(fRec), &fRec);
- androidBuffer.writeToMemory(desc->addEntry(kAndroidOpts_SkDescriptorTag,
- androidBuffer.bytesWritten(), NULL));
-
- newRec->fFontID = newFontID;
- desc->computeChecksum();
-
- return newFace->createScalerContext(desc);
-#else
- return NULL;
-#endif
-}
-
-/* Return the next context, creating it if its not already created, but return
- NULL if the fonthost says there are no more fonts to fallback to.
- */
-SkScalerContext* SkScalerContext::getNextContext() {
- SkScalerContext* next = fNextContext;
- // if next is null, then either it isn't cached yet, or we're at the
- // end of our possible chain
- if (NULL == next) {
- next = this->allocNextContext();
- if (NULL == next) {
- return NULL;
- }
- // next's base is our base + our local count
- next->setBaseGlyphCount(fBaseGlyphCount + this->getGlyphCount());
- // cache the answer
- fNextContext = next;
- }
- return next;
-}
-
-SkScalerContext* SkScalerContext::getGlyphContext(const SkGlyph& glyph) {
- unsigned glyphID = glyph.getGlyphID();
- SkScalerContext* ctx = this;
- for (;;) {
- unsigned count = ctx->getGlyphCount();
- if (glyphID < count) {
- break;
- }
- glyphID -= count;
- ctx = ctx->getNextContext();
- if (NULL == ctx) {
-// SkDebugf("--- no context for glyph %x\n", glyph.getGlyphID());
- // just return the original context (this)
- return this;
- }
- }
- 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.
-
- As this is somewhat expensive operation, it should only be done on the first
- char of a run.
- */
-unsigned SkScalerContext::getBaseGlyphCount(SkUnichar uni) {
- SkScalerContext* ctx = this->getContextFromChar(uni, NULL);
- if (NULL != ctx) {
- return ctx->fBaseGlyphCount;
- } else {
- SkDEBUGF(("--- no context for char %x\n", uni));
- return this->fBaseGlyphCount;
- }
-}
-#endif
-
-/* This loops through all available fallback contexts (if needed) until it
- finds some context that can handle the unichar. If all fail, returns 0
- */
-uint16_t SkScalerContext::charToGlyphID(SkUnichar uni) {
-
- 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
- unsigned glyphID = tempID + ctx->fBaseGlyphCount;
- // check for overflow of 16bits, since our glyphID cannot exceed that
- if (glyphID > 0xFFFF) {
- glyphID = 0;
- }
- return SkToU16(glyphID);
-}
-
-SkUnichar SkScalerContext::glyphIDToChar(uint16_t glyphID) {
- SkScalerContext* ctx = this;
- unsigned rangeEnd = 0;
- do {
- unsigned rangeStart = rangeEnd;
-
- rangeEnd += ctx->getGlyphCount();
- if (rangeStart <= glyphID && glyphID < rangeEnd) {
- return ctx->generateGlyphToChar(glyphID - rangeStart);
- }
- ctx = ctx->getNextContext();
- } while (NULL != ctx);
- return 0;
-}
-
void SkScalerContext::getAdvance(SkGlyph* glyph) {
// mark us as just having a valid advance
glyph->fMaskFormat = MASK_FORMAT_JUST_ADVANCE;
// we mark the format before making the call, in case the impl
// internally ends up calling its generateMetrics, which is OK
// albeit slower than strictly necessary
- this->getGlyphContext(*glyph)->generateAdvance(glyph);
+ generateAdvance(glyph);
}
void SkScalerContext::getMetrics(SkGlyph* glyph) {
- this->getGlyphContext(*glyph)->generateMetrics(glyph);
+ generateMetrics(glyph);
// for now we have separate cache entries for devkerning on and off
// in the future we might share caches, but make our measure/draw
@@ -737,7 +576,7 @@ void SkScalerContext::getImage(const SkGlyph& origGlyph) {
generateMask(mask, devPath, fPreBlend);
}
} else {
- this->getGlyphContext(*glyph)->generateImage(*glyph);
+ generateImage(*glyph);
}
if (fMaskFilter) {
@@ -811,8 +650,7 @@ SkUnichar SkScalerContext::generateGlyphToChar(uint16_t glyph) {
void SkScalerContext::internalGetPath(const SkGlyph& glyph, SkPath* fillPath,
SkPath* devPath, SkMatrix* fillToDevMatrix) {
SkPath path;
-
- this->getGlyphContext(glyph)->generatePath(glyph, &path);
+ generatePath(glyph, &path);
if (fRec.fFlags & SkScalerContext::kSubpixelPositioning_Flag) {
SkFixed dx = glyph.getSubXFixed();
diff --git a/src/core/SkScalerContext.h b/src/core/SkScalerContext.h
index be5d3b555e..43b5ebfaf6 100644
--- a/src/core/SkScalerContext.h
+++ b/src/core/SkScalerContext.h
@@ -164,22 +164,21 @@ public:
return SkToBool(fRec.fFlags & kVertical_Flag);
}
- // remember our glyph offset/base
- void setBaseGlyphCount(unsigned baseGlyphCount) {
- fBaseGlyphCount = baseGlyphCount;
- }
-
/** Return the corresponding glyph for the specified unichar. Since contexts
may be chained (under the hood), the glyphID that is returned may in
fact correspond to a different font/context. In that case, we use the
base-glyph-count to know how to translate back into local glyph space.
*/
- uint16_t charToGlyphID(SkUnichar uni);
+ uint16_t charToGlyphID(SkUnichar uni) {
+ return generateCharToGlyph(uni);
+ }
/** Map the glyphID to its glyph index, and then to its char code. Unmapped
glyphs return zero.
*/
- SkUnichar glyphIDToChar(uint16_t glyphID);
+ SkUnichar glyphIDToChar(uint16_t glyphID) {
+ return (glyphID < getGlyphCount()) ? generateGlyphToChar(glyphID) : 0;
+ }
unsigned getGlyphCount() { return this->generateGlyphCount(); }
void getAdvance(SkGlyph*);
@@ -199,14 +198,6 @@ public:
static void GetGammaLUTData(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma,
void* data);
-#ifdef SK_BUILD_FOR_ANDROID
- unsigned getBaseGlyphCount(SkUnichar charCode);
-
- // This function must be public for SkTypeface_android.h, but should not be
- // called by other callers
- SkFontID findTypefaceIdForChar(SkUnichar uni);
-#endif
-
static void MakeRec(const SkPaint&, const SkDeviceProperties* deviceProperties,
const SkMatrix*, Rec* rec);
static inline void PostMakeRec(const SkPaint&, Rec*);
@@ -215,7 +206,6 @@ public:
protected:
Rec fRec;
- unsigned fBaseGlyphCount;
/** Generates the contents of glyph.fAdvanceX and glyph.fAdvanceY.
* May call getMetrics if that would be just as fast.
@@ -288,25 +278,11 @@ private:
void internalGetPath(const SkGlyph& glyph, SkPath* fillPath,
SkPath* devPath, SkMatrix* fillToDevMatrix);
- // Return the context associated with the next logical typeface, or NULL if
- // there are no more entries in the fallback chain.
- SkScalerContext* allocNextContext() const;
-
- // return the next context, treating fNextContext as a cache of the answer
- SkScalerContext* getNextContext();
-
- // returns the right context from our link-list for this glyph. If no match
- // is found, just returns the original context (this)
- SkScalerContext* getGlyphContext(const SkGlyph& glyph);
-
// returns the right context from our link-list for this char. If no match
// is found it returns NULL. If a match is found then the glyphID param is
// set to the glyphID that maps to the provided char.
SkScalerContext* getContextFromChar(SkUnichar uni, uint16_t* glyphID);
- // link-list of context, to handle missing chars. null-terminated.
- SkScalerContext* fNextContext;
-
// SkMaskGamma::PreBlend converts linear masks to gamma correcting masks.
protected:
// Visible to subclasses so that generateImage can apply the pre-blend directly.