1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MarkerStyle.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "MarkerStyle.hxx"
34 #include "xexptran.hxx"
35 #include <xmloff/attrlist.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include <xmloff/xmluconv.hxx>
38 #include "xmlnmspe.hxx"
39 #include <xmloff/xmltoken.hxx>
40 #include <xmloff/xmlexp.hxx>
41 #include <xmloff/xmlimp.hxx>
42 #include <rtl/ustrbuf.hxx>
43 #include <rtl/ustring.hxx>
44 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
46 using namespace ::com::sun::star
;
47 using ::rtl::OUString
;
48 using ::rtl::OUStringBuffer
;
50 using namespace ::xmloff::token
;
53 //-------------------------------------------------------------
55 //-------------------------------------------------------------
57 XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport
& rImp
)
62 XMLMarkerStyleImport::~XMLMarkerStyleImport()
66 sal_Bool
XMLMarkerStyleImport::importXML(
67 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
71 sal_Bool bHasViewBox
= sal_False
;
72 sal_Bool bHasPathData
= sal_False
;
73 OUString aDisplayName
;
75 SdXMLImExViewBox
* pViewBox
= NULL
;
77 SvXMLNamespaceMap
& rNamespaceMap
= rImport
.GetNamespaceMap();
78 SvXMLUnitConverter
& rUnitConverter
= rImport
.GetMM100UnitConverter();
82 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
83 for( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
85 OUString aStrFullAttrName
= xAttrList
->getNameByIndex( i
);
86 OUString aStrAttrName
;
87 rNamespaceMap
.GetKeyByAttrName( aStrFullAttrName
, &aStrAttrName
);
88 OUString aStrValue
= xAttrList
->getValueByIndex( i
);
90 if( IsXMLToken( aStrAttrName
, XML_NAME
) )
94 else if( IsXMLToken( aStrAttrName
, XML_DISPLAY_NAME
) )
96 aDisplayName
= aStrValue
;
98 else if( IsXMLToken( aStrAttrName
, XML_VIEWBOX
) )
100 pViewBox
= new SdXMLImExViewBox( aStrValue
, rUnitConverter
);
101 bHasViewBox
= sal_True
;
104 else if( IsXMLToken( aStrAttrName
, XML_D
) )
106 strPathData
= aStrValue
;
107 bHasPathData
= sal_True
;
111 if( bHasViewBox
&& bHasPathData
)
113 SdXMLImExSvgDElement
aPoints(strPathData
, *pViewBox
, awt::Point( 0, 0 ),
114 awt::Size( pViewBox
->GetWidth(), pViewBox
->GetHeight() ),
117 if(aPoints
.IsCurve())
119 drawing::PolyPolygonBezierCoords
aSourcePolyPolygon(
120 aPoints
.GetPointSequenceSequence(),
121 aPoints
.GetFlagSequenceSequence());
122 rValue
<<= aSourcePolyPolygon
;
126 drawing::PolyPolygonBezierCoords aSourcePolyPolygon
;
127 aSourcePolyPolygon
.Coordinates
= aPoints
.GetPointSequenceSequence();
128 aSourcePolyPolygon
.Flags
.realloc(aSourcePolyPolygon
.Coordinates
.getLength());
130 // Zeiger auf innere sequences holen
131 const drawing::PointSequence
* pInnerSequence
= aSourcePolyPolygon
.Coordinates
.getConstArray();
132 drawing::FlagSequence
* pInnerSequenceFlags
= aSourcePolyPolygon
.Flags
.getArray();
134 for(sal_Int32
a(0); a
< aSourcePolyPolygon
.Coordinates
.getLength(); a
++)
136 pInnerSequenceFlags
->realloc(pInnerSequence
->getLength());
137 drawing::PolygonFlags
* pPolyFlags
= pInnerSequenceFlags
->getArray();
139 for(sal_Int32
b(0); b
< pInnerSequence
->getLength(); b
++)
140 *pPolyFlags
++ = drawing::PolygonFlags_NORMAL
;
144 pInnerSequenceFlags
++;
147 rValue
<<= aSourcePolyPolygon
;
150 if( aDisplayName
.getLength() )
152 rImport
.AddStyleDisplayName( XML_STYLE_FAMILY_SD_MARKER_ID
, rStrName
,
154 rStrName
= aDisplayName
;
162 return bHasViewBox
&& bHasPathData
;
166 //-------------------------------------------------------------
168 //-------------------------------------------------------------
172 XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport
& rExp
)
177 XMLMarkerStyleExport::~XMLMarkerStyleExport()
181 sal_Bool
XMLMarkerStyleExport::exportXML(
182 const OUString
& rStrName
,
183 const uno::Any
& rValue
)
185 sal_Bool
bRet(sal_False
);
187 if(rStrName
.getLength())
189 drawing::PolyPolygonBezierCoords aBezier
;
191 if(rValue
>>= aBezier
)
198 sal_Bool bEncoded
= sal_False
;
199 OUString
aStrName( rStrName
);
200 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_NAME
,
201 rExport
.EncodeStyleName( aStrName
,
204 rExport
.AddAttribute( XML_NAMESPACE_DRAW
, XML_DISPLAY_NAME
,
208 // Viewbox (viewBox="0 0 1500 1000")
209 sal_Int32
nMinX(0x7fffffff);
210 sal_Int32
nMaxX(0x80000000);
211 sal_Int32
nMinY(0x7fffffff);
212 sal_Int32
nMaxY(0x80000000);
213 sal_Int32
nOuterCnt(aBezier
.Coordinates
.getLength());
214 drawing::PointSequence
* pOuterSequence
= aBezier
.Coordinates
.getArray();
216 sal_Bool
bClosed(sal_False
);
218 for(a
= 0L; a
< nOuterCnt
; a
++)
220 drawing::PointSequence
* pSequence
= pOuterSequence
++;
221 const awt::Point
*pPoints
= pSequence
->getConstArray();
222 sal_Int32
nPointCount(pSequence
->getLength());
226 const awt::Point aStart
= pPoints
[0];
227 const awt::Point aEnd
= pPoints
[nPointCount
- 1];
229 if(aStart
.X
== aEnd
.X
&& aStart
.Y
== aEnd
.Y
)
235 for(b
= 0L; b
< nPointCount
; b
++)
237 const awt::Point aPoint
= pPoints
[b
];
239 if( aPoint
.X
< nMinX
)
242 if( aPoint
.X
> nMaxX
)
245 if( aPoint
.Y
< nMinY
)
248 if( aPoint
.Y
> nMaxY
)
253 sal_Int32
nDifX(nMaxX
- nMinX
);
254 sal_Int32
nDifY(nMaxY
- nMinY
);
256 SdXMLImExViewBox
aViewBox( 0, 0, nDifX
, nDifY
);
257 rExport
.AddAttribute( XML_NAMESPACE_SVG
, XML_VIEWBOX
, aViewBox
.GetExportString() );
261 pOuterSequence
= aBezier
.Coordinates
.getArray();
262 drawing::FlagSequence
* pOuterFlags
= aBezier
.Flags
.getArray();
263 SdXMLImExSvgDElement
aSvgDElement(aViewBox
);
265 for(a
= 0L; a
< nOuterCnt
; a
++)
267 drawing::PointSequence
* pSequence
= pOuterSequence
++;
268 drawing::FlagSequence
* pFlags
= pOuterFlags
++;
270 aSvgDElement
.AddPolygon(pSequence
, pFlags
,
272 awt::Size( aViewBox
.GetWidth(), aViewBox
.GetHeight() ),
277 rExport
.AddAttribute(XML_NAMESPACE_SVG
, XML_D
, aSvgDElement
.GetExportString());
281 SvXMLElementExport
rElem( rExport
, XML_NAMESPACE_DRAW
, XML_MARKER
,
282 sal_True
, sal_False
);
289 #endif // #ifndef SVX_LIGHT