1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "drawingml/textbodypropertiescontext.hxx"
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 "drawingml/textbodyproperties.hxx"
26 #include "oox/drawingml/drawingmltypes.hxx"
27 #include "oox/helper/attributelist.hxx"
28 #include "oox/helper/propertymap.hxx"
29 #include <oox/token/namespaces.hxx>
30 #include <oox/token/properties.hxx>
31 #include <oox/token/tokens.hxx>
33 using namespace ::oox::core
;
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::drawing
;
36 using namespace ::com::sun::star::text
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::xml::sax
;
40 namespace oox
{ namespace drawingml
{
42 // CT_TextBodyProperties
43 TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler2Helper
& rParent
,
44 const AttributeList
& rAttribs
, TextBodyProperties
& rTextBodyProp
)
45 : ContextHandler2( rParent
)
46 , mrTextBodyProp( rTextBodyProp
)
48 // ST_TextWrappingType
49 sal_Int32 nWrappingType
= rAttribs
.getToken( XML_wrap
, XML_square
);
50 mrTextBodyProp
.maPropertyMap
.setProperty( PROP_TextWordWrap
, nWrappingType
== XML_square
);
54 sal_Int32 aIns
[] = { XML_lIns
, XML_tIns
, XML_rIns
, XML_bIns
};
55 for( sal_Int32 i
= 0; i
< ( sal_Int32
) SAL_N_ELEMENTS( aIns
); i
++)
57 sValue
= rAttribs
.getString( aIns
[i
] ).get();
58 if( !sValue
.isEmpty() )
59 mrTextBodyProp
.moInsets
[i
] = GetCoordinate( sValue
);
62 mrTextBodyProp
.mbAnchorCtr
= rAttribs
.getBool( XML_anchorCtr
, false );
63 if( mrTextBodyProp
.mbAnchorCtr
)
64 mrTextBodyProp
.maPropertyMap
.setProperty( PROP_TextHorizontalAdjust
, TextHorizontalAdjust_CENTER
);
66 // bool bCompatLineSpacing = rAttribs.getBool( XML_compatLnSpc, false );
67 // bool bForceAA = rAttribs.getBool( XML_forceAA, false );
68 // bool bFromWordArt = rAttribs.getBool( XML_fromWordArt, false );
70 // ST_TextHorzOverflowType
71 // sal_Int32 nHorzOverflow = rAttribs.getToken( XML_horzOverflow, XML_overflow );
72 // ST_TextVertOverflowType
73 // sal_Int32 nVertOverflow = rAttribs.getToken( XML_vertOverflow, XML_overflow );
76 // sal_Int32 nNumCol = rAttribs.getInteger( XML_numCol, 1 );
79 mrTextBodyProp
.moRotation
= rAttribs
.getInteger( XML_rot
);
81 // bool bRtlCol = rAttribs.getBool( XML_rtlCol, false );
82 // ST_PositiveCoordinate
83 // sal_Int32 nSpcCol = rAttribs.getInteger( XML_spcCol, 0 );
84 // bool bSpcFirstLastPara = rAttribs.getBool( XML_spcFirstLastPara, 0 );
85 // bool bUpRight = rAttribs.getBool( XML_upright, 0 );
87 // ST_TextVerticalType
88 if( rAttribs
.hasAttribute( XML_vert
) ) {
89 mrTextBodyProp
.moVert
= rAttribs
.getToken( XML_vert
);
90 sal_Int32 tVert
= mrTextBodyProp
.moVert
.get( XML_horz
);
91 if (tVert
== XML_vert
|| tVert
== XML_eaVert
|| tVert
== XML_mongolianVert
)
92 mrTextBodyProp
.moRotation
= 5400000;
93 else if (tVert
== XML_vert270
)
94 mrTextBodyProp
.moRotation
= 5400000 * 3;
96 bool bRtl
= rAttribs
.getBool( XML_rtl
, false );
97 mrTextBodyProp
.maPropertyMap
.setProperty( PROP_TextWritingMode
,
98 ( bRtl
? WritingMode_RL_TB
: WritingMode_LR_TB
));
102 // ST_TextAnchoringType
103 if( rAttribs
.hasAttribute( XML_anchor
) )
105 mrTextBodyProp
.meVA
= GetTextVerticalAdjust( rAttribs
.getToken( XML_anchor
, XML_t
) );
106 mrTextBodyProp
.maPropertyMap
.setProperty( PROP_TextVerticalAdjust
, mrTextBodyProp
.meVA
);
110 mrTextBodyProp
.maPropertyMap
.setProperty( PROP_TextAutoGrowHeight
, false);
111 mrTextBodyProp
.maPropertyMap
.setProperty( PROP_TextFitToSize
, drawing::TextFitToSizeType_NONE
);
114 ContextHandlerRef
TextBodyPropertiesContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& /*rAttribs*/)
116 switch( aElementToken
)
119 case A_TOKEN( prstTxWarp
): // CT_PresetTextShape
120 case A_TOKEN( prot
): // CT_TextProtectionProperty
124 case A_TOKEN( noAutofit
):
125 mrTextBodyProp
.maPropertyMap
.setProperty( PROP_TextAutoGrowHeight
, false); // CT_TextNoAutofit
127 case A_TOKEN( normAutofit
): // CT_TextNormalAutofit
128 mrTextBodyProp
.maPropertyMap
.setProperty( PROP_TextFitToSize
, TextFitToSizeType_AUTOFIT
);
129 mrTextBodyProp
.maPropertyMap
.setProperty( PROP_TextAutoGrowHeight
, false);
131 case A_TOKEN( spAutoFit
):
133 const sal_Int32 tVert
= mrTextBodyProp
.moVert
.get( XML_horz
);
134 if( tVert
!= XML_vert
&& tVert
!= XML_eaVert
&& tVert
!= XML_vert270
&& tVert
!= XML_mongolianVert
)
135 mrTextBodyProp
.maPropertyMap
.setProperty( PROP_TextAutoGrowHeight
, true);
139 case A_TOKEN( scene3d
): // CT_Scene3D
142 case A_TOKEN( sp3d
): // CT_Shape3D
143 case A_TOKEN( flatTx
): // CT_FlatText
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */