xref: /aoo42x/main/oox/source/dump/dffdumper.cxx (revision ca5ec200)
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
10*ca5ec200SAndrew Rist  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist  *
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.
19*ca5ec200SAndrew Rist  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/dump/dffdumper.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #if OOX_INCLUDE_DUMPER
27cdf0e10cSrcweir 
28cdf0e10cSrcweir namespace oox {
29cdf0e10cSrcweir namespace dump {
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // ============================================================================
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using ::rtl::OUString;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // ============================================================================
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace {
38cdf0e10cSrcweir 
39cdf0e10cSrcweir const sal_uInt16 DFF_ID_BSE                 = 0xF007;   /// BLIP store entry.
40cdf0e10cSrcweir const sal_uInt16 DFF_ID_BSTORECONTAINER     = 0xF001;   /// BLIP store container.
41cdf0e10cSrcweir const sal_uInt16 DFF_ID_CHILDANCHOR         = 0xF00F;   /// Child anchor (in groups).
42cdf0e10cSrcweir const sal_uInt16 DFF_ID_CLIENTANCHOR        = 0xF010;   /// Client anchor.
43cdf0e10cSrcweir const sal_uInt16 DFF_ID_DG                  = 0xF008;   /// Drawing.
44cdf0e10cSrcweir const sal_uInt16 DFF_ID_DGG                 = 0xF006;   /// Drawing group.
45cdf0e10cSrcweir const sal_uInt16 DFF_ID_OPT                 = 0xF00B;   /// Property set.
46cdf0e10cSrcweir const sal_uInt16 DFF_ID_OPT2                = 0xF121;   /// Secondary property set.
47cdf0e10cSrcweir const sal_uInt16 DFF_ID_OPT3                = 0xF122;   /// Ternary property set.
48cdf0e10cSrcweir const sal_uInt16 DFF_ID_SP                  = 0xF00A;   /// Shape.
49cdf0e10cSrcweir const sal_uInt16 DFF_ID_SPGR                = 0xF009;   /// Shape group.
50cdf0e10cSrcweir const sal_uInt16 DFF_ID_SPLITMENUCOLORS     = 0xF11E;   /// Current toolbar colors.
51cdf0e10cSrcweir 
52cdf0e10cSrcweir const sal_uInt16 DFF_OPT_IDMASK             = 0x3FFF;
53cdf0e10cSrcweir const sal_uInt16 DFF_OPT_PICTURE            = 0x4000;
54cdf0e10cSrcweir const sal_uInt16 DFF_OPT_COMPLEX            = 0x8000;
55cdf0e10cSrcweir const sal_uInt16 DFF_OPT_FLAGSMASK          = 0x003F;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir } // namespace
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // ============================================================================
60cdf0e10cSrcweir 
construct(const ObjectBase & rParent,const BinaryInputStreamRef & rxStrm,const OUString & rSysFileName)61cdf0e10cSrcweir void DffStreamObject::construct( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     SequenceRecordObjectBase::construct( rParent, rxStrm, rSysFileName, "DFF-RECORD-NAMES" );
64cdf0e10cSrcweir     constructDffObj();
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
construct(const OutputObjectBase & rParent,const BinaryInputStreamRef & rxStrm)67cdf0e10cSrcweir void DffStreamObject::construct( const OutputObjectBase& rParent, const BinaryInputStreamRef& rxStrm )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     SequenceRecordObjectBase::construct( rParent, rxStrm, "DFF-RECORD-NAMES" );
70cdf0e10cSrcweir     constructDffObj();
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
implReadRecordHeader(BinaryInputStream & rBaseStrm,sal_Int64 & ornRecId,sal_Int64 & ornRecSize)73cdf0e10cSrcweir bool DffStreamObject::implReadRecordHeader( BinaryInputStream& rBaseStrm, sal_Int64& ornRecId, sal_Int64& ornRecSize )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     sal_uInt16 nRecId;
76cdf0e10cSrcweir     rBaseStrm >> mnInstVer >> nRecId >> mnRealSize;
77cdf0e10cSrcweir     ornRecId = nRecId;
78cdf0e10cSrcweir     ornRecSize = isContainer() ? 0 : mnRealSize;
79cdf0e10cSrcweir     return !rBaseStrm.isEof();
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
implWriteExtHeader()82cdf0e10cSrcweir void DffStreamObject::implWriteExtHeader()
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     const sal_Char* pcListName = "DFF-RECORD-INST";
85cdf0e10cSrcweir     switch( getRecId() )
86cdf0e10cSrcweir     {
87cdf0e10cSrcweir         case DFF_ID_BSE:                pcListName = "DFFBSE-RECORD-INST";          break;  // BLIP type
88cdf0e10cSrcweir         case DFF_ID_BSTORECONTAINER:    pcListName = "DFFBSTORECONT-RECORD-INST";   break;  // BLIP count
89cdf0e10cSrcweir         case DFF_ID_DG:                 pcListName = "DFFDG-RECORD-INST";           break;  // drawing ID
90cdf0e10cSrcweir         case DFF_ID_OPT:                pcListName = "DFFOPT-RECORD-INST";          break;  // property count
91cdf0e10cSrcweir         case DFF_ID_SP:                 pcListName = "DFFSP-RECORD-INST";           break;  // shape type
92cdf0e10cSrcweir         case DFF_ID_SPLITMENUCOLORS:    pcListName = "DFFSPLITMENUC-RECORD-INST";   break;  // number of colors
93cdf0e10cSrcweir     }
94cdf0e10cSrcweir     MultiItemsGuard aMultiGuard( mxOut );
95cdf0e10cSrcweir     writeHexItem( "instance", mnInstVer, pcListName );
96cdf0e10cSrcweir     if( isContainer() ) writeDecItem( "container-size", mnRealSize );
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
implDumpRecordBody()99cdf0e10cSrcweir void DffStreamObject::implDumpRecordBody()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     switch( getRecId() )
102cdf0e10cSrcweir     {
103cdf0e10cSrcweir         case DFF_ID_BSE:
104cdf0e10cSrcweir             dumpDec< sal_uInt8 >( "win-type", "DFFBSE-TYPE" );
105cdf0e10cSrcweir             dumpDec< sal_uInt8 >( "mac-type", "DFFBSE-TYPE" );
106cdf0e10cSrcweir             dumpGuid( "guid" );
107cdf0e10cSrcweir             dumpDec< sal_uInt16 >( "tag" );
108cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "blip-size" );
109cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "blip-refcount" );
110cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "blip-streampos" );
111cdf0e10cSrcweir             dumpDec< sal_uInt8 >( "blip-usage", "DFFBSE-USAGE" );
112cdf0e10cSrcweir             dumpDec< sal_uInt8 >( "blip-name-len" );
113cdf0e10cSrcweir             dumpUnused( 2 );
114cdf0e10cSrcweir         break;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir         case DFF_ID_CHILDANCHOR:
117cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "left" );
118cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "top" );
119cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "right" );
120cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "bottom" );
121cdf0e10cSrcweir         break;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         case DFF_ID_CLIENTANCHOR:
124cdf0e10cSrcweir             implDumpClientAnchor();
125cdf0e10cSrcweir         break;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         case DFF_ID_DG:
128cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "shape-count" );
129cdf0e10cSrcweir             dumpHex< sal_uInt32 >( "max-shape-id", "CONV-DEC" );
130cdf0e10cSrcweir         break;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         case DFF_ID_DGG:
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir             dumpHex< sal_uInt32 >( "max-shape-id", "CONV-DEC" );
135cdf0e10cSrcweir             sal_uInt32 nClusters = dumpDec< sal_uInt32 >( "id-cluster-count" );
136cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "shape-count" );
137cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "drawing-count" );
138cdf0e10cSrcweir             mxOut->resetItemIndex( 1 );
139cdf0e10cSrcweir             TableGuard aTabGuard( mxOut, 15, 16 );
140cdf0e10cSrcweir             for( sal_uInt32 nCluster = 1; !mxStrm->isEof() && (nCluster < nClusters); ++nCluster )
141cdf0e10cSrcweir             {
142cdf0e10cSrcweir                 MultiItemsGuard aMultiGuard( mxOut );
143cdf0e10cSrcweir                 writeEmptyItem( "#cluster" );
144cdf0e10cSrcweir                 dumpDec< sal_uInt32 >( "drawing-id" );
145cdf0e10cSrcweir                 dumpHex< sal_uInt32 >( "next-free-id", "CONV-DEC" );
146cdf0e10cSrcweir             }
147cdf0e10cSrcweir         }
148cdf0e10cSrcweir         break;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         case DFF_ID_OPT:
151cdf0e10cSrcweir         case DFF_ID_OPT2:
152cdf0e10cSrcweir         case DFF_ID_OPT3:
153cdf0e10cSrcweir             dumpDffOpt();
154cdf0e10cSrcweir         break;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         case DFF_ID_SP:
157cdf0e10cSrcweir             dumpHex< sal_uInt32 >( "shape-id", "CONV-DEC" );
158cdf0e10cSrcweir             dumpHex< sal_uInt32 >( "shape-flags", "DFFSP-FLAGS" );
159cdf0e10cSrcweir         break;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         case DFF_ID_SPGR:
162cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "left" );
163cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "top" );
164cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "right" );
165cdf0e10cSrcweir             dumpDec< sal_uInt32 >( "bottom" );
166cdf0e10cSrcweir         break;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         case DFF_ID_SPLITMENUCOLORS:
169cdf0e10cSrcweir             dumpDffSimpleColor( "fill-color" );
170cdf0e10cSrcweir             dumpDffSimpleColor( "line-color" );
171cdf0e10cSrcweir             dumpDffSimpleColor( "shadow-color" );
172cdf0e10cSrcweir             dumpDffSimpleColor( "3d-color" );
173cdf0e10cSrcweir         break;
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
implDumpClientAnchor()177cdf0e10cSrcweir void DffStreamObject::implDumpClientAnchor()
178cdf0e10cSrcweir {
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
constructDffObj()181cdf0e10cSrcweir void DffStreamObject::constructDffObj()
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     mnInstVer = 0;
184cdf0e10cSrcweir     mnRealSize = 0;
185cdf0e10cSrcweir     if( SequenceRecordObjectBase::implIsValid() )
186cdf0e10cSrcweir     {
187cdf0e10cSrcweir         maSimpleProps.insertFormats( cfg().getNameList( "DFFOPT-SIMPLE-PROPERTIES" ) );
188cdf0e10cSrcweir         maComplexProps.insertFormats( cfg().getNameList( "DFFOPT-COMPLEX-PROPERTIES" ) );
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
dumpDffSimpleColor(const String & rName)192cdf0e10cSrcweir sal_uInt32 DffStreamObject::dumpDffSimpleColor( const String& rName )
193cdf0e10cSrcweir {
194cdf0e10cSrcweir     return dumpHex< sal_uInt32 >( rName, "DFF-SIMPLE-COLOR" );
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
dumpDffColor(const String & rName)197cdf0e10cSrcweir sal_uInt32 DffStreamObject::dumpDffColor( const String& rName )
198cdf0e10cSrcweir {
199cdf0e10cSrcweir     return dumpHex< sal_uInt32 >( rName, "DFF-COLOR" );
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir namespace {
203cdf0e10cSrcweir 
204cdf0e10cSrcweir enum PropType { PROPTYPE_BINARY, PROPTYPE_STRING, PROPTYPE_BLIP, PROPTYPE_COLORARRAY };
205cdf0e10cSrcweir 
206cdf0e10cSrcweir struct PropInfo
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     OUString            maName;
209cdf0e10cSrcweir     PropType            meType;
210cdf0e10cSrcweir     sal_uInt16          mnId;
211cdf0e10cSrcweir     sal_uInt32          mnSize;
PropInfooox::dump::__anonbe97311f0211::PropInfo212cdf0e10cSrcweir     inline explicit     PropInfo( const OUString& rName, PropType eType, sal_uInt16 nId, sal_uInt32 nSize ) :
213cdf0e10cSrcweir                             maName( rName ), meType( eType ), mnId( nId ), mnSize( nSize ) {}
214cdf0e10cSrcweir };
215cdf0e10cSrcweir 
216cdf0e10cSrcweir typedef ::std::vector< PropInfo > PropInfoVector;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir } // namespace
219cdf0e10cSrcweir 
dumpDffOpt()220cdf0e10cSrcweir void DffStreamObject::dumpDffOpt()
221cdf0e10cSrcweir {
222cdf0e10cSrcweir     sal_uInt16 nPropCount = getInst();
223cdf0e10cSrcweir     PropInfoVector aPropInfos;
224cdf0e10cSrcweir     mxOut->resetItemIndex();
225cdf0e10cSrcweir     for( sal_uInt16 nPropIdx = 0; !mxStrm->isEof() && (nPropIdx < nPropCount); ++nPropIdx )
226cdf0e10cSrcweir     {
227cdf0e10cSrcweir         sal_uInt16 nPropId = dumpDffOptPropHeader();
228cdf0e10cSrcweir         sal_uInt16 nBaseId = nPropId & DFF_OPT_IDMASK;
229cdf0e10cSrcweir         sal_uInt32 nValue = mxStrm->readuInt32();
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         IndentGuard aIndent( mxOut );
232cdf0e10cSrcweir         if( getFlag( nPropId, DFF_OPT_COMPLEX ) )
233cdf0e10cSrcweir         {
234cdf0e10cSrcweir             writeHexItem( "complex-size", nValue, "CONV-DEC" );
235cdf0e10cSrcweir             String aName;
236cdf0e10cSrcweir             PropType eType = PROPTYPE_BINARY;
237cdf0e10cSrcweir             ItemFormatMap::const_iterator aIt = maComplexProps.find( nBaseId );
238cdf0e10cSrcweir             if( aIt != maComplexProps.end() )
239cdf0e10cSrcweir             {
240cdf0e10cSrcweir                 const ItemFormat& rItemFmt = aIt->second;
241cdf0e10cSrcweir                 aName = rItemFmt.maItemName;
242cdf0e10cSrcweir                 if( rItemFmt.maListName.equalsAscii( "binary" ) )
243cdf0e10cSrcweir                     eType = PROPTYPE_BINARY;
244cdf0e10cSrcweir                 else if( rItemFmt.maListName.equalsAscii( "string" ) )
245cdf0e10cSrcweir                     eType = PROPTYPE_STRING;
246cdf0e10cSrcweir                 else if( rItemFmt.maListName.equalsAscii( "blip" ) )
247cdf0e10cSrcweir                     eType = PROPTYPE_BLIP;
248cdf0e10cSrcweir                 else if( rItemFmt.maListName.equalsAscii( "colorarray" ) )
249cdf0e10cSrcweir                     eType = PROPTYPE_COLORARRAY;
250cdf0e10cSrcweir             }
251cdf0e10cSrcweir             aPropInfos.push_back( PropInfo( aName( "property-data" ), eType, nBaseId, nValue ) );
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir         else
254cdf0e10cSrcweir         {
255cdf0e10cSrcweir             ItemFormatMap::const_iterator aIt = maSimpleProps.find( nBaseId );
256cdf0e10cSrcweir             if( aIt != maSimpleProps.end() )
257cdf0e10cSrcweir             {
258cdf0e10cSrcweir                 const ItemFormat& rItemFmt = aIt->second;
259cdf0e10cSrcweir                 // flags always at end of block of 64 properties
260cdf0e10cSrcweir                 if( (nBaseId & DFF_OPT_FLAGSMASK) == DFF_OPT_FLAGSMASK )
261cdf0e10cSrcweir                 {
262cdf0e10cSrcweir                     FlagsList* pFlagsList = dynamic_cast< FlagsList* >( cfg().getNameList( rItemFmt.maListName ).get() );
263cdf0e10cSrcweir                     sal_Int64 nOldIgnoreFlags = 0;
264cdf0e10cSrcweir                     if( pFlagsList )
265cdf0e10cSrcweir                     {
266cdf0e10cSrcweir                         nOldIgnoreFlags = pFlagsList->getIgnoreFlags();
267cdf0e10cSrcweir                         pFlagsList->setIgnoreFlags( nOldIgnoreFlags | 0xFFFF0000 | ~(nValue >> 16) );
268cdf0e10cSrcweir                     }
269cdf0e10cSrcweir                     writeValueItem( rItemFmt, nValue );
270cdf0e10cSrcweir                     if( pFlagsList )
271cdf0e10cSrcweir                         pFlagsList->setIgnoreFlags( nOldIgnoreFlags );
272cdf0e10cSrcweir                 }
273cdf0e10cSrcweir                 else
274cdf0e10cSrcweir                     writeValueItem( rItemFmt, nValue );
275cdf0e10cSrcweir             }
276cdf0e10cSrcweir             else
277cdf0e10cSrcweir                 writeHexItem( "value", nValue );
278cdf0e10cSrcweir         }
279cdf0e10cSrcweir     }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir     mxOut->resetItemIndex();
282cdf0e10cSrcweir     for( PropInfoVector::iterator aIt = aPropInfos.begin(), aEnd = aPropInfos.end(); !mxStrm->isEof() && (aIt != aEnd); ++aIt )
283cdf0e10cSrcweir     {
284cdf0e10cSrcweir         mxOut->startMultiItems();
285cdf0e10cSrcweir         writeEmptyItem( "#complex-data" );
286cdf0e10cSrcweir         writeHexItem( "id", aIt->mnId, "DFFOPT-PROPERTY-NAMES" );
287cdf0e10cSrcweir         mxOut->endMultiItems();
288cdf0e10cSrcweir         IndentGuard aIndent( mxOut );
289cdf0e10cSrcweir         switch( aIt->meType )
290cdf0e10cSrcweir         {
291cdf0e10cSrcweir             case PROPTYPE_BINARY:
292cdf0e10cSrcweir                 dumpBinary( aIt->maName, aIt->mnSize );
293cdf0e10cSrcweir             break;
294cdf0e10cSrcweir             case PROPTYPE_STRING:
295cdf0e10cSrcweir                 dumpUnicodeArray( aIt->maName, aIt->mnSize / 2, true );
296cdf0e10cSrcweir             break;
297cdf0e10cSrcweir             case PROPTYPE_BLIP:
298cdf0e10cSrcweir                 dumpBinary( aIt->maName, aIt->mnSize );
299cdf0e10cSrcweir             break;
300cdf0e10cSrcweir             case PROPTYPE_COLORARRAY:
301cdf0e10cSrcweir                 dumpBinary( aIt->maName, aIt->mnSize );
302cdf0e10cSrcweir             break;
303cdf0e10cSrcweir         }
304cdf0e10cSrcweir     }
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
dumpDffOptPropHeader()307cdf0e10cSrcweir sal_uInt16 DffStreamObject::dumpDffOptPropHeader()
308cdf0e10cSrcweir {
309cdf0e10cSrcweir     MultiItemsGuard aMultiGuard( mxOut );
310cdf0e10cSrcweir     TableGuard aTabGuard( mxOut, 11 );
311cdf0e10cSrcweir     writeEmptyItem( "#prop" );
312cdf0e10cSrcweir     return dumpHex< sal_uInt16 >( "id", "DFFOPT-PROPERTY-ID" );
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir // ============================================================================
316cdf0e10cSrcweir 
317cdf0e10cSrcweir } // namespace dump
318cdf0e10cSrcweir } // namespace oox
319cdf0e10cSrcweir 
320cdf0e10cSrcweir #endif
321