Bug 1746187 - Implement rendering support for hyphenate-character. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D133890
This commit is contained in:
Jonathan Kew
2021-12-16 13:47:56 +00:00
parent 4518577c5b
commit d45a6027c4
2 changed files with 22 additions and 5 deletions

View File

@@ -2158,8 +2158,17 @@ static already_AddRefed<gfxTextRun> GetHyphenTextRun(nsTextFrame* aTextFrame,
RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetInflatedFontMetricsForFrame(aTextFrame);
return fm->GetThebesFontGroup()->MakeHyphenTextRun(
dt, aTextFrame->PresContext()->AppUnitsPerDevPixel());
auto* fontGroup = fm->GetThebesFontGroup();
auto appPerDev = aTextFrame->PresContext()->AppUnitsPerDevPixel();
const auto& hyphenateChar = aTextFrame->StyleText()->mHyphenateCharacter;
if (hyphenateChar.IsAuto()) {
return fontGroup->MakeHyphenTextRun(dt, appPerDev);
}
auto* missingFonts = aTextFrame->PresContext()->MissingFontRecorder();
const NS_ConvertUTF8toUTF16 hyphenStr(hyphenateChar.AsString().AsString());
return fontGroup->MakeTextRun(hyphenStr.BeginReading(), hyphenStr.Length(),
dt, appPerDev, gfx::ShapedTextFlags(),
nsTextFrameUtils::Flags(), missingFonts);
}
already_AddRefed<gfxTextRun> BuildTextRunsScanner::BuildTextRunForFrames(
@@ -3641,7 +3650,13 @@ void nsTextFrame::PropertyProvider::CalcTabWidths(Range aRange,
gfxFloat nsTextFrame::PropertyProvider::GetHyphenWidth() const {
if (mHyphenWidth < 0) {
mHyphenWidth = GetFontGroup()->GetHyphenWidth(this);
const auto& hyphenateChar = mTextStyle->mHyphenateCharacter;
if (hyphenateChar.IsAuto()) {
mHyphenWidth = GetFontGroup()->GetHyphenWidth(this);
} else {
RefPtr<gfxTextRun> hyphRun = GetHyphenTextRun(mFrame, nullptr);
mHyphenWidth = hyphRun ? hyphRun->GetAdvanceWidth() : 0;
}
}
return mHyphenWidth + mLetterSpacing;
}