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/textbodypropertiescontext.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/text/ControlCharacter.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/text/WritingMode.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
35*cdf0e10cSrcweir #include "oox/drawingml/textbodyproperties.hxx"
36*cdf0e10cSrcweir #include "oox/drawingml/drawingmltypes.hxx"
37*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
38*cdf0e10cSrcweir #include "oox/helper/propertymap.hxx"
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir using ::rtl::OUString;
41*cdf0e10cSrcweir using namespace ::oox::core;
42*cdf0e10cSrcweir using namespace ::com::sun::star;
43*cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
44*cdf0e10cSrcweir using namespace ::com::sun::star::text;
45*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir namespace oox { namespace drawingml {
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir // --------------------------------------------------------------------
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir // CT_TextBodyProperties
53*cdf0e10cSrcweir TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler& rParent,
54*cdf0e10cSrcweir     const Reference< XFastAttributeList >& xAttributes, TextBodyProperties& rTextBodyProp )
55*cdf0e10cSrcweir : ContextHandler( rParent )
56*cdf0e10cSrcweir , mrTextBodyProp( rTextBodyProp )
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir     AttributeList aAttribs( xAttributes );
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 	// ST_TextWrappingType
61*cdf0e10cSrcweir     sal_Int32 nWrappingType = aAttribs.getToken( XML_wrap, XML_square );
62*cdf0e10cSrcweir     mrTextBodyProp.maPropertyMap[ PROP_TextWordWrap ] <<= static_cast< sal_Bool >( nWrappingType == XML_square );
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 	// ST_Coordinate
65*cdf0e10cSrcweir 	OUString sValue;
66*cdf0e10cSrcweir 	sValue = xAttributes->getOptionalValue( XML_lIns );
67*cdf0e10cSrcweir     if( sValue.getLength() ) {
68*cdf0e10cSrcweir 	sal_Int32 nLeftInset = ( sValue.getLength() != 0 ? GetCoordinate(  sValue ) : 91440 / 360 );
69*cdf0e10cSrcweir 	mrTextBodyProp.maPropertyMap[ PROP_TextLeftDistance ]  <<= static_cast< sal_Int32 >( nLeftInset );
70*cdf0e10cSrcweir     }
71*cdf0e10cSrcweir 	sValue = xAttributes->getOptionalValue( XML_tIns );
72*cdf0e10cSrcweir     if( sValue.getLength() ) {
73*cdf0e10cSrcweir 	sal_Int32 nTopInset  = ( sValue.getLength() != 0 ? GetCoordinate(  sValue ) : 91440 / 360 );
74*cdf0e10cSrcweir 	mrTextBodyProp.maPropertyMap[ PROP_TextUpperDistance ] <<= static_cast< sal_Int32 >( nTopInset );
75*cdf0e10cSrcweir     }
76*cdf0e10cSrcweir 	sValue = xAttributes->getOptionalValue( XML_rIns );
77*cdf0e10cSrcweir     if( sValue.getLength() ) {
78*cdf0e10cSrcweir 	sal_Int32 nRightInset  = ( sValue.getLength() != 0 ? GetCoordinate(  sValue ) : 91440 / 360 );
79*cdf0e10cSrcweir 	mrTextBodyProp.maPropertyMap[ PROP_TextRightDistance ] <<= static_cast< sal_Int32 >( nRightInset );
80*cdf0e10cSrcweir     }
81*cdf0e10cSrcweir 	sValue = xAttributes->getOptionalValue( XML_bIns );
82*cdf0e10cSrcweir     if( sValue.getLength() ) {
83*cdf0e10cSrcweir 	sal_Int32 nBottonInset = ( sValue.getLength() != 0 ? GetCoordinate(  sValue ) : 45720 / 360 );
84*cdf0e10cSrcweir 	mrTextBodyProp.maPropertyMap[ PROP_TextLowerDistance ] <<= static_cast< sal_Int32 >( nBottonInset );
85*cdf0e10cSrcweir     }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 	// ST_TextAnchoringType
88*cdf0e10cSrcweir 	drawing::TextVerticalAdjust	eVA( drawing::TextVerticalAdjust_TOP );
89*cdf0e10cSrcweir 	switch( xAttributes->getOptionalValueToken( XML_anchor, XML_t ) )
90*cdf0e10cSrcweir 	{
91*cdf0e10cSrcweir 		case XML_b :	eVA = drawing::TextVerticalAdjust_BOTTOM; break;
92*cdf0e10cSrcweir 		case XML_dist :
93*cdf0e10cSrcweir 		case XML_just :
94*cdf0e10cSrcweir 		case XML_ctr :	eVA = drawing::TextVerticalAdjust_CENTER; break;
95*cdf0e10cSrcweir 		default:
96*cdf0e10cSrcweir 		case XML_t :	eVA = drawing::TextVerticalAdjust_TOP; break;
97*cdf0e10cSrcweir 	}
98*cdf0e10cSrcweir 	mrTextBodyProp.maPropertyMap[ PROP_TextVerticalAdjust ] <<= eVA;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     bool bAnchorCenter = aAttribs.getBool( XML_anchorCtr, false );
101*cdf0e10cSrcweir     if( bAnchorCenter )
102*cdf0e10cSrcweir 	mrTextBodyProp.maPropertyMap[ PROP_TextHorizontalAdjust ] <<=
103*cdf0e10cSrcweir 	    TextHorizontalAdjust_CENTER;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir //   bool bCompatLineSpacing = aAttribs.getBool( XML_compatLnSpc, false );
106*cdf0e10cSrcweir //   bool bForceAA = aAttribs.getBool( XML_forceAA, false );
107*cdf0e10cSrcweir //   bool bFromWordArt = aAttribs.getBool( XML_fromWordArt, false );
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir   // ST_TextHorzOverflowType
110*cdf0e10cSrcweir //   sal_Int32 nHorzOverflow = xAttributes->getOptionalValueToken( XML_horzOverflow, XML_overflow );
111*cdf0e10cSrcweir 	// ST_TextVertOverflowType
112*cdf0e10cSrcweir //   sal_Int32 nVertOverflow =  xAttributes->getOptionalValueToken( XML_vertOverflow, XML_overflow );
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 	// ST_TextColumnCount
115*cdf0e10cSrcweir //   sal_Int32 nNumCol = aAttribs.getInteger( XML_numCol, 1 );
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     // ST_Angle
118*cdf0e10cSrcweir     mrTextBodyProp.moRotation = aAttribs.getInteger( XML_rot );
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir //   bool bRtlCol = aAttribs.getBool( XML_rtlCol, false );
121*cdf0e10cSrcweir 	// ST_PositiveCoordinate
122*cdf0e10cSrcweir //   sal_Int32 nSpcCol = aAttribs.getInteger( XML_spcCol, 0 );
123*cdf0e10cSrcweir //   bool bSpcFirstLastPara = aAttribs.getBool( XML_spcFirstLastPara, 0 );
124*cdf0e10cSrcweir //   bool bUpRight = aAttribs.getBool( XML_upright, 0 );
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 	// ST_TextVerticalType
127*cdf0e10cSrcweir     mrTextBodyProp.moVert = aAttribs.getToken( XML_vert );
128*cdf0e10cSrcweir     bool bRtl = aAttribs.getBool( XML_rtl, false );
129*cdf0e10cSrcweir     sal_Int32 tVert = mrTextBodyProp.moVert.get( XML_horz );
130*cdf0e10cSrcweir     if( tVert == XML_vert || tVert == XML_eaVert || tVert == XML_vert270 || tVert == XML_mongolianVert ) {
131*cdf0e10cSrcweir       mrTextBodyProp.maPropertyMap[ PROP_TextWritingMode ]
132*cdf0e10cSrcweir 	<<= WritingMode_TB_RL;
133*cdf0e10cSrcweir       // workaround for TB_LR as using WritingMode2 doesn't work
134*cdf0e10cSrcweir     	if( !bAnchorCenter )
135*cdf0e10cSrcweir     	    mrTextBodyProp.maPropertyMap[ PROP_TextHorizontalAdjust ] <<=
136*cdf0e10cSrcweir     		TextHorizontalAdjust_LEFT;
137*cdf0e10cSrcweir     } else
138*cdf0e10cSrcweir       mrTextBodyProp.maPropertyMap[ PROP_TextWritingMode ]
139*cdf0e10cSrcweir 	<<= ( bRtl ? WritingMode_RL_TB : WritingMode_LR_TB );
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir // --------------------------------------------------------------------
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir void TextBodyPropertiesContext::endFastElement( sal_Int32 ) throw (SAXException, RuntimeException)
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir // --------------------------------------------------------------------
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir Reference< XFastContextHandler > TextBodyPropertiesContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& /*xAttributes*/) throw (SAXException, RuntimeException)
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir 	Reference< XFastContextHandler > xRet;
153*cdf0e10cSrcweir 	switch( aElementToken )
154*cdf0e10cSrcweir 	{
155*cdf0e10cSrcweir 			// Sequence
156*cdf0e10cSrcweir 			case A_TOKEN( prstTxWarp ):		// CT_PresetTextShape
157*cdf0e10cSrcweir 			case A_TOKEN( prot ):			// CT_TextProtectionProperty
158*cdf0e10cSrcweir 				break;
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 			// EG_TextAutofit
161*cdf0e10cSrcweir 			case A_TOKEN( noAutofit ):
162*cdf0e10cSrcweir                 mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= false;   // CT_TextNoAutofit
163*cdf0e10cSrcweir 				break;
164*cdf0e10cSrcweir 			case A_TOKEN( normAutofit ):	// CT_TextNormalAutofit
165*cdf0e10cSrcweir                 mrTextBodyProp.maPropertyMap[ PROP_TextFitToSize ] <<= true;
166*cdf0e10cSrcweir                 mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= false;
167*cdf0e10cSrcweir                 break;
168*cdf0e10cSrcweir 			case A_TOKEN( spAutoFit ):
169*cdf0e10cSrcweir                 mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= true;
170*cdf0e10cSrcweir 				break;
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 			case A_TOKEN( scene3d ):		// CT_Scene3D
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 			// EG_Text3D
175*cdf0e10cSrcweir 			case A_TOKEN( sp3d ):			// CT_Shape3D
176*cdf0e10cSrcweir 			case A_TOKEN( flatTx ):			// CT_FlatText
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 				break;
179*cdf0e10cSrcweir 	}
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 	return xRet;
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir // --------------------------------------------------------------------
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir } }
187*cdf0e10cSrcweir 
188