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 <tools/UnitConversion.hxx>
25 #include <editeng/svxenum.hxx>
26 #include <com/sun/star/beans/XPropertySet.hpp>
28 using namespace ::com::sun::star
;
30 PPTExCharSheet::PPTExCharSheet( int nInstance
)
32 sal_uInt16 nFontHeight
= 24;
34 for ( int nDepth
= 0; nDepth
< 5; nDepth
++ )
36 PPTExCharLevel
& rLev
= maCharLevel
[ nDepth
];
39 case EPP_TEXTTYPE_Title
:
40 case EPP_TEXTTYPE_CenterTitle
:
43 case EPP_TEXTTYPE_Body
:
44 case EPP_TEXTTYPE_CenterBody
:
45 case EPP_TEXTTYPE_HalfBody
:
46 case EPP_TEXTTYPE_QuarterBody
:
50 case 0 : nFontHeight
= 32; break;
51 case 1 : nFontHeight
= 28; break;
52 case 2 : nFontHeight
= 24; break;
53 default :nFontHeight
= 20; break;
57 case EPP_TEXTTYPE_Notes
:
60 case EPP_TEXTTYPE_notUsed
:
61 case EPP_TEXTTYPE_Other
:
67 rLev
.mnAsianOrComplexFont
= 0xffff;
68 rLev
.mnFontHeight
= nFontHeight
;
70 rLev
.mnEscapement
= 0;
74 void PPTExCharSheet::SetStyleSheet( const css::uno::Reference
< css::beans::XPropertySet
> & rXPropSet
,
75 FontCollection
& rFontCollection
, int nLevel
)
77 PortionObj
aPortionObj( rXPropSet
, rFontCollection
);
79 PPTExCharLevel
& rLev
= maCharLevel
[ nLevel
];
81 if ( aPortionObj
.meCharColor
== css::beans::PropertyState_DIRECT_VALUE
)
82 rLev
.mnFontColor
= Color(ColorTransparency
, aPortionObj
.mnCharColor
);
83 if ( aPortionObj
.meCharEscapement
== css::beans::PropertyState_DIRECT_VALUE
)
84 rLev
.mnEscapement
= aPortionObj
.mnCharEscapement
;
85 if ( aPortionObj
.meCharHeight
== css::beans::PropertyState_DIRECT_VALUE
)
86 rLev
.mnFontHeight
= aPortionObj
.mnCharHeight
;
87 if ( aPortionObj
.meFontName
== css::beans::PropertyState_DIRECT_VALUE
)
88 rLev
.mnFont
= aPortionObj
.mnFont
;
89 if ( aPortionObj
.meAsianOrComplexFont
== css::beans::PropertyState_DIRECT_VALUE
)
90 rLev
.mnAsianOrComplexFont
= aPortionObj
.mnAsianOrComplexFont
;
91 rLev
.mnFlags
= aPortionObj
.mnCharAttr
;
94 void PPTExCharSheet::Write( SvStream
& rSt
, sal_uInt16 nLev
, bool bSimpleText
,
95 const css::uno::Reference
< css::beans::XPropertySet
> & rPagePropSet
)
97 const PPTExCharLevel
& rLev
= maCharLevel
[ nLev
];
99 sal_uInt32 nCharFlags
= 0xefffff;
101 nCharFlags
= 0x7ffff;
103 rSt
.WriteUInt32( nCharFlags
)
104 .WriteUInt16( rLev
.mnFlags
)
105 .WriteUInt16( rLev
.mnFont
);
107 Color nFontColor
= rLev
.mnFontColor
;
108 if ( nFontColor
== COL_AUTO
)
110 bool bIsDark
= false;
112 if ( PropValue::GetPropertyValue( aAny
, rPagePropSet
, u
"IsBackgroundDark"_ustr
, true ) )
114 nFontColor
= Color(ColorTransparency
, bIsDark
? 0xffffff : 0x000000);
116 nFontColor
.SetAlpha(1);
119 rSt
.WriteUInt16( rLev
.mnFontHeight
)
120 .WriteUInt32( sal_uInt32(nFontColor
) );
124 rSt
.WriteUInt16( rLev
.mnAsianOrComplexFont
)
125 .WriteUInt16( 0xffff ) // unknown
126 .WriteUInt16( 0xffff ) // unknown
127 .WriteUInt16( rLev
.mnFontHeight
)
128 .WriteUInt32( sal_uInt32(nFontColor
) )
129 .WriteUInt16( rLev
.mnEscapement
);
133 PPTExParaSheet::PPTExParaSheet( int nInstance
, sal_uInt16 nDefaultTab
, PPTExBulletProvider
* pProv
) :
135 mnInstance ( nInstance
)
137 bool bHasBullet
= false;
139 sal_uInt16 nUpperDist
= 0;
140 sal_uInt16 nBulletChar
= 0x2022;
141 sal_uInt16 nBulletOfs
= 0;
142 sal_uInt16 nTextOfs
= 0;
144 for ( int nDepth
= 0; nDepth
< 5; nDepth
++ )
146 PPTExParaLevel
& rLev
= maParaLevel
[ nDepth
];
149 case EPP_TEXTTYPE_Title
:
150 case EPP_TEXTTYPE_CenterTitle
:
152 case EPP_TEXTTYPE_Body
:
153 case EPP_TEXTTYPE_CenterBody
:
154 case EPP_TEXTTYPE_HalfBody
:
155 case EPP_TEXTTYPE_QuarterBody
:
161 case EPP_TEXTTYPE_Notes
:
170 nBulletChar
= 0x2022;
172 nTextOfs
= bHasBullet
? 0xd8 : 0;
177 nBulletChar
= 0x2013;
184 nBulletChar
= 0x2022;
191 nBulletChar
= 0x2013;
204 rLev
.mbIsBullet
= bHasBullet
;
205 rLev
.mnBulletChar
= nBulletChar
;
206 rLev
.mnBulletFont
= 0;
207 rLev
.mnBulletHeight
= 100;
208 rLev
.mnBulletColor
= 0;
210 rLev
.mnLineFeed
= 100;
211 rLev
.mnLowerDist
= 0;
212 rLev
.mnUpperDist
= nUpperDist
;
213 rLev
.mnTextOfs
= nTextOfs
;
214 rLev
.mnBulletOfs
= nBulletOfs
;
215 rLev
.mnDefaultTab
= nDefaultTab
;
216 rLev
.mnAsianSettings
= 2;
219 rLev
.mbExtendedBulletsUsed
= false;
220 rLev
.mnBulletId
= 0xffff;
221 rLev
.mnBulletStart
= 0;
222 rLev
.mnMappedNumType
= 0;
223 rLev
.mnNumberingType
= 0;
227 void PPTExParaSheet::SetStyleSheet( const css::uno::Reference
< css::beans::XPropertySet
> & rXPropSet
,
228 FontCollection
& rFontCollection
, int nLevel
, const PPTExCharLevel
& rCharLevel
)
230 ParagraphObj
aParagraphObj( rXPropSet
, pBuProv
);
231 aParagraphObj
.CalculateGraphicBulletSize( rCharLevel
.mnFontHeight
);
232 PPTExParaLevel
& rLev
= maParaLevel
[ nLevel
];
234 if ( aParagraphObj
.meTextAdjust
== css::beans::PropertyState_DIRECT_VALUE
)
235 rLev
.mnAdjust
= aParagraphObj
.mnTextAdjust
;
236 if ( aParagraphObj
.meLineSpacing
== css::beans::PropertyState_DIRECT_VALUE
)
238 sal_Int16 nLineSpacing
= aParagraphObj
.mnLineSpacing
;
239 if ( nLineSpacing
> 0 ) // if nLinespacing is < 0 the linespacing is an absolute spacing
241 bool bFixedLineSpacing
= false;
242 uno::Any aAny
= rXPropSet
->getPropertyValue(u
"FontIndependentLineSpacing"_ustr
);
243 if( !(aAny
>>= bFixedLineSpacing
) || !bFixedLineSpacing
)
245 const FontCollectionEntry
* pDesc
= rFontCollection
.GetById( rCharLevel
.mnFont
);
247 nLineSpacing
= static_cast<sal_Int16
>( static_cast<double>(nLineSpacing
) * pDesc
->Scaling
+ 0.5 );
252 if ( rCharLevel
.mnFontHeight
> o3tl::make_unsigned(o3tl::convert(-nLineSpacing
, o3tl::Length::mm100
, o3tl::Length::pt
) ) )
254 const FontCollectionEntry
* pDesc
= rFontCollection
.GetById( rCharLevel
.mnFont
);
256 nLineSpacing
= static_cast<sal_Int16
>( 100.0 * pDesc
->Scaling
+ 0.5 );
261 nLineSpacing
= static_cast<sal_Int16
>(convertMm100ToMasterUnit(nLineSpacing
));
263 rLev
.mnLineFeed
= nLineSpacing
;
265 if ( aParagraphObj
.meLineSpacingBottom
== css::beans::PropertyState_DIRECT_VALUE
)
266 rLev
.mnLowerDist
= aParagraphObj
.mnLineSpacingBottom
;
267 if ( aParagraphObj
.meLineSpacingTop
== css::beans::PropertyState_DIRECT_VALUE
)
268 rLev
.mnUpperDist
= aParagraphObj
.mnLineSpacingTop
;
269 if ( aParagraphObj
.meForbiddenRules
== css::beans::PropertyState_DIRECT_VALUE
)
271 rLev
.mnAsianSettings
&=~1;
272 if ( aParagraphObj
.mbForbiddenRules
)
273 rLev
.mnAsianSettings
|= 1;
275 if ( aParagraphObj
.meParagraphPunctation
== css::beans::PropertyState_DIRECT_VALUE
)
277 rLev
.mnAsianSettings
&=~4;
278 if ( aParagraphObj
.mbParagraphPunctation
)
279 rLev
.mnAsianSettings
|= 4;
282 if ( aParagraphObj
.meBiDi
== css::beans::PropertyState_DIRECT_VALUE
)
283 rLev
.mnBiDi
= aParagraphObj
.mnBiDi
;
285 rLev
.mbIsBullet
= aParagraphObj
.mbIsBullet
; //( ( aParagraphObj.nBulletFlags & 1 ) != 0 );
290 if (!(aParagraphObj
.bExtendedParameters
&&
291 aParagraphObj
.meBullet
== css::beans::PropertyState_DIRECT_VALUE
))
294 for ( sal_Int16 i
= 0; i
< 5; i
++ )
296 PPTExParaLevel
& rLevel
= maParaLevel
[ i
];
298 aParagraphObj
.ImplGetNumberingLevel( pBuProv
, i
, false, false );
299 rLevel
.mnTextOfs
= aParagraphObj
.nTextOfs
;
300 rLevel
.mnBulletOfs
= static_cast<sal_uInt16
>(aParagraphObj
.nBulletOfs
);
301 rLevel
.mnBulletChar
= aParagraphObj
.cBulletId
;
302 FontCollectionEntry
aFontDescEntry( aParagraphObj
.aFontDesc
.Name
, aParagraphObj
.aFontDesc
.Family
,
303 aParagraphObj
.aFontDesc
.Pitch
, aParagraphObj
.aFontDesc
.CharSet
);
304 rLevel
.mnBulletFont
= static_cast<sal_uInt16
>(rFontCollection
.GetId( aFontDescEntry
));
305 rLevel
.mnBulletHeight
= aParagraphObj
.nBulletRealSize
;
306 rLevel
.mnBulletColor
= aParagraphObj
.nBulletColor
;
308 rLevel
.mbExtendedBulletsUsed
= aParagraphObj
.bExtendedBulletsUsed
;
309 rLevel
.mnBulletId
= aParagraphObj
.nBulletId
;
310 rLevel
.mnNumberingType
= aParagraphObj
.nNumberingType
;
311 rLevel
.mnBulletStart
= aParagraphObj
.nStartWith
;
312 rLevel
.mnMappedNumType
= aParagraphObj
.nMappedNumType
;
316 void PPTExParaSheet::Write( SvStream
& rSt
, sal_uInt16 nLev
, bool bSimpleText
,
317 const css::uno::Reference
< css::beans::XPropertySet
> & rPagePropSet
)
319 const PPTExParaLevel
& rLev
= maParaLevel
[ nLev
];
321 if ( maParaLevel
[ 0 ].mbExtendedBulletsUsed
|| maParaLevel
[ 1 ].mbExtendedBulletsUsed
||
322 maParaLevel
[ 2 ].mbExtendedBulletsUsed
|| maParaLevel
[ 3 ].mbExtendedBulletsUsed
||
323 maParaLevel
[ 4 ].mbExtendedBulletsUsed
)
325 SvStream
& rOut
= pBuProv
->aBuExMasterStream
;
328 rOut
.WriteUInt32( ( EPP_PST_ExtendedParagraphMasterAtom
<< 16 ) | ( mnInstance
<< 4 ) )
329 .WriteUInt32( 5 * 16 + 2 )
330 .WriteUInt16( 5 ); // depth
332 sal_uInt16 nBulletId
= rLev
.mnBulletId
;
333 if ( rLev
.mnNumberingType
!= SVX_NUM_BITMAP
)
335 rOut
.WriteUInt32( 0x03800000 )
336 .WriteUInt16( nBulletId
)
337 .WriteUInt32( rLev
.mnMappedNumType
)
338 .WriteUInt16( rLev
.mnBulletStart
)
342 sal_uInt32 nParaFlags
= 0x3ffdff;
343 sal_uInt16 nBulletFlags
= ( rLev
.mbIsBullet
) ? 0xf : 0xe;
346 nParaFlags
&= 0x207fff;
348 nParaFlags
&= 0x7fff;
349 sal_uInt32 nBulletColor
= rLev
.mnBulletColor
;
350 if ( nBulletColor
== sal_uInt32(COL_AUTO
) )
352 bool bIsDark
= false;
354 if ( PropValue::GetPropertyValue( aAny
, rPagePropSet
, u
"IsBackgroundDark"_ustr
, true ) )
356 nBulletColor
= bIsDark
? 0xffffff : 0x000000;
358 nBulletColor
&= 0xffffff;
359 nBulletColor
|= 0xfe000000;
360 rSt
.WriteUInt32( nParaFlags
)
361 .WriteUInt16( nBulletFlags
)
362 .WriteUInt16( rLev
.mnBulletChar
)
363 .WriteUInt16( rLev
.mnBulletFont
)
364 .WriteUInt16( rLev
.mnBulletHeight
)
365 .WriteUInt32( nBulletColor
)
366 .WriteUInt16( rLev
.mnAdjust
)
367 .WriteUInt16( rLev
.mnLineFeed
)
368 .WriteUInt16( rLev
.mnUpperDist
)
369 .WriteUInt16( rLev
.mnLowerDist
)
370 .WriteUInt16( rLev
.mnTextOfs
)
371 .WriteUInt16( rLev
.mnBulletOfs
);
373 if ( bSimpleText
|| nLev
)
375 if ( nParaFlags
& 0x200000 )
376 rSt
.WriteUInt16( rLev
.mnBiDi
);
380 rSt
.WriteUInt16( rLev
.mnDefaultTab
)
383 .WriteUInt16( rLev
.mnAsianSettings
)
384 .WriteUInt16( rLev
.mnBiDi
);
388 PPTExStyleSheet::PPTExStyleSheet( sal_uInt16 nDefaultTab
, PPTExBulletProvider
* pBuProv
)
390 for ( int nInstance
= EPP_TEXTTYPE_Title
; nInstance
<= EPP_TEXTTYPE_QuarterBody
; nInstance
++ )
392 if (nInstance
!= EPP_TEXTTYPE_notUsed
)
394 mpParaSheet
[ nInstance
].reset(new PPTExParaSheet( nInstance
, nDefaultTab
, pBuProv
));
395 mpCharSheet
[ nInstance
].reset(new PPTExCharSheet( nInstance
));
400 PPTExStyleSheet::~PPTExStyleSheet()
404 void PPTExStyleSheet::SetStyleSheet( const css::uno::Reference
< css::beans::XPropertySet
> & rXPropSet
,
405 FontCollection
& rFontCollection
, int nInstance
, int nLevel
)
407 if ( nInstance
== EPP_TEXTTYPE_notUsed
)
409 mpCharSheet
[ nInstance
]->SetStyleSheet( rXPropSet
, rFontCollection
, nLevel
);
410 mpParaSheet
[ nInstance
]->SetStyleSheet( rXPropSet
, rFontCollection
, nLevel
, mpCharSheet
[ nInstance
]->maCharLevel
[ nLevel
] );
413 bool PPTExStyleSheet::IsHardAttribute( sal_uInt32 nInstance
, sal_uInt32 nLevel
, PPTExTextAttr eAttr
, sal_uInt32 nValue
)
415 assert(nInstance
< PPTEX_STYLESHEETENTRIES
&& nLevel
< 5);
417 const PPTExParaLevel
& rPara
= mpParaSheet
[ nInstance
]->maParaLevel
[ nLevel
];
418 const PPTExCharLevel
& rChar
= mpCharSheet
[ nInstance
]->maCharLevel
[ nLevel
];
420 sal_uInt32 nFlag
= 0;
424 case ParaAttr_BulletOn
: return ( rPara
.mbIsBullet
) ? nValue
== 0 : nValue
!= 0;
425 case ParaAttr_BuHardFont
:
426 case ParaAttr_BulletFont
: return ( rPara
.mnBulletFont
!= nValue
);
427 case ParaAttr_BuHardColor
:
428 case ParaAttr_BulletColor
: return ( rPara
.mnBulletColor
!= nValue
);
429 case ParaAttr_BuHardHeight
:
430 case ParaAttr_BulletHeight
: return ( rPara
.mnBulletHeight
!= nValue
);
431 case ParaAttr_BulletChar
: return ( rPara
.mnBulletChar
!= nValue
);
432 case ParaAttr_Adjust
: return ( rPara
.mnAdjust
!= nValue
);
433 case ParaAttr_LineFeed
: return ( rPara
.mnLineFeed
!= nValue
);
434 case ParaAttr_UpperDist
: return ( rPara
.mnUpperDist
!= nValue
);
435 case ParaAttr_LowerDist
: return ( rPara
.mnLowerDist
!= nValue
);
436 case ParaAttr_TextOfs
: return ( rPara
.mnTextOfs
!= nValue
);
437 case ParaAttr_BulletOfs
: return ( rPara
.mnBulletOfs
!= nValue
);
438 case ParaAttr_DefaultTab
: return ( rPara
.mnDefaultTab
!= nValue
);
439 case ParaAttr_BiDi
: return ( rPara
.mnBiDi
!= nValue
);
440 case CharAttr_Bold
: nFlag
= 1; break;
441 case CharAttr_Italic
: nFlag
= 2; break;
442 case CharAttr_Underline
: nFlag
= 4; break;
443 case CharAttr_Shadow
: nFlag
= 16; break;
444 case CharAttr_Strikeout
: nFlag
= 256; break;
445 case CharAttr_Embossed
: nFlag
= 512; break;
446 case CharAttr_Font
: return ( rChar
.mnFont
!= nValue
);
447 case CharAttr_AsianOrComplexFont
: return ( rChar
.mnAsianOrComplexFont
!= nValue
);
448 case CharAttr_Symbol
: return true;
449 case CharAttr_FontHeight
: return ( rChar
.mnFontHeight
!= nValue
);
450 case CharAttr_FontColor
: return ( rChar
.mnFontColor
!= Color(ColorTransparency
, nValue
) );
451 case CharAttr_Escapement
: return ( rChar
.mnEscapement
!= nValue
);
457 if ( rChar
.mnFlags
& nFlag
)
458 return ( ( nValue
& nFlag
) == 0 );
460 return ( ( nValue
& nFlag
) != 0 );
465 // the TxCFStyleAtom stores the text properties that are used
466 // when creating new objects in PowerPoint.
468 void PPTExStyleSheet::WriteTxCFStyleAtom( SvStream
& rSt
)
470 const PPTExCharLevel
& rCharStyle
= mpCharSheet
[ EPP_TEXTTYPE_Other
]->maCharLevel
[ 0 ];
472 sal_uInt16
const nFlags
= 0x60 // ??
476 sal_uInt32 nCharFlags
= rCharStyle
.mnFlags
;
477 nCharFlags
&= CharAttr_Italic
| CharAttr_Bold
| CharAttr_Underline
| CharAttr_Shadow
;
479 rSt
.WriteUInt32( EPP_TxCFStyleAtom
<< 16 ) // recordheader
480 .WriteUInt32( SizeOfTxCFStyleAtom() - 8 )
481 .WriteUInt16( 0x80 | nCharFlags
)
482 .WriteUInt16( nFlags
)
483 .WriteUInt16( nCharFlags
)
484 .WriteInt32( -1 ) // ?
485 .WriteUInt16( rCharStyle
.mnFontHeight
)
486 .WriteUInt32( sal_uInt32(rCharStyle
.mnFontColor
) );
489 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */