summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2021-10-17 00:15:04 +0200
committerRegina Henschel <rb.henschel@t-online.de>2021-10-17 14:04:29 +0200
commit3b922eb756d990c16944bbce42ae13142565a835 (patch)
treec4b19dcccbe453866f37e235e7b481eaec3f2c1f
parent4477baeba5aec71098f374cf0b4bd4591e048809 (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>
-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 5c4ea6914288..d4e7ff045fe1 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 56f67fcb0c89..32fd10661433 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;
}