summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2021-10-17 00:15:04 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2021-10-18 12:34:26 +0200
commit460af321a84aae07f699e45700c212fcad50c38a (patch)
tree44738dca5e5e83b27e338cf291b1f8697ba15647 /svx
parent164ebe08df1cb501235aff99722864556ee6fc2d (diff)
tdf#144988 correct font size in multiline Fontwork text
The error happened if ScaleX in TextPath is true. In that case the original font size is used for rendering if possible. Only if a paragraph is longer as its sub-path length, the rendered font size for the whole text is reduced until the text fits. The error was, that in case the first paragraph was too long and the second paragraph fits, the fact that the first paragraph was too long was overwritten from the factor for the second paragraph. That resulted in wrong position and size of the text and overlapping characters. The meaning of fScalingFactor is related to the usual case, where ScaleX is false. Keeping original font size is not achieved by using value 1 for fScalingFactor (which would be obvious), but the adaption to case ScaleX==true is done in FitTextOutlinesToShapeOutlines() by tweaking the width from the text bounding rectangle. Change-Id: Icf5829018a83be0f1197304d17da10a88130f702 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123714 Tested-by: Jenkins Reviewed-by: Regina Henschel <rb.henschel@t-online.de> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123732
Diffstat (limited to 'svx')
-rw-r--r--svx/qa/unit/customshapes.cxx24
-rw-r--r--svx/qa/unit/data/tdf144988_Fontwork_FontSize.odpbin0 -> 11169 bytes
-rw-r--r--svx/source/customshapes/EnhancedCustomShapeFontWork.cxx8
3 files changed, 30 insertions, 2 deletions
diff --git a/svx/qa/unit/customshapes.cxx b/svx/qa/unit/customshapes.cxx
index db9302766780..509d6204908e 100644
--- a/svx/qa/unit/customshapes.cxx
+++ b/svx/qa/unit/customshapes.cxx
@@ -127,6 +127,30 @@ void lcl_AssertRectEqualWithTolerance(std::string_view sInfo, const tools::Recta
std::abs(rExpected.GetHeight() - rActual.GetHeight()) <= nTolerance);
}
+CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf145111_Fontwork_rendering_font_size)
+{
+ // The tested position and height depend on dpi.
+ if (!IsDefaultDPI())
+ return;
+
+ // tdf#144988 In case ScaleX is true in property TextPath, the rendering font size should be
+ // reduced in case any of the paragraphs would be longer as its sub-path. That was wrong, if
+ // the first paragraph was too long and the second would fit. It resulted in wrong position
+ // and height and overlapping characters.
+
+ OUString aURL = m_directories.getURLFromSrc(sDataDirectory) + "tdf144988_Fontwork_FontSize.odp";
+ mxComponent = loadFromDesktop(aURL, "com.sun.star.comp.presentation.PresentationDocument");
+ uno::Reference<drawing::XShape> xShape(getShape(0));
+ SdrObjCustomShape& rSdrCustomShape(
+ static_cast<SdrObjCustomShape&>(*SdrObject::getSdrObjectFromXShape(xShape)));
+
+ // Without the fix in place left|top, width x height was 1279|1279, 2815 x 2448.
+ // The expected values 1501|1777, 3941 x 1446 are only valid for 96dpi.
+ tools::Rectangle aBoundRect(rSdrCustomShape.GetCurrentBoundRect());
+ tools::Rectangle aExpected(Point(1501, 1777), Size(3941, 1446));
+ lcl_AssertRectEqualWithTolerance("Wrong text rendering", aExpected, aBoundRect, 5);
+}
+
CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf145111_anchor_in_Fontwork)
{
// The tested positions depend on dpi.
diff --git a/svx/qa/unit/data/tdf144988_Fontwork_FontSize.odp b/svx/qa/unit/data/tdf144988_Fontwork_FontSize.odp
new file mode 100644
index 000000000000..943bc143ba0e
--- /dev/null
+++ b/svx/qa/unit/data/tdf144988_Fontwork_FontSize.odp
Binary files differ
diff --git a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
index 6ca82e691095..3ad4287c7743 100644
--- a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
+++ b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
@@ -163,7 +163,6 @@ static void CalculateHorizontalScalingFactor(
const tools::PolyPolygon& rOutline2d)
{
double fScalingFactor = 1.0;
- bool bScalingFactorDefined = false;
rFWData.fVerticalTextScaling = 1.0;
sal_uInt16 i = 0;
@@ -199,9 +198,14 @@ static void CalculateHorizontalScalingFactor(
if ( nOutlinesCount2d & 1 )
bSingleLineMode = true;
+ // In case of rFWData.bScaleX == true it loops with reduced font size until the current run
+ // results in a fScalingFactor >=1.0. The fact, that case rFWData.bScaleX == true keeps font
+ // size if possible, is not done here with scaling factor 1 but is done in method
+ // 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
@@ -223,7 +227,7 @@ static void CalculateHorizontalScalingFactor(
fScalingFactor = fScale;
bScalingFactorDefined = true;
}
- else if ( fScale < fScalingFactor || ( rFWData.bScaleX && fScalingFactor < 1.0 ) )
+ else if (fScale < fScalingFactor)
{
fScalingFactor = fScale;
}