From 110d3b36d601bf9b7cb8d4f7b743ea355bb7398c Mon Sep 17 00:00:00 2001 From: "tor@cs.brown.edu" Date: Mon, 2 Apr 2007 12:06:16 -0700 Subject: [PATCH] Bug 375446 - Create gfxFontGroup factory method. r=vlad --- gfx/src/thebes/nsThebesFontMetrics.cpp | 24 +++--------------------- gfx/thebes/public/gfxOS2Platform.h | 3 +++ gfx/thebes/public/gfxPlatform.h | 8 ++++++++ gfx/thebes/public/gfxPlatformGtk.h | 3 +++ gfx/thebes/public/gfxPlatformMac.h | 2 ++ gfx/thebes/public/gfxWindowsPlatform.h | 3 +++ gfx/thebes/src/gfxOS2Platform.cpp | 8 ++++++++ gfx/thebes/src/gfxPlatformGtk.cpp | 9 +++++++++ gfx/thebes/src/gfxPlatformMac.cpp | 8 ++++++++ gfx/thebes/src/gfxWindowsPlatform.cpp | 9 +++++++++ gfx/thebes/test/gfxFontSelectionTest.cpp | 17 ++--------------- gfx/thebes/test/gfxTextRunPerfTest.cpp | 15 ++------------- 12 files changed, 60 insertions(+), 49 deletions(-) diff --git a/gfx/src/thebes/nsThebesFontMetrics.cpp b/gfx/src/thebes/nsThebesFontMetrics.cpp index b8d48020ae0f..2d9e14956666 100644 --- a/gfx/src/thebes/nsThebesFontMetrics.cpp +++ b/gfx/src/thebes/nsThebesFontMetrics.cpp @@ -43,21 +43,12 @@ #include #include "gfxTextRunCache.h" +#include "gfxPlatform.h" NS_IMPL_ISUPPORTS1(nsThebesFontMetrics, nsIFontMetrics) #include -#if defined(XP_WIN) -#include "gfxWindowsFonts.h" -#elif defined(MOZ_ENABLE_PANGO) -#include "gfxPangoFonts.h" -#elif defined(XP_MACOSX) -#include "gfxAtsuiFonts.h" -#elif defined(XP_OS2) -#include "gfxOS2Fonts.h" -#endif - nsThebesFontMetrics::nsThebesFontMetrics() { mFontStyle = nsnull; @@ -98,17 +89,8 @@ nsThebesFontMetrics::Init(const nsFont& aFont, nsIAtom* aLangGroup, size, langGroup, aFont.sizeAdjust, aFont.systemFont, aFont.familyNameQuirks); -#if defined(XP_WIN) - mFontGroup = new gfxWindowsFontGroup(aFont.name, mFontStyle); -#elif defined(MOZ_ENABLE_PANGO) - mFontGroup = new gfxPangoFontGroup(aFont.name, mFontStyle); -#elif defined(XP_MACOSX) - mFontGroup = new gfxAtsuiFontGroup(aFont.name, mFontStyle); -#elif defined(XP_OS2) - mFontGroup = new gfxOS2FontGroup(aFont.name, mFontStyle); -#else -#error implement me -#endif + mFontGroup = + gfxPlatform::GetPlatform()->CreateFontGroup(aFont.name, mFontStyle); return NS_OK; } diff --git a/gfx/thebes/public/gfxOS2Platform.h b/gfx/thebes/public/gfxOS2Platform.h index ccf773292196..6ab97b3cf2de 100644 --- a/gfx/thebes/public/gfxOS2Platform.h +++ b/gfx/thebes/public/gfxOS2Platform.h @@ -65,6 +65,9 @@ public: FontResolverCallback aCallback, void *aClosure, PRBool& aAborted); + gfxFontGroup *CreateFontGroup(const nsAString &aFamilies, + const gfxFontStyle *aStyle); + private: HDC mDC; HPS mPS; diff --git a/gfx/thebes/public/gfxPlatform.h b/gfx/thebes/public/gfxPlatform.h index c761bab79d8a..4e67c6bccb50 100644 --- a/gfx/thebes/public/gfxPlatform.h +++ b/gfx/thebes/public/gfxPlatform.h @@ -46,6 +46,8 @@ #include "gfxASurface.h" class gfxImageSurface; +class gfxFontGroup; +class gfxFontStyle; class THEBES_API gfxPlatform { public: @@ -119,6 +121,12 @@ public: void *aClosure, PRBool& aAborted) = 0; + /** + * Create the appropriate platform font group + */ + virtual gfxFontGroup *CreateFontGroup(const nsAString &aFamilies, + const gfxFontStyle *aStyle) = 0; + /* Returns PR_TRUE if the given block of ARGB32 data really has alpha, otherwise PR_FALSE */ static PRBool DoesARGBImageDataHaveAlpha(PRUint8* data, PRUint32 width, diff --git a/gfx/thebes/public/gfxPlatformGtk.h b/gfx/thebes/public/gfxPlatformGtk.h index 8ff9e4529673..154931ad7492 100644 --- a/gfx/thebes/public/gfxPlatformGtk.h +++ b/gfx/thebes/public/gfxPlatformGtk.h @@ -72,6 +72,9 @@ public: FontResolverCallback aCallback, void *aClosure, PRBool& aAborted); + gfxFontGroup *CreateFontGroup(const nsAString &aFamilies, + const gfxFontStyle *aStyle); + static PRInt32 DPI() { if (sDPI == -1) { InitDPI(); diff --git a/gfx/thebes/public/gfxPlatformMac.h b/gfx/thebes/public/gfxPlatformMac.h index 18248853308b..416397240ad5 100644 --- a/gfx/thebes/public/gfxPlatformMac.h +++ b/gfx/thebes/public/gfxPlatformMac.h @@ -56,6 +56,8 @@ public: FontResolverCallback aCallback, void *aClosure, PRBool& aAborted); + gfxFontGroup *CreateFontGroup(const nsAString &aFamilies, + const gfxFontStyle *aStyle); nsresult GetFontList(const nsACString& aLangGroup, const nsACString& aGenericFamily, diff --git a/gfx/thebes/public/gfxWindowsPlatform.h b/gfx/thebes/public/gfxWindowsPlatform.h index 7543cc49844e..c1348ed933b4 100644 --- a/gfx/thebes/public/gfxWindowsPlatform.h +++ b/gfx/thebes/public/gfxWindowsPlatform.h @@ -69,6 +69,9 @@ public: FontResolverCallback aCallback, void *aClosure, PRBool& aAborted); + gfxFontGroup *CreateFontGroup(const nsAString &aFamilies, + const gfxFontStyle *aStyle); + /* local methods */ void FindOtherFonts(const PRUnichar *aString, PRUint32 aLength, const char *aLangGroup, const char *aGeneric, nsString& array); diff --git a/gfx/thebes/src/gfxOS2Platform.cpp b/gfx/thebes/src/gfxOS2Platform.cpp index 6c0a1818a0fe..a6caea718960 100644 --- a/gfx/thebes/src/gfxOS2Platform.cpp +++ b/gfx/thebes/src/gfxOS2Platform.cpp @@ -38,6 +38,7 @@ #include "gfxOS2Platform.h" #include "gfxOS2Surface.h" #include "gfxImageSurface.h" +#include "gfxOS2Fonts.h" /********************************************************************** * class gfxOS2Platform @@ -161,3 +162,10 @@ gfxOS2Platform::ResolveFontName(const nsAString& aFontName, aAborted = !(*aCallback)(aFontName, aClosure); return NS_OK; } + +gfxFontGroup * +gfxOS2Platform::CreateFontGroup(const nsAString &aFamilies, + const gfxFontStyle *aStyle) +{ + return new gfxOS2FontGroup(aFamilies, aStyle); +} diff --git a/gfx/thebes/src/gfxPlatformGtk.cpp b/gfx/thebes/src/gfxPlatformGtk.cpp index e20062f4ef52..81f72afdf164 100644 --- a/gfx/thebes/src/gfxPlatformGtk.cpp +++ b/gfx/thebes/src/gfxPlatformGtk.cpp @@ -50,6 +50,8 @@ #include "gfxImageSurface.h" #include "gfxXlibSurface.h" +#include "gfxPangoFonts.h" + #ifdef MOZ_ENABLE_GLITZ #include "gfxGlitzSurface.h" #include "glitz-glx.h" @@ -263,6 +265,13 @@ gfxPlatformGtk::ResolveFontName(const nsAString& aFontName, aClosure, aAborted); } +gfxFontGroup * +gfxPlatformGtk::CreateFontGroup(const nsAString &aFamilies, + const gfxFontStyle *aStyle) +{ + return new gfxPangoFontGroup(aFamilies, aStyle); +} + static PRInt32 GetXftDPI() { diff --git a/gfx/thebes/src/gfxPlatformMac.cpp b/gfx/thebes/src/gfxPlatformMac.cpp index f4b6229bed92..b569c0a46521 100644 --- a/gfx/thebes/src/gfxPlatformMac.cpp +++ b/gfx/thebes/src/gfxPlatformMac.cpp @@ -42,6 +42,7 @@ #include "gfxQuartzSurface.h" #include "gfxQuartzFontCache.h" +#include "gfxAtsuiFonts.h" #ifdef MOZ_ENABLE_GLITZ #include "gfxGlitzSurface.h" @@ -150,6 +151,13 @@ gfxPlatformMac::ResolveFontName(const nsAString& aFontName, return NS_OK; } +gfxFontGroup * +gfxPlatformMac::CreateFontGroup(const nsAString &aFamilies, + const gfxFontStyle *aStyle) +{ + return new gfxAtsuiFontGroup(aFamilies, aStyle); +} + nsresult gfxPlatformMac::GetFontList(const nsACString& aLangGroup, const nsACString& aGenericFamily, diff --git a/gfx/thebes/src/gfxWindowsPlatform.cpp b/gfx/thebes/src/gfxWindowsPlatform.cpp index 127a64ab0bf5..44c0ed9bf2ea 100644 --- a/gfx/thebes/src/gfxWindowsPlatform.cpp +++ b/gfx/thebes/src/gfxWindowsPlatform.cpp @@ -50,6 +50,8 @@ #include "nsIWindowsRegKey.h" +#include "gfxWindowsFonts.h" + #include gfxWindowsPlatform::gfxWindowsPlatform() @@ -499,3 +501,10 @@ gfxWindowsPlatform::PutFontWeightTable(const nsAString& aName, WeightTable *aWei { mFontWeights.Put(aName, aWeightTable); } + +gfxFontGroup * +gfxWindowsPlatform::CreateFontGroup(const nsAString &aFamilies, + const gfxFontStyle *aStyle) +{ + return new gfxWindowsFontGroup(aFamilies, aStyle); +} diff --git a/gfx/thebes/test/gfxFontSelectionTest.cpp b/gfx/thebes/test/gfxFontSelectionTest.cpp index 41c1fdeea30f..81a03b89a579 100644 --- a/gfx/thebes/test/gfxFontSelectionTest.cpp +++ b/gfx/thebes/test/gfxFontSelectionTest.cpp @@ -50,12 +50,7 @@ #include "gfxFontTest.h" -#if defined(XP_WIN) -#include "gfxWindowsFonts.h" -#elif defined(MOZ_ENABLE_PANGO) -#include "gfxPangoFonts.h" -#elif defined(XP_MACOSX) -#include "gfxAtsuiFonts.h" +#if defined(XP_MACOSX) #include "gfxTestCocoaHelper.h" #endif @@ -288,15 +283,7 @@ PRBool RunTest (TestEntry *test, gfxContext *ctx) { nsRefPtr fontGroup; -#if defined(XP_WIN) - fontGroup = new gfxWindowsFontGroup(NS_ConvertUTF8toUTF16(test->utf8FamilyString), &test->fontStyle); -#elif defined(MOZ_ENABLE_PANGO) - fontGroup = new gfxPangoFontGroup(NS_ConvertUTF8toUTF16(test->utf8FamilyString), &test->fontStyle); -#elif defined(XP_MACOSX) - fontGroup = new gfxAtsuiFontGroup(NS_ConvertUTF8toUTF16(test->utf8FamilyString), &test->fontStyle); -#else - return PR_FALSE; -#endif + fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->utf8FamilyString), &test->fontStyle); nsAutoPtr textRun; gfxTextRunFactory::Parameters params = { diff --git a/gfx/thebes/test/gfxTextRunPerfTest.cpp b/gfx/thebes/test/gfxTextRunPerfTest.cpp index d3b2305f580e..7c973b0d9158 100644 --- a/gfx/thebes/test/gfxTextRunPerfTest.cpp +++ b/gfx/thebes/test/gfxTextRunPerfTest.cpp @@ -52,12 +52,7 @@ #include "gfxFontTest.h" -#if defined(XP_WIN) -#include "gfxWindowsFonts.h" -#elif defined(MOZ_ENABLE_PANGO) -#include "gfxPangoFonts.h" -#elif defined(XP_MACOSX) -#include "gfxAtsuiFonts.h" +#if defined(XP_MACOSX) #include "gfxTestCocoaHelper.h" #endif @@ -103,13 +98,7 @@ RunTest (TestEntry *test, gfxContext *ctx) { 0.0, PR_FALSE, PR_FALSE); -#if defined(XP_WIN) - fontGroup = new gfxWindowsFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16); -#elif defined(MOZ_ENABLE_PANGO) - fontGroup = new gfxPangoFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16); -#elif defined(XP_MACOSX) - fontGroup = new gfxAtsuiFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16); -#endif + fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16); } nsAutoPtr textRun;