bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / filter / eppt / pptx-stylesheet.cxx
blob4057458c8ee31f4fb4a4d990dd8597c7323d14b3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "epptbase.hxx"
21 #include "epptdef.hxx"
22 #include "text.hxx"
23 #include <tools/color.hxx>
24 #include <editeng/svxenum.hxx>
25 #include <com/sun/star/beans/XPropertySet.hpp>
27 using namespace ::com::sun::star;
29 PPTExCharSheet::PPTExCharSheet( int nInstance )
31 sal_uInt16 nFontHeight = 24;
33 for ( int nDepth = 0; nDepth < 5; nDepth++ )
35 PPTExCharLevel& rLev = maCharLevel[ nDepth ];
36 switch ( nInstance )
38 case EPP_TEXTTYPE_Title :
39 case EPP_TEXTTYPE_CenterTitle :
40 nFontHeight = 44;
41 break;
42 case EPP_TEXTTYPE_Body :
43 case EPP_TEXTTYPE_CenterBody :
44 case EPP_TEXTTYPE_HalfBody :
45 case EPP_TEXTTYPE_QuarterBody :
47 switch ( nDepth )
49 case 0 : nFontHeight = 32; break;
50 case 1 : nFontHeight = 28; break;
51 case 2 : nFontHeight = 24; break;
52 default :nFontHeight = 20; break;
55 break;
56 case EPP_TEXTTYPE_Notes :
57 nFontHeight = 12;
58 break;
59 case EPP_TEXTTYPE_notUsed :
60 case EPP_TEXTTYPE_Other :
61 nFontHeight = 24;
62 break;
64 rLev.mnFlags = 0;
65 rLev.mnFont = 0;
66 rLev.mnAsianOrComplexFont = 0xffff;
67 rLev.mnFontHeight = nFontHeight;
68 rLev.mnFontColor = 0;
69 rLev.mnEscapement = 0;
73 void PPTExCharSheet::SetStyleSheet( const css::uno::Reference< css::beans::XPropertySet > & rXPropSet,
74 FontCollection& rFontCollection, int nLevel )
76 PortionObj aPortionObj( rXPropSet, rFontCollection );
78 PPTExCharLevel& rLev = maCharLevel[ nLevel ];
80 if ( aPortionObj.meCharColor == css::beans::PropertyState_DIRECT_VALUE )
81 rLev.mnFontColor = aPortionObj.mnCharColor;
82 if ( aPortionObj.meCharEscapement == css::beans::PropertyState_DIRECT_VALUE )
83 rLev.mnEscapement = aPortionObj.mnCharEscapement;
84 if ( aPortionObj.meCharHeight == css::beans::PropertyState_DIRECT_VALUE )
85 rLev.mnFontHeight = aPortionObj.mnCharHeight;
86 if ( aPortionObj.meFontName == css::beans::PropertyState_DIRECT_VALUE )
87 rLev.mnFont = aPortionObj.mnFont;
88 if ( aPortionObj.meAsianOrComplexFont == css::beans::PropertyState_DIRECT_VALUE )
89 rLev.mnAsianOrComplexFont = aPortionObj.mnAsianOrComplexFont;
90 rLev.mnFlags = aPortionObj.mnCharAttr;
93 void PPTExCharSheet::Write( SvStream& rSt, sal_uInt16 nLev, bool bSimpleText,
94 const css::uno::Reference< css::beans::XPropertySet > & rPagePropSet )
96 const PPTExCharLevel& rLev = maCharLevel[ nLev ];
98 sal_uInt32 nCharFlags = 0xefffff;
99 if ( bSimpleText )
100 nCharFlags = 0x7ffff;
102 rSt.WriteUInt32( nCharFlags )
103 .WriteUInt16( rLev.mnFlags )
104 .WriteUInt16( rLev.mnFont );
106 Color nFontColor = rLev.mnFontColor;
107 if ( nFontColor == COL_AUTO )
109 bool bIsDark = false;
110 css::uno::Any aAny;
111 if ( PropValue::GetPropertyValue( aAny, rPagePropSet, "IsBackgroundDark", true ) )
112 aAny >>= bIsDark;
113 nFontColor = bIsDark ? 0xffffff : 0x000000;
115 nFontColor.SetTransparency(0xfe);
116 if ( bSimpleText )
118 rSt.WriteUInt16( rLev.mnFontHeight )
119 .WriteUInt32( sal_uInt32(nFontColor) );
121 else
123 rSt.WriteUInt16( rLev.mnAsianOrComplexFont )
124 .WriteUInt16( 0xffff ) // unknown
125 .WriteUInt16( 0xffff ) // unknown
126 .WriteUInt16( rLev.mnFontHeight )
127 .WriteUInt32( sal_uInt32(nFontColor) )
128 .WriteUInt16( rLev.mnEscapement );
132 PPTExParaSheet::PPTExParaSheet( int nInstance, sal_uInt16 nDefaultTab, PPTExBulletProvider* pProv ) :
133 pBuProv ( pProv ),
134 mnInstance ( nInstance )
136 bool bHasBullet = false;
138 sal_uInt16 nUpperDist = 0;
139 sal_uInt16 nBulletChar = 0x2022;
140 sal_uInt16 nBulletOfs = 0;
141 sal_uInt16 nTextOfs = 0;
143 for ( int nDepth = 0; nDepth < 5; nDepth++ )
145 PPTExParaLevel& rLev = maParaLevel[ nDepth ];
146 switch ( nInstance )
148 case EPP_TEXTTYPE_Title :
149 case EPP_TEXTTYPE_CenterTitle :
150 break;
151 case EPP_TEXTTYPE_Body :
152 case EPP_TEXTTYPE_CenterBody :
153 case EPP_TEXTTYPE_HalfBody :
154 case EPP_TEXTTYPE_QuarterBody :
156 bHasBullet = true;
157 nUpperDist = 0x14;
159 break;
160 case EPP_TEXTTYPE_Notes :
161 nUpperDist = 0x1e;
162 break;
165 switch ( nDepth )
167 case 0 :
169 nBulletChar = 0x2022;
170 nBulletOfs = 0;
171 nTextOfs = bHasBullet ? 0xd8 : 0;
173 break;
174 case 1 :
176 nBulletChar = 0x2013;
177 nBulletOfs = 0x120;
178 nTextOfs = 0x1d4;
180 break;
181 case 2 :
183 nBulletChar = 0x2022;
184 nBulletOfs = 0x240;
185 nTextOfs = 0x2d0;
187 break;
188 case 3 :
190 nBulletChar = 0x2013;
191 nBulletOfs = 0x360;
192 nTextOfs = 0x3f0;
194 break;
195 case 4 :
197 nBulletChar = 0xbb;
198 nBulletOfs = 0x480;
199 nTextOfs = 0x510;
201 break;
203 rLev.mbIsBullet = bHasBullet;
204 rLev.mnBulletChar = nBulletChar;
205 rLev.mnBulletFont = 0;
206 rLev.mnBulletHeight = 100;
207 rLev.mnBulletColor = 0;
208 rLev.mnAdjust = 0;
209 rLev.mnLineFeed = 100;
210 rLev.mnLowerDist = 0;
211 rLev.mnUpperDist = nUpperDist;
212 rLev.mnTextOfs = nTextOfs;
213 rLev.mnBulletOfs = nBulletOfs;
214 rLev.mnDefaultTab = nDefaultTab;
215 rLev.mnAsianSettings = 2;
216 rLev.mnBiDi = 0;
218 rLev.mbExtendedBulletsUsed = false;
219 rLev.mnBulletId = 0xffff;
220 rLev.mnBulletStart = 0;
221 rLev.mnMappedNumType = 0;
222 rLev.mnNumberingType = 0;
226 void PPTExParaSheet::SetStyleSheet( const css::uno::Reference< css::beans::XPropertySet > & rXPropSet,
227 FontCollection& rFontCollection, int nLevel, const PPTExCharLevel& rCharLevel )
229 ParagraphObj aParagraphObj( rXPropSet, pBuProv );
230 aParagraphObj.CalculateGraphicBulletSize( rCharLevel.mnFontHeight );
231 PPTExParaLevel& rLev = maParaLevel[ nLevel ];
233 if ( aParagraphObj.meTextAdjust == css::beans::PropertyState_DIRECT_VALUE )
234 rLev.mnAdjust = aParagraphObj.mnTextAdjust;
235 if ( aParagraphObj.meLineSpacing == css::beans::PropertyState_DIRECT_VALUE )
237 sal_Int16 nLineSpacing = aParagraphObj.mnLineSpacing;
238 if ( nLineSpacing > 0 ) // if nLinespacing is < 0 the linespacing is an absolute spacing
240 bool bFixedLineSpacing = false;
241 uno::Any aAny = rXPropSet->getPropertyValue("FontIndependentLineSpacing");
242 if( !(aAny >>= bFixedLineSpacing) || !bFixedLineSpacing )
244 const FontCollectionEntry* pDesc = rFontCollection.GetById( rCharLevel.mnFont );
245 if ( pDesc )
246 nLineSpacing = static_cast<sal_Int16>( static_cast<double>(nLineSpacing) * pDesc->Scaling + 0.5 );
249 else
251 if ( rCharLevel.mnFontHeight > static_cast<sal_uInt16>( static_cast<double>(-nLineSpacing) * 0.001 * 72.0 / 2.54 ) ) // 1/100mm to point
253 const FontCollectionEntry* pDesc = rFontCollection.GetById( rCharLevel.mnFont );
254 if ( pDesc )
255 nLineSpacing = static_cast<sal_Int16>( 100.0 * pDesc->Scaling + 0.5 );
256 else
257 nLineSpacing = 100;
259 else
260 nLineSpacing = static_cast<sal_Int16>( static_cast<double>(nLineSpacing) / 4.40972 );
262 rLev.mnLineFeed = nLineSpacing;
264 if ( aParagraphObj.meLineSpacingBottom == css::beans::PropertyState_DIRECT_VALUE )
265 rLev.mnLowerDist = aParagraphObj.mnLineSpacingBottom;
266 if ( aParagraphObj.meLineSpacingTop == css::beans::PropertyState_DIRECT_VALUE )
267 rLev.mnUpperDist = aParagraphObj.mnLineSpacingTop;
268 if ( aParagraphObj.meForbiddenRules == css::beans::PropertyState_DIRECT_VALUE )
270 rLev.mnAsianSettings &=~1;
271 if ( aParagraphObj.mbForbiddenRules )
272 rLev.mnAsianSettings |= 1;
274 if ( aParagraphObj.meParagraphPunctation == css::beans::PropertyState_DIRECT_VALUE )
276 rLev.mnAsianSettings &=~4;
277 if ( aParagraphObj.mbParagraphPunctation )
278 rLev.mnAsianSettings |= 4;
281 if ( aParagraphObj.meBiDi == css::beans::PropertyState_DIRECT_VALUE )
282 rLev.mnBiDi = aParagraphObj.mnBiDi;
284 rLev.mbIsBullet = aParagraphObj.mbIsBullet; //( ( aParagraphObj.nBulletFlags & 1 ) != 0 );
286 if ( nLevel )
287 return;
289 if (!(aParagraphObj.bExtendedParameters &&
290 aParagraphObj.meBullet == css::beans::PropertyState_DIRECT_VALUE))
291 return;
293 for ( sal_Int16 i = 0; i < 5; i++ )
295 PPTExParaLevel& rLevel = maParaLevel[ i ];
296 if ( i )
297 aParagraphObj.ImplGetNumberingLevel( pBuProv, i, false, false );
298 rLevel.mnTextOfs = aParagraphObj.nTextOfs;
299 rLevel.mnBulletOfs = static_cast<sal_uInt16>(aParagraphObj.nBulletOfs);
300 rLevel.mnBulletChar = aParagraphObj.cBulletId;
301 FontCollectionEntry aFontDescEntry( aParagraphObj.aFontDesc.Name, aParagraphObj.aFontDesc.Family,
302 aParagraphObj.aFontDesc.Pitch, aParagraphObj.aFontDesc.CharSet );
303 rLevel.mnBulletFont = static_cast<sal_uInt16>(rFontCollection.GetId( aFontDescEntry ));
304 rLevel.mnBulletHeight = aParagraphObj.nBulletRealSize;
305 rLevel.mnBulletColor = aParagraphObj.nBulletColor;
307 rLevel.mbExtendedBulletsUsed = aParagraphObj.bExtendedBulletsUsed;
308 rLevel.mnBulletId = aParagraphObj.nBulletId;
309 rLevel.mnNumberingType = aParagraphObj.nNumberingType;
310 rLevel.mnBulletStart = aParagraphObj.nStartWith;
311 rLevel.mnMappedNumType = aParagraphObj.nMappedNumType;
315 void PPTExParaSheet::Write( SvStream& rSt, sal_uInt16 nLev, bool bSimpleText,
316 const css::uno::Reference< css::beans::XPropertySet > & rPagePropSet )
318 const PPTExParaLevel& rLev = maParaLevel[ nLev ];
320 if ( maParaLevel[ 0 ].mbExtendedBulletsUsed || maParaLevel[ 1 ].mbExtendedBulletsUsed ||
321 maParaLevel[ 2 ].mbExtendedBulletsUsed || maParaLevel[ 3 ].mbExtendedBulletsUsed ||
322 maParaLevel[ 4 ].mbExtendedBulletsUsed )
324 SvStream& rOut = pBuProv->aBuExMasterStream;
325 if ( !nLev )
327 rOut.WriteUInt32( ( EPP_PST_ExtendedParagraphMasterAtom << 16 ) | ( mnInstance << 4 ) )
328 .WriteUInt32( 5 * 16 + 2 )
329 .WriteUInt16( 5 ); // depth
331 sal_uInt16 nBulletId = rLev.mnBulletId;
332 if ( rLev.mnNumberingType != SVX_NUM_BITMAP )
333 nBulletId = 0xffff;
334 rOut.WriteUInt32( 0x03800000 )
335 .WriteUInt16( nBulletId )
336 .WriteUInt32( rLev.mnMappedNumType )
337 .WriteUInt16( rLev.mnBulletStart )
338 .WriteUInt32( 0 );
341 sal_uInt32 nParaFlags = 0x3ffdff;
342 sal_uInt16 nBulletFlags = ( rLev.mbIsBullet ) ? 0xf : 0xe;
344 if ( nLev )
345 nParaFlags &= 0x207fff;
346 if ( bSimpleText )
347 nParaFlags &= 0x7fff;
348 sal_uInt32 nBulletColor = rLev.mnBulletColor;
349 if ( nBulletColor == sal_uInt32(COL_AUTO) )
351 bool bIsDark = false;
352 css::uno::Any aAny;
353 if ( PropValue::GetPropertyValue( aAny, rPagePropSet, "IsBackgroundDark", true ) )
354 aAny >>= bIsDark;
355 nBulletColor = bIsDark ? 0xffffff : 0x000000;
357 nBulletColor &= 0xffffff;
358 nBulletColor |= 0xfe000000;
359 rSt.WriteUInt32( nParaFlags )
360 .WriteUInt16( nBulletFlags )
361 .WriteUInt16( rLev.mnBulletChar )
362 .WriteUInt16( rLev.mnBulletFont )
363 .WriteUInt16( rLev.mnBulletHeight )
364 .WriteUInt32( nBulletColor )
365 .WriteUInt16( rLev.mnAdjust )
366 .WriteUInt16( rLev.mnLineFeed )
367 .WriteUInt16( rLev.mnUpperDist )
368 .WriteUInt16( rLev.mnLowerDist )
369 .WriteUInt16( rLev.mnTextOfs )
370 .WriteUInt16( rLev.mnBulletOfs );
372 if ( bSimpleText || nLev )
374 if ( nParaFlags & 0x200000 )
375 rSt.WriteUInt16( rLev.mnBiDi );
377 else
379 rSt.WriteUInt16( rLev.mnDefaultTab )
380 .WriteUInt16( 0 )
381 .WriteUInt16( 0 )
382 .WriteUInt16( rLev.mnAsianSettings )
383 .WriteUInt16( rLev.mnBiDi );
387 PPTExStyleSheet::PPTExStyleSheet( sal_uInt16 nDefaultTab, PPTExBulletProvider* pBuProv )
389 for ( int nInstance = EPP_TEXTTYPE_Title; nInstance <= EPP_TEXTTYPE_QuarterBody; nInstance++ )
391 if (nInstance != EPP_TEXTTYPE_notUsed)
393 mpParaSheet[ nInstance ].reset(new PPTExParaSheet( nInstance, nDefaultTab, pBuProv ));
394 mpCharSheet[ nInstance ].reset(new PPTExCharSheet( nInstance ));
399 PPTExStyleSheet::~PPTExStyleSheet()
403 void PPTExStyleSheet::SetStyleSheet( const css::uno::Reference< css::beans::XPropertySet > & rXPropSet,
404 FontCollection& rFontCollection, int nInstance, int nLevel )
406 if ( nInstance == EPP_TEXTTYPE_notUsed )
407 return;
408 mpCharSheet[ nInstance ]->SetStyleSheet( rXPropSet, rFontCollection, nLevel );
409 mpParaSheet[ nInstance ]->SetStyleSheet( rXPropSet, rFontCollection, nLevel, mpCharSheet[ nInstance ]->maCharLevel[ nLevel ] );
412 bool PPTExStyleSheet::IsHardAttribute( sal_uInt32 nInstance, sal_uInt32 nLevel, PPTExTextAttr eAttr, sal_uInt32 nValue )
414 assert(nInstance < PPTEX_STYLESHEETENTRIES && nLevel < 5);
416 const PPTExParaLevel& rPara = mpParaSheet[ nInstance ]->maParaLevel[ nLevel ];
417 const PPTExCharLevel& rChar = mpCharSheet[ nInstance ]->maCharLevel[ nLevel ];
419 sal_uInt32 nFlag = 0;
421 switch ( eAttr )
423 case ParaAttr_BulletOn : return ( rPara.mbIsBullet ) ? nValue == 0 : nValue != 0;
424 case ParaAttr_BuHardFont :
425 case ParaAttr_BulletFont : return ( rPara.mnBulletFont != nValue );
426 case ParaAttr_BuHardColor :
427 case ParaAttr_BulletColor : return ( rPara.mnBulletColor != nValue );
428 case ParaAttr_BuHardHeight :
429 case ParaAttr_BulletHeight : return ( rPara.mnBulletHeight != nValue );
430 case ParaAttr_BulletChar : return ( rPara.mnBulletChar != nValue );
431 case ParaAttr_Adjust : return ( rPara.mnAdjust != nValue );
432 case ParaAttr_LineFeed : return ( rPara.mnLineFeed != nValue );
433 case ParaAttr_UpperDist : return ( rPara.mnUpperDist != nValue );
434 case ParaAttr_LowerDist : return ( rPara.mnLowerDist != nValue );
435 case ParaAttr_TextOfs : return ( rPara.mnTextOfs != nValue );
436 case ParaAttr_BulletOfs : return ( rPara.mnBulletOfs != nValue );
437 case ParaAttr_DefaultTab : return ( rPara.mnDefaultTab != nValue );
438 case ParaAttr_BiDi : return ( rPara.mnBiDi != nValue );
439 case CharAttr_Bold : nFlag = 1; break;
440 case CharAttr_Italic : nFlag = 2; break;
441 case CharAttr_Underline : nFlag = 4; break;
442 case CharAttr_Shadow : nFlag = 16; break;
443 case CharAttr_Strikeout : nFlag = 256; break;
444 case CharAttr_Embossed : nFlag = 512; break;
445 case CharAttr_Font : return ( rChar.mnFont != nValue );
446 case CharAttr_AsianOrComplexFont : return ( rChar.mnAsianOrComplexFont != nValue );
447 case CharAttr_Symbol : return true;
448 case CharAttr_FontHeight : return ( rChar.mnFontHeight != nValue );
449 case CharAttr_FontColor : return ( rChar.mnFontColor != nValue );
450 case CharAttr_Escapement : return ( rChar.mnEscapement != nValue );
451 default:
452 break;
454 if ( nFlag )
456 if ( rChar.mnFlags & nFlag )
457 return ( ( nValue & nFlag ) == 0 );
458 else
459 return ( ( nValue & nFlag ) != 0 );
461 return true;
464 // the TxCFStyleAtom stores the text properties that are used
465 // when creating new objects in PowerPoint.
467 void PPTExStyleSheet::WriteTxCFStyleAtom( SvStream& rSt )
469 const PPTExCharLevel& rCharStyle = mpCharSheet[ EPP_TEXTTYPE_Other ]->maCharLevel[ 0 ];
471 sal_uInt16 const nFlags = 0x60 // ??
472 | 0x02 // fontsize;
473 | 0x04; // fontcolor
475 sal_uInt32 nCharFlags = rCharStyle.mnFlags;
476 nCharFlags &= CharAttr_Italic | CharAttr_Bold | CharAttr_Underline | CharAttr_Shadow;
478 rSt.WriteUInt32( EPP_TxCFStyleAtom << 16 ) // recordheader
479 .WriteUInt32( SizeOfTxCFStyleAtom() - 8 )
480 .WriteUInt16( 0x80 | nCharFlags )
481 .WriteUInt16( nFlags )
482 .WriteUInt16( nCharFlags )
483 .WriteInt32( -1 ) // ?
484 .WriteUInt16( rCharStyle.mnFontHeight )
485 .WriteUInt32( sal_uInt32(rCharStyle.mnFontColor) );
488 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */