зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1100738 - Use GetMetricsFor() to avoid many Fontconfig allocations. r=karlt.
--HG-- extra : rebase_source : 0640212684c4ef103823dff01dbcca1849daa0cf
This commit is contained in:
Родитель
9479ef0f97
Коммит
2f90e27747
|
@ -2995,16 +2995,7 @@ CanvasRenderingContext2D::SetFont(const nsAString& font,
|
|||
|
||||
const nsStyleFont* fontStyle = sc->StyleFont();
|
||||
|
||||
nsIAtom* language = fontStyle->mLanguage;
|
||||
if (!language) {
|
||||
language = presShell->GetPresContext()->GetLanguageFromCharset();
|
||||
}
|
||||
|
||||
// use CSS pixels instead of dev pixels to avoid being affected by page zoom
|
||||
const uint32_t aupcp = nsPresContext::AppUnitsPerCSSPixel();
|
||||
|
||||
bool printerFont = (presShell->GetPresContext()->Type() == nsPresContext::eContext_PrintPreview ||
|
||||
presShell->GetPresContext()->Type() == nsPresContext::eContext_Print);
|
||||
nsPresContext *c = presShell->GetPresContext();
|
||||
|
||||
// Purposely ignore the font size that respects the user's minimum
|
||||
// font preference (fontStyle->mFont.size) in favor of the computed
|
||||
|
@ -3012,28 +3003,28 @@ CanvasRenderingContext2D::SetFont(const nsAString& font,
|
|||
// https://bugzilla.mozilla.org/show_bug.cgi?id=698652.
|
||||
MOZ_ASSERT(!fontStyle->mAllowZoom,
|
||||
"expected text zoom to be disabled on this nsStyleFont");
|
||||
gfxFontStyle style(fontStyle->mFont.style,
|
||||
fontStyle->mFont.weight,
|
||||
fontStyle->mFont.stretch,
|
||||
NSAppUnitsToFloatPixels(fontStyle->mSize, float(aupcp)),
|
||||
language,
|
||||
nsFont resizedFont(fontStyle->mFont);
|
||||
// Create a font group working in units of CSS pixels instead of the usual
|
||||
// device pixels, to avoid being affected by page zoom. nsFontMetrics will
|
||||
// convert nsFont size in app units to device pixels for the font group, so
|
||||
// here we first apply to the size the equivalent of a conversion from device
|
||||
// pixels to CSS pixels, to adjust for the difference in expectations from
|
||||
// other nsFontMetrics clients.
|
||||
resizedFont.size =
|
||||
(fontStyle->mSize * c->AppUnitsPerDevPixel()) / c->AppUnitsPerCSSPixel();
|
||||
|
||||
nsRefPtr<nsFontMetrics> metrics;
|
||||
c->DeviceContext()->GetMetricsFor(resizedFont,
|
||||
fontStyle->mLanguage,
|
||||
fontStyle->mExplicitLanguage,
|
||||
fontStyle->mFont.sizeAdjust,
|
||||
fontStyle->mFont.systemFont,
|
||||
printerFont,
|
||||
fontStyle->mFont.synthesis & NS_FONT_SYNTHESIS_WEIGHT,
|
||||
fontStyle->mFont.synthesis & NS_FONT_SYNTHESIS_STYLE,
|
||||
fontStyle->mFont.languageOverride);
|
||||
gfxFont::eHorizontal,
|
||||
c->GetUserFontSet(),
|
||||
c->GetTextPerfMetrics(),
|
||||
*getter_AddRefs(metrics));
|
||||
|
||||
fontStyle->mFont.AddFontFeaturesToStyle(&style);
|
||||
|
||||
nsPresContext *c = presShell->GetPresContext();
|
||||
CurrentState().fontGroup =
|
||||
gfxPlatform::GetPlatform()->CreateFontGroup(fontStyle->mFont.fontlist,
|
||||
&style,
|
||||
c->GetUserFontSet());
|
||||
gfxFontGroup* newFontGroup = metrics->GetThebesFontGroup();
|
||||
CurrentState().fontGroup = newFontGroup;
|
||||
NS_ASSERTION(CurrentState().fontGroup, "Could not get font group");
|
||||
CurrentState().fontGroup->SetTextPerfMetrics(c->GetTextPerfMetrics());
|
||||
CurrentState().font = usedFont;
|
||||
CurrentState().fontFont = fontStyle->mFont;
|
||||
CurrentState().fontFont.size = fontStyle->mSize;
|
||||
|
|
Загрузка…
Ссылка в новой задаче