LibreOffice Module oox (master) 1
textbodypropertiescontext.cxx
Go to the documentation of this file.
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
21
22#include <com/sun/star/text/WritingMode.hpp>
23#include <com/sun/star/text/WritingMode2.hpp>
24#include <com/sun/star/drawing/TextFitToSizeType.hpp>
25#include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
26#include <com/sun/star/text/XTextColumns.hpp>
27
36#include <oox/token/namespaces.hxx>
37#include <oox/token/properties.hxx>
38#include <oox/token/tokens.hxx>
40
41using namespace ::oox::core;
42using namespace ::com::sun::star;
43using namespace ::com::sun::star::drawing;
44using namespace ::com::sun::star::text;
45using namespace ::com::sun::star::uno;
46using namespace ::com::sun::star::xml::sax;
47
48namespace oox::drawingml {
49
50// CT_TextBodyProperties
51TextBodyPropertiesContext::TextBodyPropertiesContext(ContextHandler2Helper const& rParent,
52 const AttributeList& rAttribs,
53 const ShapePtr& pShapePtr)
54 : TextBodyPropertiesContext(rParent, rAttribs, pShapePtr->getTextBody()->getTextProperties())
55{
56 mpShapePtr = pShapePtr;
57}
58
59TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler2Helper const & rParent,
60 const AttributeList& rAttribs, TextBodyProperties& rTextBodyProp )
61: ContextHandler2( rParent )
62, mrTextBodyProp( rTextBodyProp )
63{
64 // ST_TextWrappingType
65 sal_Int32 nWrappingType = rAttribs.getToken( XML_wrap, XML_square );
66 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextWordWrap, nWrappingType == XML_square );
67
68 // ST_Coordinate
69 OUString sValue;
70 sal_Int32 aIns[] = { XML_lIns, XML_tIns, XML_rIns, XML_bIns };
71 for( sal_Int32 i = 0; i < sal_Int32(std::size( aIns )); i++)
72 {
73 sValue = rAttribs.getStringDefaulted( aIns[i] );
74 if( !sValue.isEmpty() )
75 mrTextBodyProp.moInsets[i] = GetCoordinate( sValue );
76 }
77
78// bool bCompatLineSpacing = rAttribs.getBool( XML_compatLnSpc, false );
79// bool bForceAA = rAttribs.getBool( XML_forceAA, false );
80 bool bFromWordArt = rAttribs.getBool(XML_fromWordArt, false);
81 mrTextBodyProp.maPropertyMap.setProperty(PROP_FromWordArt, bFromWordArt);
82
83 // ST_TextHorzOverflowType
84 mrTextBodyProp.msHorzOverflow = rAttribs.getStringDefaulted(XML_horzOverflow);
85 // ST_TextVertOverflowType
86 if( rAttribs.hasAttribute(XML_vertOverflow) )
87 {
88 mrTextBodyProp.moVertOverflow = rAttribs.getToken(XML_vertOverflow);
89 switch( mrTextBodyProp.moVertOverflow.value_or(XML_overflow) )
90 {
91 case XML_ellipsis:
92 case XML_clip:
93 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextClipVerticalOverflow, true);
94 break;
95 default:
96 break;
97 }
98 }
99
100 // ST_TextColumnCount
101 if (const sal_Int32 nColumns = rAttribs.getInteger(XML_numCol, 0); nColumns > 0)
102 {
103 css::uno::Reference<css::text::XTextColumns> xCols(SvxXTextColumns_createInstance(),
104 css::uno::UNO_QUERY_THROW);
105 xCols->setColumnCount(nColumns);
106 css::uno::Reference<css::beans::XPropertySet> xProps(xCols, css::uno::UNO_QUERY_THROW);
107 // ST_PositiveCoordinate32
108 const sal_Int32 nSpacing = o3tl::convert(rAttribs.getInteger(XML_spcCol, 0),
110 xProps->setPropertyValue("AutomaticDistance", css::uno::Any(nSpacing));
111 mrTextBodyProp.maPropertyMap.setAnyProperty(PROP_TextColumns, css::uno::Any(xCols));
112 }
113
114 // ST_Angle
115 if (rAttribs.getInteger(XML_rot).has_value())
116 mrTextBodyProp.moTextAreaRotation = rAttribs.getInteger(XML_rot).value();
117
118// bool bRtlCol = rAttribs.getBool( XML_rtlCol, false );
119 // ST_PositiveCoordinate
120// sal_Int32 nSpcCol = rAttribs.getInteger( XML_spcCol, 0 );
121// bool bSpcFirstLastPara = rAttribs.getBool( XML_spcFirstLastPara, 0 );
122
123 bool bUpright = rAttribs.getBool(XML_upright, false);
124 if (bUpright)
125 mrTextBodyProp.moUpright = true;
126
127 // ST_TextVerticalType
128 if( rAttribs.hasAttribute( XML_vert ) ) {
129 mrTextBodyProp.moVert = rAttribs.getToken( XML_vert );
130 sal_Int32 tVert = mrTextBodyProp.moVert.value_or( XML_horz );
131 if (tVert == XML_eaVert)
132 {
133 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextWritingMode, WritingMode_TB_RL);
134 mrTextBodyProp.maPropertyMap.setProperty(PROP_WritingMode, text::WritingMode2::TB_RL);
135 }
136 else if (tVert == XML_vert)
137 {
138 mrTextBodyProp.maPropertyMap.setProperty(PROP_WritingMode, text::WritingMode2::TB_RL90);
139 }
140 else if (tVert == XML_mongolianVert)
141 {
142 // rendering not yet implemented for shape text, only for frames
143 mrTextBodyProp.maPropertyMap.setProperty(PROP_WritingMode, text::WritingMode2::TB_LR);
144 }
145 else if (tVert == XML_vert270)
146 {
147 mrTextBodyProp.maPropertyMap.setProperty(PROP_WritingMode, text::WritingMode2::BT_LR);
148 }
149 else {
150 bool bRtl = rAttribs.getBool( XML_rtl, false );
151 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextWritingMode,
152 ( bRtl ? WritingMode_RL_TB : WritingMode_LR_TB ));
153 mrTextBodyProp.maPropertyMap.setProperty(PROP_WritingMode,
154 ( bRtl ? text::WritingMode2::RL_TB : text::WritingMode2::LR_TB));
155 }
156 }
157
158 // ST_TextAnchoringType
159 mrTextBodyProp.mbAnchorCtr = rAttribs.getBool(XML_anchorCtr, false );
160 if (rAttribs.hasAttribute(XML_anchor))
161 mrTextBodyProp.meVA = GetTextVerticalAdjust( rAttribs.getToken(XML_anchor, XML_t));
162 // else meVA is initialized to TextVerticalAdjust_TOP
163
164 sal_Int32 tVert = mrTextBodyProp.moVert.value_or(XML_horz);
165 if (tVert == XML_eaVert || tVert == XML_mongolianVert)
166 {
167 if (mrTextBodyProp.mbAnchorCtr)
168 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextVerticalAdjust,
169 TextVerticalAdjust_CENTER);
170 else
171 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextVerticalAdjust,
172 TextVerticalAdjust_TOP);
173
174 if (mrTextBodyProp.meVA == TextVerticalAdjust_CENTER)
175 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextHorizontalAdjust,
176 TextHorizontalAdjust_CENTER);
177 else if (mrTextBodyProp.meVA == TextVerticalAdjust_TOP)
178 {
179 mrTextBodyProp.maPropertyMap.setProperty(
180 PROP_TextHorizontalAdjust,
181 tVert == XML_eaVert ? TextHorizontalAdjust_RIGHT : TextHorizontalAdjust_LEFT);
182 }
183 else // meVA == TextVerticalAdjust_BOTTOM
184 {
185 mrTextBodyProp.maPropertyMap.setProperty(
186 PROP_TextHorizontalAdjust,
187 tVert == XML_eaVert ? TextHorizontalAdjust_LEFT : TextHorizontalAdjust_RIGHT);
188 }
189 }
190 else
191 {
192 if (mrTextBodyProp.mbAnchorCtr)
193 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextHorizontalAdjust,
194 TextHorizontalAdjust_CENTER);
195 else // BLOCK is nearer to rendering in MS Office than LEFT, see tdf#137023
196 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextHorizontalAdjust,
197 TextHorizontalAdjust_BLOCK);
198 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextVerticalAdjust, mrTextBodyProp.meVA);
199 }
200
201 // Push defaults
202 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, false);
203 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextFitToSize, drawing::TextFitToSizeType_NONE);
204}
205
206ContextHandlerRef TextBodyPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
207{
208 switch( aElementToken )
209 {
210 // Sequence
211 case A_TOKEN( prstTxWarp ): // CT_PresetTextShape
212 if( mpShapePtr )
213 {
214 const std::optional<OUString> sPrst = rAttribs.getString( XML_prst );
215 if( sPrst.has_value() )
216 {
217 mrTextBodyProp.msPrst = sPrst.value();
218 if( mrTextBodyProp.msPrst != "textNoShape" )
219 return new PresetTextShapeContext( *this, rAttribs,
220 *( mpShapePtr->getCustomShapeProperties() ) );
221 }
222 }
223 break;
224
225 case A_TOKEN( prot ): // CT_TextProtectionProperty
226 break;
227
228 // EG_TextAutofit
229 case A_TOKEN( noAutofit ):
230 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, false); // CT_TextNoAutofit
231 break;
232 case A_TOKEN( normAutofit ): // CT_TextNormalAutofit
233 {
234 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextFitToSize, TextFitToSizeType_AUTOFIT);
235 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, false);
236 mrTextBodyProp.mnFontScale = rAttribs.getInteger(XML_fontScale, 100000);
237 break;
238 }
239 case A_TOKEN( spAutoFit ):
240 {
241 const sal_Int32 tVert = mrTextBodyProp.moVert.value_or( XML_horz );
242 if( tVert != XML_vert && tVert != XML_eaVert && tVert != XML_vert270 && tVert != XML_mongolianVert )
243 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, true);
244 }
245 break;
246
247 case A_TOKEN( scene3d ): // CT_Scene3D
248 {
249 if(mpShapePtr && mpShapePtr->getServiceName() == "com.sun.star.drawing.CustomShape")
250 return new SceneText3DPropertiesContext( *this, mpShapePtr->getTextBody()->get3DProperties() );
251
252 break;
253 }
254
255 // EG_Text3D
256 case A_TOKEN( sp3d ): // CT_Shape3D
257 {
258 if (mpShapePtr && mpShapePtr->getServiceName() == "com.sun.star.drawing.CustomShape")
259 {
260 if (rAttribs.hasAttribute(XML_extrusionH))
261 mpShapePtr->getTextBody()->get3DProperties().mnExtrusionH = rAttribs.getInteger(XML_extrusionH, 0);
262 if (rAttribs.hasAttribute(XML_contourW))
263 mpShapePtr->getTextBody()->get3DProperties().mnContourW = rAttribs.getInteger(XML_contourW, 0);
264 if (rAttribs.hasAttribute(XML_z))
265 mpShapePtr->getTextBody()->get3DProperties().mnShapeZ = rAttribs.getInteger(XML_z, 0);
266 if (rAttribs.hasAttribute(XML_prstMaterial))
267 mpShapePtr->getTextBody()->get3DProperties().mnMaterial = rAttribs.getToken(XML_prstMaterial, XML_none);
268 return new SceneText3DPropertiesContext(*this, mpShapePtr->getTextBody()->get3DProperties());
269 }
270 break;
271 }
272
273 case A_TOKEN( flatTx ): // CT_FlatText
274
275 break;
276 }
277
278 return nullptr;
279}
280
281}
282
283/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxXTextColumns_createInstance() noexcept
Provides access to attribute values of an element.
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
std::optional< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
TextBodyPropertiesContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttributes, TextBodyProperties &rTextBodyProp)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
TextVerticalAdjust GetTextVerticalAdjust(sal_Int32 nToken)
sal_Int32 GetCoordinate(sal_Int32 nValue)
converts EMUs into 1/100th mmm
std::shared_ptr< Shape > ShapePtr
XML_none
constexpr OUStringLiteral PROP_TextFitToSize
constexpr OUStringLiteral PROP_TextAutoGrowHeight