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 0 : PptEscherEx::PptEscherEx( SvStream& rOutStrm, const OUString& rBaseURI ) :
23 0 : EscherEx( EscherExGlobalRef( new EscherExGlobal ), &rOutStrm )
24 : {
25 0 : mxGlobal->SetBaseURI( rBaseURI );
26 0 : mnCurrentDg = 0;
27 0 : }
28 :
29 0 : sal_uInt32 PptEscherEx::DrawingGroupContainerSize()
30 : {
31 0 : return ImplDggContainerSize() + 8;
32 : }
33 :
34 0 : void PptEscherEx::WriteDrawingGroupContainer( SvStream& rSt )
35 : {
36 0 : sal_uInt32 nSize = DrawingGroupContainerSize();
37 0 : rSt.WriteUInt32( ( 0xf | ( 1035 << 16 ) ) ) // EPP_PPDrawingGroup
38 0 : .WriteUInt32( ( nSize - 8 ) );
39 :
40 0 : ImplWriteDggContainer( rSt );
41 0 : }
42 :
43 0 : sal_uInt32 PptEscherEx::ImplDggContainerSize()
44 : {
45 : sal_uInt32 nSize;
46 :
47 0 : nSize = mxGlobal->GetDggAtomSize();
48 0 : nSize += mxGlobal->GetBlibStoreContainerSize();
49 0 : nSize += ImplOptAtomSize();
50 0 : nSize += ImplSplitMenuColorsAtomSize();
51 :
52 0 : return nSize + 8;
53 : }
54 :
55 0 : void PptEscherEx::ImplWriteDggContainer( SvStream& rSt )
56 : {
57 0 : sal_uInt32 nSize = ImplDggContainerSize();
58 0 : if ( nSize )
59 : {
60 0 : rSt.WriteUInt32( ( 0xf | ( ESCHER_DggContainer << 16 ) ) )
61 0 : .WriteUInt32( ( nSize - 8 ) );
62 :
63 0 : mxGlobal->SetDggContainer();
64 0 : mxGlobal->WriteDggAtom( rSt );
65 0 : mxGlobal->WriteBlibStoreContainer( rSt );
66 0 : ImplWriteOptAtom( rSt );
67 0 : ImplWriteSplitMenuColorsAtom( rSt );
68 : }
69 0 : }
70 :
71 : #define ESCHER_OPT_COUNT 6
72 :
73 0 : sal_uInt32 PptEscherEx::ImplOptAtomSize()
74 : {
75 0 : sal_uInt32 nSize = 0;
76 : if ( ESCHER_OPT_COUNT != 0 )
77 0 : nSize = ( ESCHER_OPT_COUNT * 6 ) + 8;
78 0 : return nSize;
79 : }
80 :
81 0 : void PptEscherEx::ImplWriteOptAtom( SvStream& rSt )
82 : {
83 0 : sal_uInt32 nSize = ImplOptAtomSize();
84 0 : if ( nSize )
85 : {
86 0 : rSt.WriteUInt32( ( ( ESCHER_OPT << 16 ) | ( ESCHER_OPT_COUNT << 4 ) | 0x3 ) )
87 0 : .WriteUInt32( ( nSize - 8 ) )
88 0 : .WriteUInt16( ESCHER_Prop_fillColor ) .WriteUInt32( 0xffb800 )
89 0 : .WriteUInt16( ESCHER_Prop_fillBackColor ) .WriteUInt32( 0 )
90 0 : .WriteUInt16( ESCHER_Prop_fNoFillHitTest ) .WriteUInt32( 0x00100010 )
91 0 : .WriteUInt16( ESCHER_Prop_lineColor ) .WriteUInt32( 0x8000001 )
92 0 : .WriteUInt16( ESCHER_Prop_fNoLineDrawDash ) .WriteUInt32( 0x00080008 )
93 0 : .WriteUInt16( ESCHER_Prop_shadowColor ) .WriteUInt32( 0x8000002 );
94 : }
95 0 : }
96 :
97 : #define ESCHER_SPLIT_MENU_COLORS_COUNT 4
98 :
99 0 : sal_uInt32 PptEscherEx::ImplSplitMenuColorsAtomSize()
100 : {
101 0 : sal_uInt32 nSize = 0;
102 : if ( ESCHER_SPLIT_MENU_COLORS_COUNT != 0 )
103 0 : nSize = ( ESCHER_SPLIT_MENU_COLORS_COUNT << 2 ) + 8;
104 0 : return nSize;
105 : }
106 :
107 0 : void PptEscherEx::ImplWriteSplitMenuColorsAtom( SvStream& rSt )
108 : {
109 0 : sal_uInt32 nSize = ImplSplitMenuColorsAtomSize();
110 0 : if ( nSize )
111 : {
112 0 : rSt.WriteUInt32( ( ( ESCHER_SplitMenuColors << 16 ) | ( ESCHER_SPLIT_MENU_COLORS_COUNT << 4 ) ) )
113 0 : .WriteUInt32( ( nSize - 8 ) )
114 0 : .WriteUInt32( 0x08000004 )
115 0 : .WriteUInt32( 0x08000001 )
116 0 : .WriteUInt32( 0x08000002 )
117 0 : .WriteUInt32( 0x100000f7 );
118 : }
119 :
120 0 : }
121 :
122 0 : PptEscherEx::~PptEscherEx()
123 : {
124 0 : }
125 :
126 0 : void PptEscherEx::OpenContainer( sal_uInt16 n_EscherContainer, int nRecInstance )
127 : {
128 0 : mpOutStrm->WriteUInt16( ( ( nRecInstance << 4 ) | 0xf ) ).WriteUInt16( n_EscherContainer ).WriteUInt32( 0 );
129 0 : mOffsets.push_back( mpOutStrm->Tell() - 4 );
130 0 : mRecTypes.push_back( n_EscherContainer );
131 :
132 0 : switch( n_EscherContainer )
133 : {
134 : case ESCHER_DgContainer :
135 : {
136 0 : if ( !mbEscherDg )
137 : {
138 0 : mbEscherDg = true;
139 0 : mnCurrentDg = mxGlobal->GenerateDrawingId();
140 0 : AddAtom( 8, ESCHER_Dg, 0, mnCurrentDg );
141 0 : PtReplaceOrInsert( ESCHER_Persist_Dg | mnCurrentDg, mpOutStrm->Tell() );
142 0 : mpOutStrm->WriteUInt32( 0 ) // The number of shapes in this drawing
143 0 : .WriteUInt32( 0 ); // The last MSOSPID given to an SP in this DG
144 : }
145 : }
146 0 : break;
147 :
148 : case ESCHER_SpgrContainer :
149 : {
150 0 : if ( mbEscherDg )
151 : {
152 0 : mbEscherSpgr = true;
153 : }
154 : }
155 0 : break;
156 :
157 : default:
158 0 : break;
159 : }
160 0 : }
161 :
162 0 : 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 0 : if ( ( mRecTypes.back() != ESCHER_SpgrContainer ) || ( mnGroupLevel < 12 ) )
169 : {
170 0 : sal_uInt32 nSize, nPos = mpOutStrm->Tell();
171 0 : nSize = ( nPos - mOffsets.back() ) - 4;
172 0 : mpOutStrm->Seek( mOffsets.back() );
173 0 : mpOutStrm->WriteUInt32( nSize );
174 :
175 0 : switch( mRecTypes.back() )
176 : {
177 : case ESCHER_DgContainer :
178 : {
179 0 : if ( mbEscherDg )
180 : {
181 0 : mbEscherDg = false;
182 0 : if ( DoSeek( ESCHER_Persist_Dg | mnCurrentDg ) )
183 0 : mpOutStrm->WriteUInt32( mxGlobal->GetDrawingShapeCount( mnCurrentDg ) ).WriteUInt32( mxGlobal->GetLastShapeId( mnCurrentDg ) );
184 : }
185 : }
186 0 : break;
187 :
188 : case ESCHER_SpgrContainer :
189 : {
190 0 : if ( mbEscherSpgr )
191 : {
192 0 : mbEscherSpgr = false;
193 : }
194 : }
195 0 : break;
196 :
197 : default:
198 0 : break;
199 : }
200 0 : mOffsets.pop_back();
201 0 : mRecTypes.pop_back();
202 0 : mpOutStrm->Seek( nPos );
203 : }
204 0 : }
205 :
206 0 : sal_uInt32 PptEscherEx::EnterGroup( Rectangle* pBoundRect, SvMemoryStream* pClientData )
207 : {
208 0 : 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 0 : if ( mnGroupLevel < 12 )
214 : {
215 0 : Rectangle aRect;
216 0 : if ( pBoundRect )
217 0 : aRect = *pBoundRect;
218 :
219 0 : OpenContainer( ESCHER_SpgrContainer );
220 0 : OpenContainer( ESCHER_SpContainer );
221 0 : AddAtom( 16, ESCHER_Spgr, 1 );
222 0 : PtReplaceOrInsert( ESCHER_Persist_Grouping_Snap | mnGroupLevel, mpOutStrm->Tell() );
223 0 : mpOutStrm ->WriteInt32( aRect.Left() ) // bounding box for the grouped shapes to which they are attached
224 0 : .WriteInt32( aRect.Top() )
225 0 : .WriteInt32( aRect.Right() )
226 0 : .WriteInt32( aRect.Bottom() );
227 :
228 0 : nShapeId = GenerateShapeId();
229 0 : if ( !mnGroupLevel )
230 0 : 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 0 : 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 0 : CloseContainer(); // ESCHER_SpContainer
262 : }
263 0 : mnGroupLevel++;
264 0 : return nShapeId;
265 24 : }
266 :
267 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|