LibreOffice Module oox (master) 1
transform2dcontext.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
25#include <oox/token/namespaces.hxx>
26
27using namespace ::com::sun::star;
29
30namespace oox::drawingml {
31
33Transform2DContext::Transform2DContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs, Shape& rShape, bool btxXfrm ) noexcept
34: ContextHandler2( rParent )
35, mrShape( rShape )
36, mbtxXfrm ( btxXfrm )
37{
38 if( !btxXfrm )
39 {
40 mrShape.setRotation( rAttribs.getInteger( XML_rot, 0 ) ); // 60000ths of a degree Positive angles are clockwise; negative angles are counter-clockwise
41 mrShape.setFlip( rAttribs.getBool( XML_flipH, false ), rAttribs.getBool( XML_flipV, false ) );
42 }
43 else
44 {
45 if( rAttribs.hasAttribute( XML_rot ) )
46 mrShape.getTextBody()->getTextProperties().moRotation = rAttribs.getInteger( XML_rot, 0 );
47 }
48}
49
50ContextHandlerRef Transform2DContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
51{
52 if( mbtxXfrm )
53 {
54 // Workaround: only for rectangles
55 const sal_Int32 nType = mrShape.getCustomShapeProperties()->getShapePresetType();
56 if( nType == XML_rect || nType == XML_roundRect || nType == XML_ellipse )
57 {
58 switch( aElementToken )
59 {
60 case A_TOKEN( off ):
61 {
62 const OUString sXValue = rAttribs.getStringDefaulted( XML_x );
63 const OUString sYValue = rAttribs.getStringDefaulted( XML_y );
64
65 if( !sXValue.isEmpty() && nType != XML_ellipse )
66 mrShape.getTextBody()->getTextProperties().moTextOffLeft = GetCoordinate( sXValue.toInt32() - mrShape.getPosition().X );
67 if( !sYValue.isEmpty() )
68 mrShape.getTextBody()->getTextProperties().moTextOffUpper = GetCoordinate( sYValue.toInt32() - mrShape.getPosition().Y );
69 }
70 break;
71 case A_TOKEN( ext ):
72 {
73 const OUString sXValue = rAttribs.getStringDefaulted( XML_cx );
74 const OUString sYValue = rAttribs.getStringDefaulted( XML_cy );
75
76 if( !sXValue.isEmpty() && nType == XML_rect )
77 {
78 mrShape.getTextBody()->getTextProperties().moTextOffRight = GetCoordinate(mrShape.getSize().Width - sXValue.toInt32());
79 if( mrShape.getTextBody()->getTextProperties().moTextOffLeft )
80 *mrShape.getTextBody()->getTextProperties().moTextOffRight -= *mrShape.getTextBody()->getTextProperties().moTextOffLeft;
81 }
82 if( !sYValue.isEmpty() )
83 {
84 mrShape.getTextBody()->getTextProperties().moTextOffLower = GetCoordinate(mrShape.getSize().Height - sYValue.toInt32());
85 if( mrShape.getTextBody()->getTextProperties().moTextOffUpper )
86 *mrShape.getTextBody()->getTextProperties().moTextOffLower -= *mrShape.getTextBody()->getTextProperties().moTextOffUpper;
87
88 }
89 }
90 break;
91 }
92 }
93 return nullptr;
94 }
95
96 switch( aElementToken )
97 {
98 case A_TOKEN( off ): // horz/vert translation
99 mrShape.setPosition( awt::Point( rAttribs.getStringDefaulted( XML_x ).toInt32(), rAttribs.getStringDefaulted( XML_y ).toInt32() ) );
100 break;
101 case A_TOKEN( ext ): // horz/vert size
102 mrShape.setSize( awt::Size( rAttribs.getStringDefaulted( XML_cx ).toInt32(), rAttribs.getStringDefaulted( XML_cy ).toInt32() ) );
103 break;
104 case A_TOKEN( chOff ): // horz/vert translation of children
105 mrShape.setChildPosition( awt::Point( rAttribs.getStringDefaulted( XML_x ).toInt32(), rAttribs.getStringDefaulted( XML_y ).toInt32() ) );
106 break;
107 case A_TOKEN( chExt ): // horz/vert size of children
108 {
109 sal_Int32 nChExtCx = rAttribs.getStringDefaulted(XML_cx).toInt32();
110
111 if(nChExtCx == 0)
112 nChExtCx = mrShape.getSize().Width;
113
114 sal_Int32 nChExtCy = rAttribs.getStringDefaulted(XML_cy).toInt32();
115
116 if(nChExtCy == 0)
117 nChExtCy = mrShape.getSize().Height;
118
119 mrShape.setChildSize(awt::Size(nChExtCx, nChExtCy));
120 }
121 break;
122 }
123
124 return nullptr;
125}
126
127} // namespace oox::drawingml
128
129/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to attribute values of an element.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
Helper class that provides a context stack.
CustomShapePropertiesPtr & getCustomShapeProperties()
Definition: shape.hxx:137
void setSize(css::awt::Size aSize)
Definition: shape.hxx:159
const css::awt::Size & getSize() const
Definition: shape.hxx:160
const css::awt::Point & getPosition() const
Definition: shape.hxx:157
void setChildPosition(css::awt::Point nPosition)
Definition: shape.hxx:153
void setPosition(css::awt::Point nPosition)
Definition: shape.hxx:156
void setChildSize(css::awt::Size aSize)
Definition: shape.hxx:154
const TextBodyPtr & getTextBody() const
Definition: shape.hxx:193
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
Transform2DContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttributes, Shape &rShape, bool btxXfrm=false) noexcept
context to import a CT_Transform2D
::rtl::Reference< ContextHandler > ContextHandlerRef
sal_Int32 GetCoordinate(sal_Int32 nValue)
converts EMUs into 1/100th mmm
QPRO_FUNC_TYPE nType