Coverage Report

Created: 2026-06-13 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwps/src/lib/WPSGraphicShape.h
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
3
/* libwps
4
 * Version: MPL 2.0 / LGPLv2.1+
5
 *
6
 * This Source Code Form is subject to the terms of the Mozilla Public
7
 * License, v. 2.0. If a copy of the MPL was not distributed with this
8
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
 *
10
 * Major Contributor(s):
11
 * Copyright (C) 2002, 2005 William Lachance (william.lachance@sympatico.ca)
12
 * Copyright (C) 2002, 2004 Marc Maurer (uwog@uwog.net)
13
 *
14
 * For minor contributions see the git repository.
15
 *
16
 * Alternatively, the contents of this file may be used under the terms
17
 * of the GNU Lesser General Public License Version 2.1 or later
18
 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
19
 * applicable instead of those above.
20
 *
21
 * For further information visit http://libwps.sourceforge.net
22
*/
23
#ifndef WPS_GRAPHIC_SHAPE
24
#  define WPS_GRAPHIC_SHAPE
25
#  include <ostream>
26
#  include <string>
27
#  include <vector>
28
29
#  include "librevenge/librevenge.h"
30
31
#  include "libwps_internal.h"
32
33
/** a structure used to define a picture shape */
34
class WPSGraphicShape
35
{
36
public:
37
  //! an enum used to define the shape type
38
  enum Type { Arc, Circle, Line, Rectangle, Path, Pie, Polygon, Polyline, ShapeUnknown };
39
  //! an enum used to define the interface command
40
  enum Command { C_Ellipse, C_Polyline, C_Rectangle, C_Path, C_Polygon, C_Bad };
41
  //! a simple path component
42
  struct PathData
43
  {
44
    //! constructor
45
    explicit PathData(char type, Vec2f const &x=Vec2f(), Vec2f const &x1=Vec2f(), Vec2f const &x2=Vec2f())
46
207k
      : m_type(type)
47
207k
      , m_x(x)
48
207k
      , m_x1(x1)
49
207k
      , m_x2(x2)
50
207k
      , m_r()
51
207k
      , m_rotate(0)
52
207k
      , m_largeAngle(false)
53
207k
      , m_sweep(false)
54
207k
    {
55
207k
    }
56
    //! translate all the coordinate by delta
57
    void translate(Vec2f const &delta);
58
    //! scale all the coordinate by a factor
59
    void scale(Vec2f const &factor);
60
    //! rotate all the coordinate by angle (origin rotation) then translate coordinate
61
    void rotate(float angle, Vec2f const &delta);
62
    //! multiply all the coordinate by a matrix
63
    void transform(WPSTransformation const &matrix, float rotation);
64
    //! update the property list to correspond to a command
65
    bool get(librevenge::RVNGPropertyList &pList, Vec2f const &orig) const;
66
    //! a print operator
67
    friend std::ostream &operator<<(std::ostream &o, PathData const &path);
68
    //! comparison function
69
    int cmp(PathData const &a) const;
70
    //! the type: M, L, ...
71
    char m_type;
72
    //! the main x value
73
    Vec2f m_x;
74
    //! x1 value
75
    Vec2f m_x1;
76
    //! x2 value
77
    Vec2f m_x2;
78
    //! the radius ( A command)
79
    Vec2f m_r;
80
    //! the rotate ( A command)
81
    float m_rotate;
82
    //! large angle ( A command)
83
    bool m_largeAngle;
84
    //! sweep value ( A command)
85
    bool m_sweep;
86
  };
87
88
  //! constructor
89
  WPSGraphicShape()
90
576k
    : m_type(ShapeUnknown)
91
576k
    , m_bdBox()
92
576k
    , m_formBox()
93
576k
    , m_cornerWidth(0,0)
94
576k
    , m_arcAngles(0,0)
95
576k
    , m_vertices()
96
576k
    , m_path()
97
576k
    , m_extra("")
98
576k
  {
99
576k
  }
100
185k
  WPSGraphicShape(WPSGraphicShape const &)=default;
101
50.1k
  WPSGraphicShape(WPSGraphicShape &&)=default;
102
  WPSGraphicShape &operator=(WPSGraphicShape const &)=default;
103
210k
  WPSGraphicShape &operator=(WPSGraphicShape &&)=default;
104
  //! destructor
105
812k
  ~WPSGraphicShape() { }
106
  //! static constructor to create a line
107
  static WPSGraphicShape line(Vec2f const &orign, Vec2f const &dest);
108
  //! static constructor to create a rectangle
109
  static WPSGraphicShape rectangle(WPSBox2f const &box, Vec2f const &corners=Vec2f(0,0))
110
42.7k
  {
111
42.7k
    WPSGraphicShape res;
112
42.7k
    res.m_type=Rectangle;
113
42.7k
    res.m_bdBox=res.m_formBox=box;
114
42.7k
    res.m_cornerWidth=corners;
115
42.7k
    return res;
116
42.7k
  }
117
  //! static constructor to create a circle
118
  static WPSGraphicShape circle(WPSBox2f const &box)
119
35.2k
  {
120
35.2k
    WPSGraphicShape res;
121
35.2k
    res.m_type=Circle;
122
35.2k
    res.m_bdBox=res.m_formBox=box;
123
35.2k
    return res;
124
35.2k
  }
125
  //! static constructor to create a arc
126
  static WPSGraphicShape arc(WPSBox2f const &box, WPSBox2f const &circleWPSBox, Vec2f const &angles)
127
2.66k
  {
128
2.66k
    WPSGraphicShape res;
129
2.66k
    res.m_type=Arc;
130
2.66k
    res.m_bdBox=box;
131
2.66k
    res.m_formBox=circleWPSBox;
132
2.66k
    res.m_arcAngles=angles;
133
2.66k
    return res;
134
2.66k
  }
135
  //! static constructor to create a pie
136
  static WPSGraphicShape pie(WPSBox2f const &box, WPSBox2f const &circleWPSBox, Vec2f const &angles)
137
0
  {
138
0
    WPSGraphicShape res;
139
0
    res.m_type=Pie;
140
0
    res.m_bdBox=box;
141
0
    res.m_formBox=circleWPSBox;
142
0
    res.m_arcAngles=angles;
143
0
    return res;
144
0
  }
145
  //! static constructor to create a polygon
146
  static WPSGraphicShape polygon(WPSBox2f const &box)
147
2.00k
  {
148
2.00k
    WPSGraphicShape res;
149
2.00k
    res.m_type=Polygon;
150
2.00k
    res.m_bdBox=box;
151
2.00k
    return res;
152
2.00k
  }
153
  //! static constructor to create a polyline
154
  static WPSGraphicShape polyline(WPSBox2f const &box)
155
7.40k
  {
156
7.40k
    WPSGraphicShape res;
157
7.40k
    res.m_type=Polyline;
158
7.40k
    res.m_bdBox=box;
159
7.40k
    return res;
160
7.40k
  }
161
  //! static constructor to create a path
162
  static WPSGraphicShape path(WPSBox2f const &box)
163
35.6k
  {
164
35.6k
    WPSGraphicShape res;
165
35.6k
    res.m_type=Path;
166
35.6k
    res.m_bdBox=box;
167
35.6k
    return res;
168
35.6k
  }
169
170
  //! translate all the coordinate by delta
171
  void translate(Vec2f const &delta);
172
  //! rescale all the coordinate
173
  void scale(Vec2f const &factor);
174
  /** return a new shape corresponding to a rotation from center.
175
176
   \note the final bdbox is not tight */
177
  WPSGraphicShape rotate(float angle, Vec2f const &center) const;
178
  //! returns a new shape corresponding to a matrix transformation
179
  WPSGraphicShape transform(WPSTransformation const &matrix) const;
180
  //! returns the type corresponding to a shape
181
  Type getType() const
182
89.0k
  {
183
89.0k
    return m_type;
184
89.0k
  }
185
  //! returns the basic bdbox
186
  WPSBox2f getBdBox() const
187
96.2k
  {
188
96.2k
    return m_bdBox;
189
96.2k
  }
190
  //! updates the propList to send to an interface
191
  Command addTo(Vec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const;
192
  //! a print operator
193
  friend std::ostream &operator<<(std::ostream &o, WPSGraphicShape const &sh);
194
  /** compare two shapes */
195
  int cmp(WPSGraphicShape const &a) const;
196
protected:
197
  //! return a path corresponding to the shape
198
  std::vector<PathData> getPath(bool forTransformation) const;
199
public:
200
  //! the type
201
  Type m_type;
202
  //! the shape bdbox
203
  WPSBox2f m_bdBox;
204
  //! the internal shape bdbox ( used for arc, circle to store the circle bdbox )
205
  WPSBox2f m_formBox;
206
  //! the rectangle round corner
207
  Vec2f m_cornerWidth;
208
  //! the start and end value which defines an arc
209
  Vec2f m_arcAngles;
210
  //! the list of vertices for lines or polygons
211
  std::vector<Vec2f> m_vertices;
212
  //! the list of path component
213
  std::vector<PathData> m_path;
214
  //! extra data
215
  std::string m_extra;
216
};
217
#endif
218
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */