Bump for 3.6-28
[LibreOffice.git] / xmloff / source / style / MarkerStyle.cxx
blob5c0c0ec0b3680f3425ffac7789579332222f25ce
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "xmloff/MarkerStyle.hxx"
30 #include "xexptran.hxx"
31 #include <xmloff/attrlist.hxx>
32 #include <xmloff/nmspmap.hxx>
33 #include <xmloff/xmluconv.hxx>
34 #include "xmloff/xmlnmspe.hxx"
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/xmlexp.hxx>
37 #include <xmloff/xmlimp.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <rtl/ustring.hxx>
40 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
42 using namespace ::com::sun::star;
43 using ::rtl::OUString;
44 using ::rtl::OUStringBuffer;
46 using namespace ::xmloff::token;
49 //-------------------------------------------------------------
50 // Import
51 //-------------------------------------------------------------
53 XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport& rImp )
54 : rImport( rImp )
58 XMLMarkerStyleImport::~XMLMarkerStyleImport()
62 sal_Bool XMLMarkerStyleImport::importXML(
63 const uno::Reference< xml::sax::XAttributeList >& xAttrList,
64 uno::Any& rValue,
65 OUString& rStrName )
67 sal_Bool bHasViewBox = sal_False;
68 sal_Bool bHasPathData = sal_False;
69 OUString aDisplayName;
71 SdXMLImExViewBox* pViewBox = NULL;
73 SvXMLNamespaceMap& rNamespaceMap = rImport.GetNamespaceMap();
74 SvXMLUnitConverter& rUnitConverter = rImport.GetMM100UnitConverter();
76 OUString strPathData;
78 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
79 for( sal_Int16 i = 0; i < nAttrCount; i++ )
81 OUString aStrFullAttrName = xAttrList->getNameByIndex( i );
82 OUString aStrAttrName;
83 rNamespaceMap.GetKeyByAttrName( aStrFullAttrName, &aStrAttrName );
84 OUString aStrValue = xAttrList->getValueByIndex( i );
86 if( IsXMLToken( aStrAttrName, XML_NAME ) )
88 rStrName = aStrValue;
90 else if( IsXMLToken( aStrAttrName, XML_DISPLAY_NAME ) )
92 aDisplayName = aStrValue;
94 else if( IsXMLToken( aStrAttrName, XML_VIEWBOX ) )
96 pViewBox = new SdXMLImExViewBox( aStrValue, rUnitConverter );
97 bHasViewBox = sal_True;
100 else if( IsXMLToken( aStrAttrName, XML_D ) )
102 strPathData = aStrValue;
103 bHasPathData = sal_True;
107 if( bHasViewBox && bHasPathData )
109 SdXMLImExSvgDElement aPoints(strPathData, *pViewBox, awt::Point( 0, 0 ),
110 awt::Size( pViewBox->GetWidth(), pViewBox->GetHeight() ), rImport );
112 if(aPoints.IsCurve())
114 drawing::PolyPolygonBezierCoords aSourcePolyPolygon(
115 aPoints.GetPointSequenceSequence(),
116 aPoints.GetFlagSequenceSequence());
117 rValue <<= aSourcePolyPolygon;
119 else
121 drawing::PolyPolygonBezierCoords aSourcePolyPolygon;
122 aSourcePolyPolygon.Coordinates = aPoints.GetPointSequenceSequence();
123 aSourcePolyPolygon.Flags.realloc(aSourcePolyPolygon.Coordinates.getLength());
125 // Zeiger auf innere sequences holen
126 const drawing::PointSequence* pInnerSequence = aSourcePolyPolygon.Coordinates.getConstArray();
127 drawing::FlagSequence* pInnerSequenceFlags = aSourcePolyPolygon.Flags.getArray();
129 for(sal_Int32 a(0); a < aSourcePolyPolygon.Coordinates.getLength(); a++)
131 pInnerSequenceFlags->realloc(pInnerSequence->getLength());
132 drawing::PolygonFlags* pPolyFlags = pInnerSequenceFlags->getArray();
134 for(sal_Int32 b(0); b < pInnerSequence->getLength(); b++)
135 *pPolyFlags++ = drawing::PolygonFlags_NORMAL;
137 // next run
138 pInnerSequence++;
139 pInnerSequenceFlags++;
142 rValue <<= aSourcePolyPolygon;
145 if( !aDisplayName.isEmpty() )
147 rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_MARKER_ID, rStrName,
148 aDisplayName );
149 rStrName = aDisplayName;
154 if( pViewBox )
155 delete pViewBox;
157 return bHasViewBox && bHasPathData;
161 //-------------------------------------------------------------
162 // Export
163 //-------------------------------------------------------------
165 XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport& rExp )
166 : rExport( rExp )
170 XMLMarkerStyleExport::~XMLMarkerStyleExport()
174 sal_Bool XMLMarkerStyleExport::exportXML(
175 const OUString& rStrName,
176 const uno::Any& rValue )
178 sal_Bool bRet(sal_False);
180 if(!rStrName.isEmpty())
182 drawing::PolyPolygonBezierCoords aBezier;
184 if(rValue >>= aBezier)
186 OUString aStrValue;
187 OUStringBuffer aOut;
189 /////////////////
190 // Name
191 sal_Bool bEncoded = sal_False;
192 OUString aStrName( rStrName );
193 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
194 rExport.EncodeStyleName( aStrName,
195 &bEncoded ) );
196 if( bEncoded )
197 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
198 aStrName );
200 /////////////////
201 // Viewbox (viewBox="0 0 1500 1000")
202 sal_Int32 nMinX(0x7fffffff);
203 sal_Int32 nMaxX(0x80000000);
204 sal_Int32 nMinY(0x7fffffff);
205 sal_Int32 nMaxY(0x80000000);
206 sal_Int32 nOuterCnt(aBezier.Coordinates.getLength());
207 drawing::PointSequence* pOuterSequence = aBezier.Coordinates.getArray();
208 sal_Int32 a, b;
209 sal_Bool bClosed(sal_False);
211 for (a = 0; a < nOuterCnt; a++)
213 drawing::PointSequence* pSequence = pOuterSequence++;
214 const awt::Point *pPoints = pSequence->getConstArray();
215 sal_Int32 nPointCount(pSequence->getLength());
217 if(nPointCount)
219 const awt::Point aStart = pPoints[0];
220 const awt::Point aEnd = pPoints[nPointCount - 1];
222 if(aStart.X == aEnd.X && aStart.Y == aEnd.Y)
224 bClosed = sal_True;
228 for (b = 0; b < nPointCount; b++)
230 const awt::Point aPoint = pPoints[b];
232 if( aPoint.X < nMinX )
233 nMinX = aPoint.X;
235 if( aPoint.X > nMaxX )
236 nMaxX = aPoint.X;
238 if( aPoint.Y < nMinY )
239 nMinY = aPoint.Y;
241 if( aPoint.Y > nMaxY )
242 nMaxY = aPoint.Y;
246 sal_Int32 nDifX(nMaxX - nMinX);
247 sal_Int32 nDifY(nMaxY - nMinY);
249 SdXMLImExViewBox aViewBox( 0, 0, nDifX, nDifY );
250 rExport.AddAttribute( XML_NAMESPACE_SVG, XML_VIEWBOX, aViewBox.GetExportString() );
252 /////////////////
253 // Pathdata
254 pOuterSequence = aBezier.Coordinates.getArray();
255 drawing::FlagSequence* pOuterFlags = aBezier.Flags.getArray();
256 SdXMLImExSvgDElement aSvgDElement(aViewBox, rExport);
258 for (a = 0; a < nOuterCnt; a++)
260 drawing::PointSequence* pSequence = pOuterSequence++;
261 drawing::FlagSequence* pFlags = pOuterFlags++;
263 aSvgDElement.AddPolygon(pSequence, pFlags,
264 awt::Point( 0, 0 ),
265 awt::Size( aViewBox.GetWidth(), aViewBox.GetHeight() ),
266 bClosed);
269 // write point array
270 rExport.AddAttribute(XML_NAMESPACE_SVG, XML_D, aSvgDElement.GetExportString());
272 /////////////////
273 // Do Write
274 SvXMLElementExport rElem( rExport, XML_NAMESPACE_DRAW, XML_MARKER,
275 sal_True, sal_False );
279 return bRet;
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */