bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / style / MarkerStyle.cxx
blob53bf23eca1d6cd9d3689078b6b7a87fbc7a5d6b1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 //-------------------------------------------------------------
39 // Import
40 //-------------------------------------------------------------
42 XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport& rImp )
43 : rImport( rImp )
47 XMLMarkerStyleImport::~XMLMarkerStyleImport()
51 sal_Bool XMLMarkerStyleImport::importXML(
52 const uno::Reference< xml::sax::XAttributeList >& xAttrList,
53 uno::Any& rValue,
54 OUString& rStrName )
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();
65 OUString strPathData;
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 ) )
77 rStrName = aStrValue;
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;
108 else
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;
126 // next run
127 pInnerSequence++;
128 pInnerSequenceFlags++;
131 rValue <<= aSourcePolyPolygon;
134 if( !aDisplayName.isEmpty() )
136 rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_MARKER_ID, rStrName,
137 aDisplayName );
138 rStrName = aDisplayName;
143 if( pViewBox )
144 delete pViewBox;
146 return bHasViewBox && bHasPathData;
150 //-------------------------------------------------------------
151 // Export
152 //-------------------------------------------------------------
154 XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport& rExp )
155 : rExport( 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)
175 /////////////////
176 // Name
177 sal_Bool bEncoded = sal_False;
178 OUString aStrName( rStrName );
179 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
180 rExport.EncodeStyleName( aStrName,
181 &bEncoded ) );
182 if( bEncoded )
183 rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
184 aStrName );
186 /////////////////
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();
194 sal_Int32 a, b;
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());
203 if(nPointCount)
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)
210 bClosed = sal_True;
214 for (b = 0; b < nPointCount; b++)
216 const awt::Point aPoint = pPoints[b];
218 if( aPoint.X < nMinX )
219 nMinX = aPoint.X;
221 if( aPoint.X > nMaxX )
222 nMaxX = aPoint.X;
224 if( aPoint.Y < nMinY )
225 nMinY = aPoint.Y;
227 if( aPoint.Y > nMaxY )
228 nMaxY = aPoint.Y;
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() );
238 /////////////////
239 // Pathdata
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,
250 awt::Point( 0, 0 ),
251 awt::Size( aViewBox.GetWidth(), aViewBox.GetHeight() ),
252 bClosed);
255 // write point array
256 rExport.AddAttribute(XML_NAMESPACE_SVG, XML_D, aSvgDElement.GetExportString());
258 /////////////////
259 // Do Write
260 SvXMLElementExport rElem( rExport, XML_NAMESPACE_DRAW, XML_MARKER,
261 sal_True, sal_False );
265 return bRet;
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */