From 828754d15850550b1fd4ded83f3e58fa4230f6c0 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Thu, 16 Dec 2021 13:47:56 +0000 Subject: [PATCH] Bug 1746187 - Implement rendering support for hyphenate-character. r=emilio Differential Revision: https://phabricator.services.mozilla.com/D133890 --- layout/generic/nsTextFrame.cpp | 21 ++++++++++++++++++--- layout/style/nsStyleStruct.cpp | 6 ++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 3dad4e5d3991..f8119b4f8584 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -2158,8 +2158,17 @@ static already_AddRefed GetHyphenTextRun(nsTextFrame* aTextFrame, RefPtr 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 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 hyphRun = GetHyphenTextRun(mFrame, nullptr); + mHyphenWidth = hyphRun ? hyphRun->GetAdvanceWidth() : 0; + } } return mHyphenWidth + mLetterSpacing; } diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index 149c6ff3333c..36b08fde30d9 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -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; }