tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / xmloff / source / style / MarkerStyle.cxx
blob5e4107888a77c72772d92332d88e44bbd3057d9d
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/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>
35 using namespace ::com::sun::star;
37 using namespace ::xmloff::token;
39 // Import
41 XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport& rImp )
42 : m_rImport( rImp )
46 void XMLMarkerStyleImport::importXML(
47 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList,
48 uno::Any& rValue,
49 OUString& rStrName )
51 bool bHasViewBox = false;
52 bool bHasPathData = false;
53 OUString aDisplayName;
55 std::unique_ptr<SdXMLImExViewBox> xViewBox;
57 SvXMLUnitConverter& rUnitConverter = m_rImport.GetMM100UnitConverter();
59 OUString strPathData;
61 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
63 OUString aStrValue = aIter.toString();
65 switch (aIter.getToken() & TOKEN_MASK)
67 case XML_NAME:
68 rStrName = aStrValue;
69 break;
70 case XML_DISPLAY_NAME:
71 aDisplayName = aStrValue;
72 break;
73 case XML_VIEWBOX:
74 xViewBox.reset(new SdXMLImExViewBox(aStrValue, rUnitConverter));
75 bHasViewBox = true;
76 break;
77 case XML_D:
78 strPathData = aStrValue;
79 bHasPathData = true;
80 break;
81 default:
82 XMLOFF_WARN_UNKNOWN("xmloff.style", aIter);
86 if( bHasViewBox && bHasPathData )
88 basegfx::B2DPolyPolygon aPolyPolygon;
90 if(basegfx::utils::importFromSvgD(aPolyPolygon, strPathData, m_rImport.needFixPositionAfterZ(), nullptr))
92 if(aPolyPolygon.count())
94 // ViewBox probably not used, but stay with former processing inside of
95 // SdXMLImExSvgDElement
96 const basegfx::B2DRange aSourceRange(
97 xViewBox->GetX(), xViewBox->GetY(),
98 xViewBox->GetX() + xViewBox->GetWidth(),
99 xViewBox->GetY() + xViewBox->GetHeight());
100 const basegfx::B2DRange aTargetRange(
101 0.0, 0.0,
102 xViewBox->GetWidth(), xViewBox->GetHeight());
104 if(!aSourceRange.equal(aTargetRange))
106 aPolyPolygon.transform(
107 basegfx::utils::createSourceRangeTargetRangeTransform(
108 aSourceRange,
109 aTargetRange));
112 // always use PolyPolygonBezierCoords here
113 drawing::PolyPolygonBezierCoords aSourcePolyPolygon;
115 basegfx::utils::B2DPolyPolygonToUnoPolyPolygonBezierCoords(
116 aPolyPolygon,
117 aSourcePolyPolygon);
118 rValue <<= aSourcePolyPolygon;
122 if( !aDisplayName.isEmpty() )
124 m_rImport.AddStyleDisplayName( XmlStyleFamily::SD_MARKER_ID, rStrName,
125 aDisplayName );
126 rStrName = aDisplayName;
130 xViewBox.reset();
133 // Export
135 XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport& rExp )
136 : m_rExport( rExp )
140 void XMLMarkerStyleExport::exportXML(
141 const OUString& rStrName,
142 const uno::Any& rValue )
144 if(rStrName.isEmpty())
145 return;
147 drawing::PolyPolygonBezierCoords aBezier;
149 if(!(rValue >>= aBezier))
150 return;
152 // Name
153 bool bEncoded(false);
155 m_rExport.AddAttribute(XML_NAMESPACE_DRAW, XML_NAME, m_rExport.EncodeStyleName( rStrName, &bEncoded ) );
157 if( bEncoded )
159 m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, rStrName );
162 const basegfx::B2DPolyPolygon aPolyPolygon(
163 basegfx::utils::UnoPolyPolygonBezierCoordsToB2DPolyPolygon(
164 aBezier));
165 const basegfx::B2DRange aPolyPolygonRange(aPolyPolygon.getB2DRange());
168 // Viewbox (viewBox="0 0 1500 1000")
170 SdXMLImExViewBox aViewBox(
171 aPolyPolygonRange.getMinX(),
172 aPolyPolygonRange.getMinY(),
173 aPolyPolygonRange.getWidth(),
174 aPolyPolygonRange.getHeight());
175 m_rExport.AddAttribute( XML_NAMESPACE_SVG, XML_VIEWBOX, aViewBox.GetExportString() );
177 // Pathdata
178 const OUString aPolygonString(
179 basegfx::utils::exportToSvgD(
180 aPolyPolygon,
181 true, // bUseRelativeCoordinates
182 false, // bDetectQuadraticBeziers: not used in old, but maybe activated now
183 true)); // bHandleRelativeNextPointCompatible
185 // write point array
186 m_rExport.AddAttribute(XML_NAMESPACE_SVG, XML_D, aPolygonString);
188 // Do Write
189 SvXMLElementExport rElem( m_rExport, XML_NAMESPACE_DRAW, XML_MARKER, true, false );
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */