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: textparagraphpropertiescontext.cxx,v $
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/textparagraphpropertiescontext.hxx"
33 #include <com/sun/star/text/WritingMode.hpp>
34 #include <com/sun/star/awt/FontDescriptor.hpp>
36 #include "oox/drawingml/colorchoicecontext.hxx"
37 #include "oox/drawingml/textcharacterpropertiescontext.hxx"
38 #include "oox/drawingml/fillproperties.hxx"
39 #include "oox/helper/attributelist.hxx"
40 #include "oox/core/namespaces.hxx"
41 #include "properties.hxx"
42 #include "textspacingcontext.hxx"
43 #include "texttabstoplistcontext.hxx"
46 using ::rtl::OUString
;
47 using namespace ::oox::core
;
48 using ::com::sun::star::awt::FontDescriptor
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::xml::sax
;
51 using namespace ::com::sun::star::style
;
52 using namespace ::com::sun::star::text
;
54 namespace oox
{ namespace drawingml
{
56 // CT_TextParagraphProperties
57 TextParagraphPropertiesContext::TextParagraphPropertiesContext( ContextHandler
& rParent
,
58 const Reference
< XFastAttributeList
>& xAttribs
,
59 TextParagraphProperties
& rTextParagraphProperties
)
60 : ContextHandler( rParent
)
61 , mrTextParagraphProperties( rTextParagraphProperties
)
62 , mrSpaceBefore( rTextParagraphProperties
.getParaTopMargin() )
63 , mrSpaceAfter( rTextParagraphProperties
.getParaBottomMargin() )
64 , mrBulletList( rTextParagraphProperties
.getBulletList() )
67 AttributeList
attribs( xAttribs
);
69 PropertyMap
& rPropertyMap( mrTextParagraphProperties
.getTextParagraphPropertyMap() );
72 if ( xAttribs
->hasAttribute( XML_algn
) )
74 sal_Int32 nAlign
= xAttribs
->getOptionalValueToken( XML_algn
, XML_l
);
75 rPropertyMap
[ PROP_ParaAdjust
] <<= GetParaAdjust( nAlign
);
77 // OSL_TRACE( "OOX: para adjust %d", GetParaAdjust( nAlign ));
78 // TODO see to do the same with RubyAdjust
81 // sValue = xAttribs->getOptionalValue( XML_defTabSz ); SJ: we need to be able to set the default tab size for each text object,
82 // this is possible at the moment only for the whole document.
83 // sal_Int32 nDefTabSize = ( sValue.getLength() == 0 ? 0 : GetCoordinate( sValue ) );
86 // bool bEaLineBrk = attribs.getBool( XML_eaLnBrk, true );
87 if ( xAttribs
->hasAttribute( XML_latinLnBrk
) )
89 bool bLatinLineBrk
= attribs
.getBool( XML_latinLnBrk
, true );
90 rPropertyMap
[ PROP_ParaIsHyphenation
] <<= bLatinLineBrk
;
92 // TODO see what to do with Asian hyphenation
94 // ST_TextFontAlignType
96 // sal_Int32 nFontAlign = xAttribs->getOptionalValueToken( XML_fontAlgn, XML_base );
98 if ( xAttribs
->hasAttribute( XML_hangingPunct
) )
100 bool bHangingPunct
= attribs
.getBool( XML_hangingPunct
, false );
101 rPropertyMap
[ PROP_ParaIsHangingPunctuation
] <<= bHangingPunct
;
105 if ( xAttribs
->hasAttribute( XML_indent
) )
107 sValue
= xAttribs
->getOptionalValue( XML_indent
);
108 mrTextParagraphProperties
.getFirstLineIndentation() = boost::optional
< sal_Int32
>( sValue
.getLength() == 0 ? 0 : GetCoordinate( sValue
) );
111 // ST_TextIndentLevelType
112 // -1 is an invalid value and denote the lack of level
113 sal_Int32 nLevel
= attribs
.getInteger( XML_lvl
, 0 );
114 if( nLevel
> 8 || nLevel
< 0 )
119 mrTextParagraphProperties
.setLevel( static_cast< sal_Int16
>( nLevel
) );
121 char name
[] = "Outline X";
122 name
[8] = static_cast<char>( '1' + nLevel
);
123 const OUString
sStyleNameValue( rtl::OUString::createFromAscii( name
) );
124 mrBulletList
.setStyleName( sStyleNameValue
);
128 if ( xAttribs
->hasAttribute( XML_marL
) )
130 sValue
= xAttribs
->getOptionalValue( XML_marL
);
131 mrTextParagraphProperties
.getParaLeftMargin() = boost::optional
< sal_Int32
>( sValue
.getLength() == 0 ? 0 : GetCoordinate( sValue
) );
135 if ( xAttribs
->hasAttribute( XML_marR
) )
137 sValue
= xAttribs
->getOptionalValue( XML_marR
);
138 sal_Int32 nMarR
= ( sValue
.getLength() == 0 ? 0 : GetCoordinate( sValue
) );
139 rPropertyMap
[ PROP_ParaRightMargin
] <<= nMarR
;
142 if ( xAttribs
->hasAttribute( XML_rtl
) )
144 bool bRtl
= attribs
.getBool( XML_rtl
, false );
145 rPropertyMap
[ PROP_TextWritingMode
] <<= ( bRtl
? WritingMode_RL_TB
: WritingMode_LR_TB
);
151 TextParagraphPropertiesContext::~TextParagraphPropertiesContext()
153 PropertyMap
& rPropertyMap( mrTextParagraphProperties
.getTextParagraphPropertyMap() );
154 if ( maLineSpacing
.bHasValue
)
155 rPropertyMap
[ PROP_ParaLineSpacing
] <<= maLineSpacing
.toLineSpacing();
157 ::std::list
< TabStop
>::size_type nTabCount
= maTabList
.size();
160 Sequence
< TabStop
> aSeq( nTabCount
);
161 TabStop
* aArray
= aSeq
.getArray();
162 OSL_ENSURE( aArray
!= NULL
, "sequence array is NULL" );
163 ::std::copy( maTabList
.begin(), maTabList
.end(), aArray
);
164 rPropertyMap
[ PROP_ParaTabStops
] <<= aSeq
;
167 if ( mxBlipProps
.get() && mxBlipProps
->mxGraphic
.is() )
168 mrBulletList
.setGraphic( mxBlipProps
->mxGraphic
);
170 if( mrBulletList
.is() )
171 rPropertyMap
[ PROP_IsNumbering
] <<= sal_True
;
172 sal_Int16 nLevel
= mrTextParagraphProperties
.getLevel();
173 rPropertyMap
[ PROP_NumberingLevel
] <<= nLevel
;
174 rPropertyMap
[ PROP_NumberingIsNumber
] <<= sal_True
;
177 // --------------------------------------------------------------------
179 void TextParagraphPropertiesContext::endFastElement( sal_Int32
) throw (SAXException
, RuntimeException
)
185 // --------------------------------------------------------------------
187 Reference
< XFastContextHandler
> TextParagraphPropertiesContext::createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& rXAttributes
) throw (SAXException
, RuntimeException
)
189 AttributeList
aAttribs( rXAttributes
);
190 Reference
< XFastContextHandler
> xRet
;
191 switch( aElementToken
)
193 case NMSP_DRAWINGML
|XML_lnSpc
: // CT_TextSpacing
194 xRet
.set( new TextSpacingContext( *this, maLineSpacing
) );
196 case NMSP_DRAWINGML
|XML_spcBef
: // CT_TextSpacing
197 xRet
.set( new TextSpacingContext( *this, mrSpaceBefore
) );
199 case NMSP_DRAWINGML
|XML_spcAft
: // CT_TextSpacing
200 xRet
.set( new TextSpacingContext( *this, mrSpaceAfter
) );
203 // EG_TextBulletColor
204 case NMSP_DRAWINGML
|XML_buClrTx
: // CT_TextBulletColorFollowText ???
205 mrBulletList
.mbBulletColorFollowText
<<= sal_True
;
207 case NMSP_DRAWINGML
|XML_buClr
: // CT_Color
208 xRet
.set( new ColorContext( *this, *mrBulletList
.maBulletColorPtr
) );
212 case NMSP_DRAWINGML
|XML_buSzTx
: // CT_TextBulletSizeFollowText
213 mrBulletList
.setBulletSize(100);
215 case NMSP_DRAWINGML
|XML_buSzPct
: // CT_TextBulletSizePercent
216 mrBulletList
.setBulletSize( static_cast<sal_Int16
>( GetPercent( rXAttributes
->getOptionalValue( XML_val
) ) / 1000 ) );
218 case NMSP_DRAWINGML
|XML_buSzPts
: // CT_TextBulletSizePoint
219 mrBulletList
.setBulletSize(0);
220 mrBulletList
.setFontSize( static_cast<sal_Int16
>(GetTextSize( rXAttributes
->getOptionalValue( XML_val
) ) ) );
223 // EG_TextBulletTypeface
224 case NMSP_DRAWINGML
|XML_buFontTx
: // CT_TextBulletTypefaceFollowText
225 mrBulletList
.mbBulletFontFollowText
<<= sal_True
;
227 case NMSP_DRAWINGML
|XML_buFont
: // CT_TextFont
228 mrBulletList
.maBulletFont
.setAttributes( aAttribs
);
232 case NMSP_DRAWINGML
|XML_buNone
: // CT_TextNoBullet
233 mrBulletList
.setNone();
235 case NMSP_DRAWINGML
|XML_buAutoNum
: // CT_TextAutonumberBullet
237 AttributeList
attribs( rXAttributes
);
239 sal_Int32 nType
= rXAttributes
->getValueToken( XML_type
);
240 sal_Int32 nStartAt
= attribs
.getInteger( XML_startAt
, 1 );
241 if( nStartAt
> 32767 )
245 else if( nStartAt
< 1 )
249 mrBulletList
.setStartAt( nStartAt
);
250 mrBulletList
.setType( nType
);
252 catch(SAXException
& /* e */ )
254 OSL_TRACE("OOX: SAXException in XML_buAutoNum");
258 case NMSP_DRAWINGML
|XML_buChar
: // CT_TextCharBullet
260 mrBulletList
.setBulletChar( rXAttributes
->getValue( XML_char
) );
262 catch(SAXException
& /* e */)
264 OSL_TRACE("OOX: SAXException in XML_buChar");
267 case NMSP_DRAWINGML
|XML_buBlip
: // CT_TextBlipBullet
269 mxBlipProps
.reset( new BlipFillProperties
);
270 xRet
.set( new BlipFillContext( *this, rXAttributes
, *mxBlipProps
) );
274 case NMSP_DRAWINGML
|XML_tabLst
: // CT_TextTabStopList
275 xRet
.set( new TextTabStopListContext( *this, maTabList
) );
277 case NMSP_DRAWINGML
|XML_defRPr
: // CT_TextCharacterProperties
278 xRet
.set( new TextCharacterPropertiesContext( *this, rXAttributes
, mrTextParagraphProperties
.getTextCharacterProperties() ) );
286 // --------------------------------------------------------------------