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 "oox/drawingml/textparagraphpropertiescontext.hxx"
22 #include <com/sun/star/text/WritingMode.hpp>
23 #include <com/sun/star/awt/FontDescriptor.hpp>
25 #include "oox/drawingml/colorchoicecontext.hxx"
26 #include "oox/drawingml/textcharacterpropertiescontext.hxx"
27 #include "oox/drawingml/fillproperties.hxx"
28 #include "oox/helper/attributelist.hxx"
29 #include "textspacingcontext.hxx"
30 #include "texttabstoplistcontext.hxx"
32 using namespace ::oox::core
;
33 using ::com::sun::star::awt::FontDescriptor
;
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::xml::sax
;
36 using namespace ::com::sun::star::style
;
37 using namespace ::com::sun::star::text
;
39 namespace oox
{ namespace drawingml
{
41 // CT_TextParagraphProperties
42 TextParagraphPropertiesContext::TextParagraphPropertiesContext( ContextHandler
& rParent
,
43 const Reference
< XFastAttributeList
>& xAttribs
,
44 TextParagraphProperties
& rTextParagraphProperties
)
45 : ContextHandler( rParent
)
46 , mrTextParagraphProperties( rTextParagraphProperties
)
47 , mrSpaceBefore( rTextParagraphProperties
.getParaTopMargin() )
48 , mrSpaceAfter( rTextParagraphProperties
.getParaBottomMargin() )
49 , mrBulletList( rTextParagraphProperties
.getBulletList() )
52 AttributeList
attribs( xAttribs
);
54 PropertyMap
& rPropertyMap( mrTextParagraphProperties
.getTextParagraphPropertyMap() );
57 rPropertyMap
[ PROP_ParaAdjust
] <<= GetParaAdjust( xAttribs
->getOptionalValueToken( XML_algn
, XML_l
) );
58 // TODO see to do the same with RubyAdjust
61 // sValue = xAttribs->getOptionalValue( XML_defTabSz ); SJ: we need to be able to set the default tab size for each text object,
62 // this is possible at the moment only for the whole document.
63 // sal_Int32 nDefTabSize = ( sValue.getLength() == 0 ? 0 : GetCoordinate( sValue ) );
66 // bool bEaLineBrk = attribs.getBool( XML_eaLnBrk, true );
67 if ( xAttribs
->hasAttribute( XML_latinLnBrk
) )
69 bool bLatinLineBrk
= attribs
.getBool( XML_latinLnBrk
, true );
70 rPropertyMap
[ PROP_ParaIsHyphenation
] <<= bLatinLineBrk
;
72 // TODO see what to do with Asian hyphenation
74 // ST_TextFontAlignType
76 // sal_Int32 nFontAlign = xAttribs->getOptionalValueToken( XML_fontAlgn, XML_base );
78 if ( xAttribs
->hasAttribute( XML_hangingPunct
) )
80 bool bHangingPunct
= attribs
.getBool( XML_hangingPunct
, false );
81 rPropertyMap
[ PROP_ParaIsHangingPunctuation
] <<= bHangingPunct
;
85 if ( xAttribs
->hasAttribute( XML_indent
) )
87 sValue
= xAttribs
->getOptionalValue( XML_indent
);
88 mrTextParagraphProperties
.getFirstLineIndentation() = boost::optional
< sal_Int32
>( sValue
.isEmpty() ? 0 : GetCoordinate( sValue
) );
91 // ST_TextIndentLevelType
92 // -1 is an invalid value and denote the lack of level
93 sal_Int32 nLevel
= attribs
.getInteger( XML_lvl
, 0 );
94 if( nLevel
> 8 || nLevel
< 0 )
99 mrTextParagraphProperties
.setLevel( static_cast< sal_Int16
>( nLevel
) );
101 char name
[] = "Outline X";
102 name
[8] = static_cast<char>( '1' + nLevel
);
103 const OUString
sStyleNameValue( OUString::createFromAscii( name
) );
104 mrBulletList
.setStyleName( sStyleNameValue
);
108 if ( xAttribs
->hasAttribute( XML_marL
) )
110 sValue
= xAttribs
->getOptionalValue( XML_marL
);
111 mrTextParagraphProperties
.getParaLeftMargin() = boost::optional
< sal_Int32
>( sValue
.isEmpty() ? 0 : GetCoordinate( sValue
) );
115 if ( xAttribs
->hasAttribute( XML_marR
) )
117 sValue
= xAttribs
->getOptionalValue( XML_marR
);
118 sal_Int32 nMarR
= sValue
.isEmpty() ? 0 : GetCoordinate( sValue
) ;
119 rPropertyMap
[ PROP_ParaRightMargin
] <<= nMarR
;
122 if ( xAttribs
->hasAttribute( XML_rtl
) )
124 bool bRtl
= attribs
.getBool( XML_rtl
, false );
125 rPropertyMap
[ PROP_TextWritingMode
] <<= ( bRtl
? WritingMode_RL_TB
: WritingMode_LR_TB
);
131 TextParagraphPropertiesContext::~TextParagraphPropertiesContext()
133 PropertyMap
& rPropertyMap( mrTextParagraphProperties
.getTextParagraphPropertyMap() );
134 if ( maLineSpacing
.bHasValue
)
135 rPropertyMap
[ PROP_ParaLineSpacing
] <<= maLineSpacing
.toLineSpacing();
137 rPropertyMap
[ PROP_ParaLineSpacing
] <<= ::com::sun::star::style::LineSpacing( ::com::sun::star::style::LineSpacingMode::PROP
, 100 );
140 ::std::list
< TabStop
>::size_type nTabCount
= maTabList
.size();
143 Sequence
< TabStop
> aSeq( nTabCount
);
144 TabStop
* aArray
= aSeq
.getArray();
145 OSL_ENSURE( aArray
!= NULL
, "sequence array is NULL" );
146 ::std::copy( maTabList
.begin(), maTabList
.end(), aArray
);
147 rPropertyMap
[ PROP_ParaTabStops
] <<= aSeq
;
150 if ( mxBlipProps
.get() && mxBlipProps
->mxGraphic
.is() )
151 mrBulletList
.setGraphic( mxBlipProps
->mxGraphic
);
153 if( mrBulletList
.is() )
154 rPropertyMap
[ PROP_IsNumbering
] <<= sal_True
;
155 sal_Int16 nLevel
= mrTextParagraphProperties
.getLevel();
156 rPropertyMap
[ PROP_NumberingLevel
] <<= nLevel
;
157 rPropertyMap
[ PROP_NumberingIsNumber
] <<= sal_True
;
160 // --------------------------------------------------------------------
162 void TextParagraphPropertiesContext::endFastElement( sal_Int32
) throw (SAXException
, RuntimeException
)
168 // --------------------------------------------------------------------
170 Reference
< XFastContextHandler
> TextParagraphPropertiesContext::createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& rXAttributes
) throw (SAXException
, RuntimeException
)
172 AttributeList
aAttribs( rXAttributes
);
173 Reference
< XFastContextHandler
> xRet
;
174 switch( aElementToken
)
176 case A_TOKEN( lnSpc
): // CT_TextSpacing
177 xRet
.set( new TextSpacingContext( *this, maLineSpacing
) );
179 case A_TOKEN( spcBef
): // CT_TextSpacing
180 xRet
.set( new TextSpacingContext( *this, mrSpaceBefore
) );
182 case A_TOKEN( spcAft
): // CT_TextSpacing
183 xRet
.set( new TextSpacingContext( *this, mrSpaceAfter
) );
186 // EG_TextBulletColor
187 case A_TOKEN( buClrTx
): // CT_TextBulletColorFollowText ???
188 mrBulletList
.mbBulletColorFollowText
<<= sal_True
;
190 case A_TOKEN( buClr
): // CT_Color
191 xRet
.set( new ColorContext( *this, *mrBulletList
.maBulletColorPtr
) );
195 case A_TOKEN( buSzTx
): // CT_TextBulletSizeFollowText
196 mrBulletList
.setBulletSize(100);
198 case A_TOKEN( buSzPct
): // CT_TextBulletSizePercent
199 mrBulletList
.setBulletSize( static_cast<sal_Int16
>( GetPercent( rXAttributes
->getOptionalValue( XML_val
) ) / 1000 ) );
201 case A_TOKEN( buSzPts
): // CT_TextBulletSizePoint
202 mrBulletList
.setBulletSize(0);
203 mrBulletList
.setFontSize( static_cast<sal_Int16
>(GetTextSize( rXAttributes
->getOptionalValue( XML_val
) ) ) );
206 // EG_TextBulletTypeface
207 case A_TOKEN( buFontTx
): // CT_TextBulletTypefaceFollowText
208 mrBulletList
.mbBulletFontFollowText
<<= sal_True
;
210 case A_TOKEN( buFont
): // CT_TextFont
211 mrBulletList
.maBulletFont
.setAttributes( aAttribs
);
215 case A_TOKEN( buNone
): // CT_TextNoBullet
216 mrBulletList
.setNone();
218 case A_TOKEN( buAutoNum
): // CT_TextAutonumberBullet
220 AttributeList
attribs( rXAttributes
);
222 sal_Int32 nType
= rXAttributes
->getValueToken( XML_type
);
223 sal_Int32 nStartAt
= attribs
.getInteger( XML_startAt
, 1 );
224 if( nStartAt
> 32767 )
228 else if( nStartAt
< 1 )
232 mrBulletList
.setStartAt( nStartAt
);
233 mrBulletList
.setType( nType
);
235 catch(SAXException
& /* e */ )
237 OSL_TRACE("OOX: SAXException in XML_buAutoNum");
241 case A_TOKEN( buChar
): // CT_TextCharBullet
243 mrBulletList
.setBulletChar( rXAttributes
->getValue( XML_char
) );
245 catch(SAXException
& /* e */)
247 OSL_TRACE("OOX: SAXException in XML_buChar");
250 case A_TOKEN( buBlip
): // CT_TextBlipBullet
252 mxBlipProps
.reset( new BlipFillProperties
);
253 xRet
.set( new BlipFillContext( *this, rXAttributes
, *mxBlipProps
) );
257 case A_TOKEN( tabLst
): // CT_TextTabStopList
258 xRet
.set( new TextTabStopListContext( *this, maTabList
) );
260 case A_TOKEN( defRPr
): // CT_TextCharacterProperties
261 xRet
.set( new TextCharacterPropertiesContext( *this, rXAttributes
, mrTextParagraphProperties
.getTextCharacterProperties() ) );
269 // --------------------------------------------------------------------
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */