1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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
];
38 case EPP_TEXTTYPE_Title
:
39 case EPP_TEXTTYPE_CenterTitle
:
42 case EPP_TEXTTYPE_Body
:
43 case EPP_TEXTTYPE_CenterBody
:
44 case EPP_TEXTTYPE_HalfBody
:
45 case EPP_TEXTTYPE_QuarterBody
:
49 case 0 : nFontHeight
= 32; break;
50 case 1 : nFontHeight
= 28; break;
51 case 2 : nFontHeight
= 24; break;
52 default :nFontHeight
= 20; break;
56 case EPP_TEXTTYPE_Notes
:
59 case EPP_TEXTTYPE_notUsed
:
60 case EPP_TEXTTYPE_Other
:
66 rLev
.mnAsianOrComplexFont
= 0xffff;
67 rLev
.mnFontHeight
= nFontHeight
;
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;
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;
111 if ( PropValue::GetPropertyValue( aAny
, rPagePropSet
, "IsBackgroundDark", true ) )
113 nFontColor
= bIsDark
? 0xffffff : 0x000000;
115 nFontColor
.SetTransparency(0xfe);
118 rSt
.WriteUInt16( rLev
.mnFontHeight
)
119 .WriteUInt32( sal_uInt32(nFontColor
) );
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
) :
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
];
148 case EPP_TEXTTYPE_Title
:
149 case EPP_TEXTTYPE_CenterTitle
:
151 case EPP_TEXTTYPE_Body
:
152 case EPP_TEXTTYPE_CenterBody
:
153 case EPP_TEXTTYPE_HalfBody
:
154 case EPP_TEXTTYPE_QuarterBody
:
160 case EPP_TEXTTYPE_Notes
:
169 nBulletChar
= 0x2022;
171 nTextOfs
= bHasBullet
? 0xd8 : 0;
176 nBulletChar
= 0x2013;
183 nBulletChar
= 0x2022;
190 nBulletChar
= 0x2013;
203 rLev
.mbIsBullet
= bHasBullet
;
204 rLev
.mnBulletChar
= nBulletChar
;
205 rLev
.mnBulletFont
= 0;
206 rLev
.mnBulletHeight
= 100;
207 rLev
.mnBulletColor
= 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;
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
);
246 nLineSpacing
= static_cast<sal_Int16
>( static_cast<double>(nLineSpacing
) * pDesc
->Scaling
+ 0.5 );
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
);
255 nLineSpacing
= static_cast<sal_Int16
>( 100.0 * pDesc
->Scaling
+ 0.5 );
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 );
289 if (!(aParagraphObj
.bExtendedParameters
&&
290 aParagraphObj
.meBullet
== css::beans::PropertyState_DIRECT_VALUE
))
293 for ( sal_Int16 i
= 0; i
< 5; i
++ )
295 PPTExParaLevel
& rLevel
= maParaLevel
[ 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
;
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
)
334 rOut
.WriteUInt32( 0x03800000 )
335 .WriteUInt16( nBulletId
)
336 .WriteUInt32( rLev
.mnMappedNumType
)
337 .WriteUInt16( rLev
.mnBulletStart
)
341 sal_uInt32 nParaFlags
= 0x3ffdff;
342 sal_uInt16 nBulletFlags
= ( rLev
.mbIsBullet
) ? 0xf : 0xe;
345 nParaFlags
&= 0x207fff;
347 nParaFlags
&= 0x7fff;
348 sal_uInt32 nBulletColor
= rLev
.mnBulletColor
;
349 if ( nBulletColor
== sal_uInt32(COL_AUTO
) )
351 bool bIsDark
= false;
353 if ( PropValue::GetPropertyValue( aAny
, rPagePropSet
, "IsBackgroundDark", true ) )
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
);
379 rSt
.WriteUInt16( rLev
.mnDefaultTab
)
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
)
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;
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
);
456 if ( rChar
.mnFlags
& nFlag
)
457 return ( ( nValue
& nFlag
) == 0 );
459 return ( ( nValue
& nFlag
) != 0 );
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 // ??
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: */