tdf#162571 - sd: Text box expands or shrinks on left or right or

both sides, depending on the text alignment. Set the text anchor
position based on the first paragraph alignment.

WIP: testing...

Change-Id: Ie1588c3eab5dd24eddb20baf342aca57c0dd39fc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174885
Reviewed-by: Gabor Kelemen <gabor.kelemen.extern@allotropia.de>
Tested-by: Jenkins
Tested-by: Gabor Kelemen <gabor.kelemen.extern@allotropia.de>
This commit is contained in:
Balazs Varga
2024-10-16 20:19:58 +02:00
committed by Gabor Kelemen
parent 3233383b26
commit 1d9ce0a67a
6 changed files with 89 additions and 45 deletions
+40
View File
@@ -75,6 +75,7 @@
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/HomogenMatrix3.hpp>
#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
#include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
#include <com/sun/star/drawing/GraphicExportFilter.hpp>
#include <com/sun/star/drawing/XShapes.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
@@ -616,6 +617,16 @@ static SdrTextHorzAdjust lcl_convertAdjust( ParagraphAdjust eAdjust )
return SDRTEXTHORZADJUST_LEFT;
}
static TextHorizontalAdjust lcl_convertTextAdjust(ParagraphAdjust eAdjust)
{
if (eAdjust == ParagraphAdjust_LEFT)
return drawing::TextHorizontalAdjust_LEFT;
else if (eAdjust == ParagraphAdjust_RIGHT)
return drawing::TextHorizontalAdjust_RIGHT;
else
return drawing::TextHorizontalAdjust_BLOCK;
}
// LO does not interpret properties in styles belonging to the text content of a FontWork shape,
// but only those in the shape style. This method copies properties from the text content styles to
// the shape style.
@@ -1508,6 +1519,35 @@ Reference< XShape > const & Shape::createAndInsert(
}
}
// tdf#162571: In case of shapes with TextAutoGrowHeight, PP calculates/grow the
// shapes size in edit mode (typing) based on the text horizontal alignment.
// In LO, we simulate it by setting TextHorizontalAdjust based on the ParagraphAdjust
// of the 1. paragraph
// It is not perfect, because we have 1 TextHorizontalAdjust / 1 shape,
// while we can have many ParagraphAdjust / 1 shape
if (!mpTextBody->getTextProperties().maPropertyMap.hasProperty(PROP_WritingMode)
&& mpTextBody->getParagraphs().size() > 0)
{
std::optional<css::style::ParagraphAdjust>& oParaAdjust
= mpTextBody->getParagraphs()[0]->getProperties().getParaAdjust();
bool bAutoHeight = false;
Reference< XPropertySetInfo > xSetInfo(xSet->getPropertySetInfo());
const OUString& rPropName = PropertyMap::getPropertyName(PROP_TextAutoGrowHeight);
if (xSetInfo.is() && xSetInfo->hasPropertyByName(rPropName))
{
uno::Any aTextAutoGrowHeight = xSet->getPropertyValue(u"TextAutoGrowHeight"_ustr);
aTextAutoGrowHeight >>= bAutoHeight;
}
if (bAutoHeight && nShapeRotateInclCamera == 0)
{
mpTextBody->getTextProperties().maPropertyMap.setProperty(
PROP_TextHorizontalAdjust, lcl_convertTextAdjust(
oParaAdjust ? *oParaAdjust : ParagraphAdjust_LEFT));
}
}
mpTextBody->getTextProperties().pushTextDistances(Size(aShapeRectHmm.Width, aShapeRectHmm.Height));
aShapeProps.assignUsed( mpTextBody->getTextProperties().maPropertyMap );
// Push char properties as well - specifically useful when this is a placeholder
+2 -2
View File
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<XShapes>
<XShape positionX="3175" positionY="7197" sizeX="17991" sizeY="7619" type="com.sun.star.drawing.CustomShape" name="Freeform 15" fontHeight="24.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="BLOCK" textVerticalAdjust="CENTER" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="729fcf" fillTransparence="0" fillTransparenceGradientName="">
<XShape positionX="3175" positionY="7197" sizeX="17991" sizeY="7619" type="com.sun.star.drawing.CustomShape" name="Freeform 15" fontHeight="24.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="LEFT" textVerticalAdjust="CENTER" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="729fcf" fillTransparence="0" fillTransparenceGradientName="">
<FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/>
<FillGradient style="LINEAR" startColor="3465a4" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/>
<FillHatch style="SINGLE" color="3465a4" distance="20" angle="0"/>
@@ -85,7 +85,7 @@
</PropertyValue>
</CustomShapeGeometry>
</XShape>
<XShape positionX="3387" positionY="4229" sizeX="17682" sizeY="9528" type="com.sun.star.drawing.CustomShape" name="Freeform 16" fontHeight="24.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="BLOCK" textVerticalAdjust="CENTER" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="729fcf" fillTransparence="0" fillTransparenceGradientName="">
<XShape positionX="3387" positionY="4229" sizeX="17682" sizeY="9528" type="com.sun.star.drawing.CustomShape" name="Freeform 16" fontHeight="24.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="LEFT" textVerticalAdjust="CENTER" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="729fcf" fillTransparence="0" fillTransparenceGradientName="">
<FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/>
<FillGradient style="LINEAR" startColor="3465a4" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/>
<FillHatch style="SINGLE" color="3465a4" distance="20" angle="0"/>
+2 -2
View File
@@ -64,7 +64,7 @@
</XShape>
<XShape positionX="20904" positionY="11701" sizeX="846" sizeY="1057" type="com.sun.star.drawing.GroupShape" name="Group 43">
<XShapes>
<XShape positionX="21750" positionY="12758" sizeX="846" sizeY="1057" type="com.sun.star.drawing.CustomShape" name="Oval 44" fontHeight="24.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="BLOCK" textVerticalAdjust="CENTER" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="HATCH" fillColor="ffffff" fillTransparence="0" fillTransparenceGradientName="">
<XShape positionX="21750" positionY="12758" sizeX="846" sizeY="1057" type="com.sun.star.drawing.CustomShape" name="Oval 44" fontHeight="24.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="LEFT" textVerticalAdjust="CENTER" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="HATCH" fillColor="ffffff" fillTransparence="0" fillTransparenceGradientName="">
<FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/>
<FillGradient style="LINEAR" startColor="3465a4" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/>
<FillHatch style="DOUBLE" color="000000" distance="175" angle="450"/>
@@ -148,7 +148,7 @@
</PropertyValue>
</CustomShapeGeometry>
</XShape>
<XShape positionX="21750" positionY="12758" sizeX="211" sizeY="1057" type="com.sun.star.drawing.CustomShape" name="Oval 45" fontHeight="24.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="BLOCK" textVerticalAdjust="CENTER" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="HATCH" fillColor="ffffff" fillTransparence="0" fillTransparenceGradientName="">
<XShape positionX="21750" positionY="12758" sizeX="211" sizeY="1057" type="com.sun.star.drawing.CustomShape" name="Oval 45" fontHeight="24.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="LEFT" textVerticalAdjust="CENTER" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="HATCH" fillColor="ffffff" fillTransparence="0" fillTransparenceGradientName="">
<FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/>
<FillGradient style="LINEAR" startColor="3465a4" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/>
<FillHatch style="DOUBLE" color="000000" distance="175" angle="450"/>
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<XShapes>
<XShape positionX="5498" positionY="2715" sizeX="11630" sizeY="8623" type="com.sun.star.drawing.CustomShape" name="Freeform 3" fontHeight="11.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="BLOCK" textVerticalAdjust="CENTER" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="SOLID" fillColor="e7e6e6" fillTransparence="0" fillTransparenceGradientName="">
<XShape positionX="5498" positionY="2715" sizeX="11630" sizeY="8623" type="com.sun.star.drawing.CustomShape" name="Freeform 3" fontHeight="11.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="LEFT" textVerticalAdjust="CENTER" textLeftDistance="250" textRightDistance="250" textUpperDistance="125" textLowerDistance="125" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="SOLID" fillColor="e7e6e6" fillTransparence="0" fillTransparenceGradientName="">
<FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/>
<FillGradient style="LINEAR" startColor="3465a4" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/>
<FillHatch style="SINGLE" color="3465a4" distance="20" angle="0"/>
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<XShapes>
<XShape positionX="4826" positionY="4826" sizeX="19557" sizeY="12953" type="com.sun.star.drawing.CustomShape" fontHeight="18.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="BLOCK" textVerticalAdjust="CENTER" textLeftDistance="325" textRightDistance="325" textUpperDistance="200" textLowerDistance="200" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="SOLID" fillColor="729fcf" fillTransparence="0" fillTransparenceGradientName="">
<XShape positionX="4826" positionY="4826" sizeX="19557" sizeY="12953" type="com.sun.star.drawing.CustomShape" fontHeight="18.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="NONE" textHorizontalAdjust="LEFT" textVerticalAdjust="CENTER" textLeftDistance="325" textRightDistance="325" textUpperDistance="200" textLowerDistance="200" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="0" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="SOLID" fillColor="729fcf" fillTransparence="0" fillTransparenceGradientName="">
<FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/>
<FillGradient style="LINEAR" startColor="3465a4" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/>
<FillHatch style="SINGLE" color="3465a4" distance="20" angle="0"/>
+43 -39
View File
@@ -512,6 +512,8 @@ void TextObjectBar::ExecuteImpl(ViewShell* mpViewShell, ::sd::View* mpView, SfxR
if( !pArgs )
{
SvxAdjust eAdjst;
SdrTextHorzAdjust eAnchor;
switch ( nSlot )
{
case SID_ATTR_CHAR_WEIGHT:
@@ -601,26 +603,25 @@ void TextObjectBar::ExecuteImpl(ViewShell* mpViewShell, ::sd::View* mpView, SfxR
}
break;
case SID_ATTR_PARA_ADJUST_LEFT:
case SID_ATTR_PARA_ADJUST_LEFT: eAdjst = SvxAdjust::Left; eAnchor = SDRTEXTHORZADJUST_LEFT; goto SET_ADJUST;
case SID_ATTR_PARA_ADJUST_CENTER: eAdjst = SvxAdjust::Center; eAnchor = SDRTEXTHORZADJUST_CENTER; goto SET_ADJUST;
case SID_ATTR_PARA_ADJUST_RIGHT: eAdjst = SvxAdjust::Right; eAnchor = SDRTEXTHORZADJUST_RIGHT; goto SET_ADJUST;
case SID_ATTR_PARA_ADJUST_BLOCK: eAdjst = SvxAdjust::Block; eAnchor = SDRTEXTHORZADJUST_BLOCK; goto SET_ADJUST;
SET_ADJUST:
{
aNewAttr.Put( SvxAdjustItem( SvxAdjust::Left, EE_PARA_JUST ) );
}
break;
case SID_ATTR_PARA_ADJUST_CENTER:
{
aNewAttr.Put( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
}
break;
case SID_ATTR_PARA_ADJUST_RIGHT:
{
aNewAttr.Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) );
}
break;
case SID_ATTR_PARA_ADJUST_BLOCK:
{
aNewAttr.Put( SvxAdjustItem( SvxAdjust::Block, EE_PARA_JUST ) );
aNewAttr.Put(SvxAdjustItem(eAdjst, EE_PARA_JUST));
// set anchor
ESelection aSel = pOLV->GetSelection();
aSel.Adjust();
sal_Int32 nStartPara = aSel.nStartPara;
if (!aSel.HasRange())
nStartPara = 0;
if (nStartPara == 0)
aNewAttr.Put(SdrTextHorzAdjustItem(eAnchor));
}
break;
case SID_ATTR_PARA_LINESPACE_10:
{
SvxLineSpacingItem aItem( LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL );
@@ -746,29 +747,32 @@ void TextObjectBar::ExecuteImpl(ViewShell* mpViewShell, ::sd::View* mpView, SfxR
nSlot == SID_ATTR_PARA_ADJUST_RIGHT ||
nSlot == SID_ATTR_PARA_ADJUST_BLOCK)
{
switch( nSlot )
{
case SID_ATTR_PARA_ADJUST_LEFT:
{
aNewAttr.Put( SvxAdjustItem( SvxAdjust::Left, EE_PARA_JUST ) );
}
break;
case SID_ATTR_PARA_ADJUST_CENTER:
{
aNewAttr.Put( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
}
break;
case SID_ATTR_PARA_ADJUST_RIGHT:
{
aNewAttr.Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) );
}
break;
case SID_ATTR_PARA_ADJUST_BLOCK:
{
aNewAttr.Put( SvxAdjustItem( SvxAdjust::Block, EE_PARA_JUST ) );
}
break;
SvxAdjust eAdjst;
SdrTextHorzAdjust eAnchor;
if (nSlot == SID_ATTR_PARA_ADJUST_LEFT) {
eAdjst = SvxAdjust::Left; eAnchor = SDRTEXTHORZADJUST_LEFT;
}
else if (nSlot == SID_ATTR_PARA_ADJUST_CENTER) {
eAdjst = SvxAdjust::Center; eAnchor = SDRTEXTHORZADJUST_CENTER;
}
else if (nSlot == SID_ATTR_PARA_ADJUST_RIGHT) {
eAdjst = SvxAdjust::Right; eAnchor = SDRTEXTHORZADJUST_RIGHT;
}
else {
eAdjst = SvxAdjust::Block; eAnchor = SDRTEXTHORZADJUST_BLOCK;
}
aNewAttr.Put(SvxAdjustItem(eAdjst, EE_PARA_JUST));
// set anchor
ESelection aSel = pOLV->GetSelection();
aSel.Adjust();
sal_Int32 nStartPara = aSel.nStartPara;
if (!aSel.HasRange())
nStartPara = 0;
if (nStartPara == 0)
aNewAttr.Put(SdrTextHorzAdjustItem(eAnchor));
rReq.Done( aNewAttr );
pArgs = rReq.GetArgs();
}