Bug 702851: Move mScaledFont into gfxFont superclass. r=jdaggett
authorBas Schouten <bschouten@mozilla.com>
Thu, 15 Dec 2011 17:12:40 +0100
changeset 83463 2dcafeb76514fb00e9318eb8f8e2eef778b60721
parent 83462 bb6812611234e2e7a0ee74120c45c072d721a0b7
child 83464 d744d9200a0b1437a3f67a811ca3ac68e4886d4a
push idunknown
push userunknown
push dateunknown
reviewersjdaggett
bugs702851
milestone11.0a1
Bug 702851: Move mScaledFont into gfxFont superclass. r=jdaggett
gfx/thebes/gfxDWriteFonts.cpp
gfx/thebes/gfxDWriteFonts.h
gfx/thebes/gfxFT2FontBase.cpp
gfx/thebes/gfxFT2FontBase.h
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxFont.h
gfx/thebes/gfxGDIFont.cpp
gfx/thebes/gfxGDIFont.h
gfx/thebes/gfxMacFont.cpp
gfx/thebes/gfxMacFont.h
gfx/thebes/gfxOS2Fonts.cpp
gfx/thebes/gfxOS2Fonts.h
--- a/gfx/thebes/gfxDWriteFonts.cpp
+++ b/gfx/thebes/gfxDWriteFonts.cpp
@@ -119,17 +119,16 @@ UsingClearType()
 ////////////////////////////////////////////////////////////////////////////////
 // gfxDWriteFont
 gfxDWriteFont::gfxDWriteFont(gfxFontEntry *aFontEntry,
                              const gfxFontStyle *aFontStyle,
                              bool aNeedsBold,
                              AntialiasOption anAAOption)
     : gfxFont(aFontEntry, aFontStyle, anAAOption)
     , mCairoFontFace(nsnull)
-    , mCairoScaledFont(nsnull)
     , mMetrics(nsnull)
     , mNeedsOblique(false)
     , mNeedsBold(aNeedsBold)
     , mUseSubpixelPositions(false)
     , mAllowManualShowGlyphs(true)
 {
     gfxDWriteFontEntry *fe =
         static_cast<gfxDWriteFontEntry*>(aFontEntry);
@@ -165,18 +164,18 @@ gfxDWriteFont::gfxDWriteFont(gfxFontEntr
     }
 }
 
 gfxDWriteFont::~gfxDWriteFont()
 {
     if (mCairoFontFace) {
         cairo_font_face_destroy(mCairoFontFace);
     }
-    if (mCairoScaledFont) {
-        cairo_scaled_font_destroy(mCairoScaledFont);
+    if (mScaledFont) {
+        cairo_scaled_font_destroy(mScaledFont);
     }
     delete mMetrics;
 }
 
 gfxFont*
 gfxDWriteFont::CopyWithAntialiasOption(AntialiasOption anAAOption)
 {
     return new gfxDWriteFont(static_cast<gfxDWriteFontEntry*>(mFontEntry.get()),
@@ -566,17 +565,17 @@ gfxDWriteFont::CairoFontFace()
     }
     return mCairoFontFace;
 }
 
 
 cairo_scaled_font_t *
 gfxDWriteFont::CairoScaledFont()
 {
-    if (!mCairoScaledFont) {
+    if (!mScaledFont) {
         cairo_matrix_t sizeMatrix;
         cairo_matrix_t identityMatrix;
 
         cairo_matrix_init_scale(&sizeMatrix, mAdjustedSize, mAdjustedSize);
         cairo_matrix_init_identity(&identityMatrix);
 
         cairo_font_options_t *fontOptions = cairo_font_options_create();
         if (mNeedsOblique) {
@@ -593,37 +592,37 @@ gfxDWriteFont::CairoScaledFont()
             cairo_matrix_multiply(&sizeMatrix, &sizeMatrix, &style);
         }
 
         if (mAntialiasOption != kAntialiasDefault) {
             cairo_font_options_set_antialias(fontOptions,
                 GetCairoAntialiasOption(mAntialiasOption));
         }
 
-        mCairoScaledFont = cairo_scaled_font_create(CairoFontFace(),
+        mScaledFont = cairo_scaled_font_create(CairoFontFace(),
                                                     &sizeMatrix,
                                                     &identityMatrix,
                                                     fontOptions);
         cairo_font_options_destroy(fontOptions);
 
-        cairo_dwrite_scaled_font_allow_manual_show_glyphs(mCairoScaledFont,
+        cairo_dwrite_scaled_font_allow_manual_show_glyphs(mScaledFont,
                                                           mAllowManualShowGlyphs);
 
         gfxDWriteFontEntry *fe =
             static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
-        cairo_dwrite_scaled_font_set_force_GDI_classic(mCairoScaledFont,
+        cairo_dwrite_scaled_font_set_force_GDI_classic(mScaledFont,
                                                        GetForceGDIClassic());
     }
 
     NS_ASSERTION(mAdjustedSize == 0.0 ||
-                 cairo_scaled_font_status(mCairoScaledFont) 
+                 cairo_scaled_font_status(mScaledFont) 
                    == CAIRO_STATUS_SUCCESS,
                  "Failed to make scaled font");
 
-    return mCairoScaledFont;
+    return mScaledFont;
 }
 
 gfxFont::RunMetrics
 gfxDWriteFont::Measure(gfxTextRun *aTextRun,
                     PRUint32 aStart, PRUint32 aEnd,
                     BoundingBoxType aBoundingBoxType,
                     gfxContext *aRefContext,
                     Spacing *aSpacing)
--- a/gfx/thebes/gfxDWriteFonts.h
+++ b/gfx/thebes/gfxDWriteFonts.h
@@ -109,17 +109,16 @@ protected:
 
     static void DestroyBlobFunc(void* userArg);
 
     DWRITE_MEASURING_MODE GetMeasuringMode();
     bool GetForceGDIClassic();
 
     nsRefPtr<IDWriteFontFace> mFontFace;
     cairo_font_face_t *mCairoFontFace;
-    cairo_scaled_font_t *mCairoScaledFont;
 
     gfxFont::Metrics          *mMetrics;
 
     // cache of glyph widths in 16.16 fixed-point pixels
     nsDataHashtable<nsUint32HashKey,PRInt32>    mGlyphWidths;
 
     bool mNeedsOblique;
     bool mNeedsBold;
--- a/gfx/thebes/gfxFT2FontBase.cpp
+++ b/gfx/thebes/gfxFT2FontBase.cpp
@@ -42,18 +42,17 @@
 
 #include "gfxFT2FontBase.h"
 #include "gfxFT2Utils.h"
 #include "harfbuzz/hb-blob.h"
 
 gfxFT2FontBase::gfxFT2FontBase(cairo_scaled_font_t *aScaledFont,
                                gfxFontEntry *aFontEntry,
                                const gfxFontStyle *aFontStyle)
-    : gfxFont(aFontEntry, aFontStyle),
-      mScaledFont(aScaledFont),
+    : gfxFont(aFontEntry, aFontStyle, kAntialiasDefault, aScaledFont),
       mSpaceGlyph(0),
       mHasMetrics(false)
 {
     cairo_scaled_font_reference(mScaledFont);
 }
 
 gfxFT2FontBase::~gfxFT2FontBase()
 {
--- a/gfx/thebes/gfxFT2FontBase.h
+++ b/gfx/thebes/gfxFT2FontBase.h
@@ -64,15 +64,14 @@ public:
     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);
 
 protected:
-    cairo_scaled_font_t *mScaledFont;
     PRUint32 mSpaceGlyph;
     bool mHasMetrics;
     Metrics mMetrics;
 };
 
 #endif /* GFX_FT2FONTBASE_H */
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -1063,17 +1063,18 @@ gfxFont::RunMetrics::CombineWith(const R
     } else {
         mBoundingBox =
             mBoundingBox.Union(aOther.mBoundingBox + gfxPoint(mAdvanceWidth, 0));
     }
     mAdvanceWidth += aOther.mAdvanceWidth;
 }
 
 gfxFont::gfxFont(gfxFontEntry *aFontEntry, const gfxFontStyle *aFontStyle,
-                 AntialiasOption anAAOption) :
+                 AntialiasOption anAAOption, cairo_scaled_font_t *aScaledFont) :
+    mScaledFont(aScaledFont),
     mFontEntry(aFontEntry), mIsValid(true),
     mApplySyntheticBold(false),
     mStyle(*aFontStyle),
     mAdjustedSize(0.0),
     mFUnitsConvFactor(0.0f),
     mAntialiasOption(anAAOption)
 {
 #ifdef DEBUG_TEXT_RUN_STORAGE_METRICS
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -53,16 +53,18 @@
 #include "gfxSkipChars.h"
 #include "gfxRect.h"
 #include "nsExpirationTracker.h"
 #include "gfxFontConstants.h"
 #include "gfxPlatform.h"
 #include "nsIAtom.h"
 #include "nsISupportsImpl.h"
 
+typedef struct _cairo_scaled_font cairo_scaled_font_t;
+
 #ifdef DEBUG
 #include <stdio.h>
 #endif
 
 class gfxContext;
 class gfxTextRun;
 class gfxFont;
 class gfxFontFamily;
@@ -950,31 +952,33 @@ public:
         kAntialiasDefault,
         kAntialiasNone,
         kAntialiasGrayscale,
         kAntialiasSubpixel
     } AntialiasOption;
 
 protected:
     nsAutoRefCnt mRefCnt;
+    cairo_scaled_font_t *mScaledFont;
 
     void NotifyReleased() {
         gfxFontCache *cache = gfxFontCache::GetCache();
         if (cache) {
             // Don't delete just yet; return the object to the cache for
             // possibly recycling within some time limit
             cache->NotifyReleased(this);
         } else {
             // The cache may have already been shut down.
             delete this;
         }
     }
 
     gfxFont(gfxFontEntry *aFontEntry, const gfxFontStyle *aFontStyle,
-            AntialiasOption anAAOption = kAntialiasDefault);
+            AntialiasOption anAAOption = kAntialiasDefault,
+            cairo_scaled_font_t *aScaledFont = nsnull);
 
 public:
     virtual ~gfxFont();
 
     bool Valid() const {
         return mIsValid;
     }
 
--- a/gfx/thebes/gfxGDIFont.cpp
+++ b/gfx/thebes/gfxGDIFont.cpp
@@ -72,17 +72,16 @@ GetCairoAntialiasOption(gfxFont::Antiali
 
 gfxGDIFont::gfxGDIFont(GDIFontEntry *aFontEntry,
                        const gfxFontStyle *aFontStyle,
                        bool aNeedsBold,
                        AntialiasOption anAAOption)
     : gfxFont(aFontEntry, aFontStyle, anAAOption),
       mFont(NULL),
       mFontFace(nsnull),
-      mScaledFont(nsnull),
       mMetrics(nsnull),
       mSpaceGlyph(0),
       mNeedsBold(aNeedsBold)
 {
 #ifdef MOZ_GRAPHITE
     if (FontCanSupportGraphite()) {
         mGraphiteShaper = new gfxGraphiteShaper(this);
     }
--- a/gfx/thebes/gfxGDIFont.h
+++ b/gfx/thebes/gfxGDIFont.h
@@ -105,17 +105,16 @@ protected:
     void FillLogFont(LOGFONTW& aLogFont, gfxFloat aSize);
 
     // mPlatformShaper is used for the GDI shaper, mUniscribeShaper
     // for the Uniscribe version if needed
     nsAutoPtr<gfxFontShaper>   mUniscribeShaper;
 
     HFONT                 mFont;
     cairo_font_face_t    *mFontFace;
-    cairo_scaled_font_t  *mScaledFont;
 
     Metrics              *mMetrics;
     PRUint32              mSpaceGlyph;
 
     bool                  mNeedsBold;
 
     // cache of glyph widths in 16.16 fixed-point pixels
     nsDataHashtable<nsUint32HashKey,PRInt32>    mGlyphWidths;
--- a/gfx/thebes/gfxMacFont.cpp
+++ b/gfx/thebes/gfxMacFont.cpp
@@ -53,18 +53,17 @@
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 gfxMacFont::gfxMacFont(MacOSFontEntry *aFontEntry, const gfxFontStyle *aFontStyle,
                        bool aNeedsBold)
     : gfxFont(aFontEntry, aFontStyle),
       mCGFont(nsnull),
-      mFontFace(nsnull),
-      mScaledFont(nsnull)
+      mFontFace(nsnull)
 {
     mApplySyntheticBold = aNeedsBold;
 
     mCGFont = aFontEntry->GetFontRef();
     if (!mCGFont) {
         mIsValid = false;
         return;
     }
--- a/gfx/thebes/gfxMacFont.h
+++ b/gfx/thebes/gfxMacFont.h
@@ -104,17 +104,16 @@ protected:
 
     static void DestroyBlobFunc(void* aUserData);
 
     // a weak reference to the CoreGraphics font: this is owned by the
     // MacOSFontEntry, it is not retained or released by gfxMacFont
     CGFontRef             mCGFont;
 
     cairo_font_face_t    *mFontFace;
-    cairo_scaled_font_t  *mScaledFont;
 
     Metrics               mMetrics;
     PRUint32              mSpaceGlyph;
 
     mozilla::RefPtr<mozilla::gfx::ScaledFont> mAzureFont;
 };
 
 #endif /* GFX_MACFONT_H */
--- a/gfx/thebes/gfxOS2Fonts.cpp
+++ b/gfx/thebes/gfxOS2Fonts.cpp
@@ -54,17 +54,17 @@
 using namespace mozilla;
 
 /**********************************************************************
  * class gfxOS2Font
  **********************************************************************/
 
 gfxOS2Font::gfxOS2Font(gfxOS2FontEntry *aFontEntry, const gfxFontStyle *aFontStyle)
     : gfxFont(aFontEntry, aFontStyle),
-      mFontFace(nsnull), mScaledFont(nsnull),
+      mFontFace(nsnull),
       mMetrics(nsnull), mAdjustedSize(0),
       mHinting(FC_HINT_MEDIUM), mAntialias(FcTrue)
 {
 #ifdef DEBUG_thebes_2
     printf("gfxOS2Font[%p]::gfxOS2Font(%p \"%s\", aFontStyle)\n",
            (void *)this, (void *)aFontEntry,
            NS_LossyConvertUTF16toASCII(aFontEntry->Name()).get());
 #endif
--- a/gfx/thebes/gfxOS2Fonts.h
+++ b/gfx/thebes/gfxOS2Fonts.h
@@ -76,17 +76,16 @@ public:
     static already_AddRefed<gfxOS2Font> GetOrMakeFont(const nsAString& aName,
                                                       const gfxFontStyle *aStyle);
 
 protected:
     virtual bool SetupCairoFont(gfxContext *aContext);
 
 private:
     cairo_font_face_t *mFontFace;
-    cairo_scaled_font_t *mScaledFont;
     Metrics *mMetrics;
     gfxFloat mAdjustedSize;
     PRUint32 mSpaceGlyph;
     int mHinting;
     bool mAntialias;
 };