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 : // CT_TextBodyProperties
40 0 : TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler2Helper& rParent,
41 : const AttributeList& rAttribs, TextBodyProperties& rTextBodyProp )
42 : : ContextHandler2( rParent )
43 0 : , mrTextBodyProp( rTextBodyProp )
44 : {
45 : // ST_TextWrappingType
46 0 : sal_Int32 nWrappingType = rAttribs.getToken( XML_wrap, XML_square );
47 0 : mrTextBodyProp.maPropertyMap.setProperty( PROP_TextWordWrap, static_cast< sal_Bool >( nWrappingType == XML_square ));
48 :
49 : // ST_Coordinate
50 0 : OUString sValue;
51 0 : sal_Int32 aIns[] = { XML_lIns, XML_tIns, XML_rIns, XML_bIns };
52 0 : for( sal_Int32 i = 0; i < ( sal_Int32 )( sizeof( aIns ) / sizeof( sal_Int32 ) ); i++)
53 : {
54 0 : sValue = rAttribs.getString( aIns[i] ).get();
55 0 : if( !sValue.isEmpty() )
56 0 : mrTextBodyProp.moInsets[i] = GetCoordinate( sValue );
57 : }
58 :
59 0 : mrTextBodyProp.mbAnchorCtr = rAttribs.getBool( XML_anchorCtr, false );
60 0 : if( mrTextBodyProp.mbAnchorCtr )
61 0 : mrTextBodyProp.maPropertyMap.setProperty( PROP_TextHorizontalAdjust, TextHorizontalAdjust_CENTER );
62 :
63 : // bool bCompatLineSpacing = rAttribs.getBool( XML_compatLnSpc, false );
64 : // bool bForceAA = rAttribs.getBool( XML_forceAA, false );
65 : // bool bFromWordArt = rAttribs.getBool( XML_fromWordArt, false );
66 :
67 : // ST_TextHorzOverflowType
68 : // sal_Int32 nHorzOverflow = rAttribs.getToken( XML_horzOverflow, XML_overflow );
69 : // ST_TextVertOverflowType
70 : // sal_Int32 nVertOverflow = rAttribs.getToken( XML_vertOverflow, XML_overflow );
71 :
72 : // ST_TextColumnCount
73 : // sal_Int32 nNumCol = rAttribs.getInteger( XML_numCol, 1 );
74 :
75 : // ST_Angle
76 0 : mrTextBodyProp.moRotation = rAttribs.getInteger( XML_rot );
77 :
78 : // bool bRtlCol = rAttribs.getBool( XML_rtlCol, false );
79 : // ST_PositiveCoordinate
80 : // sal_Int32 nSpcCol = rAttribs.getInteger( XML_spcCol, 0 );
81 : // bool bSpcFirstLastPara = rAttribs.getBool( XML_spcFirstLastPara, 0 );
82 : // bool bUpRight = rAttribs.getBool( XML_upright, 0 );
83 :
84 : // ST_TextVerticalType
85 0 : if( rAttribs.hasAttribute( XML_vert ) ) {
86 0 : mrTextBodyProp.moVert = rAttribs.getToken( XML_vert );
87 0 : bool bRtl = rAttribs.getBool( XML_rtl, false );
88 0 : sal_Int32 tVert = mrTextBodyProp.moVert.get( XML_horz );
89 0 : if( tVert == XML_vert || tVert == XML_eaVert || tVert == XML_vert270 || tVert == XML_mongolianVert )
90 0 : mrTextBodyProp.moRotation = -5400000*(tVert==XML_vert270?3:1);
91 : else
92 : mrTextBodyProp.maPropertyMap.setProperty( PROP_TextWritingMode,
93 0 : ( bRtl ? WritingMode_RL_TB : WritingMode_LR_TB ));
94 : }
95 :
96 : // ST_TextAnchoringType
97 0 : if( rAttribs.hasAttribute( XML_anchor ) )
98 : {
99 0 : mrTextBodyProp.meVA = GetTextVerticalAdjust( rAttribs.getToken( XML_anchor, XML_t ) );
100 0 : mrTextBodyProp.maPropertyMap.setProperty( PROP_TextVerticalAdjust, mrTextBodyProp.meVA);
101 : }
102 :
103 : // Push defaults
104 0 : mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, false);
105 0 : mrTextBodyProp.maPropertyMap.setProperty( PROP_TextFitToSize, drawing::TextFitToSizeType_NONE);
106 0 : }
107 :
108 0 : ContextHandlerRef TextBodyPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& /*rAttribs*/)
109 : {
110 0 : switch( aElementToken )
111 : {
112 : // Sequence
113 : case A_TOKEN( prstTxWarp ): // CT_PresetTextShape
114 : case A_TOKEN( prot ): // CT_TextProtectionProperty
115 0 : break;
116 :
117 : // EG_TextAutofit
118 : case A_TOKEN( noAutofit ):
119 0 : mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, false); // CT_TextNoAutofit
120 0 : break;
121 : case A_TOKEN( normAutofit ): // CT_TextNormalAutofit
122 0 : mrTextBodyProp.maPropertyMap.setProperty( PROP_TextFitToSize, TextFitToSizeType_AUTOFIT);
123 0 : mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, false);
124 0 : break;
125 : case A_TOKEN( spAutoFit ):
126 0 : mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, true);
127 0 : break;
128 :
129 : case A_TOKEN( scene3d ): // CT_Scene3D
130 :
131 : // EG_Text3D
132 : case A_TOKEN( sp3d ): // CT_Shape3D
133 : case A_TOKEN( flatTx ): // CT_FlatText
134 :
135 0 : break;
136 : }
137 :
138 0 : return 0;
139 : }
140 :
141 : } }
142 :
143 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|