Update ooo320-m1
[ooovba.git] / writerfilter / source / doctok / DffImpl.cxx
blobea5dcc36cd840012569c0cfbf5fe6b4da649b83c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DffImpl.cxx,v $
10 * $Revision: 1.15 $
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 "resources.hxx"
32 #include "WW8DocumentImpl.hxx"
34 namespace writerfilter {
35 namespace doctok
38 class ShapeTypeToString
40 typedef boost::shared_ptr<ShapeTypeToString> Pointer_t;
42 static Pointer_t pInstance;
44 typedef map<sal_uInt32, string> Map_t;
45 Map_t mMap;
47 protected:
48 ShapeTypeToString();
50 public:
51 static Pointer_t Instance()
53 if (pInstance == NULL)
54 pInstance = Pointer_t(new ShapeTypeToString());
56 return pInstance;
59 string operator()(sal_uInt32 nShapeType)
61 return mMap[nShapeType];
65 ShapeTypeToString::Pointer_t ShapeTypeToString::pInstance;
67 ShapeTypeToString::ShapeTypeToString()
69 mMap[0]="NotPrimitive";
70 mMap[1]="Rectangle";
71 mMap[2]="RoundRectangle";
72 mMap[3]="Ellipse";
73 mMap[4]="Diamond";
74 mMap[5]="IsocelesTriangle";
75 mMap[6]="RightTriangle";
76 mMap[7]="Parallelogram";
77 mMap[8]="Trapezoid";
78 mMap[9]="Hexagon";
79 mMap[10]="Octagon";
80 mMap[11]="Plus";
81 mMap[12]="Star";
82 mMap[13]="Arrow";
83 mMap[14]="ThickArrow";
84 mMap[15]="HomePlate";
85 mMap[16]="Cube";
86 mMap[17]="Balloon";
87 mMap[18]="Seal";
88 mMap[19]="Arc";
89 mMap[20]="Line";
90 mMap[21]="Plaque";
91 mMap[22]="Can";
92 mMap[23]="Donut";
93 mMap[24]="TextSimple";
94 mMap[25]="TextOctagon";
95 mMap[26]="TextHexagon";
96 mMap[27]="TextCurve";
97 mMap[28]="TextWave";
98 mMap[29]="TextRing";
99 mMap[30]="TextOnCurve";
100 mMap[31]="TextOnRing";
101 mMap[32]="StraightConnector1";
102 mMap[33]="BentConnector2";
103 mMap[34]="BentConnector3";
104 mMap[35]="BentConnector4";
105 mMap[36]="BentConnector5";
106 mMap[37]="CurvedConnector2";
107 mMap[38]="CurvedConnector3";
108 mMap[39]="CurvedConnector4";
109 mMap[40]="CurvedConnector5";
110 mMap[41]="Callout1";
111 mMap[42]="Callout2";
112 mMap[43]="Callout3";
113 mMap[44]="AccentCallout1";
114 mMap[45]="AccentCallout2";
115 mMap[46]="AccentCallout3";
116 mMap[47]="BorderCallout1";
117 mMap[48]="BorderCallout2";
118 mMap[49]="BorderCallout3";
119 mMap[50]="AccentBorderCallout1";
120 mMap[51]="AccentBorderCallout2";
121 mMap[52]="AccentBorderCallout3";
122 mMap[53]="Ribbon";
123 mMap[54]="Ribbon2";
124 mMap[55]="Chevron";
125 mMap[56]="Pentagon";
126 mMap[57]="NoSmoking";
127 mMap[58]="Seal8";
128 mMap[59]="Seal16";
129 mMap[60]="Seal32";
130 mMap[61]="WedgeRectCallout";
131 mMap[62]="WedgeRRectCallout";
132 mMap[63]="WedgeEllipseCallout";
133 mMap[64]="Wave";
134 mMap[65]="FoldedCorner";
135 mMap[66]="LeftArrow";
136 mMap[67]="DownArrow";
137 mMap[68]="UpArrow";
138 mMap[69]="LeftRightArrow";
139 mMap[70]="UpDownArrow";
140 mMap[71]="IrregularSeal1";
141 mMap[72]="IrregularSeal2";
142 mMap[73]="LightningBolt";
143 mMap[74]="Heart";
144 mMap[75]="PictureFrame";
145 mMap[76]="QuadArrow";
146 mMap[77]="LeftArrowCallout";
147 mMap[78]="RightArrowCallout";
148 mMap[79]="UpArrowCallout";
149 mMap[80]="DownArrowCallout";
150 mMap[81]="LeftRightArrowCallout";
151 mMap[82]="UpDownArrowCallout";
152 mMap[83]="QuadArrowCallout";
153 mMap[84]="Bevel";
154 mMap[85]="LeftBracket";
155 mMap[86]="RightBracket";
156 mMap[87]="LeftBrace";
157 mMap[88]="RightBrace";
158 mMap[89]="LeftUpArrow";
159 mMap[90]="BentUpArrow";
160 mMap[91]="BentArrow";
161 mMap[92]="Seal24";
162 mMap[93]="StripedRightArrow";
163 mMap[94]="NotchedRightArrow";
164 mMap[95]="BlockArc";
165 mMap[96]="SmileyFace";
166 mMap[97]="VerticalScroll";
167 mMap[98]="HorizontalScroll";
168 mMap[99]="CircularArrow";
169 mMap[100]="NotchedCircularArrow";
170 mMap[101]="UturnArrow";
171 mMap[102]="CurvedRightArrow";
172 mMap[103]="CurvedLeftArrow";
173 mMap[104]="CurvedUpArrow";
174 mMap[105]="CurvedDownArrow";
175 mMap[106]="CloudCallout";
176 mMap[107]="EllipseRibbon";
177 mMap[108]="EllipseRibbon2";
178 mMap[109]="FlowChartProcess";
179 mMap[110]="FlowChartDecision";
180 mMap[111]="FlowChartInputOutput";
181 mMap[112]="FlowChartPredefinedProcess";
182 mMap[113]="FlowChartInternalStorage";
183 mMap[114]="FlowChartDocument";
184 mMap[115]="FlowChartMultidocument";
185 mMap[116]="FlowChartTerminator";
186 mMap[117]="FlowChartPreparation";
187 mMap[118]="FlowChartManualInput";
188 mMap[119]="FlowChartManualOperation";
189 mMap[120]="FlowChartConnector";
190 mMap[121]="FlowChartPunchedCard";
191 mMap[122]="FlowChartPunchedTape";
192 mMap[123]="FlowChartSummingJunction";
193 mMap[124]="FlowChartOr";
194 mMap[125]="FlowChartCollate";
195 mMap[126]="FlowChartSort";
196 mMap[127]="FlowChartExtract";
197 mMap[128]="FlowChartMerge";
198 mMap[129]="FlowChartOfflineStorage";
199 mMap[130]="FlowChartOnlineStorage";
200 mMap[131]="FlowChartMagneticTape";
201 mMap[132]="FlowChartMagneticDisk";
202 mMap[133]="FlowChartMagneticDrum";
203 mMap[134]="FlowChartDisplay";
204 mMap[135]="FlowChartDelay";
205 mMap[136]="TextPlainText";
206 mMap[137]="TextStop";
207 mMap[138]="TextTriangle";
208 mMap[139]="TextTriangleInverted";
209 mMap[140]="TextChevron";
210 mMap[141]="TextChevronInverted";
211 mMap[142]="TextRingInside";
212 mMap[143]="TextRingOutside";
213 mMap[144]="TextArchUpCurve";
214 mMap[145]="TextArchDownCurve";
215 mMap[146]="TextCircleCurve";
216 mMap[147]="TextButtonCurve";
217 mMap[148]="TextArchUpPour";
218 mMap[149]="TextArchDownPour";
219 mMap[150]="TextCirclePour";
220 mMap[151]="TextButtonPour";
221 mMap[152]="TextCurveUp";
222 mMap[153]="TextCurveDown";
223 mMap[154]="TextCascadeUp";
224 mMap[155]="TextCascadeDown";
225 mMap[156]="TextWave1";
226 mMap[157]="TextWave2";
227 mMap[158]="TextWave3";
228 mMap[159]="TextWave4";
229 mMap[160]="TextInflate";
230 mMap[161]="TextDeflate";
231 mMap[162]="TextInflateBottom";
232 mMap[163]="TextDeflateBottom";
233 mMap[164]="TextInflateTop";
234 mMap[165]="TextDeflateTop";
235 mMap[166]="TextDeflateInflate";
236 mMap[167]="TextDeflateInflateDeflate";
237 mMap[168]="TextFadeRight";
238 mMap[169]="TextFadeLeft";
239 mMap[170]="TextFadeUp";
240 mMap[171]="TextFadeDown";
241 mMap[172]="TextSlantUp";
242 mMap[173]="TextSlantDown";
243 mMap[174]="TextCanUp";
244 mMap[175]="TextCanDown";
245 mMap[176]="FlowChartAlternateProcess";
246 mMap[177]="FlowChartOffpageConnector";
247 mMap[178]="Callout90";
248 mMap[179]="AccentCallout90";
249 mMap[180]="BorderCallout90";
250 mMap[181]="AccentBorderCallout90";
251 mMap[182]="LeftRightUpArrow";
252 mMap[183]="Sun";
253 mMap[184]="Moon";
254 mMap[185]="BracketPair";
255 mMap[186]="BracePair";
256 mMap[187]="Seal4";
257 mMap[188]="DoubleWave";
258 mMap[189]="ActionButtonBlank";
259 mMap[190]="ActionButtonHome";
260 mMap[191]="ActionButtonHelp";
261 mMap[192]="ActionButtonInformation";
262 mMap[193]="ActionButtonForwardNext";
263 mMap[194]="ActionButtonBackPrevious";
264 mMap[195]="ActionButtonEnd";
265 mMap[196]="ActionButtonBeginning";
266 mMap[197]="ActionButtonReturn";
267 mMap[198]="ActionButtonDocument";
268 mMap[199]="ActionButtonSound";
269 mMap[200]="ActionButtonMovie";
270 mMap[201]="HostControl";
271 mMap[202]="TextBox";
274 // DffOPT
276 sal_uInt32 DffOPT::get_property_count()
278 return getInstance();
281 writerfilter::Reference<Properties>::Pointer_t
282 DffOPT::get_property(sal_uInt32 nPos)
284 WW8FOPTE * pTmp = new WW8FOPTE(this, 0x8 + nPos * WW8FOPTE::getSize());
285 pTmp->setIndex(nPos);
287 return writerfilter::Reference<Properties>::Pointer_t(pTmp);
290 sal_uInt32 DffOPT::get_extraoffset_count()
292 return get_property_count();
295 sal_uInt32 DffOPT::get_extraoffset(sal_uInt32 pos)
297 sal_uInt32 nResult;
298 sal_uInt32 nCount = get_property_count();
300 if (pos < nCount)
302 nResult = 0x8 + nCount * WW8FOPTE::getSize();
304 for (sal_uInt32 n = 0; n < pos; ++n)
306 WW8FOPTE aFOPTE(this, 0x8 + n * WW8FOPTE::getSize());
308 if (aFOPTE.get_fComplex())
310 sal_uInt32 nValue = aFOPTE.get_op();
311 nResult += nValue;
315 else
316 nResult = getCount();
318 return nResult;
321 //DffDGG
323 sal_uInt32 DffDGG::get_fidcl_count()
325 return (getCount() - 0x18) / WW8FIDCL::getSize();
328 writerfilter::Reference<Properties>::Pointer_t
329 DffDGG::get_fidcl(sal_uInt32 pos)
331 return writerfilter::Reference<Properties>::Pointer_t
332 (new WW8FIDCL(this, 0x18 + pos * WW8FIDCL::getSize()));
336 // DffBSE
338 rtl::OUString DffBSE::get_blipname()
340 rtl::OUString sResult;
341 WW8FBSE aFBSE(this, 0x8);
343 if (aFBSE.get_cbName() > 0)
344 sResult = getString(0x24, aFBSE.get_cbName());
346 return sResult;
349 writerfilter::Reference<Properties>::Pointer_t
350 DffBSE::get_blip()
352 writerfilter::Reference<Properties>::Pointer_t pResult;
354 WW8FBSE aFBSE(this, 8);
355 sal_uInt32 nOffset = 8 + WW8FBSE::getSize() + aFBSE.get_cbName();
357 if (nOffset + 8 < getCount())
359 WW8StructBase aTmp(this, nOffset, 0x8);
361 sal_uInt32 nCount = getCount() - 8;
363 if (aTmp.getU32(0x4) - 8 < nCount)
364 nCount = aTmp.getU32(0x4) - 8;
366 if (nCount)
368 DffRecord * pRecord = createDffRecord(this, nOffset);
370 pResult = writerfilter::Reference<Properties>::Pointer_t(pRecord);
373 else
375 nOffset = sal::static_int_cast<sal_Int32>(aFBSE.get_foDelay());
376 if (! (nOffset & 1 << 31) && nOffset > 0 && getDocument() != NULL)
378 WW8StructBase aStructBase(*getDocument()->getDocStream(),
379 nOffset, 0x8);
381 DffRecord * pRecord =
382 createDffRecord(*getDocument()->getDocStream(),
383 aFBSE.get_foDelay());
385 pResult = writerfilter::Reference<Properties>::Pointer_t(pRecord);
389 return pResult;
392 #if 0
393 WW8BinaryObjReference::Pointer_t DffBSE::get_binary()
395 WW8BinaryObjReference::Pointer_t pResult;
397 if (getCount() > 0x45)
398 pResult = WW8BinaryObjReference::Pointer_t
399 (new WW8BinaryObjReference(this, 0x45,
400 getCount() - 0x45));
401 else
403 WW8FBSE aFBSE(this, 0x8);
405 sal_Int32 nOffset = sal::static_int_cast<sal_Int32>(aFBSE.get_foDelay());
406 if (nOffset > 0 && getDocument() != NULL)
408 WW8StructBase aStructBase(*getDocument()->getDocStream(),
409 nOffset, 0x8);
411 sal_uInt32 nCount = aStructBase.getU32(0x4) - 0x11;
413 pResult = WW8BinaryObjReference::Pointer_t
414 (new WW8BinaryObjReference(*getDocument()->getDocStream(),
415 aFBSE.get_foDelay() + 0x19, nCount));
419 return pResult;
421 #endif
423 // WW8FOPTE
424 void WW8FOPTE::resolveNoAuto(Properties & rHandler)
426 sal_uInt16 nId = get_pid() + 1;
427 sal_uInt32 nOp = get_op();
428 sal_uInt32 nMask = 2;
430 while (isBooleanDffOpt(nId))
432 WW8Value::Pointer_t pVal = createValue(getDffOptName(nId));
433 rHandler.attribute(NS_rtf::LN_shpname, *pVal);
435 pVal = createValue((nOp & nMask) != 0);
436 rHandler.attribute(NS_rtf::LN_shpvalue, *pVal);
438 --nId;
439 nMask = nMask << 1;
443 // DffFSP
445 rtl::OUString DffFSP::get_shptypename()
447 string aName = (*ShapeTypeToString::Instance())(get_shptype());
449 return rtl::OUString::createFromAscii(aName.c_str());
452 // DffSpContainer
454 writerfilter::Reference<Properties>::Pointer_t
455 DffSpContainer::get_blip()
457 writerfilter::Reference<Properties>::Pointer_t pResult;
459 if (getShapeType() == 75)
461 sal_uInt32 nBid = getShapeBid();
463 if (getDocument() != NULL && nBid > 0)
464 pResult = getDocument()->getBlip(nBid);
467 return pResult;
470 writerfilter::Reference<Stream>::Pointer_t
471 DffSpContainer::get_shptxt()
473 writerfilter::Reference<Stream>::Pointer_t pResult;
475 if (getShapeType() == 202)
477 sal_uInt32 nShpId = getShapeId();
479 if (getDocument() != NULL)
480 pResult = getDocument()->getTextboxText(nShpId);
483 return pResult;
486 // DffUDefProp
488 void DffUDefProp::resolveNoAuto(Properties & rHandler)
490 sal_uInt32 nOffset = 0x8;
491 sal_uInt32 nCount = getCount();
493 while (nOffset + 6 <= nCount)
495 sal_uInt16 nPid = getU16(nOffset);
496 sal_uInt32 nValue = getU32(nOffset + 2);
498 sal_uInt32 nAttrid = 0;
499 switch (nPid)
501 case 0x38f: nAttrid = NS_rtf::LN_XAlign; break;
502 case 0x390: nAttrid = NS_rtf::LN_XRelTo; break;
503 case 0x391: nAttrid = NS_rtf::LN_YAlign; break;
504 case 0x392: nAttrid = NS_rtf::LN_YRelTo; break;
505 case 0x3bf: nAttrid = NS_rtf::LN_LayoutInTableCell; break;
506 case 0x53f: nAttrid = NS_rtf::LN_Inline; break;
507 default:
508 break;
511 if (nAttrid != 0)
513 WW8Value::Pointer_t pVal = createValue(nValue);
514 rHandler.attribute(nAttrid, *pVal);
517 nOffset += 6;