/src/libreoffice/xmloff/source/style/MarkerStyle.cxx
Line | Count | Source |
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 <memory> |
21 | | #include <xmloff/MarkerStyle.hxx> |
22 | | #include <xexptran.hxx> |
23 | | #include <xmloff/xmluconv.hxx> |
24 | | #include <xmloff/xmlnamespace.hxx> |
25 | | #include <xmloff/xmltoken.hxx> |
26 | | #include <xmloff/xmlexp.hxx> |
27 | | #include <xmloff/xmlimp.hxx> |
28 | | #include <sal/log.hxx> |
29 | | #include <rtl/ustring.hxx> |
30 | | #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp> |
31 | | #include <basegfx/polygon/b2dpolypolygon.hxx> |
32 | | #include <basegfx/polygon/b2dpolypolygontools.hxx> |
33 | | #include <basegfx/matrix/b2dhommatrixtools.hxx> |
34 | | |
35 | | using namespace ::com::sun::star; |
36 | | |
37 | | using namespace ::xmloff::token; |
38 | | |
39 | | // Import |
40 | | |
41 | | XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport& rImp ) |
42 | 31.0k | : m_rImport( rImp ) |
43 | 31.0k | { |
44 | 31.0k | } |
45 | | |
46 | | void XMLMarkerStyleImport::importXML( |
47 | | const uno::Reference< xml::sax::XFastAttributeList >& xAttrList, |
48 | | uno::Any& rValue, |
49 | | OUString& rStrName ) |
50 | 31.0k | { |
51 | 31.0k | bool bHasViewBox = false; |
52 | 31.0k | bool bHasPathData = false; |
53 | 31.0k | OUString aDisplayName; |
54 | | |
55 | 31.0k | std::unique_ptr<SdXMLImExViewBox> xViewBox; |
56 | | |
57 | 31.0k | SvXMLUnitConverter& rUnitConverter = m_rImport.GetMM100UnitConverter(); |
58 | | |
59 | 31.0k | OUString strPathData; |
60 | | |
61 | 31.0k | for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) |
62 | 78.8k | { |
63 | 78.8k | OUString aStrValue = aIter.toString(); |
64 | | |
65 | 78.8k | switch (aIter.getToken() & TOKEN_MASK) |
66 | 78.8k | { |
67 | 22.2k | case XML_NAME: |
68 | 22.2k | rStrName = aStrValue; |
69 | 22.2k | break; |
70 | 38 | case XML_DISPLAY_NAME: |
71 | 38 | aDisplayName = aStrValue; |
72 | 38 | break; |
73 | 28.3k | case XML_VIEWBOX: |
74 | 28.3k | xViewBox.reset(new SdXMLImExViewBox(aStrValue, rUnitConverter)); |
75 | 28.3k | bHasViewBox = true; |
76 | 28.3k | break; |
77 | 28.2k | case XML_D: |
78 | 28.2k | strPathData = aStrValue; |
79 | 28.2k | bHasPathData = true; |
80 | 28.2k | break; |
81 | 25 | default: |
82 | 25 | XMLOFF_WARN_UNKNOWN("xmloff.style", aIter); |
83 | 78.8k | } |
84 | 78.8k | } |
85 | | |
86 | 31.0k | if( bHasViewBox && bHasPathData ) |
87 | 27.1k | { |
88 | 27.1k | basegfx::B2DPolyPolygon aPolyPolygon; |
89 | | |
90 | 27.1k | if(basegfx::utils::importFromSvgD(aPolyPolygon, strPathData, m_rImport.needFixPositionAfterZ(), nullptr)) |
91 | 25.9k | { |
92 | 25.9k | if(aPolyPolygon.count()) |
93 | 25.9k | { |
94 | | // ViewBox probably not used, but stay with former processing inside of |
95 | | // SdXMLImExSvgDElement |
96 | 25.9k | const basegfx::B2DRange aSourceRange( |
97 | 25.9k | xViewBox->GetX(), xViewBox->GetY(), |
98 | 25.9k | xViewBox->GetX() + xViewBox->GetWidth(), |
99 | 25.9k | xViewBox->GetY() + xViewBox->GetHeight()); |
100 | 25.9k | const basegfx::B2DRange aTargetRange( |
101 | 25.9k | 0.0, 0.0, |
102 | 25.9k | xViewBox->GetWidth(), xViewBox->GetHeight()); |
103 | | |
104 | 25.9k | if(!aSourceRange.equal(aTargetRange)) |
105 | 8.17k | { |
106 | 8.17k | aPolyPolygon.transform( |
107 | 8.17k | basegfx::utils::createSourceRangeTargetRangeTransform( |
108 | 8.17k | aSourceRange, |
109 | 8.17k | aTargetRange)); |
110 | 8.17k | } |
111 | | |
112 | | // always use PolyPolygonBezierCoords here |
113 | 25.9k | drawing::PolyPolygonBezierCoords aSourcePolyPolygon; |
114 | | |
115 | 25.9k | basegfx::utils::B2DPolyPolygonToUnoPolyPolygonBezierCoords( |
116 | 25.9k | aPolyPolygon, |
117 | 25.9k | aSourcePolyPolygon); |
118 | 25.9k | rValue <<= aSourcePolyPolygon; |
119 | 25.9k | } |
120 | 25.9k | } |
121 | | |
122 | 27.1k | if( !aDisplayName.isEmpty() ) |
123 | 25 | { |
124 | 25 | m_rImport.AddStyleDisplayName( XmlStyleFamily::SD_MARKER_ID, rStrName, |
125 | 25 | aDisplayName ); |
126 | 25 | rStrName = aDisplayName; |
127 | 25 | } |
128 | 27.1k | } |
129 | | |
130 | 31.0k | xViewBox.reset(); |
131 | 31.0k | } |
132 | | |
133 | | // Export |
134 | | |
135 | | XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport& rExp ) |
136 | 3 | : m_rExport( rExp ) |
137 | 3 | { |
138 | 3 | } |
139 | | |
140 | | void XMLMarkerStyleExport::exportXML( |
141 | | const OUString& rStrName, |
142 | | const uno::Any& rValue ) |
143 | 3 | { |
144 | 3 | if(rStrName.isEmpty()) |
145 | 0 | return; |
146 | | |
147 | 3 | drawing::PolyPolygonBezierCoords aBezier; |
148 | | |
149 | 3 | if(!(rValue >>= aBezier)) |
150 | 0 | return; |
151 | | |
152 | | // Name |
153 | 3 | bool bEncoded(false); |
154 | | |
155 | 3 | m_rExport.AddAttribute(XML_NAMESPACE_DRAW, XML_NAME, m_rExport.EncodeStyleName( rStrName, &bEncoded ) ); |
156 | | |
157 | 3 | if( bEncoded ) |
158 | 0 | { |
159 | 0 | m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, rStrName ); |
160 | 0 | } |
161 | | |
162 | 3 | const basegfx::B2DPolyPolygon aPolyPolygon( |
163 | 3 | basegfx::utils::UnoPolyPolygonBezierCoordsToB2DPolyPolygon( |
164 | 3 | aBezier)); |
165 | 3 | const basegfx::B2DRange aPolyPolygonRange(aPolyPolygon.getB2DRange()); |
166 | | |
167 | | |
168 | | // Viewbox (viewBox="0 0 1500 1000") |
169 | | |
170 | 3 | SdXMLImExViewBox aViewBox( |
171 | 3 | aPolyPolygonRange.getMinX(), |
172 | 3 | aPolyPolygonRange.getMinY(), |
173 | 3 | aPolyPolygonRange.getWidth(), |
174 | 3 | aPolyPolygonRange.getHeight()); |
175 | 3 | m_rExport.AddAttribute( XML_NAMESPACE_SVG, XML_VIEWBOX, aViewBox.GetExportString() ); |
176 | | |
177 | | // Pathdata |
178 | 3 | const OUString aPolygonString( |
179 | 3 | basegfx::utils::exportToSvgD( |
180 | 3 | aPolyPolygon, |
181 | 3 | true, // bUseRelativeCoordinates |
182 | 3 | false, // bDetectQuadraticBeziers: not used in old, but maybe activated now |
183 | 3 | true)); // bHandleRelativeNextPointCompatible |
184 | | |
185 | | // write point array |
186 | 3 | m_rExport.AddAttribute(XML_NAMESPACE_SVG, XML_D, aPolygonString); |
187 | | |
188 | | // Do Write |
189 | 3 | SvXMLElementExport rElem( m_rExport, XML_NAMESPACE_DRAW, XML_MARKER, true, false ); |
190 | 3 | } |
191 | | |
192 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |