xref: /AOO41X/main/oox/source/drawingml/textparagraphpropertiescontext.cxx (revision bbdaa03c027b99dfd94777720229473c094bb8b9)
1ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ca5ec200SAndrew Rist  * distributed with this work for additional information
6ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18ca5ec200SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20ca5ec200SAndrew Rist  *************************************************************/
21ca5ec200SAndrew Rist 
22ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/drawingml/textparagraphpropertiescontext.hxx"
25cdf0e10cSrcweir 
26*bbdaa03cSZhe Wang #include <com/sun/star/text/WritingMode2.hpp>
27cdf0e10cSrcweir #include <com/sun/star/awt/FontDescriptor.hpp>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "oox/drawingml/colorchoicecontext.hxx"
30cdf0e10cSrcweir #include "oox/drawingml/textcharacterpropertiescontext.hxx"
31cdf0e10cSrcweir #include "oox/drawingml/fillproperties.hxx"
32cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
33cdf0e10cSrcweir #include "textspacingcontext.hxx"
34cdf0e10cSrcweir #include "texttabstoplistcontext.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir using ::rtl::OUString;
37cdf0e10cSrcweir using namespace ::oox::core;
38cdf0e10cSrcweir using ::com::sun::star::awt::FontDescriptor;
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
41cdf0e10cSrcweir using namespace ::com::sun::star::style;
42cdf0e10cSrcweir using namespace ::com::sun::star::text;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir namespace oox { namespace drawingml {
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // CT_TextParagraphProperties
TextParagraphPropertiesContext(ContextHandler & rParent,const Reference<XFastAttributeList> & xAttribs,TextParagraphProperties & rTextParagraphProperties)47cdf0e10cSrcweir TextParagraphPropertiesContext::TextParagraphPropertiesContext( ContextHandler& rParent,
48cdf0e10cSrcweir 															    const Reference< XFastAttributeList >& xAttribs,
49cdf0e10cSrcweir                                                                 TextParagraphProperties& rTextParagraphProperties )
50cdf0e10cSrcweir : ContextHandler( rParent )
51cdf0e10cSrcweir , mrTextParagraphProperties( rTextParagraphProperties )
52cdf0e10cSrcweir , mrSpaceBefore( rTextParagraphProperties.getParaTopMargin() )
53cdf0e10cSrcweir , mrSpaceAfter( rTextParagraphProperties.getParaBottomMargin() )
54cdf0e10cSrcweir , mrBulletList( rTextParagraphProperties.getBulletList() )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir 	OUString sValue;
57cdf0e10cSrcweir 	AttributeList attribs( xAttribs );
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     PropertyMap& rPropertyMap( mrTextParagraphProperties.getTextParagraphPropertyMap() );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	// ST_TextAlignType
62cdf0e10cSrcweir 	if ( xAttribs->hasAttribute( XML_algn ) )
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir 		sal_Int32 nAlign = xAttribs->getOptionalValueToken( XML_algn, XML_l );
65cdf0e10cSrcweir         rPropertyMap[ PROP_ParaAdjust ] <<= GetParaAdjust( nAlign );
66cdf0e10cSrcweir 	}
67cdf0e10cSrcweir //	OSL_TRACE( "OOX: para adjust %d", GetParaAdjust( nAlign ));
68cdf0e10cSrcweir 	// TODO see to do the same with RubyAdjust
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	// ST_Coordinate32
71cdf0e10cSrcweir //	sValue = xAttribs->getOptionalValue( XML_defTabSz );	SJ: we need to be able to set the default tab size for each text object,
72cdf0e10cSrcweir //															this is possible at the moment only for the whole document.
73cdf0e10cSrcweir //	sal_Int32 nDefTabSize = ( sValue.getLength() == 0 ? 0 : GetCoordinate(  sValue ) );
74cdf0e10cSrcweir 	// TODO
75cdf0e10cSrcweir 
76cdf0e10cSrcweir //	bool bEaLineBrk = attribs.getBool( XML_eaLnBrk, true );
77cdf0e10cSrcweir 	if ( xAttribs->hasAttribute( XML_latinLnBrk ) )
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir 		bool bLatinLineBrk = attribs.getBool( XML_latinLnBrk, true );
80cdf0e10cSrcweir         rPropertyMap[ PROP_ParaIsHyphenation ] <<= bLatinLineBrk;
81cdf0e10cSrcweir 	}
82cdf0e10cSrcweir 	// TODO see what to do with Asian hyphenation
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	// ST_TextFontAlignType
85cdf0e10cSrcweir 	// TODO
86cdf0e10cSrcweir //	sal_Int32 nFontAlign = xAttribs->getOptionalValueToken( XML_fontAlgn, XML_base );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	if ( xAttribs->hasAttribute( XML_hangingPunct ) )
89cdf0e10cSrcweir 	{
90cdf0e10cSrcweir 		bool bHangingPunct = attribs.getBool( XML_hangingPunct, false );
91cdf0e10cSrcweir         rPropertyMap[ PROP_ParaIsHangingPunctuation ] <<= bHangingPunct;
92cdf0e10cSrcweir 	}
93cdf0e10cSrcweir 
94cdf0e10cSrcweir   // ST_Coordinate
95cdf0e10cSrcweir 	if ( xAttribs->hasAttribute( XML_indent ) )
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		sValue = xAttribs->getOptionalValue( XML_indent );
98cdf0e10cSrcweir 		mrTextParagraphProperties.getFirstLineIndentation() = boost::optional< sal_Int32 >( sValue.getLength() == 0 ? 0 : GetCoordinate( sValue ) );
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir 
101cdf0e10cSrcweir   // ST_TextIndentLevelType
102cdf0e10cSrcweir 	// -1 is an invalid value and denote the lack of level
103cdf0e10cSrcweir 	sal_Int32 nLevel = attribs.getInteger( XML_lvl, 0 );
104cdf0e10cSrcweir 	if( nLevel > 8 || nLevel < 0 )
105cdf0e10cSrcweir 	{
106cdf0e10cSrcweir 		nLevel = 0;
107cdf0e10cSrcweir 	}
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	mrTextParagraphProperties.setLevel( static_cast< sal_Int16 >( nLevel ) );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	char name[] = "Outline X";
112cdf0e10cSrcweir 	name[8] = static_cast<char>( '1' + nLevel );
113cdf0e10cSrcweir 	const OUString sStyleNameValue( rtl::OUString::createFromAscii( name ) );
114cdf0e10cSrcweir 	mrBulletList.setStyleName( sStyleNameValue );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	// ST_TextMargin
117cdf0e10cSrcweir 	// ParaLeftMargin
118cdf0e10cSrcweir 	if ( xAttribs->hasAttribute( XML_marL ) )
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir 		sValue = xAttribs->getOptionalValue( XML_marL );
121cdf0e10cSrcweir 		mrTextParagraphProperties.getParaLeftMargin() = boost::optional< sal_Int32 >( sValue.getLength() == 0 ? 0 : GetCoordinate( sValue ) );
122cdf0e10cSrcweir 	}
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	// ParaRightMargin
125cdf0e10cSrcweir 	if ( xAttribs->hasAttribute( XML_marR ) )
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		sValue = xAttribs->getOptionalValue( XML_marR );
128cdf0e10cSrcweir 		sal_Int32 nMarR  = ( sValue.getLength() == 0 ? 0 : GetCoordinate( sValue ) );
129cdf0e10cSrcweir         rPropertyMap[ PROP_ParaRightMargin ] <<= nMarR;
130cdf0e10cSrcweir 	}
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	if ( xAttribs->hasAttribute( XML_rtl ) )
133cdf0e10cSrcweir 	{
134cdf0e10cSrcweir 		bool bRtl = attribs.getBool( XML_rtl, false );
135*bbdaa03cSZhe Wang 		rPropertyMap[ PROP_WritingMode ] <<= ( bRtl ? WritingMode2::RL_TB : WritingMode2::LR_TB );
136cdf0e10cSrcweir 	}
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 
~TextParagraphPropertiesContext()141cdf0e10cSrcweir TextParagraphPropertiesContext::~TextParagraphPropertiesContext()
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	PropertyMap& rPropertyMap( mrTextParagraphProperties.getTextParagraphPropertyMap() );
144cdf0e10cSrcweir 	if ( maLineSpacing.bHasValue )
145cdf0e10cSrcweir         rPropertyMap[ PROP_ParaLineSpacing ] <<= maLineSpacing.toLineSpacing();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     ::std::list< TabStop >::size_type nTabCount = maTabList.size();
148cdf0e10cSrcweir 	if( nTabCount != 0 )
149cdf0e10cSrcweir 	{
150cdf0e10cSrcweir 		Sequence< TabStop > aSeq( nTabCount );
151cdf0e10cSrcweir 		TabStop * aArray = aSeq.getArray();
152cdf0e10cSrcweir 		OSL_ENSURE( aArray != NULL, "sequence array is NULL" );
153cdf0e10cSrcweir 		::std::copy( maTabList.begin(), maTabList.end(), aArray );
154cdf0e10cSrcweir         rPropertyMap[ PROP_ParaTabStops ] <<= aSeq;
155cdf0e10cSrcweir 	}
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     if ( mxBlipProps.get() && mxBlipProps->mxGraphic.is() )
158cdf0e10cSrcweir         mrBulletList.setGraphic( mxBlipProps->mxGraphic );
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 	if( mrBulletList.is() )
161cdf0e10cSrcweir         rPropertyMap[ PROP_IsNumbering ] <<= sal_True;
162cdf0e10cSrcweir 	sal_Int16 nLevel = mrTextParagraphProperties.getLevel();
163cdf0e10cSrcweir     rPropertyMap[ PROP_NumberingLevel ] <<= nLevel;
164cdf0e10cSrcweir     rPropertyMap[ PROP_NumberingIsNumber ] <<= sal_True;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir // --------------------------------------------------------------------
168cdf0e10cSrcweir 
endFastElement(sal_Int32)169cdf0e10cSrcweir void TextParagraphPropertiesContext::endFastElement( sal_Int32 ) throw (SAXException, RuntimeException)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 
175cdf0e10cSrcweir // --------------------------------------------------------------------
176cdf0e10cSrcweir 
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & rXAttributes)177cdf0e10cSrcweir Reference< XFastContextHandler > TextParagraphPropertiesContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& rXAttributes ) throw (SAXException, RuntimeException)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     AttributeList aAttribs( rXAttributes );
180cdf0e10cSrcweir 	Reference< XFastContextHandler > xRet;
181cdf0e10cSrcweir 	switch( aElementToken )
182cdf0e10cSrcweir 	{
183cdf0e10cSrcweir 		case A_TOKEN( lnSpc ):			// CT_TextSpacing
184cdf0e10cSrcweir             xRet.set( new TextSpacingContext( *this, maLineSpacing ) );
185cdf0e10cSrcweir 			break;
186cdf0e10cSrcweir 		case A_TOKEN( spcBef ):			// CT_TextSpacing
187cdf0e10cSrcweir             xRet.set( new TextSpacingContext( *this, mrSpaceBefore ) );
188cdf0e10cSrcweir 			break;
189cdf0e10cSrcweir 		case A_TOKEN( spcAft ):			// CT_TextSpacing
190cdf0e10cSrcweir             xRet.set( new TextSpacingContext( *this, mrSpaceAfter ) );
191cdf0e10cSrcweir 			break;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 		// EG_TextBulletColor
194cdf0e10cSrcweir 		case A_TOKEN( buClrTx ):		// CT_TextBulletColorFollowText ???
195cdf0e10cSrcweir 			mrBulletList.mbBulletColorFollowText <<= sal_True;
196cdf0e10cSrcweir 			break;
197cdf0e10cSrcweir 		case A_TOKEN( buClr ):			// CT_Color
198cdf0e10cSrcweir             xRet.set( new ColorContext( *this, *mrBulletList.maBulletColorPtr ) );
199cdf0e10cSrcweir 			break;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 		// EG_TextBulletSize
202cdf0e10cSrcweir 		case A_TOKEN( buSzTx ):			// CT_TextBulletSizeFollowText
203cdf0e10cSrcweir 			mrBulletList.setBulletSize(100);
204cdf0e10cSrcweir 			break;
205cdf0e10cSrcweir 		case A_TOKEN( buSzPct ):		// CT_TextBulletSizePercent
206cdf0e10cSrcweir 			mrBulletList.setBulletSize( static_cast<sal_Int16>( GetPercent( rXAttributes->getOptionalValue( XML_val ) ) / 1000 ) );
207cdf0e10cSrcweir 			break;
208cdf0e10cSrcweir 		case A_TOKEN( buSzPts ):		// CT_TextBulletSizePoint
209cdf0e10cSrcweir 			mrBulletList.setBulletSize(0);
210cdf0e10cSrcweir 			mrBulletList.setFontSize( static_cast<sal_Int16>(GetTextSize( rXAttributes->getOptionalValue( XML_val ) ) ) );
211cdf0e10cSrcweir 			break;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 		// EG_TextBulletTypeface
214cdf0e10cSrcweir 		case A_TOKEN( buFontTx ):		// CT_TextBulletTypefaceFollowText
215cdf0e10cSrcweir 			mrBulletList.mbBulletFontFollowText <<= sal_True;
216cdf0e10cSrcweir 			break;
217cdf0e10cSrcweir 		case A_TOKEN( buFont ):			// CT_TextFont
218cdf0e10cSrcweir             mrBulletList.maBulletFont.setAttributes( aAttribs );
219cdf0e10cSrcweir 			break;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 		// EG_TextBullet
222cdf0e10cSrcweir 		case A_TOKEN( buNone ):			// CT_TextNoBullet
223cdf0e10cSrcweir 			mrBulletList.setNone();
224cdf0e10cSrcweir 			break;
225cdf0e10cSrcweir 		case A_TOKEN( buAutoNum ):		// CT_TextAutonumberBullet
226cdf0e10cSrcweir 		{
227cdf0e10cSrcweir 			AttributeList attribs( rXAttributes );
228cdf0e10cSrcweir 			try {
229cdf0e10cSrcweir 				sal_Int32 nType = rXAttributes->getValueToken( XML_type );
230cdf0e10cSrcweir 				sal_Int32 nStartAt = attribs.getInteger( XML_startAt, 1 );
231cdf0e10cSrcweir 				if( nStartAt > 32767 )
232cdf0e10cSrcweir 				{
233cdf0e10cSrcweir 					nStartAt = 32767;
234cdf0e10cSrcweir 				}
235cdf0e10cSrcweir 				else if( nStartAt < 1 )
236cdf0e10cSrcweir 				{
237cdf0e10cSrcweir 					nStartAt = 1;
238cdf0e10cSrcweir 				}
239cdf0e10cSrcweir 				mrBulletList.setStartAt( nStartAt );
240cdf0e10cSrcweir 				mrBulletList.setType( nType );
241cdf0e10cSrcweir 			}
242cdf0e10cSrcweir 			catch(SAXException& /* e */ )
243cdf0e10cSrcweir 			{
244cdf0e10cSrcweir 				OSL_TRACE("OOX: SAXException in XML_buAutoNum");
245cdf0e10cSrcweir 			}
246cdf0e10cSrcweir 			break;
247cdf0e10cSrcweir 		}
248cdf0e10cSrcweir 		case A_TOKEN( buChar ):			// CT_TextCharBullet
249cdf0e10cSrcweir 			try {
250cdf0e10cSrcweir 				mrBulletList.setBulletChar( rXAttributes->getValue( XML_char ) );
251cdf0e10cSrcweir 			}
252cdf0e10cSrcweir 			catch(SAXException& /* e */)
253cdf0e10cSrcweir 			{
254cdf0e10cSrcweir 				OSL_TRACE("OOX: SAXException in XML_buChar");
255cdf0e10cSrcweir 			}
256cdf0e10cSrcweir 			break;
257cdf0e10cSrcweir 		case A_TOKEN( buBlip ):			// CT_TextBlipBullet
258cdf0e10cSrcweir 			{
259cdf0e10cSrcweir                 mxBlipProps.reset( new BlipFillProperties );
260cdf0e10cSrcweir                 xRet.set( new BlipFillContext( *this, rXAttributes, *mxBlipProps ) );
261cdf0e10cSrcweir 			}
262cdf0e10cSrcweir 			break;
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 		case A_TOKEN( tabLst ):			// CT_TextTabStopList
265cdf0e10cSrcweir             xRet.set( new TextTabStopListContext( *this, maTabList ) );
266cdf0e10cSrcweir 			break;
267cdf0e10cSrcweir 		case A_TOKEN( defRPr ):			// CT_TextCharacterProperties
268cdf0e10cSrcweir             xRet.set( new TextCharacterPropertiesContext( *this, rXAttributes, mrTextParagraphProperties.getTextCharacterProperties() ) );
269cdf0e10cSrcweir 			break;
270cdf0e10cSrcweir 	}
271cdf0e10cSrcweir 	if ( !xRet.is() )
272cdf0e10cSrcweir 		xRet.set( this );
273cdf0e10cSrcweir 	return xRet;
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir // --------------------------------------------------------------------
277cdf0e10cSrcweir 
278cdf0e10cSrcweir } }
279cdf0e10cSrcweir 
280