VSDStyles.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* libvisio
3  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License or as specified alternatively below. You may obtain a copy of
8  * the License at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * Major Contributor(s):
16  * Copyright (C) 2011 Fridrich Strba <fridrich.strba@bluewin.ch>
17  * Copyright (C) 2011 Eilidh McAdam <tibbylickle@gmail.com>
18  *
19  *
20  * All Rights Reserved.
21  *
22  * For minor contributions see the git repository.
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
26  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
27  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
28  * instead of those above.
29  */
30 
31 #ifndef __VSDSTYLES_H__
32 #define __VSDSTYLES_H__
33 
34 #include <map>
35 #include <vector>
36 #include <boost/optional.hpp>
37 #include <libwpg/libwpg.h>
38 #include "VSDTypes.h"
39 
40 namespace libvisio
41 {
42 
44 {
46  width(), colour(), pattern(), startMarker(), endMarker(), cap() {}
47  VSDOptionalLineStyle(const boost::optional<double> &w, const boost::optional<Colour> &col,
48  const boost::optional<unsigned char> &p, const boost::optional<unsigned char> &sm,
49  const boost::optional<unsigned char> &em, const boost::optional<unsigned char> &c) :
50  width(w), colour(col), pattern(p), startMarker(sm), endMarker(em), cap(c) {}
52  width(style.width), colour(style.colour), pattern(style.pattern), startMarker(style.startMarker),
53  endMarker(style.endMarker), cap(style.cap) {}
55  void override(const VSDOptionalLineStyle &style)
56  {
57  ASSIGN_OPTIONAL(style.width, width);
58  ASSIGN_OPTIONAL(style.colour, colour);
59  ASSIGN_OPTIONAL(style.pattern, pattern);
60  ASSIGN_OPTIONAL(style.startMarker, startMarker);
61  ASSIGN_OPTIONAL(style.endMarker, endMarker);
62  ASSIGN_OPTIONAL(style.cap, cap);
63  }
64 
65  boost::optional<double> width;
66  boost::optional<Colour> colour;
67  boost::optional<unsigned char> pattern;
68  boost::optional<unsigned char> startMarker;
69  boost::optional<unsigned char> endMarker;
70  boost::optional<unsigned char> cap;
71 };
72 
74 {
76  width(0.01), colour(), pattern(1), startMarker(0), endMarker(0), cap(0) {}
77  VSDLineStyle(double w, Colour col, unsigned char p, unsigned char sm,
78  unsigned char em, unsigned char c) :
79  width(w), colour(col), pattern(p), startMarker(sm), endMarker(em), cap(c) {}
80  VSDLineStyle(const VSDLineStyle &style) :
81  width(style.width), colour(style.colour), pattern(style.pattern), startMarker(style.startMarker),
82  endMarker(style.endMarker), cap(style.cap) {}
84  void override(const VSDOptionalLineStyle &style)
85  {
86  ASSIGN_OPTIONAL(style.width, width);
87  ASSIGN_OPTIONAL(style.colour, colour);
88  ASSIGN_OPTIONAL(style.pattern, pattern);
89  ASSIGN_OPTIONAL(style.startMarker, startMarker);
90  ASSIGN_OPTIONAL(style.endMarker, endMarker);
91  ASSIGN_OPTIONAL(style.cap, cap);
92  }
93 
94  double width;
96  unsigned char pattern;
97  unsigned char startMarker;
98  unsigned char endMarker;
99  unsigned char cap;
100 };
101 
103 {
107  VSDOptionalFillStyle(const boost::optional<Colour> &fgc, const boost::optional<Colour> &bgc,
108  const boost::optional<unsigned char> &p, const boost::optional<double> &fga,
109  const boost::optional<double> &bga, const boost::optional<Colour> &sfgc,
110  const boost::optional<unsigned char> &shp, const boost::optional<double> &shX,
111  const boost::optional<double> &shY) :
112  fgColour(fgc), bgColour(bgc), pattern(p), fgTransparency(fga), bgTransparency(bga),
113  shadowFgColour(sfgc), shadowPattern(shp), shadowOffsetX(shX), shadowOffsetY(shY) {}
119  void override(const VSDOptionalFillStyle &style)
120  {
121  ASSIGN_OPTIONAL(style.fgColour, fgColour);
122  ASSIGN_OPTIONAL(style.bgColour, bgColour);
123  ASSIGN_OPTIONAL(style.pattern, pattern);
124  ASSIGN_OPTIONAL(style.fgTransparency, fgTransparency);
125  ASSIGN_OPTIONAL(style.bgTransparency, bgTransparency);
126  ASSIGN_OPTIONAL(style.shadowFgColour, shadowFgColour);
127  ASSIGN_OPTIONAL(style.shadowPattern, shadowPattern);
128  ASSIGN_OPTIONAL(style.shadowOffsetX, shadowOffsetX);
129  ASSIGN_OPTIONAL(style.shadowOffsetY, shadowOffsetY);
130  }
131 
132  boost::optional<Colour> fgColour;
133  boost::optional<Colour> bgColour;
134  boost::optional<unsigned char> pattern;
135  boost::optional<double> fgTransparency;
136  boost::optional<double> bgTransparency;
137  boost::optional<Colour> shadowFgColour;
138  boost::optional<unsigned char> shadowPattern;
139  boost::optional<double> shadowOffsetX;
140  boost::optional<double> shadowOffsetY;
141 };
142 
144 {
146  : fgColour(), bgColour(0xff, 0xff, 0xff, 0), pattern(0), fgTransparency(0), bgTransparency(0), shadowFgColour(),
148  VSDFillStyle(const Colour &fgc, const Colour &bgc, unsigned char p, double fga, double bga, const Colour &sfgc,
149  unsigned char shp, double shX, double shY)
150  : fgColour(fgc), bgColour(bgc), pattern(p), fgTransparency(fga), bgTransparency(bga),
151  shadowFgColour(sfgc), shadowPattern(shp), shadowOffsetX(shX), shadowOffsetY(shY) {}
152  VSDFillStyle(const VSDFillStyle &style) :
157  void override(const VSDOptionalFillStyle &style)
158  {
159  ASSIGN_OPTIONAL(style.fgColour, fgColour);
160  ASSIGN_OPTIONAL(style.bgColour, bgColour);
161  ASSIGN_OPTIONAL(style.pattern, pattern);
162  ASSIGN_OPTIONAL(style.fgTransparency, fgTransparency);
163  ASSIGN_OPTIONAL(style.bgTransparency, bgTransparency);
164  ASSIGN_OPTIONAL(style.shadowFgColour, shadowFgColour);
165  ASSIGN_OPTIONAL(style.shadowPattern, shadowPattern);
166  ASSIGN_OPTIONAL(style.shadowOffsetX, shadowOffsetX);
167  ASSIGN_OPTIONAL(style.shadowOffsetY, shadowOffsetY);
168  }
169 
172  unsigned char pattern;
176  unsigned char shadowPattern;
179 };
180 
182 {
184  : charCount(0), font(), colour(), size(), bold(), italic(), underline(), doubleunderline(), strikeout(),
186  VSDOptionalCharStyle(unsigned cc, const boost::optional<VSDName> &ft,
187  const boost::optional<Colour> &c, const boost::optional<double> &s, const boost::optional<bool> &b,
188  const boost::optional<bool> &i, const boost::optional<bool> &u, const boost::optional<bool> &du,
189  const boost::optional<bool> &so, const boost::optional<bool> &dso, const boost::optional<bool> &ac,
190  const boost::optional<bool> &ic, const boost::optional<bool> &sc, const boost::optional<bool> &super,
191  const boost::optional<bool> &sub) :
192  charCount(cc), font(ft), colour(c), size(s), bold(b), italic(i), underline(u), doubleunderline(du),
193  strikeout(so), doublestrikeout(dso), allcaps(ac), initcaps(ic), smallcaps(sc), superscript(super),
194  subscript(sub) {}
196  charCount(style.charCount), font(style.font), colour(style.colour), size(style.size), bold(style.bold),
199  superscript(style.superscript), subscript(style.subscript) {}
201  void override(const VSDOptionalCharStyle &style)
202  {
203  ASSIGN_OPTIONAL(style.font, font);
204  ASSIGN_OPTIONAL(style.colour, colour);
205  ASSIGN_OPTIONAL(style.size, size);
206  ASSIGN_OPTIONAL(style.bold, bold);
207  ASSIGN_OPTIONAL(style.italic, italic);
208  ASSIGN_OPTIONAL(style.underline, underline);
209  ASSIGN_OPTIONAL(style.doubleunderline, doubleunderline);
210  ASSIGN_OPTIONAL(style.strikeout, strikeout);
211  ASSIGN_OPTIONAL(style.doublestrikeout, doublestrikeout);
212  ASSIGN_OPTIONAL(style.allcaps, allcaps);
213  ASSIGN_OPTIONAL(style.initcaps, initcaps);
214  ASSIGN_OPTIONAL(style.smallcaps, smallcaps);
215  ASSIGN_OPTIONAL(style.superscript, superscript);
216  ASSIGN_OPTIONAL(style.subscript, subscript);
217  }
218 
219  unsigned charCount;
220  boost::optional<VSDName> font;
221  boost::optional<Colour> colour;
222  boost::optional<double> size;
223  boost::optional<bool> bold;
224  boost::optional<bool> italic;
225  boost::optional<bool> underline;
226  boost::optional<bool> doubleunderline;
227  boost::optional<bool> strikeout;
228  boost::optional<bool> doublestrikeout;
229  boost::optional<bool> allcaps;
230  boost::optional<bool> initcaps;
231  boost::optional<bool> smallcaps;
232  boost::optional<bool> superscript;
233  boost::optional<bool> subscript;
234 };
235 
237 {
239  : charCount(0), font(), colour(), size(12.0/72.0), bold(false), italic(false), underline(false),
240  doubleunderline(false), strikeout(false), doublestrikeout(false), allcaps(false), initcaps(false),
241  smallcaps(false), superscript(false), subscript(false) {}
242  VSDCharStyle(unsigned cc, const VSDName &ft, const Colour &c, double s, bool b, bool i, bool u, bool du,
243  bool so, bool dso, bool ac, bool ic, bool sc, bool super, bool sub) :
244  charCount(cc), font(ft), colour(c), size(s), bold(b), italic(i), underline(u), doubleunderline(du),
245  strikeout(so), doublestrikeout(dso), allcaps(ac), initcaps(ic), smallcaps(sc), superscript(super),
246  subscript(sub) {}
247  VSDCharStyle(const VSDCharStyle &style) :
248  charCount(style.charCount), font(style.font), colour(style.colour), size(style.size), bold(style.bold),
251  superscript(style.superscript), subscript(style.subscript) {}
253  void override(const VSDOptionalCharStyle &style)
254  {
255  ASSIGN_OPTIONAL(style.font, font);
256  ASSIGN_OPTIONAL(style.colour, colour);
257  ASSIGN_OPTIONAL(style.size, size);
258  ASSIGN_OPTIONAL(style.bold, bold);
259  ASSIGN_OPTIONAL(style.italic, italic);
260  ASSIGN_OPTIONAL(style.underline, underline);
261  ASSIGN_OPTIONAL(style.doubleunderline, doubleunderline);
262  ASSIGN_OPTIONAL(style.strikeout, strikeout);
263  ASSIGN_OPTIONAL(style.doublestrikeout, doublestrikeout);
264  ASSIGN_OPTIONAL(style.allcaps, allcaps);
265  ASSIGN_OPTIONAL(style.initcaps, initcaps);
266  ASSIGN_OPTIONAL(style.smallcaps, smallcaps);
267  ASSIGN_OPTIONAL(style.superscript, superscript);
268  ASSIGN_OPTIONAL(style.subscript, subscript);
269  }
270 
271  unsigned charCount;
274  double size;
275  bool bold;
276  bool italic;
277  bool underline;
279  bool strikeout;
281  bool allcaps;
282  bool initcaps;
283  bool smallcaps;
285  bool subscript;
286 };
287 
289 {
291  charCount(0), indFirst(), indLeft(), indRight(), spLine(), spBefore(), spAfter(), align(), flags() {}
292  VSDOptionalParaStyle(unsigned cc, const boost::optional<double> &ifst, const boost::optional<double> &il,
293  const boost::optional<double> &ir, const boost::optional<double> &sl, const boost::optional<double> &sb,
294  const boost::optional<double> &sa, const boost::optional<unsigned char> &a, const boost::optional<unsigned> &f) :
295  charCount(cc), indFirst(ifst), indLeft(il), indRight(ir), spLine(sl), spBefore(sb), spAfter(sa), align(a), flags(f) {}
297  charCount(style.charCount), indFirst(style.indFirst), indLeft(style.indLeft), indRight(style.indRight), spLine(style.spLine),
298  spBefore(style.spBefore), spAfter(style.spAfter), align(style.align), flags(style.flags) {}
300  void override(const VSDOptionalParaStyle &style)
301  {
302  ASSIGN_OPTIONAL(style.indFirst, indFirst);
303  ASSIGN_OPTIONAL(style.indLeft, indLeft);
304  ASSIGN_OPTIONAL(style.indRight,indRight);
305  ASSIGN_OPTIONAL(style.spLine, spLine);
306  ASSIGN_OPTIONAL(style.spBefore, spBefore);
307  ASSIGN_OPTIONAL(style.spAfter, spAfter);
308  ASSIGN_OPTIONAL(style.align, align);
309  ASSIGN_OPTIONAL(style.flags, flags);
310  }
311 
312  unsigned charCount;
313  boost::optional<double> indFirst;
314  boost::optional<double> indLeft;
315  boost::optional<double> indRight;
316  boost::optional<double> spLine;
317  boost::optional<double> spBefore;
318  boost::optional<double> spAfter;
319  boost::optional<unsigned char> align;
320  boost::optional<unsigned> flags;
321 };
322 
324 {
326  charCount(0), indFirst(0.0), indLeft(0.0), indRight(0.0), spLine(-1.2), spBefore(0.0), spAfter(0.0), align(1), flags(0) {}
327  VSDParaStyle(unsigned cc, double ifst, double il, double ir, double sl, double sb,
328  double sa, unsigned char a, unsigned f) :
329  charCount(cc), indFirst(ifst), indLeft(il), indRight(ir), spLine(sl), spBefore(sb), spAfter(sa), align(a), flags(f) {}
330  VSDParaStyle(const VSDParaStyle &style) :
331  charCount(style.charCount), indFirst(style.indFirst), indLeft(style.indLeft), indRight(style.indRight), spLine(style.spLine),
332  spBefore(style.spBefore), spAfter(style.spAfter), align(style.align), flags(style.flags) {}
334  void override(const VSDOptionalParaStyle &style)
335  {
336  ASSIGN_OPTIONAL(style.indFirst, indFirst);
337  ASSIGN_OPTIONAL(style.indLeft, indLeft);
338  ASSIGN_OPTIONAL(style.indRight,indRight);
339  ASSIGN_OPTIONAL(style.spLine, spLine);
340  ASSIGN_OPTIONAL(style.spBefore, spBefore);
341  ASSIGN_OPTIONAL(style.spAfter, spAfter);
342  ASSIGN_OPTIONAL(style.align, align);
343  ASSIGN_OPTIONAL(style.flags, flags);
344  }
345 
346  unsigned charCount;
347  double indFirst;
348  double indLeft;
349  double indRight;
350  double spLine;
351  double spBefore;
352  double spAfter;
353  unsigned char align;
354  unsigned flags;
355 };
356 
358 {
362  VSDOptionalTextBlockStyle(const boost::optional<double> &lm, const boost::optional<double> &rm,
363  const boost::optional<double> &tm, const boost::optional<double> &bm,
364  const boost::optional<unsigned char> &va, const boost::optional<bool> &isBgFilled,
365  const boost::optional<Colour> &bgClr, const boost::optional<double> &defTab,
366  const boost::optional<unsigned char> &td) :
368  isTextBkgndFilled(isBgFilled), textBkgndColour(bgClr), defaultTabStop(defTab), textDirection(td) {}
374  void override(const VSDOptionalTextBlockStyle &style)
375  {
376  ASSIGN_OPTIONAL(style.leftMargin, leftMargin);
377  ASSIGN_OPTIONAL(style.rightMargin, rightMargin);
378  ASSIGN_OPTIONAL(style.topMargin, topMargin);
379  ASSIGN_OPTIONAL(style.bottomMargin, bottomMargin);
380  ASSIGN_OPTIONAL(style.verticalAlign, verticalAlign);
381  ASSIGN_OPTIONAL(style.isTextBkgndFilled, isTextBkgndFilled);
382  ASSIGN_OPTIONAL(style.textBkgndColour, textBkgndColour);
383  ASSIGN_OPTIONAL(style.defaultTabStop, defaultTabStop);
384  ASSIGN_OPTIONAL(style.textDirection, textDirection);
385  }
386 
387  boost::optional<double> leftMargin;
388  boost::optional<double> rightMargin;
389  boost::optional<double> topMargin;
390  boost::optional<double> bottomMargin;
391  boost::optional<unsigned char> verticalAlign;
392  boost::optional<bool> isTextBkgndFilled;
393  boost::optional<Colour> textBkgndColour;
394  boost::optional<double> defaultTabStop;
395  boost::optional<unsigned char> textDirection;
396 };
397 
399 {
401  leftMargin(0.0), rightMargin(0.0), topMargin(0.0), bottomMargin(0.0), verticalAlign(1),
402  isTextBkgndFilled(true), textBkgndColour(0xff,0xff,0xff,0), defaultTabStop(0.5), textDirection(0) {}
403  VSDTextBlockStyle(double lm, double rm, double tm, double bm, unsigned char va,
404  bool isBgFilled, Colour bgClr, double defTab, unsigned char td) :
406  isTextBkgndFilled(isBgFilled), textBkgndColour(bgClr), defaultTabStop(defTab), textDirection(td) {}
412  void override(const VSDOptionalTextBlockStyle &style)
413  {
414  ASSIGN_OPTIONAL(style.leftMargin, leftMargin);
415  ASSIGN_OPTIONAL(style.rightMargin, rightMargin);
416  ASSIGN_OPTIONAL(style.topMargin, topMargin);
417  ASSIGN_OPTIONAL(style.bottomMargin, bottomMargin);
418  ASSIGN_OPTIONAL(style.verticalAlign, verticalAlign);
419  ASSIGN_OPTIONAL(style.isTextBkgndFilled, isTextBkgndFilled);
420  ASSIGN_OPTIONAL(style.textBkgndColour, textBkgndColour);
421  ASSIGN_OPTIONAL(style.defaultTabStop, defaultTabStop);
422  ASSIGN_OPTIONAL(style.textDirection, textDirection);
423  }
424 
425  double leftMargin;
426  double rightMargin;
427  double topMargin;
428  double bottomMargin;
429  unsigned char verticalAlign;
433  unsigned char textDirection;
434 };
435 
437 {
438 public:
439  VSDStyles();
440  VSDStyles(const VSDStyles &styles);
441  ~VSDStyles();
442  VSDStyles &operator=(const VSDStyles &styles);
443  void addLineStyle(unsigned lineStyleIndex, const VSDOptionalLineStyle &lineStyle);
444  void addFillStyle(unsigned fillStyleIndex, const VSDOptionalFillStyle &fillStyle);
445  void addTextBlockStyle(unsigned textStyleIndex, const VSDOptionalTextBlockStyle &textBlockStyle);
446  void addCharStyle(unsigned textStyleIndex, const VSDOptionalCharStyle &charStyle);
447  void addParaStyle(unsigned textStyleIndex, const VSDOptionalParaStyle &paraStyle);
448 
449  void addLineStyleMaster(unsigned lineStyleIndex, unsigned lineStyleMaster);
450  void addFillStyleMaster(unsigned fillStyleIndex, unsigned fillStyleMaster);
451  void addTextStyleMaster(unsigned textStyleIndex, unsigned textStyleMaster);
452 
453  VSDLineStyle getLineStyle(unsigned lineStyleIndex) const;
454  VSDOptionalLineStyle getOptionalLineStyle(unsigned lineStyleIndex) const;
455  VSDFillStyle getFillStyle(unsigned fillStyleIndex) const;
456  VSDOptionalFillStyle getOptionalFillStyle(unsigned fillStyleIndex) const;
457  VSDTextBlockStyle getTextBlockStyle(unsigned textStyleIndex) const;
458  VSDOptionalTextBlockStyle getOptionalTextBlockStyle(unsigned textStyleIndex) const;
459  VSDCharStyle getCharStyle(unsigned textStyleIndex) const;
460  VSDOptionalCharStyle getOptionalCharStyle(unsigned textStyleIndex) const;
461  VSDParaStyle getParaStyle(unsigned textStyleIndex) const;
462  VSDOptionalParaStyle getOptionalParaStyle(unsigned textStyleIndex) const;
463 
464 private:
465  std::map<unsigned, VSDOptionalLineStyle> m_lineStyles;
466  std::map<unsigned, VSDOptionalFillStyle> m_fillStyles;
467  std::map<unsigned, VSDOptionalTextBlockStyle> m_textBlockStyles;
468  std::map<unsigned, VSDOptionalCharStyle> m_charStyles;
469  std::map<unsigned, VSDOptionalParaStyle> m_paraStyles;
470  std::map<unsigned, unsigned> m_lineStyleMasters;
471  std::map<unsigned, unsigned> m_fillStyleMasters;
472  std::map<unsigned, unsigned> m_textStyleMasters;
473 };
474 
475 
476 } // namespace libvisio
477 
478 #endif // __VSDSTYLES_H__
479 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libvisio by doxygen 1.8.2