summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Kosiorek <gang65@poczta.onet.pl>2023-05-10 22:30:20 +0200
committerBartosz Kosiorek <gang65@poczta.onet.pl>2023-05-12 22:42:00 +0200
commit717bdd06a7ac1a2a266f36a43d7f1e695559d056 (patch)
tree097c185b9a3180cee573e19db1a5b8cc7d4a3822
parenta9c14a3b2c1d14373b63cf0aff0eb92ab5d640d8 (diff)
EMF Fix text aligning for EMR_SETTEXTALIGN for wrong values.
Change-Id: I4d67eb7112d2295185905eac52ebab022a1beb78 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151670 Tested-by: Jenkins Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
-rw-r--r--emfio/inc/mtftools.hxx4
-rw-r--r--emfio/qa/cppunit/wmf/data/TestSetTextAlign.wmfbin0 -> 1910 bytes
-rw-r--r--emfio/qa/cppunit/wmf/wmfimporttest.cxx91
-rw-r--r--emfio/source/reader/mtftools.cxx10
4 files changed, 99 insertions, 6 deletions
diff --git a/emfio/inc/mtftools.hxx b/emfio/inc/mtftools.hxx
index b2237736869b..f5638af59ecb 100644
--- a/emfio/inc/mtftools.hxx
+++ b/emfio/inc/mtftools.hxx
@@ -178,7 +178,9 @@ namespace emfio
TA_RIGHT_CENTER = (TA_RIGHT | TA_CENTER),
TA_TOP = 0x0000,
TA_BOTTOM = 0x0008,
- TA_BASELINE = 0x0018,
+ // In [MS-WMF] 2.1.2.3, TA_BASELINE value is wrong.
+ // It is 0x0018 and it should be 0x0010.
+ TA_BASELINE = 0x0010,
TA_RTLREADING = 0x0100
};
diff --git a/emfio/qa/cppunit/wmf/data/TestSetTextAlign.wmf b/emfio/qa/cppunit/wmf/data/TestSetTextAlign.wmf
new file mode 100644
index 000000000000..9a3ad46f1d32
--- /dev/null
+++ b/emfio/qa/cppunit/wmf/data/TestSetTextAlign.wmf
Binary files differ
diff --git a/emfio/qa/cppunit/wmf/wmfimporttest.cxx b/emfio/qa/cppunit/wmf/wmfimporttest.cxx
index 48e47fb0fd36..780933da58d7 100644
--- a/emfio/qa/cppunit/wmf/wmfimporttest.cxx
+++ b/emfio/qa/cppunit/wmf/wmfimporttest.cxx
@@ -48,6 +48,7 @@ public:
void testNonPlaceableWmf();
void testTdf88163NonPlaceableWmf();
void testTdf88163PlaceableWmf();
+ void testSetTextAlignWmf();
void testSine();
void testEmfProblem();
void testEmfLineStyles();
@@ -65,6 +66,7 @@ public:
CPPUNIT_TEST(testNonPlaceableWmf);
CPPUNIT_TEST(testTdf88163NonPlaceableWmf);
CPPUNIT_TEST(testTdf88163PlaceableWmf);
+ CPPUNIT_TEST(testSetTextAlignWmf);
CPPUNIT_TEST(testSine);
CPPUNIT_TEST(testEmfProblem);
CPPUNIT_TEST(testEmfLineStyles);
@@ -184,6 +186,95 @@ void WmfTest::testTdf88163PlaceableWmf()
assertXPath(pDoc, "/metafile/push[2]/textarray[3]", "y", "390");
}
+void WmfTest::testSetTextAlignWmf()
+{
+ OUString fileName(u"TestSetTextAlign.wmf");
+ SvFileStream aFileStream(getFullUrl(fileName), StreamMode::READ);
+ GDIMetaFile aGDIMetaFile;
+ ReadWindowMetafile(aFileStream, aGDIMetaFile);
+
+ MetafileXmlDump dumper;
+
+ xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
+
+ CPPUNIT_ASSERT(pDoc);
+
+ assertXPath(pDoc, "/metafile", "height", "20999");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[2]", "align", "top");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[2]", "x", "11642");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[2]", "y", "212");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[2]/text", "textalignment:default");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[3]", "align", "top");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[3]", "x", "12700");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[3]", "y", "212");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[3]/text", "textalignment:0x00");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[4]", "align", "top");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[4]", "x", "11999");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[4]", "y", "423");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[4]/text", "textalignment:0x02");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[5]", "align", "top");
+ // Fails without the fix: Expected: 11999, Actual: 12350
+ assertXPath(pDoc, "/metafile/push[2]/textarray[5]", "x", "11999");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[5]", "y", "635");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[5]/text", "textalignment:0x04");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[6]", "align", "top");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[6]", "x", "12350");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[6]", "y", "847");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[6]/text", "textalignment:0x06");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[7]", "align", "top");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[7]", "x", "12700");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[7]", "y", "1058");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[7]/text", "textalignment:0x08");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[8]", "align", "top");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[8]", "x", "11999");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[8]", "y", "1270");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[8]/text", "textalignment:0x0A");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[9]", "align", "bottom");
+ // Fails without the fix: Expected: 11999, Actual: 12350
+ assertXPath(pDoc, "/metafile/push[2]/textarray[9]", "x", "11999");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[9]", "y", "1482");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[9]/text", "textalignment:0x0C");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[10]", "align", "bottom");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[10]", "x", "12350");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[10]", "y", "1693");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[10]/text", "textalignment:0x0E");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[11]", "align", "bottom");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[11]", "x", "12700");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[11]", "y", "1905");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[11]/text", "textalignment:0x10");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[12]", "align", "bottom");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[12]", "x", "11999");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[12]", "y", "2117");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[12]/text", "textalignment:0x12");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[13]", "align", "bottom");
+ // Fails without the fix: Expected: 11999, Actual: 12350
+ assertXPath(pDoc, "/metafile/push[2]/textarray[13]", "x", "11999");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[13]", "y", "2328");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[13]/text", "textalignment:0x14");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[14]", "align", "bottom");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[14]", "x", "12350");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[14]", "y", "2540");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[14]/text", "textalignment:0x16");
+
+ assertXPath(pDoc, "/metafile/push[2]/textalign[15]", "align", "bottom");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[15]", "x", "12700");
+ assertXPath(pDoc, "/metafile/push[2]/textarray[15]", "y", "2752");
+ assertXPathContent(pDoc, "/metafile/push[2]/textarray[15]/text", "textalignment:0x18");
+}
+
void WmfTest::testSine()
{
SvFileStream aFileStream(getFullUrl(u"sine_wave.emf"), StreamMode::READ);
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index 8c85d0e126a3..f2446e1864de 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -1682,11 +1682,11 @@ namespace emfio
mnLatestTextLayoutMode = mnTextLayoutMode;
mpGDIMetaFile->AddAction( new MetaLayoutModeAction( mnTextLayoutMode ) );
}
- SetGfxMode( nGfxMode );
+ SetGfxMode(nGfxMode);
TextAlign eTextAlign;
- if ( ( mnTextAlign & TA_BASELINE) == TA_BASELINE )
+ if (mnTextAlign & TA_BASELINE)
eTextAlign = ALIGN_BASELINE;
- else if( ( mnTextAlign & TA_BOTTOM) == TA_BOTTOM )
+ else if (mnTextAlign & TA_BOTTOM)
eTextAlign = ALIGN_BOTTOM;
else
eTextAlign = ALIGN_TOP;
@@ -1781,9 +1781,9 @@ namespace emfio
if( mnTextAlign & TA_UPDATECP )
rPosition = maActPos;
- if ( mnTextAlign & TA_RIGHT_CENTER )
+ if (mnTextAlign & TA_RIGHT_CENTER)
{
- Point aDisplacement( ( ( mnTextAlign & TA_RIGHT_CENTER ) == TA_RIGHT ) ? nTextWidth : nTextWidth >> 1, 0 );
+ Point aDisplacement(((mnTextAlign & TA_RIGHT_CENTER) == TA_CENTER) ? nTextWidth >> 1: nTextWidth, 0);
Point().RotateAround(aDisplacement, maFont.GetOrientation());
rPosition -= aDisplacement;
}