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