editeng/source/editeng/editeng.cxx | 4 - editeng/source/editeng/editobj.cxx | 6 - editeng/source/editeng/editobj2.hxx | 10 +- editeng/source/editeng/impedit.hxx | 30 +++---- editeng/source/editeng/impedit2.cxx | 4 - editeng/source/editeng/impedit3.cxx | 41 ++++------ editeng/source/editeng/impedit4.cxx | 6 - editeng/source/outliner/outlin2.cxx | 7 - editeng/source/outliner/outliner.cxx | 12 +-- include/editeng/editeng.hxx | 4 - include/editeng/outliner.hxx | 4 - sd/qa/unit/import-tests2.cxx | 6 - sd/source/ui/view/drtxtob.cxx | 6 - svx/source/svdraw/svdotext.cxx | 110 ++++++++++++++++++---------- svx/source/svdraw/svdotextdecomposition.cxx | 2 15 files changed, 139 insertions(+), 113 deletions(-)
New commits: commit 9fc6702071d243652d48e7311db39b84be70903d Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Oct 31 13:28:27 2022 +0100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Fri Apr 7 12:34:37 2023 +0200 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). Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142064 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> Change-Id: Ifdf2481ddbaac0e9cf62a6ddf8a83984be134855 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149931 Tested-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx index 615fca65028f..993b6e1b15f1 100644 --- a/editeng/source/editeng/editeng.cxx +++ b/editeng/source/editeng/editeng.cxx @@ -2265,12 +2265,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 62ed45b20988..292d32e3bb3d 100644 --- a/editeng/source/editeng/editobj.cxx +++ b/editeng/source/editeng/editobj.cxx @@ -73,10 +73,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 ed7b5b5e0dd8..6d2303ee113c 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; @@ -1079,8 +1079,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; } @@ -1279,43 +1279,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 f62cc6d6a636..d37334f3c2e1 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -97,8 +97,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 6f9b35bc6d69..f1cec3a1db18 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -963,8 +963,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() ); @@ -2797,22 +2797,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(); @@ -2827,17 +2826,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) ); } @@ -4232,20 +4229,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 59efed0e7544..0c5992e7ad2d 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -1087,7 +1087,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++ ) { @@ -1173,8 +1173,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 3d4061a82cde..19230afeeab3 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 00b5ff202992..0acbc3dbbb4a 100644 --- a/editeng/source/outliner/outliner.cxx +++ b/editeng/source/outliner/outliner.cxx @@ -844,7 +844,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; @@ -891,12 +891,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 ); diff --git a/include/editeng/editeng.hxx b/include/editeng/editeng.hxx index 560f3be1a83a..29e33da53d71 100644 --- a/include/editeng/editeng.hxx +++ b/include/editeng/editeng.hxx @@ -414,8 +414,8 @@ public: void QuickDelete( const ESelection& rSel ); void QuickMarkToBeRepainted( sal_Int32 nPara ); - void SetGlobalCharStretching( sal_uInt16 nX, sal_uInt16 nY ); - void GetGlobalCharStretching( sal_uInt16& rX, sal_uInt16& rY ) const; + void SetGlobalCharStretching(double nX, double nY); + void GetGlobalCharStretching(double& rX, double& rY) const; void SetEditTextObjectPool( SfxItemPool* pPool ); SfxItemPool* GetEditTextObjectPool() const; diff --git a/include/editeng/outliner.hxx b/include/editeng/outliner.hxx index e45d00558378..1d560b3643bc 100644 --- a/include/editeng/outliner.hxx +++ b/include/editeng/outliner.hxx @@ -925,8 +925,8 @@ public: bool IsTextPos( const Point& rPaperPos, sal_uInt16 nBorder ); bool IsTextPos( const Point& rPaperPos, sal_uInt16 nBorder, bool* pbBulletPos ); - void SetGlobalCharStretching( sal_uInt16 nX = 100, sal_uInt16 nY = 100 ); - void GetGlobalCharStretching( sal_uInt16& rX, sal_uInt16& rY ) const; + void SetGlobalCharStretching(double nX = 100.0, double nY = 100.0); + void GetGlobalCharStretching(double& rX, double& rY) const; void EraseVirtualDevice(); bool ShouldCreateBigTextObject() const; diff --git a/sd/qa/unit/import-tests2.cxx b/sd/qa/unit/import-tests2.cxx index da74fafb6a9c..dc229c7da3cb 100644 --- a/sd/qa/unit/import-tests2.cxx +++ b/sd/qa/unit/import-tests2.cxx @@ -1564,10 +1564,8 @@ void SdImportTest2::testTdf120028() double fCharHeight = 0; xPropSet->getPropertyValue("CharHeight") >>= fCharHeight; CPPUNIT_ASSERT_DOUBLES_EQUAL(13.5, fCharHeight, 1E-12); - // 13.5 * 86% is approx. 11.6 (the correct scaled font size) - CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(86)), xShape->getPropertyValue("TextFitToSizeScale")); - - xDocShRef->DoClose(); + // 13.5 * 87% is approx. 11.7 (the correct scaled font size) + CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(87)), xShape->getPropertyValue("TextFitToSizeScale")); } void SdImportTest2::testDescriptionImport() diff --git a/sd/source/ui/view/drtxtob.cxx b/sd/source/ui/view/drtxtob.cxx index b10af08289fa..d8503d0412f7 100644 --- a/sd/source/ui/view/drtxtob.cxx +++ b/sd/source/ui/view/drtxtob.cxx @@ -165,7 +165,7 @@ void TextObjectBar::GetAttrState( SfxItemSet& rSet ) case SID_ATTR_CHAR_STRIKEOUT: case SID_ATTR_CHAR_CASEMAP: { - sal_uInt16 stretchX = 100; + double stretchX = 100.0; SvxScriptSetItem aSetItem( nSlotId, GetPool() ); aSetItem.GetItemSet().Put( aAttrSet, false ); @@ -183,9 +183,9 @@ void TextObjectBar::GetAttrState( SfxItemSet& rSet ) if (OutlineView* pOView = dynamic_cast<OutlineView*>(mpView)) pOLV = pOView->GetViewByWindow(mpViewShell->GetActiveWindow()); - sal_uInt16 stretchY = 100; + double stretchY = 100.0; if( pOutliner ) - pOutliner->GetGlobalCharStretching( stretchX, stretchY ); + pOutliner->GetGlobalCharStretching(stretchX, stretchY); if(pOLV && !pOLV->GetSelection().HasRange()) { diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx index 91a0870630e0..6117acac124c 100644 --- a/svx/source/svdraw/svdotext.cxx +++ b/svx/source/svdraw/svdotext.cxx @@ -937,56 +937,88 @@ void SdrTextObj::ImpSetCharStretching(SdrOutliner& rOutliner, const Size& rTextS tools::Long nXTolMi=nWantWdt/25; // tolerance: -4% tools::Long nXCorr =nWantWdt/20; // correction scale: 5% - tools::Long nX=(nWantWdt*100) /nIsWdt; // calculate X stretching - tools::Long nY=(nWantHgt*100) /nIsHgt; // calculate Y stretching + double nX = (nWantWdt * 100.0) / double(nIsWdt); // calculate X stretching + double nY = (nWantHgt * 100.0) / double(nIsHgt); // calculate Y stretching bool bChkX = true; - if (bNoStretching) { // might only be possible proportionally - if (nX>nY) { nX=nY; bChkX=false; } - else { nY=nX; } + if (bNoStretching) + { // might only be possible proportionally + if (nX > nY) + { + nX = nY; + bChkX = false; + } + else + { + nY = nX; + } } - while (nLoopCount<5 && !bNoMoreLoop) { - if (nX<0) nX=-nX; - if (nX<1) { nX=1; bNoMoreLoop = true; } - if (nX>65535) { nX=65535; bNoMoreLoop = true; } + while (nLoopCount<5 && !bNoMoreLoop) + { + if (nX < 0.0) + nX = -nX; + if (nX < 1.0) + { + nX = 1.0; + bNoMoreLoop = true; + } + if (nX > 65535.0) + { + nX = 65535.0; + bNoMoreLoop = true; + } - if (nY<0) nY=-nY; - if (nY<1) { nY=1; bNoMoreLoop = true; } - if (nY>65535) { nY=65535; bNoMoreLoop = true; } + if (nY < 0.0) + { + nY = -nY; + } + if (nY < 1.0) + { + nY = 1.0; + bNoMoreLoop = true; + } + if (nY > 65535.0) + { + nY = 65535.0; + bNoMoreLoop = true; + } // exception, there is no text yet (horizontal case) - if(nIsWdt <= 1) + if (nIsWdt <= 1) { nX = nY; bNoMoreLoop = true; } // exception, there is no text yet (vertical case) - if(nIsHgt <= 1) + if (nIsHgt <= 1) { nY = nX; bNoMoreLoop = true; } - - rOutliner.SetGlobalCharStretching(static_cast<sal_uInt16>(nX),static_cast<sal_uInt16>(nY)); + rOutliner.SetGlobalCharStretching(nX, nY); nLoopCount++; Size aSiz(rOutliner.CalcTextSize()); - tools::Long nXDiff=aSiz.Width()-nWantWdt; + tools::Long nXDiff = aSiz.Width() - nWantWdt; rFitXCorrection=Fraction(nWantWdt,aSiz.Width()); if (((nXDiff>=nXTolMi || !bChkX) && nXDiff<=nXTolPl) || nXDiff==nXDiff0) { bNoMoreLoop = true; } else { // correct stretching factors - tools::Long nMul=nWantWdt; - tools::Long nDiv=aSiz.Width(); - if (std::abs(nXDiff)<=2*nXCorr) { - if (nMul>nDiv) nDiv+=(nMul-nDiv)/2; // but only add half of what we calculated, - else nMul+=(nDiv-nMul)/2; // because the EditEngine calculates wrongly later on + tools::Long nMul = nWantWdt; + tools::Long nDiv = aSiz.Width(); + if (std::abs(nXDiff) <= 2 * nXCorr) + { + if (nMul > nDiv) + nDiv += (nMul - nDiv) / 2.0; // but only add half of what we calculated, + else + nMul += (nDiv - nMul) / 2.0;// because the EditEngine calculates wrongly later on } - nX=nX*nMul/nDiv; - if (bNoStretching) nY=nX; + nX = nX * double(nMul) / double(nDiv); + if (bNoStretching) + nY = nX; } - nXDiff0=nXDiff; + nXDiff0 = nXDiff; } } @@ -1149,7 +1181,7 @@ void SdrTextObj::ImpInitDrawOutliner( SdrOutliner& rOutl ) const nOutlinerMode = OutlinerMode::TextObject; rOutl.Init( nOutlinerMode ); - rOutl.SetGlobalCharStretching(); + rOutl.SetGlobalCharStretching(100.0, 100.0); EEControlBits nStat=rOutl.GetControlWord(); nStat &= ~EEControlBits(EEControlBits::STRETCHING|EEControlBits::AUTOPAGESIZE); rOutl.SetControlWord(nStat); @@ -1213,8 +1245,8 @@ sal_uInt16 SdrTextObj::GetFontScaleY() const // This eventually calls ImpAutoFitText UpdateOutlinerFormatting(rOutliner, o3tl::temporary(tools::Rectangle())); - sal_uInt16 nStretchY; - rOutliner.GetGlobalCharStretching(o3tl::temporary(sal_uInt16()), nStretchY); + double nStretchY; + rOutliner.GetGlobalCharStretching(o3tl::temporary(double()), nStretchY); return nStretchY; } @@ -1234,13 +1266,14 @@ void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, const Size& rTextSize, // line-breaking text that we need some more samples // loop early-exits if we detect an already attained value - sal_uInt16 nMinStretchX=0, nMinStretchY=0; + double nMinStretchX = 0.0; + double nMinStretchY = 0.0; sal_uInt16 aOldStretchXVals[]={0,0,0,0,0,0,0,0,0,0}; const size_t aStretchArySize=SAL_N_ELEMENTS(aOldStretchXVals); for(unsigned int i=0; i<aStretchArySize; ++i) { const Size aCurrTextSize = rOutliner.CalcTextSizeNTP(); - double fFactor(1.0); + double fFactor = 1.0; if( bIsVerticalWriting ) { if (aCurrTextSize.Width() != 0) @@ -1259,15 +1292,15 @@ void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, const Size& rTextSize, // - bulleted words will have to go through more iterations fFactor = std::sqrt(fFactor); - sal_uInt16 nCurrStretchX, nCurrStretchY; + double nCurrStretchX, nCurrStretchY; rOutliner.GetGlobalCharStretching(nCurrStretchX, nCurrStretchY); if (fFactor >= 1.0 ) { // resulting text area fits into available shape rect - // err on the larger stretching, to optimally fill area - nMinStretchX = std::max(nMinStretchX,nCurrStretchX); - nMinStretchY = std::max(nMinStretchY,nCurrStretchY); + nMinStretchX = std::max(nMinStretchX, nCurrStretchX); + nMinStretchY = std::max(nMinStretchY, nCurrStretchY); } aOldStretchXVals[i] = nCurrStretchX; @@ -1276,10 +1309,10 @@ void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, const Size& rTextSize, if (fFactor < 1.0 || nCurrStretchX != 100) { - nCurrStretchX = sal::static_int_cast<sal_uInt16>(nCurrStretchX*fFactor); - nCurrStretchY = sal::static_int_cast<sal_uInt16>(nCurrStretchY*fFactor); - rOutliner.SetGlobalCharStretching(std::min(sal_uInt16(100),nCurrStretchX), - std::min(sal_uInt16(100),nCurrStretchY)); + nCurrStretchX = nCurrStretchX * fFactor; + nCurrStretchY = nCurrStretchY * fFactor; + + rOutliner.SetGlobalCharStretching(std::min(100.0, nCurrStretchX), std::min(100.0, nCurrStretchY)); SAL_INFO("svx", "zoom is " << nCurrStretchX); } } @@ -1292,8 +1325,7 @@ void SdrTextObj::ImpAutoFitText(SdrOutliner& rOutliner, const Size& rTextSize, } SAL_INFO("svx", "final zoom is " << nMinStretchX); - rOutliner.SetGlobalCharStretching(std::min(sal_uInt16(100),nMinStretchX), - std::min(sal_uInt16(100),nMinStretchY)); + rOutliner.SetGlobalCharStretching(std::min(100.0, nMinStretchX), std::min(100.0, nMinStretchY)); } void SdrTextObj::SetupOutlinerFormatting( SdrOutliner& rOutl, tools::Rectangle& rPaintRect ) const diff --git a/svx/source/svdraw/svdotextdecomposition.cxx b/svx/source/svdraw/svdotextdecomposition.cxx index 607a2546d1d5..1fc6b8f08cff 100644 --- a/svx/source/svdraw/svdotextdecomposition.cxx +++ b/svx/source/svdraw/svdotextdecomposition.cxx @@ -1203,7 +1203,7 @@ void SdrTextObj::impDecomposeStretchTextPrimitive( // to layout without mirroring const double fScaleX(fabs(aScale.getX()) / aOutlinerScale.getX()); const double fScaleY(fabs(aScale.getY()) / aOutlinerScale.getY()); - rOutliner.SetGlobalCharStretching(static_cast<sal_Int16>(FRound(fScaleX * 100.0)), static_cast<sal_Int16>(FRound(fScaleY * 100.0))); + rOutliner.SetGlobalCharStretching(fScaleX * 100.0, fScaleY * 100.0); // When mirroring in X and Y, // move the null point which was top left to bottom right.