bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / filter / eppt / pptx-stylesheet.cxx
blob50daceb9089291acf4bc032953096dc43e1bfe6c
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>
26 using namespace ::com::sun::star;
28 PPTExCharSheet::PPTExCharSheet( int nInstance )
30 sal_uInt16 nFontHeight = 24;
32 for ( int nDepth = 0; nDepth < 5; nDepth++ )
34 PPTExCharLevel& rLev = maCharLevel[ nDepth ];
35 switch ( nInstance )
37 case EPP_TEXTTYPE_Title :
38 case EPP_TEXTTYPE_CenterTitle :
39 nFontHeight = 44;
40 break;
41 case EPP_TEXTTYPE_Body :
42 case EPP_TEXTTYPE_CenterBody :
43 case EPP_TEXTTYPE_HalfBody :
44 case EPP_TEXTTYPE_QuarterBody :
46 switch ( nDepth )
48 case 0 : nFontHeight = 32; break;
49 case 1 : nFontHeight = 28; break;
50 case 2 : nFontHeight = 24; break;
51 default :nFontHeight = 20; break;
54 break;
55 case EPP_TEXTTYPE_Notes :
56 nFontHeight = 12;
57 break;
58 case EPP_TEXTTYPE_notUsed :
59 case EPP_TEXTTYPE_Other :
60 nFontHeight = 24;
61 break;
63 rLev.mnFlags = 0;
64 rLev.mnFont = 0;
65 rLev.mnAsianOrComplexFont = 0xffff;
66 rLev.mnFontHeight = nFontHeight;
67 rLev.mnFontColor = 0;
68 rLev.mnEscapement = 0;
72 void PPTExCharSheet::SetStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
73 FontCollection& rFontCollection, int nLevel )
75 PortionObj aPortionObj( rXPropSet, rFontCollection );
77 PPTExCharLevel& rLev = maCharLevel[ nLevel ];
79 if ( aPortionObj.meCharColor == ::com::sun::star::beans::PropertyState_DIRECT_VALUE )
80 rLev.mnFontColor = aPortionObj.mnCharColor;
81 if ( aPortionObj.meCharEscapement == ::com::sun::star::beans::PropertyState_DIRECT_VALUE )
82 rLev.mnEscapement = aPortionObj.mnCharEscapement;
83 if ( aPortionObj.meCharHeight == ::com::sun::star::beans::PropertyState_DIRECT_VALUE )
84 rLev.mnFontHeight = aPortionObj.mnCharHeight;
85 if ( aPortionObj.meFontName == ::com::sun::star::beans::PropertyState_DIRECT_VALUE )
86 rLev.mnFont = aPortionObj.mnFont;
87 if ( aPortionObj.meAsianOrComplexFont == ::com::sun::star::beans::PropertyState_DIRECT_VALUE )
88 rLev.mnAsianOrComplexFont = aPortionObj.mnAsianOrComplexFont;
89 rLev.mnFlags = aPortionObj.mnCharAttr;
92 void PPTExCharSheet::Write( SvStream& rSt, PptEscherEx*, sal_uInt16 nLev, bool, bool bSimpleText,
93 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rPagePropSet )
95 const PPTExCharLevel& rLev = maCharLevel[ nLev ];
97 sal_uInt32 nCharFlags = 0xefffff;
98 if ( bSimpleText )
99 nCharFlags = 0x7ffff;
101 rSt.WriteUInt32( nCharFlags )
102 .WriteUInt16( rLev.mnFlags )
103 .WriteUInt16( rLev.mnFont );
105 sal_uInt32 nFontColor = rLev.mnFontColor;
106 if ( nFontColor == COL_AUTO )
108 bool bIsDark = false;
109 ::com::sun::star::uno::Any aAny;
110 if ( PropValue::GetPropertyValue( aAny, rPagePropSet, OUString( "IsBackgroundDark" ), true ) )
111 aAny >>= bIsDark;
112 nFontColor = bIsDark ? 0xffffff : 0x000000;
114 nFontColor &= 0xffffff;
115 nFontColor |= 0xfe000000;
116 if ( bSimpleText )
118 rSt.WriteUInt16( rLev.mnFontHeight )
119 .WriteUInt32( nFontColor );
121 else
123 rSt.WriteUInt16( rLev.mnAsianOrComplexFont )
124 .WriteUInt16( 0xffff ) // unknown
125 .WriteUInt16( 0xffff ) // unknown
126 .WriteUInt16( rLev.mnFontHeight )
127 .WriteUInt32( 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 ::com::sun::star::uno::Reference< ::com::sun::star::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 == ::com::sun::star::beans::PropertyState_DIRECT_VALUE )
234 rLev.mnAdjust = aParagraphObj.mnTextAdjust;
235 if ( aParagraphObj.meLineSpacing == ::com::sun::star::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 = (sal_Int16)( (double)nLineSpacing * pDesc->Scaling + 0.5 );
249 else
251 if ( rCharLevel.mnFontHeight > (sal_uInt16)( ((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 = (sal_Int16)( (double)100.0 * pDesc->Scaling + 0.5 );
256 else
257 nLineSpacing = 100;
259 else
260 nLineSpacing = (sal_Int16)( (double)nLineSpacing / 4.40972 );
262 rLev.mnLineFeed = nLineSpacing;
264 if ( aParagraphObj.meLineSpacingBottom == ::com::sun::star::beans::PropertyState_DIRECT_VALUE )
265 rLev.mnLowerDist = aParagraphObj.mnLineSpacingBottom;
266 if ( aParagraphObj.meLineSpacingTop == ::com::sun::star::beans::PropertyState_DIRECT_VALUE )
267 rLev.mnUpperDist = aParagraphObj.mnLineSpacingTop;
268 if ( aParagraphObj.meForbiddenRules == ::com::sun::star::beans::PropertyState_DIRECT_VALUE )
270 rLev.mnAsianSettings &=~1;
271 if ( aParagraphObj.mbForbiddenRules )
272 rLev.mnAsianSettings |= 1;
274 if ( aParagraphObj.meParagraphPunctation == ::com::sun::star::beans::PropertyState_DIRECT_VALUE )
276 rLev.mnAsianSettings &=~4;
277 if ( aParagraphObj.mbParagraphPunctation )
278 rLev.mnAsianSettings |= 4;
281 if ( aParagraphObj.meBiDi == ::com::sun::star::beans::PropertyState_DIRECT_VALUE )
282 rLev.mnBiDi = aParagraphObj.mnBiDi;
284 rLev.mbIsBullet = aParagraphObj.mbIsBullet; //( ( aParagraphObj.nBulletFlags & 1 ) != 0 );
286 if ( !nLevel )
288 if (aParagraphObj.bExtendedParameters &&
289 aParagraphObj.meBullet == ::com::sun::star::beans::PropertyState_DIRECT_VALUE)
291 for ( sal_Int16 i = 0; i < 5; i++ )
293 PPTExParaLevel& rLevel = maParaLevel[ i ];
294 if ( i )
295 aParagraphObj.ImplGetNumberingLevel( pBuProv, i, false );
296 rLevel.mnTextOfs = aParagraphObj.nTextOfs;
297 rLevel.mnBulletOfs = (sal_uInt16)aParagraphObj.nBulletOfs;
298 rLevel.mnBulletChar = aParagraphObj.cBulletId;
299 FontCollectionEntry aFontDescEntry( aParagraphObj.aFontDesc.Name, aParagraphObj.aFontDesc.Family,
300 aParagraphObj.aFontDesc.Pitch, aParagraphObj.aFontDesc.CharSet );
301 rLevel.mnBulletFont = (sal_uInt16)rFontCollection.GetId( aFontDescEntry );
302 rLevel.mnBulletHeight = aParagraphObj.nBulletRealSize;
303 rLevel.mnBulletColor = aParagraphObj.nBulletColor;
305 rLevel.mbExtendedBulletsUsed = aParagraphObj.bExtendedBulletsUsed;
306 rLevel.mnBulletId = aParagraphObj.nBulletId;
307 rLevel.mnNumberingType = aParagraphObj.nNumberingType;
308 rLevel.mnBulletStart = aParagraphObj.nStartWith;
309 rLevel.mnMappedNumType = aParagraphObj.nMappedNumType;
315 void PPTExParaSheet::Write( SvStream& rSt, PptEscherEx*, sal_uInt16 nLev, bool, bool bSimpleText,
316 const ::com::sun::star::uno::Reference< ::com::sun::star::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 == COL_AUTO )
351 bool bIsDark = false;
352 ::com::sun::star::uno::Any aAny;
353 if ( PropValue::GetPropertyValue( aAny, rPagePropSet, OUString( "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 mpParaSheet[ nInstance ] = ( nInstance == EPP_TEXTTYPE_notUsed ) ? NULL : new PPTExParaSheet( nInstance, nDefaultTab, pBuProv );
392 mpCharSheet[ nInstance ] = ( nInstance == EPP_TEXTTYPE_notUsed ) ? NULL : new PPTExCharSheet( nInstance );
396 PPTExStyleSheet::~PPTExStyleSheet()
398 for ( int nInstance = EPP_TEXTTYPE_Title; nInstance <= EPP_TEXTTYPE_QuarterBody; nInstance++ )
400 if ( nInstance == EPP_TEXTTYPE_notUsed )
401 continue;
403 delete mpParaSheet[ nInstance ];
404 delete mpCharSheet[ nInstance ];
408 void PPTExStyleSheet::SetStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
409 FontCollection& rFontCollection, int nInstance, int nLevel )
411 if ( nInstance == EPP_TEXTTYPE_notUsed )
412 return;
413 mpCharSheet[ nInstance ]->SetStyleSheet( rXPropSet, rFontCollection, nLevel );
414 mpParaSheet[ nInstance ]->SetStyleSheet( rXPropSet, rFontCollection, nLevel, mpCharSheet[ nInstance ]->maCharLevel[ nLevel ] );
417 bool PPTExStyleSheet::IsHardAttribute( sal_uInt32 nInstance, sal_uInt32 nLevel, PPTExTextAttr eAttr, sal_uInt32 nValue )
419 const PPTExParaLevel& rPara = mpParaSheet[ nInstance ]->maParaLevel[ nLevel ];
420 const PPTExCharLevel& rChar = mpCharSheet[ nInstance ]->maCharLevel[ nLevel ];
422 sal_uInt32 nFlag = 0;
424 switch ( eAttr )
426 case ParaAttr_BulletOn : return ( rPara.mbIsBullet ) ? nValue == 0 : nValue != 0;
427 case ParaAttr_BuHardFont :
428 case ParaAttr_BulletFont : return ( rPara.mnBulletFont != nValue );
429 case ParaAttr_BuHardColor :
430 case ParaAttr_BulletColor : return ( rPara.mnBulletColor != nValue );
431 case ParaAttr_BuHardHeight :
432 case ParaAttr_BulletHeight : return ( rPara.mnBulletHeight != nValue );
433 case ParaAttr_BulletChar : return ( rPara.mnBulletChar != nValue );
434 case ParaAttr_Adjust : return ( rPara.mnAdjust != nValue );
435 case ParaAttr_LineFeed : return ( rPara.mnLineFeed != nValue );
436 case ParaAttr_UpperDist : return ( rPara.mnUpperDist != nValue );
437 case ParaAttr_LowerDist : return ( rPara.mnLowerDist != nValue );
438 case ParaAttr_TextOfs : return ( rPara.mnTextOfs != nValue );
439 case ParaAttr_BulletOfs : return ( rPara.mnBulletOfs != nValue );
440 case ParaAttr_DefaultTab : return ( rPara.mnDefaultTab != nValue );
441 case ParaAttr_BiDi : return ( rPara.mnBiDi != nValue );
442 case CharAttr_Bold : nFlag = 1; break;
443 case CharAttr_Italic : nFlag = 2; break;
444 case CharAttr_Underline : nFlag = 4; break;
445 case CharAttr_Shadow : nFlag = 16; break;
446 case CharAttr_Strikeout : nFlag = 256; break;
447 case CharAttr_Embossed : nFlag = 512; break;
448 case CharAttr_Font : return ( rChar.mnFont != nValue );
449 case CharAttr_AsianOrComplexFont : return ( rChar.mnAsianOrComplexFont != nValue );
450 case CharAttr_Symbol : return true;
451 case CharAttr_FontHeight : return ( rChar.mnFontHeight != nValue );
452 case CharAttr_FontColor : return ( rChar.mnFontColor != nValue );
453 case CharAttr_Escapement : return ( rChar.mnEscapement != nValue );
454 default:
455 break;
457 if ( nFlag )
459 if ( rChar.mnFlags & nFlag )
460 return ( ( nValue & nFlag ) == 0 );
461 else
462 return ( ( nValue & nFlag ) != 0 );
464 return true;
467 // the TxCFStyleAtom stores the text properties that are used
468 // when creating new objects in PowerPoint.
470 void PPTExStyleSheet::WriteTxCFStyleAtom( SvStream& rSt )
472 const PPTExCharLevel& rCharStyle = mpCharSheet[ EPP_TEXTTYPE_Other ]->maCharLevel[ 0 ];
474 sal_uInt16 nFlags = 0x60 // ??
475 | 0x02 // fontsize;
476 | 0x04; // fontcolor
478 sal_uInt32 nCharFlags = rCharStyle.mnFlags;
479 nCharFlags &= CharAttr_Italic | CharAttr_Bold | CharAttr_Underline | CharAttr_Shadow;
481 rSt.WriteUInt32( EPP_TxCFStyleAtom << 16 ) // recordheader
482 .WriteUInt32( SizeOfTxCFStyleAtom() - 8 )
483 .WriteUInt16( 0x80 | nCharFlags )
484 .WriteUInt16( nFlags )
485 .WriteUInt16( nCharFlags )
486 .WriteInt32( -1 ) // ?
487 .WriteUInt16( rCharStyle.mnFontHeight )
488 .WriteUInt32( rCharStyle.mnFontColor );
491 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */