From 364e126c767e085521ea77e90364dd34c581cbd1 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Mon, 30 Jun 2014 14:25:11 +1000 Subject: [PATCH] Bug 1031199 - Disallow aWeight = 0 when calling gfxUserFontSet::AddFontFace. r=jdaggett --- gfx/thebes/gfxUserFontSet.cpp | 6 +++--- gfx/thebes/gfxUserFontSet.h | 2 +- layout/style/nsFontFaceLoader.cpp | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gfx/thebes/gfxUserFontSet.cpp b/gfx/thebes/gfxUserFontSet.cpp index 487efac812b7..9d4eb99cc84f 100644 --- a/gfx/thebes/gfxUserFontSet.cpp +++ b/gfx/thebes/gfxUserFontSet.cpp @@ -129,14 +129,14 @@ gfxUserFontSet::AddFontFace(const nsAString& aFamilyName, const nsString& aLanguageOverride, gfxSparseBitSet *aUnicodeRanges) { + MOZ_ASSERT(aWeight != 0, + "aWeight must not be 0; use NS_FONT_WEIGHT_NORMAL instead"); + nsAutoString key(aFamilyName); ToLowerCase(key); bool found; - if (aWeight == 0) - aWeight = NS_FONT_WEIGHT_NORMAL; - // stretch, italic/oblique ==> zero implies normal gfxMixedFontFamily *family = mFontFamilies.GetWeak(key, &found); diff --git a/gfx/thebes/gfxUserFontSet.h b/gfx/thebes/gfxUserFontSet.h index 446e236ee88b..2424ef219f2c 100644 --- a/gfx/thebes/gfxUserFontSet.h +++ b/gfx/thebes/gfxUserFontSet.h @@ -167,7 +167,7 @@ public: // add in a font face - // weight - 0 == unknown, [100, 900] otherwise (multiples of 100) + // weight - [100, 900] (multiples of 100) // stretch = [NS_FONT_STRETCH_ULTRA_CONDENSED, NS_FONT_STRETCH_ULTRA_EXPANDED] // italic style = constants in gfxFontConstants.h, e.g. NS_FONT_STYLE_NORMAL // TODO: support for unicode ranges not yet implemented diff --git a/layout/style/nsFontFaceLoader.cpp b/layout/style/nsFontFaceLoader.cpp index fa7e479bdfe0..3e94cfce56a5 100644 --- a/layout/style/nsFontFaceLoader.cpp +++ b/layout/style/nsFontFaceLoader.cpp @@ -578,6 +578,9 @@ nsUserFontSet::InsertRule(nsCSSFontFaceRule* aRule, uint8_t aSheetType, unit = val.GetUnit(); if (unit == eCSSUnit_Integer || unit == eCSSUnit_Enumerated) { weight = val.GetIntValue(); + if (weight == 0) { + weight = NS_STYLE_FONT_STYLE_NORMAL; + } } else if (unit == eCSSUnit_Normal) { weight = NS_STYLE_FONT_WEIGHT_NORMAL; } else {