Bug 691581 - Don't let a zero-sized font result in assertions from FUnitsToDevUnitsFactor(). r=jdaggett

This commit is contained in:
Jonathan Kew 2015-11-02 08:36:50 +00:00
Родитель e255b900f5
Коммит 9adf8fcb59
3 изменённых файлов: 15 добавлений и 10 удалений

Просмотреть файл

@ -748,7 +748,7 @@ gfxFont::gfxFont(gfxFontEntry *aFontEntry, const gfxFontStyle *aFontStyle,
mApplySyntheticBold(false), mApplySyntheticBold(false),
mStyle(*aFontStyle), mStyle(*aFontStyle),
mAdjustedSize(0.0), mAdjustedSize(0.0),
mFUnitsConvFactor(0.0f), mFUnitsConvFactor(-1.0f), // negative to indicate "not yet initialized"
mAntialiasOption(anAAOption) mAntialiasOption(anAAOption)
{ {
#ifdef DEBUG_TEXT_RUN_STORAGE_METRICS #ifdef DEBUG_TEXT_RUN_STORAGE_METRICS
@ -785,10 +785,10 @@ gfxFont::GetGlyphHAdvance(gfxContext *aCtx, uint16_t aGID)
if (ProvidesGlyphWidths()) { if (ProvidesGlyphWidths()) {
return GetGlyphWidth(*aCtx->GetDrawTarget(), aGID) / 65536.0; return GetGlyphWidth(*aCtx->GetDrawTarget(), aGID) / 65536.0;
} }
if (mFUnitsConvFactor == 0.0f) { if (mFUnitsConvFactor < 0.0f) {
GetMetrics(eHorizontal); GetMetrics(eHorizontal);
} }
NS_ASSERTION(mFUnitsConvFactor > 0.0f, NS_ASSERTION(mFUnitsConvFactor >= 0.0f,
"missing font unit conversion factor"); "missing font unit conversion factor");
if (!mHarfBuzzShaper) { if (!mHarfBuzzShaper) {
mHarfBuzzShaper = new gfxHarfBuzzShaper(this); mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
@ -3215,7 +3215,7 @@ gfxFont::InitMetricsFromSfntTables(Metrics& aMetrics)
uint32_t len; uint32_t len;
if (mFUnitsConvFactor == 0.0) { if (mFUnitsConvFactor < 0.0) {
// If the conversion factor from FUnits is not yet set, // If the conversion factor from FUnits is not yet set,
// get the unitsPerEm from the 'head' table via the font entry // get the unitsPerEm from the 'head' table via the font entry
uint16_t unitsPerEm = GetFontEntry()->UnitsPerEm(); uint16_t unitsPerEm = GetFontEntry()->UnitsPerEm();
@ -3451,7 +3451,7 @@ gfxFont::CreateVerticalMetrics()
const float UNINITIALIZED_LEADING = -10000.0f; const float UNINITIALIZED_LEADING = -10000.0f;
metrics->externalLeading = UNINITIALIZED_LEADING; metrics->externalLeading = UNINITIALIZED_LEADING;
if (mFUnitsConvFactor == 0.0) { if (mFUnitsConvFactor < 0.0) {
uint16_t upem = GetFontEntry()->UnitsPerEm(); uint16_t upem = GetFontEntry()->UnitsPerEm();
if (upem != gfxFontEntry::kInvalidUPEM) { if (upem != gfxFontEntry::kInvalidUPEM) {
mFUnitsConvFactor = GetAdjustedSize() / upem; mFUnitsConvFactor = GetAdjustedSize() / upem;
@ -3462,7 +3462,7 @@ gfxFont::CreateVerticalMetrics()
#define SET_SIGNED(field,src) metrics->field = int16_t(src) * mFUnitsConvFactor #define SET_SIGNED(field,src) metrics->field = int16_t(src) * mFUnitsConvFactor
gfxFontEntry::AutoTable os2Table(mFontEntry, kOS_2TableTag); gfxFontEntry::AutoTable os2Table(mFontEntry, kOS_2TableTag);
if (os2Table && mFUnitsConvFactor > 0.0) { if (os2Table && mFUnitsConvFactor >= 0.0) {
const OS2Table *os2 = const OS2Table *os2 =
reinterpret_cast<const OS2Table*>(hb_blob_get_data(os2Table, &len)); reinterpret_cast<const OS2Table*>(hb_blob_get_data(os2Table, &len));
// These fields should always be present in any valid OS/2 table // These fields should always be present in any valid OS/2 table
@ -3488,7 +3488,7 @@ gfxFont::CreateVerticalMetrics()
// and use the line height from its ascent/descent. // and use the line height from its ascent/descent.
if (!metrics->aveCharWidth) { if (!metrics->aveCharWidth) {
gfxFontEntry::AutoTable hheaTable(mFontEntry, kHheaTableTag); gfxFontEntry::AutoTable hheaTable(mFontEntry, kHheaTableTag);
if (hheaTable && mFUnitsConvFactor > 0.0) { if (hheaTable && mFUnitsConvFactor >= 0.0) {
const MetricsHeader* hhea = const MetricsHeader* hhea =
reinterpret_cast<const MetricsHeader*> reinterpret_cast<const MetricsHeader*>
(hb_blob_get_data(hheaTable, &len)); (hb_blob_get_data(hheaTable, &len));
@ -3504,7 +3504,7 @@ gfxFont::CreateVerticalMetrics()
// Read real vertical metrics if available. // Read real vertical metrics if available.
gfxFontEntry::AutoTable vheaTable(mFontEntry, kVheaTableTag); gfxFontEntry::AutoTable vheaTable(mFontEntry, kVheaTableTag);
if (vheaTable && mFUnitsConvFactor > 0.0) { if (vheaTable && mFUnitsConvFactor >= 0.0) {
const MetricsHeader* vhea = const MetricsHeader* vhea =
reinterpret_cast<const MetricsHeader*> reinterpret_cast<const MetricsHeader*>
(hb_blob_get_data(vheaTable, &len)); (hb_blob_get_data(vheaTable, &len));

Просмотреть файл

@ -1390,7 +1390,7 @@ public:
float FUnitsToDevUnitsFactor() const { float FUnitsToDevUnitsFactor() const {
// check this was set up during font initialization // check this was set up during font initialization
NS_ASSERTION(mFUnitsConvFactor > 0.0f, "mFUnitsConvFactor not valid"); NS_ASSERTION(mFUnitsConvFactor >= 0.0f, "mFUnitsConvFactor not valid");
return mFUnitsConvFactor; return mFUnitsConvFactor;
} }
@ -2032,7 +2032,10 @@ protected:
gfxFloat mAdjustedSize; gfxFloat mAdjustedSize;
float mFUnitsConvFactor; // conversion factor from font units to dev units // Conversion factor from font units to dev units; note that this may be
// zero (in the degenerate case where mAdjustedSize has become zero).
// This is OK because we only multiply by this factor, never divide.
float mFUnitsConvFactor;
// the AA setting requested for this font - may affect glyph bounds // the AA setting requested for this font - may affect glyph bounds
AntialiasOption mAntialiasOption; AntialiasOption mAntialiasOption;

Просмотреть файл

@ -360,6 +360,8 @@ gfxGDIFont::Initialize()
} }
SanitizeMetrics(mMetrics, GetFontEntry()->mIsBadUnderlineFont); SanitizeMetrics(mMetrics, GetFontEntry()->mIsBadUnderlineFont);
} else {
mFUnitsConvFactor = 0.0; // zero-sized font: all values scale to zero
} }
if (IsSyntheticBold()) { if (IsSyntheticBold()) {