1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir #include "XMLImageMapExport.hxx"
31*cdf0e10cSrcweir #include <rtl/ustring.hxx>
32*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
33*cdf0e10cSrcweir #include <tools/debug.hxx>
34*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
35*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.h>
36*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP
41*cdf0e10cSrcweir #include <com/sun/star/document/XEventsSupplier.hpp>
42*cdf0e10cSrcweir #endif
43*cdf0e10cSrcweir #include <com/sun/star/awt/Rectangle.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/awt/Point.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/drawing/PointSequence.hpp>
47*cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
48*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
49*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
50*cdf0e10cSrcweir #include <xmloff/XMLEventExport.hxx>
51*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
52*cdf0e10cSrcweir #include "xexptran.hxx"
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir using namespace ::com::sun::star;
57*cdf0e10cSrcweir using namespace ::xmloff::token;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir using ::rtl::OUString;
60*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
61*cdf0e10cSrcweir using ::com::sun::star::uno::Any;
62*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY;
63*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
64*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
65*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet;
66*cdf0e10cSrcweir using ::com::sun::star::container::XIndexContainer;
67*cdf0e10cSrcweir using ::com::sun::star::document::XEventsSupplier;
68*cdf0e10cSrcweir using ::com::sun::star::lang::XServiceInfo;
69*cdf0e10cSrcweir using ::com::sun::star::drawing::PointSequence;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir const sal_Char sAPI_ImageMapRectangleObject[] = "com.sun.star.image.ImageMapRectangleObject";
73*cdf0e10cSrcweir const sal_Char sAPI_ImageMapCircleObject[] = "com.sun.star.image.ImageMapCircleObject";
74*cdf0e10cSrcweir const sal_Char sAPI_ImageMapPolygonObject[] = "com.sun.star.image.ImageMapPolygonObject";
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir XMLImageMapExport::XMLImageMapExport(SvXMLExport& rExp) :
77*cdf0e10cSrcweir 	msBoundary(RTL_CONSTASCII_USTRINGPARAM("Boundary")),
78*cdf0e10cSrcweir 	msCenter(RTL_CONSTASCII_USTRINGPARAM("Center")),
79*cdf0e10cSrcweir 	msDescription(RTL_CONSTASCII_USTRINGPARAM("Description")),
80*cdf0e10cSrcweir 	msImageMap(RTL_CONSTASCII_USTRINGPARAM("ImageMap")),
81*cdf0e10cSrcweir 	msIsActive(RTL_CONSTASCII_USTRINGPARAM("IsActive")),
82*cdf0e10cSrcweir 	msName(RTL_CONSTASCII_USTRINGPARAM("Name")),
83*cdf0e10cSrcweir 	msPolygon(RTL_CONSTASCII_USTRINGPARAM("Polygon")),
84*cdf0e10cSrcweir 	msRadius(RTL_CONSTASCII_USTRINGPARAM("Radius")),
85*cdf0e10cSrcweir 	msTarget(RTL_CONSTASCII_USTRINGPARAM("Target")),
86*cdf0e10cSrcweir 	msURL(RTL_CONSTASCII_USTRINGPARAM("URL")),
87*cdf0e10cSrcweir 	msTitle(RTL_CONSTASCII_USTRINGPARAM("Title")),
88*cdf0e10cSrcweir 	mrExport(rExp),
89*cdf0e10cSrcweir 	mbWhiteSpace(sal_True)
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir XMLImageMapExport::~XMLImageMapExport()
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir void XMLImageMapExport::Export(
99*cdf0e10cSrcweir 	const Reference<XPropertySet> & rPropertySet)
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir 	if (rPropertySet->getPropertySetInfo()->hasPropertyByName(msImageMap))
102*cdf0e10cSrcweir 	{
103*cdf0e10cSrcweir 		Any aAny = rPropertySet->getPropertyValue(msImageMap);
104*cdf0e10cSrcweir 		Reference<XIndexContainer> aContainer;
105*cdf0e10cSrcweir 		aAny >>= aContainer;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 		Export(aContainer);
108*cdf0e10cSrcweir 	}
109*cdf0e10cSrcweir 	// else: no ImageMap property -> nothing to do
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir void XMLImageMapExport::Export(
113*cdf0e10cSrcweir 	const Reference<XIndexContainer> & rContainer)
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir 	if (rContainer.is())
116*cdf0e10cSrcweir 	{
117*cdf0e10cSrcweir 		if (rContainer->hasElements())
118*cdf0e10cSrcweir 		{
119*cdf0e10cSrcweir 			// image map container element
120*cdf0e10cSrcweir 			SvXMLElementExport aImageMapElement(
121*cdf0e10cSrcweir 				mrExport, XML_NAMESPACE_DRAW, XML_IMAGE_MAP,
122*cdf0e10cSrcweir 				mbWhiteSpace, mbWhiteSpace);
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 			// iterate over image map elements and call ExportMapEntry(...)
125*cdf0e10cSrcweir 			// for each
126*cdf0e10cSrcweir 			sal_Int32 nLength = rContainer->getCount();
127*cdf0e10cSrcweir 			for(sal_Int32 i = 0; i < nLength; i++)
128*cdf0e10cSrcweir 			{
129*cdf0e10cSrcweir 				Any aAny = rContainer->getByIndex(i);
130*cdf0e10cSrcweir 				Reference<XPropertySet> rElement;
131*cdf0e10cSrcweir 				aAny >>= rElement;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 				DBG_ASSERT(rElement.is(), "Image map element is empty!");
134*cdf0e10cSrcweir 				if (rElement.is())
135*cdf0e10cSrcweir 				{
136*cdf0e10cSrcweir 					ExportMapEntry(rElement);
137*cdf0e10cSrcweir 				}
138*cdf0e10cSrcweir 			}
139*cdf0e10cSrcweir 		}
140*cdf0e10cSrcweir 		// else: container is empty -> nothing to do
141*cdf0e10cSrcweir 	}
142*cdf0e10cSrcweir 	// else: no container -> nothign to do
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir void XMLImageMapExport::ExportMapEntry(
147*cdf0e10cSrcweir 	const Reference<XPropertySet> & rPropertySet)
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir 	Reference<XServiceInfo> xServiceInfo(rPropertySet, UNO_QUERY);
150*cdf0e10cSrcweir 	if (xServiceInfo.is())
151*cdf0e10cSrcweir 	{
152*cdf0e10cSrcweir 		enum XMLTokenEnum eType = XML_TOKEN_INVALID;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 		// distinguish map entries by their service name
155*cdf0e10cSrcweir 		Sequence<OUString> sServiceNames =
156*cdf0e10cSrcweir 			xServiceInfo->getSupportedServiceNames();
157*cdf0e10cSrcweir 		sal_Int32 nLength = sServiceNames.getLength();
158*cdf0e10cSrcweir 		for( sal_Int32 i=0; i<nLength; i++ )
159*cdf0e10cSrcweir 		{
160*cdf0e10cSrcweir 			OUString& rName = sServiceNames[i];
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 			if ( rName.equalsAsciiL(sAPI_ImageMapRectangleObject,
163*cdf0e10cSrcweir 									sizeof(sAPI_ImageMapRectangleObject)-1) )
164*cdf0e10cSrcweir 			{
165*cdf0e10cSrcweir 				eType = XML_AREA_RECTANGLE;
166*cdf0e10cSrcweir 				break;
167*cdf0e10cSrcweir 			}
168*cdf0e10cSrcweir 			else if ( rName.equalsAsciiL(sAPI_ImageMapCircleObject,
169*cdf0e10cSrcweir 										 sizeof(sAPI_ImageMapCircleObject)-1) )
170*cdf0e10cSrcweir 			{
171*cdf0e10cSrcweir 				eType = XML_AREA_CIRCLE;
172*cdf0e10cSrcweir 				break;
173*cdf0e10cSrcweir 			}
174*cdf0e10cSrcweir 			else if ( rName.equalsAsciiL(sAPI_ImageMapPolygonObject,
175*cdf0e10cSrcweir 										 sizeof(sAPI_ImageMapPolygonObject)-1))
176*cdf0e10cSrcweir 			{
177*cdf0e10cSrcweir 				eType = XML_AREA_POLYGON;
178*cdf0e10cSrcweir 				break;
179*cdf0e10cSrcweir 			}
180*cdf0e10cSrcweir 		}
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 		// return from method if no proper service is found!
183*cdf0e10cSrcweir 		DBG_ASSERT(XML_TOKEN_INVALID != eType,
184*cdf0e10cSrcweir 				   "Image map element doesn't support appropriate service!");
185*cdf0e10cSrcweir 		if (XML_TOKEN_INVALID == eType)
186*cdf0e10cSrcweir 			return;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 		// now: handle ImageMapObject properties (those for all types)
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 		// XLINK (URL property)
191*cdf0e10cSrcweir 		Any aAny = rPropertySet->getPropertyValue(msURL);
192*cdf0e10cSrcweir 		OUString sHref;
193*cdf0e10cSrcweir 		aAny >>= sHref;
194*cdf0e10cSrcweir 		if (sHref.getLength() > 0)
195*cdf0e10cSrcweir 		{
196*cdf0e10cSrcweir 			mrExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, mrExport.GetRelativeReference(sHref));
197*cdf0e10cSrcweir 		}
198*cdf0e10cSrcweir 		mrExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 		// Target property (and xlink:show)
201*cdf0e10cSrcweir 		aAny = rPropertySet->getPropertyValue(msTarget);
202*cdf0e10cSrcweir 		OUString sTargt;
203*cdf0e10cSrcweir 		aAny >>= sTargt;
204*cdf0e10cSrcweir 		if (sTargt.getLength() > 0)
205*cdf0e10cSrcweir 		{
206*cdf0e10cSrcweir 			mrExport.AddAttribute(
207*cdf0e10cSrcweir 				XML_NAMESPACE_OFFICE, XML_TARGET_FRAME_NAME, sTargt);
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 			mrExport.AddAttribute(
210*cdf0e10cSrcweir 				XML_NAMESPACE_XLINK, XML_SHOW,
211*cdf0e10cSrcweir 				sTargt.equalsAsciiL( "_blank", sizeof("_blank")-1 )
212*cdf0e10cSrcweir 										? XML_NEW : XML_REPLACE );
213*cdf0e10cSrcweir 		}
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 		// name
216*cdf0e10cSrcweir 		aAny = rPropertySet->getPropertyValue(msName);
217*cdf0e10cSrcweir 		OUString sItemName;
218*cdf0e10cSrcweir 		aAny >>= sItemName;
219*cdf0e10cSrcweir 		if (sItemName.getLength() > 0)
220*cdf0e10cSrcweir 		{
221*cdf0e10cSrcweir 			mrExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_NAME, sItemName);
222*cdf0e10cSrcweir 		}
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 		// is-active
225*cdf0e10cSrcweir 		aAny = rPropertySet->getPropertyValue(msIsActive);
226*cdf0e10cSrcweir 		if (! *(sal_Bool*)aAny.getValue())
227*cdf0e10cSrcweir 		{
228*cdf0e10cSrcweir 			mrExport.AddAttribute(XML_NAMESPACE_DRAW, XML_NOHREF, XML_NOHREF);
229*cdf0e10cSrcweir 		}
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 		// call specific rectangle/circle/... method
232*cdf0e10cSrcweir 		// also prepare element name
233*cdf0e10cSrcweir 		switch (eType)
234*cdf0e10cSrcweir 		{
235*cdf0e10cSrcweir 			case XML_AREA_RECTANGLE:
236*cdf0e10cSrcweir 				ExportRectangle(rPropertySet);
237*cdf0e10cSrcweir 				break;
238*cdf0e10cSrcweir 			case XML_AREA_CIRCLE:
239*cdf0e10cSrcweir 				ExportCircle(rPropertySet);
240*cdf0e10cSrcweir 				break;
241*cdf0e10cSrcweir 			case XML_AREA_POLYGON:
242*cdf0e10cSrcweir 				ExportPolygon(rPropertySet);
243*cdf0e10cSrcweir 				break;
244*cdf0e10cSrcweir 			default:
245*cdf0e10cSrcweir 				break;
246*cdf0e10cSrcweir 		}
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 		// write element
249*cdf0e10cSrcweir 		DBG_ASSERT(XML_TOKEN_INVALID != eType,
250*cdf0e10cSrcweir                    "No name?! How did this happen?");
251*cdf0e10cSrcweir 		SvXMLElementExport aAreaElement(mrExport, XML_NAMESPACE_DRAW, eType,
252*cdf0e10cSrcweir 										mbWhiteSpace, mbWhiteSpace);
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 		// title property (as <svg:title> element)
255*cdf0e10cSrcweir 		OUString sTitle;
256*cdf0e10cSrcweir 		rPropertySet->getPropertyValue(msTitle) >>= sTitle;
257*cdf0e10cSrcweir 		if(sTitle.getLength())
258*cdf0e10cSrcweir 		{
259*cdf0e10cSrcweir 			SvXMLElementExport aEventElemt(mrExport, XML_NAMESPACE_SVG, XML_TITLE, mbWhiteSpace, sal_False);
260*cdf0e10cSrcweir 			mrExport.Characters(sTitle);
261*cdf0e10cSrcweir 		}
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 		// description property (as <svg:desc> element)
264*cdf0e10cSrcweir 		OUString sDescription;
265*cdf0e10cSrcweir 		rPropertySet->getPropertyValue(msDescription) >>= sDescription;
266*cdf0e10cSrcweir 		if (sDescription.getLength() > 0)
267*cdf0e10cSrcweir 		{
268*cdf0e10cSrcweir 			SvXMLElementExport aDesc(mrExport, XML_NAMESPACE_SVG, XML_DESC, mbWhiteSpace, sal_False);
269*cdf0e10cSrcweir 			mrExport.Characters(sDescription);
270*cdf0e10cSrcweir 		}
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 		// export events attached to this
273*cdf0e10cSrcweir 		Reference<XEventsSupplier> xSupplier(rPropertySet, UNO_QUERY);
274*cdf0e10cSrcweir 		mrExport.GetEventExport().Export(xSupplier, mbWhiteSpace);
275*cdf0e10cSrcweir 	}
276*cdf0e10cSrcweir 	// else: no service info -> can't determine type -> ignore entry
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir void XMLImageMapExport::ExportRectangle(
280*cdf0e10cSrcweir 	const Reference<XPropertySet> & rPropertySet)
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir 	// get boundary rectangle
283*cdf0e10cSrcweir 	Any aAny = rPropertySet->getPropertyValue(msBoundary);
284*cdf0e10cSrcweir 	awt::Rectangle aRectangle;
285*cdf0e10cSrcweir 	aAny >>= aRectangle;
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 	// parameters svg:x, svg:y, svg:width, svg:height
288*cdf0e10cSrcweir 	OUStringBuffer aBuffer;
289*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(aBuffer, aRectangle.X);
290*cdf0e10cSrcweir 	mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_X,
291*cdf0e10cSrcweir 						  aBuffer.makeStringAndClear() );
292*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(aBuffer, aRectangle.Y);
293*cdf0e10cSrcweir 	mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_Y,
294*cdf0e10cSrcweir 						  aBuffer.makeStringAndClear() );
295*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(aBuffer, aRectangle.Width);
296*cdf0e10cSrcweir 	mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH,
297*cdf0e10cSrcweir 						  aBuffer.makeStringAndClear() );
298*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(aBuffer, aRectangle.Height);
299*cdf0e10cSrcweir 	mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT,
300*cdf0e10cSrcweir 						  aBuffer.makeStringAndClear() );
301*cdf0e10cSrcweir }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir void XMLImageMapExport::ExportCircle(
304*cdf0e10cSrcweir 	const Reference<XPropertySet> & rPropertySet)
305*cdf0e10cSrcweir {
306*cdf0e10cSrcweir 	// get boundary rectangle
307*cdf0e10cSrcweir 	Any aAny = rPropertySet->getPropertyValue(msCenter);
308*cdf0e10cSrcweir 	awt::Point aCenter;
309*cdf0e10cSrcweir 	aAny >>= aCenter;
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 	// parameters svg:cx, svg:cy
312*cdf0e10cSrcweir 	OUStringBuffer aBuffer;
313*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(aBuffer, aCenter.X);
314*cdf0e10cSrcweir 	mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_CX,
315*cdf0e10cSrcweir 						  aBuffer.makeStringAndClear() );
316*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(aBuffer, aCenter.Y);
317*cdf0e10cSrcweir 	mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_CY,
318*cdf0e10cSrcweir 						  aBuffer.makeStringAndClear() );
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir 	// radius
321*cdf0e10cSrcweir 	aAny = rPropertySet->getPropertyValue(msRadius);
322*cdf0e10cSrcweir 	sal_Int32 nRadius = 0;
323*cdf0e10cSrcweir 	aAny >>= nRadius;
324*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(aBuffer, nRadius);
325*cdf0e10cSrcweir 	mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_R,
326*cdf0e10cSrcweir 						  aBuffer.makeStringAndClear() );
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir void XMLImageMapExport::ExportPolygon(
330*cdf0e10cSrcweir 	const Reference<XPropertySet> & rPropertySet)
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir 	// polygons get exported as bounding box, viewbox, and coordinate
333*cdf0e10cSrcweir 	// pair sequence. The bounding box is always the entire image.
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 	// get polygon point sequence
336*cdf0e10cSrcweir 	Any aAny = rPropertySet->getPropertyValue(msPolygon);
337*cdf0e10cSrcweir 	PointSequence aPoly;
338*cdf0e10cSrcweir 	aAny >>= aPoly;
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 	// get bounding box (assume top-left to be 0,0)
341*cdf0e10cSrcweir 	sal_Int32 nWidth = 0;
342*cdf0e10cSrcweir 	sal_Int32 nHeight = 0;
343*cdf0e10cSrcweir 	sal_Int32 nLength = aPoly.getLength();
344*cdf0e10cSrcweir 	const struct awt::Point* pPointPtr = aPoly.getConstArray();
345*cdf0e10cSrcweir 	for	( sal_Int32 i = 0; i < nLength; i++ )
346*cdf0e10cSrcweir 	{
347*cdf0e10cSrcweir 		sal_Int32 nPolyX = pPointPtr->X;
348*cdf0e10cSrcweir 		sal_Int32 nPolyY = pPointPtr->Y;
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 		if ( nPolyX > nWidth )
351*cdf0e10cSrcweir 			nWidth = nPolyX;
352*cdf0e10cSrcweir 		if ( nPolyY > nHeight )
353*cdf0e10cSrcweir 			nHeight = nPolyY;
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 		pPointPtr++;
356*cdf0e10cSrcweir 	}
357*cdf0e10cSrcweir 	DBG_ASSERT(nWidth > 0, "impossible Polygon found");
358*cdf0e10cSrcweir 	DBG_ASSERT(nHeight > 0, "impossible Polygon found");
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 	// parameters svg:x, svg:y, svg:width, svg:height
361*cdf0e10cSrcweir 	OUStringBuffer aBuffer;
362*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(aBuffer, 0);
363*cdf0e10cSrcweir 	mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_X,
364*cdf0e10cSrcweir 						  aBuffer.makeStringAndClear() );
365*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(aBuffer, 0);
366*cdf0e10cSrcweir 	mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_Y,
367*cdf0e10cSrcweir 						  aBuffer.makeStringAndClear() );
368*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(aBuffer, nWidth);
369*cdf0e10cSrcweir 	mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH,
370*cdf0e10cSrcweir 						  aBuffer.makeStringAndClear() );
371*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(aBuffer, nHeight);
372*cdf0e10cSrcweir 	mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT,
373*cdf0e10cSrcweir 						  aBuffer.makeStringAndClear() );
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 	// svg:viewbox
376*cdf0e10cSrcweir 	SdXMLImExViewBox aViewBox(0, 0, nWidth, nHeight);
377*cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_SVG, XML_VIEWBOX,
378*cdf0e10cSrcweir 				aViewBox.GetExportString());
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir 	// export point sequence
381*cdf0e10cSrcweir 	awt::Point aPoint(0, 0);
382*cdf0e10cSrcweir 	awt::Size aSize(nWidth, nHeight);
383*cdf0e10cSrcweir 	SdXMLImExPointsElement aPoints( &aPoly, aViewBox, aPoint, aSize );
384*cdf0e10cSrcweir 	mrExport.AddAttribute( XML_NAMESPACE_DRAW, XML_POINTS,
385*cdf0e10cSrcweir 						  aPoints.GetExportString());
386*cdf0e10cSrcweir }
387