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