diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-10-31 13:28:27 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-11-03 07:24:22 +0100 |
commit | 4c349be1d74c669e5804c3c43f3f0a3960c88bc5 (patch) | |
tree | eb89aec9996cffa1bc281071e7b20fba956b77db /editeng/source | |
parent | 643fec7cf7a81bf8c89a8efd47c0310b38f9076c (diff) |
fix rendering of text when "fit to frame" is enabled
This changes the nStretchX and nStretchY from sal_uInt16 to double
so the text in text boxes is rendered correctly (text should be
resized to the same size as the textbox).
Change-Id: Ic92d03043af0abe86f1b67ae15522d0176ebb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142064
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'editeng/source')
-rw-r--r-- | editeng/source/editeng/editeng.cxx | 4 | ||||
-rw-r--r-- | editeng/source/editeng/editobj.cxx | 6 | ||||
-rw-r--r-- | editeng/source/editeng/editobj2.hxx | 10 | ||||
-rw-r--r-- | editeng/source/editeng/impedit.hxx | 30 | ||||
-rw-r--r-- | editeng/source/editeng/impedit2.cxx | 4 | ||||
-rw-r--r-- | editeng/source/editeng/impedit3.cxx | 41 | ||||
-rw-r--r-- | editeng/source/editeng/impedit4.cxx | 6 | ||||
-rw-r--r-- | editeng/source/outliner/outlin2.cxx | 7 | ||||
-rw-r--r-- | editeng/source/outliner/outliner.cxx | 12 |
9 files changed, 58 insertions, 62 deletions
diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx index 88bc04a9efed..c8a66d0470a4 100644 --- a/editeng/source/editeng/editeng.cxx +++ b/editeng/source/editeng/editeng.cxx @@ -2266,12 +2266,12 @@ bool EditEngine::HasText( const SvxSearchItem& rSearchItem ) return pImpEditEngine->HasText( rSearchItem ); } -void EditEngine::SetGlobalCharStretching( sal_uInt16 nX, sal_uInt16 nY ) +void EditEngine::SetGlobalCharStretching(double nX, double nY) { pImpEditEngine->SetCharStretching( nX, nY ); } -void EditEngine::GetGlobalCharStretching( sal_uInt16& rX, sal_uInt16& rY ) const +void EditEngine::GetGlobalCharStretching(double& rX, double& rY) const { pImpEditEngine->GetCharStretching( rX, rY ); } diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx index 6d57c7497c2b..437754d70def 100644 --- a/editeng/source/editeng/editobj.cxx +++ b/editeng/source/editeng/editobj.cxx @@ -71,10 +71,10 @@ void XEditAttribute::SetItem(const SfxPoolItem& rNew) } XParaPortionList::XParaPortionList( - OutputDevice* pRefDev, sal_uInt32 nPW, sal_uInt16 _nStretchX, sal_uInt16 _nStretchY) + OutputDevice* pRefDev, sal_uInt32 nPW, double nStretchX, double nStretchY) : pRefDevPtr(pRefDev) - , nStretchX(_nStretchX) - , nStretchY(_nStretchY) + , mnStretchX(nStretchX) + , mnStretchY(nStretchY) , nPaperWidth(nPW) { } diff --git a/editeng/source/editeng/editobj2.hxx b/editeng/source/editeng/editobj2.hxx index 250341fd4283..86a2e379be20 100644 --- a/editeng/source/editeng/editobj2.hxx +++ b/editeng/source/editeng/editobj2.hxx @@ -94,12 +94,12 @@ class XParaPortionList ListType maList; VclPtr<OutputDevice> pRefDevPtr; - sal_uInt16 nStretchX; - sal_uInt16 nStretchY; + double mnStretchX; + double mnStretchY; sal_uInt32 nPaperWidth; public: - XParaPortionList(OutputDevice* pRefDev, sal_uInt32 nPW, sal_uInt16 _nStretchX, sal_uInt16 _nStretchY); + XParaPortionList(OutputDevice* pRefDev, sal_uInt32 nPW, double nStretchX, double nStretchY); void push_back(XParaPortion* p); const XParaPortion& operator[](size_t i) const; @@ -108,8 +108,8 @@ public: sal_uInt32 GetPaperWidth() const { return nPaperWidth; } bool RefDevIsVirtual() const {return pRefDevPtr->IsVirtual();} const MapMode& GetRefMapMode() const { return pRefDevPtr->GetMapMode(); } - sal_uInt16 GetStretchX() const { return nStretchX; } - sal_uInt16 GetStretchY() const { return nStretchY; } + double GetStretchX() const { return mnStretchX; } + double GetStretchY() const { return mnStretchY; } }; class ContentInfo diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index b761e3bc4135..f75e71b7f509 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -528,8 +528,8 @@ private: Color maBackgroundColor; - sal_uInt16 nStretchX; - sal_uInt16 nStretchY; + double mnStretchX; + double mnStretchY; CharCompressType nAsianCompressionMode; @@ -1080,8 +1080,8 @@ public: SvxCellJustifyMethod GetJustifyMethod( sal_Int32 nPara ) const; SvxCellVerJustify GetVerJustification( sal_Int32 nPara ) const; - void SetCharStretching( sal_uInt16 nX, sal_uInt16 nY ); - inline void GetCharStretching( sal_uInt16& rX, sal_uInt16& rY ) const; + void SetCharStretching(double nX, double nY); + inline void GetCharStretching(double& rX, double& rY) const; sal_Int32 GetBigTextObjectStart() const { return nBigTextObjectStart; } @@ -1282,43 +1282,43 @@ inline ParaPortion* ImpEditEngine::FindParaPortion( ContentNode const * pNode ) return GetParaPortions()[ nPos ]; } -inline void ImpEditEngine::GetCharStretching( sal_uInt16& rX, sal_uInt16& rY ) const +inline void ImpEditEngine::GetCharStretching(double& rX, double& rY) const { - rX = nStretchX; - rY = nStretchY; + rX = mnStretchX; + rY = mnStretchY; } inline short ImpEditEngine::GetXValue( short nXValue ) const { - if ( !aStatus.DoStretch() || ( nStretchX == 100 ) ) + if ( !aStatus.DoStretch() || ( mnStretchX == 100.0 ) ) return nXValue; - return static_cast<short>(static_cast<tools::Long>(nXValue)*nStretchX/100); + return basegfx::fround(double(nXValue) * mnStretchX / 100.0); } inline tools::Long ImpEditEngine::GetXValue( tools::Long nXValue ) const { - if ( !aStatus.DoStretch() || ( nStretchX == 100 ) ) + if ( !aStatus.DoStretch() || ( mnStretchX == 100.0 ) ) return nXValue; - return nXValue*nStretchX/100; + return basegfx::fround(nXValue * mnStretchX / 100.0); } inline short ImpEditEngine::GetYValue( short nYValue ) const { - if ( !aStatus.DoStretch() || ( nStretchY == 100 ) ) + if ( !aStatus.DoStretch() || ( mnStretchY == 100.0 ) ) return nYValue; - return static_cast<short>(static_cast<tools::Long>(nYValue)*nStretchY/100); + return basegfx::fround(double(nYValue) * mnStretchY / 100.0); } inline sal_uInt16 ImpEditEngine::GetYValue( sal_uInt16 nYValue ) const { - if ( !aStatus.DoStretch() || ( nStretchY == 100 ) ) + if ( !aStatus.DoStretch() || ( mnStretchY == 100.0 ) ) return nYValue; - return static_cast<sal_uInt16>(static_cast<tools::Long>(nYValue)*nStretchY/100); + return basegfx::fround(double(nYValue) * mnStretchY / 100.0); } inline PointerStyle ImpEditView::GetPointer() diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index 455587bac4a6..c7df8af33337 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -98,8 +98,8 @@ ImpEditEngine::ImpEditEngine( EditEngine* pEE, SfxItemPool* pItemPool ) : pUndoManager(nullptr), aWordDelimiters(" .,;:-`'?!_=\"{}()[]"), maBackgroundColor(COL_AUTO), - nStretchX(100), - nStretchY(100), + mnStretchX(100.0), + mnStretchY(100.0), nAsianCompressionMode(CharCompressType::NONE), eDefaultHorizontalTextDirection(EEHorizontalTextDirection::Default), nBigTextObjectStart(20), diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index 3f0418dc7505..f932fd0df8ed 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -1050,8 +1050,8 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) // Search for Tab-Pos... tools::Long nCurPos = nTmpWidth+nStartX; // consider scaling - if ( aStatus.DoStretch() && ( nStretchX != 100 ) ) - nCurPos = nCurPos*100/std::max(static_cast<sal_Int32>(nStretchX), static_cast<sal_Int32>(1)); + if ( aStatus.DoStretch() && ( mnStretchX != 100.0 ) ) + nCurPos = basegfx::fround(double(nCurPos) * 100.0 / std::max(mnStretchX, 1.0)); short nAllSpaceBeforeText = static_cast< short >(rLRItem.GetTextLeft()/* + rLRItem.GetTextLeft()*/ + nSpaceBeforeAndMinLabelWidth); aCurrentTab.aTabStop = pNode->GetContentAttribs().FindTabStop( nCurPos - nAllSpaceBeforeText /*rLRItem.GetTextLeft()*/, aEditDoc.GetDefTab() ); @@ -2982,22 +2982,21 @@ void ImpEditEngine::SeekCursor( ContentNode* pNode, sal_Int32 nPos, SvxFont& rFo if ( aStatus.DoStretch() ) { - if ( nStretchY != 100 ) + if (mnStretchY != 100.0) { - aRealSz.setHeight( aRealSz.Height() * nStretchY ); - aRealSz.setHeight( aRealSz.Height() / 100 ); + double fNewHeight = (double(aRealSz.Height()) * mnStretchY) / 100.0; + aRealSz.setHeight(basegfx::fround(fNewHeight)); } - if ( nStretchX != 100 ) + if (mnStretchX != 100.0) { - if ( nStretchX == nStretchY && - nRelWidth == 100 ) + if (mnStretchX == mnStretchY && nRelWidth == 100 ) { aRealSz.setWidth( 0 ); } else { - aRealSz.setWidth( aRealSz.Width() * nStretchX ); - aRealSz.setWidth( aRealSz.Width() / 100 ); + double fNewWidth = (double(aRealSz.Width()) * mnStretchX) / 100.0; + aRealSz.setWidth(basegfx::fround(fNewWidth)); // Also the Kerning: (long due to handle Interim results) tools::Long nKerning = rFont.GetFixKerning(); @@ -3012,17 +3011,15 @@ void ImpEditEngine::SeekCursor( ContentNode* pNode, sal_Int32 nPos, SvxFont& rFo >0 >100 > (Proportional) <0 >100 < (The amount, thus disproportional) */ - if ( ( nKerning < 0 ) && ( nStretchX > 100 ) ) + if (nKerning < 0 && mnStretchX > 100.0) { // disproportional - nKerning *= 100; - nKerning /= nStretchX; + nKerning = basegfx::fround((double(nKerning) * 100.0) / mnStretchX); } else if ( nKerning ) { // Proportional - nKerning *= nStretchX; - nKerning /= 100; + nKerning = basegfx::fround((double(nKerning) * mnStretchX) / 100.0); } rFont.SetFixKerning( static_cast<short>(nKerning) ); } @@ -4428,20 +4425,20 @@ void ImpEditEngine::SetFlatMode( bool bFlat ) pActiveView->ShowCursor(); } -void ImpEditEngine::SetCharStretching( sal_uInt16 nX, sal_uInt16 nY ) +void ImpEditEngine::SetCharStretching(double nX, double nY) { bool bChanged; if ( !IsEffectivelyVertical() ) { - bChanged = nStretchX!=nX || nStretchY!=nY; - nStretchX = nX; - nStretchY = nY; + bChanged = mnStretchX != nX || mnStretchY != nY; + mnStretchX = nX; + mnStretchY = nY; } else { - bChanged = nStretchX!=nY || nStretchY!=nX; - nStretchX = nY; - nStretchY = nX; + bChanged = mnStretchX != nY || mnStretchY != nX; + mnStretchX = nY; + mnStretchY = nX; } if (bChanged && aStatus.DoStretch()) diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index ee9ebe89ff2e..bc83fc412c75 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -1083,7 +1083,7 @@ std::unique_ptr<EditTextObject> ImpEditEngine::CreateTextObject( EditSelection a // sleeper set up when Olli paragraphs not hacked! if ( bAllowBigObjects && bOnlyFullParagraphs && IsFormatted() && IsUpdateLayout() && ( nTextPortions >= nBigObjectStart ) ) { - XParaPortionList* pXList = new XParaPortionList( GetRefDevice(), GetColumnWidth(aPaperSize), nStretchX, nStretchY ); + XParaPortionList* pXList = new XParaPortionList( GetRefDevice(), GetColumnWidth(aPaperSize), mnStretchX, mnStretchY ); pTxtObj->SetPortionInfo(std::unique_ptr<XParaPortionList>(pXList)); for ( nNode = nStartNode; nNode <= nEndNode; nNode++ ) { @@ -1169,8 +1169,8 @@ EditSelection ImpEditEngine::InsertTextObject( const EditTextObject& rTextObject if ( pPortionInfo && ( static_cast<tools::Long>(pPortionInfo->GetPaperWidth()) == GetColumnWidth(aPaperSize) ) && ( pPortionInfo->GetRefMapMode() == GetRefDevice()->GetMapMode() ) - && ( pPortionInfo->GetStretchX() == nStretchX ) - && ( pPortionInfo->GetStretchY() == nStretchY ) ) + && ( pPortionInfo->GetStretchX() == mnStretchX) + && ( pPortionInfo->GetStretchY() == mnStretchY)) { if ( (pPortionInfo->GetRefDevPtr() == GetRefDevice()) || (pPortionInfo->RefDevIsVirtual() && GetRefDevice()->IsVirtual()) ) diff --git a/editeng/source/outliner/outlin2.cxx b/editeng/source/outliner/outlin2.cxx index 951f6923563f..68b1d0fb802e 100644 --- a/editeng/source/outliner/outlin2.cxx +++ b/editeng/source/outliner/outlin2.cxx @@ -482,9 +482,8 @@ void Outliner::QuickFormatDoc() pEditEngine->QuickFormatDoc(); } -void Outliner::SetGlobalCharStretching( sal_uInt16 nX, sal_uInt16 nY ) +void Outliner::SetGlobalCharStretching(double nX, double nY) { - // reset bullet size sal_Int32 nParagraphs = pParaList->GetParagraphCount(); for ( sal_Int32 nPara = 0; nPara < nParagraphs; nPara++ ) @@ -497,9 +496,9 @@ void Outliner::SetGlobalCharStretching( sal_uInt16 nX, sal_uInt16 nY ) pEditEngine->SetGlobalCharStretching( nX, nY ); } -void Outliner::GetGlobalCharStretching( sal_uInt16& rX, sal_uInt16& rY ) const +void Outliner::GetGlobalCharStretching(double& rX, double& rY) const { - pEditEngine->GetGlobalCharStretching( rX, rY ); + pEditEngine->GetGlobalCharStretching(rX, rY); } void Outliner::EraseVirtualDevice() diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx index d7ea27662e77..9254bae2ab77 100644 --- a/editeng/source/outliner/outliner.cxx +++ b/editeng/source/outliner/outliner.cxx @@ -840,7 +840,7 @@ vcl::Font Outliner::ImpCalcBulletFont( sal_Int32 nPara ) const } // Use original scale... - sal_uInt16 nStretchX, nStretchY; + double nStretchX, nStretchY; GetGlobalCharStretching(nStretchX, nStretchY); sal_uInt16 nScale = pFmt->GetBulletRelSize() * nStretchY / 100; @@ -887,12 +887,12 @@ void Outliner::PaintBullet(sal_Int32 nPara, const Point& rStartPos, const Point& bool bRightToLeftPara = pEditEngine->IsRightToLeft( nPara ); tools::Rectangle aBulletArea( ImpCalcBulletArea( nPara, true, false ) ); - sal_uInt16 nStretchX, nStretchY; + double nStretchX, nStretchY; GetGlobalCharStretching(nStretchX, nStretchY); - aBulletArea = tools::Rectangle( Point(aBulletArea.Left()*nStretchX/100, - aBulletArea.Top()), - Size(aBulletArea.GetWidth()*nStretchX/100, - aBulletArea.GetHeight()) ); + tools::Long nStretchBulletX = basegfx::fround(double(aBulletArea.Left()) * nStretchX / 100.0); + tools::Long nStretchBulletWidth = basegfx::fround(double(aBulletArea.GetWidth()) * nStretchX / 100.0); + aBulletArea = tools::Rectangle(Point(nStretchBulletX, aBulletArea.Top()), + Size(nStretchBulletWidth, aBulletArea.GetHeight()) ); Paragraph* pPara = pParaList->GetParagraph( nPara ); const SvxNumberFormat* pFmt = GetNumberFormat( nPara ); |