bump product version to 7.6.3.2-android
[LibreOffice.git] / xmloff / source / style / MarkerStyle.cxx
blob9cf9ecc9423e7fc4069c70397881fa2ebde42996
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 <memory>
21 #include <xmloff/MarkerStyle.hxx>
22 #include <xexptran.hxx>
23 #include <xmloff/namespacemap.hxx>
24 #include <xmloff/xmluconv.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlexp.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <sal/log.hxx>
30 #include <rtl/ustring.hxx>
31 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
32 #include <basegfx/polygon/b2dpolypolygon.hxx>
33 #include <basegfx/polygon/b2dpolypolygontools.hxx>
34 #include <basegfx/matrix/b2dhommatrixtools.hxx>
36 using namespace ::com::sun::star;
38 using namespace ::xmloff::token;
40 // Import
42 XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport& rImp )
43 : m_rImport( rImp )
47 void XMLMarkerStyleImport::importXML(
48 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList,
49 uno::Any& rValue,
50 OUString& rStrName )
52 bool bHasViewBox = false;
53 bool bHasPathData = false;
54 OUString aDisplayName;
56 std::unique_ptr<SdXMLImExViewBox> xViewBox;
58 SvXMLUnitConverter& rUnitConverter = m_rImport.GetMM100UnitConverter();
60 OUString strPathData;
62 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
64 OUString aStrValue = aIter.toString();
66 switch (aIter.getToken() & TOKEN_MASK)
68 case XML_NAME:
69 rStrName = aStrValue;
70 break;
71 case XML_DISPLAY_NAME:
72 aDisplayName = aStrValue;
73 break;
74 case XML_VIEWBOX:
75 xViewBox.reset(new SdXMLImExViewBox(aStrValue, rUnitConverter));
76 bHasViewBox = true;
77 break;
78 case XML_D:
79 strPathData = aStrValue;
80 bHasPathData = true;
81 break;
82 default:
83 XMLOFF_WARN_UNKNOWN("xmloff.style", aIter);
87 if( bHasViewBox && bHasPathData )
89 basegfx::B2DPolyPolygon aPolyPolygon;
91 if(basegfx::utils::importFromSvgD(aPolyPolygon, strPathData, m_rImport.needFixPositionAfterZ(), nullptr))
93 if(aPolyPolygon.count())
95 // ViewBox probably not used, but stay with former processing inside of
96 // SdXMLImExSvgDElement
97 const basegfx::B2DRange aSourceRange(
98 xViewBox->GetX(), xViewBox->GetY(),
99 xViewBox->GetX() + xViewBox->GetWidth(),
100 xViewBox->GetY() + xViewBox->GetHeight());
101 const basegfx::B2DRange aTargetRange(
102 0.0, 0.0,
103 xViewBox->GetWidth(), xViewBox->GetHeight());
105 if(!aSourceRange.equal(aTargetRange))
107 aPolyPolygon.transform(
108 basegfx::utils::createSourceRangeTargetRangeTransform(
109 aSourceRange,
110 aTargetRange));
113 // always use PolyPolygonBezierCoords here
114 drawing::PolyPolygonBezierCoords aSourcePolyPolygon;
116 basegfx::utils::B2DPolyPolygonToUnoPolyPolygonBezierCoords(
117 aPolyPolygon,
118 aSourcePolyPolygon);
119 rValue <<= aSourcePolyPolygon;
123 if( !aDisplayName.isEmpty() )
125 m_rImport.AddStyleDisplayName( XmlStyleFamily::SD_MARKER_ID, rStrName,
126 aDisplayName );
127 rStrName = aDisplayName;
131 xViewBox.reset();
134 // Export
136 XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport& rExp )
137 : m_rExport( rExp )
141 void XMLMarkerStyleExport::exportXML(
142 const OUString& rStrName,
143 const uno::Any& rValue )
145 if(rStrName.isEmpty())
146 return;
148 drawing::PolyPolygonBezierCoords aBezier;
150 if(!(rValue >>= aBezier))
151 return;
153 // Name
154 bool bEncoded(false);
156 m_rExport.AddAttribute(XML_NAMESPACE_DRAW, XML_NAME, m_rExport.EncodeStyleName( rStrName, &bEncoded ) );
158 if( bEncoded )
160 m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, rStrName );
163 const basegfx::B2DPolyPolygon aPolyPolygon(
164 basegfx::utils::UnoPolyPolygonBezierCoordsToB2DPolyPolygon(
165 aBezier));
166 const basegfx::B2DRange aPolyPolygonRange(aPolyPolygon.getB2DRange());
169 // Viewbox (viewBox="0 0 1500 1000")
171 SdXMLImExViewBox aViewBox(
172 aPolyPolygonRange.getMinX(),
173 aPolyPolygonRange.getMinY(),
174 aPolyPolygonRange.getWidth(),
175 aPolyPolygonRange.getHeight());
176 m_rExport.AddAttribute( XML_NAMESPACE_SVG, XML_VIEWBOX, aViewBox.GetExportString() );
178 // Pathdata
179 const OUString aPolygonString(
180 basegfx::utils::exportToSvgD(
181 aPolyPolygon,
182 true, // bUseRelativeCoordinates
183 false, // bDetectQuadraticBeziers: not used in old, but maybe activated now
184 true)); // bHandleRelativeNextPointCompatible
186 // write point array
187 m_rExport.AddAttribute(XML_NAMESPACE_SVG, XML_D, aPolygonString);
189 // Do Write
190 SvXMLElementExport rElem( m_rExport, XML_NAMESPACE_DRAW, XML_MARKER, true, false );
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */