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/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
;
41 XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport
& rImp
)
46 void XMLMarkerStyleImport::importXML(
47 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
,
51 bool bHasViewBox
= false;
52 bool bHasPathData
= false;
53 OUString aDisplayName
;
55 std::unique_ptr
<SdXMLImExViewBox
> xViewBox
;
57 SvXMLUnitConverter
& rUnitConverter
= m_rImport
.GetMM100UnitConverter();
61 for (auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
))
63 OUString aStrValue
= aIter
.toString();
65 switch (aIter
.getToken() & TOKEN_MASK
)
70 case XML_DISPLAY_NAME
:
71 aDisplayName
= aStrValue
;
74 xViewBox
.reset(new SdXMLImExViewBox(aStrValue
, rUnitConverter
));
78 strPathData
= aStrValue
;
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(
102 xViewBox
->GetWidth(), xViewBox
->GetHeight());
104 if(!aSourceRange
.equal(aTargetRange
))
106 aPolyPolygon
.transform(
107 basegfx::utils::createSourceRangeTargetRangeTransform(
112 // always use PolyPolygonBezierCoords here
113 drawing::PolyPolygonBezierCoords aSourcePolyPolygon
;
115 basegfx::utils::B2DPolyPolygonToUnoPolyPolygonBezierCoords(
118 rValue
<<= aSourcePolyPolygon
;
122 if( !aDisplayName
.isEmpty() )
124 m_rImport
.AddStyleDisplayName( XmlStyleFamily::SD_MARKER_ID
, rStrName
,
126 rStrName
= aDisplayName
;
135 XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport
& rExp
)
140 void XMLMarkerStyleExport::exportXML(
141 const OUString
& rStrName
,
142 const uno::Any
& rValue
)
144 if(rStrName
.isEmpty())
147 drawing::PolyPolygonBezierCoords aBezier
;
149 if(!(rValue
>>= aBezier
))
153 bool bEncoded(false);
155 m_rExport
.AddAttribute(XML_NAMESPACE_DRAW
, XML_NAME
, m_rExport
.EncodeStyleName( rStrName
, &bEncoded
) );
159 m_rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_DISPLAY_NAME
, rStrName
);
162 const basegfx::B2DPolyPolygon
aPolyPolygon(
163 basegfx::utils::UnoPolyPolygonBezierCoordsToB2DPolyPolygon(
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() );
178 const OUString
aPolygonString(
179 basegfx::utils::exportToSvgD(
181 true, // bUseRelativeCoordinates
182 false, // bDetectQuadraticBeziers: not used in old, but maybe activated now
183 true)); // bHandleRelativeNextPointCompatible
186 m_rExport
.AddAttribute(XML_NAMESPACE_SVG
, XML_D
, aPolygonString
);
189 SvXMLElementExport
rElem( m_rExport
, XML_NAMESPACE_DRAW
, XML_MARKER
, true, false );
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */