Bug 524107 - part 2 - store language as atom instead of string in gfxFontStyle. r=roc sr=mats
authorJonathan Kew <jfkthame@gmail.com>
Wed, 24 Feb 2010 09:57:57 -0800
changeset 38493 4c60c40075e932db1ee1e52d6e8c3370b112c72a
parent 38492 fe3c9f571228d6c9d8c8effc17755c4c4206b84b
child 38494 c44fd5b31fb82b246301dac1af5663e0459b51fc
push id11780
push userjkew@mozilla.com
push dateWed, 24 Feb 2010 18:32:41 +0000
treeherdermozilla-central@4c60c40075e9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, mats
bugs524107
milestone1.9.3a2pre
Bug 524107 - part 2 - store language as atom instead of string in gfxFontStyle. r=roc sr=mats
content/canvas/src/nsCanvasRenderingContext2D.cpp
gfx/src/thebes/nsThebesFontEnumerator.cpp
gfx/src/thebes/nsThebesFontMetrics.cpp
gfx/thebes/public/gfxBeOSPlatform.h
gfx/thebes/public/gfxFT2Fonts.h
gfx/thebes/public/gfxFont.h
gfx/thebes/public/gfxOS2Platform.h
gfx/thebes/public/gfxPangoFonts.h
gfx/thebes/public/gfxPlatform.h
gfx/thebes/public/gfxPlatformGtk.h
gfx/thebes/public/gfxPlatformMac.h
gfx/thebes/public/gfxQtPlatform.h
gfx/thebes/public/gfxWindowsFonts.h
gfx/thebes/public/gfxWindowsPlatform.h
gfx/thebes/src/Makefile.in
gfx/thebes/src/gfxAtomList.h
gfx/thebes/src/gfxAtoms.cpp
gfx/thebes/src/gfxAtoms.h
gfx/thebes/src/gfxBeOSPlatform.cpp
gfx/thebes/src/gfxFT2Fonts.cpp
gfx/thebes/src/gfxFont.cpp
gfx/thebes/src/gfxFontconfigUtils.cpp
gfx/thebes/src/gfxFontconfigUtils.h
gfx/thebes/src/gfxOS2Platform.cpp
gfx/thebes/src/gfxPangoFonts.cpp
gfx/thebes/src/gfxPlatform.cpp
gfx/thebes/src/gfxPlatformFontList.cpp
gfx/thebes/src/gfxPlatformFontList.h
gfx/thebes/src/gfxPlatformGtk.cpp
gfx/thebes/src/gfxPlatformMac.cpp
gfx/thebes/src/gfxQtPlatform.cpp
gfx/thebes/src/gfxWindowsFonts.cpp
gfx/thebes/src/gfxWindowsPlatform.cpp
gfx/thebes/src/nsUnicodeRange.cpp
gfx/thebes/src/nsUnicodeRange.h
gfx/thebes/test/gfxFontSelectionTests.h
gfx/thebes/test/gfxTextRunPerfTest.cpp
gfx/thebes/test/gfxWordCacheTest.cpp
layout/svg/base/src/nsSVGGlyphFrame.cpp
--- a/content/canvas/src/nsCanvasRenderingContext2D.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp
@@ -1927,18 +1927,17 @@ nsCanvasRenderingContext2D::SetFont(cons
         return NS_ERROR_FAILURE;
     }
 
     nsIPresShell* presShell = GetPresShell();
     if (!presShell)
       return NS_ERROR_FAILURE;
     nsIDocument* document = presShell->GetDocument();
 
-    nsCString language;
-    presShell->GetPresContext()->GetLanguage()->ToUTF8String(language);
+    nsIAtom *language = presShell->GetPresContext()->GetLanguage();
 
     nsCOMArray<nsIStyleRule> rules;
 
     nsCOMPtr<nsICSSStyleRule> rule;
     rv = CreateFontStyleRule(font, mCSSParser.get(), document, getter_AddRefs(rule));
     if (NS_FAILED(rv))
         return rv;
 
@@ -1999,17 +1998,20 @@ nsCanvasRenderingContext2D::SetFont(cons
                        fontStyle->mFont.stretch,
                        NSAppUnitsToFloatPixels(fontSize, aupcp),
                        language,
                        fontStyle->mFont.sizeAdjust,
                        fontStyle->mFont.systemFont,
                        fontStyle->mFont.familyNameQuirks,
                        printerFont);
 
-    CurrentState().fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(fontStyle->mFont.name, &style, presShell->GetPresContext()->GetUserFontSet());
+    CurrentState().fontGroup =
+        gfxPlatform::GetPlatform()->CreateFontGroup(fontStyle->mFont.name,
+                                                    &style,
+                                                    presShell->GetPresContext()->GetUserFontSet());
     NS_ASSERTION(CurrentState().fontGroup, "Could not get font group");
     CurrentState().font = font;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsCanvasRenderingContext2D::GetFont(nsAString& font)
 {
--- a/gfx/src/thebes/nsThebesFontEnumerator.cpp
+++ b/gfx/src/thebes/nsThebesFontEnumerator.cpp
@@ -37,16 +37,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsThebesFontEnumerator.h"
 
 #include "nsMemory.h"
 
 #include "gfxPlatform.h"
 #include "nsTArray.h"
+#include "nsIAtom.h"
 
 NS_IMPL_ISUPPORTS1(nsThebesFontEnumerator, nsIFontEnumerator)
 
 nsThebesFontEnumerator::nsThebesFontEnumerator()
 {
 }
 
 NS_IMETHODIMP
@@ -62,30 +63,24 @@ nsThebesFontEnumerator::EnumerateFonts(c
                                        PRUint32 *aCount,
                                        PRUnichar ***aResult)
 {
     NS_ENSURE_ARG_POINTER(aCount);
     NS_ENSURE_ARG_POINTER(aResult);
 
     nsTArray<nsString> fontList;
 
-    nsCAutoString langGroup;
     nsCAutoString generic;
-
-    if (aLangGroup)
-        langGroup.Assign(aLangGroup);
-    else
-        langGroup.SetIsVoid(PR_TRUE);
-
     if (aGeneric)
         generic.Assign(aGeneric);
     else
         generic.SetIsVoid(PR_TRUE);
 
-    nsresult rv = gfxPlatform::GetPlatform()->GetFontList(langGroup, generic, fontList);
+    nsCOMPtr<nsIAtom> langGroupAtom = do_GetAtom(aLangGroup);
+    nsresult rv = gfxPlatform::GetPlatform()->GetFontList(langGroupAtom, generic, fontList);
 
     if (NS_FAILED(rv)) {
         *aCount = 0;
         *aResult = nsnull;
         /* XXX in this case, do we want to return the CSS generics? */
         return NS_OK;
     }
 
--- a/gfx/src/thebes/nsThebesFontMetrics.cpp
+++ b/gfx/src/thebes/nsThebesFontMetrics.cpp
@@ -73,24 +73,19 @@ nsThebesFontMetrics::Init(const nsFont& 
     mLanguage = aLanguage;
     mDeviceContext = (nsThebesDeviceContext*)aContext;
     mP2A = mDeviceContext->AppUnitsPerDevPixel();
     mIsRightToLeft = PR_FALSE;
     mTextRunRTL = PR_FALSE;
 
     gfxFloat size = gfxFloat(aFont.size) / mP2A;
 
-    nsCString language;
-    if (aLanguage) {
-        mLanguage->ToUTF8String(language);
-    }
-
     PRBool printerFont = mDeviceContext->IsPrinterSurface();
     mFontStyle = new gfxFontStyle(aFont.style, aFont.weight, aFont.stretch,
-                                  size, language,
+                                  size, aLanguage,
                                   aFont.sizeAdjust, aFont.systemFont,
                                   aFont.familyNameQuirks,
                                   printerFont);
 
     mFontGroup =
         gfxPlatform::GetPlatform()->CreateFontGroup(aFont.name, mFontStyle, 
                                                     aUserFontSet);
     if (mFontGroup->FontListLength() < 1) 
--- a/gfx/thebes/public/gfxBeOSPlatform.h
+++ b/gfx/thebes/public/gfxBeOSPlatform.h
@@ -53,17 +53,17 @@ public:
         return (gfxBeOSPlatform*) gfxPlatform::GetPlatform();
     }
 
     already_AddRefed<gfxASurface>
         CreateOffscreenSurface(PRUint32 width,
                                PRUint32 height,
                                gfxASurface::gfxImageFormat imageFormat);
 
-    nsresult GetFontList(const nsACString& aLangGroup,
+    nsresult GetFontList(nsIAtom *aLangGroup,
                          const nsACString& aGenericFamily,
                          nsTArray<nsString>& aListOfFonts);
 
     nsresult UpdateFontList();
 
     nsresult ResolveFontName(const nsAString& aFontName,
                              FontResolverCallback aCallback,
                              void *aClosure, PRBool& aAborted);
--- a/gfx/thebes/public/gfxFT2Fonts.h
+++ b/gfx/thebes/public/gfxFT2Fonts.h
@@ -198,21 +198,21 @@ protected: // new functions
     void CreateGlyphRunsFT(gfxTextRun *aTextRun);
     void AddRange(gfxTextRun *aTextRun, gfxFT2Font *font, const PRUnichar *str, PRUint32 offset, PRUint32 len);
 
     static PRBool FontCallback (const nsAString & fontName, 
                                 const nsACString & genericName, 
                                 void *closure);
     PRBool mEnableKerning;
 
-    void GetPrefFonts(const char *aLangGroup,
+    void GetPrefFonts(nsIAtom *aLangGroup,
                       nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList);
     void GetCJKPrefFonts(nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList);
     void FamilyListToArrayList(const nsString& aFamilies,
-                               const nsCString& aLangGroup,
+                               nsIAtom *aLangGroup,
                                nsTArray<nsRefPtr<gfxFontEntry> > *aFontEntryList);
     already_AddRefed<gfxFT2Font> WhichFontSupportsChar(const nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList,
                                                        PRUint32 aCh);
     already_AddRefed<gfxFont> WhichPrefFontSupportsChar(PRUint32 aCh);
     already_AddRefed<gfxFont> WhichSystemFontSupportsChar(PRUint32 aCh);
 
     nsTArray<gfxTextRange> mRanges;
     nsString mString;
--- a/gfx/thebes/public/gfxFont.h
+++ b/gfx/thebes/public/gfxFont.h
@@ -49,24 +49,24 @@
 #include "nsTArray.h"
 #include "nsTHashtable.h"
 #include "nsHashKeys.h"
 #include "gfxSkipChars.h"
 #include "gfxRect.h"
 #include "nsExpirationTracker.h"
 #include "gfxFontConstants.h"
 #include "gfxPlatform.h"
+#include "nsIAtom.h"
 
 #ifdef DEBUG
 #include <stdio.h>
 #endif
 
 class gfxContext;
 class gfxTextRun;
-class nsIAtom;
 class gfxFont;
 class gfxFontFamily;
 class gfxFontGroup;
 class gfxUserFontSet;
 class gfxUserFontData;
 
 class nsILanguageAtomService;
 
@@ -79,17 +79,17 @@ class nsILanguageAtomService;
 #define FONT_WEIGHT_NORMAL             NS_FONT_WEIGHT_NORMAL
 #define FONT_WEIGHT_BOLD               NS_FONT_WEIGHT_BOLD
 
 #define FONT_MAX_SIZE                  2000.0
 
 struct THEBES_API gfxFontStyle {
     gfxFontStyle();
     gfxFontStyle(PRUint8 aStyle, PRUint16 aWeight, PRInt16 aStretch,
-                 gfxFloat aSize, const nsACString& aLanguage,
+                 gfxFloat aSize, nsIAtom *aLanguage,
                  float aSizeAdjust, PRPackedBool aSystemFont,
                  PRPackedBool aFamilyNameQuirks,
                  PRPackedBool aPrinterFont);
     gfxFontStyle(const gfxFontStyle& aStyle);
 
     // The style of font (normal, italic, oblique)
     PRUint8 style : 7;
 
@@ -115,17 +115,17 @@ struct THEBES_API gfxFontStyle {
     // The stretch of the font (the sum of various NS_FONT_STRETCH_*
     // constants; see gfxFontConstants.h).
     PRInt16 stretch;
 
     // The logical size of the font, in pixels
     gfxFloat size;
 
     // the language (may be an internal langGroup code rather than an actual lang)
-    nsCString language;
+    nsIAtom *language;
 
     // The aspect-value (ie., the ratio actualsize:actualxheight) that any
     // actual physical font created from this font structure must have when
     // rendering or measuring a string. A value of 0 means no adjustment
     // needs to be done.
     float sizeAdjust;
 
     // Return the final adjusted font size for the given aspect ratio.
@@ -134,31 +134,31 @@ struct THEBES_API gfxFontStyle {
         NS_ASSERTION(sizeAdjust != 0.0, "Not meant to be called when sizeAdjust = 0");
         gfxFloat adjustedSize = PR_MAX(NS_round(size*(sizeAdjust/aspect)), 1.0);
         return PR_MIN(adjustedSize, FONT_MAX_SIZE);
     }
 
     PLDHashNumber Hash() const {
         return ((style + (systemFont << 7) + (familyNameQuirks << 8) +
             (weight << 9)) + PRUint32(size*1000) + PRUint32(sizeAdjust*1000)) ^
-            HashString(language);
+            nsISupportsHashKey::HashKey(language);
     }
 
     void ComputeWeightAndOffset(PRInt8 *outBaseWeight,
                                 PRInt8 *outOffset) const;
 
     PRBool Equals(const gfxFontStyle& other) const {
         return (size == other.size) &&
             (style == other.style) &&
             (systemFont == other.systemFont) &&
             (printerFont == other.printerFont) &&
             (familyNameQuirks == other.familyNameQuirks) &&
             (weight == other.weight) &&
             (stretch == other.stretch) &&
-            (language.Equals(other.language)) &&
+            (language == other.language) &&
             (sizeAdjust == other.sizeAdjust);
     }
 };
 
 class gfxFontEntry {
 public:
     THEBES_INLINE_DECL_REFCOUNTING(gfxFontEntry)
 
@@ -208,17 +208,17 @@ public:
     }
 
     virtual PRBool TestCharacterMap(PRUint32 aCh);
     virtual nsresult ReadCMAP();
 
     virtual PRBool MatchesGenericFamily(const nsACString& aGeneric) const {
         return PR_TRUE;
     }
-    virtual PRBool SupportsLangGroup(const nsACString& aLangGroup) const {
+    virtual PRBool SupportsLangGroup(nsIAtom *aLangGroup) const {
         return PR_TRUE;
     }
 
     void SetFamily(gfxFontFamily* aFamily) {
         mFamily = aFamily;
     }
 
     const nsString& FamilyName();
@@ -1787,17 +1787,17 @@ public:
 
     /* helper function for splitting font families on commas and
      * calling a function for each family to fill the mFonts array
      */
     typedef PRBool (*FontCreationCallback) (const nsAString& aName,
                                             const nsACString& aGenericName,
                                             void *closure);
     PRBool ForEachFont(const nsAString& aFamilies,
-                       const nsACString& aLanguage,
+                       nsIAtom *aLanguage,
                        FontCreationCallback fc,
                        void *closure);
     PRBool ForEachFont(FontCreationCallback fc, void *closure);
 
     /**
      * Check whether a given font (specified by its gfxFontEntry)
      * is already in the fontgroup's list of actual fonts
      */
@@ -1874,17 +1874,17 @@ protected:
      * replaced with preferred fonts.
      *
      * If aResolveFontName is true then fc() is called only for existing fonts
      * and with actual font names.  If false then fc() is called with each
      * family name in aFamilies (after resolving CSS/Gecko generic family names
      * if aResolveGeneric).
      */
     PRBool ForEachFontInternal(const nsAString& aFamilies,
-                               const nsACString& aLanguage,
+                               nsIAtom *aLanguage,
                                PRBool aResolveGeneric,
                                PRBool aResolveFontName,
                                FontCreationCallback fc,
                                void *closure);
 
     static PRBool FontResolverProc(const nsAString& aName, void *aClosure);
 
     static PRBool FindPlatformFont(const nsAString& aName,
--- a/gfx/thebes/public/gfxOS2Platform.h
+++ b/gfx/thebes/public/gfxOS2Platform.h
@@ -57,17 +57,17 @@ public:
     static gfxOS2Platform *GetPlatform() {
         return (gfxOS2Platform*) gfxPlatform::GetPlatform();
     }
 
     already_AddRefed<gfxASurface>
         CreateOffscreenSurface(const gfxIntSize& size,
                                gfxASurface::gfxImageFormat imageFormat);
 
-    nsresult GetFontList(const nsACString& aLangGroup,
+    nsresult GetFontList(nsIAtom *aLangGroup,
                          const nsACString& aGenericFamily,
                          nsTArray<nsString>& aListOfFonts);
     nsresult UpdateFontList();
     nsresult ResolveFontName(const nsAString& aFontName,
                              FontResolverCallback aCallback,
                              void *aClosure, PRBool& aAborted);
     nsresult GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName);
 
--- a/gfx/thebes/public/gfxPangoFonts.h
+++ b/gfx/thebes/public/gfxPangoFonts.h
@@ -145,17 +145,17 @@ protected:
                                   PRUint32 aUTF8HeaderLength);
 #if defined(ENABLE_FAST_PATH_8BIT) || defined(ENABLE_FAST_PATH_ALWAYS)
     PRBool CanTakeFastPath(PRUint32 aFlags);
     nsresult CreateGlyphRunsFast(gfxTextRun *aTextRun,
                                  const gchar *aUTF8, PRUint32 aUTF8Length);
 #endif
 
     void GetFcFamilies(nsTArray<nsString> *aFcFamilyList,
-                       const nsACString& aLanguage);
+                       nsIAtom *aLanguage);
 
     // @param aLang [in] language to use for pref fonts and system font
     //        resolution, or NULL to guess a language from the gfxFontStyle.
     // @param aMatchPattern [out] if non-NULL, will return the pattern used.
     already_AddRefed<gfxFcPangoFontSet>
     MakeFontSet(PangoLanguage *aLang, gfxFloat aSizeAdjustFactor,
                 nsAutoRef<FcPattern> *aMatchPattern = NULL);
 
--- a/gfx/thebes/public/gfxPlatform.h
+++ b/gfx/thebes/public/gfxPlatform.h
@@ -58,16 +58,17 @@ class gfxFont;
 class gfxFontGroup;
 struct gfxFontStyle;
 class gfxUserFontSet;
 class gfxFontEntry;
 class gfxProxyFontEntry;
 class gfxPlatformFontList;
 class gfxTextRun;
 class nsIURI;
+class nsIAtom;
 
 // pref lang id's for font prefs
 // !!! needs to match the list of pref font.default.xx entries listed in all.js !!!
 
 enum eFontPrefLang {
     eFontPrefLang_Western     =  0,
     eFontPrefLang_CentEuro    =  1,
     eFontPrefLang_Japanese    =  2,
@@ -153,17 +154,17 @@ public:
 
     virtual void SetupClusterBoundaries(gfxTextRun *aTextRun, const PRUnichar *aString);
 
     /**
      * Fill aListOfFonts with the results of querying the list of font names
      * that correspond to the given language group or generic font family
      * (or both, or neither).
      */
-    virtual nsresult GetFontList(const nsACString& aLangGroup,
+    virtual nsresult GetFontList(nsIAtom *aLangGroup,
                                  const nsACString& aGenericFamily,
                                  nsTArray<nsString>& aListOfFonts);
 
     /**
      * Rebuilds the any cached system font lists
      */
     virtual nsresult UpdateFontList();
 
@@ -227,35 +228,38 @@ public:
     /**
      * Whether to allow downloadable fonts via @font-face rules
      */
     virtual PRBool DownloadableFontsEnabled();
 
     // check whether format is supported on a platform or not (if unclear, returns true)
     virtual PRBool IsFontFormatSupported(nsIURI *aFontURI, PRUint32 aFormatFlags) { return PR_FALSE; }
 
-    void GetPrefFonts(const char *aLanguage, nsString& array, PRBool aAppendUnicode = PR_TRUE);
+    void GetPrefFonts(nsIAtom *aLanguage, nsString& array, PRBool aAppendUnicode = PR_TRUE);
 
     // in some situations, need to make decisions about ambiguous characters, may need to look at multiple pref langs
     void GetLangPrefs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, eFontPrefLang aCharLang, eFontPrefLang aPageLang);
     
     /**
      * Iterate over pref fonts given a list of lang groups.  For a single lang
      * group, multiple pref fonts are possible.  If error occurs, returns PR_FALSE,
      * PR_TRUE otherwise.  Callback returns PR_FALSE to abort process.
      */
     typedef PRBool (*PrefFontCallback) (eFontPrefLang aLang, const nsAString& aName,
                                         void *aClosure);
     static PRBool ForEachPrefFont(eFontPrefLang aLangArray[], PRUint32 aLangArrayLen,
                                   PrefFontCallback aCallback,
                                   void *aClosure);
 
-    // convert a lang group string to enum constant (i.e. "zh-TW" ==> eFontPrefLang_ChineseTW)
+    // convert a lang group to enum constant (i.e. "zh-TW" ==> eFontPrefLang_ChineseTW)
     static eFontPrefLang GetFontPrefLangFor(const char* aLang);
 
+    // convert a lang group atom to enum constant
+    static eFontPrefLang GetFontPrefLangFor(nsIAtom *aLang);
+
     // convert a enum constant to lang group string (i.e. eFontPrefLang_ChineseTW ==> "zh-TW")
     static const char* GetPrefLangName(eFontPrefLang aLang);
    
     // map a Unicode range (based on char code) to a font language for Preferences
     static eFontPrefLang GetFontPrefLangFor(PRUint8 aUnicodeRange);
 
     // returns true if a pref lang is CJK
     static PRBool IsLangCJK(eFontPrefLang aLang);
--- a/gfx/thebes/public/gfxPlatformGtk.h
+++ b/gfx/thebes/public/gfxPlatformGtk.h
@@ -68,17 +68,17 @@ public:
 
     static gfxPlatformGtk *GetPlatform() {
         return (gfxPlatformGtk*) gfxPlatform::GetPlatform();
     }
 
     already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
                                                          gfxASurface::gfxImageFormat imageFormat);
 
-    nsresult GetFontList(const nsACString& aLangGroup,
+    nsresult GetFontList(nsIAtom *aLangGroup,
                          const nsACString& aGenericFamily,
                          nsTArray<nsString>& aListOfFonts);
 
     nsresult UpdateFontList();
 
     nsresult ResolveFontName(const nsAString& aFontName,
                              FontResolverCallback aCallback,
                              void *aClosure, PRBool& aAborted);
--- a/gfx/thebes/public/gfxPlatformMac.h
+++ b/gfx/thebes/public/gfxPlatformMac.h
@@ -81,17 +81,17 @@ public:
     virtual gfxPlatformFontList* CreatePlatformFontList();
 
     virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
                                            const PRUint8 *aFontData,
                                            PRUint32 aLength);
 
     PRBool IsFontFormatSupported(nsIURI *aFontURI, PRUint32 aFormatFlags);
 
-    nsresult GetFontList(const nsACString& aLangGroup,
+    nsresult GetFontList(nsIAtom *aLangGroup,
                          const nsACString& aGenericFamily,
                          nsTArray<nsString>& aListOfFonts);
     nsresult UpdateFontList();
 
     // Returns the OS X version as returned from Gestalt(gestaltSystemVersion, ...)
     // Ex: Mac OS X 10.4.x ==> 0x104x 
     PRInt32 OSXVersion();
 
--- a/gfx/thebes/public/gfxQtPlatform.h
+++ b/gfx/thebes/public/gfxQtPlatform.h
@@ -68,17 +68,17 @@ public:
 
     static gfxQtPlatform *GetPlatform() {
         return (gfxQtPlatform*) gfxPlatform::GetPlatform();
     }
 
     already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
                                                          gfxASurface::gfxImageFormat imageFormat);
 
-    nsresult GetFontList(const nsACString& aLangGroup,
+    nsresult GetFontList(nsIAtom *aLangGroup,
                          const nsACString& aGenericFamily,
                          nsTArray<nsString>& aListOfFonts);
 
     nsresult UpdateFontList();
 
     nsresult ResolveFontName(const nsAString& aFontName,
                              FontResolverCallback aCallback,
                              void *aClosure, PRBool& aAborted);
--- a/gfx/thebes/public/gfxWindowsFonts.h
+++ b/gfx/thebes/public/gfxWindowsFonts.h
@@ -150,17 +150,17 @@ public:
 
     const nsACString& GetGenericFamily() const {
         return mGenericFamily;
     }
 
     void GroupFamilyListToArrayList(nsTArray<nsRefPtr<gfxFontEntry> > *list,
                                     nsTArray<PRPackedBool> *aNeedsBold);
     void FamilyListToArrayList(const nsString& aFamilies,
-                               const nsCString& aLangGroup,
+                               nsIAtom *aLangGroup,
                                nsTArray<nsRefPtr<gfxFontEntry> > *list);
 
     virtual void UpdateFontList();
     virtual gfxFloat GetUnderlineOffset();
 
     gfxWindowsFont* GetFontAt(PRInt32 aFontIndex) {
         // If it turns out to be hard for all clients that cache font
         // groups to call UpdateFontList at appropriate times, we could
@@ -179,17 +179,17 @@ protected:
     void InitTextRunGDI(gfxContext *aContext, gfxTextRun *aRun, const PRUnichar *aString, PRUint32 aLength);
 
     void InitTextRunUniscribe(gfxContext *aContext, gfxTextRun *aRun, const PRUnichar *aString, PRUint32 aLength);
 
     already_AddRefed<gfxFont> WhichPrefFontSupportsChar(PRUint32 aCh);
     already_AddRefed<gfxFont> WhichSystemFontSupportsChar(PRUint32 aCh);
 
     already_AddRefed<gfxWindowsFont> WhichFontSupportsChar(const nsTArray<nsRefPtr<gfxFontEntry> >& fonts, PRUint32 ch);
-    void GetPrefFonts(const char *aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& array);
+    void GetPrefFonts(nsIAtom *aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& array);
     void GetCJKPrefFonts(nsTArray<nsRefPtr<gfxFontEntry> >& array);
 
     static PRBool FindWindowsFont(const nsAString& aName,
                                   const nsACString& aGenericName,
                                   void *closure);
 
     PRBool HasFont(gfxFontEntry *aFontEntry);
 
--- a/gfx/thebes/public/gfxWindowsPlatform.h
+++ b/gfx/thebes/public/gfxWindowsPlatform.h
@@ -95,17 +95,17 @@ public:
 
         /* max */
         RENDER_MODE_MAX
     };
 
     RenderMode GetRenderMode() { return mRenderMode; }
     void SetRenderMode(RenderMode rmode) { mRenderMode = rmode; }
 
-    nsresult GetFontList(const nsACString& aLangGroup,
+    nsresult GetFontList(nsIAtom *aLangGroup,
                          const nsACString& aGenericFamily,
                          nsTArray<nsString>& aListOfFonts);
 
     nsresult UpdateFontList();
 
     nsresult ResolveFontName(const nsAString& aFontName,
                              FontResolverCallback aCallback,
                              void *aClosure, PRBool& aAborted);
--- a/gfx/thebes/src/Makefile.in
+++ b/gfx/thebes/src/Makefile.in
@@ -17,16 +17,17 @@ CPPSRCS	= \
 	gfxAlphaRecovery.cpp \
 	gfxBlur.cpp \
 	gfxContext.cpp \
 	gfxImageSurface.cpp \
 	gfxFont.cpp \
 	gfxFontMissingGlyphs.cpp \
 	gfxFontTest.cpp \
 	gfxFontUtils.cpp \
+	gfxAtoms.cpp \
 	gfxMatrix.cpp \
 	gfxPath.cpp \
 	gfxPattern.cpp \
 	gfxPlatform.cpp \
 	gfxPlatformFontList.cpp \
 	gfxRect.cpp \
 	gfxSkipChars.cpp \
 	gfxTextRunCache.cpp \
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/src/gfxAtomList.h
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Foundation code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/******
+
+  This file contains the list of all gfx language nsIAtoms and their values
+  
+  It is designed to be used as inline input to gfxAtoms.cpp *only*
+  through the magic of C preprocessing.
+
+  All entires must be enclosed in the macro GFX_ATOM which will have cruel
+  and unusual things done to it
+
+  It is recommended (but not strictly necessary) to keep all entries
+  in alphabetical order
+
+  The first argument to GFX_ATOM is the C++ identifier of the atom
+  The second argument is the string value of the atom
+
+ ******/
+
+// language codes specifically referenced in the gfx code
+GFX_ATOM(en, "en")
+GFX_ATOM(x_unicode, "x-unicode")
+GFX_ATOM(x_western, "x-western")
+
+GFX_ATOM(ja, "ja")
+GFX_ATOM(ko, "ko")
+GFX_ATOM(zh_cn, "zh-cn")
+GFX_ATOM(zh_hk, "zh-hk")
+GFX_ATOM(zh_tw, "zh-tw")
+
+// additional codes used in nsUnicodeRange.cpp
+GFX_ATOM(x_cyrillic, "x-cyrillic")
+GFX_ATOM(el, "el")
+GFX_ATOM(tr, "tr")
+GFX_ATOM(he, "he")
+GFX_ATOM(ar, "ar")
+GFX_ATOM(x_baltic, "x-baltic")
+GFX_ATOM(th, "th")
+GFX_ATOM(x_devanagari, "x-devanagari")
+GFX_ATOM(x_tamil, "x-tamil")
+GFX_ATOM(x_armn, "x-armn")
+GFX_ATOM(x_beng, "x-beng")
+GFX_ATOM(x_cans, "x-cans")
+GFX_ATOM(x_ethi, "x-ethi")
+GFX_ATOM(x_geor, "x-geor")
+GFX_ATOM(x_gujr, "x-gujr")
+GFX_ATOM(x_guru, "x-guru")
+GFX_ATOM(x_khmr, "x-khmr")
+GFX_ATOM(x_mlym, "x-mlym")
+GFX_ATOM(x_orya, "x-orya")
+GFX_ATOM(x_telu, "x-telu")
+GFX_ATOM(x_knda, "x-knda")
+GFX_ATOM(x_sinh, "x-sinh")
+
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/src/gfxAtoms.cpp
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Foundation code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "gfxAtoms.h"
+#include "nsStaticAtom.h"
+#include "nsMemory.h"
+
+#define GFX_ATOM(_name, _value) nsIAtom* gfxAtoms::_name = 0;
+#include "gfxAtomList.h"
+#undef GFX_ATOM
+
+static const nsStaticAtom atoms[] = {
+#define GFX_ATOM(_name, _value) { _value, &gfxAtoms::_name },
+#include "gfxAtomList.h"
+#undef GFX_ATOM
+};
+
+void gfxAtoms::RegisterAtoms()
+{
+    NS_RegisterStaticAtoms(atoms, NS_ARRAY_LENGTH(atoms));
+}
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/src/gfxAtoms.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Foundation code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef GFX_ATOMS_H
+#define GFX_ATOMS_H
+
+#include "prtypes.h"
+#include "nsIAtom.h"
+
+class gfxAtoms {
+public:
+    static void RegisterAtoms();
+
+    /* Declare all atoms
+
+       The atom names and values are stored in gfxAtomList.h and
+       are brought to you by the magic of C preprocessing
+
+       Add new atoms to gfxAtomList.h and all support logic will be auto-generated
+     */
+#define GFX_ATOM(_name, _value) static nsIAtom* _name;
+#include "gfxAtomList.h"
+#undef GFX_ATOM
+};
+
+#endif /* GFX_ATOMS_H */
--- a/gfx/thebes/src/gfxBeOSPlatform.cpp
+++ b/gfx/thebes/src/gfxBeOSPlatform.cpp
@@ -83,17 +83,17 @@ gfxBeOSPlatform::CreateOffscreenSurface 
                                         imageFormat == gfxASurface::ImageFormatARGB32 ? B_RGBA32 : B_RGB32);
     }
 
     NS_ADDREF(newSurface);
     return newSurface;
 }
 
 nsresult
-gfxBeOSPlatform::GetFontList(const nsACString& aLangGroup,
+gfxBeOSPlatform::GetFontList(nsIAtom *aLangGroup,
                              const nsACString& aGenericFamily,
                              nsTArray<nsString>& aListOfFonts)
 {
     return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
                                          aListOfFonts);
 }
 
 nsresult
--- a/gfx/thebes/src/gfxFT2Fonts.cpp
+++ b/gfx/thebes/src/gfxFT2Fonts.cpp
@@ -53,41 +53,36 @@
 #include "gfxFT2Fonts.h"
 #include "gfxFT2FontBase.h"
 #include "gfxFT2Utils.h"
 #include <locale.h>
 #include "cairo-ft.h"
 #include FT_TRUETYPE_TAGS_H
 #include FT_TRUETYPE_TABLES_H
 #include "gfxFontUtils.h"
+#include "gfxAtoms.h"
 #include "nsTArray.h"
 #include "nsUnicodeRange.h"
 #include "nsIPrefService.h"
 #include "nsIPrefLocalizedString.h"
 #include "nsServiceManagerUtils.h"
 #include "nsCRT.h"
 
 #include "prlog.h"
 #include "prinit.h"
 static PRLogModuleInfo *gFontLog = PR_NewLogModule("ft2fonts");
 
 static const char *sCJKLangGroup[] = {
     "ja",
     "ko",
-    "zh-CN",
-    "zh-HK",
-    "zh-TW"
+    "zh-cn",
+    "zh-hk",
+    "zh-tw"
 };
-
 #define COUNT_OF_CJK_LANG_GROUP 5
-#define CJK_LANG_JA    sCJKLangGroup[0]
-#define CJK_LANG_KO    sCJKLangGroup[1]
-#define CJK_LANG_ZH_CN sCJKLangGroup[2]
-#define CJK_LANG_ZH_HK sCJKLangGroup[3]
-#define CJK_LANG_ZH_TW sCJKLangGroup[4]
 
 // rounding and truncation functions for a Freetype floating point number
 // (FT26Dot6) stored in a 32bit integer with high 26 bits for the integer
 // part and low 6 bits for the fractional part.
 #define MOZ_FT_ROUND(x) (((x) + 32) & ~63) // 63 = 2^6 - 1
 #define MOZ_FT_TRUNC(x) ((x) >> 6)
 #define CONVERT_DESIGN_UNITS_TO_PIXELS(v, s) \
         MOZ_FT_TRUNC(MOZ_FT_ROUND(FT_MulFix((v) , (s))))
@@ -320,28 +315,28 @@ gfxFT2FontGroup::FontCallback(const nsAS
         printf(" - %s\n", NS_ConvertUTF16toUTF8(fontName).get());
 #endif
     }
 
     return PR_TRUE;
 }
 
 gfxFT2FontGroup::gfxFT2FontGroup(const nsAString& families,
-                               const gfxFontStyle *aStyle)
+                                 const gfxFontStyle *aStyle)
     : gfxFontGroup(families, aStyle)
 {
 #ifdef DEBUG_pavlov
     printf("Looking for %s\n", NS_ConvertUTF16toUTF8(families).get());
 #endif
     nsTArray<nsString> familyArray;
     ForEachFont(FontCallback, &familyArray);
 
     if (familyArray.Length() == 0) {
         nsAutoString prefFamilies;
-        gfxToolkitPlatform::GetPlatform()->GetPrefFonts(aStyle->language.get(), prefFamilies, nsnull);
+        gfxToolkitPlatform::GetPlatform()->GetPrefFonts(aStyle->language, prefFamilies, nsnull);
         if (!prefFamilies.IsEmpty()) {
             ForEachFont(prefFamilies, aStyle->language, FontCallback, &familyArray);
         }
     }
     if (familyArray.Length() == 0) {
 #if defined(MOZ_WIDGET_QT) /* FIXME DFB */
         printf("failde to find a font. sadface\n");
         // We want to get rid of this entirely at some point, but first we need real lists of fonts.
@@ -480,48 +475,48 @@ AddFontNameToArray(const nsAString& aNam
             list->AppendElement(aName);
     }
 
     return PR_TRUE;
 }
 
 void
 gfxFT2FontGroup::FamilyListToArrayList(const nsString& aFamilies,
-                                       const nsCString& aLangGroup,
+                                       nsIAtom *aLangGroup,
                                        nsTArray<nsRefPtr<gfxFontEntry> > *aFontEntryList)
 {
     nsAutoTArray<nsString, 15> fonts;
     ForEachFont(aFamilies, aLangGroup, AddFontNameToArray, &fonts);
 
     PRUint32 len = fonts.Length();
     for (PRUint32 i = 0; i < len; ++i) {
         const nsString& str = fonts[i];
         nsRefPtr<gfxFontEntry> fe = (gfxToolkitPlatform::GetPlatform()->FindFontEntry(str, mStyle));
         aFontEntryList->AppendElement(fe);
     }
 }
 
-void gfxFT2FontGroup::GetPrefFonts(const char *aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList) {
+void gfxFT2FontGroup::GetPrefFonts(nsIAtom *aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList)
+{
     NS_ASSERTION(aLangGroup, "aLangGroup is null");
     gfxToolkitPlatform *platform = gfxToolkitPlatform::GetPlatform();
     nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
-    /* this lookup has to depend on weight and style */
-    nsCAutoString key(aLangGroup);
+    nsCAutoString key;
+    aLangGroup->ToUTF8String(key);
     key.Append("-");
     key.AppendInt(GetStyle()->style);
     key.Append("-");
     key.AppendInt(GetStyle()->weight);
     if (!platform->GetPrefFontEntries(key, &fonts)) {
         nsString fontString;
         platform->GetPrefFonts(aLangGroup, fontString);
         if (fontString.IsEmpty())
             return;
 
-        FamilyListToArrayList(fontString, nsDependentCString(aLangGroup),
-                                      &fonts);
+        FamilyListToArrayList(fontString, aLangGroup, &fonts);
 
         platform->SetPrefFontEntries(key, fonts);
     }
     aFontEntryList.AppendElements(fonts);
 }
 
 static PRInt32 GetCJKLangGroupIndex(const char *aLangGroup) {
     PRInt32 i;
@@ -574,54 +569,56 @@ void gfxFT2FontGroup::GetCJKPrefFonts(ns
                 if (p == p_end)
                     break;
                 const char *start = p;
                 while (++p != p_end && *p != kComma)
                     /* nothing */ ;
                 nsCAutoString lang(Substring(start, p));
                 lang.CompressWhitespace(PR_FALSE, PR_TRUE);
                 PRInt32 index = GetCJKLangGroupIndex(lang.get());
-                if (index >= 0)
-                    GetPrefFonts(sCJKLangGroup[index], aFontEntryList);
+                if (index >= 0) {
+                    nsCOMPtr<nsIAtom> atom = do_GetAtom(sCJKLangGroup[index]);
+                    GetPrefFonts(atom, aFontEntryList);
+                }
                 p++;
             }
         }
 
         // Add the system locale
 #ifdef XP_WIN
         switch (::GetACP()) {
-            case 932: GetPrefFonts(CJK_LANG_JA, aFontEntryList); break;
-            case 936: GetPrefFonts(CJK_LANG_ZH_CN, aFontEntryList); break;
-            case 949: GetPrefFonts(CJK_LANG_KO, aFontEntryList); break;
-            // XXX Don't we need to append CJK_LANG_ZH_HK if the codepage is 950?
-            case 950: GetPrefFonts(CJK_LANG_ZH_TW, aFontEntryList); break;
+            case 932: GetPrefFonts(gfxAtoms::ja, aFontEntryList); break;
+            case 936: GetPrefFonts(gfxAtoms::zh_cn, aFontEntryList); break;
+            case 949: GetPrefFonts(gfxAtoms::ko, aFontEntryList); break;
+            // XXX Don't we need to append gfxAtoms::zh_hk if the codepage is 950?
+            case 950: GetPrefFonts(gfxAtoms::zh_tw, aFontEntryList); break;
         }
 #else
         const char *ctype = setlocale(LC_CTYPE, NULL);
         if (ctype) {
             if (!PL_strncasecmp(ctype, "ja", 2)) {
-                GetPrefFonts(CJK_LANG_JA, aFontEntryList);
+                GetPrefFonts(gfxAtoms::ja, aFontEntryList);
             } else if (!PL_strncasecmp(ctype, "zh_cn", 5)) {
-                GetPrefFonts(CJK_LANG_ZH_CN, aFontEntryList);
+                GetPrefFonts(gfxAtoms::zh_cn, aFontEntryList);
             } else if (!PL_strncasecmp(ctype, "zh_hk", 5)) {
-                GetPrefFonts(CJK_LANG_ZH_HK, aFontEntryList);
+                GetPrefFonts(gfxAtoms::zh_hk, aFontEntryList);
             } else if (!PL_strncasecmp(ctype, "zh_tw", 5)) {
-                GetPrefFonts(CJK_LANG_ZH_TW, aFontEntryList);
+                GetPrefFonts(gfxAtoms::zh_tw, aFontEntryList);
             } else if (!PL_strncasecmp(ctype, "ko", 2)) {
-                GetPrefFonts(CJK_LANG_KO, aFontEntryList);
+                GetPrefFonts(gfxAtoms::ko, aFontEntryList);
             }
         }
 #endif
 
         // last resort...
-        GetPrefFonts(CJK_LANG_JA, aFontEntryList);
-        GetPrefFonts(CJK_LANG_KO, aFontEntryList);
-        GetPrefFonts(CJK_LANG_ZH_CN, aFontEntryList);
-        GetPrefFonts(CJK_LANG_ZH_HK, aFontEntryList);
-        GetPrefFonts(CJK_LANG_ZH_TW, aFontEntryList);
+        GetPrefFonts(gfxAtoms::ja, aFontEntryList);
+        GetPrefFonts(gfxAtoms::ko, aFontEntryList);
+        GetPrefFonts(gfxAtoms::zh_cn, aFontEntryList);
+        GetPrefFonts(gfxAtoms::zh_hk, aFontEntryList);
+        GetPrefFonts(gfxAtoms::zh_tw, aFontEntryList);
 
         platform->SetPrefFontEntries(key, aFontEntryList);
     }
 }
 
 already_AddRefed<gfxFT2Font>
 gfxFT2FontGroup::WhichFontSupportsChar(const nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList, PRUint32 aCh)
 {
@@ -641,37 +638,40 @@ gfxFT2FontGroup::WhichPrefFontSupportsCh
 {
     if (aCh > 0xFFFF)
         return nsnull;
 
     nsRefPtr<gfxFT2Font> selectedFont;
 
     // check out the style's language
     nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
-    GetPrefFonts(mStyle.language.get(), fonts);
+    GetPrefFonts(mStyle.language, fonts);
     selectedFont = WhichFontSupportsChar(fonts, aCh);
 
     // otherwise search prefs
     if (!selectedFont) {
         PRUint32 unicodeRange = FindCharUnicodeRange(aCh);
 
         /* special case CJK */
         if (unicodeRange == kRangeSetCJK) {
             if (PR_LOG_TEST(gFontLog, PR_LOG_DEBUG)) {
                 PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: CJK"));
             }
 
             nsAutoTArray<nsRefPtr<gfxFontEntry>, 15> fonts;
             GetCJKPrefFonts(fonts);
             selectedFont = WhichFontSupportsChar(fonts, aCh);
         } else {
-            const char *langGroup = LangGroupFromUnicodeRange(unicodeRange);
+            nsIAtom *langGroup = LangGroupFromUnicodeRange(unicodeRange);
             if (langGroup) {
-                PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: %s", langGroup));
-
+#ifdef PR_LOGGING
+                const char *langGroupStr;
+                langGroup->GetUTF8String(&langGroupStr);
+                PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: %s", langGroupStr));
+#endif
                 nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
                 GetPrefFonts(langGroup, fonts);
                 selectedFont = WhichFontSupportsChar(fonts, aCh);
             }
         }
     }
 
     if (selectedFont) {
--- a/gfx/thebes/src/gfxFont.cpp
+++ b/gfx/thebes/src/gfxFont.cpp
@@ -41,16 +41,17 @@
 #include "nsIPrefService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsReadableUtils.h"
 #include "nsExpirationTracker.h"
 #include "nsILanguageAtomService.h"
 
 #include "gfxFont.h"
 #include "gfxPlatform.h"
+#include "gfxAtoms.h"
 
 #include "prtypes.h"
 #include "gfxTypes.h"
 #include "gfxContext.h"
 #include "gfxFontMissingGlyphs.h"
 #include "gfxUserFontSet.h"
 #include "gfxPlatformFontList.h"
 #include "nsMathUtils.h"
@@ -1413,17 +1414,17 @@ gfxGlyphExtents::SetTightGlyphExtents(PR
 }
 
 gfxFontGroup::gfxFontGroup(const nsAString& aFamilies, const gfxFontStyle *aStyle, gfxUserFontSet *aUserFontSet)
     : mFamilies(aFamilies), mStyle(*aStyle), mUnderlineOffset(UNDERLINE_OFFSET_NOT_SET)
 {
     mUserFontSet = nsnull;
     SetUserFontSet(aUserFontSet);
 
-    mPageLang = gfxPlatform::GetFontPrefLangFor(mStyle.language.get());
+    mPageLang = gfxPlatform::GetFontPrefLangFor(mStyle.language);
     BuildFontList();
 }
 
 void
 gfxFontGroup::BuildFontList()
 {
 // "#if" to be removed once all platforms are moved to gfxPlatformFontList interface
 // and subclasses of gfxFontGroup eliminated
@@ -1532,17 +1533,17 @@ gfxFontGroup::ForEachFont(FontCreationCa
                           void *closure)
 {
     return ForEachFontInternal(mFamilies, mStyle.language,
                                PR_TRUE, PR_TRUE, fc, closure);
 }
 
 PRBool
 gfxFontGroup::ForEachFont(const nsAString& aFamilies,
-                          const nsACString& aLanguage,
+                          nsIAtom *aLanguage,
                           FontCreationCallback fc,
                           void *closure)
 {
     return ForEachFontInternal(aFamilies, aLanguage,
                                PR_FALSE, PR_TRUE, fc, closure);
 }
 
 struct ResolveData {
@@ -1555,42 +1556,41 @@ struct ResolveData {
     }
     gfxFontGroup::FontCreationCallback mCallback;
     nsCString mGenericFamily;
     void *mClosure;
 };
 
 PRBool
 gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
-                                  const nsACString& aLanguage,
+                                  nsIAtom *aLanguage,
                                   PRBool aResolveGeneric,
                                   PRBool aResolveFontName,
                                   FontCreationCallback fc,
                                   void *closure)
 {
     const PRUnichar kSingleQuote  = PRUnichar('\'');
     const PRUnichar kDoubleQuote  = PRUnichar('\"');
     const PRUnichar kComma        = PRUnichar(',');
 
-    nsCAutoString langGroup;
-    if (!gLangService) {
-        CallGetService(NS_LANGUAGEATOMSERVICE_CONTRACTID, &gLangService);
-    }
-    if (gLangService) {
-        nsresult rv;
-        // temp, until we pass aLanguage as an Atom
-        nsCOMPtr<nsIAtom> lang = do_GetAtom(mStyle.language);
-        nsIAtom *group = gLangService->GetLanguageGroup(lang, &rv);
-        if (NS_SUCCEEDED(rv) && group) {
-            group->ToUTF8String(langGroup);
+    nsIAtom *groupAtom = nsnull;
+    nsCAutoString groupString;
+    if (aLanguage) {
+        if (!gLangService) {
+            CallGetService(NS_LANGUAGEATOMSERVICE_CONTRACTID, &gLangService);
+        }
+        if (gLangService) {
+            nsresult rv;
+            groupAtom = gLangService->GetLanguageGroup(aLanguage, &rv);
         }
     }
-    if (langGroup.IsEmpty()) {
-        langGroup.Assign("x-unicode"); // XXX or should use "x-user-def"?
+    if (!groupAtom) {
+        groupAtom = gfxAtoms::x_unicode;
     }
+    groupAtom->ToUTF8String(groupString);
 
     nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
 
     nsPromiseFlatString families(aFamilies);
     const PRUnichar *p, *p_end;
     families.BeginReading(p);
     families.EndReading(p_end);
     nsAutoString family;
@@ -1641,33 +1641,33 @@ gfxFontGroup::ForEachFontInternal(const 
             {
                 generic = PR_TRUE;
 
                 ToLowerCase(NS_LossyConvertUTF16toASCII(family), lcFamily);
 
                 nsCAutoString prefName("font.name.");
                 prefName.Append(lcFamily);
                 prefName.AppendLiteral(".");
-                prefName.Append(langGroup);
+                prefName.Append(groupString);
 
                 // prefs file always uses (must use) UTF-8 so that we can use
                 // |GetCharPref| and treat the result as a UTF-8 string.
                 nsresult rv = prefs->GetCharPref(prefName.get(), getter_Copies(value));
                 if (NS_SUCCEEDED(rv)) {
                     CopyASCIItoUTF16(lcFamily, genericFamily);
                     CopyUTF8toUTF16(value, family);
                 }
             } else {
                 generic = PR_FALSE;
                 genericFamily.SetIsVoid(PR_TRUE);
             }
         }
 
         if (generic) {
-            ForEachFontInternal(family, langGroup, PR_FALSE,
+            ForEachFontInternal(family, groupAtom, PR_FALSE,
                                 aResolveFontName, fc, closure);
         } else if (!family.IsEmpty()) {
             NS_LossyConvertUTF16toASCII gf(genericFamily);
             if (aResolveFontName) {
                 ResolveData data(fc, gf, closure);
                 PRBool aborted = PR_FALSE, needsBold;
                 nsresult rv;
 
@@ -1688,21 +1688,21 @@ gfxFontGroup::ForEachFontInternal(const 
                     return PR_FALSE;
             }
         }
 
         if (generic && aResolveGeneric) {
             nsCAutoString prefName("font.name-list.");
             prefName.Append(lcFamily);
             prefName.AppendLiteral(".");
-            prefName.Append(langGroup);
+            prefName.Append(groupString);
             nsresult rv = prefs->GetCharPref(prefName.get(), getter_Copies(value));
             if (NS_SUCCEEDED(rv)) {
                 ForEachFontInternal(NS_ConvertUTF8toUTF16(value),
-                                    langGroup, PR_FALSE, aResolveFontName,
+                                    groupAtom, PR_FALSE, aResolveFontName,
                                     fc, closure);
             }
         }
 
         ++p; // may advance past p_end
     }
 
     return PR_TRUE;
@@ -2163,22 +2163,22 @@ nsILanguageAtomService* gfxFontGroup::gL
 
 
 #define DEFAULT_PIXEL_FONT_SIZE 16.0f
 
 gfxFontStyle::gfxFontStyle() :
     style(FONT_STYLE_NORMAL), systemFont(PR_TRUE), printerFont(PR_FALSE), 
     familyNameQuirks(PR_FALSE), weight(FONT_WEIGHT_NORMAL),
     stretch(NS_FONT_STRETCH_NORMAL), size(DEFAULT_PIXEL_FONT_SIZE),
-    language(NS_LITERAL_CSTRING("x-western")), sizeAdjust(0.0f)
+    language(gfxAtoms::x_western), sizeAdjust(0.0f)
 {
 }
 
 gfxFontStyle::gfxFontStyle(PRUint8 aStyle, PRUint16 aWeight, PRInt16 aStretch,
-                           gfxFloat aSize, const nsACString& aLanguage,
+                           gfxFloat aSize, nsIAtom *aLanguage,
                            float aSizeAdjust, PRPackedBool aSystemFont,
                            PRPackedBool aFamilyNameQuirks,
                            PRPackedBool aPrinterFont):
     style(aStyle), systemFont(aSystemFont), printerFont(aPrinterFont),
     familyNameQuirks(aFamilyNameQuirks), weight(aWeight), stretch(aStretch),
     size(aSize), language(aLanguage), sizeAdjust(aSizeAdjust)
 {
     if (weight > 900)
@@ -2189,19 +2189,19 @@ gfxFontStyle::gfxFontStyle(PRUint8 aStyl
     if (size >= FONT_MAX_SIZE) {
         size = FONT_MAX_SIZE;
         sizeAdjust = 0.0;
     } else if (size < 0.0) {
         NS_WARNING("negative font size");
         size = 0.0;
     }
 
-    if (language.IsEmpty()) {
-        NS_WARNING("empty language");
-        language.Assign("x-western");
+    if (!language) {
+        NS_WARNING("null language");
+        language = gfxAtoms::x_western;
     }
 }
 
 gfxFontStyle::gfxFontStyle(const gfxFontStyle& aStyle) :
     style(aStyle.style), systemFont(aStyle.systemFont), printerFont(aStyle.printerFont),
     familyNameQuirks(aStyle.familyNameQuirks), weight(aStyle.weight),
     stretch(aStyle.stretch), size(aStyle.size), language(aStyle.language),
     sizeAdjust(aStyle.sizeAdjust)
@@ -3516,15 +3516,17 @@ gfxTextRun::Dump(FILE* aOutput) {
     fputs("\" [", aOutput);
     for (i = 0; i < mGlyphRuns.Length(); ++i) {
         if (i > 0) {
             fputc(',', aOutput);
         }
         gfxFont* font = mGlyphRuns[i].mFont;
         const gfxFontStyle* style = font->GetStyle();
         NS_ConvertUTF16toUTF8 fontName(font->GetName());
+        nsCAutoString lang;
+        style->language->ToUTF8String(lang);
         fprintf(aOutput, "%d: %s %f/%d/%d/%s", mGlyphRuns[i].mCharacterOffset,
                 fontName.get(), style->size,
-                style->weight, style->style, style->language.get());
+                style->weight, style->style, lang.get());
     }
     fputc(']', aOutput);
 }
 #endif
--- a/gfx/thebes/src/gfxFontconfigUtils.cpp
+++ b/gfx/thebes/src/gfxFontconfigUtils.cpp
@@ -270,24 +270,26 @@ gfxFontconfigUtils::gfxFontconfigUtils()
 {
     mFontsByFamily.Init(50);
     mFontsByFullname.Init(50);
     mLangSupportTable.Init(20);
     UpdateFontListInternal();
 }
 
 nsresult
-gfxFontconfigUtils::GetFontList(const nsACString& aLangGroup,
+gfxFontconfigUtils::GetFontList(nsIAtom *aLangGroup,
                                 const nsACString& aGenericFamily,
                                 nsTArray<nsString>& aListOfFonts)
 {
     aListOfFonts.Clear();
 
     nsTArray<nsCString> fonts;
-    nsresult rv = GetFontListInternal(fonts, aLangGroup);
+    nsCString langGroupStr;
+    aLangGroup->ToUTF8String(langGroupStr);
+    nsresult rv = GetFontListInternal(fonts, langGroupStr);
     if (NS_FAILED(rv))
         return rv;
 
     for (PRUint32 i = 0; i < fonts.Length(); ++i) {
         aListOfFonts.AppendElement(NS_ConvertUTF8toUTF16(fonts[i]));
     }
 
     aListOfFonts.Sort();
--- a/gfx/thebes/src/gfxFontconfigUtils.h
+++ b/gfx/thebes/src/gfxFontconfigUtils.h
@@ -98,17 +98,17 @@ public:
     static gfxFontconfigUtils* GetFontconfigUtils() {
         if (!sUtils)
             sUtils = new gfxFontconfigUtils();
         return sUtils;
     }
 
     static void Shutdown();
 
-    nsresult GetFontList(const nsACString& aLangGroup,
+    nsresult GetFontList(nsIAtom *aLangGroup,
                          const nsACString& aGenericFamily,
                          nsTArray<nsString>& aListOfFonts);
 
     nsresult UpdateFontList();
 
     nsresult ResolveFontName(const nsAString& aFontName,
                              gfxPlatform::FontResolverCallback aCallback,
                              void *aClosure, PRBool& aAborted);
--- a/gfx/thebes/src/gfxOS2Platform.cpp
+++ b/gfx/thebes/src/gfxOS2Platform.cpp
@@ -105,26 +105,26 @@ gfxOS2Platform::CreateOffscreenSurface(c
         return nsnull;
     }
 
     NS_IF_ADDREF(newSurface);
     return newSurface;
 }
 
 nsresult
-gfxOS2Platform::GetFontList(const nsACString& aLangGroup,
+gfxOS2Platform::GetFontList(nsIAtom *aLangGroup,
                             const nsACString& aGenericFamily,
                             nsTArray<nsString>& aListOfFonts)
 {
 #ifdef DEBUG_thebes
-    char *langgroup = ToNewCString(aLangGroup),
-         *family = ToNewCString(aGenericFamily);
+    const char *langgroup;
+    aLangGroup->GetUTF8String(&langgroup);
+    char *family = ToNewCString(aGenericFamily);
     printf("gfxOS2Platform::GetFontList(%s, %s, ..)\n",
            langgroup, family);
-    free(langgroup);
     free(family);
 #endif
     return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
                                          aListOfFonts);
 }
 
 nsresult gfxOS2Platform::UpdateFontList()
 {
--- a/gfx/thebes/src/gfxPangoFonts.cpp
+++ b/gfx/thebes/src/gfxPangoFonts.cpp
@@ -55,16 +55,17 @@
 
 #include "gfxContext.h"
 #include "gfxPlatformGtk.h"
 #include "gfxPangoFonts.h"
 #include "gfxFT2FontBase.h"
 #include "gfxFT2Utils.h"
 #include "gfxFontconfigUtils.h"
 #include "gfxUserFontSet.h"
+#include "gfxAtoms.h"
 
 #include <freetype/tttables.h>
 
 #include <cairo.h>
 #include <cairo-ft.h>
 
 #include <fontconfig/fcfreetype.h>
 #include <pango/pango.h>
@@ -92,16 +93,17 @@
 #define IS_EMPTY_GLYPH(g) ((g) == PANGO_GLYPH_EMPTY)
 
 // Same as pango_units_from_double from Pango 1.16 (but not in older versions)
 int moz_pango_units_from_double(double d) {
     return NS_lround(d * FLOAT_PANGO_SCALE);
 }
 
 static PangoLanguage *GuessPangoLanguage(const nsACString& aLangGroup);
+static PangoLanguage *GuessPangoLanguage(nsIAtom *aLangGroup);
 
 static cairo_scaled_font_t *CreateScaledFont(FcPattern *aPattern);
 
 static PangoFontMap *gPangoFontMap;
 static PangoFontMap *GetPangoFontMap();
 static PRBool gUseFontMapProperty;
 
 static FT_Library gFTLibrary;
@@ -1900,17 +1902,17 @@ gfxFontGroup *
 gfxPangoFontGroup::Copy(const gfxFontStyle *aStyle)
 {
     return new gfxPangoFontGroup(mFamilies, aStyle, mUserFontSet);
 }
 
 // An array of family names suitable for fontconfig
 void
 gfxPangoFontGroup::GetFcFamilies(nsTArray<nsString> *aFcFamilyList,
-                                 const nsACString& aLanguage)
+                                 nsIAtom *aLanguage)
 {
     FamilyCallbackData data(aFcFamilyList, mUserFontSet);
     // Leave non-existing fonts in the list so that fontconfig can get the
     // best match.
     ForEachFontInternal(mFamilies, aLanguage, PR_TRUE, PR_FALSE,
                         FamilyCallback, &data);
 }
 
@@ -1957,34 +1959,29 @@ gfxPangoFontGroup::UpdateFontList()
 }
 
 already_AddRefed<gfxFcPangoFontSet>
 gfxPangoFontGroup::MakeFontSet(PangoLanguage *aLang, gfxFloat aSizeAdjustFactor,
                                nsAutoRef<FcPattern> *aMatchPattern)
 {
     const char *lang = pango_language_to_string(aLang);
 
-    const char *langGroup = nsnull;
+    nsIAtom *langGroup = nsnull;
     if (aLang != mPangoLanguage) {
         // Set up langGroup for Mozilla's font prefs.
         if (!gLangService) {
             CallGetService(NS_LANGUAGEATOMSERVICE_CONTRACTID, &gLangService);
         }
         if (gLangService) {
-            nsIAtom *atom =
-                gLangService->LookupLanguage(NS_ConvertUTF8toUTF16(lang));
-            if (atom) {
-                atom->GetUTF8String(&langGroup);
-            }
+            langGroup = gLangService->LookupLanguage(NS_ConvertUTF8toUTF16(lang));
         }
     }
 
     nsAutoTArray<nsString, 20> fcFamilyList;
-    GetFcFamilies(&fcFamilyList,
-                  langGroup ? nsDependentCString(langGroup) : mStyle.language);
+    GetFcFamilies(&fcFamilyList, langGroup ? langGroup : mStyle.language);
 
     // To consider: A fontset cache here could be helpful.
 
     // Get a pattern suitable for matching.
     nsAutoRef<FcPattern> pattern
         (gfxFontconfigUtils::NewPattern(fcFamilyList, mStyle, lang));
 
     PrepareSortPattern(pattern, mStyle.size, aSizeAdjustFactor, mStyle.printerFont);
@@ -2203,17 +2200,17 @@ gfxFcFont::GetOrMakeFont(FcPattern *aPat
         // Shouldn't actually need to take too much care about the correct
         // name or style, as size is the only thing expected to be important.
         PRUint8 style = gfxFontconfigUtils::GetThebesStyle(aPattern);
         PRUint16 weight = gfxFontconfigUtils::GetThebesWeight(aPattern);
 
         // The LangSet in the FcPattern does not have an order so there is no
         // one particular language to choose and converting the set to a
         // string through FcNameUnparse() is more trouble than it's worth.
-        NS_NAMED_LITERAL_CSTRING(language, "en"); // TODO: get the correct language?
+        nsIAtom *language = gfxAtoms::en; // TODO: get the correct language?
         // FIXME: Pass a real stretch based on aPattern!
         gfxFontStyle fontStyle(style, weight, NS_FONT_STRETCH_NORMAL,
                                size, language, 0.0,
                                PR_TRUE, PR_FALSE, PR_FALSE);
 
         nsRefPtr<gfxFontEntry> fe;
         FcChar8 *fc_file;
         if (FcPatternGetString(aPattern,
@@ -3112,16 +3109,27 @@ GuessPangoLanguage(const nsACString& aLa
     gfxFontconfigUtils::GetSampleLangForGroup(aLangGroup, &lang);
 
     if (lang.IsEmpty())
         return NULL;
 
     return pango_language_from_string(lang.get());
 }
 
+PangoLanguage *
+GuessPangoLanguage(nsIAtom *aLangGroup)
+{
+    if (!aLangGroup)
+        return NULL;
+
+    nsCAutoString lg;
+    aLangGroup->ToUTF8String(lg);
+    return GuessPangoLanguage(lg);
+}
+
 #ifdef MOZ_WIDGET_GTK2
 /***************************************************************************
  *
  * This function must be last in the file because it uses the system cairo
  * library.  Above this point the cairo library used is the tree cairo if
  * MOZ_TREE_CAIRO.
  */
 
--- a/gfx/thebes/src/gfxPlatform.cpp
+++ b/gfx/thebes/src/gfxPlatform.cpp
@@ -46,16 +46,17 @@
 #elif defined(MOZ_WIDGET_QT)
 #include "gfxQtPlatform.h"
 #elif defined(XP_BEOS)
 #include "gfxBeOSPlatform.h"
 #elif defined(XP_OS2)
 #include "gfxOS2Platform.h"
 #endif
 
+#include "gfxAtoms.h"
 #include "gfxPlatformFontList.h"
 #include "gfxContext.h"
 #include "gfxImageSurface.h"
 #include "gfxTextRunCache.h"
 #include "gfxTextRunWordCache.h"
 #include "gfxUserFontSet.h"
 
 #include "nsUnicodeRange.h"
@@ -169,16 +170,19 @@ gfxPlatform::GetPlatform()
 {
     return gPlatform;
 }
 
 nsresult
 gfxPlatform::Init()
 {
     NS_ASSERTION(!gPlatform, "Already started???");
+
+    gfxAtoms::RegisterAtoms();
+
 #if defined(XP_WIN)
     gPlatform = new gfxWindowsPlatform;
 #elif defined(XP_MACOSX)
     gPlatform = new gfxPlatformMac;
 #elif defined(MOZ_WIDGET_GTK2)
     gPlatform = new gfxPlatformGtk;
 #elif defined(MOZ_WIDGET_QT)
     gPlatform = new gfxQtPlatform;
@@ -296,17 +300,17 @@ gfxPlatform::OptimizeImage(gfxImageSurfa
     tmpCtx.Paint();
 
     gfxASurface *ret = optSurface;
     NS_ADDREF(ret);
     return ret;
 }
 
 nsresult
-gfxPlatform::GetFontList(const nsACString& aLangGroup,
+gfxPlatform::GetFontList(nsIAtom *aLangGroup,
                          const nsACString& aGenericFamily,
                          nsTArray<nsString>& aListOfFonts)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 nsresult
 gfxPlatform::UpdateFontList()
@@ -348,38 +352,40 @@ gfxPlatform::MakePlatformFont(const gfxP
     // for freeing it when no longer required.
     if (aFontData) {
         NS_Free((void*)aFontData);
     }
     return nsnull;
 }
 
 static void
-AppendGenericFontFromPref(nsString& aFonts, const char *aLangGroup, const char *aGenericName)
+AppendGenericFontFromPref(nsString& aFonts, nsIAtom *aLangGroup, const char *aGenericName)
 {
     nsresult rv;
 
     nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
     if (!prefs)
         return;
 
-    nsCAutoString prefName;
+    nsCAutoString prefName, langGroupString;
     nsXPIDLCString nameValue, nameListValue;
 
+    aLangGroup->ToUTF8String(langGroupString);
+
     nsCAutoString genericDotLang;
     if (aGenericName) {
         genericDotLang.Assign(aGenericName);
     } else {
         prefName.AssignLiteral("font.default.");
-        prefName.Append(aLangGroup);
+        prefName.Append(langGroupString);
         prefs->GetCharPref(prefName.get(), getter_Copies(genericDotLang));
     }
 
     genericDotLang.AppendLiteral(".");
-    genericDotLang.Append(aLangGroup);
+    genericDotLang.Append(langGroupString);
 
     // fetch font.name.xxx value                   
     prefName.AssignLiteral("font.name.");
     prefName.Append(genericDotLang);
     rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameValue));
     if (NS_SUCCEEDED(rv)) {
         if (!aFonts.IsEmpty())
             aFonts.AppendLiteral(", ");
@@ -393,23 +399,23 @@ AppendGenericFontFromPref(nsString& aFon
     if (NS_SUCCEEDED(rv) && !nameListValue.Equals(nameValue)) {
         if (!aFonts.IsEmpty())
             aFonts.AppendLiteral(", ");
         aFonts.Append(NS_ConvertUTF8toUTF16(nameListValue));
     }
 }
 
 void
-gfxPlatform::GetPrefFonts(const char *aLanguage, nsString& aFonts, PRBool aAppendUnicode)
+gfxPlatform::GetPrefFonts(nsIAtom *aLanguage, nsString& aFonts, PRBool aAppendUnicode)
 {
     aFonts.Truncate();
 
     AppendGenericFontFromPref(aFonts, aLanguage, nsnull);
     if (aAppendUnicode)
-        AppendGenericFontFromPref(aFonts, "x-unicode", nsnull);
+        AppendGenericFontFromPref(aFonts, gfxAtoms::x_unicode, nsnull);
 }
 
 PRBool gfxPlatform::ForEachPrefFont(eFontPrefLang aLangArray[], PRUint32 aLangArrayLen, PrefFontCallback aCallback,
                                     void *aClosure)
 {
     nsresult rv;
 
     nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
@@ -481,16 +487,26 @@ gfxPlatform::GetFontPrefLangFor(const ch
         return eFontPrefLang_Others;
     for (PRUint32 i = 0; i < PRUint32(eFontPrefLang_LangCount); ++i) {
         if (!PL_strcasecmp(gPrefLangNames[i], aLang))
             return eFontPrefLang(i);
     }
     return eFontPrefLang_Others;
 }
 
+eFontPrefLang
+gfxPlatform::GetFontPrefLangFor(nsIAtom *aLang)
+{
+    if (!aLang)
+        return eFontPrefLang_Others;
+    nsCAutoString lang;
+    aLang->ToUTF8String(lang);
+    return GetFontPrefLangFor(lang.get());
+}
+
 const char*
 gfxPlatform::GetPrefLangName(eFontPrefLang aLang)
 {
     if (PRUint32(aLang) < PRUint32(eFontPrefLang_AllCount))
         return gPrefLangNames[PRUint32(aLang)];
     return nsnull;
 }
 
--- a/gfx/thebes/src/gfxPlatformFontList.cpp
+++ b/gfx/thebes/src/gfxPlatformFontList.cpp
@@ -258,22 +258,22 @@ gfxPlatformFontList::ResolveFontName(con
     if (family) {
         aResolvedFontName = family->Name();
         return PR_TRUE;
     }
     return PR_FALSE;
 }
 
 struct FontListData {
-    FontListData(const nsACString& aLangGroup,
+    FontListData(nsIAtom *aLangGroup,
                  const nsACString& aGenericFamily,
                  nsTArray<nsString>& aListOfFonts) :
         mLangGroup(aLangGroup), mGenericFamily(aGenericFamily),
         mListOfFonts(aListOfFonts) {}
-    const nsACString& mLangGroup;
+    nsIAtom *mLangGroup;
     const nsACString& mGenericFamily;
     nsTArray<nsString>& mListOfFonts;
 };
 
 PLDHashOperator PR_CALLBACK
 gfxPlatformFontList::HashEnumFuncForFamilies(nsStringHashKey::KeyType aKey,
                                              nsRefPtr<gfxFontFamily>& aFamilyEntry,
                                              void *aUserArg)
@@ -301,17 +301,17 @@ gfxPlatformFontList::HashEnumFuncForFami
         aFamilyEntry->LocalizedName(localizedFamilyName);
         data->mListOfFonts.AppendElement(localizedFamilyName);
     }
 
     return PL_DHASH_NEXT;
 }
 
 void
-gfxPlatformFontList::GetFontList(const nsACString& aLangGroup,
+gfxPlatformFontList::GetFontList(nsIAtom *aLangGroup,
                                  const nsACString& aGenericFamily,
                                  nsTArray<nsString>& aListOfFonts)
 {
     FontListData data(aLangGroup, aGenericFamily, aListOfFonts);
 
     mFontFamilies.Enumerate(gfxPlatformFontList::HashEnumFuncForFamilies, &data);
 
     aListOfFonts.Sort();
--- a/gfx/thebes/src/gfxPlatformFontList.h
+++ b/gfx/thebes/src/gfxPlatformFontList.h
@@ -69,17 +69,17 @@ public:
         return NS_OK;
     }
 
     static void Shutdown() {
         delete sPlatformFontList;
         sPlatformFontList = nsnull;
     }
 
-    void GetFontList (const nsACString& aLangGroup,
+    void GetFontList (nsIAtom *aLangGroup,
                       const nsACString& aGenericFamily,
                       nsTArray<nsString>& aListOfFonts);
 
     virtual PRBool ResolveFontName(const nsAString& aFontName,
                                    nsAString& aResolvedFontName);
 
     void UpdateFontList() { InitFontList(); }
 
--- a/gfx/thebes/src/gfxPlatformGtk.cpp
+++ b/gfx/thebes/src/gfxPlatformGtk.cpp
@@ -253,17 +253,17 @@ gfxPlatformGtk::CreateOffscreenSurface(c
     }
 
     return newSurface.forget();
 }
 
 #ifdef MOZ_PANGO
 
 nsresult
-gfxPlatformGtk::GetFontList(const nsACString& aLangGroup,
+gfxPlatformGtk::GetFontList(nsIAtom *aLangGroup,
                             const nsACString& aGenericFamily,
                             nsTArray<nsString>& aListOfFonts)
 {
     return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
                                          aListOfFonts);
 }
 
 nsresult
--- a/gfx/thebes/src/gfxPlatformMac.cpp
+++ b/gfx/thebes/src/gfxPlatformMac.cpp
@@ -209,17 +209,17 @@ gfxPlatformMac::IsFontFormatSupported(ns
     }
 
     // no format hint set, need to look at data
     return PR_TRUE;
 }
 
 // these will also move to gfxPlatform once all platforms support the fontlist
 nsresult
-gfxPlatformMac::GetFontList(const nsACString& aLangGroup,
+gfxPlatformMac::GetFontList(nsIAtom *aLangGroup,
                             const nsACString& aGenericFamily,
                             nsTArray<nsString>& aListOfFonts)
 {
     gfxPlatformFontList::PlatformFontList()->GetFontList(aLangGroup, aGenericFamily, aListOfFonts);
     return NS_OK;
 }
 
 nsresult
--- a/gfx/thebes/src/gfxQtPlatform.cpp
+++ b/gfx/thebes/src/gfxQtPlatform.cpp
@@ -219,19 +219,19 @@ gfxQtPlatform::CreateOffscreenSurface(co
         ctx.SetOperator(gfxContext::OPERATOR_CLEAR);
         ctx.Paint();
     }
 
     return newSurface.forget();
 }
 
 nsresult
-gfxQtPlatform::GetFontList(const nsACString& aLangGroup,
-                            const nsACString& aGenericFamily,
-                            nsTArray<nsString>& aListOfFonts)
+gfxQtPlatform::GetFontList(nsIAtom *aLangGroup,
+                           const nsACString& aGenericFamily,
+                           nsTArray<nsString>& aListOfFonts)
 {
     return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
                                          aListOfFonts);
 }
 
 nsresult
 gfxQtPlatform::UpdateFontList()
 {
--- a/gfx/thebes/src/gfxWindowsFonts.cpp
+++ b/gfx/thebes/src/gfxWindowsFonts.cpp
@@ -44,16 +44,17 @@
 #include "prtypes.h"
 #include "gfxTypes.h"
 
 #include "gfxContext.h"
 #include "gfxWindowsFonts.h"
 #include "gfxWindowsSurface.h"
 #include "gfxWindowsPlatform.h"
 #include "gfxGDIFontList.h"
+#include "gfxAtoms.h"
 
 #include "gfxFontTest.h"
 
 #include "cairo.h"
 #include "cairo-win32.h"
 
 #include <windows.h>
 
@@ -553,17 +554,17 @@ gfxWindowsFontGroup::GroupFamilyListToAr
             list->AppendElement(fe);
             aNeedsBold->AppendElement(static_cast<PRPackedBool>(needsBold));
         }
     }
 }
 
 void
 gfxWindowsFontGroup::FamilyListToArrayList(const nsString& aFamilies,
-                                           const nsCString& aLangGroup,
+                                           nsIAtom *aLangGroup,
                                            nsTArray<nsRefPtr<gfxFontEntry> > *list)
 {
     nsAutoTArray<nsString, 15> fonts;
     ForEachFont(aFamilies, aLangGroup, AddFontNameToArray, &fonts);
 
     PRUint32 len = fonts.Length();
     for (PRUint32 i = 0; i < len; ++i) {
         const nsString& str = fonts[i];
@@ -1035,27 +1036,21 @@ static const struct ScriptPropertyEntry 
     { nsnull, nsnull },
     { nsnull, nsnull },
     { "LANG_DIVEHI",     "div" }
 };
 
 static const char *sCJKLangGroup[] = {
     "ja",
     "ko",
-    "zh-CN",
-    "zh-HK",
-    "zh-TW"
+    "zh-cn",
+    "zh-hk",
+    "zh-tw"
 };
-
 #define COUNT_OF_CJK_LANG_GROUP 5
-#define CJK_LANG_JA    sCJKLangGroup[0]
-#define CJK_LANG_KO    sCJKLangGroup[1]
-#define CJK_LANG_ZH_CN sCJKLangGroup[2]
-#define CJK_LANG_ZH_HK sCJKLangGroup[3]
-#define CJK_LANG_ZH_TW sCJKLangGroup[4]
 
 #define STATIC_STRING_LENGTH 100
 
 #define ESTIMATE_MAX_GLYPHS(L) (((3 * (L)) >> 1) + 16)
 
 class UniscribeItem
 {
 public:
@@ -1713,35 +1708,36 @@ gfxWindowsFontGroup::WhichFontSupportsCh
                 continue;
             return font.forget();
         }
     }
     return nsnull;
 }
 
 // this function appends to the array passed in.
-void gfxWindowsFontGroup::GetPrefFonts(const char *aLangGroup,
-                                       nsTArray<nsRefPtr<gfxFontEntry> >& array) {
+void gfxWindowsFontGroup::GetPrefFonts(nsIAtom *aLangGroup,
+                                       nsTArray<nsRefPtr<gfxFontEntry> >& array)
+{
     NS_ASSERTION(aLangGroup, "aLangGroup is null");
     gfxWindowsPlatform *platform = gfxWindowsPlatform::GetPlatform();
     nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
     /* this lookup has to depend on weight and style */
-    nsCAutoString key(aLangGroup);
+    nsCAutoString key;
+    aLangGroup->ToUTF8String(key);
     key.Append("-");
     key.AppendInt(GetStyle()->style);
     key.Append("-");
     key.AppendInt(GetStyle()->weight);
     if (!platform->GetPrefFontEntries(key, &fonts)) {
         nsString fontString;
         platform->GetPrefFonts(aLangGroup, fontString);
         if (fontString.IsEmpty())
             return;
 
-        FamilyListToArrayList(fontString, nsDependentCString(aLangGroup),
-                                      &fonts);
+        FamilyListToArrayList(fontString, aLangGroup, &fonts);
 
         platform->SetPrefFontEntries(key, fonts);
     }
     array.AppendElements(fonts);
 }
 
 static PRInt32 GetCJKLangGroupIndex(const char *aLangGroup) {
     PRInt32 i;
@@ -1794,79 +1790,85 @@ void gfxWindowsFontGroup::GetCJKPrefFont
                 if (p == p_end)
                     break;
                 const char *start = p;
                 while (++p != p_end && *p != kComma)
                     /* nothing */ ;
                 nsCAutoString lang(Substring(start, p));
                 lang.CompressWhitespace(PR_FALSE, PR_TRUE);
                 PRInt32 index = GetCJKLangGroupIndex(lang.get());
-                if (index >= 0)
-                    GetPrefFonts(sCJKLangGroup[index], array);
+                if (index >= 0) {
+                    nsCOMPtr<nsIAtom> atom = do_GetAtom(sCJKLangGroup[index]);
+                    GetPrefFonts(atom, array);
+                }
                 p++;
             }
         }
 
         // Add the system locale
         switch (::GetACP()) {
-            case 932: GetPrefFonts(CJK_LANG_JA, array); break;
-            case 936: GetPrefFonts(CJK_LANG_ZH_CN, array); break;
-            case 949: GetPrefFonts(CJK_LANG_KO, array); break;
-            // XXX Don't we need to append CJK_LANG_ZH_HK if the codepage is 950?
-            case 950: GetPrefFonts(CJK_LANG_ZH_TW, array); break;
+            case 932: GetPrefFonts(gfxAtoms::ja, array); break;
+            case 936: GetPrefFonts(gfxAtoms::zh_cn, array); break;
+            case 949: GetPrefFonts(gfxAtoms::ko, array); break;
+            // XXX Don't we need to append gfxAtoms::zh_hk if the codepage is 950?
+            case 950: GetPrefFonts(gfxAtoms::zh_tw, array); break;
         }
 
         // last resort...
-        GetPrefFonts(CJK_LANG_JA, array);
-        GetPrefFonts(CJK_LANG_KO, array);
-        GetPrefFonts(CJK_LANG_ZH_CN, array);
-        GetPrefFonts(CJK_LANG_ZH_HK, array);
-        GetPrefFonts(CJK_LANG_ZH_TW, array);
+        GetPrefFonts(gfxAtoms::ja, array);
+        GetPrefFonts(gfxAtoms::ko, array);
+        GetPrefFonts(gfxAtoms::zh_cn, array);
+        GetPrefFonts(gfxAtoms::zh_hk, array);
+        GetPrefFonts(gfxAtoms::zh_tw, array);
 
         platform->SetPrefFontEntries(key, array);
     }
 }
 
 already_AddRefed<gfxFont> 
 gfxWindowsFontGroup::WhichPrefFontSupportsChar(PRUint32 aCh)
 {
     nsRefPtr<gfxWindowsFont> selectedFont;
 
     // check out the style's language group
     if (!selectedFont) {
         nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
-        this->GetPrefFonts(mStyle.language.get(), fonts);
+        this->GetPrefFonts(mStyle.language, fonts);
         selectedFont = WhichFontSupportsChar(fonts, aCh);
     }
 
     // otherwise search prefs
     if (!selectedFont) {
         /* first check with the script properties to see what they think */
         if (mItemLangGroup) {
             PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: %s ", mItemLangGroup));
 
             nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
-            this->GetPrefFonts(mItemLangGroup, fonts);
+            nsCOMPtr<nsIAtom> lgAtom = do_GetAtom(mItemLangGroup);
+            this->GetPrefFonts(lgAtom, fonts);
             selectedFont = WhichFontSupportsChar(fonts, aCh);
         } else if (aCh <= 0xFFFF) {
             PRUint32 unicodeRange = FindCharUnicodeRange(aCh);
 
             /* special case CJK */
             if (unicodeRange == kRangeSetCJK) {
                 if (PR_LOG_TEST(gFontLog, PR_LOG_DEBUG))
                     PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: CJK"));
 
                 nsAutoTArray<nsRefPtr<gfxFontEntry>, 15> fonts;
                 this->GetCJKPrefFonts(fonts);
                 selectedFont = WhichFontSupportsChar(fonts, aCh);
             } else {
-                const char *langGroup = LangGroupFromUnicodeRange(unicodeRange);
+                nsIAtom *langGroup = LangGroupFromUnicodeRange(unicodeRange);
                 if (langGroup) {
-                    PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: %s", langGroup));
-
+#ifdef PR_LOGGING
+                    const char *langGroupStr;
+                    langGroup->GetUTF8String(&langGroupStr);
+                    PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: %s", langGroupStr));
+#endif
                     nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
                     this->GetPrefFonts(langGroup, fonts);
                     selectedFont = WhichFontSupportsChar(fonts, aCh);
                 }
             }
         }
     }
 
--- a/gfx/thebes/src/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/src/gfxWindowsPlatform.cpp
@@ -162,17 +162,17 @@ gfxWindowsPlatform::CreateOffscreenSurfa
         surf = new gfxImageSurface(size, imageFormat);
 
     NS_IF_ADDREF(surf);
 
     return surf;
 }
 
 nsresult
-gfxWindowsPlatform::GetFontList(const nsACString& aLangGroup,
+gfxWindowsPlatform::GetFontList(nsIAtom *aLangGroup,
                                 const nsACString& aGenericFamily,
                                 nsTArray<nsString>& aListOfFonts)
 {
     gfxPlatformFontList::PlatformFontList()->GetFontList(aLangGroup, aGenericFamily, aListOfFonts);
 
     return NS_OK;
 }
 
--- a/gfx/thebes/src/nsUnicodeRange.cpp
+++ b/gfx/thebes/src/nsUnicodeRange.cpp
@@ -31,48 +31,50 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsUnicodeRange.h"
+#include "nsIAtom.h"
+#include "gfxAtoms.h"
 
 // This table depends on unicode range definitions. 
 // Each item's index must correspond unicode range value
 // eg. x-cyrillic = LangGroupTable[kRangeCyrillic]
-static const char *gUnicodeRangeToLangGroupTable[] = 
+static nsIAtom **gUnicodeRangeToLangGroupAtomTable[] =
 {
-  "x-cyrillic",
-  "el",
-  "tr",
-  "he",
-  "ar",
-  "x-baltic",
-  "th",
-  "ko",
-  "ja",
-  "zh-CN",
-  "zh-TW",
-  "x-devanagari",
-  "x-tamil",
-  "x-armn",
-  "x-beng",
-  "x-cans",
-  "x-ethi",
-  "x-geor",
-  "x-gujr",
-  "x-guru",
-  "x-khmr",
-  "x-mlym",
-  "x-orya",
-  "x-telu",
-  "x-knda",
-  "x-sinh"
+  &gfxAtoms::x_cyrillic,
+  &gfxAtoms::el,
+  &gfxAtoms::tr,
+  &gfxAtoms::he,
+  &gfxAtoms::ar,
+  &gfxAtoms::x_baltic,
+  &gfxAtoms::th,
+  &gfxAtoms::ko,
+  &gfxAtoms::ja,
+  &gfxAtoms::zh_cn,
+  &gfxAtoms::zh_tw,
+  &gfxAtoms::x_devanagari,
+  &gfxAtoms::x_tamil,
+  &gfxAtoms::x_armn,
+  &gfxAtoms::x_beng,
+  &gfxAtoms::x_cans,
+  &gfxAtoms::x_ethi,
+  &gfxAtoms::x_geor,
+  &gfxAtoms::x_gujr,
+  &gfxAtoms::x_guru,
+  &gfxAtoms::x_khmr,
+  &gfxAtoms::x_mlym,
+  &gfxAtoms::x_orya,
+  &gfxAtoms::x_telu,
+  &gfxAtoms::x_knda,
+  &gfxAtoms::x_sinh
 };
 
 /**********************************************************************
  * Unicode subranges as defined in unicode 3.0
  * x-western, x-central-euro, tr, x-baltic  -> latin 
  *  0000 - 036f 
  *  1e00 - 1eff
  *  2000 - 206f  (general punctuation)
@@ -450,14 +452,16 @@ PRUint32 FindCharUnicodeRange(PRUnichar 
     return range;
   if (range < kRangeTertiaryTable)
     return gUnicodeSubrangeTable[range - kRangeTableBase][(ch & 0x00f0) >> 4];
 
   // Yet another table to look at : U+0700 - U+16FF : 128 code point blocks
   return gUnicodeTertiaryRangeTable[(ch - 0x0700) >> 7];
 }
 
-const char* LangGroupFromUnicodeRange(PRUint8 unicodeRange)
+nsIAtom *LangGroupFromUnicodeRange(PRUint8 unicodeRange)
 {
-  if (kRangeSpecificItemNum > unicodeRange)  
-    return gUnicodeRangeToLangGroupTable[unicodeRange];
+  if (kRangeSpecificItemNum > unicodeRange) {
+    nsIAtom **atom = gUnicodeRangeToLangGroupAtomTable[unicodeRange];
+    return *atom;
+  }
   return nsnull;
 }
--- a/gfx/thebes/src/nsUnicodeRange.h
+++ b/gfx/thebes/src/nsUnicodeRange.h
@@ -32,16 +32,18 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nscore.h"
 
+class nsIAtom;
+
 // The following constants define unicode subranges
 // values below kRangeNum must be continuous so that we can map to 
 // lang group directly.
 // all ranges we care about should be defined under 32, that allows 
 // us to store range using bits of a PRUint32
 
 // frequently used range definitions
 const PRUint8   kRangeCyrillic =    0;
@@ -107,9 +109,9 @@ const PRUint8   kRangeSpecials          
 const PRUint8   kRangeTableBase   = 128;    //values over 127 are reserved for internal use only
 const PRUint8   kRangeTertiaryTable  = 145; // leave room for 16 subtable 
                                             // indices (kRangeTableBase + 1 ..
                                             // kRangeTableBase + 16)
 
 
 
 PRUint32 FindCharUnicodeRange(PRUnichar ch);
-const char* LangGroupFromUnicodeRange(PRUint8 unicodeRange);
+nsIAtom* LangGroupFromUnicodeRange(PRUint8 unicodeRange);
--- a/gfx/thebes/test/gfxFontSelectionTests.h
+++ b/gfx/thebes/test/gfxFontSelectionTests.h
@@ -104,25 +104,25 @@ SetupTests()
 {
     TestEntry *t;
 
     /* some common styles */
     gfxFontStyle style_western_normal_16 (FONT_STYLE_NORMAL,
                                           NS_FONT_STRETCH_NORMAL,
                                           400,
                                           16.0,
-                                          nsDependentCString("en"),
+                                          NS_NewPermanentAtom("en"),
                                           0.0,
                                           PR_FALSE, PR_FALSE, PR_FALSE);
 
     gfxFontStyle style_western_bold_16 (FONT_STYLE_NORMAL,
                                         NS_FONT_STRETCH_NORMAL,
                                         700,
                                         16.0,
-                                        nsDependentCString("en"),
+                                        NS_NewPermanentAtom("en"),
                                         0.0,
                                         PR_FALSE, PR_FALSE, PR_FALSE);
 
     /* Test 0 */
     t = AddTest ("sans-serif",
                  style_western_normal_16,
                  S_ASCII,
                  "ABCD");
--- a/gfx/thebes/test/gfxTextRunPerfTest.cpp
+++ b/gfx/thebes/test/gfxTextRunPerfTest.cpp
@@ -88,17 +88,17 @@ const char* lastFamilies = nsnull;
 
 void
 RunTest (TestEntry *test, gfxContext *ctx) {
     if (!lastFamilies || strcmp(lastFamilies, test->mFamilies)) {
         gfxFontStyle style_western_normal_16 (FONT_STYLE_NORMAL,
                                               NS_FONT_STRETCH_NORMAL,
                                               400,
                                               16.0,
-                                              nsDependentCString("en"),
+                                              NS_NewPermanentAtom("en"),
                                               0.0,
                                               PR_FALSE, PR_FALSE, PR_FALSE);
 
         fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16, nsnull);
     }
 
     nsAutoPtr<gfxTextRun> textRun;
     PRUint32 i;
--- a/gfx/thebes/test/gfxWordCacheTest.cpp
+++ b/gfx/thebes/test/gfxWordCacheTest.cpp
@@ -154,17 +154,17 @@ main (int argc, char **argv) {
    gTextRuns = new FrameTextRunCache();
 
    nsRefPtr<gfxContext> ctx = MakeContext();
    {
        gfxFontStyle style (FONT_STYLE_NORMAL,
                            NS_FONT_STRETCH_NORMAL,
                            139,
                            10.0,
-                           nsDependentCString("en"),
+                           NS_NewPermanentAtom("en"),
                            0.0,
                            PR_FALSE, PR_FALSE, PR_FALSE);
 
        nsRefPtr<gfxFontGroup> fontGroup =
            gfxPlatform::GetPlatform()->CreateFontGroup(NS_LITERAL_STRING("Geneva, MS Sans Serif, Helvetica,serif"), &style, nsnull);
 
        gfxTextRunFactory::Parameters params = {
            ctx, nsnull, nsnull, nsnull, 0, 60
--- a/layout/svg/base/src/nsSVGGlyphFrame.cpp
+++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp
@@ -1330,36 +1330,31 @@ nsSVGGlyphFrame::EnsureTextRun(float *aD
     }
 
     // The context scale is the ratio of the length of the transformed
     // diagonal vector (1,1) to the length of the untransformed diagonal
     // (which is sqrt(2)).
     gfxPoint p = m.Transform(gfxPoint(1, 1)) - m.Transform(gfxPoint(0, 0));
     double contextScale = nsSVGUtils::ComputeNormalizedHypotenuse(p.x, p.y);
 
-    nsCString language;
-    nsIAtom *languageAtom = mStyleContext->GetStyleVisibility()->mLanguage;
-    if (languageAtom) {
-      languageAtom->ToUTF8String(language);
-    }
-
     if (GetStyleSVG()->mTextRendering ==
         NS_STYLE_TEXT_RENDERING_GEOMETRICPRECISION) {
       textRunSize = PRECISE_SIZE;
     } else {
       textRunSize = size*contextScale;
       textRunSize = NS_MAX(textRunSize, double(CLAMP_MIN_SIZE));
       textRunSize = NS_MIN(textRunSize, double(CLAMP_MAX_SIZE));
     }
 
     const nsFont& font = fontData->mFont;
     PRBool printerFont = (presContext->Type() == nsPresContext::eContext_PrintPreview ||
                           presContext->Type() == nsPresContext::eContext_Print);
     gfxFontStyle fontStyle(font.style, font.weight, font.stretch, textRunSize,
-                           language, font.sizeAdjust, font.systemFont,
+                           mStyleContext->GetStyleVisibility()->mLanguage,
+                           font.sizeAdjust, font.systemFont,
                            font.familyNameQuirks,
                            printerFont);
 
     nsRefPtr<gfxFontGroup> fontGroup =
       gfxPlatform::GetPlatform()->CreateFontGroup(font.name, &fontStyle, presContext->GetUserFontSet());
 
     PRUint32 flags = gfxTextRunFactory::TEXT_NEED_BOUNDING_BOX |
       nsLayoutUtils::GetTextRunFlagsForStyle(GetStyleContext(), GetStyleText(), GetStyleFont());