summaryrefslogtreecommitdiff
path: root/emfio/qa/cppunit/wmf
diff options
context:
space:
mode:
authorHossein <hossein@libreoffice.org>2021-09-02 18:29:08 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-09-03 09:37:37 +0200
commitd25906087918c085239aac30fd72cb65aa7b9eb4 (patch)
treec15aa6a45d23d0e102ef89b6481d3654b66e280c /emfio/qa/cppunit/wmf
parent9e7f07dc1378354a5228898e339f8336bbbb41f3 (diff)
tdf#88163 Fix WMF font size
The problems in tdf#88163 can be categorized into two parts: 1. A regression which is caused by the commit a9020e461803964a206d5551884b70717eed165c. The font size for text is wrongly calculated for wmf files WITHOUT the placeable header. 2. A long-lasting bug that has existed from LO 3.5 (tested with various LibreOffice versions from 3.5 to master). The font size for text is wrongly calculated for wmf files WITH the placeable header. This patch solves the first part. In this patch the way wmf is scaled is changed using mnUnitsPerInch as a variable that controls the scale. The previous method was dividing the left/right/top/bottom fields of aPlaceableBound which caused the bad scaling of text. The second problem still remains, and possibly can be solved by usign the old scaling method that was previously used here (dividing pos values of aPlaceableBound), but the scaling factor should be calculated, which varies in different wmf files. More study should be done to solve this part. Values used for the example "visio_import_source.wmf" used in the test WmfTest::testNonPlaceableWmf() are slightly changed, but the rendering should not noticeably change, except the fix for the text font size. A new test WmfTest::testTdf88163NonPlaceableWmf() is added which checks for both font height and text boxes' positions. Font height can depend on the exact font that is used for Roman in the platform, so it vary between Linux, Windows and macOS. Thus, a range is used for ensuring that the font height is correct. By visual inspection, it is confirmed that this fix does not affect fdo#74336 and the fix for it still works for attachment 93188. Change-Id: I55bf38ba4345a0aa48c3e522976a2a5c32f7ec8c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121272 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'emfio/qa/cppunit/wmf')
-rw-r--r--emfio/qa/cppunit/wmf/data/tdf88163-non-placeable.wmfbin0 -> 1268 bytes
-rw-r--r--emfio/qa/cppunit/wmf/wmfimporttest.cxx63
2 files changed, 53 insertions, 10 deletions
diff --git a/emfio/qa/cppunit/wmf/data/tdf88163-non-placeable.wmf b/emfio/qa/cppunit/wmf/data/tdf88163-non-placeable.wmf
new file mode 100644
index 000000000000..b39514bd1b5c
--- /dev/null
+++ b/emfio/qa/cppunit/wmf/data/tdf88163-non-placeable.wmf
Binary files differ
diff --git a/emfio/qa/cppunit/wmf/wmfimporttest.cxx b/emfio/qa/cppunit/wmf/wmfimporttest.cxx
index 62a669fe3676..00da6f14ad84 100644
--- a/emfio/qa/cppunit/wmf/wmfimporttest.cxx
+++ b/emfio/qa/cppunit/wmf/wmfimporttest.cxx
@@ -46,6 +46,7 @@ public:
}
void testNonPlaceableWmf();
+ void testTdf88163NonPlaceableWmf();
void testSine();
void testEmfProblem();
void testEmfLineStyles();
@@ -57,6 +58,7 @@ public:
CPPUNIT_TEST_SUITE(WmfTest);
CPPUNIT_TEST(testNonPlaceableWmf);
+ CPPUNIT_TEST(testTdf88163NonPlaceableWmf);
CPPUNIT_TEST(testSine);
CPPUNIT_TEST(testEmfProblem);
CPPUNIT_TEST(testEmfLineStyles);
@@ -77,24 +79,65 @@ void WmfTest::testNonPlaceableWmf()
MetafileXmlDump dumper;
dumper.filterAllActionTypes();
dumper.filterActionType(MetaActionType::POLYLINE, false);
+
xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
CPPUNIT_ASSERT(pDoc);
- assertXPath(pDoc, "/metafile/polyline[1]/point[1]", "x", "16798");
- assertXPath(pDoc, "/metafile/polyline[1]/point[1]", "y", "1003");
+ // These values come from changes done in tdf#88163
+ assertXPath(pDoc, "/metafile/polyline[1]/point[1]", "x", "16813");
+ assertXPath(pDoc, "/metafile/polyline[1]/point[1]", "y", "1004");
+
+ assertXPath(pDoc, "/metafile/polyline[1]/point[2]", "x", "16813");
+ assertXPath(pDoc, "/metafile/polyline[1]/point[2]", "y", "7514");
+
+ assertXPath(pDoc, "/metafile/polyline[1]/point[3]", "x", "26112");
+ assertXPath(pDoc, "/metafile/polyline[1]/point[3]", "y", "7514");
+
+ assertXPath(pDoc, "/metafile/polyline[1]/point[4]", "x", "26112");
+ assertXPath(pDoc, "/metafile/polyline[1]/point[4]", "y", "1004");
+
+ assertXPath(pDoc, "/metafile/polyline[1]/point[5]", "x", "16813");
+ assertXPath(pDoc, "/metafile/polyline[1]/point[5]", "y", "1004");
+}
- assertXPath(pDoc, "/metafile/polyline[1]/point[2]", "x", "16798");
- assertXPath(pDoc, "/metafile/polyline[1]/point[2]", "y", "7507");
+void WmfTest::testTdf88163NonPlaceableWmf()
+{
+ OUString fileName(u"tdf88163-non-placeable.wmf");
+ SvFileStream aFileStream(getFullUrl(fileName), StreamMode::READ);
+ GDIMetaFile aGDIMetaFile;
+ ReadWindowMetafile(aFileStream, aGDIMetaFile);
- assertXPath(pDoc, "/metafile/polyline[1]/point[3]", "x", "26090");
- assertXPath(pDoc, "/metafile/polyline[1]/point[3]", "y", "7507");
+ MetafileXmlDump dumper;
+ xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
- assertXPath(pDoc, "/metafile/polyline[1]/point[4]", "x", "26090");
- assertXPath(pDoc, "/metafile/polyline[1]/point[4]", "y", "1003");
+ CPPUNIT_ASSERT(pDoc);
- assertXPath(pDoc, "/metafile/polyline[1]/point[5]", "x", "16798");
- assertXPath(pDoc, "/metafile/polyline[1]/point[5]", "y", "1003");
+ // These values come from the fix for tdf#88163
+
+ // Font 'Roman' and its height can vary according to the platform
+ // Fails without the fix
+ // Linux: With fix: 3136, without fix: ~ 8000
+ // Mac: With fix: 3230, without fix: ~ 8000
+ // Windows: With fix: 3303, without fix: ~ 8000
+ auto x = getXPath(pDoc, "/metafile/push[2]/font[1]", "height");
+ CPPUNIT_ASSERT_MESSAGE(fileName.toUtf8().getStr(), x.toInt32() > 3000);
+ CPPUNIT_ASSERT_MESSAGE(fileName.toUtf8().getStr(), x.toInt32() < 3500);
+
+ // Fails without the fix: Expected: 7359, Actual: 7336
+ assertXPath(pDoc, "/metafile/push[2]/textarray[1]", "x", "7359");
+ // Fails without the fix: Expected: 4118, Actual: 4104
+ assertXPath(pDoc, "/metafile/push[2]/textarray[1]", "y", "4118");
+
+ // Fails without the fix: Expected: 5989, Actual: 5971
+ assertXPath(pDoc, "/metafile/push[2]/textarray[2]", "x", "5989");
+ // Fails without the fix: Expected: 16264, Actual: 16208
+ assertXPath(pDoc, "/metafile/push[2]/textarray[2]", "y", "16264");
+
+ // Fails without the fix: Expected: 20769, Actual: 20705
+ assertXPath(pDoc, "/metafile/push[2]/textarray[3]", "x", "20769");
+ // Fails without the fix: Expected: 4077, Actual: 4062
+ assertXPath(pDoc, "/metafile/push[2]/textarray[3]", "y", "4077");
}
void WmfTest::testSine()