bug 844669 pt 3 - implement a simple GetCommonFallbackFonts for Android, to reduce the chances of hitting the global fallback codepath and loading all cmaps. r=blassey a=bajaj
authorJonathan Kew <jkew@mozilla.com>
Mon, 04 Mar 2013 17:03:16 +0000
changeset 132359 41d7a2a0776b05426a47a7d52eda55ca6fca1592
parent 132358 b661c3303b3c2c924c4319bac1fa3e9bc16bb38e
child 132360 a11d11b69ee7f17c026118c6de2e6c6be8359291
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey, bajaj
bugs844669
milestone21.0a2
bug 844669 pt 3 - implement a simple GetCommonFallbackFonts for Android, to reduce the chances of hitting the global fallback codepath and loading all cmaps. r=blassey a=bajaj
gfx/thebes/gfxAndroidPlatform.cpp
gfx/thebes/gfxAndroidPlatform.h
--- a/gfx/thebes/gfxAndroidPlatform.cpp
+++ b/gfx/thebes/gfxAndroidPlatform.cpp
@@ -121,16 +121,64 @@ gfxAndroidPlatform::CreateOffscreenSurfa
                                       gfxASurface::gfxContentType contentType)
 {
     nsRefPtr<gfxASurface> newSurface;
     newSurface = new gfxImageSurface(size, OptimalFormatForContent(contentType));
 
     return newSurface.forget();
 }
 
+void
+gfxAndroidPlatform::GetCommonFallbackFonts(const uint32_t aCh,
+                                           int32_t aRunScript,
+                                           nsTArray<const char*>& aFontList)
+{
+    static const char kDroidSansJapanese[] = "Droid Sans Japanese";
+
+    if (IS_IN_BMP(aCh)) {
+        // try language-specific "Droid Sans *" fonts for certain blocks,
+        // as most devices probably have these
+        uint8_t block = (aCh >> 8) & 0xff;
+        switch (block) {
+        case 0x05:
+            aFontList.AppendElement("Droid Sans Hebrew");
+            aFontList.AppendElement("Droid Sans Armenian");
+            break;
+        case 0x06:
+            aFontList.AppendElement("Droid Sans Arabic");
+            break;
+        case 0x09:
+            aFontList.AppendElement("Droid Sans Devanagari");
+            break;
+        case 0x0b:
+            aFontList.AppendElement("Droid Sans Tamil");
+            break;
+        case 0x0e:
+            aFontList.AppendElement("Droid Sans Thai");
+            break;
+        case 0x10: case 0x2d:
+            aFontList.AppendElement("Droid Sans Georgian");
+            break;
+        case 0x12: case 0x13:
+            aFontList.AppendElement("Droid Sans Ethiopic");
+            break;
+        case 0xf9: case 0xfa:
+            aFontList.AppendElement(kDroidSansJapanese);
+            break;
+        default:
+            if (block >= 0x2e && block <= 0x9f) {
+                aFontList.AppendElement(kDroidSansJapanese);
+            }
+            break;
+        }
+    }
+    // and try Droid Sans Fallback as a last resort
+    aFontList.AppendElement("Droid Sans Fallback");
+}
+
 nsresult
 gfxAndroidPlatform::GetFontList(nsIAtom *aLangGroup,
                                 const nsACString& aGenericFamily,
                                 nsTArray<nsString>& aListOfFonts)
 {
     gfxPlatformFontList::PlatformFontList()->GetFontList(aLangGroup,
                                                          aGenericFamily,
                                                          aListOfFonts);
--- a/gfx/thebes/gfxAndroidPlatform.h
+++ b/gfx/thebes/gfxAndroidPlatform.h
@@ -42,16 +42,20 @@ public:
     void GetFontList(InfallibleTArray<FontListEntry>* retValue);
 
     // platform implementations of font functions
     virtual bool IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags);
     virtual gfxPlatformFontList* CreatePlatformFontList();
     virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
                                            const uint8_t *aFontData, uint32_t aLength);
 
+    virtual void GetCommonFallbackFonts(const uint32_t aCh,
+                                        int32_t aRunScript,
+                                        nsTArray<const char*>& aFontList);
+
     virtual nsresult GetFontList(nsIAtom *aLangGroup,
                                  const nsACString& aGenericFamily,
                                  nsTArray<nsString>& aListOfFonts);
 
     virtual nsresult UpdateFontList();
 
     virtual nsresult ResolveFontName(const nsAString& aFontName,
                                      FontResolverCallback aCallback,