diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-06-18 21:13:47 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-06-19 13:25:12 +0200 |
commit | 03b5c306044c8a41e58b99ef7f648f81ee4a9533 (patch) | |
tree | ca3823efdd74a95819402576a0b1c9300e9b7f61 | |
parent | 422fcc74f9e334d45e4cc971a45465bd9f5b1777 (diff) |
factor out body as UpdateScalingMode
Change-Id: Ib65856e4573bbd0a4ac08aac9ef6e26b86678f46
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136092
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | svx/source/customshapes/EnhancedCustomShapeFontWork.cxx | 67 |
1 files changed, 36 insertions, 31 deletions
diff --git a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx index 0043b69cd646..a08e03f146eb 100644 --- a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx +++ b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx @@ -153,6 +153,41 @@ static double GetLength( const tools::Polygon& rPolygon ) return fLength; } +static void UpdateScalingMode(FWData& rFWData, const tools::PolyPolygon& rOutline2d, + bool bSingleLineMode, + VirtualDevice* pVirDev, double& rScalingFactor) +{ + sal_uInt16 i = 0; + bool bScalingFactorDefined = false; // New calculation for each font size + for( const auto& rTextArea : rFWData.vTextAreas ) + { + // calculating the width of the corresponding 2d text area + double fWidth = GetLength( rOutline2d.GetObject( i++ ) ); + if ( !bSingleLineMode ) + { + fWidth += GetLength( rOutline2d.GetObject( i++ ) ); + fWidth /= 2.0; + } + + for( const auto& rParagraph : rTextArea.vParagraphs ) + { + double fTextWidth = pVirDev->GetTextWidth( rParagraph.aString ); + if ( fTextWidth > 0.0 ) + { + double fScale = fWidth / fTextWidth; + if ( !bScalingFactorDefined ) + { + rScalingFactor = fScale; + bScalingFactorDefined = true; + } + else if (fScale < rScalingFactor) + { + rScalingFactor = fScale; + } + } + } + } +} /* CalculateHorizontalScalingFactor returns the horizontal scaling factor for the whole text object, so that each text will match its corresponding 2d Outline */ @@ -164,7 +199,6 @@ static void CalculateHorizontalScalingFactor( double fScalingFactor = 1.0; rFWData.fVerticalTextScaling = 1.0; - sal_uInt16 i = 0; bool bSingleLineMode = false; sal_uInt16 nOutlinesCount2d = rOutline2d.Count(); @@ -205,36 +239,7 @@ static void CalculateHorizontalScalingFactor( // FitTextOutlinesToShapeOutlines() do { - i = 0; - bool bScalingFactorDefined = false; // New calculation for each font size - for( const auto& rTextArea : rFWData.vTextAreas ) - { - // calculating the width of the corresponding 2d text area - double fWidth = GetLength( rOutline2d.GetObject( i++ ) ); - if ( !bSingleLineMode ) - { - fWidth += GetLength( rOutline2d.GetObject( i++ ) ); - fWidth /= 2.0; - } - - for( const auto& rParagraph : rTextArea.vParagraphs ) - { - double fTextWidth = pVirDev->GetTextWidth( rParagraph.aString ); - if ( fTextWidth > 0.0 ) - { - double fScale = fWidth / fTextWidth; - if ( !bScalingFactorDefined ) - { - fScalingFactor = fScale; - bScalingFactorDefined = true; - } - else if (fScale < fScalingFactor) - { - fScalingFactor = fScale; - } - } - } - } + UpdateScalingMode(rFWData, rOutline2d, bSingleLineMode, pVirDev, fScalingFactor); if (fScalingFactor < 1.0) { |