diff options
author | Mark Hung <marklm9@gmail.com> | 2022-05-01 14:07:01 +0800 |
---|---|---|
committer | Mark Hung <marklh9@gmail.com> | 2022-05-13 01:32:22 +0200 |
commit | fb8eb0ad9c3a5957a6e131490a7a8c97e5353ba2 (patch) | |
tree | 006cf8b8ebc761142c56ff629a83168924976798 /sw/source/core/text | |
parent | 9391e9fb99a87e71897e29da79eba084682fdaa5 (diff) |
tdf#104930 aligning CTL text with hanging baseline.
1. SwTextSizeInfo::GetHangingBaseline() calls SwFont::GetHangingBaseline() to obtain the hanging baseline value. Only CTL script handled, it always return 0 for other two scripts. Eventually Outdev::GetFontMetric() and TextMetric::GetHangingBaseline() are called to obtain the hanging baseline value from vcl.
2. SwTextFormatter::CalcAscent() sets the baseline value for the portion via SwTextSizeInfo::GetHangingBaseline().
3. SwTextFormatter::InsertPortion() sets the maximum baseline value for the whole line.
4. SwTextCursor::AdjustBaseLine() calculates the new baseline in case hanging baseline is available.
Change-Id: I1aae7a34dfc953227b7873fc8e3af5cc7e2fbbff
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133668
Tested-by: Jenkins
Reviewed-by: Mark Hung <marklh9@gmail.com>
Diffstat (limited to 'sw/source/core/text')
-rw-r--r-- | sw/source/core/text/inftxt.hxx | 7 | ||||
-rw-r--r-- | sw/source/core/text/itrform2.cxx | 3 | ||||
-rw-r--r-- | sw/source/core/text/itrpaint.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/text/itrtxt.cxx | 9 | ||||
-rw-r--r-- | sw/source/core/text/porlin.cxx | 1 | ||||
-rw-r--r-- | sw/source/core/text/porlin.hxx | 5 |
6 files changed, 25 insertions, 2 deletions
diff --git a/sw/source/core/text/inftxt.hxx b/sw/source/core/text/inftxt.hxx index 7c7bf57afa56..1621b4f35a8f 100644 --- a/sw/source/core/text/inftxt.hxx +++ b/sw/source/core/text/inftxt.hxx @@ -267,6 +267,7 @@ public: vcl::text::TextLayoutCache const*) const; sal_uInt16 GetAscent() const; + sal_uInt16 GetHangingBaseline() const; TextFrameIndex GetIdx() const { return m_nIdx; } void SetIdx(const TextFrameIndex nNew) { m_nIdx = nNew; } @@ -715,6 +716,12 @@ inline sal_uInt16 SwTextSizeInfo::GetTextHeight() const return const_cast<SwFont*>(GetFont())->GetHeight( m_pVsh, *GetOut() ); } +inline sal_uInt16 SwTextSizeInfo::GetHangingBaseline() const +{ + assert(GetOut()); + return const_cast<SwFont*>(GetFont())->GetHangingBaseline( m_pVsh, *GetOut() ); +} + inline SwPosSize SwTextSizeInfo::GetTextSize( const OUString &rText ) const { return GetTextSize(m_pOut, nullptr, rText, TextFrameIndex(0), TextFrameIndex(rText.getLength())); diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index 52d13e690481..e7bcde5983b8 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -341,6 +341,8 @@ void SwTextFormatter::InsertPortion( SwTextFormatInfo &rInf, m_pCurr->Height( pPor->Height(), pPor->IsTextPortion() ); if( m_pCurr->GetAscent() < pPor->GetAscent() ) m_pCurr->SetAscent( pPor->GetAscent() ); + if( m_pCurr->GetHangingBaseline() < pPor->GetHangingBaseline() ) + m_pCurr->SetHangingBaseline( pPor->GetHangingBaseline() ); if (GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(DocumentSettingId::MS_WORD_COMP_MIN_LINE_HEIGHT_BY_FLY)) { @@ -831,6 +833,7 @@ void SwTextFormatter::CalcAscent( SwTextFormatInfo &rInf, SwLinePortion *pPor ) if( bChg || bFirstPor || !pPor->GetAscent() || !rInf.GetLast()->InTextGrp() ) { + pPor->SetHangingBaseline( rInf.GetHangingBaseline() ); pPor->SetAscent( rInf.GetAscent() ); pPor->Height( rInf.GetTextHeight() ); bCalc = true; diff --git a/sw/source/core/text/itrpaint.cxx b/sw/source/core/text/itrpaint.cxx index 7f783e40428f..3935630192dd 100644 --- a/sw/source/core/text/itrpaint.cxx +++ b/sw/source/core/text/itrpaint.cxx @@ -243,7 +243,7 @@ void SwTextPainter::DrawTextLine( const SwRect &rPaint, SwSaveClip &rClip, SwTextGridItem const*const pGrid(GetGridItem(GetTextFrame()->FindPageFrame())); const bool bAdjustBaseLine = GetLineInfo().HasSpecialAlign( GetTextFrame()->IsVertical() ) || - ( nullptr != pGrid ); + ( nullptr != pGrid ) || m_pCurr->GetHangingBaseline(); const SwTwips nLineBaseLine = GetInfo().GetPos().Y() + nTmpAscent; if ( ! bAdjustBaseLine ) GetInfo().Y( nLineBaseLine ); diff --git a/sw/source/core/text/itrtxt.cxx b/sw/source/core/text/itrtxt.cxx index 8fb8334a83fa..53e084b03736 100644 --- a/sw/source/core/text/itrtxt.cxx +++ b/sw/source/core/text/itrtxt.cxx @@ -289,7 +289,14 @@ SwTwips SwTextCursor::AdjustBaseLine( const SwLineLayout& rLine, [[fallthrough]]; case SvxParaVertAlignItem::Align::Baseline : // base line - nOfst = nOfst + rLine.GetAscent(); + if (pPor && pPor->GetHangingBaseline()) + { + nOfst += rLine.GetAscent() // Romn baseline of the line. + - rLine.GetHangingBaseline() // Hanging baseline of the line. + + pPor->GetHangingBaseline(); // Romn baseline of the portion. + } + else + nOfst = nOfst + rLine.GetAscent(); break; } } diff --git a/sw/source/core/text/porlin.cxx b/sw/source/core/text/porlin.cxx index d7b3a1a41e5b..d2e95e88249a 100644 --- a/sw/source/core/text/porlin.cxx +++ b/sw/source/core/text/porlin.cxx @@ -67,6 +67,7 @@ SwLinePortion::SwLinePortion( ) : mpNextPortion( nullptr ), mnLineLength( 0 ), mnAscent( 0 ), + mnHangingBaseline( 0 ), mnWhichPor( PortionType::NONE ), m_bJoinBorderWithPrev(false), m_bJoinBorderWithNext(false) diff --git a/sw/source/core/text/porlin.hxx b/sw/source/core/text/porlin.hxx index fb820f9bc577..3cd1d9fff942 100644 --- a/sw/source/core/text/porlin.hxx +++ b/sw/source/core/text/porlin.hxx @@ -56,6 +56,7 @@ protected: // Count of chars and spaces on the line TextFrameIndex mnLineLength; SwTwips mnAscent; // Maximum ascender + SwTwips mnHangingBaseline; SwLinePortion(); private: @@ -82,6 +83,8 @@ public: SwTwips PrtWidth() const { return Width(); } void AddPrtWidth( const SwTwips nNew ) { Width( Width() + nNew ); } void SubPrtWidth( const SwTwips nNew ) { Width( Width() - nNew ); } + SwTwips GetHangingBaseline() const { return mnHangingBaseline; } + void SetHangingBaseline( const SwTwips nNewBaseline ) { mnHangingBaseline = nNewBaseline; } // Insert methods virtual SwLinePortion *Insert( SwLinePortion *pPortion ); @@ -184,6 +187,7 @@ inline SwLinePortion &SwLinePortion::operator=(const SwLinePortion &rPortion) *static_cast<SwPosSize*>(this) = rPortion; mnLineLength = rPortion.mnLineLength; mnAscent = rPortion.mnAscent; + mnHangingBaseline = rPortion.mnHangingBaseline; mnWhichPor = rPortion.mnWhichPor; m_bJoinBorderWithPrev = rPortion.m_bJoinBorderWithPrev; m_bJoinBorderWithNext = rPortion.m_bJoinBorderWithNext; @@ -195,6 +199,7 @@ inline SwLinePortion::SwLinePortion(const SwLinePortion &rPortion) : mpNextPortion( nullptr ), mnLineLength( rPortion.mnLineLength ), mnAscent( rPortion.mnAscent ), + mnHangingBaseline( rPortion.mnHangingBaseline ), mnWhichPor( rPortion.mnWhichPor ), m_bJoinBorderWithPrev( rPortion.m_bJoinBorderWithPrev ), m_bJoinBorderWithNext( rPortion.m_bJoinBorderWithNext ) |