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