update dev300-m58
[ooovba.git] / xmloff / source / style / MarkerStyle.cxx
blob86c78cbd6a371ed0ef3b81a5ab59b55b144e6bc9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MarkerStyle.cxx,v $
10 * $Revision: 1.16 $
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 //-------------------------------------------------------------
54 // Import
55 //-------------------------------------------------------------
57 XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport& rImp )
58 : rImport( rImp )
62 XMLMarkerStyleImport::~XMLMarkerStyleImport()
66 sal_Bool XMLMarkerStyleImport::importXML(
67 const uno::Reference< xml::sax::XAttributeList >& xAttrList,
68 uno::Any& rValue,
69 OUString& rStrName )
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();
80 OUString strPathData;
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 ) )
92 rStrName = aStrValue;
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() ),
115 rUnitConverter );
117 if(aPoints.IsCurve())
119 drawing::PolyPolygonBezierCoords aSourcePolyPolygon(
120 aPoints.GetPointSequenceSequence(),
121 aPoints.GetFlagSequenceSequence());
122 rValue <<= aSourcePolyPolygon;
124 else
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;
142 // next run
143 pInnerSequence++;
144 pInnerSequenceFlags++;
147 rValue <<= aSourcePolyPolygon;
150 if( aDisplayName.getLength() )
152 rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_MARKER_ID, rStrName,
153 aDisplayName );
154 rStrName = aDisplayName;
159 if( pViewBox )
160 delete pViewBox;
162 return bHasViewBox && bHasPathData;
166 //-------------------------------------------------------------
167 // Export
168 //-------------------------------------------------------------
170 #ifndef SVX_LIGHT
172 XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport& rExp )
173 : rExport( 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)
193 OUString aStrValue;
194 OUStringBuffer aOut;
196 /////////////////
197 // Name
198 sal_Bool bEncoded = sal_False;
199 OUString aStrName( rStrName );
200 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
201 rExport.EncodeStyleName( aStrName,
202 &bEncoded ) );
203 if( bEncoded )
204 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
205 aStrName );
207 /////////////////
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();
215 sal_Int32 a, b;
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());
224 if(nPointCount)
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)
231 bClosed = sal_True;
235 for(b = 0L; b < nPointCount; b++)
237 const awt::Point aPoint = pPoints[b];
239 if( aPoint.X < nMinX )
240 nMinX = aPoint.X;
242 if( aPoint.X > nMaxX )
243 nMaxX = aPoint.X;
245 if( aPoint.Y < nMinY )
246 nMinY = aPoint.Y;
248 if( aPoint.Y > nMaxY )
249 nMaxY = aPoint.Y;
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() );
259 /////////////////
260 // Pathdata
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,
271 awt::Point( 0, 0 ),
272 awt::Size( aViewBox.GetWidth(), aViewBox.GetHeight() ),
273 bClosed);
276 // write point array
277 rExport.AddAttribute(XML_NAMESPACE_SVG, XML_D, aSvgDElement.GetExportString());
279 /////////////////
280 // Do Write
281 SvXMLElementExport rElem( rExport, XML_NAMESPACE_DRAW, XML_MARKER,
282 sal_True, sal_False );
286 return bRet;
289 #endif // #ifndef SVX_LIGHT