LibreOffice Module oox (master)  1
dffdumper.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <oox/dump/dffdumper.hxx>
21 
22 #ifdef DBG_UTIL
23 
24 namespace oox::dump {
25 
26 namespace {
27 
28 const sal_uInt16 DFF_ID_BSE = 0xF007;
29 const sal_uInt16 DFF_ID_BSTORECONTAINER = 0xF001;
30 const sal_uInt16 DFF_ID_CHILDANCHOR = 0xF00F;
31 const sal_uInt16 DFF_ID_CLIENTANCHOR = 0xF010;
32 const sal_uInt16 DFF_ID_DG = 0xF008;
33 const sal_uInt16 DFF_ID_DGG = 0xF006;
34 const sal_uInt16 DFF_ID_OPT = 0xF00B;
35 const sal_uInt16 DFF_ID_OPT2 = 0xF121;
36 const sal_uInt16 DFF_ID_OPT3 = 0xF122;
37 const sal_uInt16 DFF_ID_SP = 0xF00A;
38 const sal_uInt16 DFF_ID_SPGR = 0xF009;
39 const sal_uInt16 DFF_ID_SPLITMENUCOLORS = 0xF11E;
40 
41 const sal_uInt16 DFF_OPT_IDMASK = 0x3FFF;
42 const sal_uInt16 DFF_OPT_COMPLEX = 0x8000;
43 
44 } // namespace
45 
46 bool DffStreamObject::implReadRecordHeader( BinaryInputStream& rBaseStrm, sal_Int64& ornRecId, sal_Int64& ornRecSize )
47 {
48  mnInstVer = rBaseStrm.readuInt16();
49  ornRecId = rBaseStrm.readuInt16();
50  mnRealSize = rBaseStrm.readInt32();
51  ornRecSize = isContainer() ? 0 : mnRealSize;
52  return !rBaseStrm.isEof();
53 }
54 
56 {
57  const char* pcListName = "DFF-RECORD-INST";
58  switch( getRecId() )
59  {
60  case DFF_ID_BSE: pcListName = "DFFBSE-RECORD-INST"; break; // BLIP type
61  case DFF_ID_BSTORECONTAINER: pcListName = "DFFBSTORECONT-RECORD-INST"; break; // BLIP count
62  case DFF_ID_DG: pcListName = "DFFDG-RECORD-INST"; break; // drawing ID
63  case DFF_ID_OPT: pcListName = "DFFOPT-RECORD-INST"; break; // property count
64  case DFF_ID_SP: pcListName = "DFFSP-RECORD-INST"; break; // shape type
65  case DFF_ID_SPLITMENUCOLORS: pcListName = "DFFSPLITMENUC-RECORD-INST"; break; // number of colors
66  }
67  MultiItemsGuard aMultiGuard( mxOut );
68  writeHexItem( "instance", mnInstVer, pcListName );
69  if( isContainer() ) writeDecItem( "container-size", mnRealSize );
70 }
71 
73 {
74  switch( getRecId() )
75  {
76  case DFF_ID_BSE:
77  dumpDec< sal_uInt8 >( "win-type", "DFFBSE-TYPE" );
78  dumpDec< sal_uInt8 >( "mac-type", "DFFBSE-TYPE" );
79  dumpGuid( "guid" );
80  dumpDec< sal_uInt16 >( "tag" );
81  dumpDec< sal_uInt32 >( "blip-size" );
82  dumpDec< sal_uInt32 >( "blip-refcount" );
83  dumpDec< sal_uInt32 >( "blip-streampos" );
84  dumpDec< sal_uInt8 >( "blip-usage", "DFFBSE-USAGE" );
85  dumpDec< sal_uInt8 >( "blip-name-len" );
86  dumpUnused( 2 );
87  break;
88 
89  case DFF_ID_CHILDANCHOR:
90  dumpDec< sal_uInt32 >( "left" );
91  dumpDec< sal_uInt32 >( "top" );
92  dumpDec< sal_uInt32 >( "right" );
93  dumpDec< sal_uInt32 >( "bottom" );
94  break;
95 
96  case DFF_ID_CLIENTANCHOR:
97  break;
98 
99  case DFF_ID_DG:
100  dumpDec< sal_uInt32 >( "shape-count" );
101  dumpHex< sal_uInt32 >( "max-shape-id", "CONV-DEC" );
102  break;
103 
104  case DFF_ID_DGG:
105  {
106  dumpHex< sal_uInt32 >( "max-shape-id", "CONV-DEC" );
107  sal_uInt32 nClusters = dumpDec< sal_uInt32 >( "id-cluster-count" );
108  dumpDec< sal_uInt32 >( "shape-count" );
109  dumpDec< sal_uInt32 >( "drawing-count" );
110  mxOut->resetItemIndex( 1 );
111  TableGuard aTabGuard( mxOut, 15, 16 );
112  for( sal_uInt32 nCluster = 1; !mxStrm->isEof() && (nCluster < nClusters); ++nCluster )
113  {
114  MultiItemsGuard aMultiGuard( mxOut );
115  writeEmptyItem( "#cluster" );
116  dumpDec< sal_uInt32 >( "drawing-id" );
117  dumpHex< sal_uInt32 >( "next-free-id", "CONV-DEC" );
118  }
119  }
120  break;
121 
122  case DFF_ID_OPT:
123  case DFF_ID_OPT2:
124  case DFF_ID_OPT3:
125  dumpDffOpt();
126  break;
127 
128  case DFF_ID_SP:
129  dumpHex< sal_uInt32 >( "shape-id", "CONV-DEC" );
130  dumpHex< sal_uInt32 >( "shape-flags", "DFFSP-FLAGS" );
131  break;
132 
133  case DFF_ID_SPGR:
134  dumpDec< sal_uInt32 >( "left" );
135  dumpDec< sal_uInt32 >( "top" );
136  dumpDec< sal_uInt32 >( "right" );
137  dumpDec< sal_uInt32 >( "bottom" );
138  break;
139 
140  case DFF_ID_SPLITMENUCOLORS:
141  dumpDffSimpleColor( "fill-color" );
142  dumpDffSimpleColor( "line-color" );
143  dumpDffSimpleColor( "shadow-color" );
144  dumpDffSimpleColor( "3d-color" );
145  break;
146  }
147 }
148 
149 sal_uInt32 DffStreamObject::dumpDffSimpleColor( const String& rName )
150 {
151  return dumpHex< sal_uInt32 >( rName, "DFF-SIMPLE-COLOR" );
152 }
153 
154 namespace {
155 
156 enum class PropType { Binary };
157 
158 struct PropInfo
159 {
160  OUString maName;
161  PropType meType;
162  sal_uInt16 mnId;
163  sal_uInt32 mnSize;
164  explicit PropInfo( const OUString& rName, PropType eType, sal_uInt16 nId, sal_uInt32 nSize ) :
165  maName( rName ), meType( eType ), mnId( nId ), mnSize( nSize ) {}
166 };
167 
168 typedef ::std::vector< PropInfo > PropInfoVector;
169 
170 } // namespace
171 
173 {
174  sal_uInt16 nPropCount = getInst();
175  PropInfoVector aPropInfos;
176  mxOut->resetItemIndex();
177  for( sal_uInt16 nPropIdx = 0; !mxStrm->isEof() && (nPropIdx < nPropCount); ++nPropIdx )
178  {
179  sal_uInt16 nPropId = dumpDffOptPropHeader();
180  sal_uInt16 nBaseId = nPropId & DFF_OPT_IDMASK;
181  sal_uInt32 nValue = mxStrm->readuInt32();
182 
183  IndentGuard aIndent( mxOut );
184  if( getFlag( nPropId, DFF_OPT_COMPLEX ) )
185  {
186  writeHexItem( "complex-size", nValue, "CONV-DEC" );
187  aPropInfos.emplace_back( String( "property-data" ), PropType::Binary, nBaseId, nValue );
188  }
189  else
190  {
191  writeHexItem( "value", nValue );
192  }
193  }
194 
195  mxOut->resetItemIndex();
196  for (auto const& propInfo : aPropInfos)
197  {
198  if (mxStrm->isEof())
199  break;
200  mxOut->startMultiItems();
201  writeEmptyItem( "#complex-data" );
202  writeHexItem( "id", propInfo.mnId, "DFFOPT-PROPERTY-NAMES" );
203  mxOut->endMultiItems();
204  IndentGuard aIndent( mxOut );
205  switch(propInfo.meType)
206  {
207  case PropType::Binary:
208  dumpBinary( propInfo.maName, propInfo.mnSize );
209  break;
210  default: assert(false && "missing implementation?");
211  }
212  }
213 }
214 
216 {
217  MultiItemsGuard aMultiGuard( mxOut );
218  TableGuard aTabGuard( mxOut, 11 );
219  writeEmptyItem( "#prop" );
220  return dumpHex< sal_uInt16 >( "id", "DFFOPT-PROPERTY-ID" );
221 }
222 
223 } // namespace oox::dump
224 
225 #endif
226 
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void writeHexItem(const String &rName, Type nData, const NameListWrapper &rListWrp=NO_LIST)
virtual bool implReadRecordHeader(BinaryInputStream &rBaseStrm, sal_Int64 &ornRecId, sal_Int64 &ornRecSize) override
Definition: dffdumper.cxx:46
sal_uInt16 getInst() const
Definition: dffdumper.hxx:37
bool isContainer() const
Definition: dffdumper.hxx:38
sal_Int16 nId
Definition: olehelper.cxx:97
sal_uInt16 mnId
Definition: dffdumper.cxx:162
sal_uInt32 dumpDffSimpleColor(const String &rName)
Definition: dffdumper.cxx:149
virtual void implWriteExtHeader() override
Definition: dffdumper.cxx:55
bool getFlag(Type nBitField, Type nMask)
Returns true, if at least one of the bits set in nMask is set in nBitField.
Definition: helper.hxx:135
Interface for binary input stream classes.
void writeDecItem(const String &rName, Type nData, const NameListWrapper &rListWrp=NO_LIST)
OUString dumpGuid(const String &rName=EMPTY_STRING)
sal_uInt16 dumpDffOptPropHeader()
Definition: dffdumper.cxx:215
void dumpBinary(const String &rName, sal_Int64 nBytes, bool bShowOffset=true)
void dumpUnused(sal_Int32 nBytes)
PropType meType
Definition: dffdumper.cxx:161
virtual void implDumpRecordBody() override
Definition: dffdumper.cxx:72
sal_Int64 getRecId() const
void writeEmptyItem(const String &rName)
OUString maName
Definition: dffdumper.cxx:160
bool isEof() const
Returns true, if the stream position is invalid (EOF).
BinaryInputStreamRef mxStrm
sal_Int16 nValue
sal_uInt32 mnSize
Definition: dffdumper.cxx:163