diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index b371be19b4ed..25668c11f714 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -2468,12 +2468,13 @@ public: virtual float GetExLength() const override { - gfxTextPerfMetrics* tp = mPresContext->GetTextPerfMetrics(); RefPtr fontMetrics; nsDeviceContext* dc = mPresContext->DeviceContext(); - dc->GetMetricsFor(mFont, mFontLanguage, mExplicitLanguage, - gfxFont::eHorizontal, nullptr, tp, - *getter_AddRefs(fontMetrics)); + nsFontMetrics::Params params; + params.language = mFontLanguage; + params.explicitLanguage = mExplicitLanguage; + params.textPerf = mPresContext->GetTextPerfMetrics(); + dc->GetMetricsFor(mFont, params, *getter_AddRefs(fontMetrics)); return NSAppUnitsToFloatPixels(fontMetrics->XHeight(), nsPresContext::AppUnitsPerCSSPixel()); } @@ -3230,13 +3231,13 @@ CanvasRenderingContext2D::SetFontInternal(const nsAString& aFont, resizedFont.size = (fontStyle->mSize * c->AppUnitsPerDevPixel()) / c->AppUnitsPerCSSPixel(); + nsFontMetrics::Params params; + params.language = fontStyle->mLanguage; + params.explicitLanguage = fontStyle->mExplicitLanguage; + params.userFontSet = c->GetUserFontSet(); + params.textPerf = c->GetTextPerfMetrics(); RefPtr metrics; - c->DeviceContext()->GetMetricsFor(resizedFont, - fontStyle->mLanguage, - fontStyle->mExplicitLanguage, - gfxFont::eHorizontal, - c->GetUserFontSet(), - c->GetTextPerfMetrics(), + c->DeviceContext()->GetMetricsFor(resizedFont, params, *getter_AddRefs(metrics)); gfxFontGroup* newFontGroup = metrics->GetThebesFontGroup(); diff --git a/gfx/src/nsDeviceContext.cpp b/gfx/src/nsDeviceContext.cpp index 8948c588e394..3f53382235df 100644 --- a/gfx/src/nsDeviceContext.cpp +++ b/gfx/src/nsDeviceContext.cpp @@ -65,10 +65,7 @@ public: void Destroy(); nsresult GetMetricsFor(const nsFont& aFont, - nsIAtom* aLanguage, bool aExplicitLanguage, - gfxFont::Orientation aOrientation, - gfxUserFontSet* aUserFontSet, - gfxTextPerfMetrics* aTextPerf, + const nsFontMetrics::Params& aParams, nsFontMetrics*& aMetrics); void FontMetricsDeleted(const nsFontMetrics* aFontMetrics); @@ -127,14 +124,11 @@ nsFontCache::Observe(nsISupports*, const char* aTopic, const char16_t*) nsresult nsFontCache::GetMetricsFor(const nsFont& aFont, - nsIAtom* aLanguage, bool aExplicitLanguage, - gfxFont::Orientation aOrientation, - gfxUserFontSet* aUserFontSet, - gfxTextPerfMetrics* aTextPerf, + const nsFontMetrics::Params& aParams, nsFontMetrics*& aMetrics) { - if (!aLanguage) - aLanguage = mLocaleLanguage; + nsIAtom* language = aParams.language ? aParams.language + : mLocaleLanguage.get(); // First check our cache // start from the end, which is where we put the most-recent-used element @@ -143,8 +137,10 @@ nsFontCache::GetMetricsFor(const nsFont& aFont, int32_t n = mFontMetrics.Length() - 1; for (int32_t i = n; i >= 0; --i) { fm = mFontMetrics[i]; - if (fm->Font().Equals(aFont) && fm->GetUserFontSet() == aUserFontSet && - fm->Language() == aLanguage && fm->Orientation() == aOrientation) { + if (fm->Font().Equals(aFont) && + fm->GetUserFontSet() == aParams.userFontSet && + fm->Language() == language && + fm->Orientation() == aParams.orientation) { if (i != n) { // promote it to the end of the cache mFontMetrics.RemoveElementAt(i); @@ -158,10 +154,11 @@ nsFontCache::GetMetricsFor(const nsFont& aFont, // It's not in the cache. Get font metrics and then cache them. + nsFontMetrics::Params params = aParams; + params.language = language; fm = new nsFontMetrics(); NS_ADDREF(fm); - nsresult rv = fm->Init(aFont, aLanguage, aExplicitLanguage, aOrientation, - mContext, aUserFontSet, aTextPerf); + nsresult rv = fm->Init(aFont, params, mContext); if (NS_SUCCEEDED(rv)) { // the mFontMetrics list has the "head" at the end, because append // is cheaper than insert @@ -180,8 +177,7 @@ nsFontCache::GetMetricsFor(const nsFont& aFont, Compact(); fm = new nsFontMetrics(); NS_ADDREF(fm); - rv = fm->Init(aFont, aLanguage, aExplicitLanguage, aOrientation, mContext, - aUserFontSet, aTextPerf); + rv = fm->Init(aFont, params, mContext); if (NS_SUCCEEDED(rv)) { mFontMetrics.AppendElement(fm); aMetrics = fm; @@ -268,11 +264,7 @@ nsDeviceContext::~nsDeviceContext() nsresult nsDeviceContext::GetMetricsFor(const nsFont& aFont, - nsIAtom* aLanguage, - bool aExplicitLanguage, - gfxFont::Orientation aOrientation, - gfxUserFontSet* aUserFontSet, - gfxTextPerfMetrics* aTextPerf, + const nsFontMetrics::Params& aParams, nsFontMetrics*& aMetrics) { if (!mFontCache) { @@ -281,9 +273,7 @@ nsDeviceContext::GetMetricsFor(const nsFont& aFont, mFontCache->Init(this); } - return mFontCache->GetMetricsFor(aFont, aLanguage, aExplicitLanguage, - aOrientation, aUserFontSet, aTextPerf, - aMetrics); + return mFontCache->GetMetricsFor(aFont, aParams, aMetrics); } nsresult diff --git a/gfx/src/nsDeviceContext.h b/gfx/src/nsDeviceContext.h index 401b0c56ee7a..40377324b4a1 100644 --- a/gfx/src/nsDeviceContext.h +++ b/gfx/src/nsDeviceContext.h @@ -19,6 +19,7 @@ #include "nsMathUtils.h" // for NS_round #include "nscore.h" // for char16_t, nsAString #include "mozilla/AppUnits.h" // for AppUnits +#include "nsFontMetrics.h" // for nsFontMetrics::Params class gfxASurface; class gfxContext; @@ -26,7 +27,6 @@ class gfxTextPerfMetrics; class gfxUserFontSet; struct nsFont; class nsFontCache; -class nsFontMetrics; class nsIAtom; class nsIDeviceContextSpec; class nsIScreen; @@ -113,16 +113,11 @@ public: * Get the nsFontMetrics that describe the properties of * an nsFont. * @param aFont font description to obtain metrics for - * @param aLanguage the language of the document * @param aMetrics out parameter for font metrics - * @param aUserFontSet user font set * @return error status */ nsresult GetMetricsFor(const nsFont& aFont, - nsIAtom* aLanguage, bool aExplicitLanguage, - gfxFont::Orientation aOrientation, - gfxUserFontSet* aUserFontSet, - gfxTextPerfMetrics* aTextPerf, + const nsFontMetrics::Params& aParams, nsFontMetrics*& aMetrics); /** diff --git a/gfx/src/nsFontMetrics.cpp b/gfx/src/nsFontMetrics.cpp index 9b18e9882d2e..6ec85f733260 100644 --- a/gfx/src/nsFontMetrics.cpp +++ b/gfx/src/nsFontMetrics.cpp @@ -121,18 +121,14 @@ nsFontMetrics::~nsFontMetrics() } nsresult -nsFontMetrics::Init(const nsFont& aFont, - nsIAtom* aLanguage, bool aExplicitLanguage, - gfxFont::Orientation aOrientation, - nsDeviceContext *aContext, - gfxUserFontSet *aUserFontSet, - gfxTextPerfMetrics *aTextPerf) +nsFontMetrics::Init(const nsFont& aFont, const Params& aParams, + nsDeviceContext *aContext) { MOZ_ASSERT(mP2A == 0, "already initialized"); mFont = aFont; - mLanguage = aLanguage; - mOrientation = aOrientation; + mLanguage = aParams.language; + mOrientation = aParams.orientation; mDeviceContext = aContext; mP2A = mDeviceContext->AppUnitsPerDevPixel(); @@ -140,8 +136,8 @@ nsFontMetrics::Init(const nsFont& aFont, aFont.weight, aFont.stretch, gfxFloat(aFont.size) / mP2A, - aLanguage, - aExplicitLanguage, + aParams.language, + aParams.explicitLanguage, aFont.sizeAdjust, aFont.systemFont, mDeviceContext->IsPrinterSurface(), @@ -154,8 +150,8 @@ nsFontMetrics::Init(const nsFont& aFont, gfxFloat devToCssSize = gfxFloat(mP2A) / gfxFloat(mDeviceContext->AppUnitsPerCSSPixel()); mFontGroup = gfxPlatform::GetPlatform()-> - CreateFontGroup(aFont.fontlist, &style, aTextPerf, - aUserFontSet, devToCssSize); + CreateFontGroup(aFont.fontlist, &style, aParams.textPerf, + aParams.userFontSet, devToCssSize); return NS_OK; } diff --git a/gfx/src/nsFontMetrics.h b/gfx/src/nsFontMetrics.h index 0c38818f8b01..87bd0c0ca550 100644 --- a/gfx/src/nsFontMetrics.h +++ b/gfx/src/nsFontMetrics.h @@ -49,6 +49,15 @@ public: typedef gfxTextRun::Range Range; typedef mozilla::gfx::DrawTarget DrawTarget; + struct Params + { + nsIAtom* language = nullptr; + bool explicitLanguage = false; + gfxFont::Orientation orientation = gfxFont::eHorizontal; + gfxUserFontSet* userFontSet = nullptr; + gfxTextPerfMetrics* textPerf = nullptr; + }; + nsFontMetrics(); NS_INLINE_DECL_REFCOUNTING(nsFontMetrics) @@ -56,15 +65,9 @@ public: /** * Initialize the font metrics. Call this after creating the font metrics. * Font metrics you get from the font cache do NOT need to be initialized - * - * @see nsDeviceContext#GetMetricsFor() */ - nsresult Init(const nsFont& aFont, - nsIAtom* aLanguage, bool aExplicitLanguage, - gfxFont::Orientation aOrientation, - nsDeviceContext *aContext, - gfxUserFontSet *aUserFontSet, - gfxTextPerfMetrics *aTextPerf); + nsresult Init(const nsFont& aFont, const Params& aParams, + nsDeviceContext *aContext); /** * Destroy this font metrics. This breaks the association between diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index c11f139d35cd..8f9c502d438a 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -4039,36 +4039,33 @@ nsLayoutUtils::GetFontMetricsForStyleContext(nsStyleContext* aStyleContext, nsFontMetrics** aFontMetrics, float aInflation) { - // pass the user font set object into the device context to pass along to CreateFontGroup nsPresContext* pc = aStyleContext->PresContext(); - gfxUserFontSet* fs = pc->GetUserFontSet(); - gfxTextPerfMetrics* tp = pc->GetTextPerfMetrics(); WritingMode wm(aStyleContext); - gfxFont::Orientation orientation = + const nsStyleFont* styleFont = aStyleContext->StyleFont(); + nsFontMetrics::Params params; + params.language = styleFont->mLanguage; + params.explicitLanguage = styleFont->mExplicitLanguage; + params.orientation = wm.IsVertical() && !wm.IsSideways() ? gfxFont::eVertical : gfxFont::eHorizontal; - - const nsStyleFont* styleFont = aStyleContext->StyleFont(); + // pass the user font set object into the device context to + // pass along to CreateFontGroup + params.userFontSet = pc->GetUserFontSet(); + params.textPerf = pc->GetTextPerfMetrics(); // When aInflation is 1.0, avoid making a local copy of the nsFont. // This also avoids running font.size through floats when it is large, // which would be lossy. Fortunately, in such cases, aInflation is // guaranteed to be 1.0f. if (aInflation == 1.0f) { - return pc->DeviceContext()->GetMetricsFor(styleFont->mFont, - styleFont->mLanguage, - styleFont->mExplicitLanguage, - orientation, fs, tp, + return pc->DeviceContext()->GetMetricsFor(styleFont->mFont, params, *aFontMetrics); } nsFont font = styleFont->mFont; font.size = NSToCoordRound(font.size * aInflation); - return pc->DeviceContext()->GetMetricsFor(font, styleFont->mLanguage, - styleFont->mExplicitLanguage, - orientation, fs, tp, - *aFontMetrics); + return pc->DeviceContext()->GetMetricsFor(font, params, *aFontMetrics); } nsIFrame* diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 1ff1f29c5b47..6c183438d872 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -10341,10 +10341,12 @@ void ReflowCountMgr::PaintCount(const char* aName, // We don't care about the document language or user fonts here; // just get a default Latin font. nsFont font(eFamily_serif, nsPresContext::CSSPixelsToAppUnits(11)); + nsFontMetrics::Params params; + params.language = nsGkAtoms::x_western; + params.textPerf = aPresContext->GetTextPerfMetrics(); RefPtr fm; - aPresContext->DeviceContext()->GetMetricsFor(font, - nsGkAtoms::x_western, false, gfxFont::eHorizontal, nullptr, - aPresContext->GetTextPerfMetrics(), *getter_AddRefs(fm)); + aPresContext->DeviceContext()-> + GetMetricsFor(font, params, *getter_AddRefs(fm)); char buf[16]; int len = snprintf_literal(buf, "%d", counter->mCount); diff --git a/layout/generic/MathMLTextRunFactory.cpp b/layout/generic/MathMLTextRunFactory.cpp index 3f7337f0d9bf..ea7a28a97d12 100644 --- a/layout/generic/MathMLTextRunFactory.cpp +++ b/layout/generic/MathMLTextRunFactory.cpp @@ -741,14 +741,13 @@ MathMLTextRunFactory::RebuildTextRun(nsTransformedTextRun* aTextRun, if (length) { font.size = NSToCoordRound(font.size * mFontInflation); nsPresContext* pc = styles[0]->mPresContext; + nsFontMetrics::Params params; + params.language = styles[0]->mLanguage; + params.explicitLanguage = styles[0]->mExplicitLanguage; + params.userFontSet = pc->GetUserFontSet(); + params.textPerf = pc->GetTextPerfMetrics(); RefPtr metrics; - pc->DeviceContext()->GetMetricsFor(font, - styles[0]->mLanguage, - styles[0]->mExplicitLanguage, - gfxFont::eHorizontal, - pc->GetUserFontSet(), - pc->GetTextPerfMetrics(), - *getter_AddRefs(metrics)); + pc->DeviceContext()->GetMetricsFor(font, params, *getter_AddRefs(metrics)); if (metrics) { newFontGroup = metrics->GetThebesFontGroup(); } diff --git a/layout/generic/nsPageFrame.cpp b/layout/generic/nsPageFrame.cpp index bdf6a615ae9c..16bf48986a2b 100644 --- a/layout/generic/nsPageFrame.cpp +++ b/layout/generic/nsPageFrame.cpp @@ -630,11 +630,11 @@ nsPageFrame::PaintHeaderFooter(nsRenderingContext& aRenderingContext, disable(aRenderingContext.GetDrawTarget(), aDisableSubpixelAA); // Get the FontMetrics to determine width.height of strings + nsFontMetrics::Params params; + params.userFontSet = pc->GetUserFontSet(); + params.textPerf = pc->GetTextPerfMetrics(); RefPtr fontMet; - pc->DeviceContext()->GetMetricsFor(mPD->mHeadFootFont, nullptr, false, - gfxFont::eHorizontal, - pc->GetUserFontSet(), - pc->GetTextPerfMetrics(), + pc->DeviceContext()->GetMetricsFor(mPD->mHeadFootFont, params, *getter_AddRefs(fontMet)); nscoord ascent = 0; diff --git a/layout/mathml/nsMathMLChar.cpp b/layout/mathml/nsMathMLChar.cpp index 3f52b29f39d8..341edd1886ac 100644 --- a/layout/mathml/nsMathMLChar.cpp +++ b/layout/mathml/nsMathMLChar.cpp @@ -991,15 +991,14 @@ nsMathMLChar::SetFontFamily(nsPresContext* aPresContext, nsFont font = aFont; font.fontlist = familyList; const nsStyleFont* styleFont = mStyleContext->StyleFont(); + nsFontMetrics::Params params; + params.language = styleFont->mLanguage; + params.explicitLanguage = styleFont->mExplicitLanguage; + params.userFontSet = aPresContext->GetUserFontSet(); + params.textPerf = aPresContext->GetTextPerfMetrics(); RefPtr fm; aPresContext->DeviceContext()-> - GetMetricsFor(font, - styleFont->mLanguage, - styleFont->mExplicitLanguage, - gfxFont::eHorizontal, - aPresContext->GetUserFontSet(), - aPresContext->GetTextPerfMetrics(), - *getter_AddRefs(fm)); + GetMetricsFor(font, params, *getter_AddRefs(fm)); // Set the font if it is an unicode table // or if the same family name has been found gfxFont *firstFont = fm->GetThebesFontGroup()->GetFirstValidFont(); @@ -1533,15 +1532,14 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext, NormalizeDefaultFont(font, aFontSizeInflation); const nsStyleFont* styleFont = mStyleContext->StyleFont(); + nsFontMetrics::Params params; + params.language = styleFont->mLanguage; + params.explicitLanguage = styleFont->mExplicitLanguage; + params.userFontSet = aPresContext->GetUserFontSet(); + params.textPerf = aPresContext->GetTextPerfMetrics(); RefPtr fm; aPresContext->DeviceContext()-> - GetMetricsFor(font, - styleFont->mLanguage, - styleFont->mExplicitLanguage, - gfxFont::eHorizontal, - aPresContext->GetUserFontSet(), - aPresContext->GetTextPerfMetrics(), - *getter_AddRefs(fm)); + GetMetricsFor(font, params, *getter_AddRefs(fm)); uint32_t len = uint32_t(mData.Length()); nsAutoPtr textRun; textRun = fm->GetThebesFontGroup()-> diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 566058f19d57..940a50d40ae7 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -321,11 +321,6 @@ GetMetricsFor(nsPresContext* aPresContext, { nsFont font = aStyleFont->mFont; font.size = aFontSize; - gfxUserFontSet *fs = nullptr; - if (aUseUserFontSet) { - fs = aPresContext->GetUserFontSet(); - } - gfxTextPerfMetrics *tp = aPresContext->GetTextPerfMetrics(); gfxFont::Orientation orientation = gfxFont::eHorizontal; if (aStyleContext) { WritingMode wm(aStyleContext); @@ -333,12 +328,16 @@ GetMetricsFor(nsPresContext* aPresContext, orientation = gfxFont::eVertical; } } + nsFontMetrics::Params params; + params.language = aStyleFont->mLanguage; + params.explicitLanguage = aStyleFont->mExplicitLanguage; + params.orientation = orientation; + params.userFontSet = + aUseUserFontSet ? aPresContext->GetUserFontSet() : nullptr; + params.textPerf = aPresContext->GetTextPerfMetrics(); RefPtr fm; - aPresContext->DeviceContext()->GetMetricsFor(font, - aStyleFont->mLanguage, - aStyleFont->mExplicitLanguage, - orientation, - fs, tp, *getter_AddRefs(fm)); + aPresContext->DeviceContext()-> + GetMetricsFor(font, params, *getter_AddRefs(fm)); return fm.forget(); }