summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2018-08-07 10:44:21 +0200
committerAndras Timar <andras.timar@collabora.com>2018-08-20 10:14:41 +0200
commit40b396ef207213ebd07981206674a2260256cb3c (patch)
treeaed1e5334a28cfa67dbe709fd4ac4ad8edb2f358 /svx
parent406280c62843e9ed167e7adaa005fba92a39608f (diff)
tdf#116350 Correctly display text on arc
Change-Id: Ice8c141db20d43ccc8d6e2b56004a4a28d2b257a Reviewed-on: https://gerrit.libreoffice.org/58729 Tested-by: Jenkins Reviewed-by: Szymon Kłos <szymon.klos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/58840 Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/customshapes/EnhancedCustomShapeFontWork.cxx148
1 files changed, 115 insertions, 33 deletions
diff --git a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
index 9bfed5d53ab4..0419038f0fda 100644
--- a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
+++ b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
@@ -33,6 +33,7 @@
#include <editeng/fontitem.hxx>
#include <editeng/postitem.hxx>
#include <editeng/wghtitem.hxx>
+#include <editeng/fhgtitem.hxx>
#include <editeng/charscaleitem.hxx>
#include <svx/EnhancedCustomShapeTypeNames.hxx>
#include <svx/svdorect.hxx>
@@ -79,9 +80,11 @@ struct FWData // representing the whole text
{
std::vector< FWTextArea > vTextAreas;
double fHorizontalTextScaling;
+ double fVerticalTextScaling;
sal_uInt32 nMaxParagraphsPerTextArea;
sal_Int32 nSingleLineHeight;
bool bSingleLineMode;
+ bool bScaleX;
};
@@ -98,6 +101,13 @@ static bool InitializeFontWorkData(
else
nTextAreaCount >>= 1;
+ const SdrCustomShapeGeometryItem& rGeometryItem( rSdrObjCustomShape.GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
+ const css::uno::Any* pAny = rGeometryItem.GetPropertyValueByName( "TextPath", "ScaleX" );
+ if (pAny)
+ *pAny >>= rFWData.bScaleX;
+ else
+ rFWData.bScaleX = false;
+
if ( nTextAreaCount )
{
rFWData.bSingleLineMode = bSingleLineMode;
@@ -157,18 +167,31 @@ void CalculateHorizontalScalingFactor(
{
double fScalingFactor = 1.0;
bool bScalingFactorDefined = false;
+ rFWData.fVerticalTextScaling = 1.0;
sal_uInt16 i = 0;
bool bSingleLineMode = false;
sal_uInt16 nOutlinesCount2d = rOutline2d.Count();
vcl::Font aFont;
- const SvxFontItem& rFontItem(rSdrObjCustomShape.GetMergedItem( EE_CHAR_FONTINFO ));
- aFont.SetFontHeight(rSdrObjCustomShape.GetLogicRect().GetHeight() / rFWData.nMaxParagraphsPerTextArea);
+ const SvxFontItem& rFontItem( rSdrObjCustomShape.GetMergedItem( EE_CHAR_FONTINFO ) );
+ const SvxFontHeightItem& rFontHeight( rSdrObjCustomShape.GetMergedItem( EE_CHAR_FONTHEIGHT ) );
+ sal_Int32 nFontSize = rFontHeight.GetHeight();
+
+ if (rFWData.bScaleX)
+ aFont.SetFontHeight( nFontSize );
+ else
+ aFont.SetFontHeight( rSdrObjCustomShape.GetLogicRect().GetHeight() / rFWData.nMaxParagraphsPerTextArea );
+
aFont.SetAlignment( ALIGN_TOP );
aFont.SetFamilyName( rFontItem.GetFamilyName() );
aFont.SetFamily( rFontItem.GetFamily() );
aFont.SetStyleName( rFontItem.GetStyleName() );
+ const SvxPostureItem& rPostureItem = rSdrObjCustomShape.GetMergedItem( EE_CHAR_ITALIC );
+ aFont.SetItalic( rPostureItem.GetPosture() );
+
+ const SvxWeightItem& rWeightItem = rSdrObjCustomShape.GetMergedItem( EE_CHAR_WEIGHT );
+ aFont.SetWeight( rWeightItem.GetWeight() );
aFont.SetOrientation( 0 );
// initializing virtual device
@@ -179,40 +202,55 @@ void CalculateHorizontalScalingFactor(
if ( nOutlinesCount2d & 1 )
bSingleLineMode = true;
- std::vector< FWTextArea >::iterator aTextAreaIter = rFWData.vTextAreas.begin();
- std::vector< FWTextArea >::const_iterator aTextAreaIEnd = rFWData.vTextAreas.end();
- while( aTextAreaIter != aTextAreaIEnd )
+ do
{
- // 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;
- }
- std::vector< FWParagraphData >::const_iterator aParagraphIter( aTextAreaIter->vParagraphs.begin() );
- std::vector< FWParagraphData >::const_iterator aParagraphIEnd( aTextAreaIter->vParagraphs.end() );
- while( aParagraphIter != aParagraphIEnd )
+ i = 0;
+ std::vector< FWTextArea >::iterator aTextAreaIter = rFWData.vTextAreas.begin();
+ std::vector< FWTextArea >::const_iterator aTextAreaIEnd = rFWData.vTextAreas.end();
+ while( aTextAreaIter != aTextAreaIEnd )
{
- double fTextWidth = pVirDev->GetTextWidth( aParagraphIter->aString );
- if ( fTextWidth > 0.0 )
+ // calculating the width of the corresponding 2d text area
+ double fWidth = GetLength( rOutline2d.GetObject( i++ ) );
+ if ( !bSingleLineMode )
{
- double fScale = fWidth / fTextWidth;
- if ( !bScalingFactorDefined )
- {
- fScalingFactor = fScale;
- bScalingFactorDefined = true;
- }
- else
+ fWidth += GetLength( rOutline2d.GetObject( i++ ) );
+ fWidth /= 2.0;
+ }
+
+ std::vector< FWParagraphData >::const_iterator aParagraphIter( aTextAreaIter->vParagraphs.begin() );
+ std::vector< FWParagraphData >::const_iterator aParagraphIEnd( aTextAreaIter->vParagraphs.end() );
+ while( aParagraphIter != aParagraphIEnd )
+ {
+ double fTextWidth = pVirDev->GetTextWidth( aParagraphIter->aString );
+ if ( fTextWidth > 0.0 )
{
- if ( fScale < fScalingFactor )
+ double fScale = fWidth / fTextWidth;
+ if ( !bScalingFactorDefined )
+ {
fScalingFactor = fScale;
+ bScalingFactorDefined = true;
+ }
+ else if ( fScale < fScalingFactor || ( rFWData.bScaleX && fScalingFactor < 1.0 ) )
+ {
+ fScalingFactor = fScale;
+ }
}
+ ++aParagraphIter;
}
- ++aParagraphIter;
+ ++aTextAreaIter;
+ }
+
+ if (fScalingFactor < 1.0)
+ {
+ nFontSize--;
+ aFont.SetFontHeight( nFontSize );
+ pVirDev->SetFont( aFont );
}
- ++aTextAreaIter;
}
+ while (rFWData.bScaleX && fScalingFactor < 1.0 && nFontSize > 1 );
+
+ if (nFontSize > 1)
+ rFWData.fVerticalTextScaling = static_cast<double>(nFontSize) / rFontHeight.GetHeight();
rFWData.fHorizontalTextScaling = fScalingFactor;
}
@@ -255,7 +293,9 @@ void GetTextAreaOutline(
nFntItm = EE_CHAR_FONTINFO_CJK;
const SvxFontItem& rFontItem = static_cast<const SvxFontItem&>(rSdrObjCustomShape.GetMergedItem( nFntItm ));
vcl::Font aFont;
+
aFont.SetFontHeight( rFWData.nSingleLineHeight );
+
aFont.SetAlignment( ALIGN_TOP );
aFont.SetFamilyName( rFontItem.GetFamilyName() );
@@ -433,18 +473,22 @@ bool GetFontWorkOutline(
std::vector< FWTextArea >::iterator aTextAreaIter = rFWData.vTextAreas.begin();
std::vector< FWTextArea >::const_iterator aTextAreaIEnd = rFWData.vTextAreas.end();
- rFWData.nSingleLineHeight = static_cast<sal_Int32>( ( static_cast<double>(rSdrObjCustomShape.GetLogicRect().GetHeight())
- / rFWData.nMaxParagraphsPerTextArea ) * rFWData.fHorizontalTextScaling );
-
- if (rFWData.nSingleLineHeight == SAL_MIN_INT32)
- return false;
-
bool bSameLetterHeights = false;
const SdrCustomShapeGeometryItem& rGeometryItem(rSdrObjCustomShape.GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ));
const css::uno::Any* pAny = rGeometryItem.GetPropertyValueByName( "TextPath", "SameLetterHeights" );
if ( pAny )
*pAny >>= bSameLetterHeights;
+ const SvxFontHeightItem& rFontHeight( rSdrObjCustomShape.GetMergedItem( EE_CHAR_FONTHEIGHT ) );
+ if (rFWData.bScaleX)
+ rFWData.nSingleLineHeight = rFWData.fVerticalTextScaling * rFontHeight.GetHeight();
+ else
+ rFWData.nSingleLineHeight = static_cast<sal_Int32>( ( static_cast<double>( rSdrObjCustomShape.GetLogicRect().GetHeight() )
+ / rFWData.nMaxParagraphsPerTextArea ) * rFWData.fHorizontalTextScaling );
+
+ if (rFWData.nSingleLineHeight == SAL_MIN_INT32)
+ return false;
+
while ( aTextAreaIter != aTextAreaIEnd )
{
GetTextAreaOutline(
@@ -484,6 +528,38 @@ bool GetFontWorkOutline(
++aParagraphIter;
}
}
+ else if (rFWData.bScaleX)
+ {
+ std::vector< FWParagraphData >::iterator aParagraphIter( aTextAreaIter->vParagraphs.begin() );
+ std::vector< FWParagraphData >::const_iterator aParagraphIEnd( aTextAreaIter->vParagraphs.end() );
+ while ( aParagraphIter != aParagraphIEnd )
+ {
+ sal_Int32 nHorzDiff = 0;
+ if ( eHorzAdjust == SDRTEXTHORZADJUST_CENTER )
+ nHorzDiff = ( rFWData.fHorizontalTextScaling * aTextAreaIter->aBoundRect.GetWidth() - aParagraphIter->aBoundRect.GetWidth() ) / 2;
+ else if ( eHorzAdjust == SDRTEXTHORZADJUST_RIGHT )
+ nHorzDiff = ( rFWData.fHorizontalTextScaling * aTextAreaIter->aBoundRect.GetWidth() - aParagraphIter->aBoundRect.GetWidth() );
+
+ if (nHorzDiff)
+ {
+ std::vector< FWCharacterData >::iterator aCharacterIter( aParagraphIter->vCharacters.begin() );
+ std::vector< FWCharacterData >::const_iterator aCharacterIEnd( aParagraphIter->vCharacters.end() );
+ while ( aCharacterIter != aCharacterIEnd )
+ {
+ std::vector< tools::PolyPolygon >::iterator aOutlineIter = aCharacterIter->vOutlines.begin();
+ std::vector< tools::PolyPolygon >::const_iterator aOutlineIEnd = aCharacterIter->vOutlines.end();
+ while( aOutlineIter != aOutlineIEnd )
+ {
+ aOutlineIter->Move( nHorzDiff, 0 );
+ ++aOutlineIter;
+ }
+ ++aCharacterIter;
+ }
+ }
+
+ ++aParagraphIter;
+ }
+ }
else
{
switch( eHorzAdjust )
@@ -670,6 +746,12 @@ void FitTextOutlinesToShapeOutlines( const tools::PolyPolygon& aOutlines2d, FWDa
sal_Int32 nTop = rTextAreaBoundRect.Top();
sal_Int32 nWidth = rTextAreaBoundRect.GetWidth();
sal_Int32 nHeight= rTextAreaBoundRect.GetHeight();
+
+ if (rFWData.bScaleX)
+ {
+ nWidth *= rFWData.fHorizontalTextScaling;
+ }
+
if ( rFWData.bSingleLineMode && nHeight && nWidth )
{
if ( nOutline2dIdx >= aOutlines2d.Count() )