Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "oox/drawingml/textbodypropertiescontext.hxx"
21 :
22 : #include <com/sun/star/text/WritingMode.hpp>
23 : #include <com/sun/star/drawing/TextFitToSizeType.hpp>
24 : #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
25 : #include "oox/drawingml/textbodyproperties.hxx"
26 : #include "oox/drawingml/drawingmltypes.hxx"
27 : #include "oox/helper/attributelist.hxx"
28 : #include "oox/helper/propertymap.hxx"
29 :
30 : using namespace ::oox::core;
31 : using namespace ::com::sun::star;
32 : using namespace ::com::sun::star::drawing;
33 : using namespace ::com::sun::star::text;
34 : using namespace ::com::sun::star::uno;
35 : using namespace ::com::sun::star::xml::sax;
36 :
37 : namespace oox { namespace drawingml {
38 :
39 : // --------------------------------------------------------------------
40 :
41 : // CT_TextBodyProperties
42 53 : TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler& rParent,
43 : const Reference< XFastAttributeList >& xAttributes, TextBodyProperties& rTextBodyProp )
44 : : ContextHandler( rParent )
45 53 : , mrTextBodyProp( rTextBodyProp )
46 : {
47 53 : AttributeList aAttribs( xAttributes );
48 :
49 : // ST_TextWrappingType
50 53 : sal_Int32 nWrappingType = aAttribs.getToken( XML_wrap, XML_square );
51 53 : mrTextBodyProp.maPropertyMap[ PROP_TextWordWrap ] <<= static_cast< sal_Bool >( nWrappingType == XML_square );
52 :
53 : // ST_Coordinate
54 53 : OUString sValue;
55 53 : sal_Int32 aIns[] = { XML_lIns, XML_tIns, XML_rIns, XML_bIns };
56 265 : for( sal_Int32 i = 0; i < ( sal_Int32 )( sizeof( aIns ) / sizeof( sal_Int32 ) ); i++)
57 : {
58 212 : sValue = xAttributes->getOptionalValue( aIns[i] );
59 212 : if( !sValue.isEmpty() )
60 128 : mrTextBodyProp.moInsets[i] = GetCoordinate( sValue );
61 : }
62 :
63 53 : bool bAnchorCenter = aAttribs.getBool( XML_anchorCtr, false );
64 53 : if( xAttributes->hasAttribute( XML_anchorCtr ) ) {
65 7 : if( bAnchorCenter )
66 0 : mrTextBodyProp.maPropertyMap[ PROP_TextHorizontalAdjust ] <<=
67 0 : TextHorizontalAdjust_CENTER;
68 : }
69 : // bool bCompatLineSpacing = aAttribs.getBool( XML_compatLnSpc, false );
70 : // bool bForceAA = aAttribs.getBool( XML_forceAA, false );
71 : // bool bFromWordArt = aAttribs.getBool( XML_fromWordArt, false );
72 :
73 : // ST_TextHorzOverflowType
74 : // sal_Int32 nHorzOverflow = xAttributes->getOptionalValueToken( XML_horzOverflow, XML_overflow );
75 : // ST_TextVertOverflowType
76 : // sal_Int32 nVertOverflow = xAttributes->getOptionalValueToken( XML_vertOverflow, XML_overflow );
77 :
78 : // ST_TextColumnCount
79 : // sal_Int32 nNumCol = aAttribs.getInteger( XML_numCol, 1 );
80 :
81 : // ST_Angle
82 53 : mrTextBodyProp.moRotation = aAttribs.getInteger( XML_rot );
83 :
84 : // bool bRtlCol = aAttribs.getBool( XML_rtlCol, false );
85 : // ST_PositiveCoordinate
86 : // sal_Int32 nSpcCol = aAttribs.getInteger( XML_spcCol, 0 );
87 : // bool bSpcFirstLastPara = aAttribs.getBool( XML_spcFirstLastPara, 0 );
88 : // bool bUpRight = aAttribs.getBool( XML_upright, 0 );
89 :
90 : // ST_TextVerticalType
91 53 : if( xAttributes->hasAttribute( XML_vert ) ) {
92 23 : mrTextBodyProp.moVert = aAttribs.getToken( XML_vert );
93 23 : bool bRtl = aAttribs.getBool( XML_rtl, false );
94 23 : sal_Int32 tVert = mrTextBodyProp.moVert.get( XML_horz );
95 23 : if( tVert == XML_vert || tVert == XML_eaVert || tVert == XML_vert270 || tVert == XML_mongolianVert )
96 0 : mrTextBodyProp.moRotation = -5400000*(tVert==XML_vert270?3:1);
97 : else
98 23 : mrTextBodyProp.maPropertyMap[ PROP_TextWritingMode ]
99 46 : <<= ( bRtl ? WritingMode_RL_TB : WritingMode_LR_TB );
100 : }
101 :
102 : // ST_TextAnchoringType
103 53 : if( xAttributes->hasAttribute( XML_anchor ) ) {
104 23 : switch( xAttributes->getOptionalValueToken( XML_anchor, XML_t ) )
105 : {
106 2 : case XML_b : mrTextBodyProp.meVA = drawing::TextVerticalAdjust_BOTTOM; break;
107 : case XML_dist :
108 : case XML_just :
109 18 : case XML_ctr : mrTextBodyProp.meVA = drawing::TextVerticalAdjust_CENTER; break;
110 : default:
111 3 : case XML_t : mrTextBodyProp.meVA = drawing::TextVerticalAdjust_TOP; break;
112 : }
113 23 : mrTextBodyProp.maPropertyMap[ PROP_TextVerticalAdjust ] <<= mrTextBodyProp.meVA;
114 : }
115 :
116 : // Push defaults
117 53 : mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= false;
118 53 : mrTextBodyProp.maPropertyMap[ PROP_TextFitToSize ] <<= drawing::TextFitToSizeType_NONE;
119 53 : }
120 :
121 : // --------------------------------------------------------------------
122 :
123 53 : void TextBodyPropertiesContext::endFastElement( sal_Int32 ) throw (SAXException, RuntimeException)
124 : {
125 53 : }
126 :
127 : // --------------------------------------------------------------------
128 :
129 12 : Reference< XFastContextHandler > TextBodyPropertiesContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& /*xAttributes*/) throw (SAXException, RuntimeException)
130 : {
131 12 : Reference< XFastContextHandler > xRet;
132 12 : switch( aElementToken )
133 : {
134 : // Sequence
135 : case A_TOKEN( prstTxWarp ): // CT_PresetTextShape
136 : case A_TOKEN( prot ): // CT_TextProtectionProperty
137 4 : break;
138 :
139 : // EG_TextAutofit
140 : case A_TOKEN( noAutofit ):
141 3 : mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= false; // CT_TextNoAutofit
142 3 : break;
143 : case A_TOKEN( normAutofit ): // CT_TextNormalAutofit
144 5 : mrTextBodyProp.maPropertyMap[ PROP_TextFitToSize ] <<= TextFitToSizeType_AUTOFIT;
145 5 : mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= false;
146 5 : break;
147 : case A_TOKEN( spAutoFit ):
148 0 : mrTextBodyProp.maPropertyMap[ PROP_TextAutoGrowHeight ] <<= true;
149 0 : break;
150 :
151 : case A_TOKEN( scene3d ): // CT_Scene3D
152 :
153 : // EG_Text3D
154 : case A_TOKEN( sp3d ): // CT_Shape3D
155 : case A_TOKEN( flatTx ): // CT_FlatText
156 :
157 0 : break;
158 : }
159 :
160 12 : return xRet;
161 : }
162 :
163 : // --------------------------------------------------------------------
164 :
165 : } }
166 :
167 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|