bug 619521 pt 2 - load fonts from the current profile as well as the Android system fonts. r=jdagget
authorJonathan Kew <jkew@mozilla.com>
Wed, 03 Oct 2012 12:27:25 -0700
changeset 115408 5542e7d206769430dba9aca41bac4341d75fd05a
parent 115407 5c2b826588d334bb3b02cae238adec4549bac7b6
child 115409 5a788605acfe681ddd81ba4b479b6e4b5abdc4b6
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdagget
bugs619521
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 619521 pt 2 - load fonts from the current profile as well as the Android system fonts. r=jdagget
gfx/thebes/gfxFT2FontList.cpp
gfx/thebes/gfxFT2FontList.h
--- a/gfx/thebes/gfxFT2FontList.cpp
+++ b/gfx/thebes/gfxFT2FontList.cpp
@@ -932,16 +932,46 @@ gfxFT2FontList::FindFonts()
     char *androidRoot = PR_GetEnv("ANDROID_ROOT");
     if (androidRoot) {
         root = androidRoot;
     } else {
         root = NS_LITERAL_CSTRING("/system");
     }
     root.Append("/fonts");
 
+    FindFontsInDir(root, &fnc);
+
+    if (mFontFamilies.Count() == 0) {
+        // if we can't find/read the font directory, we are doomed!
+        NS_RUNTIMEABORT("Could not read the system fonts directory");
+    }
+
+    // look for locally-added fonts in the profile
+    nsCOMPtr<nsIFile> localDir;
+    nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_LOCAL_50_DIR,
+                                         getter_AddRefs(localDir));
+    if (NS_SUCCEEDED(rv)) {
+        nsCString localPath;
+        rv = localDir->GetNativePath(localPath);
+        if (NS_SUCCEEDED(rv)) {
+            FindFontsInDir(localPath, &fnc);
+        }
+    }
+
+    // Finalize the families by sorting faces into standard order
+    // and marking "simple" families.
+    // Passing non-null userData here says that we want faces to be sorted.
+    mFontFamilies.Enumerate(FinalizeFamilyMemberList, this);
+#endif // XP_WIN && ANDROID
+}
+
+#ifdef ANDROID
+void
+gfxFT2FontList::FindFontsInDir(const nsCString& aDir, FontNameCache *aFNC)
+{
     static const char* sStandardFonts[] = {
         "DroidSans.ttf",
         "DroidSans-Bold.ttf",
         "DroidSerif-Regular.ttf",
         "DroidSerif-Bold.ttf",
         "DroidSerif-Italic.ttf",
         "DroidSerif-BoldItalic.ttf",
         "DroidSansMono.ttf",
@@ -949,60 +979,53 @@ gfxFT2FontList::FindFonts()
         "DroidSansHebrew.ttf",
         "DroidSansThai.ttf",
         "MTLmr3m.ttf",
         "MTLc3m.ttf",
         "DroidSansJapanese.ttf",
         "DroidSansFallback.ttf"
     };
 
-    DIR *d = opendir(root.get());
+    DIR *d = opendir(aDir.get());
     if (!d) {
-        // if we can't find/read the font directory, we are doomed!
-        NS_RUNTIMEABORT("Could not read the system fonts directory");
+        return;
     }
 
     struct dirent *ent = NULL;
     while ((ent = readdir(d)) != NULL) {
         int namelen = strlen(ent->d_name);
         if (namelen <= 4) {
             // cannot be a usable font filename
             continue;
         }
         const char *ext = ent->d_name + namelen - 4;
         if (strcasecmp(ext, ".ttf") == 0 ||
             strcasecmp(ext, ".otf") == 0 ||
-            strcasecmp(ext, ".ttc") == 0)
-        {
+            strcasecmp(ext, ".ttc") == 0) {
             bool isStdFont = false;
             for (unsigned int i = 0;
-                 i < ArrayLength(sStandardFonts) && !isStdFont; i++)
-            {
+                 i < ArrayLength(sStandardFonts) && !isStdFont; i++) {
                 isStdFont = strcmp(sStandardFonts[i], ent->d_name) == 0;
             }
 
-            nsCString s(root);
+            nsCString s(aDir);
             s.Append('/');
             s.Append(ent->d_name, namelen);
 
             // Add the face(s) from this file to our font list;
             // note that if we have cached info for this file in fnc,
             // and the file is unchanged, we won't actually need to read it.
             // If the file is new/changed, this will update the FontNameCache.
-            AppendFacesFromFontFile(s, isStdFont, &fnc);
+            AppendFacesFromFontFile(s, isStdFont, aFNC);
         }
     }
+
     closedir(d);
-
-    // Finalize the families by sorting faces into standard order
-    // and marking "simple" families.
-    // Passing non-null userData here says that we want faces to be sorted.
-    mFontFamilies.Enumerate(FinalizeFamilyMemberList, this);
-#endif // XP_WIN && ANDROID
 }
+#endif
 
 void
 gfxFT2FontList::AppendFaceFromFontListEntry(const FontListEntry& aFLE,
                                             bool aStdFile)
 {
     FT2FontEntry* fe = FT2FontEntry::CreateFontEntry(aFLE);
     if (fe) {
         fe->mStandardFace = aStdFile;
--- a/gfx/thebes/gfxFT2FontList.h
+++ b/gfx/thebes/gfxFT2FontList.h
@@ -125,11 +125,15 @@ protected:
                                  bool isStdFile = false,
                                  FontNameCache *aCache = nullptr);
 
     void AppendFacesFromCachedFaceList(nsCString& aFileName,
                                        bool isStdFile,
                                        nsCString& aFaceList);
 
     void FindFonts();
+
+#ifdef ANDROID
+    void FindFontsInDir(const nsCString& aDir, FontNameCache* aFNC);
+#endif
 };
 
 #endif /* GFX_FT2FONTLIST_H */