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