xref: /trunk/main/oox/source/drawingml/textbodypropertiescontext.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/drawingml/textbodypropertiescontext.hxx"
29 
30 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
31 #include <com/sun/star/text/ControlCharacter.hpp>
32 #include <com/sun/star/text/WritingMode.hpp>
33 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
34 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
35 #include "oox/drawingml/textbodyproperties.hxx"
36 #include "oox/drawingml/drawingmltypes.hxx"
37 #include "oox/helper/attributelist.hxx"
38 #include "oox/helper/propertymap.hxx"
39 
40 using ::rtl::OUString;
41 using namespace ::oox::core;
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::drawing;
44 using namespace ::com::sun::star::text;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::xml::sax;
47 
48 namespace oox { namespace drawingml {
49 
50 // --------------------------------------------------------------------
51 
52 // CT_TextBodyProperties
53 TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler& rParent,
54     const Reference< XFastAttributeList >& xAttributes, TextBodyProperties& rTextBodyProp )
55 : ContextHandler( rParent )
56 , mrTextBodyProp( rTextBodyProp )
57 {
58     AttributeList aAttribs( xAttributes );
59 
60     // ST_TextWrappingType
61     sal_Int32 nWrappingType = aAttribs.getToken( XML_wrap, XML_square );
62     mrTextBodyProp.maPropertyMap[ PROP_TextWordWrap ] <<= static_cast< sal_Bool >( nWrappingType == XML_square );
63 
64     // ST_Coordinate
65     OUString sValue;
66     sValue = xAttributes->getOptionalValue( XML_lIns );
67     if( sValue.getLength() ) {
68     sal_Int32 nLeftInset = ( sValue.getLength() != 0 ? GetCoordinate(  sValue ) : 91440 / 360 );
69     mrTextBodyProp.maPropertyMap[ PROP_TextLeftDistance ]  <<= static_cast< sal_Int32 >( nLeftInset );
70     }
71     sValue = xAttributes->getOptionalValue( XML_tIns );
72     if( sValue.getLength() ) {
73     sal_Int32 nTopInset  = ( sValue.getLength() != 0 ? GetCoordinate(  sValue ) : 91440 / 360 );
74     mrTextBodyProp.maPropertyMap[ PROP_TextUpperDistance ] <<= static_cast< sal_Int32 >( nTopInset );
75     }
76     sValue = xAttributes->getOptionalValue( XML_rIns );
77     if( sValue.getLength() ) {
78     sal_Int32 nRightInset  = ( sValue.getLength() != 0 ? GetCoordinate(  sValue ) : 91440 / 360 );
79     mrTextBodyProp.maPropertyMap[ PROP_TextRightDistance ] <<= static_cast< sal_Int32 >( nRightInset );
80     }
81     sValue = xAttributes->getOptionalValue( XML_bIns );
82     if( sValue.getLength() ) {
83     sal_Int32 nBottonInset = ( sValue.getLength() != 0 ? GetCoordinate(  sValue ) : 45720 / 360 );
84     mrTextBodyProp.maPropertyMap[ PROP_TextLowerDistance ] <<= static_cast< sal_Int32 >( nBottonInset );
85     }
86 
87     // ST_TextAnchoringType
88     drawing::TextVerticalAdjust eVA( drawing::TextVerticalAdjust_TOP );
89     switch( xAttributes->getOptionalValueToken( XML_anchor, XML_t ) )
90     {
91         case XML_b :    eVA = drawing::TextVerticalAdjust_BOTTOM; break;
92         case XML_dist :
93         case XML_just :
94         case XML_ctr :  eVA = drawing::TextVerticalAdjust_CENTER; break;
95         default:
96         case XML_t :    eVA = drawing::TextVerticalAdjust_TOP; break;
97     }
98     mrTextBodyProp.maPropertyMap[ PROP_TextVerticalAdjust ] <<= eVA;
99 
100     bool bAnchorCenter = aAttribs.getBool( XML_anchorCtr, false );
101     if( bAnchorCenter )
102     mrTextBodyProp.maPropertyMap[ PROP_TextHorizontalAdjust ] <<=
103         TextHorizontalAdjust_CENTER;
104 
105 //   bool bCompatLineSpacing = aAttribs.getBool( XML_compatLnSpc, false );
106 //   bool bForceAA = aAttribs.getBool( XML_forceAA, false );
107 //   bool bFromWordArt = aAttribs.getBool( XML_fromWordArt, false );
108 
109   // ST_TextHorzOverflowType
110 //   sal_Int32 nHorzOverflow = xAttributes->getOptionalValueToken( XML_horzOverflow, XML_overflow );
111     // ST_TextVertOverflowType
112 //   sal_Int32 nVertOverflow =  xAttributes->getOptionalValueToken( XML_vertOverflow, XML_overflow );
113 
114     // ST_TextColumnCount
115 //   sal_Int32 nNumCol = aAttribs.getInteger( XML_numCol, 1 );
116 
117     // ST_Angle
118     mrTextBodyProp.moRotation = aAttribs.getInteger( XML_rot );
119 
120 //   bool bRtlCol = aAttribs.getBool( XML_rtlCol, false );
121     // ST_PositiveCoordinate
122 //   sal_Int32 nSpcCol = aAttribs.getInteger( XML_spcCol, 0 );
123 //   bool bSpcFirstLastPara = aAttribs.getBool( XML_spcFirstLastPara, 0 );
124 //   bool bUpRight = aAttribs.getBool( XML_upright, 0 );
125 
126     // ST_TextVerticalType
127     mrTextBodyProp.moVert = aAttribs.getToken( XML_vert );
128     bool bRtl = aAttribs.getBool( XML_rtl, false );
129     sal_Int32 tVert = mrTextBodyProp.moVert.get( XML_horz );
130     if( tVert == XML_vert || tVert == XML_eaVert || tVert == XML_vert270 || tVert == XML_mongolianVert ) {
131       mrTextBodyProp.maPropertyMap[ PROP_TextWritingMode ]
132     <<= WritingMode_TB_RL;
133       // workaround for TB_LR as using WritingMode2 doesn't work
134         if( !bAnchorCenter )
135             mrTextBodyProp.maPropertyMap[ PROP_TextHorizontalAdjust ] <<=
136             TextHorizontalAdjust_LEFT;
137     } else
138       mrTextBodyProp.maPropertyMap[ PROP_TextWritingMode ]
139     <<= ( bRtl ? WritingMode_RL_TB : WritingMode_LR_TB );
140 }
141 
142 // --------------------------------------------------------------------
143 
144 void TextBodyPropertiesContext::endFastElement( sal_Int32 ) throw (SAXException, RuntimeException)
145 {
146 }
147 
148 // --------------------------------------------------------------------
149 
150 Reference< XFastContextHandler > TextBodyPropertiesContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& /*xAttributes*/) throw (SAXException, RuntimeException)
151 {
152     Reference< XFastContextHandler > xRet;
153     switch( aElementToken )
154     {
155             // Sequence
156             case A_TOKEN( prstTxWarp ):     // CT_PresetTextShape
157             case A_TOKEN( prot ):           // CT_TextProtectionProperty
158                 break;
159 
160             // EG_TextAutofit
161             case A_TOKEN( noAutofit ):
162                 mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= false;   // CT_TextNoAutofit
163                 break;
164             case A_TOKEN( normAutofit ):    // CT_TextNormalAutofit
165                 mrTextBodyProp.maPropertyMap[ PROP_TextFitToSize ] <<= true;
166                 mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= false;
167                 break;
168             case A_TOKEN( spAutoFit ):
169                 mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= true;
170                 break;
171 
172             case A_TOKEN( scene3d ):        // CT_Scene3D
173 
174             // EG_Text3D
175             case A_TOKEN( sp3d ):           // CT_Shape3D
176             case A_TOKEN( flatTx ):         // CT_FlatText
177 
178                 break;
179     }
180 
181     return xRet;
182 }
183 
184 // --------------------------------------------------------------------
185 
186 } }
187 
188