GlyphGenerator(const SkTypeface& typeface, const SkScalerContextEffects& effects, const SkDescriptor& desc) : fScalerContext(typeface.createScalerContext(effects, &desc)) #ifdef SK_DEBUG , fDesc(desc.copy()) #endif {}
// 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(); SkOrderedWriteBuffer androidBuffer(128); fPaintOptionsAndroid.flatten(androidBuffer); SkAutoDescriptor ad(sizeof(fRec) + androidBuffer.size() + 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.size(), NULL)); newRec->fFontID = newFontID; desc->computeChecksum(); return newFace->createScalerContext(desc); #else return NULL; #endif }
std::unique_ptr<SkScalerContext> SkGlyphCache::CreateScalerContext( const SkDescriptor& desc, const SkScalerContextEffects& effects, const SkTypeface& typeface) { auto scaler = typeface.createScalerContext(effects, &desc, true /* can fail */); // Check if we can create a scaler-context before creating the glyphcache. // If not, we may have exhausted OS/font resources, so try purging the // cache once and try again // pass true the first time, to notice if the scalercontext failed, if (scaler == nullptr) { get_globals().purgeAll(); scaler = typeface.createScalerContext(effects, &desc, false /* must succeed */); } return scaler; }
GlyphGenerator(const SkTypeface& typeface, const SkDescriptor& desc) : fScalerContext(typeface.createScalerContext(&desc)) #ifdef SK_DEBUG , fDesc(desc.copy()) #endif { fFlipMatrix.setScale(1, -1); }