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>
33 using namespace ::com::sun::star
;
35 using namespace ::xmloff::token
;
38 //-------------------------------------------------------------
40 //-------------------------------------------------------------
42 XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport
& rImp
)
47 XMLMarkerStyleImport::~XMLMarkerStyleImport()
51 sal_Bool
XMLMarkerStyleImport::importXML(
52 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
56 sal_Bool bHasViewBox
= sal_False
;
57 sal_Bool bHasPathData
= sal_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
);
86 bHasViewBox
= sal_True
;
89 else if( IsXMLToken( aStrAttrName
, XML_D
) )
91 strPathData
= aStrValue
;
92 bHasPathData
= sal_True
;
96 if( bHasViewBox
&& bHasPathData
)
98 SdXMLImExSvgDElement
aPoints(strPathData
, *pViewBox
, awt::Point( 0, 0 ),
99 awt::Size( pViewBox
->GetWidth(), pViewBox
->GetHeight() ), rImport
);
101 if(aPoints
.IsCurve())
103 drawing::PolyPolygonBezierCoords
aSourcePolyPolygon(
104 aPoints
.GetPointSequenceSequence(),
105 aPoints
.GetFlagSequenceSequence());
106 rValue
<<= aSourcePolyPolygon
;
110 drawing::PolyPolygonBezierCoords aSourcePolyPolygon
;
111 aSourcePolyPolygon
.Coordinates
= aPoints
.GetPointSequenceSequence();
112 aSourcePolyPolygon
.Flags
.realloc(aSourcePolyPolygon
.Coordinates
.getLength());
114 // Zeiger auf innere sequences holen
115 const drawing::PointSequence
* pInnerSequence
= aSourcePolyPolygon
.Coordinates
.getConstArray();
116 drawing::FlagSequence
* pInnerSequenceFlags
= aSourcePolyPolygon
.Flags
.getArray();
118 for(sal_Int32
a(0); a
< aSourcePolyPolygon
.Coordinates
.getLength(); a
++)
120 pInnerSequenceFlags
->realloc(pInnerSequence
->getLength());
121 drawing::PolygonFlags
* pPolyFlags
= pInnerSequenceFlags
->getArray();
123 for(sal_Int32
b(0); b
< pInnerSequence
->getLength(); b
++)
124 *pPolyFlags
++ = drawing::PolygonFlags_NORMAL
;
128 pInnerSequenceFlags
++;
131 rValue
<<= aSourcePolyPolygon
;
134 if( !aDisplayName
.isEmpty() )
136 rImport
.AddStyleDisplayName( XML_STYLE_FAMILY_SD_MARKER_ID
, rStrName
,
138 rStrName
= aDisplayName
;
146 return bHasViewBox
&& bHasPathData
;
150 //-------------------------------------------------------------
152 //-------------------------------------------------------------
154 XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport
& rExp
)
159 XMLMarkerStyleExport::~XMLMarkerStyleExport()
163 sal_Bool
XMLMarkerStyleExport::exportXML(
164 const OUString
& rStrName
,
165 const uno::Any
& rValue
)
167 sal_Bool
bRet(sal_False
);
169 if(!rStrName
.isEmpty())
171 drawing::PolyPolygonBezierCoords aBezier
;
173 if(rValue
>>= aBezier
)
177 sal_Bool bEncoded
= sal_False
;
178 OUString
aStrName( rStrName
);
179 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_NAME
,
180 rExport
.EncodeStyleName( aStrName
,
183 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_DISPLAY_NAME
,
187 // Viewbox (viewBox="0 0 1500 1000")
188 sal_Int32
nMinX(0x7fffffff);
189 sal_Int32
nMaxX(0x80000000);
190 sal_Int32
nMinY(0x7fffffff);
191 sal_Int32
nMaxY(0x80000000);
192 sal_Int32
nOuterCnt(aBezier
.Coordinates
.getLength());
193 drawing::PointSequence
* pOuterSequence
= aBezier
.Coordinates
.getArray();
195 sal_Bool
bClosed(sal_False
);
197 for (a
= 0; a
< nOuterCnt
; a
++)
199 drawing::PointSequence
* pSequence
= pOuterSequence
++;
200 const awt::Point
*pPoints
= pSequence
->getConstArray();
201 sal_Int32
nPointCount(pSequence
->getLength());
205 const awt::Point aStart
= pPoints
[0];
206 const awt::Point aEnd
= pPoints
[nPointCount
- 1];
208 if(aStart
.X
== aEnd
.X
&& aStart
.Y
== aEnd
.Y
)
214 for (b
= 0; b
< nPointCount
; b
++)
216 const awt::Point aPoint
= pPoints
[b
];
218 if( aPoint
.X
< nMinX
)
221 if( aPoint
.X
> nMaxX
)
224 if( aPoint
.Y
< nMinY
)
227 if( aPoint
.Y
> nMaxY
)
232 sal_Int32
nDifX(nMaxX
- nMinX
);
233 sal_Int32
nDifY(nMaxY
- nMinY
);
235 SdXMLImExViewBox
aViewBox( 0, 0, nDifX
, nDifY
);
236 rExport
.AddAttribute( XML_NAMESPACE_SVG
, XML_VIEWBOX
, aViewBox
.GetExportString() );
240 pOuterSequence
= aBezier
.Coordinates
.getArray();
241 drawing::FlagSequence
* pOuterFlags
= aBezier
.Flags
.getArray();
242 SdXMLImExSvgDElement
aSvgDElement(aViewBox
, rExport
);
244 for (a
= 0; a
< nOuterCnt
; a
++)
246 drawing::PointSequence
* pSequence
= pOuterSequence
++;
247 drawing::FlagSequence
* pFlags
= pOuterFlags
++;
249 aSvgDElement
.AddPolygon(pSequence
, pFlags
,
251 awt::Size( aViewBox
.GetWidth(), aViewBox
.GetHeight() ),
256 rExport
.AddAttribute(XML_NAMESPACE_SVG
, XML_D
, aSvgDElement
.GetExportString());
260 SvXMLElementExport
rElem( rExport
, XML_NAMESPACE_DRAW
, XML_MARKER
,
261 sal_True
, sal_False
);
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */