1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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
;
42 XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport
& rImp
)
47 void XMLMarkerStyleImport::importXML(
48 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
,
52 bool bHasViewBox
= false;
53 bool bHasPathData
= false;
54 OUString aDisplayName
;
56 std::unique_ptr
<SdXMLImExViewBox
> xViewBox
;
58 SvXMLUnitConverter
& rUnitConverter
= m_rImport
.GetMM100UnitConverter();
62 for (auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
))
64 OUString aStrValue
= aIter
.toString();
66 switch (aIter
.getToken() & TOKEN_MASK
)
71 case XML_DISPLAY_NAME
:
72 aDisplayName
= aStrValue
;
75 xViewBox
.reset(new SdXMLImExViewBox(aStrValue
, rUnitConverter
));
79 strPathData
= aStrValue
;
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(
103 xViewBox
->GetWidth(), xViewBox
->GetHeight());
105 if(!aSourceRange
.equal(aTargetRange
))
107 aPolyPolygon
.transform(
108 basegfx::utils::createSourceRangeTargetRangeTransform(
113 // always use PolyPolygonBezierCoords here
114 drawing::PolyPolygonBezierCoords aSourcePolyPolygon
;
116 basegfx::utils::B2DPolyPolygonToUnoPolyPolygonBezierCoords(
119 rValue
<<= aSourcePolyPolygon
;
123 if( !aDisplayName
.isEmpty() )
125 m_rImport
.AddStyleDisplayName( XmlStyleFamily::SD_MARKER_ID
, rStrName
,
127 rStrName
= aDisplayName
;
136 XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport
& rExp
)
141 void XMLMarkerStyleExport::exportXML(
142 const OUString
& rStrName
,
143 const uno::Any
& rValue
)
145 if(rStrName
.isEmpty())
148 drawing::PolyPolygonBezierCoords aBezier
;
150 if(!(rValue
>>= aBezier
))
154 bool bEncoded(false);
156 m_rExport
.AddAttribute(XML_NAMESPACE_DRAW
, XML_NAME
, m_rExport
.EncodeStyleName( rStrName
, &bEncoded
) );
160 m_rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_DISPLAY_NAME
, rStrName
);
163 const basegfx::B2DPolyPolygon
aPolyPolygon(
164 basegfx::utils::UnoPolyPolygonBezierCoordsToB2DPolyPolygon(
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() );
179 const OUString
aPolygonString(
180 basegfx::utils::exportToSvgD(
182 true, // bUseRelativeCoordinates
183 false, // bDetectQuadraticBeziers: not used in old, but maybe activated now
184 true)); // bHandleRelativeNextPointCompatible
187 m_rExport
.AddAttribute(XML_NAMESPACE_SVG
, XML_D
, aPolygonString
);
190 SvXMLElementExport
rElem( m_rExport
, XML_NAMESPACE_DRAW
, XML_MARKER
, true, false );
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */