Bug 798853, gfx. r=roc a=akeybl
authorMats Palmgren <matspal@gmail.com>
Fri, 02 Nov 2012 00:15:15 +0100
changeset 82067 677added3cc5c95643f5948b90f5439cb6a30123
parent 82066 3c7c48e34e747f5eab365a2a2917c004044468d1
child 82068 4bc1f76124369296032816cd34a0675e6d40ccaa
push id322
push usermpalmgren@mozilla.com
push dateThu, 01 Nov 2012 23:15:27 +0000
reviewersroc, akeybl
bugs798853
milestone10.0.11esrpre
Bug 798853, gfx. r=roc a=akeybl
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxFont.h
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -61,16 +61,17 @@
 #include "gfxPlatformFontList.h"
 #include "gfxScriptItemizer.h"
 #include "gfxUnicodeProperties.h"
 #include "nsMathUtils.h"
 #include "nsBidiUtils.h"
 #include "nsUnicodeRange.h"
 #include "nsCompressedCharMap.h"
 #include "nsStyleConsts.h"
+#include "mozilla/FloatingPoint.h"
 #include "mozilla/Preferences.h"
 
 #include "cairo.h"
 #include "gfxFontTest.h"
 
 #include "harfbuzz/hb-blob.h"
 
 #include "nsCRT.h"
@@ -992,16 +993,19 @@ void
 gfxFontCache::AddNew(gfxFont *aFont)
 {
     Key key(aFont->GetFontEntry(), aFont->GetStyle());
     HashEntry *entry = mFonts.PutEntry(key);
     if (!entry)
         return;
     gfxFont *oldFont = entry->mFont;
     entry->mFont = aFont;
+    // Assert that we can find the entry we just put in (this fails if the key
+    // has a NaN float value in it, e.g. 'sizeAdjust').
+    MOZ_ASSERT(entry == mFonts.GetEntry(key));
     // If someone's asked us to replace an existing font entry, then that's a
     // bit weird, but let it happen, and expire the old font if it's not used.
     if (oldFont && oldFont->GetExpirationState()->IsTracked()) {
         // if oldFont == aFont, recount should be > 0,
         // so we shouldn't be here.
         NS_ASSERTION(aFont != oldFont, "new font is tracked for expiry!");
         NotifyExpired(oldFont);
     }
@@ -1029,18 +1033,19 @@ gfxFontCache::NotifyExpired(gfxFont *aFo
     DestroyFont(aFont);
 }
 
 void
 gfxFontCache::DestroyFont(gfxFont *aFont)
 {
     Key key(aFont->GetFontEntry(), aFont->GetStyle());
     HashEntry *entry = mFonts.GetEntry(key);
-    if (entry && entry->mFont == aFont)
+    if (entry && entry->mFont == aFont) {
         mFonts.RemoveEntry(key);
+    }
     NS_ASSERTION(aFont->GetRefCount() == 0,
                  "Destroying with non-zero ref count!");
     delete aFont;
 }
 
 void
 gfxFont::RunMetrics::CombineWith(const RunMetrics& aOther, bool aOtherIsOnLeft)
 {
@@ -3025,16 +3030,19 @@ gfxFontStyle::gfxFontStyle(PRUint8 aStyl
                            const nsString& aFeatureSettings,
                            const nsString& aLanguageOverride):
     style(aStyle), systemFont(aSystemFont), printerFont(aPrinterFont),
     weight(aWeight), stretch(aStretch),
     size(aSize), sizeAdjust(aSizeAdjust),
     language(aLanguage),
     languageOverride(ParseFontLanguageOverride(aLanguageOverride))
 {
+    MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(size));
+    MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(sizeAdjust));
+
     ParseFontFeatureSettings(aFeatureSettings, featureSettings);
 
     if (weight > 900)
         weight = 900;
     if (weight < 100)
         weight = 100;
 
     if (size >= FONT_MAX_SIZE) {
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -176,24 +176,27 @@ struct THEBES_API gfxFontStyle {
         return ((style + (systemFont << 7) +
             (weight << 8)) + PRUint32(size*1000) + PRUint32(sizeAdjust*1000)) ^
             nsISupportsHashKey::HashKey(language);
     }
 
     PRInt8 ComputeWeight() const;
 
     bool Equals(const gfxFontStyle& other) const {
-        return (size == other.size) &&
+        return
+            (*reinterpret_cast<const uint64_t*>(&size) ==
+             *reinterpret_cast<const uint64_t*>(&other.size)) &&
             (style == other.style) &&
             (systemFont == other.systemFont) &&
             (printerFont == other.printerFont) &&
             (weight == other.weight) &&
             (stretch == other.stretch) &&
             (language == other.language) &&
-            (sizeAdjust == other.sizeAdjust) &&
+            (*reinterpret_cast<const uint32_t*>(&sizeAdjust) ==
+             *reinterpret_cast<const uint32_t*>(&other.sizeAdjust)) &&
             (featureSettings == other.featureSettings) &&
             (languageOverride == other.languageOverride);
     }
 
     static void ParseFontFeatureSettings(const nsString& aFeatureString,
                                          nsTArray<gfxFontFeature>& aFeatures);
 
     static PRUint32 ParseFontLanguageOverride(const nsString& aLangTag);