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 .
20 #include <xmloff/MarkerStyle.hxx>
21 #include "xexptran.hxx"
22 #include <xmloff/attrlist.hxx>
23 #include <xmloff/nmspmap.hxx>
24 #include <xmloff/xmluconv.hxx>
25 #include <xmloff/xmlnmspe.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlexp.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <rtl/ustrbuf.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 XMLMarkerStyleImport::~XMLMarkerStyleImport()
51 bool XMLMarkerStyleImport::importXML(
52 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
56 bool bHasViewBox
= false;
57 bool bHasPathData
= false;
58 OUString aDisplayName
;
60 SdXMLImExViewBox
* pViewBox
= NULL
;
62 SvXMLNamespaceMap
& rNamespaceMap
= rImport
.GetNamespaceMap();
63 SvXMLUnitConverter
& rUnitConverter
= rImport
.GetMM100UnitConverter();
67 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
68 for( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
70 OUString aStrFullAttrName
= xAttrList
->getNameByIndex( i
);
71 OUString aStrAttrName
;
72 rNamespaceMap
.GetKeyByAttrName( aStrFullAttrName
, &aStrAttrName
);
73 OUString aStrValue
= xAttrList
->getValueByIndex( i
);
75 if( IsXMLToken( aStrAttrName
, XML_NAME
) )
79 else if( IsXMLToken( aStrAttrName
, XML_DISPLAY_NAME
) )
81 aDisplayName
= aStrValue
;
83 else if( IsXMLToken( aStrAttrName
, XML_VIEWBOX
) )
85 pViewBox
= new SdXMLImExViewBox( aStrValue
, rUnitConverter
);
89 else if( IsXMLToken( aStrAttrName
, XML_D
) )
91 strPathData
= aStrValue
;
96 if( bHasViewBox
&& bHasPathData
)
98 basegfx::B2DPolyPolygon aPolyPolygon
;
100 if(basegfx::tools::importFromSvgD(aPolyPolygon
, strPathData
, rImport
.needFixPositionAfterZ(), 0))
102 if(aPolyPolygon
.count())
104 // ViewBox probably not used, but stay with former processing inside of
105 // SdXMLImExSvgDElement
106 const basegfx::B2DRange
aSourceRange(
107 pViewBox
->GetX(), pViewBox
->GetY(),
108 pViewBox
->GetX() + pViewBox
->GetWidth(), pViewBox
->GetY() + pViewBox
->GetHeight());
109 const basegfx::B2DRange
aTargetRange(
111 pViewBox
->GetWidth(), pViewBox
->GetHeight());
113 if(!aSourceRange
.equal(aTargetRange
))
115 aPolyPolygon
.transform(
116 basegfx::tools::createSourceRangeTargetRangeTransform(
121 // always use PolyPolygonBezierCoords here
122 drawing::PolyPolygonBezierCoords aSourcePolyPolygon
;
124 basegfx::tools::B2DPolyPolygonToUnoPolyPolygonBezierCoords(
127 rValue
<<= aSourcePolyPolygon
;
131 if( !aDisplayName
.isEmpty() )
133 rImport
.AddStyleDisplayName( XML_STYLE_FAMILY_SD_MARKER_ID
, rStrName
,
135 rStrName
= aDisplayName
;
142 return bHasViewBox
&& bHasPathData
;
147 XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport
& rExp
)
152 XMLMarkerStyleExport::~XMLMarkerStyleExport()
156 void XMLMarkerStyleExport::exportXML(
157 const OUString
& rStrName
,
158 const uno::Any
& rValue
)
160 if(!rStrName
.isEmpty())
162 drawing::PolyPolygonBezierCoords aBezier
;
164 if(rValue
>>= aBezier
)
167 bool bEncoded(false);
168 OUString
aStrName( rStrName
);
170 rExport
.AddAttribute(XML_NAMESPACE_DRAW
, XML_NAME
, rExport
.EncodeStyleName( aStrName
, &bEncoded
) );
174 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_DISPLAY_NAME
, aStrName
);
177 const basegfx::B2DPolyPolygon
aPolyPolygon(
178 basegfx::tools::UnoPolyPolygonBezierCoordsToB2DPolyPolygon(
180 const basegfx::B2DRange
aPolyPolygonRange(aPolyPolygon
.getB2DRange());
183 // Viewbox (viewBox="0 0 1500 1000")
185 SdXMLImExViewBox
aViewBox(
186 aPolyPolygonRange
.getMinX(),
187 aPolyPolygonRange
.getMinY(),
188 aPolyPolygonRange
.getWidth(),
189 aPolyPolygonRange
.getHeight());
190 rExport
.AddAttribute( XML_NAMESPACE_SVG
, XML_VIEWBOX
, aViewBox
.GetExportString() );
193 const OUString
aPolygonString(
194 basegfx::tools::exportToSvgD(
196 true, // bUseRelativeCoordinates
197 false, // bDetectQuadraticBeziers: not used in old, but maybe activated now
198 true)); // bHandleRelativeNextPointCompatible
201 rExport
.AddAttribute(XML_NAMESPACE_SVG
, XML_D
, aPolygonString
);
204 SvXMLElementExport
rElem( rExport
, XML_NAMESPACE_DRAW
, XML_MARKER
, true, false );
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */