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 
20 #include <drawingml/transform2dcontext.hxx>
21 #include <oox/helper/attributelist.hxx>
22 #include <oox/drawingml/shape.hxx>
23 #include <drawingml/customshapeproperties.hxx>
24 #include <drawingml/textbody.hxx>
25 #include <oox/token/namespaces.hxx>
26 
27 using namespace ::com::sun::star;
28 using ::oox::core::ContextHandlerRef;
29 
30 namespace oox {
31 namespace drawingml {
32 
33 /** context to import a CT_Transform2D */
Transform2DContext(ContextHandler2Helper const & rParent,const AttributeList & rAttribs,Shape & rShape,bool btxXfrm)34 Transform2DContext::Transform2DContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs, Shape& rShape, bool btxXfrm ) throw()
35 : ContextHandler2( rParent )
36 , mrShape( rShape )
37 , mbtxXfrm ( btxXfrm )
38 {
39     if( !btxXfrm )
40     {
41         mrShape.setRotation( rAttribs.getInteger( XML_rot, 0 ) ); // 60000ths of a degree Positive angles are clockwise; negative angles are counter-clockwise
42         mrShape.setFlip( rAttribs.getBool( XML_flipH, false ), rAttribs.getBool( XML_flipV, false ) );
43     }
44     else
45     {
46         if( rAttribs.hasAttribute( XML_rot ) )
47             mrShape.getTextBody()->getTextProperties().moRotation = rAttribs.getInteger( XML_rot ).get();
48     }
49 }
50 
onCreateContext(sal_Int32 aElementToken,const AttributeList & rAttribs)51 ContextHandlerRef Transform2DContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
52 {
53     if( mbtxXfrm )
54     {
55         // Workaround: only for rectangles
56         const sal_Int32 nType = mrShape.getCustomShapeProperties()->getShapePresetType();
57         if( nType == XML_rect || nType == XML_roundRect )
58         {
59             switch( aElementToken )
60             {
61                 case A_TOKEN( off ):
62                     {
63                         const OUString sXValue = rAttribs.getString( XML_x ).get();
64                         const OUString sYValue = rAttribs.getString( XML_y ).get();
65 
66                         if( !sXValue.isEmpty() )
67                             mrShape.getTextBody()->getTextProperties().moTextOffLeft = GetCoordinate( sXValue.toInt32() - mrShape.getPosition().X );
68                         if( !sYValue.isEmpty() )
69                             mrShape.getTextBody()->getTextProperties().moTextOffUpper = GetCoordinate( sYValue.toInt32() - mrShape.getPosition().Y );
70                     }
71                     break;
72                 case A_TOKEN( ext ):
73                     {
74                         const OUString sXValue = rAttribs.getString( XML_cx ).get();
75                         const OUString sYValue = rAttribs.getString( XML_cy ).get();
76 
77                         if( !sXValue.isEmpty() && nType == XML_rect )
78                         {
79                             mrShape.getTextBody()->getTextProperties().moTextOffRight = GetCoordinate(mrShape.getSize().Width - sXValue.toInt32());
80                             if( mrShape.getTextBody()->getTextProperties().moTextOffLeft )
81                                *mrShape.getTextBody()->getTextProperties().moTextOffRight -=  *mrShape.getTextBody()->getTextProperties().moTextOffLeft;
82                         }
83                         if( !sYValue.isEmpty() )
84                         {
85                             mrShape.getTextBody()->getTextProperties().moTextOffLower = GetCoordinate(mrShape.getSize().Height - sYValue.toInt32());
86                             if( mrShape.getTextBody()->getTextProperties().moTextOffUpper )
87                                *mrShape.getTextBody()->getTextProperties().moTextOffLower -=  *mrShape.getTextBody()->getTextProperties().moTextOffUpper;
88 
89                         }
90                     }
91                     break;
92             }
93         }
94         return nullptr;
95     }
96 
97     switch( aElementToken )
98     {
99     case A_TOKEN( off ):        // horz/vert translation
100         mrShape.setPosition( awt::Point( rAttribs.getString( XML_x ).get().toInt32(), rAttribs.getString( XML_y ).get().toInt32() ) );
101         break;
102     case A_TOKEN( ext ):        // horz/vert size
103         mrShape.setSize( awt::Size( rAttribs.getString( XML_cx ).get().toInt32(), rAttribs.getString( XML_cy ).get().toInt32() ) );
104         break;
105     case A_TOKEN( chOff ):  // horz/vert translation of children
106         mrShape.setChildPosition( awt::Point( rAttribs.getString( XML_x ).get().toInt32(), rAttribs.getString( XML_y ).get().toInt32() ) );
107         break;
108     case A_TOKEN( chExt ):  // horz/vert size of children
109         mrShape.setChildSize( awt::Size( rAttribs.getString( XML_cx ).get().toInt32(), rAttribs.getString( XML_cy ).get().toInt32() ) );
110         break;
111     }
112 
113     return nullptr;
114 }
115 
116 } // namespace drawingml
117 } // namespace oox
118 
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
120