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 
22 #include <oox/drawingml/shape.hxx>
24 #include <drawingml/textbody.hxx>
25 #include <oox/token/namespaces.hxx>
26 
27 using namespace ::com::sun::star;
29 
30 namespace oox::drawingml {
31 
33 Transform2DContext::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 ).get();
47  }
48 }
49 
50 ContextHandlerRef 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.getString( XML_x ).get();
63  const OUString sYValue = rAttribs.getString( XML_y ).get();
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.getString( XML_cx ).get();
74  const OUString sYValue = rAttribs.getString( XML_cy ).get();
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.getString( XML_x ).get().toInt32(), rAttribs.getString( XML_y ).get().toInt32() ) );
100  break;
101  case A_TOKEN( ext ): // horz/vert size
102  mrShape.setSize( awt::Size( rAttribs.getString( XML_cx ).get().toInt32(), rAttribs.getString( XML_cy ).get().toInt32() ) );
103  break;
104  case A_TOKEN( chOff ): // horz/vert translation of children
105  mrShape.setChildPosition( awt::Point( rAttribs.getString( XML_x ).get().toInt32(), rAttribs.getString( XML_y ).get().toInt32() ) );
106  break;
107  case A_TOKEN( chExt ): // horz/vert size of children
108  {
109  sal_Int32 nChExtCx = rAttribs.getString(XML_cx).get().toInt32();
110 
111  if(nChExtCx == 0)
112  nChExtCx = mrShape.getSize().Width;
113 
114  sal_Int32 nChExtCy = rAttribs.getString(XML_cy).get().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: */
void setPosition(css::awt::Point nPosition)
Definition: shape.hxx:138
Transform2DContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttributes, Shape &rShape, bool btxXfrm=false) noexcept
context to import a CT_Transform2D
const css::awt::Point & getPosition() const
Definition: shape.hxx:139
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
const Type & get() const
Definition: helper.hxx:185
void setSize(css::awt::Size aSize)
Definition: shape.hxx:141
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
Provides access to attribute values of an element.
void setChildPosition(css::awt::Point nPosition)
Definition: shape.hxx:135
void setChildSize(css::awt::Size aSize)
Definition: shape.hxx:136
CustomShapePropertiesPtr & getCustomShapeProperties()
Definition: shape.hxx:126
const TextBodyPtr & getTextBody() const
Definition: shape.hxx:175
sal_Int32 GetCoordinate(sal_Int32 nValue)
converts EMUs into 1/100th mmm
::rtl::Reference< ContextHandler > ContextHandlerRef
const css::awt::Size & getSize() const
Definition: shape.hxx:142
QPRO_FUNC_TYPE nType
Helper class that provides a context stack.