Line data Source code
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 "escherex.hxx"
21 :
22 3 : PptEscherEx::PptEscherEx( SvStream& rOutStrm, const OUString& rBaseURI ) :
23 3 : EscherEx( EscherExGlobalRef( new EscherExGlobal ), &rOutStrm )
24 : {
25 3 : mxGlobal->SetBaseURI( rBaseURI );
26 3 : mnCurrentDg = 0;
27 3 : }
28 :
29 6 : sal_uInt32 PptEscherEx::DrawingGroupContainerSize()
30 : {
31 6 : return ImplDggContainerSize() + 8;
32 : }
33 :
34 3 : void PptEscherEx::WriteDrawingGroupContainer( SvStream& rSt )
35 : {
36 3 : sal_uInt32 nSize = DrawingGroupContainerSize();
37 3 : rSt.WriteUInt32( 0xf | ( 1035 << 16 ) ) // EPP_PPDrawingGroup
38 6 : .WriteUInt32( nSize - 8 );
39 :
40 3 : ImplWriteDggContainer( rSt );
41 3 : }
42 :
43 9 : sal_uInt32 PptEscherEx::ImplDggContainerSize()
44 : {
45 : sal_uInt32 nSize;
46 :
47 9 : nSize = mxGlobal->GetDggAtomSize();
48 9 : nSize += mxGlobal->GetBlibStoreContainerSize();
49 9 : nSize += ImplOptAtomSize();
50 9 : nSize += ImplSplitMenuColorsAtomSize();
51 :
52 9 : return nSize + 8;
53 : }
54 :
55 3 : void PptEscherEx::ImplWriteDggContainer( SvStream& rSt )
56 : {
57 3 : sal_uInt32 nSize = ImplDggContainerSize();
58 3 : if ( nSize )
59 : {
60 3 : rSt.WriteUInt32( 0xf | ( ESCHER_DggContainer << 16 ) )
61 6 : .WriteUInt32( nSize - 8 );
62 :
63 3 : mxGlobal->SetDggContainer();
64 3 : mxGlobal->WriteDggAtom( rSt );
65 3 : mxGlobal->WriteBlibStoreContainer( rSt );
66 3 : ImplWriteOptAtom( rSt );
67 3 : ImplWriteSplitMenuColorsAtom( rSt );
68 : }
69 3 : }
70 :
71 : #define ESCHER_OPT_COUNT 6
72 :
73 12 : sal_uInt32 PptEscherEx::ImplOptAtomSize()
74 : {
75 12 : sal_uInt32 nSize = 0;
76 : if ( ESCHER_OPT_COUNT != 0 )
77 12 : nSize = ( ESCHER_OPT_COUNT * 6 ) + 8;
78 12 : return nSize;
79 : }
80 :
81 3 : void PptEscherEx::ImplWriteOptAtom( SvStream& rSt )
82 : {
83 3 : sal_uInt32 nSize = ImplOptAtomSize();
84 3 : if ( nSize )
85 : {
86 3 : rSt.WriteUInt32( ( ESCHER_OPT << 16 ) | ( ESCHER_OPT_COUNT << 4 ) | 0x3 )
87 6 : .WriteUInt32( nSize - 8 )
88 3 : .WriteUInt16( ESCHER_Prop_fillColor ) .WriteUInt32( 0xffb800 )
89 3 : .WriteUInt16( ESCHER_Prop_fillBackColor ) .WriteUInt32( 0 )
90 3 : .WriteUInt16( ESCHER_Prop_fNoFillHitTest ) .WriteUInt32( 0x00100010 )
91 3 : .WriteUInt16( ESCHER_Prop_lineColor ) .WriteUInt32( 0x8000001 )
92 3 : .WriteUInt16( ESCHER_Prop_fNoLineDrawDash ) .WriteUInt32( 0x00080008 )
93 3 : .WriteUInt16( ESCHER_Prop_shadowColor ) .WriteUInt32( 0x8000002 );
94 : }
95 3 : }
96 :
97 : #define ESCHER_SPLIT_MENU_COLORS_COUNT 4
98 :
99 12 : sal_uInt32 PptEscherEx::ImplSplitMenuColorsAtomSize()
100 : {
101 12 : sal_uInt32 nSize = 0;
102 : if ( ESCHER_SPLIT_MENU_COLORS_COUNT != 0 )
103 12 : nSize = ( ESCHER_SPLIT_MENU_COLORS_COUNT << 2 ) + 8;
104 12 : return nSize;
105 : }
106 :
107 3 : void PptEscherEx::ImplWriteSplitMenuColorsAtom( SvStream& rSt )
108 : {
109 3 : sal_uInt32 nSize = ImplSplitMenuColorsAtomSize();
110 3 : if ( nSize )
111 : {
112 3 : rSt.WriteUInt32( ( ESCHER_SplitMenuColors << 16 ) | ( ESCHER_SPLIT_MENU_COLORS_COUNT << 4 ) )
113 6 : .WriteUInt32( nSize - 8 )
114 3 : .WriteUInt32( 0x08000004 )
115 3 : .WriteUInt32( 0x08000001 )
116 3 : .WriteUInt32( 0x08000002 )
117 3 : .WriteUInt32( 0x100000f7 );
118 : }
119 :
120 3 : }
121 :
122 6 : PptEscherEx::~PptEscherEx()
123 : {
124 6 : }
125 :
126 216 : void PptEscherEx::OpenContainer( sal_uInt16 n_EscherContainer, int nRecInstance )
127 : {
128 216 : mpOutStrm->WriteUInt16( ( nRecInstance << 4 ) | 0xf ).WriteUInt16( n_EscherContainer ).WriteUInt32( 0 );
129 216 : mOffsets.push_back( mpOutStrm->Tell() - 4 );
130 216 : mRecTypes.push_back( n_EscherContainer );
131 :
132 216 : switch( n_EscherContainer )
133 : {
134 : case ESCHER_DgContainer :
135 : {
136 16 : if ( !mbEscherDg )
137 : {
138 16 : mbEscherDg = true;
139 16 : mnCurrentDg = mxGlobal->GenerateDrawingId();
140 16 : AddAtom( 8, ESCHER_Dg, 0, mnCurrentDg );
141 16 : PtReplaceOrInsert( ESCHER_Persist_Dg | mnCurrentDg, mpOutStrm->Tell() );
142 16 : mpOutStrm->WriteUInt32( 0 ) // The number of shapes in this drawing
143 16 : .WriteUInt32( 0 ); // The last MSOSPID given to an SP in this DG
144 : }
145 : }
146 16 : break;
147 :
148 : case ESCHER_SpgrContainer :
149 : {
150 16 : if ( mbEscherDg )
151 : {
152 16 : mbEscherSpgr = true;
153 : }
154 : }
155 16 : break;
156 :
157 : default:
158 184 : break;
159 : }
160 216 : }
161 :
162 216 : void PptEscherEx::CloseContainer()
163 : {
164 : /* SJ: #Issue 26747#
165 : not creating group objects with a depth higher than 16, because then
166 : PPT is having a big performance problem when starting a slide show
167 : */
168 216 : if ( ( mRecTypes.back() != ESCHER_SpgrContainer ) || ( mnGroupLevel < 12 ) )
169 : {
170 216 : sal_uInt32 nSize, nPos = mpOutStrm->Tell();
171 216 : nSize = ( nPos - mOffsets.back() ) - 4;
172 216 : mpOutStrm->Seek( mOffsets.back() );
173 216 : mpOutStrm->WriteUInt32( nSize );
174 :
175 216 : switch( mRecTypes.back() )
176 : {
177 : case ESCHER_DgContainer :
178 : {
179 16 : if ( mbEscherDg )
180 : {
181 16 : mbEscherDg = false;
182 16 : if ( DoSeek( ESCHER_Persist_Dg | mnCurrentDg ) )
183 16 : mpOutStrm->WriteUInt32( mxGlobal->GetDrawingShapeCount( mnCurrentDg ) ).WriteUInt32( mxGlobal->GetLastShapeId( mnCurrentDg ) );
184 : }
185 : }
186 16 : break;
187 :
188 : case ESCHER_SpgrContainer :
189 : {
190 16 : if ( mbEscherSpgr )
191 : {
192 16 : mbEscherSpgr = false;
193 : }
194 : }
195 16 : break;
196 :
197 : default:
198 184 : break;
199 : }
200 216 : mOffsets.pop_back();
201 216 : mRecTypes.pop_back();
202 216 : mpOutStrm->Seek( nPos );
203 : }
204 216 : }
205 :
206 16 : sal_uInt32 PptEscherEx::EnterGroup( Rectangle* pBoundRect, SvMemoryStream* pClientData )
207 : {
208 16 : sal_uInt32 nShapeId = 0;
209 : /* SJ: #Issue 26747#
210 : not creating group objects with a depth higher than 16, because then
211 : PPT is having a big performance problem when starting a slide show
212 : */
213 16 : if ( mnGroupLevel < 12 )
214 : {
215 16 : Rectangle aRect;
216 16 : if ( pBoundRect )
217 0 : aRect = *pBoundRect;
218 :
219 16 : OpenContainer( ESCHER_SpgrContainer );
220 16 : OpenContainer( ESCHER_SpContainer );
221 16 : AddAtom( 16, ESCHER_Spgr, 1 );
222 16 : PtReplaceOrInsert( ESCHER_Persist_Grouping_Snap | mnGroupLevel, mpOutStrm->Tell() );
223 16 : mpOutStrm ->WriteInt32( aRect.Left() ) // bounding box for the grouped shapes to which they are attached
224 32 : .WriteInt32( aRect.Top() )
225 32 : .WriteInt32( aRect.Right() )
226 32 : .WriteInt32( aRect.Bottom() );
227 :
228 16 : nShapeId = GenerateShapeId();
229 16 : if ( !mnGroupLevel )
230 16 : AddShape( ESCHER_ShpInst_Min, 5, nShapeId ); // Flags: Group | Patriarch
231 : else
232 : {
233 0 : AddShape( ESCHER_ShpInst_Min, 0x201, nShapeId ); // Flags: Group | HaveAnchor
234 0 : if ( mnGroupLevel == 1 )
235 : {
236 0 : AddAtom( 8, ESCHER_ClientAnchor );
237 0 : PtReplaceOrInsert( ESCHER_Persist_Grouping_Logic | mnGroupLevel, mpOutStrm->Tell() );
238 0 : mpOutStrm->WriteInt16( aRect.Top() ).WriteInt16( aRect.Left() ).WriteInt16( aRect.Right() ).WriteInt16( aRect.Bottom() );
239 : }
240 : else
241 : {
242 0 : AddAtom( 16, ESCHER_ChildAnchor );
243 0 : PtReplaceOrInsert( ESCHER_Persist_Grouping_Snap | mnGroupLevel, mpOutStrm->Tell() );
244 0 : mpOutStrm ->WriteInt32( aRect.Left() )
245 0 : .WriteInt32( aRect.Top() )
246 0 : .WriteInt32( aRect.Right() )
247 0 : .WriteInt32( aRect.Bottom() );
248 : }
249 : }
250 16 : if ( pClientData )
251 : {
252 0 : pClientData->Seek( STREAM_SEEK_TO_END );
253 0 : sal_uInt32 nSize = pClientData->Tell();
254 0 : if ( nSize )
255 : {
256 0 : mpOutStrm->WriteUInt32( ( ESCHER_ClientData << 16 ) | 0xf )
257 0 : .WriteUInt32( nSize );
258 0 : mpOutStrm->Write( pClientData->GetData(), nSize );
259 : }
260 : }
261 16 : CloseContainer(); // ESCHER_SpContainer
262 : }
263 16 : mnGroupLevel++;
264 16 : return nShapeId;
265 : }
266 :
267 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|