From 2018cbdd9add7cc6b5201f2bc8cba86e62bafc5c Mon Sep 17 00:00:00 2001 From: Russell Brenner Date: Thu, 3 Nov 2011 16:22:00 -0700 Subject: Fix font size handling for harfbuzz hack Complex languages (Arabic, Thai, etc.) currently need to override the base font (e.g. Roboto) with an explicitly loaded copy of the right fallback font (e.g. DroidNaskh). To keep from running out of file descriptors, a caching mechanism was put in place, but the cached data contained the font size, so the first size seen on the page was applied to all subsequent renderings of that font, regardless of the size requested. Size is now also considered in the cache. Bug: 5509443 Change-Id: I616954980122e89da14ce86efe99d5e4343a40c2 --- .../platform/graphics/android/FontAndroid.cpp | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'Source/WebCore') diff --git a/Source/WebCore/platform/graphics/android/FontAndroid.cpp b/Source/WebCore/platform/graphics/android/FontAndroid.cpp index 3528d47..1e64873 100644 --- a/Source/WebCore/platform/graphics/android/FontAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/FontAndroid.cpp @@ -59,6 +59,9 @@ using namespace android; namespace WebCore { +typedef std::pair FallbackFontKey; +typedef HashMap FallbackHash; + static void updateForFont(SkPaint* paint, const SimpleFontData* font) { font->platformData().setupPaint(paint); paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); @@ -454,7 +457,6 @@ private: }; static const char* paths[NUM_SCRIPTS]; - static const FontPlatformData* s_fallbackPlatformData[NUM_SCRIPTS]; void setupFontForScriptRun(); const FontPlatformData* setupComplexFont(CustomScript script, @@ -509,9 +511,6 @@ const char* TextRunWalker::paths[] = { "/system/fonts/DroidSansHebrew-Bold.ttf" }; -// Indexed using enum CustomScript -const FontPlatformData* TextRunWalker::s_fallbackPlatformData[] = {}; - TextRunWalker::TextRunWalker(const TextRun& run, unsigned startingX, const Font* font) : m_font(font) , m_startingX(startingX) @@ -668,17 +667,23 @@ const FontPlatformData* TextRunWalker::setupComplexFont( CustomScript script, const FontPlatformData& platformData) { - if (!s_fallbackPlatformData[script]) { + static FallbackHash fallbackPlatformData; + + FallbackFontKey key(script, platformData.size()); + FontPlatformData* newPlatformData = 0; + + if (!fallbackPlatformData.contains(key)) { SkTypeface* typeface = SkTypeface::CreateFromFile(paths[script]); - s_fallbackPlatformData[script] = new FontPlatformData(platformData, typeface); + newPlatformData = new FontPlatformData(platformData, typeface); SkSafeUnref(typeface); + fallbackPlatformData.set(key, newPlatformData); } - // If we couldn't allocate a new FontPlatformData, revert to the one passed - if (!s_fallbackPlatformData[script]) - return &platformData; + if (!newPlatformData) + newPlatformData = fallbackPlatformData.get(key); - return s_fallbackPlatformData[script]; + // If we couldn't allocate a new FontPlatformData, revert to the one passed + return newPlatformData ? newPlatformData : &platformData; } void TextRunWalker::setupFontForScriptRun() -- cgit v1.1