Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <test/bootstrapfixture.hxx>
21 : #include <test/xmltesttools.hxx>
22 : #include <test/mtfxmldump.hxx>
23 : #include <vcl/wmf.hxx>
24 : #include <vcl/metaact.hxx>
25 :
26 : using namespace css;
27 :
28 8 : class WmfTest : public test::BootstrapFixture, public XmlTestTools
29 : {
30 : OUString maDataUrl;
31 :
32 4 : OUString getFullUrl(const OUString& sFileName)
33 : {
34 4 : return getURLFromSrc(maDataUrl) + sFileName;
35 : }
36 :
37 : public:
38 4 : WmfTest() :
39 : BootstrapFixture(true, false),
40 4 : maDataUrl("/vcl/qa/cppunit/wmf/data/")
41 4 : {}
42 :
43 : void testNonPlaceableWmf();
44 : void testSine();
45 : void testEmfProblem();
46 : void testWorldTransformFontSize();
47 :
48 2 : CPPUNIT_TEST_SUITE(WmfTest);
49 1 : CPPUNIT_TEST(testNonPlaceableWmf);
50 1 : CPPUNIT_TEST(testSine);
51 1 : CPPUNIT_TEST(testEmfProblem);
52 1 : CPPUNIT_TEST(testWorldTransformFontSize);
53 :
54 5 : CPPUNIT_TEST_SUITE_END();
55 : };
56 :
57 1 : void WmfTest::testNonPlaceableWmf()
58 : {
59 1 : SvFileStream aFileStream(getFullUrl("visio_import_source.wmf"), StreamMode::READ);
60 2 : GDIMetaFile aGDIMetaFile;
61 1 : ReadWindowMetafile(aFileStream, aGDIMetaFile);
62 :
63 2 : MetafileXmlDump dumper;
64 1 : dumper.filterAllActionTypes();
65 1 : dumper.filterActionType(MetaActionType::POLYLINE, false);
66 1 : xmlDocPtr pDoc = dumper.dumpAndParse(aGDIMetaFile);
67 :
68 1 : CPPUNIT_ASSERT (pDoc);
69 :
70 1 : assertXPath(pDoc, "/metafile/polyline[1]/point[1]", "x", "16798");
71 1 : assertXPath(pDoc, "/metafile/polyline[1]/point[1]", "y", "1003");
72 :
73 1 : assertXPath(pDoc, "/metafile/polyline[1]/point[2]", "x", "16798");
74 1 : assertXPath(pDoc, "/metafile/polyline[1]/point[2]", "y", "7507");
75 :
76 1 : assertXPath(pDoc, "/metafile/polyline[1]/point[3]", "x", "26090");
77 1 : assertXPath(pDoc, "/metafile/polyline[1]/point[3]", "y", "7507");
78 :
79 1 : assertXPath(pDoc, "/metafile/polyline[1]/point[4]", "x", "26090");
80 1 : assertXPath(pDoc, "/metafile/polyline[1]/point[4]", "y", "1003");
81 :
82 1 : assertXPath(pDoc, "/metafile/polyline[1]/point[5]", "x", "16798");
83 2 : assertXPath(pDoc, "/metafile/polyline[1]/point[5]", "y", "1003");
84 1 : }
85 :
86 1 : void WmfTest::testSine()
87 : {
88 1 : SvFileStream aFileStream(getFullUrl("sine_wave.emf"), StreamMode::READ);
89 2 : GDIMetaFile aGDIMetaFile;
90 1 : ReadWindowMetafile(aFileStream, aGDIMetaFile);
91 :
92 2 : MetafileXmlDump dumper;
93 1 : dumper.filterAllActionTypes();
94 1 : dumper.filterActionType(MetaActionType::ISECTRECTCLIPREGION, false);
95 1 : xmlDocPtr pDoc = dumper.dumpAndParse(aGDIMetaFile);
96 :
97 1 : CPPUNIT_ASSERT (pDoc);
98 :
99 2 : assertXPath(pDoc, "/metafile/sectrectclipregion", 0);
100 1 : }
101 :
102 1 : void WmfTest::testEmfProblem()
103 : {
104 1 : SvFileStream aFileStream(getFullUrl("computer_mail.emf"), StreamMode::READ);
105 2 : GDIMetaFile aGDIMetaFile;
106 1 : ReadWindowMetafile(aFileStream, aGDIMetaFile);
107 :
108 2 : MetafileXmlDump dumper;
109 1 : dumper.filterAllActionTypes();
110 1 : dumper.filterActionType(MetaActionType::ISECTRECTCLIPREGION, false);
111 1 : xmlDocPtr pDoc = dumper.dumpAndParse(aGDIMetaFile);
112 :
113 1 : CPPUNIT_ASSERT (pDoc);
114 :
115 1 : assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "top", "427");
116 1 : assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "left", "740");
117 1 : assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "bottom", "2823");
118 2 : assertXPath(pDoc, "/metafile/sectrectclipregion[1]", "right", "1876");
119 1 : }
120 :
121 1 : void WmfTest::testWorldTransformFontSize()
122 : {
123 1 : SvFileStream aFileStream(getFullUrl("image1.emf"), StreamMode::READ);
124 2 : GDIMetaFile aGDIMetaFile;
125 1 : ReadWindowMetafile(aFileStream, aGDIMetaFile);
126 :
127 2 : MetafileXmlDump dumper;
128 1 : dumper.filterAllActionTypes();
129 1 : dumper.filterActionType(MetaActionType::FONT, false);
130 1 : xmlDocPtr pDoc = dumper.dumpAndParse(aGDIMetaFile);
131 :
132 1 : CPPUNIT_ASSERT (pDoc);
133 :
134 1 : assertXPath(pDoc, "/metafile/font", 8);
135 :
136 1 : assertXPath(pDoc, "/metafile/font[1]", "color", "#595959");
137 1 : assertXPath(pDoc, "/metafile/font[1]", "width", "0");
138 1 : assertXPath(pDoc, "/metafile/font[1]", "height", "389");
139 1 : assertXPath(pDoc, "/metafile/font[1]", "orientation", "0");
140 1 : assertXPath(pDoc, "/metafile/font[1]", "weight", "bold");
141 :
142 : // World transform should not affect font size. Rotating text for 90 degrees
143 : // should not exchange font width and height.
144 1 : assertXPath(pDoc, "/metafile/font[3]", "color", "#000000");
145 1 : assertXPath(pDoc, "/metafile/font[3]", "width", "0");
146 1 : assertXPath(pDoc, "/metafile/font[3]", "height", "530");
147 1 : assertXPath(pDoc, "/metafile/font[3]", "orientation", "900");
148 2 : assertXPath(pDoc, "/metafile/font[3]", "weight", "normal");
149 1 : }
150 :
151 1 : CPPUNIT_TEST_SUITE_REGISTRATION(WmfTest);
152 :
153 4 : CPPUNIT_PLUGIN_IMPLEMENT();
154 :
155 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|