Bug 1452466 - Get rid of gfxFontStyle::ComputeWeight. r=jfkthame
authorJonathan Watt <jwatt@jwatt.org>
Mon, 09 Apr 2018 10:39:17 +0100
changeset 457290 e7478c64d4d9cef3ebe48d1f64c87b2bf39530f1
parent 457289 5c3a7a21deddec8f18c40abdd5746cdd8ddce5fe
child 457291 8924788c2d5b98b965b592cc28c4307cb81ee5f2
push id153
push userfmarier@mozilla.com
push dateTue, 10 Apr 2018 02:28:40 +0000
reviewersjfkthame
bugs1452466
milestone61.0a1
Bug 1452466 - Get rid of gfxFontStyle::ComputeWeight. r=jfkthame
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxFont.h
gfx/thebes/gfxFontEntry.cpp
gfx/thebes/gfxTextRun.cpp
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -4161,29 +4161,16 @@ gfxFontStyle::gfxFontStyle(uint8_t aStyl
     }
 
     if (!language) {
         NS_WARNING("null language");
         language = nsGkAtoms::x_western;
     }
 }
 
-int8_t
-gfxFontStyle::ComputeWeight() const
-{
-    int8_t baseWeight = (weight + 50) / 100;
-
-    if (baseWeight < 0)
-        baseWeight = 0;
-    if (baseWeight > 9)
-        baseWeight = 9;
-
-    return baseWeight;
-}
-
 void
 gfxFontStyle::AdjustForSubSuperscript(int32_t aAppUnitsPerDevPixel)
 {
     NS_PRECONDITION(variantSubSuper != NS_FONT_VARIANT_POSITION_NORMAL &&
                     baselineOffset == 0,
                     "can't adjust this style for sub/superscript");
 
     // calculate the baseline offset (before changing the size)
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -184,18 +184,16 @@ struct gfxFontStyle {
     }
 
     PLDHashNumber Hash() const {
         return ((style + (systemFont << 7) +
             (weight << 8)) + uint32_t(size*1000) + int32_t(sizeAdjust*1000)) ^
             nsRefPtrHashKey<nsAtom>::HashKey(language);
     }
 
-    int8_t ComputeWeight() const;
-
     // Adjust this style to simulate sub/superscript (as requested in the
     // variantSubSuper field) using size and baselineOffset instead.
     void AdjustForSubSuperscript(int32_t aAppUnitsPerDevPixel);
 
     bool Equals(const gfxFontStyle& other) const {
         return
             (*reinterpret_cast<const uint64_t*>(&size) ==
              *reinterpret_cast<const uint64_t*>(&other.size)) &&
--- a/gfx/thebes/gfxFontEntry.cpp
+++ b/gfx/thebes/gfxFontEntry.cpp
@@ -1302,18 +1302,17 @@ gfxFontFamily::FindAllFontsForStyle(cons
         FindStyleVariations(); // collect faces for the family, if not already done
     }
 
     NS_ASSERTION(mAvailableFonts.Length() > 0, "font family with no faces!");
     NS_ASSERTION(aFontEntryList.IsEmpty(), "non-empty fontlist passed in");
 
     aNeedsSyntheticBold = false;
 
-    int8_t baseWeight = aFontStyle.ComputeWeight();
-    bool wantBold = baseWeight >= 6;
+    bool wantBold = aFontStyle.weight >= 600;
     gfxFontEntry *fe = nullptr;
 
     // If the family has only one face, we simply return it; no further
     // checking needed
     uint32_t count = mAvailableFonts.Length();
     if (count == 1) {
         fe = mAvailableFonts[0];
         aNeedsSyntheticBold =
@@ -1497,17 +1496,17 @@ CalcStyleMatch(gfxFontEntry *aFontEntry,
     if (aStyle) {
          // italics
          bool wantUpright = (aStyle->style == NS_FONT_STYLE_NORMAL);
          if (aFontEntry->IsUpright() == wantUpright) {
              rank += 10;
          }
 
         // measure of closeness of weight to the desired value
-        rank += 9 - DeprecatedAbs(aFontEntry->Weight() / 100 - aStyle->ComputeWeight());
+        rank += 9 - Abs((aFontEntry->Weight() - aStyle->weight) / 100);
     } else {
         // if no font to match, prefer non-bold, non-italic fonts
         if (aFontEntry->IsUpright()) {
             rank += 3;
         }
         if (!aFontEntry->IsBold()) {
             rank += 2;
         }
--- a/gfx/thebes/gfxTextRun.cpp
+++ b/gfx/thebes/gfxTextRun.cpp
@@ -3439,17 +3439,17 @@ gfxFontGroup::WhichPrefFontSupportsChar(
 gfxFont*
 gfxFontGroup::WhichSystemFontSupportsChar(uint32_t aCh, uint32_t aNextCh,
                                           Script aRunScript)
 {
     gfxFontEntry *fe =
         gfxPlatformFontList::PlatformFontList()->
             SystemFindFontForChar(aCh, aNextCh, aRunScript, &mStyle);
     if (fe) {
-        bool wantBold = mStyle.ComputeWeight() >= 6;
+        bool wantBold = mStyle.weight >= 600;
         return fe->FindOrMakeFont(&mStyle, wantBold && !fe->IsBold());
     }
 
     return nullptr;
 }
 
 void
 gfxMissingFontRecorder::Flush()