summaryrefslogtreecommitdiff
path: root/src/lib/VSDTypes.h
blob: 83be800be7f4b0509239fdbd60e24f813a1b144b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 * This file is part of the libvisio project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef VSDTYPES_H
#define VSDTYPES_H

#include <vector>
#include <map>
#include <librevenge/librevenge.h>

#define ASSIGN_OPTIONAL(t, u) if(!!t) u = t.get()
#define MINUS_ONE (unsigned)-1

namespace libvisio
{
struct XForm
{
  double pinX;
  double pinY;
  double height;
  double width;
  double pinLocX;
  double pinLocY;
  double angle;
  bool flipX;
  bool flipY;
  double x;
  double y;
  XForm() : pinX(0.0), pinY(0.0), height(0.0), width(0.0),
    pinLocX(0.0), pinLocY(0.0), angle(0.0),
    flipX(false), flipY(false), x(0.0), y(0.0) {}
  XForm(const XForm &xform) : pinX(xform.pinX), pinY(xform.pinY), height(xform.height),
    width(xform.width), pinLocX(xform.pinLocX), pinLocY(xform.pinLocY), angle(xform.angle),
    flipX(xform.flipX), flipY(xform.flipY), x(xform.x), y(xform.y) {}
  XForm &operator=(const XForm &xform);
};

struct XForm1D
{
  double beginX;
  double beginY;
  unsigned beginId;
  double endX;
  double endY;
  unsigned endId;
  XForm1D() : beginX(0.0), beginY(0.0), beginId(MINUS_ONE),
    endX(0.0), endY(0.0), endId(MINUS_ONE) {}
  XForm1D(const XForm1D &xform1d) : beginX(xform1d.beginX),
    beginY(xform1d.beginY), beginId(xform1d.beginId),
    endX(xform1d.endX), endY(xform1d.endY), endId(xform1d.endId) {}
};

// Utilities
struct ChunkHeader
{
  ChunkHeader() : chunkType(0), id(0), list(0), dataLength(0), level(0), unknown(0), trailer(0) {}
  unsigned chunkType;  // 4 bytes
  unsigned id;         // 4 bytes
  unsigned list;       // 4 bytes
  unsigned dataLength; // 4 bytes
  unsigned short level;      // 2 bytes
  unsigned char unknown;    // 1 byte
  unsigned trailer; // Derived
};

struct Colour
{
  Colour(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
    : r(red), g(green), b(blue), a(alpha) {}
  Colour() : r(0), g(0), b(0), a(0) {}
  inline bool operator==(const Colour &col) const
  {
    return ((r == col.r) && (g == col.g) && (b == col.b) && (a == col.a));
  }
  inline bool operator!=(const Colour &col) const
  {
    return !operator==(col);
  }
  inline bool operator!() const
  {
    return (!r && !g && !b && !a);
  }
  unsigned char r;
  unsigned char g;
  unsigned char b;
  unsigned char a;
};

struct NURBSData
{
  double lastKnot;
  unsigned degree;
  unsigned char xType;
  unsigned char yType;
  std::vector<double> knots;
  std::vector<double> weights;
  std::vector<std::pair<double, double> > points;
  NURBSData()
    : lastKnot(0.0),
      degree(0),
      xType(0x00),
      yType(0x00),
      knots(),
      weights(),
      points() {}
  NURBSData(const NURBSData &data)
    : lastKnot(data.lastKnot),
      degree(data.degree),
      xType(data.xType),
      yType(data.yType),
      knots(data.knots),
      weights(data.weights),
      points(data.points) {}
  NURBSData &operator=(const NURBSData &data);
};

struct PolylineData
{
  unsigned char xType;
  unsigned char yType;
  std::vector<std::pair<double, double> > points;
  PolylineData()
    : xType(0x00),
      yType(0x00),
      points() {}
};


struct ForeignData
{
  unsigned typeId;
  unsigned dataId;
  unsigned type;
  unsigned format;
  double offsetX;
  double offsetY;
  double width;
  double height;
  librevenge::RVNGBinaryData data;
  ForeignData()
    : typeId(0),
      dataId(0),
      type(0),
      format(0),
      offsetX(0.0),
      offsetY(0.0),
      width(0.0),
      height(0.0),
      data() {}
};

enum TextFormat
{
  VSD_TEXT_ANSI = 0,
  VSD_TEXT_SYMBOL,
  VSD_TEXT_GREEK,
  VSD_TEXT_TURKISH,
  VSD_TEXT_VIETNAMESE,
  VSD_TEXT_HEBREW,
  VSD_TEXT_ARABIC,
  VSD_TEXT_BALTIC,
  VSD_TEXT_RUSSIAN,
  VSD_TEXT_THAI,
  VSD_TEXT_CENTRAL_EUROPE,
  VSD_TEXT_JAPANESE,
  VSD_TEXT_KOREAN,
  VSD_TEXT_CHINESE_SIMPLIFIED,
  VSD_TEXT_CHINESE_TRADITIONAL,
  VSD_TEXT_UTF8,
  VSD_TEXT_UTF16
};

class VSDName
{
public:
  VSDName(const librevenge::RVNGBinaryData &data, TextFormat format)
    : m_data(data),
      m_format(format) {}
  VSDName() : m_data(), m_format(VSD_TEXT_ANSI) {}
  VSDName(const VSDName &name) : m_data(name.m_data), m_format(name.m_format) {}
  VSDName &operator=(const VSDName &name);
  bool empty() const
  {
    return !m_data.size();
  }
  void clear()
  {
    m_data.clear();
    m_format = VSD_TEXT_ANSI;
  }
  librevenge::RVNGBinaryData m_data;
  TextFormat m_format;
};

struct VSDFont
{
  librevenge::RVNGString m_name;
  TextFormat m_encoding;
  VSDFont() : m_name("Arial"), m_encoding(libvisio::VSD_TEXT_ANSI) {}
  VSDFont(const librevenge::RVNGString &name, const TextFormat &encoding) :
    m_name(name), m_encoding(encoding) {}
  VSDFont(const VSDFont &font) :
    m_name(font.m_name), m_encoding(font.m_encoding) {}
};

struct VSDMisc
{
  bool m_hideText;
  VSDMisc() : m_hideText(false) {}
  VSDMisc(const VSDMisc &misc) : m_hideText(misc.m_hideText) {}
  VSDMisc &operator=(const VSDMisc &misc);
};

struct VSDTabStop
{
  double m_position;
  unsigned char m_alignment;
  unsigned char m_leader;
  VSDTabStop() : m_position(0.0), m_alignment(0), m_leader(0) {}
  VSDTabStop(const VSDTabStop &tabStop) :
    m_position(tabStop.m_position), m_alignment(tabStop.m_alignment),
    m_leader(tabStop.m_leader) {}
};

struct VSDTabSet
{
  unsigned m_numChars;
  std::map<unsigned, VSDTabStop> m_tabStops;
  VSDTabSet() : m_numChars(0), m_tabStops() {}
  VSDTabSet(const VSDTabSet &tabSet) :
    m_numChars(tabSet.m_numChars), m_tabStops(tabSet.m_tabStops) {}
};

struct VSDBullet
{
  librevenge::RVNGString m_bulletStr;
  librevenge::RVNGString m_bulletFont;
  double m_bulletFontSize;
  double m_textPosAfterBullet;
  VSDBullet()
    : m_bulletStr(),
      m_bulletFont(),
      m_bulletFontSize(0.0),
      m_textPosAfterBullet(0.0) {}
  VSDBullet(const VSDBullet &bullet) :
    m_bulletStr(bullet.m_bulletStr),
    m_bulletFont(bullet.m_bulletFont),
    m_bulletFontSize(bullet.m_bulletFontSize),
    m_textPosAfterBullet(bullet.m_textPosAfterBullet) {}
  VSDBullet &operator=(const VSDBullet &bullet);
  inline bool operator==(const VSDBullet &bullet) const
  {
    return ((m_bulletStr == bullet.m_bulletStr) &&
            (m_bulletFont == bullet.m_bulletFont) &&
            (m_bulletFontSize == bullet.m_bulletFontSize) &&
            (m_textPosAfterBullet == bullet.m_textPosAfterBullet));
  }
  inline bool operator!=(const VSDBullet &bullet) const
  {
    return !operator==(bullet);
  }
  inline bool operator!() const
  {
    return m_bulletStr.empty();
  }
};

} // namespace libvisio

#endif /* VSDTYPES_H */
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */