File bsc1178807.diff of Package libreoffice

From 0bd430959f1605cb7ab5ab2efdb4b6fd217cd8c2 Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos@collabora.com>
Date: Wed, 6 Jan 2021 10:23:44 +0100
Subject: [PATCH] bsc1178807.diff

tdf#134288 svx: fix rendering of text on a zero-width shape

We have conflicting requirements here: on one hand, the shape is zero
width, so the text area is also zero.  On the other hand, we put some
text on the shape, which should be visible.

The result was that the left/right text margin (2x250 mm100) was counted
as part of the text area, so we put a few (but not 1) characters / line
for zero width. Fix this to be PowerPoint-compatible: as the width
decreases, we break the text up to more and more lines, but if the width
is 0, then we don't break it up at all.

An alternative would be to do this later in
SdrTextObj::impDecomposeBlockTextPrimitive(), but there we no longer
know the width is really 0, because the text margins and some small
increase (+1 to be an inclusive range, +1 to have a non-zero scale) is
already added to the original width.

(cherry picked from commit 65e2ef43f186164729e1cc071b805bc1a7125cfe)

Conflicts:
	svx/qa/unit/sdr.cxx

Change-Id: Ieaa3e726bc5d37983b6221452e14f01db315f790
---
 .../sdr/primitive2d/sdrdecompositiontools.cxx | 28 +++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx b/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx
index 2ee2bb625e2d..801190f5e92a 100644
--- a/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx
+++ b/svx/source/sdr/primitive2d/sdrdecompositiontools.cxx
@@ -278,12 +278,36 @@ namespace drawinglayer::primitive2d
 
                 // create a range describing the wanted text position and size (aTextAnchorRange). This
                 // means to use the text distance values here
-                const basegfx::B2DPoint aTopLeft(aSnapRange.getMinX() + rText.getTextLeftDistance(), aSnapRange.getMinY() + rText.getTextUpperDistance());
-                const basegfx::B2DPoint aBottomRight(aSnapRange.getMaxX() - rText.getTextRightDistance(), aSnapRange.getMaxY() - rText.getTextLowerDistance());
+                sal_Int32 nTextLeftDistance = rText.getTextLeftDistance();
+                // If the margin is larger than the entire width of the text area, then limit the
+                // margin.
+                if (nTextLeftDistance > aSnapRange.getWidth())
+                    nTextLeftDistance = aSnapRange.getWidth();
+                sal_Int32 nTextRightDistance = rText.getTextRightDistance();
+                if (nTextRightDistance > aSnapRange.getWidth())
+                    nTextRightDistance = aSnapRange.getWidth();
+                const basegfx::B2DPoint aTopLeft(aSnapRange.getMinX() + nTextLeftDistance,
+                                                 aSnapRange.getMinY()
+                                                     + rText.getTextUpperDistance());
+                const basegfx::B2DPoint aBottomRight(aSnapRange.getMaxX() - nTextRightDistance,
+                                                     aSnapRange.getMaxY()
+                                                         - rText.getTextLowerDistance());
                 basegfx::B2DRange aTextAnchorRange;
                 aTextAnchorRange.expand(aTopLeft);
                 aTextAnchorRange.expand(aBottomRight);
 
+                if (aTextAnchorRange.getWidth() == 0)
+                {
+                    // If the shape has no width, then don't attempt to break the text into multiple
+                    // lines, not a single character would satisfy a zero width requirement.
+                    // SdrTextObj::impDecomposeBlockTextPrimitive() uses the same constant to
+                    // effectively set no limits.
+                    aTextAnchorRange.expand(
+                        basegfx::B2DPoint(aTopLeft.getX() - 1000000, aTopLeft.getY()));
+                    aTextAnchorRange.expand(
+                        basegfx::B2DPoint(aBottomRight.getX() + 1000000, aBottomRight.getY()));
+                }
+
                 // now create a transformation from this basic range (aTextAnchorRange)
                 // #i121494# if we have no scale use at least 1.0 to have a carrier e.g. for
                 // mirror values, else these will get lost
-- 
2.26.2
openSUSE Build Service is sponsored by