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