Bug 743593: Properly cast gfxFont based on type. r=jfkthame
authorBas Schouten <bschouten@mozilla.com>
Wed, 11 Apr 2012 16:55:31 +0200
changeset 91433 2fcf9cbedd48f5303fd1d0d426390b9ebc9c25d7
parent 91432 c124fc77aab2226eccd05c002018eb75e7e8b02e
child 91434 f99886297f833872e02362515f614f70ccc981d7
push id672
push usertim.taubert@gmx.de
push dateFri, 13 Apr 2012 10:22:59 +0000
treeherderfx-team@cb2e81306595 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs743593
milestone14.0a1
Bug 743593: Properly cast gfxFont based on type. r=jfkthame
gfx/thebes/gfxDWriteFonts.h
gfx/thebes/gfxFT2FontBase.h
gfx/thebes/gfxFont.h
gfx/thebes/gfxGDIFont.h
gfx/thebes/gfxMacFont.h
gfx/thebes/gfxOS2Fonts.h
gfx/thebes/gfxWindowsPlatform.cpp
--- a/gfx/thebes/gfxDWriteFonts.h
+++ b/gfx/thebes/gfxDWriteFonts.h
@@ -92,16 +92,18 @@ public:
 
     virtual mozilla::TemporaryRef<mozilla::gfx::GlyphRenderingOptions> GetGlyphRenderingOptions();
 
     virtual void SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf,
                                      FontCacheSizes*   aSizes) const;
     virtual void SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf,
                                      FontCacheSizes*   aSizes) const;
 
+    virtual FontType GetType() const { return FONT_TYPE_DWRITE; }
+
 protected:
     friend class gfxDWriteShaper;
 
     virtual void CreatePlatformShaper();
 
     bool GetFakeMetricsForArialBlack(DWRITE_FONT_METRICS *aFontMetrics);
 
     void ComputeMetrics(AntialiasOption anAAOption);
--- a/gfx/thebes/gfxFT2FontBase.h
+++ b/gfx/thebes/gfxFT2FontBase.h
@@ -63,15 +63,16 @@ public:
     virtual bool ProvidesGetGlyph() const { return true; }
     virtual PRUint32 GetGlyph(PRUint32 unicode, PRUint32 variation_selector);
     virtual bool ProvidesGlyphWidths() { return true; }
     virtual PRInt32 GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID);
 
     cairo_scaled_font_t *CairoScaledFont() { return mScaledFont; };
     virtual bool SetupCairoFont(gfxContext *aContext);
 
+    virtual FontType GetType() const { return FONT_TYPE_FT2; }
 protected:
     PRUint32 mSpaceGlyph;
     bool mHasMetrics;
     Metrics mMetrics;
 };
 
 #endif /* GFX_FT2FONTBASE_H */
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -1521,16 +1521,26 @@ public:
         }
     }
 
     virtual void SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf,
                                      FontCacheSizes*   aSizes) const;
     virtual void SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf,
                                      FontCacheSizes*   aSizes) const;
 
+    typedef enum {
+        FONT_TYPE_DWRITE,
+        FONT_TYPE_GDI,
+        FONT_TYPE_FT2,
+        FONT_TYPE_MAC,
+        FONT_TYPE_OS2
+    } FontType;
+
+    virtual FontType GetType() const = 0;
+
 protected:
     // Call the appropriate shaper to generate glyphs for aText and store
     // them into aShapedWord.
     // The length of the text is aShapedWord->Length().
     virtual bool ShapeWord(gfxContext *aContext,
                            gfxShapedWord *aShapedWord,
                            const PRUnichar *aText,
                            bool aPreferPlatformShaping = false);
--- a/gfx/thebes/gfxGDIFont.h
+++ b/gfx/thebes/gfxGDIFont.h
@@ -88,16 +88,18 @@ public:
     // get hinted glyph width in pixels as 16.16 fixed-point value
     virtual PRInt32 GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID);
 
     virtual void SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf,
                                      FontCacheSizes*   aSizes) const;
     virtual void SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf,
                                      FontCacheSizes*   aSizes) const;
 
+    virtual FontType GetType() const { return FONT_TYPE_GDI; }
+
 protected:
     virtual void CreatePlatformShaper();
 
     /* override to check for uniscribe failure and fall back to GDI */
     virtual bool ShapeWord(gfxContext *aContext,
                            gfxShapedWord *aShapedWord,
                            const PRUnichar *aString,
                            bool aPreferPlatformShaping = false);
--- a/gfx/thebes/gfxMacFont.h
+++ b/gfx/thebes/gfxMacFont.h
@@ -81,16 +81,18 @@ public:
 
     mozilla::RefPtr<mozilla::gfx::ScaledFont> GetScaledFont();
 
     virtual void SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf,
                                      FontCacheSizes*   aSizes) const;
     virtual void SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf,
                                      FontCacheSizes*   aSizes) const;
 
+    virtual FontType GetType() const { return FONT_TYPE_MAC; }
+
 protected:
     virtual void CreatePlatformShaper();
 
     // override to prefer CoreText shaping with fonts that depend on AAT
     virtual bool ShapeWord(gfxContext *aContext,
                            gfxShapedWord *aShapedWord,
                            const PRUnichar *aText,
                            bool aPreferPlatformShaping = false);
--- a/gfx/thebes/gfxOS2Fonts.h
+++ b/gfx/thebes/gfxOS2Fonts.h
@@ -74,16 +74,18 @@ public:
     }
 
     static already_AddRefed<gfxOS2Font> GetOrMakeFont(const nsAString& aName,
                                                       const gfxFontStyle *aStyle);
 
 protected:
     virtual bool SetupCairoFont(gfxContext *aContext);
 
+    virtual FontType GetType() const { return FONT_TYPE_OS2; }
+
 private:
     cairo_font_face_t *mFontFace;
     Metrics *mMetrics;
     gfxFloat mAdjustedSize;
     PRUint32 mSpaceGlyph;
     int mHinting;
     bool mAntialias;
 };
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -712,37 +712,40 @@ gfxWindowsPlatform::CreateOffscreenSurfa
     NS_IF_ADDREF(surf);
 
     return surf;
 }
 
 RefPtr<ScaledFont>
 gfxWindowsPlatform::GetScaledFontForFont(gfxFont *aFont)
 {
-  if(mUseDirectWrite) {
-    gfxDWriteFont *font = static_cast<gfxDWriteFont*>(aFont);
+    if (aFont->GetType() == gfxFont::FONT_TYPE_DWRITE) {
+        gfxDWriteFont *font = static_cast<gfxDWriteFont*>(aFont);
+
+        NativeFont nativeFont;
+        nativeFont.mType = NATIVE_FONT_DWRITE_FONT_FACE;
+        nativeFont.mFont = font->GetFontFace();
+        RefPtr<ScaledFont> scaledFont =
+            mozilla::gfx::Factory::CreateScaledFontForNativeFont(nativeFont, font->GetAdjustedSize());
+
+        return scaledFont;
+    }
+
+    NS_ASSERTION(aFont->GetType() == gfxFont::FONT_TYPE_GDI,
+        "Fonts on windows should be GDI or DWrite!");
 
     NativeFont nativeFont;
-    nativeFont.mType = NATIVE_FONT_DWRITE_FONT_FACE;
-    nativeFont.mFont = font->GetFontFace();
+    nativeFont.mType = NATIVE_FONT_GDI_FONT_FACE;
+    LOGFONT lf;
+    GetObject(static_cast<gfxGDIFont*>(aFont)->GetHFONT(), sizeof(LOGFONT), &lf);
+    nativeFont.mFont = &lf;
     RefPtr<ScaledFont> scaledFont =
-      mozilla::gfx::Factory::CreateScaledFontForNativeFont(nativeFont, font->GetAdjustedSize());
+    Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());
 
     return scaledFont;
-  }
-
-  NativeFont nativeFont;
-  nativeFont.mType = NATIVE_FONT_GDI_FONT_FACE;
-  LOGFONT lf;
-  GetObject(static_cast<gfxGDIFont*>(aFont)->GetHFONT(), sizeof(LOGFONT), &lf);
-  nativeFont.mFont = &lf;
-  RefPtr<ScaledFont> scaledFont =
-    Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());
-
-  return scaledFont;
 }
 
 already_AddRefed<gfxASurface>
 gfxWindowsPlatform::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
 {
 #ifdef XP_WIN
   if (aTarget->GetType() == BACKEND_DIRECT2D) {
     void *surface = aTarget->GetUserData(&kThebesSurfaceKey);