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