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 "oox/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 "oox/drawingml/textbodyproperties.hxx"
26 #include "oox/drawingml/drawingmltypes.hxx"
27 #include "oox/helper/attributelist.hxx"
28 #include "oox/helper/propertymap.hxx"
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
;
37 namespace oox
{ namespace drawingml
{
39 // --------------------------------------------------------------------
41 // CT_TextBodyProperties
42 TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler
& rParent
,
43 const Reference
< XFastAttributeList
>& xAttributes
, TextBodyProperties
& rTextBodyProp
)
44 : ContextHandler( rParent
)
45 , mrTextBodyProp( rTextBodyProp
)
47 AttributeList
aAttribs( xAttributes
);
49 // ST_TextWrappingType
50 sal_Int32 nWrappingType
= aAttribs
.getToken( XML_wrap
, XML_square
);
51 mrTextBodyProp
.maPropertyMap
[ PROP_TextWordWrap
] <<= static_cast< sal_Bool
>( nWrappingType
== XML_square
);
55 sal_Int32 aIns
[] = { XML_lIns
, XML_tIns
, XML_rIns
, XML_bIns
};
56 for( sal_Int32 i
= 0; i
< ( sal_Int32
)( sizeof( aIns
) / sizeof( sal_Int32
) ); i
++)
58 sValue
= xAttributes
->getOptionalValue( aIns
[i
] );
59 if( !sValue
.isEmpty() )
60 mrTextBodyProp
.moInsets
[i
] = GetCoordinate( sValue
);
63 bool bAnchorCenter
= aAttribs
.getBool( XML_anchorCtr
, false );
64 if( xAttributes
->hasAttribute( XML_anchorCtr
) ) {
66 mrTextBodyProp
.maPropertyMap
[ PROP_TextHorizontalAdjust
] <<=
67 TextHorizontalAdjust_CENTER
;
69 // bool bCompatLineSpacing = aAttribs.getBool( XML_compatLnSpc, false );
70 // bool bForceAA = aAttribs.getBool( XML_forceAA, false );
71 // bool bFromWordArt = aAttribs.getBool( XML_fromWordArt, false );
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 );
79 // sal_Int32 nNumCol = aAttribs.getInteger( XML_numCol, 1 );
82 mrTextBodyProp
.moRotation
= aAttribs
.getInteger( XML_rot
);
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 );
90 // ST_TextVerticalType
91 if( xAttributes
->hasAttribute( XML_vert
) ) {
92 mrTextBodyProp
.moVert
= aAttribs
.getToken( XML_vert
);
93 bool bRtl
= aAttribs
.getBool( XML_rtl
, false );
94 sal_Int32 tVert
= mrTextBodyProp
.moVert
.get( XML_horz
);
95 if( tVert
== XML_vert
|| tVert
== XML_eaVert
|| tVert
== XML_vert270
|| tVert
== XML_mongolianVert
)
96 mrTextBodyProp
.moRotation
= -5400000*(tVert
==XML_vert270
?3:1);
98 mrTextBodyProp
.maPropertyMap
[ PROP_TextWritingMode
]
99 <<= ( bRtl
? WritingMode_RL_TB
: WritingMode_LR_TB
);
102 // ST_TextAnchoringType
103 if( xAttributes
->hasAttribute( XML_anchor
) ) {
104 switch( xAttributes
->getOptionalValueToken( XML_anchor
, XML_t
) )
106 case XML_b
: mrTextBodyProp
.meVA
= drawing::TextVerticalAdjust_BOTTOM
; break;
109 case XML_ctr
: mrTextBodyProp
.meVA
= drawing::TextVerticalAdjust_CENTER
; break;
111 case XML_t
: mrTextBodyProp
.meVA
= drawing::TextVerticalAdjust_TOP
; break;
113 mrTextBodyProp
.maPropertyMap
[ PROP_TextVerticalAdjust
] <<= mrTextBodyProp
.meVA
;
117 mrTextBodyProp
.maPropertyMap
[ PROP_TextAutoGrowHeight
] <<= false;
118 mrTextBodyProp
.maPropertyMap
[ PROP_TextFitToSize
] <<= drawing::TextFitToSizeType_NONE
;
121 // --------------------------------------------------------------------
123 void TextBodyPropertiesContext::endFastElement( sal_Int32
) throw (SAXException
, RuntimeException
)
127 // --------------------------------------------------------------------
129 Reference
< XFastContextHandler
> TextBodyPropertiesContext::createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& /*xAttributes*/) throw (SAXException
, RuntimeException
)
131 Reference
< XFastContextHandler
> xRet
;
132 switch( aElementToken
)
135 case A_TOKEN( prstTxWarp
): // CT_PresetTextShape
136 case A_TOKEN( prot
): // CT_TextProtectionProperty
140 case A_TOKEN( noAutofit
):
141 mrTextBodyProp
.maPropertyMap
[ PROP_TextAutoGrowHeight
] <<= false; // CT_TextNoAutofit
143 case A_TOKEN( normAutofit
): // CT_TextNormalAutofit
144 mrTextBodyProp
.maPropertyMap
[ PROP_TextFitToSize
] <<= TextFitToSizeType_AUTOFIT
;
145 mrTextBodyProp
.maPropertyMap
[ PROP_TextAutoGrowHeight
] <<= false;
147 case A_TOKEN( spAutoFit
):
148 mrTextBodyProp
.maPropertyMap
[ PROP_TextAutoGrowHeight
] <<= true;
151 case A_TOKEN( scene3d
): // CT_Scene3D
154 case A_TOKEN( sp3d
): // CT_Shape3D
155 case A_TOKEN( flatTx
): // CT_FlatText
163 // --------------------------------------------------------------------
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */