1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski #include "oox/drawingml/textbodypropertiescontext.hxx"
25*b1cdbd2cSJim Jagielski 
26*b1cdbd2cSJim Jagielski #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
27*b1cdbd2cSJim Jagielski #include <com/sun/star/text/ControlCharacter.hpp>
28*b1cdbd2cSJim Jagielski #include <com/sun/star/text/WritingMode.hpp>
29*b1cdbd2cSJim Jagielski #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
30*b1cdbd2cSJim Jagielski #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
31*b1cdbd2cSJim Jagielski #include "oox/drawingml/textbodyproperties.hxx"
32*b1cdbd2cSJim Jagielski #include "oox/drawingml/drawingmltypes.hxx"
33*b1cdbd2cSJim Jagielski #include "oox/helper/attributelist.hxx"
34*b1cdbd2cSJim Jagielski #include "oox/helper/propertymap.hxx"
35*b1cdbd2cSJim Jagielski 
36*b1cdbd2cSJim Jagielski using ::rtl::OUString;
37*b1cdbd2cSJim Jagielski using namespace ::oox::core;
38*b1cdbd2cSJim Jagielski using namespace ::com::sun::star;
39*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::drawing;
40*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::text;
41*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::uno;
42*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::xml::sax;
43*b1cdbd2cSJim Jagielski 
44*b1cdbd2cSJim Jagielski namespace oox { namespace drawingml {
45*b1cdbd2cSJim Jagielski 
46*b1cdbd2cSJim Jagielski // --------------------------------------------------------------------
47*b1cdbd2cSJim Jagielski 
48*b1cdbd2cSJim Jagielski // CT_TextBodyProperties
TextBodyPropertiesContext(ContextHandler & rParent,const Reference<XFastAttributeList> & xAttributes,TextBodyProperties & rTextBodyProp)49*b1cdbd2cSJim Jagielski TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler& rParent,
50*b1cdbd2cSJim Jagielski     const Reference< XFastAttributeList >& xAttributes, TextBodyProperties& rTextBodyProp )
51*b1cdbd2cSJim Jagielski : ContextHandler( rParent )
52*b1cdbd2cSJim Jagielski , mrTextBodyProp( rTextBodyProp )
53*b1cdbd2cSJim Jagielski {
54*b1cdbd2cSJim Jagielski     AttributeList aAttribs( xAttributes );
55*b1cdbd2cSJim Jagielski 
56*b1cdbd2cSJim Jagielski 	// ST_TextWrappingType
57*b1cdbd2cSJim Jagielski     sal_Int32 nWrappingType = aAttribs.getToken( XML_wrap, XML_square );
58*b1cdbd2cSJim Jagielski     mrTextBodyProp.maPropertyMap[ PROP_TextWordWrap ] <<= static_cast< sal_Bool >( nWrappingType == XML_square );
59*b1cdbd2cSJim Jagielski 
60*b1cdbd2cSJim Jagielski 	// ST_Coordinate
61*b1cdbd2cSJim Jagielski 	OUString sValue;
62*b1cdbd2cSJim Jagielski 	sValue = xAttributes->getOptionalValue( XML_lIns );
63*b1cdbd2cSJim Jagielski     if( sValue.getLength() ) {
64*b1cdbd2cSJim Jagielski 	sal_Int32 nLeftInset = ( sValue.getLength() != 0 ? GetCoordinate(  sValue ) : 91440 / 360 );
65*b1cdbd2cSJim Jagielski 	mrTextBodyProp.maPropertyMap[ PROP_TextLeftDistance ]  <<= static_cast< sal_Int32 >( nLeftInset );
66*b1cdbd2cSJim Jagielski     }
67*b1cdbd2cSJim Jagielski 	sValue = xAttributes->getOptionalValue( XML_tIns );
68*b1cdbd2cSJim Jagielski     if( sValue.getLength() ) {
69*b1cdbd2cSJim Jagielski 	sal_Int32 nTopInset  = ( sValue.getLength() != 0 ? GetCoordinate(  sValue ) : 91440 / 360 );
70*b1cdbd2cSJim Jagielski 	mrTextBodyProp.maPropertyMap[ PROP_TextUpperDistance ] <<= static_cast< sal_Int32 >( nTopInset );
71*b1cdbd2cSJim Jagielski     }
72*b1cdbd2cSJim Jagielski 	sValue = xAttributes->getOptionalValue( XML_rIns );
73*b1cdbd2cSJim Jagielski     if( sValue.getLength() ) {
74*b1cdbd2cSJim Jagielski 	sal_Int32 nRightInset  = ( sValue.getLength() != 0 ? GetCoordinate(  sValue ) : 91440 / 360 );
75*b1cdbd2cSJim Jagielski 	mrTextBodyProp.maPropertyMap[ PROP_TextRightDistance ] <<= static_cast< sal_Int32 >( nRightInset );
76*b1cdbd2cSJim Jagielski     }
77*b1cdbd2cSJim Jagielski 	sValue = xAttributes->getOptionalValue( XML_bIns );
78*b1cdbd2cSJim Jagielski     if( sValue.getLength() ) {
79*b1cdbd2cSJim Jagielski 	sal_Int32 nBottonInset = ( sValue.getLength() != 0 ? GetCoordinate(  sValue ) : 45720 / 360 );
80*b1cdbd2cSJim Jagielski 	mrTextBodyProp.maPropertyMap[ PROP_TextLowerDistance ] <<= static_cast< sal_Int32 >( nBottonInset );
81*b1cdbd2cSJim Jagielski     }
82*b1cdbd2cSJim Jagielski 
83*b1cdbd2cSJim Jagielski 	// ST_TextAnchoringType
84*b1cdbd2cSJim Jagielski 	drawing::TextVerticalAdjust	eVA( drawing::TextVerticalAdjust_TOP );
85*b1cdbd2cSJim Jagielski 	switch( xAttributes->getOptionalValueToken( XML_anchor, XML_t ) )
86*b1cdbd2cSJim Jagielski 	{
87*b1cdbd2cSJim Jagielski 		case XML_b :	eVA = drawing::TextVerticalAdjust_BOTTOM; break;
88*b1cdbd2cSJim Jagielski 		case XML_dist :
89*b1cdbd2cSJim Jagielski 		case XML_just :
90*b1cdbd2cSJim Jagielski 		case XML_ctr :	eVA = drawing::TextVerticalAdjust_CENTER; break;
91*b1cdbd2cSJim Jagielski 		default:
92*b1cdbd2cSJim Jagielski 		case XML_t :	eVA = drawing::TextVerticalAdjust_TOP; break;
93*b1cdbd2cSJim Jagielski 	}
94*b1cdbd2cSJim Jagielski 	mrTextBodyProp.maPropertyMap[ PROP_TextVerticalAdjust ] <<= eVA;
95*b1cdbd2cSJim Jagielski 
96*b1cdbd2cSJim Jagielski     bool bAnchorCenter = aAttribs.getBool( XML_anchorCtr, false );
97*b1cdbd2cSJim Jagielski     if( bAnchorCenter )
98*b1cdbd2cSJim Jagielski 	mrTextBodyProp.maPropertyMap[ PROP_TextHorizontalAdjust ] <<=
99*b1cdbd2cSJim Jagielski 	    TextHorizontalAdjust_CENTER;
100*b1cdbd2cSJim Jagielski 
101*b1cdbd2cSJim Jagielski //   bool bCompatLineSpacing = aAttribs.getBool( XML_compatLnSpc, false );
102*b1cdbd2cSJim Jagielski //   bool bForceAA = aAttribs.getBool( XML_forceAA, false );
103*b1cdbd2cSJim Jagielski //   bool bFromWordArt = aAttribs.getBool( XML_fromWordArt, false );
104*b1cdbd2cSJim Jagielski 
105*b1cdbd2cSJim Jagielski   // ST_TextHorzOverflowType
106*b1cdbd2cSJim Jagielski //   sal_Int32 nHorzOverflow = xAttributes->getOptionalValueToken( XML_horzOverflow, XML_overflow );
107*b1cdbd2cSJim Jagielski 	// ST_TextVertOverflowType
108*b1cdbd2cSJim Jagielski //   sal_Int32 nVertOverflow =  xAttributes->getOptionalValueToken( XML_vertOverflow, XML_overflow );
109*b1cdbd2cSJim Jagielski 
110*b1cdbd2cSJim Jagielski 	// ST_TextColumnCount
111*b1cdbd2cSJim Jagielski //   sal_Int32 nNumCol = aAttribs.getInteger( XML_numCol, 1 );
112*b1cdbd2cSJim Jagielski 
113*b1cdbd2cSJim Jagielski     // ST_Angle
114*b1cdbd2cSJim Jagielski     mrTextBodyProp.moRotation = aAttribs.getInteger( XML_rot );
115*b1cdbd2cSJim Jagielski 
116*b1cdbd2cSJim Jagielski //   bool bRtlCol = aAttribs.getBool( XML_rtlCol, false );
117*b1cdbd2cSJim Jagielski 	// ST_PositiveCoordinate
118*b1cdbd2cSJim Jagielski //   sal_Int32 nSpcCol = aAttribs.getInteger( XML_spcCol, 0 );
119*b1cdbd2cSJim Jagielski //   bool bSpcFirstLastPara = aAttribs.getBool( XML_spcFirstLastPara, 0 );
120*b1cdbd2cSJim Jagielski //   bool bUpRight = aAttribs.getBool( XML_upright, 0 );
121*b1cdbd2cSJim Jagielski 
122*b1cdbd2cSJim Jagielski 	// ST_TextVerticalType
123*b1cdbd2cSJim Jagielski     mrTextBodyProp.moVert = aAttribs.getToken( XML_vert );
124*b1cdbd2cSJim Jagielski     bool bRtl = aAttribs.getBool( XML_rtl, false );
125*b1cdbd2cSJim Jagielski     sal_Int32 tVert = mrTextBodyProp.moVert.get( XML_horz );
126*b1cdbd2cSJim Jagielski     if( tVert == XML_vert || tVert == XML_eaVert || tVert == XML_vert270 || tVert == XML_mongolianVert ) {
127*b1cdbd2cSJim Jagielski       mrTextBodyProp.maPropertyMap[ PROP_TextWritingMode ]
128*b1cdbd2cSJim Jagielski 	<<= WritingMode_TB_RL;
129*b1cdbd2cSJim Jagielski       // workaround for TB_LR as using WritingMode2 doesn't work
130*b1cdbd2cSJim Jagielski     	if( !bAnchorCenter )
131*b1cdbd2cSJim Jagielski     	    mrTextBodyProp.maPropertyMap[ PROP_TextHorizontalAdjust ] <<=
132*b1cdbd2cSJim Jagielski     		TextHorizontalAdjust_LEFT;
133*b1cdbd2cSJim Jagielski     } else
134*b1cdbd2cSJim Jagielski       mrTextBodyProp.maPropertyMap[ PROP_TextWritingMode ]
135*b1cdbd2cSJim Jagielski 	<<= ( bRtl ? WritingMode_RL_TB : WritingMode_LR_TB );
136*b1cdbd2cSJim Jagielski }
137*b1cdbd2cSJim Jagielski 
138*b1cdbd2cSJim Jagielski // --------------------------------------------------------------------
139*b1cdbd2cSJim Jagielski 
endFastElement(sal_Int32)140*b1cdbd2cSJim Jagielski void TextBodyPropertiesContext::endFastElement( sal_Int32 ) throw (SAXException, RuntimeException)
141*b1cdbd2cSJim Jagielski {
142*b1cdbd2cSJim Jagielski }
143*b1cdbd2cSJim Jagielski 
144*b1cdbd2cSJim Jagielski // --------------------------------------------------------------------
145*b1cdbd2cSJim Jagielski 
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> &)146*b1cdbd2cSJim Jagielski Reference< XFastContextHandler > TextBodyPropertiesContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& /*xAttributes*/) throw (SAXException, RuntimeException)
147*b1cdbd2cSJim Jagielski {
148*b1cdbd2cSJim Jagielski 	Reference< XFastContextHandler > xRet;
149*b1cdbd2cSJim Jagielski 	switch( aElementToken )
150*b1cdbd2cSJim Jagielski 	{
151*b1cdbd2cSJim Jagielski 			// Sequence
152*b1cdbd2cSJim Jagielski 			case A_TOKEN( prstTxWarp ):		// CT_PresetTextShape
153*b1cdbd2cSJim Jagielski 			case A_TOKEN( prot ):			// CT_TextProtectionProperty
154*b1cdbd2cSJim Jagielski 				break;
155*b1cdbd2cSJim Jagielski 
156*b1cdbd2cSJim Jagielski 			// EG_TextAutofit
157*b1cdbd2cSJim Jagielski 			case A_TOKEN( noAutofit ):
158*b1cdbd2cSJim Jagielski                 mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= false;   // CT_TextNoAutofit
159*b1cdbd2cSJim Jagielski 				break;
160*b1cdbd2cSJim Jagielski 			case A_TOKEN( normAutofit ):	// CT_TextNormalAutofit
161*b1cdbd2cSJim Jagielski                 mrTextBodyProp.maPropertyMap[ PROP_TextFitToSize ] <<= true;
162*b1cdbd2cSJim Jagielski                 mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= false;
163*b1cdbd2cSJim Jagielski                 break;
164*b1cdbd2cSJim Jagielski 			case A_TOKEN( spAutoFit ):
165*b1cdbd2cSJim Jagielski                 mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= true;
166*b1cdbd2cSJim Jagielski 				break;
167*b1cdbd2cSJim Jagielski 
168*b1cdbd2cSJim Jagielski 			case A_TOKEN( scene3d ):		// CT_Scene3D
169*b1cdbd2cSJim Jagielski 
170*b1cdbd2cSJim Jagielski 			// EG_Text3D
171*b1cdbd2cSJim Jagielski 			case A_TOKEN( sp3d ):			// CT_Shape3D
172*b1cdbd2cSJim Jagielski 			case A_TOKEN( flatTx ):			// CT_FlatText
173*b1cdbd2cSJim Jagielski 
174*b1cdbd2cSJim Jagielski 				break;
175*b1cdbd2cSJim Jagielski 	}
176*b1cdbd2cSJim Jagielski 
177*b1cdbd2cSJim Jagielski 	return xRet;
178*b1cdbd2cSJim Jagielski }
179*b1cdbd2cSJim Jagielski 
180*b1cdbd2cSJim Jagielski // --------------------------------------------------------------------
181*b1cdbd2cSJim Jagielski 
182*b1cdbd2cSJim Jagielski } }
183*b1cdbd2cSJim Jagielski 
184