Bump version to 24.04.3.4
[LibreOffice.git] / emfio / qa / cppunit / wmf / wmfimporttest.cxx
blob426b8d1b658c4fb80f62febda13f5680ed8bd7b2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <string_view>
24 #include <test/xmltesttools.hxx>
25 #include <test/bootstrapfixture.hxx>
26 #include <vcl/gdimtf.hxx>
27 #include <vcl/wmf.hxx>
28 #include <mtftools.hxx>
30 using namespace css;
32 class WmfTest : public test::BootstrapFixture, public XmlTestTools
34 OUString maDataUrl;
36 OUString getFullUrl(std::u16string_view sFileName)
38 return m_directories.getURLFromSrc(maDataUrl) + sFileName;
41 public:
42 WmfTest()
43 : BootstrapFixture(true, false)
44 , maDataUrl("/emfio/qa/cppunit/wmf/data/")
48 void testEOFWmf();
49 void testNonPlaceableWmf();
50 void testTdf88163NonPlaceableWmf();
51 void testTdf88163PlaceableWmf();
52 void testSetTextAlignWmf();
53 void testSine();
54 void testEmfProblem();
55 void testEmfLineStyles();
56 void testWorldTransformFontSize();
57 void testBigPPI();
58 void testTdf93750();
59 void testTdf99402();
60 void testTdf39894Wmf();
61 void testTdf39894Emf();
62 void testETO_PDYWmf();
63 void testETO_PDYEmf();
64 void testStockObject();
66 CPPUNIT_TEST_SUITE(WmfTest);
67 CPPUNIT_TEST(testEOFWmf);
68 CPPUNIT_TEST(testNonPlaceableWmf);
69 CPPUNIT_TEST(testTdf88163NonPlaceableWmf);
70 CPPUNIT_TEST(testTdf88163PlaceableWmf);
71 CPPUNIT_TEST(testSetTextAlignWmf);
72 CPPUNIT_TEST(testSine);
73 CPPUNIT_TEST(testEmfProblem);
74 CPPUNIT_TEST(testEmfLineStyles);
75 CPPUNIT_TEST(testWorldTransformFontSize);
76 CPPUNIT_TEST(testBigPPI);
77 CPPUNIT_TEST(testTdf93750);
78 CPPUNIT_TEST(testTdf99402);
79 CPPUNIT_TEST(testTdf39894Wmf);
80 CPPUNIT_TEST(testTdf39894Emf);
81 CPPUNIT_TEST(testETO_PDYWmf);
82 CPPUNIT_TEST(testETO_PDYEmf);
83 CPPUNIT_TEST(testStockObject);
84 CPPUNIT_TEST_SUITE_END();
87 void WmfTest::testEOFWmf()
89 // tdf#155887 Test META_EOF with size different than 3
90 // It should be properly displayed as MS Office do
91 SvFileStream aFileStream(getFullUrl(u"EOF.wmf"), StreamMode::READ);
92 GDIMetaFile aGDIMetaFile;
93 ReadWindowMetafile(aFileStream, aGDIMetaFile);
95 MetafileXmlDump dumper;
96 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
98 CPPUNIT_ASSERT(pDoc);
99 assertXPath(pDoc, "/metafile/push"_ostr, 2);
100 assertXPath(pDoc, "/metafile/push[2]"_ostr, "flags"_ostr, "PushClipRegion");
101 assertXPath(pDoc, "/metafile/push[2]/fillcolor"_ostr, 2);
102 assertXPath(pDoc, "/metafile/push[2]/fillcolor[1]"_ostr, "color"_ostr, "#000000");
103 assertXPath(pDoc, "/metafile/push[2]/fillcolor[2]"_ostr, "color"_ostr, "#d0d0d0");
104 assertXPath(pDoc, "/metafile/push[2]/linecolor"_ostr, 60);
105 assertXPath(pDoc, "/metafile/push[2]/polyline"_ostr, 209);
106 assertXPath(pDoc, "/metafile/push[2]/polyline[1]/point"_ostr, 5);
107 assertXPath(pDoc, "/metafile/push[2]/polyline[1]/point[3]"_ostr, "x"_ostr, "16906");
108 assertXPath(pDoc, "/metafile/push[2]/polyline[1]/point[3]"_ostr, "y"_ostr, "12673");
109 assertXPath(pDoc, "/metafile/push[2]/textarray"_ostr, 307);
112 void WmfTest::testNonPlaceableWmf()
114 SvFileStream aFileStream(getFullUrl(u"visio_import_source.wmf"), StreamMode::READ);
115 GDIMetaFile aGDIMetaFile;
116 ReadWindowMetafile(aFileStream, aGDIMetaFile);
118 MetafileXmlDump dumper;
119 dumper.filterAllActionTypes();
120 dumper.filterActionType(MetaActionType::POLYLINE, false);
122 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
124 CPPUNIT_ASSERT(pDoc);
126 // These values come from changes done in tdf#88163
127 assertXPath(pDoc, "/metafile/polyline[1]/point[1]"_ostr, "x"_ostr, "16813");
128 assertXPath(pDoc, "/metafile/polyline[1]/point[1]"_ostr, "y"_ostr, "1004");
130 assertXPath(pDoc, "/metafile/polyline[1]/point[2]"_ostr, "x"_ostr, "16813");
131 assertXPath(pDoc, "/metafile/polyline[1]/point[2]"_ostr, "y"_ostr, "7514");
133 assertXPath(pDoc, "/metafile/polyline[1]/point[3]"_ostr, "x"_ostr, "26112");
134 assertXPath(pDoc, "/metafile/polyline[1]/point[3]"_ostr, "y"_ostr, "7514");
136 assertXPath(pDoc, "/metafile/polyline[1]/point[4]"_ostr, "x"_ostr, "26112");
137 assertXPath(pDoc, "/metafile/polyline[1]/point[4]"_ostr, "y"_ostr, "1004");
139 assertXPath(pDoc, "/metafile/polyline[1]/point[5]"_ostr, "x"_ostr, "16813");
140 assertXPath(pDoc, "/metafile/polyline[1]/point[5]"_ostr, "y"_ostr, "1004");
143 void WmfTest::testTdf88163NonPlaceableWmf()
145 OUString fileName(u"tdf88163-non-placeable.wmf"_ustr);
146 SvFileStream aFileStream(getFullUrl(fileName), StreamMode::READ);
147 GDIMetaFile aGDIMetaFile;
148 ReadWindowMetafile(aFileStream, aGDIMetaFile);
150 MetafileXmlDump dumper;
151 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
153 CPPUNIT_ASSERT(pDoc);
155 // These values come from the fix for tdf#88163
157 // Fails without the fix
158 // With fix: 3272, without fix: ~ 8000
159 auto x = getXPath(pDoc, "/metafile/push[2]/font[1]"_ostr, "height"_ostr);
160 CPPUNIT_ASSERT_EQUAL(sal_Int32(3272), x.toInt32());
162 // Fails without the fix: Expected: 7359, Actual: 7336
163 assertXPath(pDoc, "/metafile/push[2]/textarray[1]"_ostr, "x"_ostr, "7359");
164 // Fails without the fix: Expected: 4118, Actual: 4104
165 assertXPath(pDoc, "/metafile/push[2]/textarray[1]"_ostr, "y"_ostr, "4118");
167 // Fails without the fix: Expected: 5989, Actual: 5971
168 assertXPath(pDoc, "/metafile/push[2]/textarray[2]"_ostr, "x"_ostr, "5989");
169 // Fails without the fix: Expected: 16264, Actual: 16208
170 assertXPath(pDoc, "/metafile/push[2]/textarray[2]"_ostr, "y"_ostr, "16264");
172 // Fails without the fix: Expected: 20769, Actual: 20705
173 assertXPath(pDoc, "/metafile/push[2]/textarray[3]"_ostr, "x"_ostr, "20769");
174 // Fails without the fix: Expected: 4077, Actual: 4062
175 assertXPath(pDoc, "/metafile/push[2]/textarray[3]"_ostr, "y"_ostr, "4077");
178 void WmfTest::testTdf88163PlaceableWmf()
180 OUString fileName(u"tdf88163-wrong-font-size.wmf"_ustr);
181 SvFileStream aFileStream(getFullUrl(fileName), StreamMode::READ);
182 GDIMetaFile aGDIMetaFile;
183 ReadWindowMetafile(aFileStream, aGDIMetaFile);
185 MetafileXmlDump dumper;
187 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
189 CPPUNIT_ASSERT(pDoc);
191 // These values come from the fix for tdf#88163
193 // The fix does not affect the font size
194 auto x = getXPath(pDoc, "/metafile/push[2]/font[1]"_ostr, "height"_ostr);
195 CPPUNIT_ASSERT_EQUAL(sal_Int32(313), x.toInt32());
197 // Fails without the fix: Expected: 1900, Actual: 19818
198 assertXPath(pDoc, "/metafile"_ostr, "height"_ostr, "1900");
200 // Fails without the fix: Expected: 704, Actual: 7336
201 assertXPath(pDoc, "/metafile/push[2]/textarray[1]"_ostr, "x"_ostr, "704");
202 // Fails without the fix: Expected: 394, Actual: 4110
203 assertXPath(pDoc, "/metafile/push[2]/textarray[1]"_ostr, "y"_ostr, "394");
205 // Fails without the fix: Expected: 573, Actual: 5971
206 assertXPath(pDoc, "/metafile/push[2]/textarray[2]"_ostr, "x"_ostr, "573");
207 // Fails without the fix: Expected: 1556, Actual: 16230
208 assertXPath(pDoc, "/metafile/push[2]/textarray[2]"_ostr, "y"_ostr, "1556");
210 // Fails without the fix: Expected: 1987, Actual: 20706
211 assertXPath(pDoc, "/metafile/push[2]/textarray[3]"_ostr, "x"_ostr, "1987");
212 // Fails without the fix: Expected: 390, Actual: 4068
213 assertXPath(pDoc, "/metafile/push[2]/textarray[3]"_ostr, "y"_ostr, "390");
216 void WmfTest::testSetTextAlignWmf()
218 OUString fileName(u"TestSetTextAlign.wmf"_ustr);
219 SvFileStream aFileStream(getFullUrl(fileName), StreamMode::READ);
220 GDIMetaFile aGDIMetaFile;
221 ReadWindowMetafile(aFileStream, aGDIMetaFile);
223 MetafileXmlDump dumper;
225 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
227 CPPUNIT_ASSERT(pDoc);
229 assertXPath(pDoc, "/metafile"_ostr, "height"_ostr, "20999");
231 assertXPath(pDoc, "/metafile/push[2]/textalign[2]"_ostr, "align"_ostr, "top");
232 assertXPath(pDoc, "/metafile/push[2]/textarray[2]"_ostr, "x"_ostr, "11642");
233 assertXPath(pDoc, "/metafile/push[2]/textarray[2]"_ostr, "y"_ostr, "212");
234 assertXPathContent(pDoc, "/metafile/push[2]/textarray[2]/text"_ostr, "textalignment:default");
236 assertXPath(pDoc, "/metafile/push[2]/textalign[3]"_ostr, "align"_ostr, "top");
237 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[3]"_ostr, "x"_ostr, 12700, 30);
238 assertXPath(pDoc, "/metafile/push[2]/textarray[3]"_ostr, "y"_ostr, "212");
239 assertXPathContent(pDoc, "/metafile/push[2]/textarray[3]/text"_ostr, "textalignment:0x00");
241 assertXPath(pDoc, "/metafile/push[2]/textalign[4]"_ostr, "align"_ostr, "top");
242 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[4]"_ostr, "x"_ostr, 12026, 30);
243 assertXPath(pDoc, "/metafile/push[2]/textarray[4]"_ostr, "y"_ostr, "423");
244 assertXPathContent(pDoc, "/metafile/push[2]/textarray[4]/text"_ostr, "textalignment:0x02");
246 assertXPath(pDoc, "/metafile/push[2]/textalign[5]"_ostr, "align"_ostr, "top");
247 // Fails without the fix: Expected: 12026, Actual: 12350
248 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[5]"_ostr, "x"_ostr, 12026, 30);
249 assertXPath(pDoc, "/metafile/push[2]/textarray[5]"_ostr, "y"_ostr, "635");
250 assertXPathContent(pDoc, "/metafile/push[2]/textarray[5]/text"_ostr, "textalignment:0x04");
252 assertXPath(pDoc, "/metafile/push[2]/textalign[6]"_ostr, "align"_ostr, "top");
253 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[6]"_ostr, "x"_ostr, 12363, 30);
254 assertXPath(pDoc, "/metafile/push[2]/textarray[6]"_ostr, "y"_ostr, "847");
255 assertXPathContent(pDoc, "/metafile/push[2]/textarray[6]/text"_ostr, "textalignment:0x06");
257 assertXPath(pDoc, "/metafile/push[2]/textalign[7]"_ostr, "align"_ostr, "top");
258 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[7]"_ostr, "x"_ostr, 12700, 30);
259 assertXPath(pDoc, "/metafile/push[2]/textarray[7]"_ostr, "y"_ostr, "1058");
260 assertXPathContent(pDoc, "/metafile/push[2]/textarray[7]/text"_ostr, "textalignment:0x08");
262 assertXPath(pDoc, "/metafile/push[2]/textalign[8]"_ostr, "align"_ostr, "top");
263 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[8]"_ostr, "x"_ostr, 12026, 30);
264 assertXPath(pDoc, "/metafile/push[2]/textarray[8]"_ostr, "y"_ostr, "1270");
265 assertXPathContent(pDoc, "/metafile/push[2]/textarray[8]/text"_ostr, "textalignment:0x0A");
267 assertXPath(pDoc, "/metafile/push[2]/textalign[9]"_ostr, "align"_ostr, "bottom");
268 // Fails without the fix: Expected: 12026, Actual: 12350
269 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[9]"_ostr, "x"_ostr, 12026, 30);
270 assertXPath(pDoc, "/metafile/push[2]/textarray[9]"_ostr, "y"_ostr, "1482");
271 assertXPathContent(pDoc, "/metafile/push[2]/textarray[9]/text"_ostr, "textalignment:0x0C");
273 assertXPath(pDoc, "/metafile/push[2]/textalign[10]"_ostr, "align"_ostr, "bottom");
274 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[10]"_ostr, "x"_ostr, 12363, 30);
275 assertXPath(pDoc, "/metafile/push[2]/textarray[10]"_ostr, "y"_ostr, "1693");
276 assertXPathContent(pDoc, "/metafile/push[2]/textarray[10]/text"_ostr, "textalignment:0x0E");
278 assertXPath(pDoc, "/metafile/push[2]/textalign[11]"_ostr, "align"_ostr, "bottom");
279 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[11]"_ostr, "x"_ostr, 12700, 30);
280 assertXPath(pDoc, "/metafile/push[2]/textarray[11]"_ostr, "y"_ostr, "1905");
281 assertXPathContent(pDoc, "/metafile/push[2]/textarray[11]/text"_ostr, "textalignment:0x10");
283 assertXPath(pDoc, "/metafile/push[2]/textalign[12]"_ostr, "align"_ostr, "bottom");
284 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[12]"_ostr, "x"_ostr, 12026, 30);
285 assertXPath(pDoc, "/metafile/push[2]/textarray[12]"_ostr, "y"_ostr, "2117");
286 assertXPathContent(pDoc, "/metafile/push[2]/textarray[12]/text"_ostr, "textalignment:0x12");
288 assertXPath(pDoc, "/metafile/push[2]/textalign[13]"_ostr, "align"_ostr, "bottom");
289 // Fails without the fix: Expected: 12026, Actual: 12350
290 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[13]"_ostr, "x"_ostr, 12026, 30);
291 assertXPath(pDoc, "/metafile/push[2]/textarray[13]"_ostr, "y"_ostr, "2328");
292 assertXPathContent(pDoc, "/metafile/push[2]/textarray[13]/text"_ostr, "textalignment:0x14");
294 assertXPath(pDoc, "/metafile/push[2]/textalign[14]"_ostr, "align"_ostr, "bottom");
295 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[14]"_ostr, "x"_ostr, 12363, 30);
296 assertXPath(pDoc, "/metafile/push[2]/textarray[14]"_ostr, "y"_ostr, "2540");
297 assertXPathContent(pDoc, "/metafile/push[2]/textarray[14]/text"_ostr, "textalignment:0x16");
299 assertXPath(pDoc, "/metafile/push[2]/textalign[15]"_ostr, "align"_ostr, "bottom");
300 assertXPathDoubleValue(pDoc, "/metafile/push[2]/textarray[15]"_ostr, "x"_ostr, 12700, 30);
301 assertXPath(pDoc, "/metafile/push[2]/textarray[15]"_ostr, "y"_ostr, "2752");
302 assertXPathContent(pDoc, "/metafile/push[2]/textarray[15]/text"_ostr, "textalignment:0x18");
305 void WmfTest::testSine()
307 SvFileStream aFileStream(getFullUrl(u"sine_wave.emf"), StreamMode::READ);
308 GDIMetaFile aGDIMetaFile;
309 ReadWindowMetafile(aFileStream, aGDIMetaFile);
311 MetafileXmlDump dumper;
312 dumper.filterAllActionTypes();
313 dumper.filterActionType(MetaActionType::ISECTRECTCLIPREGION, false);
314 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
316 CPPUNIT_ASSERT(pDoc);
318 assertXPath(pDoc, "/metafile/sectrectclipregion"_ostr, 0);
321 void WmfTest::testEmfProblem()
323 SvFileStream aFileStream(getFullUrl(u"computer_mail.emf"), StreamMode::READ);
324 GDIMetaFile aGDIMetaFile;
325 ReadWindowMetafile(aFileStream, aGDIMetaFile);
327 MetafileXmlDump dumper;
328 dumper.filterAllActionTypes();
329 dumper.filterActionType(MetaActionType::ISECTRECTCLIPREGION, false);
330 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
332 CPPUNIT_ASSERT(pDoc);
334 assertXPath(pDoc, "/metafile/sectrectclipregion"_ostr, 2);
335 assertXPath(pDoc, "/metafile/sectrectclipregion[1]"_ostr, "top"_ostr, "2125");
336 assertXPath(pDoc, "/metafile/sectrectclipregion[1]"_ostr, "left"_ostr, "1084");
337 assertXPath(pDoc, "/metafile/sectrectclipregion[1]"_ostr, "bottom"_ostr, "2927");
338 assertXPath(pDoc, "/metafile/sectrectclipregion[1]"_ostr, "right"_ostr, "2376");
341 void WmfTest::testEmfLineStyles()
343 SvFileStream aFileStream(getFullUrl(u"line_styles.emf"), StreamMode::READ);
344 GDIMetaFile aGDIMetaFile;
345 ReadWindowMetafile(aFileStream, aGDIMetaFile);
347 MetafileXmlDump dumper;
348 dumper.filterAllActionTypes();
349 dumper.filterActionType(MetaActionType::LINE, false);
350 dumper.filterActionType(MetaActionType::LINECOLOR, false);
351 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
353 CPPUNIT_ASSERT(pDoc);
355 assertXPath(pDoc, "/metafile/line"_ostr, 4);
356 assertXPath(pDoc, "/metafile/linecolor"_ostr, 5);
358 assertXPath(pDoc, "/metafile/linecolor[1]"_ostr, "color"_ostr, "#ffffff");
359 assertXPath(pDoc, "/metafile/linecolor[2]"_ostr, "color"_ostr, "#00ff00");
360 assertXPath(pDoc, "/metafile/linecolor[3]"_ostr, "color"_ostr, "#408080");
361 assertXPath(pDoc, "/metafile/linecolor[4]"_ostr, "color"_ostr, "#ff0000");
362 assertXPath(pDoc, "/metafile/linecolor[5]"_ostr, "color"_ostr, "#0000ff");
364 assertXPath(pDoc, "/metafile/line[1]"_ostr, "style"_ostr, "dash");
365 assertXPath(pDoc, "/metafile/line[1]"_ostr, "dashlen"_ostr, "528");
366 assertXPath(pDoc, "/metafile/line[1]"_ostr, "dashcount"_ostr, "1");
367 assertXPath(pDoc, "/metafile/line[1]"_ostr, "dotlen"_ostr, "176");
368 assertXPath(pDoc, "/metafile/line[1]"_ostr, "dotcount"_ostr, "0");
369 assertXPath(pDoc, "/metafile/line[1]"_ostr, "distance"_ostr, "176");
370 assertXPath(pDoc, "/metafile/line[1]"_ostr, "join"_ostr, "miter");
371 assertXPath(pDoc, "/metafile/line[1]"_ostr, "cap"_ostr, "butt");
373 assertXPath(pDoc, "/metafile/line[2]"_ostr, "style"_ostr, "dash");
374 assertXPath(pDoc, "/metafile/line[2]"_ostr, "dashlen"_ostr, "528");
375 assertXPath(pDoc, "/metafile/line[2]"_ostr, "dashcount"_ostr, "0");
376 assertXPath(pDoc, "/metafile/line[2]"_ostr, "dotlen"_ostr, "176");
377 assertXPath(pDoc, "/metafile/line[2]"_ostr, "dotcount"_ostr, "1");
378 assertXPath(pDoc, "/metafile/line[2]"_ostr, "distance"_ostr, "176");
379 assertXPath(pDoc, "/metafile/line[2]"_ostr, "join"_ostr, "miter");
380 assertXPath(pDoc, "/metafile/line[2]"_ostr, "cap"_ostr, "butt");
382 assertXPath(pDoc, "/metafile/line[3]"_ostr, "style"_ostr, "dash");
383 assertXPath(pDoc, "/metafile/line[3]"_ostr, "dashlen"_ostr, "528");
384 assertXPath(pDoc, "/metafile/line[3]"_ostr, "dashcount"_ostr, "1");
385 assertXPath(pDoc, "/metafile/line[3]"_ostr, "dotlen"_ostr, "176");
386 assertXPath(pDoc, "/metafile/line[3]"_ostr, "dotcount"_ostr, "1");
387 assertXPath(pDoc, "/metafile/line[3]"_ostr, "distance"_ostr, "176");
388 assertXPath(pDoc, "/metafile/line[3]"_ostr, "join"_ostr, "miter");
389 assertXPath(pDoc, "/metafile/line[3]"_ostr, "cap"_ostr, "butt");
391 assertXPath(pDoc, "/metafile/line[4]"_ostr, "style"_ostr, "dash");
392 assertXPath(pDoc, "/metafile/line[4]"_ostr, "dashlen"_ostr, "528");
393 assertXPath(pDoc, "/metafile/line[4]"_ostr, "dashcount"_ostr, "1");
394 assertXPath(pDoc, "/metafile/line[4]"_ostr, "dotlen"_ostr, "176");
395 assertXPath(pDoc, "/metafile/line[4]"_ostr, "dotcount"_ostr, "2");
396 assertXPath(pDoc, "/metafile/line[4]"_ostr, "distance"_ostr, "176");
397 assertXPath(pDoc, "/metafile/line[4]"_ostr, "join"_ostr, "miter");
398 assertXPath(pDoc, "/metafile/line[4]"_ostr, "cap"_ostr, "butt");
401 void WmfTest::testWorldTransformFontSize()
403 SvFileStream aFileStream(getFullUrl(u"image1.emf"), StreamMode::READ);
404 GDIMetaFile aGDIMetaFile;
405 ReadWindowMetafile(aFileStream, aGDIMetaFile);
407 MetafileXmlDump dumper;
408 dumper.filterAllActionTypes();
409 dumper.filterActionType(MetaActionType::FONT, false);
410 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
412 CPPUNIT_ASSERT(pDoc);
414 assertXPath(pDoc, "/metafile/font"_ostr, 9);
416 assertXPath(pDoc, "/metafile/font[1]"_ostr, "color"_ostr, "#595959");
417 assertXPath(pDoc, "/metafile/font[1]"_ostr, "width"_ostr, "0");
418 assertXPath(pDoc, "/metafile/font[1]"_ostr, "height"_ostr, "389");
419 assertXPath(pDoc, "/metafile/font[1]"_ostr, "orientation"_ostr, "0");
420 assertXPath(pDoc, "/metafile/font[1]"_ostr, "weight"_ostr, "bold");
422 assertXPath(pDoc, "/metafile/font[3]"_ostr, "color"_ostr, "#000000");
423 assertXPath(pDoc, "/metafile/font[3]"_ostr, "width"_ostr, "0");
424 assertXPath(pDoc, "/metafile/font[3]"_ostr, "height"_ostr, "389");
425 assertXPath(pDoc, "/metafile/font[3]"_ostr, "orientation"_ostr, "0");
426 assertXPath(pDoc, "/metafile/font[3]"_ostr, "weight"_ostr, "bold");
428 // World transform should not affect font size. Rotating text for 90 degrees
429 // should not exchange font width and height.
430 assertXPath(pDoc, "/metafile/font[4]"_ostr, "color"_ostr, "#000000");
431 assertXPath(pDoc, "/metafile/font[4]"_ostr, "width"_ostr, "0");
432 assertXPath(pDoc, "/metafile/font[4]"_ostr, "height"_ostr, "530");
433 assertXPath(pDoc, "/metafile/font[4]"_ostr, "orientation"_ostr, "900");
434 assertXPath(pDoc, "/metafile/font[4]"_ostr, "weight"_ostr, "normal");
437 void WmfTest::testBigPPI()
439 // Test that PPI is reduced from 2540 to 96 (width from META_SETWINDOWEXT) to make the graphic
440 // bigger
441 SvFileStream aFileStream(getFullUrl(u"TestBigPPI.wmf"), StreamMode::READ);
442 GDIMetaFile aGDIMetaFile;
443 ReadWindowMetafile(aFileStream, aGDIMetaFile);
445 MetafileXmlDump dumper;
446 dumper.filterAllActionTypes();
447 dumper.filterActionType(MetaActionType::FONT, false);
448 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
450 CPPUNIT_ASSERT(pDoc);
452 // If the PPI was not reduced the width and height would be <100 which is too small
453 // Related: tdf#150888
454 assertXPath(pDoc, "/metafile"_ostr, "width"_ostr, "2540");
455 assertXPath(pDoc, "/metafile"_ostr, "height"_ostr, "2143");
458 void WmfTest::testTdf93750()
460 SvFileStream aFileStream(getFullUrl(u"tdf93750.emf"), StreamMode::READ);
461 GDIMetaFile aGDIMetaFile;
462 ReadWindowMetafile(aFileStream, aGDIMetaFile);
464 MetafileXmlDump dumper;
465 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
467 CPPUNIT_ASSERT(pDoc);
469 assertXPath(pDoc, "/metafile/push[1]/comment[2]"_ostr, "datasize"_ostr, "28");
470 assertXPath(pDoc, "/metafile/push[1]/comment[3]"_ostr, "datasize"_ostr, "72");
473 void WmfTest::testTdf99402()
475 // Symbol font should arrive with RTL_TEXTENCODING_SYMBOL encoding,
476 // even if charset is OEM_CHARSET/DEFAULT_CHARSET in WMF
477 emfio::LOGFONTW logfontw;
478 logfontw.lfHeight = 0;
479 logfontw.lfWidth = 0;
480 logfontw.lfEscapement = 0;
481 logfontw.lfWeight = 0;
482 logfontw.lfItalic = 0;
483 logfontw.lfUnderline = 0;
484 logfontw.lfStrikeOut = 0;
485 logfontw.lfCharSet = emfio::CharacterSet::OEM_CHARSET;
486 logfontw.lfPitchAndFamily = emfio::FamilyFont::FF_ROMAN << 4 | emfio::PitchFont::DEFAULT_PITCH;
487 logfontw.alfFaceName = "Symbol";
489 emfio::WinMtfFontStyle fontStyle(logfontw);
491 CPPUNIT_ASSERT_EQUAL(RTL_TEXTENCODING_SYMBOL, fontStyle.aFont.GetCharSet());
494 void WmfTest::testTdf39894Wmf()
496 SvFileStream aFileStream(getFullUrl(u"tdf39894.wmf"), StreamMode::READ);
497 GDIMetaFile aGDIMetaFile;
498 ReadWindowMetafile(aFileStream, aGDIMetaFile);
500 MetafileXmlDump dumper;
501 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
503 CPPUNIT_ASSERT(pDoc);
505 // The x position of the second text must take into account
506 // the previous text's last Dx (previously was ~300)
507 auto x = getXPath(pDoc, "/metafile/push[2]/textarray[2]"_ostr, "x"_ostr);
508 CPPUNIT_ASSERT_GREATER(sal_Int32(2700), x.toInt32());
511 void WmfTest::testTdf39894Emf()
513 SvFileStream aFileStream(getFullUrl(u"tdf39894.emf"), StreamMode::READ);
514 GDIMetaFile aGDIMetaFile;
515 ReadWindowMetafile(aFileStream, aGDIMetaFile);
517 MetafileXmlDump dumper;
518 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
520 CPPUNIT_ASSERT(pDoc);
522 // The x position of the second text must take into account
523 // the previous text's last Dx (previously was ~300)
524 auto x = getXPath(pDoc, "/metafile/push[2]/textarray[2]"_ostr, "x"_ostr);
525 CPPUNIT_ASSERT_GREATER(sal_Int32(2700), x.toInt32());
528 void WmfTest::testETO_PDYWmf()
530 SvFileStream aFileStream(getFullUrl(u"ETO_PDY.wmf"), StreamMode::READ);
531 GDIMetaFile aGDIMetaFile;
532 ReadWindowMetafile(aFileStream, aGDIMetaFile);
534 MetafileXmlDump dumper;
535 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
537 CPPUNIT_ASSERT(pDoc);
539 // The y position of following text
540 // must be smaller than that of previous
541 auto y1 = getXPath(pDoc, "/metafile/push[2]/textarray[1]"_ostr, "y"_ostr);
542 auto y2 = getXPath(pDoc, "/metafile/push[2]/textarray[2]"_ostr, "y"_ostr);
543 auto y3 = getXPath(pDoc, "/metafile/push[2]/textarray[3]"_ostr, "y"_ostr);
544 CPPUNIT_ASSERT(y2.toInt32() < y1.toInt32());
545 CPPUNIT_ASSERT(y3.toInt32() < y2.toInt32());
548 void WmfTest::testETO_PDYEmf()
550 SvFileStream aFileStream(getFullUrl(u"ETO_PDY.emf"), StreamMode::READ);
551 GDIMetaFile aGDIMetaFile;
552 ReadWindowMetafile(aFileStream, aGDIMetaFile);
554 MetafileXmlDump dumper;
555 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
557 CPPUNIT_ASSERT(pDoc);
559 // The y position of following text
560 // must be smaller than that of previous
561 auto y1 = getXPath(pDoc, "/metafile/push[2]/textarray[1]"_ostr, "y"_ostr);
562 auto y2 = getXPath(pDoc, "/metafile/push[2]/textarray[2]"_ostr, "y"_ostr);
563 auto y3 = getXPath(pDoc, "/metafile/push[2]/textarray[3]"_ostr, "y"_ostr);
564 CPPUNIT_ASSERT(y2.toInt32() < y1.toInt32());
565 CPPUNIT_ASSERT(y3.toInt32() < y2.toInt32());
568 void WmfTest::testStockObject()
570 SvFileStream aFileStream(getFullUrl(u"stockobject.emf"), StreamMode::READ);
571 GDIMetaFile aGDIMetaFile;
572 ReadWindowMetafile(aFileStream, aGDIMetaFile);
574 MetafileXmlDump dumper;
575 xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
577 CPPUNIT_ASSERT(pDoc);
579 // Without the fix in place, this test would have failed with
580 // - Expected: 1
581 // - Actual : 0
582 // - In <>, XPath '/metafile/push[2]/fillcolor[2]' number of nodes is incorrect
583 assertXPath(pDoc, "/metafile/push[2]/fillcolor[2]"_ostr, "color"_ostr, "#000000");
586 CPPUNIT_TEST_SUITE_REGISTRATION(WmfTest);
588 CPPUNIT_PLUGIN_IMPLEMENT();
590 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */