Bug 1099977. Part 1: Make gfxDwriteFont cache GetSpaceGlyph. r=jfkthame

--HG--
extra : rebase_source : b658f532dfef60d68c2d3f4aeae08de9966033ed
This commit is contained in:
Robert O'Callahan 2014-11-18 23:19:54 +13:00
parent fd4c0662da
commit 6630278821
2 changed files with 13 additions and 11 deletions

View File

@ -75,6 +75,7 @@ gfxDWriteFont::gfxDWriteFont(gfxFontEntry *aFontEntry,
: gfxFont(aFontEntry, aFontStyle, anAAOption)
, mCairoFontFace(nullptr)
, mMetrics(nullptr)
, mSpaceGlyph(0)
, mNeedsOblique(false)
, mNeedsBold(aNeedsBold)
, mUseSubpixelPositions(false)
@ -228,8 +229,15 @@ gfxDWriteFont::ComputeMetrics(AntialiasOption anAAOption)
mMetrics->internalLeading = std::max(mMetrics->maxHeight - mMetrics->emHeight, 0.0);
mMetrics->externalLeading = ceil(fontMetrics.lineGap * mFUnitsConvFactor);
UINT16 glyph = (uint16_t)GetSpaceGlyph();
mMetrics->spaceWidth = MeasureGlyphWidth(glyph);
UINT32 ucs = L' ';
UINT16 glyph;
HRESULT hr = mFontFace->GetGlyphIndicesA(&ucs, 1, &glyph);
if (FAILED(hr)) {
mMetrics->spaceWidth = 0;
} else {
mSpaceGlyph = glyph;
mMetrics->spaceWidth = MeasureGlyphWidth(glyph);
}
// try to get aveCharWidth from the OS/2 table, fall back to measuring 'x'
// if the table is not available or if using hinted/pixel-snapped widths
@ -251,7 +259,6 @@ gfxDWriteFont::ComputeMetrics(AntialiasOption anAAOption)
}
}
UINT32 ucs;
if (mMetrics->aveCharWidth < 1) {
ucs = L'x';
if (SUCCEEDED(mFontFace->GetGlyphIndicesA(&ucs, 1, &glyph))) {
@ -442,14 +449,7 @@ gfxDWriteFont::HasBitmapStrikeForSize(uint32_t aSize)
uint32_t
gfxDWriteFont::GetSpaceGlyph()
{
UINT32 ucs = L' ';
UINT16 glyph;
HRESULT hr;
hr = mFontFace->GetGlyphIndicesA(&ucs, 1, &glyph);
if (FAILED(hr)) {
return 0;
}
return glyph;
return mSpaceGlyph;
}
bool

View File

@ -98,6 +98,8 @@ protected:
// cache of glyph widths in 16.16 fixed-point pixels
nsAutoPtr<nsDataHashtable<nsUint32HashKey,int32_t> > mGlyphWidths;
uint32_t mSpaceGlyph;
bool mNeedsOblique;
bool mNeedsBold;
bool mUseSubpixelPositions;