1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef OOX_DUMP_BIFFDUMPER_HXX
25 #define OOX_DUMP_BIFFDUMPER_HXX
26
27 #include "oox/dump/dumperbase.hxx"
28 #include "oox/dump/dffdumper.hxx"
29 #include "oox/dump/oledumper.hxx"
30 #include "oox/xls/richstring.hxx"
31 #include "oox/xls/biffinputstream.hxx"
32
33 #if OOX_INCLUDE_DUMPER
34
35 namespace oox { namespace xls {
36 class BiffInputStream;
37 class FontPortionModelList;
38 struct FunctionInfo;
39 class FunctionProvider;
40 } }
41
42 namespace oox {
43 namespace dump {
44 namespace biff {
45
46 typedef ::boost::shared_ptr< ::oox::xls::BiffInputStream > BiffInputStreamRef;
47
48 // ============================================================================
49 // ============================================================================
50
51 class BiffDffStreamObject : public DffStreamObject
52 {
53 public:
54 explicit BiffDffStreamObject(
55 const OutputObjectBase& rParent,
56 const BinaryInputStreamRef& rxStrm );
57
58 protected:
59 virtual void implDumpClientAnchor();
60 };
61
62 // ============================================================================
63
64 class BiffCtlsStreamObject : public InputObjectBase
65 {
66 public:
67 explicit BiffCtlsStreamObject( const OutputObjectBase& rParent, const BinaryInputStreamRef& rxStrm );
68
69 void dumpControl( sal_uInt32 nStartPos, sal_uInt32 nLength );
70
71 protected:
72 virtual void implDump();
73
74 private:
75 sal_uInt32 mnStartPos;
76 sal_uInt32 mnLength;
77 };
78
79 // ============================================================================
80 // ============================================================================
81
82 class BiffConfig : public Config
83 {
84 public:
85 explicit BiffConfig( const Config& rParent, ::oox::xls::BiffType eBiff );
86
87 protected:
88 virtual bool implIsValid() const;
89 virtual NameListRef implGetNameList( const ::rtl::OUString& rKey ) const;
90
91 private:
92 ::oox::xls::BiffType meBiff;
93 };
94
95 // ============================================================================
96
97 class BiffSharedData : public Base
98 {
99 public:
100 explicit BiffSharedData( ::oox::xls::BiffType eBiff );
101
102 void initializePerSheet();
103
getBiff() const104 inline ::oox::xls::BiffType getBiff() const { return meBiff; }
105
getTextEncoding() const106 inline rtl_TextEncoding getTextEncoding() const { return meTextEnc; }
107 void setTextEncoding( rtl_TextEncoding eTextEnc );
108
109 sal_uInt16 getFontCount() const;
110 rtl_TextEncoding getFontEncoding( sal_uInt16 nFontId ) const;
111 void appendFontEncoding( rtl_TextEncoding eFontEnc );
112
113 sal_uInt16 getXfCount() const;
114 rtl_TextEncoding getXfEncoding( sal_uInt16 nXfId ) const;
115 void appendXfFontId( sal_uInt16 nFontId );
116
117 protected:
118 virtual bool implIsValid() const;
119
120 private:
121 typedef ::std::vector< rtl_TextEncoding > TextEncVec;
122 typedef ::std::vector< sal_uInt16 > FontIdVec;
123
124 TextEncVec maFontEncs;
125 FontIdVec maXfFontIds;
126 ::oox::xls::BiffType meBiff;
127 rtl_TextEncoding meTextEnc;
128 };
129
130 // ============================================================================
131
132 class BiffObjectBase : public RecordObjectBase
133 {
134 public:
getBiffData() const135 inline BiffSharedData& getBiffData() const { return *mxBiffData; }
getBiffStream() const136 inline ::oox::xls::BiffInputStream& getBiffStream() const { return *mxBiffStrm; }
getBiff() const137 inline ::oox::xls::BiffType getBiff() const { return mxBiffData->getBiff(); }
138
139 protected:
BiffObjectBase()140 inline explicit BiffObjectBase() {}
141 virtual ~BiffObjectBase();
142
143 using InputObjectBase::construct;
144 void construct( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, ::oox::xls::BiffType eBiff, const ::rtl::OUString& rSysFileName );
145 void construct( const BiffObjectBase& rParent );
146
147 virtual bool implIsValid() const;
148 virtual bool implStartRecord( BinaryInputStream& rBaseStrm, sal_Int64& ornRecPos, sal_Int64& ornRecId, sal_Int64& ornRecSize );
149
getLastRecId() const150 inline sal_uInt16 getLastRecId() const { return mnLastRecId; }
151 ::rtl::OUString getErrorName( sal_uInt8 nErrCode ) const;
152
153 // ------------------------------------------------------------------------
154
155 sal_Int32 readCol( bool bCol16Bit );
156 sal_Int32 readRow( bool bRow32Bit );
157 void readAddress( Address& orAddress, bool bCol16Bit = true, bool bRow32Bit = false );
158 void readRange( Range& orRange, bool bCol16Bit = true, bool bRow32Bit = false );
159 void readRangeList( RangeList& orRanges, bool bCol16Bit = true, bool bRow32Bit = false );
160
161 // ------------------------------------------------------------------------
162
163 void writeBooleanItem( const String& rName, sal_uInt8 nBool );
164 void writeErrorCodeItem( const String& rName, sal_uInt8 nErrCode );
165
166 void writeFontPortions( const ::oox::xls::FontPortionModelList& rPortions );
167
168 template< typename Type >
169 void writeRectItem( const String& rName,
170 Type nLeft, Type nTop, Type nWidth, Type nHeight,
171 const NameListWrapper& rListWrp = NO_LIST,
172 FormatType eFmtType = FORMATTYPE_DEC );
173
174 // ------------------------------------------------------------------------
175
176 ::rtl::OUString dumpByteString(
177 const String& rName,
178 ::oox::xls::BiffStringFlags nFlags = ::oox::xls::BIFF_STR_DEFAULT,
179 rtl_TextEncoding eDefaultTextEnc = RTL_TEXTENCODING_DONTKNOW );
180 ::rtl::OUString dumpUniString(
181 const String& rName,
182 ::oox::xls::BiffStringFlags nFlags = ::oox::xls::BIFF_STR_DEFAULT );
183 ::rtl::OUString dumpString(
184 const String& rName,
185 ::oox::xls::BiffStringFlags nByteFlags = ::oox::xls::BIFF_STR_DEFAULT,
186 ::oox::xls::BiffStringFlags nUniFlags = ::oox::xls::BIFF_STR_DEFAULT,
187 rtl_TextEncoding eDefaultTextEnc = RTL_TEXTENCODING_DONTKNOW );
188
189 ::rtl::OUString dumpSegmentedUniString( const String& rName );
190 void dumpSegmentedUniStringArray( const String& rName );
191
192 sal_uInt8 dumpBoolean( const String& rName = EMPTY_STRING );
193 sal_uInt8 dumpErrorCode( const String& rName = EMPTY_STRING );
194
195 rtl_TextEncoding dumpCodePage( const String& rName = EMPTY_STRING );
196 void dumpFormulaResult( const String& rName = EMPTY_STRING );
197
198 sal_Int32 dumpColIndex( const String& rName = EMPTY_STRING, bool bCol16Bit = true );
199 sal_Int32 dumpRowIndex( const String& rName = EMPTY_STRING, bool bRow32Bit = false );
200 sal_Int32 dumpColRange( const String& rName = EMPTY_STRING, bool bCol16Bit = true );
201 sal_Int32 dumpRowRange( const String& rName = EMPTY_STRING, bool bRow32Bit = false );
202
203 Address dumpAddress( const String& rName = EMPTY_STRING, bool bCol16Bit = true, bool bRow32Bit = false );
204 Range dumpRange( const String& rName = EMPTY_STRING, bool bCol16Bit = true, bool bRow32Bit = false );
205 void dumpRangeList( const String& rName = EMPTY_STRING, bool bCol16Bit = true, bool bRow32Bit = false );
206
207 void dumpConstArrayHeader( sal_uInt32& rnCols, sal_uInt32& rnRows );
208 ::rtl::OUString dumpConstValue( sal_Unicode cStrQuote = OOX_DUMP_STRQUOTE );
209
210 template< typename Type >
211 void dumpRect( const String& rName,
212 const NameListWrapper& rListWrp = NO_LIST,
213 FormatType eFmtType = FORMATTYPE_DEC );
214 template< typename Type >
215 void dumpRectWithGaps( const String& rName, sal_Int32 nGap,
216 const NameListWrapper& rListWrp = NO_LIST,
217 FormatType eFmtType = FORMATTYPE_DEC );
218
219 sal_uInt16 dumpRepeatedRecId();
220 void dumpFrHeader( bool bWithFlags, bool bWithRange );
221
222 void dumpDffClientRect();
223 void dumpEmbeddedDff();
224 void dumpControl();
225
226 private:
227 typedef ::boost::shared_ptr< BiffSharedData > BiffSharedDataRef;
228 typedef ::boost::shared_ptr< BiffDffStreamObject > BiffDffStreamObjRef;
229 typedef ::boost::shared_ptr< BiffCtlsStreamObject > BiffCtlsStrmObjRef;
230
231 BiffSharedDataRef mxBiffData;
232 BiffInputStreamRef mxBiffStrm;
233 BiffDffStreamObjRef mxDffObj;
234 BiffCtlsStrmObjRef mxCtlsObj;
235 NameListRef mxErrCodes;
236 NameListRef mxConstType;
237 NameListRef mxResultType;
238 sal_uInt16 mnLastRecId;
239 bool mbMergeContRec;
240 };
241
242 // ----------------------------------------------------------------------------
243
244 template< typename Type >
writeRectItem(const String & rName,Type nLeft,Type nTop,Type nWidth,Type nHeight,const NameListWrapper & rListWrp,FormatType eFmtType)245 void BiffObjectBase::writeRectItem( const String& rName,
246 Type nLeft, Type nTop, Type nWidth, Type nHeight,
247 const NameListWrapper& rListWrp, FormatType eFmtType )
248 {
249 MultiItemsGuard aMultiGuard( mxOut );
250 writeEmptyItem( rName );
251 writeValueItem( "x-pos", nLeft, eFmtType, rListWrp );
252 writeValueItem( "y-pos", nTop, eFmtType, rListWrp );
253 writeValueItem( "x-size", nWidth, eFmtType, rListWrp );
254 writeValueItem( "y-size", nHeight, eFmtType, rListWrp );
255 }
256
257 template< typename Type >
dumpRect(const String & rName,const NameListWrapper & rListWrp,FormatType eFmtType)258 void BiffObjectBase::dumpRect( const String& rName,
259 const NameListWrapper& rListWrp, FormatType eFmtType )
260 {
261 Type nLeft, nTop, nWidth, nHeight;
262 *mxBiffStrm >> nLeft >> nTop >> nWidth >> nHeight;
263 writeRectItem( rName, nLeft, nTop, nWidth, nHeight, rListWrp, eFmtType );
264 }
265
266 template< typename Type >
dumpRectWithGaps(const String & rName,sal_Int32 nGap,const NameListWrapper & rListWrp,FormatType eFmtType)267 void BiffObjectBase::dumpRectWithGaps( const String& rName, sal_Int32 nGap,
268 const NameListWrapper& rListWrp, FormatType eFmtType )
269 {
270 Type nLeft, nTop, nWidth, nHeight;
271 *mxBiffStrm >> nLeft;
272 mxBiffStrm->skip( nGap );
273 *mxBiffStrm >> nTop;
274 mxBiffStrm->skip( nGap );
275 *mxBiffStrm >> nWidth;
276 mxBiffStrm->skip( nGap );
277 *mxBiffStrm >> nHeight;
278 mxBiffStrm->skip( nGap );
279 writeRectItem( rName, nLeft, nTop, nWidth, nHeight, rListWrp, eFmtType );
280 }
281
282 // ============================================================================
283 // ============================================================================
284
285 class FormulaObject : public BiffObjectBase
286 {
287 public:
288 explicit FormulaObject( const BiffObjectBase& rParent );
289 virtual ~FormulaObject();
290
291 sal_uInt16 readFormulaSize();
292 sal_uInt16 dumpFormulaSize( const String& rName = EMPTY_STRING );
293
294 void dumpCellFormula( const String& rName, sal_uInt16 nSize );
295 void dumpCellFormula( const String& rName = EMPTY_STRING );
296 void dumpNameFormula( const String& rName, sal_uInt16 nSize );
297 void dumpNameFormula( const String& rName = EMPTY_STRING );
298
299 protected:
300 virtual void implDump();
301
302 private:
303 void constructFmlaObj();
304
305 void dumpFormula( const String& rName, sal_uInt16 nSize, bool bNameMode );
306 void dumpFormula( const String& rName, bool bNameMode );
307
308 TokenAddress createTokenAddress( sal_uInt16 nCol, sal_uInt16 nRow, bool bRelC, bool bRelR, bool bNameMode ) const;
309 ::rtl::OUString createRef( const ::rtl::OUString& rData ) const;
310 ::rtl::OUString createName( sal_uInt16 nNameIdx ) const;
311 ::rtl::OUString createPlaceHolder( size_t nIdx ) const;
312 ::rtl::OUString createPlaceHolder() const;
313
314 sal_uInt16 readFuncId();
315 ::rtl::OUString writeFuncIdItem( sal_uInt16 nFuncId, const ::oox::xls::FunctionInfo** oppFuncInfo = 0 );
316
317 sal_uInt16 dumpTokenCol( const String& rName, bool& rbRelC, bool& rbRelR );
318 sal_uInt16 dumpTokenRow( const String& rName, bool& rbRelC, bool& rbRelR );
319 TokenAddress dumpTokenAddress( bool bNameMode );
320 TokenRange dumpTokenRange( bool bNameMode );
321
322 sal_Int16 readTokenRefIdx();
323 ::rtl::OUString dumpTokenRefIdx();
324 ::rtl::OUString dumpTokenRefTabIdxs();
325
326 void dumpIntToken();
327 void dumpDoubleToken();
328 void dumpStringToken();
329 void dumpBoolToken();
330 void dumpErrorToken();
331 void dumpMissArgToken();
332
333 void dumpArrayToken( const ::rtl::OUString& rTokClass );
334 void dumpNameToken( const ::rtl::OUString& rTokClass );
335 void dumpNameXToken( const ::rtl::OUString& rTokClass );
336 void dumpRefToken( const ::rtl::OUString& rTokClass, bool bNameMode );
337 void dumpAreaToken( const ::rtl::OUString& rTokClass, bool bNameMode );
338 void dumpRefErrToken( const ::rtl::OUString& rTokClass, bool bArea );
339 void dumpRef3dToken( const ::rtl::OUString& rTokClass, bool bNameMode );
340 void dumpArea3dToken( const ::rtl::OUString& rTokClass, bool bNameMode );
341 void dumpRefErr3dToken( const ::rtl::OUString& rTokClass, bool bArea );
342 void dumpMemFuncToken( const ::rtl::OUString& rTokClass );
343 void dumpMemAreaToken( const ::rtl::OUString& rTokClass, bool bAddData );
344
345 void dumpExpToken( const String& rName );
346 void dumpUnaryOpToken( const String& rLOp, const String& rROp );
347 void dumpBinaryOpToken( const String& rOp );
348 void dumpFuncToken( const ::rtl::OUString& rTokClass );
349 void dumpFuncVarToken( const ::rtl::OUString& rTokClass );
350 void dumpCmdToken( const ::rtl::OUString& rTokClass );
351
352 void dumpSheetToken();
353 void dumpEndSheetToken();
354 bool dumpAttrToken();
355
356 bool dumpNlrToken();
357 void dumpNlrErrToken();
358 void dumpNlrColRowToken( const ::rtl::OUString& rTokClass, bool bAddData );
359 void dumpNlrRangeToken( const ::rtl::OUString& rTokClass, bool bAddData );
360 void dumpNlrRangeErrToken();
361
362 void dumpAddTokenData();
363 void dumpAddDataNlr( size_t nIdx );
364 void dumpAddDataArray( size_t nIdx );
365 void dumpAddDataMemArea( size_t nIdx );
366
367 private:
368 enum AddDataType { ADDDATA_NLR, ADDDATA_ARRAY, ADDDATA_MEMAREA };
369
370 typedef ::boost::shared_ptr< FormulaStack > FormulaStackRef;
371 typedef ::boost::shared_ptr< ::oox::xls::FunctionProvider > FuncProvRef;
372 typedef ::std::vector< AddDataType > AddDataTypeVec;
373
374 NameListRef mxTokens;
375 NameListRef mxClasses;
376 NameListRef mxRelFlags;
377 NameListRef mxNlrTypes;
378 NameListRef mxAttrTypes;
379 NameListRef mxSpTypes;
380 sal_Int32 mnColCount;
381 sal_Int32 mnRowCount;
382
383 FormulaStackRef mxStack;
384 FuncProvRef mxFuncProv;
385 AddDataTypeVec maAddData;
386 ::rtl::OUString maRefPrefix;
387 ::rtl::OUString maName;
388 sal_uInt16 mnSize;
389 bool mbNameMode;
390 };
391
392 // ============================================================================
393 // ============================================================================
394
395 class RecordStreamObject : public BiffObjectBase
396 {
397 protected:
RecordStreamObject()398 inline explicit RecordStreamObject() {}
399 virtual ~RecordStreamObject();
400
401 using BiffObjectBase::construct;
402 void construct( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, ::oox::xls::BiffType eBiff, const ::rtl::OUString& rSysFileName );
403
404 virtual bool implIsValid() const;
405
getFormulaDumper() const406 inline FormulaObject& getFormulaDumper() const { return *mxFmlaObj; }
407
408 private:
409 typedef ::boost::shared_ptr< FormulaObject > FormulaObjectRef;
410 FormulaObjectRef mxFmlaObj;
411 };
412
413 // ============================================================================
414
415 class WorkbookStreamObject : public RecordStreamObject
416 {
417 public:
418 explicit WorkbookStreamObject( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const ::rtl::OUString& rSysFileName );
419 virtual ~WorkbookStreamObject();
420
421 protected:
422 virtual void implDumpRecordBody();
423
424 private:
425 void initializePerSheet();
426
427 ::rtl::OUString createFontName( const ::rtl::OUString& rName, sal_uInt16 nHeight, bool bBold, bool bItalic ) const;
428
429 sal_uInt16 dumpPatternIdx( const String& rName = EMPTY_STRING, bool b16Bit = true );
430 sal_uInt16 dumpColorIdx( const String& rName = EMPTY_STRING, bool b16Bit = true );
431 sal_uInt16 dumpFontIdx( const String& rName = EMPTY_STRING, bool b16Bit = true );
432 sal_uInt16 dumpFormatIdx( const String& rName = EMPTY_STRING );
433 sal_uInt16 dumpXfIdx( const String& rName = EMPTY_STRING, bool bBiff2Style = false );
434
435 template< typename Type >
dumpExtColorType()436 inline Type dumpExtColorType() { return dumpDec< Type >( "color-type", "EXTCOLOR-TYPE" ); }
437 void dumpExtColorValue( sal_uInt32 nColorType );
438 void dumpExtColor( const String& rName = EMPTY_STRING );
439 void dumpExtCfColor( const String& rName = EMPTY_STRING );
440 void dumpExtGradientHead();
441
442 sal_uInt8 dumpFilterColumnOperator( const String& rName );
443
444 ::rtl::OUString dumpPivotString( const String& rName, sal_uInt16 nStrLen );
445 ::rtl::OUString dumpPivotString( const String& rName );
446
447 sal_uInt16 dumpCellHeader( bool bBiff2Style = false );
448 void dumpBoolErr();
449
450 void dumpCfRuleProp();
451 void dumpXfExtProp();
452 void dumpDxfProp();
453 void dumpDxf12Prop();
454 void dumpCfRule12Param( sal_uInt16 nSubType );
455
456 void dumpFontRec();
457 void dumpFormatRec();
458 void dumpXfRec();
459
460 void dumpObjRec();
461 void dumpObjRecBiff3();
462 void dumpObjRecBiff4();
463 void dumpObjRecBiff5();
464 void dumpObjRecBiff8();
465
466 void dumpObjRecLineData();
467 void dumpObjRecFillData();
468 void dumpObjRecRectData();
469 void dumpObjRecTextDataBiff3( sal_uInt16& ornTextLen, sal_uInt16& ornFormatSize );
470 void dumpObjRecTextDataBiff5( sal_uInt16& ornTextLen, sal_uInt16& ornFormatSize, sal_uInt16& ornLinkSize );
471 void dumpObjRecSbsData();
472 void dumpObjRecGboData();
473 void dumpObjRecEdoData();
474 void dumpObjRecRboData();
475 void dumpObjRecCblsData();
476 void dumpObjRecLbsData();
477
478 void dumpObjRecPadding();
479 void dumpObjRecString( const String& rName, sal_uInt16 nTextLen, bool bRepeatLen );
480 void dumpObjRecTextFmt( sal_uInt16 nFormatSize );
481 void dumpObjRecFmlaRaw();
482 void dumpObjRecFmla( const String& rName, sal_uInt16 nFmlaSize );
483 void dumpObjRecPictFmla( sal_uInt16 nFmlaSize );
484
485 typedef ::std::pair< sal_uInt8, ::rtl::OUString > ChFrExtPropInfo;
486
487 void dumpChFrExtProps();
488 ChFrExtPropInfo dumpChFrExtPropHeader();
489
490 private:
491 NameListRef mxColors;
492 NameListRef mxBorderStyles;
493 NameListRef mxFillPatterns;
494 NameListRef mxFontNames;
495 NameListRef mxFormats;
496 sal_uInt16 mnFormatIdx;
497 sal_uInt16 mnPTRowFields;
498 sal_uInt16 mnPTColFields;
499 sal_uInt16 mnPTRowColItemsIdx;
500 bool mbHasCodePage;
501 bool mbHasDff;
502 };
503
504 // ============================================================================
505
506 class PivotCacheStreamObject : public RecordStreamObject
507 {
508 public:
509 explicit PivotCacheStreamObject(
510 const ObjectBase& rParent,
511 const BinaryInputStreamRef& rxStrm,
512 ::oox::xls::BiffType eBiff,
513 const ::rtl::OUString& rSysFileName );
514
515 protected:
516 virtual void implDumpRecordBody();
517 };
518
519 // ============================================================================
520 // ============================================================================
521
522 class RootStorageObject : public OleStorageObject
523 {
524 public:
525 explicit RootStorageObject( const DumperBase& rParent );
526
527 protected:
528 virtual void implDumpStream(
529 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxStrm,
530 const ::rtl::OUString& rStrgPath,
531 const ::rtl::OUString& rStrmName,
532 const ::rtl::OUString& rSysFileName );
533
534 virtual void implDumpStorage(
535 const StorageRef& rxStrg,
536 const ::rtl::OUString& rStrgPath,
537 const ::rtl::OUString& rSysPath );
538
539 virtual void implDumpBaseStream(
540 const BinaryInputStreamRef& rxStrm,
541 const ::rtl::OUString& rSysFileName );
542 };
543
544 // ============================================================================
545 // ============================================================================
546
547 class Dumper : public DumperBase
548 {
549 public:
550 explicit Dumper( const ::oox::core::FilterBase& rFilter );
551
552 explicit Dumper(
553 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
554 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStrm,
555 const ::rtl::OUString& rSysFileName );
556
557 protected:
558 virtual void implDump();
559 };
560
561 // ============================================================================
562 // ============================================================================
563
564 } // namespace biff
565 } // namespace dump
566 } // namespace oox
567
568 #endif
569 #endif
570