Update ooo320-m1
[ooovba.git] / oox / source / export / shapes.cxx
blob7ce05d820cedb5d1dedbf683e7615d2276c01af4
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$
10 * $Revision$
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 #include "tokens.hxx"
32 #include "oox/core/xmlfilterbase.hxx"
33 #include "oox/export/shapes.hxx"
34 #include "oox/export/utils.hxx"
36 #include <cstdio>
37 #include <com/sun/star/awt/CharSet.hpp>
38 #include <com/sun/star/awt/FontDescriptor.hpp>
39 #include <com/sun/star/awt/FontSlant.hpp>
40 #include <com/sun/star/awt/FontWeight.hpp>
41 #include <com/sun/star/awt/FontUnderline.hpp>
42 #include <com/sun/star/awt/Gradient.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/beans/XPropertyState.hpp>
45 #include <com/sun/star/container/XEnumerationAccess.hpp>
46 #include <com/sun/star/drawing/FillStyle.hpp>
47 #include <com/sun/star/drawing/BitmapMode.hpp>
48 #include <com/sun/star/drawing/ConnectorType.hpp>
49 #include <com/sun/star/drawing/LineDash.hpp>
50 #include <com/sun/star/drawing/LineJoint.hpp>
51 #include <com/sun/star/drawing/LineStyle.hpp>
52 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
53 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
54 #include <com/sun/star/i18n/ScriptType.hpp>
55 #include <com/sun/star/io/XOutputStream.hpp>
56 #include <com/sun/star/style/ParagraphAdjust.hpp>
57 #include <com/sun/star/text/XSimpleText.hpp>
58 #include <com/sun/star/text/XText.hpp>
59 #include <com/sun/star/text/XTextContent.hpp>
60 #include <com/sun/star/text/XTextField.hpp>
61 #include <com/sun/star/text/XTextRange.hpp>
62 #include <tools/stream.hxx>
63 #include <tools/string.hxx>
64 #include <vcl/cvtgrf.hxx>
65 #include <vcl/fontcvt.hxx>
66 #include <vcl/graph.hxx>
67 #include <vcl/outdev.hxx>
68 #include <goodies/grfmgr.hxx>
69 #include <rtl/strbuf.hxx>
70 #include <sfx2/app.hxx>
71 #include <svtools/languageoptions.hxx>
72 #include <svx/escherex.hxx>
73 #include <svx/svdoashp.hxx>
74 #include <svx/svxenum.hxx>
75 #include <svx/unoapi.hxx>
77 using namespace ::com::sun::star;
78 using namespace ::com::sun::star::uno;
79 using namespace ::com::sun::star::drawing;
80 using namespace ::com::sun::star::i18n;
81 using ::com::sun::star::beans::PropertyState;
82 using ::com::sun::star::beans::PropertyValue;
83 using ::com::sun::star::beans::XPropertySet;
84 using ::com::sun::star::beans::XPropertyState;
85 using ::com::sun::star::container::XEnumeration;
86 using ::com::sun::star::container::XEnumerationAccess;
87 using ::com::sun::star::container::XIndexAccess;
88 using ::com::sun::star::drawing::FillStyle;
89 using ::com::sun::star::io::XOutputStream;
90 using ::com::sun::star::text::XSimpleText;
91 using ::com::sun::star::text::XText;
92 using ::com::sun::star::text::XTextContent;
93 using ::com::sun::star::text::XTextField;
94 using ::com::sun::star::text::XTextRange;
95 using ::rtl::OString;
96 using ::rtl::OStringBuffer;
97 using ::rtl::OUString;
98 using ::rtl::OUStringBuffer;
99 using ::sax_fastparser::FSHelperPtr;
101 DBG(extern void dump_pset(Reference< XPropertySet > rXPropSet));
103 #define IDS(x) (OString(#x " ") + OString::valueOf( mnShapeIdMax++ )).getStr()
105 struct CustomShapeTypeTranslationTable
107 const char* sOOo;
108 const char* sMSO;
111 static const CustomShapeTypeTranslationTable pCustomShapeTypeTranslationTable[] =
113 // { "non-primitive", mso_sptMin },
114 { "rectangle", "rect" },
115 { "round-rectangle", "roundRect" },
116 { "ellipse", "ellipse" },
117 { "diamond", "diamond" },
118 { "isosceles-triangle", "triangle" },
119 { "right-triangle", "rtTriangle" },
120 { "parallelogram", "parallelogram" },
121 { "trapezoid", "trapezoid" },
122 { "hexagon", "hexagon" },
123 { "octagon", "octagon" },
124 { "cross", "plus" },
125 { "star5", "star5" },
126 { "right-arrow", "rightArrow" },
127 // { "mso-spt14", mso_sptThickArrow },
128 { "pentagon-right", "homePlate" },
129 { "cube", "cube" },
130 // { "mso-spt17", mso_sptBalloon },
131 // { "mso-spt18", mso_sptSeal },
132 { "mso-spt19", "arc" },
133 { "mso-spt20", "line" },
134 { "mso-spt21", "plaque" },
135 { "can", "can" },
136 { "ring", "donut" },
137 { "mso-spt24", "textSimple" },
138 { "mso-spt25", "textOctagon" },
139 { "mso-spt26", "textHexagon" },
140 { "mso-spt27", "textCurve" },
141 { "mso-spt28", "textWave" },
142 { "mso-spt29", "textRing" },
143 { "mso-spt30", "textOnCurve" },
144 { "mso-spt31", "textOnRing" },
145 { "mso-spt32", "straightConnector1" },
146 { "mso-spt33", "bentConnector2" },
147 { "mso-spt34", "bentConnector3" },
148 { "mso-spt35", "bentConnector4" },
149 { "mso-spt36", "bentConnector5" },
150 { "mso-spt37", "curvedConnector2" },
151 { "mso-spt38", "curvedConnector3" },
152 { "mso-spt39", "curvedConnector4" },
153 { "mso-spt40", "curvedConnector5" },
154 { "mso-spt41", "callout1" },
155 { "mso-spt42", "callout2" },
156 { "mso-spt43", "callout3" },
157 { "mso-spt44", "accentCallout1" },
158 { "mso-spt45", "accentCallout2" },
159 { "mso-spt46", "accentCallout3" },
160 { "line-callout-1", "borderCallout1" },
161 { "line-callout-2", "borderCallout2" },
162 { "line-callout-3", "borderCallout3" },
163 { "mso-spt49", "accentBorderCallout90" },
164 { "mso-spt50", "accentBorderCallout1" },
165 { "mso-spt51", "accentBorderCallout2" },
166 { "mso-spt52", "accentBorderCallout3" },
167 { "mso-spt53", "ribbon" },
168 { "mso-spt54", "ribbon2" },
169 { "chevron", "chevron" },
170 { "pentagon", "pentagon" },
171 { "forbidden", "noSmoking" },
172 { "star8", "seal8" },
173 { "mso-spt59", "seal16" },
174 { "mso-spt60", "seal32" },
175 { "rectangular-callout", "wedgeRectCallout" },
176 { "round-rectangular-callout", "wedgeRoundRectCallout" },
177 { "round-callout", "wedgeEllipseCallout" },
178 { "mso-spt64", "wave" },
179 { "paper", "foldedCorner" },
180 { "left-arrow", "leftArrow" },
181 { "down-arrow", "downArrow" },
182 { "up-arrow", "upArrow" },
183 { "left-right-arrow", "leftRightArrow" },
184 { "up-down-arrow", "upDownArrow" },
185 { "mso-spt71", "irregularSeal1" },
186 { "bang", "irregularSeal2" },
187 { "lightning", "lightningBolt" },
188 { "heart", "heart" },
189 { "mso-spt75", "pictureFrame" },
190 { "quad-arrow", "quadArrow" },
191 { "left-arrow-callout", "leftArrowCallout" },
192 { "right-arrow-callout", "rightArrowCallout" },
193 { "up-arrow-callout", "upArrowCallout" },
194 { "down-arrow-callout", "downArrowCallout" },
195 { "left-right-arrow-callout", "leftRightArrowCallout" },
196 { "up-down-arrow-callout", "upDownArrowCallout" },
197 { "quad-arrow-callout", "quadArrowCallout" },
198 { "quad-bevel", "bevel" },
199 { "left-bracket", "leftBracket" },
200 { "right-bracket", "rightBracket" },
201 { "left-brace", "leftBrace" },
202 { "right-brace", "rightBrace" },
203 { "mso-spt89", "leftUpArrow" },
204 { "mso-spt90", "bentUpArrow" },
205 { "mso-spt91", "bentArrow" },
206 { "star24", "seal24" },
207 { "striped-right-arrow", "stripedRightArrow" },
208 { "notched-right-arrow", "notchedRightArrow" },
209 { "block-arc", "blockArc" },
210 { "smiley", "smileyFace" },
211 { "vertical-scroll", "verticalScroll" },
212 { "horizontal-scroll", "horizontalScroll" },
213 { "circular-arrow", "circularArrow" },
214 { "mso-spt100", "pie" }, // looks like MSO_SPT is wrong here
215 { "mso-spt101", "uturnArrow" },
216 { "mso-spt102", "curvedRightArrow" },
217 { "mso-spt103", "curvedLeftArrow" },
218 { "mso-spt104", "curvedUpArrow" },
219 { "mso-spt105", "curvedDownArrow" },
220 { "cloud-callout", "cloudCallout" },
221 { "mso-spt107", "ellipseRibbon" },
222 { "mso-spt108", "ellipseRibbon2" },
223 { "flowchart-process", "flowChartProcess" },
224 { "flowchart-decision", "flowChartDecision" },
225 { "flowchart-data", "flowChartInputOutput" },
226 { "flowchart-predefined-process", "flowChartPredefinedProcess" },
227 { "flowchart-internal-storage", "flowChartInternalStorage" },
228 { "flowchart-document", "flowChartDocument" },
229 { "flowchart-multidocument", "flowChartMultidocument" },
230 { "flowchart-terminator", "flowChartTerminator" },
231 { "flowchart-preparation", "flowChartPreparation" },
232 { "flowchart-manual-input", "flowChartManualInput" },
233 { "flowchart-manual-operation", "flowChartManualOperation" },
234 { "flowchart-connector", "flowChartConnector" },
235 { "flowchart-card", "flowChartPunchedCard" },
236 { "flowchart-punched-tape", "flowChartPunchedTape" },
237 { "flowchart-summing-junction", "flowChartSummingJunction" },
238 { "flowchart-or", "flowChartOr" },
239 { "flowchart-collate", "flowChartCollate" },
240 { "flowchart-sort", "flowChartSort" },
241 { "flowchart-extract", "flowChartExtract" },
242 { "flowchart-merge", "flowChartMerge" },
243 { "mso-spt129", "flowChartOfflineStorage" },
244 { "flowchart-stored-data", "flowChartOnlineStorage" },
245 { "flowchart-sequential-access", "flowChartMagneticTape" },
246 { "flowchart-magnetic-disk", "flowChartMagneticDisk" },
247 { "flowchart-direct-access-storage", "flowChartMagneticDrum" },
248 { "flowchart-display", "flowChartDisplay" },
249 { "flowchart-delay", "flowChartDelay" },
250 { "fontwork-plain-text", "textPlainText" },
251 { "fontwork-stop", "textStop" },
252 { "fontwork-triangle-up", "textTriangle" },
253 { "fontwork-triangle-down", "textTriangleInverted" },
254 { "fontwork-chevron-up", "textChevron" },
255 { "fontwork-chevron-down", "textChevronInverted" },
256 { "mso-spt142", "textRingInside" },
257 { "mso-spt143", "textRingOutside" },
258 { "fontwork-arch-up-curve", "textArchUpCurve" },
259 { "fontwork-arch-down-curve", "textArchDownCurve" },
260 { "fontwork-circle-curve", "textCircleCurve" },
261 { "fontwork-open-circle-curve", "textButtonCurve" },
262 { "fontwork-arch-up-pour", "textArchUpPour" },
263 { "fontwork-arch-down-pour", "textArchDownPour" },
264 { "fontwork-circle-pour", "textCirclePour" },
265 { "fontwork-open-circle-pour", "textButtonPour" },
266 { "fontwork-curve-up", "textCurveUp" },
267 { "fontwork-curve-down", "textCurveDown" },
268 { "fontwork-fade-up-and-right", "textCascadeUp" },
269 { "fontwork-fade-up-and-left", "textCascadeDown" },
270 { "fontwork-wave", "textWave1" },
271 { "mso-spt157", "textWave2" },
272 { "mso-spt158", "textWave3" },
273 { "mso-spt159", "textWave4" },
274 { "fontwork-inflate", "textInflate" },
275 { "mso-spt161", "textDeflate" },
276 { "mso-spt162", "textInflateBottom" },
277 { "mso-spt163", "textDeflateBottom" },
278 { "mso-spt164", "textInflateTop" },
279 { "mso-spt165", "textDeflateTop" },
280 { "mso-spt166", "textDeflateInflate" },
281 { "mso-spt167", "textDeflateInflateDeflate" },
282 { "fontwork-fade-right", "textFadeRight" },
283 { "fontwork-fade-left", "textFadeLeft" },
284 { "fontwork-fade-up", "textFadeUp" },
285 { "fontwork-fade-down", "textFadeDown" },
286 { "fontwork-slant-up", "textSlantUp" },
287 { "fontwork-slant-down", "textSlantDown" },
288 { "mso-spt174", "textCanUp" },
289 { "mso-spt175", "textCanDown" },
290 { "flowchart-alternate-process", "flowChartAlternateProcess" },
291 { "flowchart-off-page-connector", "flowChartOffpageConnector" },
292 { "mso-spt178", "callout90" },
293 { "mso-spt179", "accentCallout90" },
294 { "mso-spt180", "borderCallout90" },
295 { "mso-spt182", "leftRightUpArrow" },
296 { "sun", "sun" },
297 { "moon", "moon" },
298 { "bracket-pair", "bracketPair" },
299 { "brace-pair", "bracePair" },
300 { "star4", "seal4" },
301 { "mso-spt188", "doubleWave" },
302 { "mso-spt189", "actionButtonBlank" },
303 { "mso-spt190", "actionButtonHome" },
304 { "mso-spt191", "actionButtonHelp" },
305 { "mso-spt192", "actionButtonInformation" },
306 { "mso-spt193", "actionButtonForwardNext" },
307 { "mso-spt194", "actionButtonBackPrevious" },
308 { "mso-spt195", "actionButtonEnd" },
309 { "mso-spt196", "actionButtonBeginning" },
310 { "mso-spt197", "actionButtonReturn" },
311 { "mso-spt198", "actionButtonDocument" },
312 { "mso-spt199", "actionButtonSound" },
313 { "mso-spt200", "actionButtonMovie" },
314 { "mso-spt201", "hostControl" },
315 { "mso-spt202", "rect" }
318 struct StringCheck
320 bool operator()( const char* s1, const char* s2 ) const
322 return strcmp( s1, s2 ) == 0;
326 typedef std::hash_map< const char*, const char*, std::hash<const char*>, StringCheck> CustomShapeTypeTranslationHashMap;
327 static CustomShapeTypeTranslationHashMap* pCustomShapeTypeTranslationHashMap = NULL;
329 static const char* lcl_GetPresetGeometry( const char* sShapeType )
331 const char* sPresetGeo;
333 if( pCustomShapeTypeTranslationHashMap == NULL )
335 pCustomShapeTypeTranslationHashMap = new CustomShapeTypeTranslationHashMap ();
336 for( unsigned int i = 0; i < sizeof( pCustomShapeTypeTranslationTable )/sizeof( CustomShapeTypeTranslationTable ); i ++ )
338 (*pCustomShapeTypeTranslationHashMap)[ pCustomShapeTypeTranslationTable[ i ].sOOo ] = pCustomShapeTypeTranslationTable[ i ].sMSO;
339 //DBG(printf("type OOo: %s MSO: %s\n", pCustomShapeTypeTranslationTable[ i ].sOOo, pCustomShapeTypeTranslationTable[ i ].sMSO));
343 sPresetGeo = (*pCustomShapeTypeTranslationHashMap)[ sShapeType ];
345 if( sPresetGeo == NULL )
346 sPresetGeo = "rect";
348 return sPresetGeo;
351 namespace oox { namespace drawingml {
353 #define GETA(propName) \
354 GetProperty( rXPropSet, String( RTL_CONSTASCII_USTRINGPARAM( #propName ) ) )
356 #define GETAD(propName) \
357 ( GetPropertyAndState( rXPropSet, rXPropState, String( RTL_CONSTASCII_USTRINGPARAM( #propName ) ), eState ) && eState == beans::PropertyState_DIRECT_VALUE )
359 #define GET(variable, propName) \
360 if ( GETA(propName) ) \
361 mAny >>= variable;
363 ShapeExport::ShapeExport( sal_Int32 nXmlNamespace, FSHelperPtr pFS, ::oox::core::XmlFilterBase* pFB, DocumentType eDocumentType )
364 : DrawingML( pFS, pFB, eDocumentType )
365 , mnXmlNamespace( nXmlNamespace )
366 , mnShapeIdMax( 1 )
367 , mnPictureIdMax( 1 )
368 , maFraction( 1, 576 )
369 , maMapModeSrc( MAP_100TH_MM )
370 , maMapModeDest( MAP_INCH, Point(), maFraction, maFraction )
374 sal_Int32 ShapeExport::GetXmlNamespace() const
376 return mnXmlNamespace;
379 ShapeExport& ShapeExport::SetXmlNamespace( sal_Int32 nXmlNamespace )
381 mnXmlNamespace = nXmlNamespace;
382 return *this;
385 awt::Size ShapeExport::MapSize( const awt::Size& rSize ) const
387 Size aRetSize( OutputDevice::LogicToLogic( Size( rSize.Width, rSize.Height ), maMapModeSrc, maMapModeDest ) );
389 if ( !aRetSize.Width() )
390 aRetSize.Width()++;
391 if ( !aRetSize.Height() )
392 aRetSize.Height()++;
393 return awt::Size( aRetSize.Width(), aRetSize.Height() );
396 sal_Bool ShapeExport::NonEmptyText( Reference< XShape > xShape )
398 Reference< XSimpleText > xText( xShape, UNO_QUERY );
400 return ( xText.is() && xText->getString().getLength() );
403 ShapeExport& ShapeExport::WriteBezierShape( Reference< XShape > xShape, sal_Bool bClosed )
405 DBG(printf("write open bezier shape\n"));
407 FSHelperPtr pFS = GetFS();
408 pFS->startElementNS( mnXmlNamespace, XML_sp, FSEND );
410 PolyPolygon aPolyPolygon = EscherPropertyContainer::GetPolyPolygon( xShape );
411 Rectangle aRect( aPolyPolygon.GetBoundRect() );
412 awt::Size size = MapSize( awt::Size( aRect.GetWidth(), aRect.GetHeight() ) );
414 DBG(printf("poly count %d\nsize: %d x %d", aPolyPolygon.Count(), int( size.Width ), int( size.Height )));
416 // non visual shape properties
417 pFS->startElementNS( mnXmlNamespace, XML_nvSpPr, FSEND );
418 pFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
419 XML_id, I32S( GetNewShapeID( xShape ) ),
420 XML_name, IDS( Freeform ),
421 FSEND );
422 pFS->singleElementNS( mnXmlNamespace, XML_cNvSpPr, FSEND );
423 WriteNonVisualProperties( xShape );
424 pFS->endElementNS( mnXmlNamespace, XML_nvSpPr );
426 // visual shape properties
427 pFS->startElementNS( mnXmlNamespace, XML_spPr, FSEND );
428 WriteTransformation( aRect );
429 WritePolyPolygon( aPolyPolygon );
430 Reference< XPropertySet > xProps( xShape, UNO_QUERY );
431 if( xProps.is() ) {
432 if( bClosed )
433 WriteFill( xProps );
434 WriteOutline( xProps );
437 pFS->endElementNS( mnXmlNamespace, XML_spPr );
439 // write text
440 WriteTextBox( xShape );
442 pFS->endElementNS( mnXmlNamespace, XML_sp );
444 return *this;
447 ShapeExport& ShapeExport::WriteClosedBezierShape( Reference< XShape > xShape )
449 return WriteBezierShape( xShape, TRUE );
452 ShapeExport& ShapeExport::WriteOpenBezierShape( Reference< XShape > xShape )
454 return WriteBezierShape( xShape, FALSE );
457 ShapeExport& ShapeExport::WriteCustomShape( Reference< XShape > xShape )
459 DBG(printf("write custom shape\n"));
461 Reference< XPropertySet > rXPropSet( xShape, UNO_QUERY );
462 SdrObjCustomShape* pShape = (SdrObjCustomShape*) GetSdrObjectFromXShape( xShape );
463 sal_Bool bIsDefaultObject = EscherPropertyContainer::IsDefaultObject( pShape );
464 sal_Bool bPredefinedHandlesUsed = TRUE;
465 OUString sShapeType;
466 sal_uInt32 nMirrorFlags = 0;
467 MSO_SPT eShapeType = EscherPropertyContainer::GetCustomShapeType( xShape, nMirrorFlags, sShapeType );
468 const char* sPresetShape = lcl_GetPresetGeometry( USS( sShapeType ) );
469 DBG(printf("custom shape type: %s ==> %s\n", USS( sShapeType ), sPresetShape));
470 Sequence< PropertyValue > aGeometrySeq;
471 sal_Int32 nAdjustmentValuesIndex = -1;
472 sal_Int32 nAdjustmentsWhichNeedsToBeConverted = 0;
474 if( GETA( CustomShapeGeometry ) ) {
475 DBG(printf("got custom shape geometry\n"));
476 if( mAny >>= aGeometrySeq ) {
478 DBG(printf("got custom shape geometry sequence\n"));
479 for( int i = 0; i < aGeometrySeq.getLength(); i++ ) {
480 const PropertyValue& rProp = aGeometrySeq[ i ];
481 DBG(printf("geometry property: %s\n", USS( rProp.Name )));
483 if( rProp.Name.equalsAscii( "AdjustmentValues" ))
484 nAdjustmentValuesIndex = i;
485 else if( rProp.Name.equalsAscii( "Handles" )) {
486 if( !bIsDefaultObject )
487 bPredefinedHandlesUsed = FALSE;
488 // TODO: update nAdjustmentsWhichNeedsToBeConverted here
494 FSHelperPtr pFS = GetFS();
495 pFS->startElementNS( mnXmlNamespace, XML_sp, FSEND );
497 // non visual shape properties
498 pFS->startElementNS( mnXmlNamespace, XML_nvSpPr, FSEND );
499 pFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
500 XML_id, I32S( GetNewShapeID( xShape ) ),
501 XML_name, IDS( CustomShape ),
502 FSEND );
503 pFS->singleElementNS( mnXmlNamespace, XML_cNvSpPr, FSEND );
504 WriteNonVisualProperties( xShape );
505 pFS->endElementNS( mnXmlNamespace, XML_nvSpPr );
507 // visual shape properties
508 pFS->startElementNS( mnXmlNamespace, XML_spPr, FSEND );
509 WriteShapeTransformation( xShape );
510 if( nAdjustmentValuesIndex != -1 )
511 WritePresetShape( sPresetShape, eShapeType, bPredefinedHandlesUsed, nAdjustmentsWhichNeedsToBeConverted, aGeometrySeq[ nAdjustmentValuesIndex ] );
512 else
513 WritePresetShape( sPresetShape );
514 if( rXPropSet.is() )
516 WriteFill( rXPropSet );
517 WriteOutline( rXPropSet );
520 pFS->endElementNS( mnXmlNamespace, XML_spPr );
522 // write text
523 WriteTextBox( xShape );
525 pFS->endElementNS( mnXmlNamespace, XML_sp );
527 return *this;
530 ShapeExport& ShapeExport::WriteEllipseShape( Reference< XShape > xShape )
532 DBG(printf("write ellipse shape\n"));
534 FSHelperPtr pFS = GetFS();
536 pFS->startElementNS( mnXmlNamespace, XML_sp, FSEND );
538 // TODO: arc, section, cut, connector
540 // non visual shape properties
541 pFS->startElementNS( mnXmlNamespace, XML_nvSpPr, FSEND );
542 pFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
543 XML_id, I32S( GetNewShapeID( xShape ) ),
544 XML_name, IDS( Ellipse ),
545 FSEND );
546 pFS->singleElementNS( mnXmlNamespace, XML_cNvSpPr, FSEND );
547 WriteNonVisualProperties( xShape );
548 pFS->endElementNS( mnXmlNamespace, XML_nvSpPr );
550 // visual shape properties
551 pFS->startElementNS( mnXmlNamespace, XML_spPr, FSEND );
552 WriteShapeTransformation( xShape );
553 WritePresetShape( "ellipse" );
554 Reference< XPropertySet > xProps( xShape, UNO_QUERY );
555 if( xProps.is() )
557 WriteFill( xProps );
558 WriteOutline( xProps );
560 pFS->endElementNS( mnXmlNamespace, XML_spPr );
562 // write text
563 WriteTextBox( xShape );
565 pFS->endElementNS( mnXmlNamespace, XML_sp );
567 return *this;
570 ShapeExport& ShapeExport::WriteFill( Reference< XPropertySet > xPropSet )
572 FillStyle aFillStyle( FillStyle_NONE );
573 xPropSet->getPropertyValue( S( "FillStyle" ) ) >>= aFillStyle;
575 if( aFillStyle == FillStyle_BITMAP )
577 //DBG(printf ("FillStyle_BITMAP properties\n"));
578 //DBG(dump_pset(rXPropSet));
581 if( aFillStyle == FillStyle_NONE ||
582 aFillStyle == FillStyle_HATCH )
583 return *this;
585 switch( aFillStyle )
587 case ::com::sun::star::drawing::FillStyle_SOLID :
588 WriteSolidFill( xPropSet );
589 break;
590 case ::com::sun::star::drawing::FillStyle_GRADIENT :
591 WriteGradientFill( xPropSet );
592 break;
593 case ::com::sun::star::drawing::FillStyle_BITMAP :
594 WriteBlipFill( xPropSet, S( "FillBitmapURL" ) );
595 break;
596 default:
600 return *this;
603 ShapeExport& ShapeExport::WriteGraphicObjectShape( Reference< XShape > xShape )
605 DBG(printf("write graphic object shape\n"));
607 if( NonEmptyText( xShape ) )
609 WriteTextShape( xShape );
611 //DBG(dump_pset(mXPropSet));
613 return *this;
616 DBG(printf("graphicObject without text\n"));
618 OUString sGraphicURL;
619 Reference< XPropertySet > xShapeProps( xShape, UNO_QUERY );
620 if( !xShapeProps.is() || !( xShapeProps->getPropertyValue( S( "GraphicURL" ) ) >>= sGraphicURL ) )
622 DBG(printf("no graphic URL found\n"));
623 return *this;
626 FSHelperPtr pFS = GetFS();
628 pFS->startElementNS( mnXmlNamespace, XML_pic, FSEND );
630 pFS->startElementNS( mnXmlNamespace, XML_nvPicPr, FSEND );
632 OUString sName, sDescr;
633 bool bHaveName = xShapeProps->getPropertyValue( S( "Name" ) ) >>= sName;
634 bool bHaveDesc = xShapeProps->getPropertyValue( S( "Description" ) ) >>= sDescr;
636 pFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
637 XML_id, I32S( GetNewShapeID( xShape ) ),
638 XML_name, bHaveName ? USS( sName ) : (OString("Picture ") + OString::valueOf( mnPictureIdMax++ )).getStr(),
639 XML_descr, bHaveDesc ? USS( sDescr ) : NULL,
640 FSEND );
641 // OOXTODO: //cNvPr children: XML_extLst, XML_hlinkClick, XML_hlinkHover
643 pFS->singleElementNS( mnXmlNamespace, XML_cNvPicPr,
644 // OOXTODO: XML_preferRelativeSize
645 FSEND );
647 WriteNonVisualProperties( xShape );
649 pFS->endElementNS( mnXmlNamespace, XML_nvPicPr );
651 pFS->startElementNS( mnXmlNamespace, XML_blipFill, FSEND );
653 WriteBlip( sGraphicURL );
655 bool bStretch = false;
656 if( ( xShapeProps->getPropertyValue( S( "FillBitmapStretch" ) ) >>= bStretch ) && bStretch )
658 WriteStretch();
661 pFS->endElementNS( mnXmlNamespace, XML_blipFill );
663 // visual shape properties
664 pFS->startElementNS( mnXmlNamespace, XML_spPr, FSEND );
665 WriteShapeTransformation( xShape );
666 WritePresetShape( "rect" );
667 pFS->endElementNS( mnXmlNamespace, XML_spPr );
669 pFS->endElementNS( mnXmlNamespace, XML_pic );
671 return *this;
674 ShapeExport& ShapeExport::WriteConnectorShape( Reference< XShape > xShape )
676 sal_Bool bFlipH = false;
677 sal_Bool bFlipV = false;
679 DBG(printf("write connector shape\n"));
681 FSHelperPtr pFS = GetFS();
683 const char* sGeometry = "line";
684 Reference< XPropertySet > rXPropSet( xShape, UNO_QUERY );
685 Reference< XPropertyState > rXPropState( xShape, UNO_QUERY );
686 awt::Point aStartPoint, aEndPoint;
687 Reference< XShape > rXShapeA;
688 Reference< XShape > rXShapeB;
689 PropertyState eState;
690 ConnectorType eConnectorType;
691 if( GETAD( EdgeKind ) ) {
692 mAny >>= eConnectorType;
694 switch( eConnectorType ) {
695 case ConnectorType_CURVE:
696 sGeometry = "curvedConnector3";
697 break;
698 case ConnectorType_STANDARD:
699 sGeometry = "bentConnector3";
700 break;
701 default:
702 case ConnectorType_LINE:
703 case ConnectorType_LINES:
704 sGeometry = "straightConnector1";
705 break;
708 if( GETAD( EdgeStartPoint ) ) {
709 mAny >>= aStartPoint;
710 if( GETAD( EdgeEndPoint ) ) {
711 mAny >>= aEndPoint;
714 GET( rXShapeA, EdgeStartConnection );
715 GET( rXShapeB, EdgeEndConnection );
717 EscherConnectorListEntry aConnectorEntry( xShape, aStartPoint, rXShapeA, aEndPoint, rXShapeB );
719 Rectangle aRect( Point( aStartPoint.X, aStartPoint.Y ), Point( aEndPoint.X, aEndPoint.Y ) );
720 if( aRect.getWidth() < 0 ) {
721 bFlipH = TRUE;
722 aRect.setX( aEndPoint.X );
723 aRect.setWidth( aStartPoint.X - aEndPoint.X );
726 if( aRect.getHeight() < 0 ) {
727 bFlipV = TRUE;
728 aRect.setY( aEndPoint.Y );
729 aRect.setHeight( aStartPoint.Y - aEndPoint.Y );
732 pFS->startElementNS( mnXmlNamespace, XML_cxnSp, FSEND );
734 // non visual shape properties
735 pFS->startElementNS( mnXmlNamespace, XML_nvCxnSpPr, FSEND );
736 pFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
737 XML_id, I32S( GetNewShapeID( xShape ) ),
738 XML_name, IDS( Line ),
739 FSEND );
740 // non visual connector shape drawing properties
741 pFS->startElementNS( mnXmlNamespace, XML_cNvCxnSpPr, FSEND );
742 WriteConnectorConnections( aConnectorEntry, GetShapeID( rXShapeA ), GetShapeID( rXShapeB ) );
743 pFS->endElementNS( mnXmlNamespace, XML_cNvCxnSpPr );
744 pFS->singleElementNS( mnXmlNamespace, XML_nvPr, FSEND );
745 pFS->endElementNS( mnXmlNamespace, XML_nvCxnSpPr );
747 // visual shape properties
748 pFS->startElementNS( mnXmlNamespace, XML_spPr, FSEND );
749 WriteTransformation( aRect, bFlipH, bFlipV );
750 // TODO: write adjustments (ppt export doesn't work well there either)
751 WritePresetShape( sGeometry );
752 Reference< XPropertySet > xShapeProps( xShape, UNO_QUERY );
753 if( xShapeProps.is() )
754 WriteOutline( xShapeProps );
755 pFS->endElementNS( mnXmlNamespace, XML_spPr );
757 // write text
758 WriteTextBox( xShape );
760 pFS->endElementNS( mnXmlNamespace, XML_cxnSp );
762 return *this;
765 ShapeExport& ShapeExport::WriteLineShape( Reference< XShape > xShape )
767 sal_Bool bFlipH = false;
768 sal_Bool bFlipV = false;
770 DBG(printf("write line shape\n"));
772 FSHelperPtr pFS = GetFS();
774 pFS->startElementNS( mnXmlNamespace, XML_sp, FSEND );
776 PolyPolygon aPolyPolygon = EscherPropertyContainer::GetPolyPolygon( xShape );
777 if( aPolyPolygon.Count() == 1 && aPolyPolygon[ 0 ].GetSize() == 2)
779 const Polygon& rPoly = aPolyPolygon[ 0 ];
781 bFlipH = ( rPoly[ 0 ].X() > rPoly[ 1 ].X() );
782 bFlipV = ( rPoly[ 0 ].Y() > rPoly[ 1 ].Y() );
785 // non visual shape properties
786 pFS->startElementNS( mnXmlNamespace, XML_nvSpPr, FSEND );
787 pFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
788 XML_id, I32S( GetNewShapeID( xShape ) ),
789 XML_name, IDS( Line ),
790 FSEND );
791 pFS->singleElementNS( mnXmlNamespace, XML_cNvSpPr, FSEND );
792 WriteNonVisualProperties( xShape );
793 pFS->endElementNS( mnXmlNamespace, XML_nvSpPr );
795 // visual shape properties
796 pFS->startElementNS( mnXmlNamespace, XML_spPr, FSEND );
797 WriteShapeTransformation( xShape, bFlipH, bFlipV );
798 WritePresetShape( "line" );
799 Reference< XPropertySet > xShapeProps( xShape, UNO_QUERY );
800 if( xShapeProps.is() )
801 WriteOutline( xShapeProps );
802 pFS->endElementNS( mnXmlNamespace, XML_spPr );
804 // write text
805 WriteTextBox( xShape );
807 pFS->endElementNS( mnXmlNamespace, XML_sp );
809 return *this;
812 ShapeExport& ShapeExport::WriteNonVisualDrawingProperties( Reference< XShape > xShape, const char* pName )
814 GetFS()->singleElementNS( mnXmlNamespace, XML_cNvPr,
815 XML_id, I32S( GetNewShapeID( xShape ) ),
816 XML_name, pName,
817 FSEND );
819 return *this;
822 ShapeExport& ShapeExport::WriteNonVisualProperties( Reference< XShape > )
824 // Override to generate //nvPr elements.
825 return *this;
828 ShapeExport& ShapeExport::WriteRectangleShape( Reference< XShape > xShape )
830 DBG(printf("write rectangle shape\n"));
832 FSHelperPtr pFS = GetFS();
834 pFS->startElementNS( mnXmlNamespace, XML_sp, FSEND );
836 sal_Int32 nRadius = 0;
838 Reference< XPropertySet > xShapeProps( xShape, UNO_QUERY );
839 if( xShapeProps.is() )
841 xShapeProps->getPropertyValue( S( "CornerRadius" ) ) >>= nRadius;
844 if( nRadius )
846 nRadius = MapSize( awt::Size( nRadius, 0 ) ).Width;
849 // non visual shape properties
850 pFS->startElementNS( mnXmlNamespace, XML_nvSpPr, FSEND );
851 pFS->singleElementNS( mnXmlNamespace, XML_cNvPr,
852 XML_id, I32S( GetNewShapeID( xShape ) ),
853 XML_name, IDS( Rectangle ),
854 FSEND );
855 pFS->singleElementNS( mnXmlNamespace, XML_cNvSpPr, FSEND );
856 WriteNonVisualProperties( xShape );
857 pFS->endElementNS( mnXmlNamespace, XML_nvSpPr );
859 // visual shape properties
860 pFS->startElementNS( mnXmlNamespace, XML_spPr, FSEND );
861 WriteShapeTransformation( xShape );
862 WritePresetShape( "rect" );
863 Reference< XPropertySet > xProps( xShape, UNO_QUERY );
864 if( xProps.is() )
866 WriteFill( xProps );
867 WriteOutline( xProps );
869 pFS->endElementNS( mnXmlNamespace, XML_spPr );
871 // write text
872 WriteTextBox( xShape );
874 pFS->endElementNS( mnXmlNamespace, XML_sp );
876 return *this;
879 typedef ShapeExport& (ShapeExport::*ShapeConverter)( Reference< XShape > );
880 typedef std::hash_map< const char*, ShapeConverter, std::hash<const char*>, StringCheck> NameToConvertMapType;
882 static const NameToConvertMapType& lcl_GetConverters()
884 static bool shape_map_inited = false;
885 static NameToConvertMapType shape_converters;
886 if( shape_map_inited )
888 return shape_converters;
891 shape_converters[ "com.sun.star.drawing.ClosedBezierShape" ] = &ShapeExport::WriteClosedBezierShape;
892 shape_converters[ "com.sun.star.drawing.ConnectorShape" ] = &ShapeExport::WriteConnectorShape;
893 shape_converters[ "com.sun.star.drawing.CustomShape" ] = &ShapeExport::WriteCustomShape;
894 shape_converters[ "com.sun.star.drawing.EllipseShape" ] = &ShapeExport::WriteEllipseShape;
895 shape_converters[ "com.sun.star.drawing.GraphicObjectShape" ] = &ShapeExport::WriteGraphicObjectShape;
896 shape_converters[ "com.sun.star.drawing.LineShape" ] = &ShapeExport::WriteLineShape;
897 shape_converters[ "com.sun.star.drawing.OpenBezierShape" ] = &ShapeExport::WriteOpenBezierShape;
898 shape_converters[ "com.sun.star.drawing.RectangleShape" ] = &ShapeExport::WriteRectangleShape;
899 shape_converters[ "com.sun.star.drawing.TextShape" ] = &ShapeExport::WriteTextShape;
900 shape_converters[ "com.sun.star.presentation.DateTimeShape" ] = &ShapeExport::WriteTextShape;
901 shape_converters[ "com.sun.star.presentation.FooterShape" ] = &ShapeExport::WriteTextShape;
902 shape_converters[ "com.sun.star.presentation.HeaderShape" ] = &ShapeExport::WriteTextShape;
903 shape_converters[ "com.sun.star.presentation.NotesShape" ] = &ShapeExport::WriteTextShape;
904 shape_converters[ "com.sun.star.presentation.OutlinerShape" ] = &ShapeExport::WriteTextShape;
905 shape_converters[ "com.sun.star.presentation.SlideNumberShape" ] = &ShapeExport::WriteTextShape;
906 shape_converters[ "com.sun.star.presentation.TitleTextShape" ] = &ShapeExport::WriteTextShape;
907 shape_map_inited = true;
909 return shape_converters;
912 ShapeExport& ShapeExport::WriteShape( Reference< XShape > xShape )
914 OUString sShapeType = xShape->getShapeType();
915 DBG( printf( "write shape: %s\n", USS( sShapeType ) ) );
916 NameToConvertMapType::const_iterator aConverter = lcl_GetConverters().find( USS( sShapeType ) );
917 if( aConverter == lcl_GetConverters().end() )
919 DBG( printf( "unknown shape\n" ) );
920 return WriteUnknownShape( xShape );
922 (this->*(aConverter->second))( xShape );
924 return *this;
927 ShapeExport& ShapeExport::WriteTextBox( Reference< XShape > xShape )
929 if( NonEmptyText( xShape ) )
931 FSHelperPtr pFS = GetFS();
933 pFS->startElementNS( mnXmlNamespace, XML_txBody, FSEND );
934 WriteText( xShape );
935 pFS->endElementNS( mnXmlNamespace, XML_txBody );
938 return *this;
941 ShapeExport& ShapeExport::WriteTextShape( Reference< XShape > xShape )
943 FSHelperPtr pFS = GetFS();
945 pFS->startElementNS( mnXmlNamespace, XML_sp, FSEND );
947 // non visual shape properties
948 pFS->startElementNS( mnXmlNamespace, XML_nvSpPr, FSEND );
949 WriteNonVisualDrawingProperties( xShape, IDS( TextShape ) );
950 pFS->singleElementNS( mnXmlNamespace, XML_cNvSpPr, XML_txBox, "1", FSEND );
951 WriteNonVisualProperties( xShape );
952 pFS->endElementNS( mnXmlNamespace, XML_nvSpPr );
954 // visual shape properties
955 pFS->startElementNS( mnXmlNamespace, XML_spPr, FSEND );
956 WriteShapeTransformation( xShape );
957 WritePresetShape( "rect" );
958 WriteBlipFill( Reference< XPropertySet >(xShape, UNO_QUERY ), S( "GraphicURL" ) );
959 pFS->endElementNS( mnXmlNamespace, XML_spPr );
961 WriteTextBox( xShape );
963 pFS->endElementNS( mnXmlNamespace, XML_sp );
965 return *this;
968 ShapeExport& ShapeExport::WriteUnknownShape( Reference< XShape > )
970 // Override this method to do something useful.
971 return *this;
974 size_t ShapeExport::ShapeHash::operator()( const ::com::sun::star::uno::Reference < ::com::sun::star::drawing::XShape > rXShape ) const
976 return maHashFunction( USS( rXShape->getShapeType() ) );
979 sal_Int32 ShapeExport::GetNewShapeID( const Reference< XShape > rXShape )
981 sal_Int32 nID = GetFB()->GetUniqueId();
983 maShapeMap[ rXShape ] = nID;
985 return nID;
988 sal_Int32 ShapeExport::GetShapeID( const Reference< XShape > rXShape )
990 ShapeHashMap::const_iterator aIter = maShapeMap.find( rXShape );
992 if( aIter == maShapeMap.end() )
993 return -1;
995 return aIter->second;