update dev300-m58
[ooovba.git] / oox / source / drawingml / textparagraphproperties.cxx
blob087293682f22969dd3922d46a07584e9f6612628
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: textparagraphproperties.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/drawingml/textparagraphproperties.hxx"
33 #include <com/sun/star/text/XNumberingRulesSupplier.hpp>
34 #include <com/sun/star/container/XIndexReplace.hpp>
35 #include <com/sun/star/text/HoriOrientation.hpp>
36 #include <com/sun/star/awt/FontDescriptor.hpp>
37 #include <com/sun/star/awt/XBitmap.hpp>
38 #include <com/sun/star/graphic/XGraphic.hpp>
39 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include "oox/helper/helper.hxx"
42 #include "oox/helper/propertyset.hxx"
43 #include "oox/core/namespaces.hxx"
44 #include "oox/drawingml/drawingmltypes.hxx"
45 #include "properties.hxx"
46 #include "tokens.hxx"
48 using rtl::OUString;
49 using namespace ::oox::core;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::beans;
52 using namespace ::com::sun::star::style;
53 using namespace ::com::sun::star::text;
54 using namespace ::com::sun::star::container;
55 using ::com::sun::star::awt::FontDescriptor;
57 namespace oox { namespace drawingml {
59 BulletList::BulletList( )
60 : maBulletColorPtr( new Color() )
64 bool BulletList::is() const
66 return mnNumberingType.hasValue();
69 void BulletList::setBulletChar( const ::rtl::OUString & sChar )
71 mnNumberingType <<= NumberingType::CHAR_SPECIAL;
72 msBulletChar <<= sChar;
75 void BulletList::setGraphic( ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >& rXGraphic )
77 mnNumberingType <<= NumberingType::BITMAP;
78 maGraphic <<= rXGraphic;
81 void BulletList::setNone( )
83 mnNumberingType <<= NumberingType::NUMBER_NONE;
86 void BulletList::setSuffixParenBoth()
88 msNumberingSuffix <<= CREATE_OUSTRING( ")" );
89 msNumberingPrefix <<= CREATE_OUSTRING( "(" );
92 void BulletList::setSuffixParenRight()
94 msNumberingSuffix <<= CREATE_OUSTRING( ")" );
95 msNumberingPrefix <<= OUString();
98 void BulletList::setSuffixPeriod()
100 msNumberingSuffix <<= CREATE_OUSTRING( "." );
101 msNumberingPrefix <<= OUString();
104 void BulletList::setSuffixNone()
106 msNumberingSuffix <<= OUString();
107 msNumberingPrefix <<= OUString();
110 void BulletList::setSuffixMinusRight()
112 msNumberingSuffix <<= CREATE_OUSTRING( "-" );
113 msNumberingPrefix <<= OUString();
116 void BulletList::setType( sal_Int32 nType )
118 // OSL_TRACE( "OOX: set list numbering type %d", nType);
119 switch( nType )
121 case XML_alphaLcParenBoth:
122 mnNumberingType <<= NumberingType::CHARS_LOWER_LETTER;
123 setSuffixParenBoth();
124 break;
125 case XML_alphaLcParenR:
126 mnNumberingType <<= NumberingType::CHARS_LOWER_LETTER;
127 setSuffixParenRight();
128 break;
129 case XML_alphaLcPeriod:
130 mnNumberingType <<= NumberingType::CHARS_LOWER_LETTER;
131 setSuffixPeriod();
132 break;
133 case XML_alphaUcParenBoth:
134 mnNumberingType <<= NumberingType::CHARS_UPPER_LETTER;
135 setSuffixParenBoth();
136 break;
137 case XML_alphaUcParenR:
138 mnNumberingType <<= NumberingType::CHARS_UPPER_LETTER;
139 setSuffixParenRight();
140 break;
141 case XML_alphaUcPeriod:
142 mnNumberingType <<= NumberingType::CHARS_UPPER_LETTER;
143 setSuffixPeriod();
144 break;
145 case XML_arabic1Minus:
146 case XML_arabic2Minus:
147 case XML_arabicDbPeriod:
148 case XML_arabicDbPlain:
149 // TODO
150 break;
151 case XML_arabicParenBoth:
152 mnNumberingType <<= NumberingType::ARABIC;
153 setSuffixParenBoth();
154 break;
155 case XML_arabicParenR:
156 mnNumberingType <<= NumberingType::ARABIC;
157 setSuffixParenRight();
158 break;
159 case XML_arabicPeriod:
160 mnNumberingType <<= NumberingType::ARABIC;
161 setSuffixPeriod();
162 break;
163 case XML_arabicPlain:
164 mnNumberingType <<= NumberingType::ARABIC;
165 setSuffixNone();
166 break;
167 case XML_circleNumDbPlain:
168 case XML_circleNumWdBlackPlain:
169 case XML_circleNumWdWhitePlain:
170 mnNumberingType <<= NumberingType::CIRCLE_NUMBER;
171 break;
172 case XML_ea1ChsPeriod:
173 mnNumberingType <<= NumberingType::NUMBER_UPPER_ZH;
174 setSuffixPeriod();
175 break;
176 case XML_ea1ChsPlain:
177 mnNumberingType <<= NumberingType::NUMBER_UPPER_ZH;
178 setSuffixNone();
179 break;
180 case XML_ea1ChtPeriod:
181 mnNumberingType <<= NumberingType::NUMBER_UPPER_ZH_TW;
182 setSuffixPeriod();
183 break;
184 case XML_ea1ChtPlain:
185 mnNumberingType <<= NumberingType::NUMBER_UPPER_ZH_TW;
186 setSuffixNone();
187 break;
188 case XML_ea1JpnChsDbPeriod:
189 case XML_ea1JpnKorPeriod:
190 case XML_ea1JpnKorPlain:
191 break;
192 case XML_hebrew2Minus:
193 mnNumberingType <<= NumberingType::CHARS_HEBREW;
194 setSuffixMinusRight();
195 break;
196 case XML_hindiAlpha1Period:
197 case XML_hindiAlphaPeriod:
198 case XML_hindiNumParenR:
199 case XML_hindiNumPeriod:
200 // TODO
201 break;
202 case XML_romanLcParenBoth:
203 mnNumberingType <<= NumberingType::ROMAN_LOWER;
204 setSuffixParenBoth();
205 break;
206 case XML_romanLcParenR:
207 mnNumberingType <<= NumberingType::ROMAN_LOWER;
208 setSuffixParenRight();
209 break;
210 case XML_romanLcPeriod:
211 mnNumberingType <<= NumberingType::ROMAN_LOWER;
212 setSuffixPeriod();
213 break;
214 case XML_romanUcParenBoth:
215 mnNumberingType <<= NumberingType::ROMAN_UPPER;
216 setSuffixParenBoth();
217 break;
218 case XML_romanUcParenR:
219 mnNumberingType <<= NumberingType::ROMAN_UPPER;
220 setSuffixParenRight();
221 break;
222 case XML_romanUcPeriod:
223 mnNumberingType <<= NumberingType::ROMAN_UPPER;
224 setSuffixPeriod();
225 break;
226 case XML_thaiAlphaParenBoth:
227 case XML_thaiNumParenBoth:
228 mnNumberingType <<= NumberingType::CHARS_THAI;
229 setSuffixParenBoth();
230 break;
231 case XML_thaiAlphaParenR:
232 case XML_thaiNumParenR:
233 mnNumberingType <<= NumberingType::CHARS_THAI;
234 setSuffixParenRight();
235 break;
236 case XML_thaiAlphaPeriod:
237 case XML_thaiNumPeriod:
238 mnNumberingType <<= NumberingType::CHARS_THAI;
239 setSuffixPeriod();
240 break;
244 void BulletList::setBulletSize(sal_Int16 nSize)
246 mnSize <<= nSize;
250 void BulletList::setFontSize(sal_Int16 nSize)
252 mnFontSize <<= nSize;
255 void BulletList::apply( const BulletList& rSource )
257 if ( rSource.maBulletColorPtr->isUsed() )
258 maBulletColorPtr = rSource.maBulletColorPtr;
259 if ( rSource.mbBulletColorFollowText.hasValue() )
260 mbBulletColorFollowText = rSource.mbBulletColorFollowText;
261 if ( rSource.mbBulletFontFollowText.hasValue() )
262 mbBulletFontFollowText = rSource.mbBulletFontFollowText;
263 maBulletFont.assignIfUsed( rSource.maBulletFont );
264 if ( rSource.msBulletChar.hasValue() )
265 msBulletChar = rSource.msBulletChar;
266 if ( rSource.mnStartAt.hasValue() )
267 mnStartAt = rSource.mnStartAt;
268 if ( rSource.mnNumberingType.hasValue() )
269 mnNumberingType = rSource.mnNumberingType;
270 if ( rSource.msNumberingPrefix.hasValue() )
271 msNumberingPrefix = rSource.msNumberingPrefix;
272 if ( rSource.msNumberingSuffix.hasValue() )
273 msNumberingSuffix = rSource.msNumberingSuffix;
274 if ( rSource.mnSize.hasValue() )
275 mnSize = rSource.mnSize;
276 if ( rSource.mnFontSize.hasValue() )
277 mnFontSize = rSource.mnFontSize;
278 if ( rSource.maStyleName.hasValue() )
279 maStyleName = rSource.maStyleName;
280 if ( rSource.maGraphic.hasValue() )
281 maGraphic = rSource.maGraphic;
284 void BulletList::pushToPropMap( const ::oox::core::XmlFilterBase& rFilterBase, PropertyMap& rPropMap ) const
286 if( msNumberingPrefix.hasValue() )
287 rPropMap[ PROP_Prefix ] = msNumberingPrefix;
288 if( msNumberingSuffix.hasValue() )
289 rPropMap[ PROP_Suffix ] = msNumberingSuffix;
290 if( mnStartAt.hasValue() )
291 rPropMap[ PROP_StartWith ] = mnStartAt;
292 rPropMap[ PROP_Adjust ] <<= HoriOrientation::LEFT;
294 if( mnNumberingType.hasValue() )
295 rPropMap[ PROP_NumberingType ] = mnNumberingType;
297 OUString aBulletFontName;
298 sal_Int16 nBulletFontPitch = 0;
299 sal_Int16 nBulletFontFamily = 0;
300 if( maBulletFont.getFontData( aBulletFontName, nBulletFontPitch, nBulletFontFamily, rFilterBase ) )
302 FontDescriptor aFontDesc;
303 sal_Int16 nFontSize = 0;
304 if( mnFontSize >>= nFontSize )
305 aFontDesc.Height = nFontSize;
307 // TODO move the to the TextFont struct.
308 aFontDesc.Name = aBulletFontName;
309 aFontDesc.Pitch = nBulletFontPitch;
310 aFontDesc.Family = nBulletFontFamily;
311 rPropMap[ PROP_BulletFont ] <<= aFontDesc;
312 rPropMap[ PROP_BulletFontName ] <<= aBulletFontName;
314 if ( msBulletChar.hasValue() )
315 rPropMap[ PROP_BulletChar ] = msBulletChar;
316 if ( maGraphic.hasValue() )
318 Reference< com::sun::star::awt::XBitmap > xBitmap( maGraphic, UNO_QUERY );
319 if ( xBitmap.is() )
320 rPropMap[ PROP_Graphic ] <<= xBitmap;
322 if( mnSize.hasValue() )
323 rPropMap[ PROP_BulletRelSize ] = mnSize;
324 if ( maStyleName.hasValue() )
325 rPropMap[ PROP_CharStyleName ] <<= maStyleName;
326 if ( maBulletColorPtr->isUsed() )
327 rPropMap[ PROP_BulletColor ] <<= maBulletColorPtr->getColor( rFilterBase );
330 TextParagraphProperties::TextParagraphProperties()
331 : mnLevel( 0 )
335 TextParagraphProperties::~TextParagraphProperties()
339 void TextParagraphProperties::apply( const TextParagraphProperties& rSourceProps )
341 maTextParagraphPropertyMap.insert( rSourceProps.maTextParagraphPropertyMap.begin(), rSourceProps.maTextParagraphPropertyMap.end() );
342 maBulletList.apply( rSourceProps.maBulletList );
343 maTextCharacterProperties.assignUsed( rSourceProps.maTextCharacterProperties );
344 if ( rSourceProps.maParaTopMargin.bHasValue )
345 maParaTopMargin = rSourceProps.maParaTopMargin;
346 if ( rSourceProps.maParaBottomMargin.bHasValue )
347 maParaBottomMargin = rSourceProps.maParaBottomMargin;
348 if ( rSourceProps.moParaLeftMargin )
349 moParaLeftMargin = rSourceProps.moParaLeftMargin;
350 if ( rSourceProps.moFirstLineIndentation )
351 moFirstLineIndentation = rSourceProps.moFirstLineIndentation;
354 void TextParagraphProperties::pushToPropSet( const ::oox::core::XmlFilterBase& rFilterBase,
355 const Reference < XPropertySet >& xPropSet, PropertyMap& rioBulletMap, const BulletList* pMasterBuList, sal_Bool bApplyBulletMap, float fCharacterSize ) const
357 PropertySet aPropSet( xPropSet );
358 aPropSet.setProperties( maTextParagraphPropertyMap );
360 sal_Int32 nNumberingType = NumberingType::NUMBER_NONE;
361 if ( maBulletList.mnNumberingType.hasValue() )
362 maBulletList.mnNumberingType >>= nNumberingType;
363 else if ( pMasterBuList && pMasterBuList->mnNumberingType.hasValue() )
364 pMasterBuList->mnNumberingType >>= nNumberingType;
365 if ( nNumberingType == NumberingType::NUMBER_NONE )
366 aPropSet.setProperty< sal_Int16 >( PROP_NumberingLevel, -1 );
368 maBulletList.pushToPropMap( rFilterBase, rioBulletMap );
370 if ( maParaTopMargin.bHasValue )
371 aPropSet.setProperty( PROP_ParaTopMargin, maParaTopMargin.toMargin( getCharHeightPoints( 18.0 ) ) );
372 if ( maParaBottomMargin.bHasValue )
373 aPropSet.setProperty( PROP_ParaBottomMargin, maParaBottomMargin.toMargin( getCharHeightPoints( 18.0 ) ) );
374 if ( nNumberingType == NumberingType::BITMAP )
376 fCharacterSize = getCharHeightPoints( fCharacterSize );
378 com::sun::star::awt::Size aBulletSize;
379 aBulletSize.Width = aBulletSize.Height = static_cast< sal_Int32 >( ( fCharacterSize * ( 2540.0 / 72.0 ) * 0.8 ) );
380 rioBulletMap[ PROP_GraphicSize ] <<= aBulletSize;
383 boost::optional< sal_Int32 > noParaLeftMargin( moParaLeftMargin );
384 boost::optional< sal_Int32 > noFirstLineIndentation( moFirstLineIndentation );
386 if ( nNumberingType != NumberingType::NUMBER_NONE )
388 if ( noParaLeftMargin )
390 rioBulletMap[ PROP_LeftMargin ] <<= static_cast< sal_Int32 >( *noParaLeftMargin );
391 noParaLeftMargin = boost::optional< sal_Int32 >( 0 );
393 if ( noFirstLineIndentation )
395 rioBulletMap[ PROP_FirstLineOffset ] <<= static_cast< sal_Int32 >( *noFirstLineIndentation );
396 noFirstLineIndentation = boost::optional< sal_Int32 >( 0 );
400 if ( bApplyBulletMap )
402 Reference< XIndexReplace > xNumRule;
403 aPropSet.getProperty( xNumRule, PROP_NumberingRules );
404 OSL_ENSURE( xNumRule.is(), "can't get Numbering rules");
406 if( xNumRule.is() )
408 if( !rioBulletMap.empty() )
410 Sequence< PropertyValue > aBulletPropSeq = rioBulletMap.makePropertyValueSequence();
411 xNumRule->replaceByIndex( getLevel(), makeAny( aBulletPropSeq ) );
414 aPropSet.setProperty( PROP_NumberingRules, xNumRule );
417 if ( noParaLeftMargin )
418 aPropSet.setProperty( PROP_ParaLeftMargin, *noParaLeftMargin );
419 if ( noFirstLineIndentation )
420 aPropSet.setProperty( PROP_ParaFirstLineIndent, *noFirstLineIndentation );
423 float TextParagraphProperties::getCharHeightPoints( float fDefault ) const
425 return maTextCharacterProperties.getCharHeightPoints( fDefault );