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 mrTextBodyProp.msVertOverflow = rAttribs.getStringDefaulted(XML_vertOverflow);
87
88 // ST_TextColumnCount
89 if (const sal_Int32 nColumns = rAttribs.getInteger(XML_numCol, 0); nColumns > 0)
90 {
91 css::uno::Reference<css::text::XTextColumns> xCols(SvxXTextColumns_createInstance(),
92 css::uno::UNO_QUERY_THROW);
93 xCols->setColumnCount(nColumns);
94 css::uno::Reference<css::beans::XPropertySet> xProps(xCols, css::uno::UNO_QUERY_THROW);
95 // ST_PositiveCoordinate32
96 const sal_Int32 nSpacing = o3tl::convert(rAttribs.getInteger(XML_spcCol, 0),
98 xProps->setPropertyValue("AutomaticDistance", css::uno::Any(nSpacing));
99 mrTextBodyProp.maPropertyMap.setAnyProperty(PROP_TextColumns, css::uno::Any(xCols));
100 }
101
102 // ST_Angle
103 if (rAttribs.getInteger(XML_rot).has_value())
104 mrTextBodyProp.moTextAreaRotation = rAttribs.getInteger(XML_rot).value();
105
106// bool bRtlCol = rAttribs.getBool( XML_rtlCol, false );
107 // ST_PositiveCoordinate
108// sal_Int32 nSpcCol = rAttribs.getInteger( XML_spcCol, 0 );
109// bool bSpcFirstLastPara = rAttribs.getBool( XML_spcFirstLastPara, 0 );
110
111 bool bUpright = rAttribs.getBool(XML_upright, false);
112 if (bUpright)
113 mrTextBodyProp.moUpright = true;
114
115 // ST_TextVerticalType
116 if( rAttribs.hasAttribute( XML_vert ) ) {
117 mrTextBodyProp.moVert = rAttribs.getToken( XML_vert );
118 sal_Int32 tVert = mrTextBodyProp.moVert.value_or( XML_horz );
119 if (tVert == XML_eaVert)
120 {
121 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextWritingMode, WritingMode_TB_RL);
122 mrTextBodyProp.maPropertyMap.setProperty(PROP_WritingMode, text::WritingMode2::TB_RL);
123 }
124 else if (tVert == XML_vert)
125 {
126 mrTextBodyProp.maPropertyMap.setProperty(PROP_WritingMode, text::WritingMode2::TB_RL90);
127 }
128 else if (tVert == XML_mongolianVert)
129 {
130 // rendering not yet implemented for shape text, only for frames
131 mrTextBodyProp.maPropertyMap.setProperty(PROP_WritingMode, text::WritingMode2::TB_LR);
132 }
133 else if (tVert == XML_vert270)
134 {
135 mrTextBodyProp.maPropertyMap.setProperty(PROP_WritingMode, text::WritingMode2::BT_LR);
136 }
137 else {
138 bool bRtl = rAttribs.getBool( XML_rtl, false );
139 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextWritingMode,
140 ( bRtl ? WritingMode_RL_TB : WritingMode_LR_TB ));
141 mrTextBodyProp.maPropertyMap.setProperty(PROP_WritingMode,
142 ( bRtl ? text::WritingMode2::RL_TB : text::WritingMode2::LR_TB));
143 }
144 }
145
146 // ST_TextAnchoringType
147 mrTextBodyProp.mbAnchorCtr = rAttribs.getBool(XML_anchorCtr, false );
148 if (rAttribs.hasAttribute(XML_anchor))
149 mrTextBodyProp.meVA = GetTextVerticalAdjust( rAttribs.getToken(XML_anchor, XML_t));
150 // else meVA is initialized to TextVerticalAdjust_TOP
151
152 sal_Int32 tVert = mrTextBodyProp.moVert.value_or(XML_horz);
153 if (tVert == XML_eaVert || tVert == XML_mongolianVert)
154 {
155 if (mrTextBodyProp.mbAnchorCtr)
156 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextVerticalAdjust,
157 TextVerticalAdjust_CENTER);
158 else
159 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextVerticalAdjust,
160 TextVerticalAdjust_TOP);
161
162 if (mrTextBodyProp.meVA == TextVerticalAdjust_CENTER)
163 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextHorizontalAdjust,
164 TextHorizontalAdjust_CENTER);
165 else if (mrTextBodyProp.meVA == TextVerticalAdjust_TOP)
166 {
167 mrTextBodyProp.maPropertyMap.setProperty(
168 PROP_TextHorizontalAdjust,
169 tVert == XML_eaVert ? TextHorizontalAdjust_RIGHT : TextHorizontalAdjust_LEFT);
170 }
171 else // meVA == TextVerticalAdjust_BOTTOM
172 {
173 mrTextBodyProp.maPropertyMap.setProperty(
174 PROP_TextHorizontalAdjust,
175 tVert == XML_eaVert ? TextHorizontalAdjust_LEFT : TextHorizontalAdjust_RIGHT);
176 }
177 }
178 else
179 {
180 if (mrTextBodyProp.mbAnchorCtr)
181 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextHorizontalAdjust,
182 TextHorizontalAdjust_CENTER);
183 else // BLOCK is nearer to rendering in MS Office than LEFT, see tdf#137023
184 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextHorizontalAdjust,
185 TextHorizontalAdjust_BLOCK);
186 mrTextBodyProp.maPropertyMap.setProperty(PROP_TextVerticalAdjust, mrTextBodyProp.meVA);
187 }
188
189 // Push defaults
190 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, false);
191 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextFitToSize, drawing::TextFitToSizeType_NONE);
192}
193
194ContextHandlerRef TextBodyPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
195{
196 switch( aElementToken )
197 {
198 // Sequence
199 case A_TOKEN( prstTxWarp ): // CT_PresetTextShape
200 if( mpShapePtr )
201 {
202 const std::optional<OUString> sPrst = rAttribs.getString( XML_prst );
203 if( sPrst.has_value() )
204 {
205 mrTextBodyProp.msPrst = sPrst.value();
206 if( mrTextBodyProp.msPrst != "textNoShape" )
207 return new PresetTextShapeContext( *this, rAttribs,
208 *( mpShapePtr->getCustomShapeProperties() ) );
209 }
210 }
211 break;
212
213 case A_TOKEN( prot ): // CT_TextProtectionProperty
214 break;
215
216 // EG_TextAutofit
217 case A_TOKEN( noAutofit ):
218 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, false); // CT_TextNoAutofit
219 break;
220 case A_TOKEN( normAutofit ): // CT_TextNormalAutofit
221 {
222 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextFitToSize, TextFitToSizeType_AUTOFIT);
223 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, false);
224 mrTextBodyProp.mnFontScale = rAttribs.getInteger(XML_fontScale, 100000);
225 break;
226 }
227 case A_TOKEN( spAutoFit ):
228 {
229 const sal_Int32 tVert = mrTextBodyProp.moVert.value_or( XML_horz );
230 if( tVert != XML_vert && tVert != XML_eaVert && tVert != XML_vert270 && tVert != XML_mongolianVert )
231 mrTextBodyProp.maPropertyMap.setProperty( PROP_TextAutoGrowHeight, true);
232 }
233 break;
234
235 case A_TOKEN( scene3d ): // CT_Scene3D
236 {
237 if(mpShapePtr && mpShapePtr->getServiceName() == "com.sun.star.drawing.CustomShape")
238 return new SceneText3DPropertiesContext( *this, mpShapePtr->getTextBody()->get3DProperties() );
239
240 break;
241 }
242
243 // EG_Text3D
244 case A_TOKEN( sp3d ): // CT_Shape3D
245 {
246 if (mpShapePtr && mpShapePtr->getServiceName() == "com.sun.star.drawing.CustomShape")
247 {
248 if (rAttribs.hasAttribute(XML_extrusionH))
249 mpShapePtr->getTextBody()->get3DProperties().mnExtrusionH = rAttribs.getInteger(XML_extrusionH, 0);
250 if (rAttribs.hasAttribute(XML_contourW))
251 mpShapePtr->getTextBody()->get3DProperties().mnContourW = rAttribs.getInteger(XML_contourW, 0);
252 if (rAttribs.hasAttribute(XML_z))
253 mpShapePtr->getTextBody()->get3DProperties().mnShapeZ = rAttribs.getInteger(XML_z, 0);
254 if (rAttribs.hasAttribute(XML_prstMaterial))
255 mpShapePtr->getTextBody()->get3DProperties().mnMaterial = rAttribs.getToken(XML_prstMaterial, XML_none);
256 return new SceneText3DPropertiesContext(*this, mpShapePtr->getTextBody()->get3DProperties());
257 }
258 break;
259 }
260
261 case A_TOKEN( flatTx ): // CT_FlatText
262
263 break;
264 }
265
266 return nullptr;
267}
268
269}
270
271/* 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