Bug 1097499 part 11 - Set width variant for text-combined frame. r=jfkthame
MozReview-Commit-ID: 60QB0PGtOKM
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -4163,48 +4163,65 @@ nsLayoutUtils::ComputeObjectDestRect(con
}
}
return nsRect(imageTopLeftPt, concreteObjectSize);
}
already_AddRefed<nsFontMetrics>
nsLayoutUtils::GetFontMetricsForFrame(const nsIFrame* aFrame, float aInflation)
{
- return GetFontMetricsForStyleContext(aFrame->StyleContext(), aInflation);
+ nsStyleContext* styleContext = aFrame->StyleContext();
+ uint8_t variantWidth = NS_FONT_VARIANT_WIDTH_NORMAL;
+ if (styleContext->IsTextCombined()) {
+ MOZ_ASSERT(aFrame->GetType() == nsGkAtoms::textFrame);
+ auto textFrame = static_cast<const nsTextFrame*>(aFrame);
+ auto clusters = textFrame->CountGraphemeClusters();
+ if (clusters == 2) {
+ variantWidth = NS_FONT_VARIANT_WIDTH_HALF;
+ } else if (clusters == 3) {
+ variantWidth = NS_FONT_VARIANT_WIDTH_THIRD;
+ } else if (clusters == 4) {
+ variantWidth = NS_FONT_VARIANT_WIDTH_QUARTER;
+ }
+ }
+ return GetFontMetricsForStyleContext(styleContext, aInflation, variantWidth);
}
already_AddRefed<nsFontMetrics>
nsLayoutUtils::GetFontMetricsForStyleContext(nsStyleContext* aStyleContext,
- float aInflation)
+ float aInflation,
+ uint8_t aVariantWidth)
{
nsPresContext* pc = aStyleContext->PresContext();
WritingMode wm(aStyleContext);
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;
// 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.
+ // When aInflation is 1.0 and we don't require width variant, 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) {
+ if (aInflation == 1.0f && aVariantWidth == NS_FONT_VARIANT_WIDTH_NORMAL) {
return pc->DeviceContext()->GetMetricsFor(styleFont->mFont, params);
}
nsFont font = styleFont->mFont;
font.size = NSToCoordRound(font.size * aInflation);
+ font.variantWidth = aVariantWidth;
return pc->DeviceContext()->GetMetricsFor(font, params);
}
nsIFrame*
nsLayoutUtils::FindChildContainingDescendant(nsIFrame* aParent, nsIFrame* aDescendantFrame)
{
nsIFrame* result = aDescendantFrame;
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -1250,17 +1250,18 @@ public:
}
/**
* Get the font metrics corresponding to the given style data.
* @param aStyleContext the style data
* @param aSizeInflation number to multiply font size by
*/
static already_AddRefed<nsFontMetrics> GetFontMetricsForStyleContext(
- nsStyleContext* aStyleContext, float aSizeInflation = 1.0f);
+ nsStyleContext* aStyleContext, float aSizeInflation = 1.0f,
+ uint8_t aVariantWidth = NS_FONT_VARIANT_WIDTH_NORMAL);
/**
* Get the font metrics of emphasis marks corresponding to the given
* style data. The result is same as GetFontMetricsForStyleContext
* except that the font size is scaled down to 50%.
* @param aStyleContext the style data
* @param aInflation number to multiple font size by
*/