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
Родитель 20ec7ce89f
Коммит 828754d158
2 изменённых файлов: 22 добавлений и 5 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -2962,7 +2962,8 @@ nsStyleText::nsStyleText(const nsStyleText& aSource)
mTextUnderlinePosition(aSource.mTextUnderlinePosition),
mWebkitTextStrokeWidth(aSource.mWebkitTextStrokeWidth),
mTextShadow(aSource.mTextShadow),
mTextEmphasisStyle(aSource.mTextEmphasisStyle) {
mTextEmphasisStyle(aSource.mTextEmphasisStyle),
mHyphenateCharacter(aSource.mHyphenateCharacter) {
MOZ_COUNT_CTOR(nsStyleText);
}
@ -2996,7 +2997,8 @@ nsChangeHint nsStyleText::CalcDifference(const nsStyleText& aNewData) const {
(mTextIndent != aNewData.mTextIndent) ||
(mTextJustify != aNewData.mTextJustify) ||
(mWordSpacing != aNewData.mWordSpacing) ||
(mTabSize != aNewData.mTabSize)) {
(mTabSize != aNewData.mTabSize) ||
(mHyphenateCharacter != aNewData.mHyphenateCharacter)) {
return NS_STYLE_HINT_REFLOW;
}