File: fmt_opts.h

package info (click to toggle)
musescore 2.0.3%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 202,532 kB
  • ctags: 58,769
  • sloc: cpp: 257,595; xml: 172,226; ansic: 139,931; python: 6,565; sh: 6,383; perl: 423; makefile: 290; awk: 142; pascal: 67; sed: 3
file content (136 lines) | stat: -rw-r--r-- 3,636 bytes parent folder | download | duplicates (14)
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
#ifndef __FMT_OPTS_H__
#define __FMT_OPTS_H__

#include "config.h"
#include "common.h"
#include <stack>
#include <vector>
#include <deque>
#include <map>

struct color {
   int r, g, b;
   color() : r(-1), g(-1), b(-1) {}
   bool operator==(const color &clr)
   {
      return r==clr.r && g==clr.g && b==clr.b;
   }
   bool operator!=(const color &clr)
   {
      return !(*this==clr);
   }
   color &operator=(const color &clr)
   {
      r=clr.r; g=clr.g; b=clr.b;
      return *this;
   }
};

typedef std::vector<color> colorvect;

struct font {
   enum font_family {ff_none, ff_serif, ff_sans_serif, ff_cursive, 
                     ff_fantasy, ff_monospace};
   font_family family;
   std::string name;
   int pitch;
   int charset;
   font() : family(ff_none), name(), pitch(0), charset(0) {}
   bool operator==(const font &f)
   {
      return family==f.family && name==f.name;
   }
   bool operator!=(const font &f)
   {
      return !(*this==f);
   }
   font &operator=(const font &f)
   {
      family=f.family; name=f.name; pitch=f.pitch; charset=f.charset;
      return *this;
   }
};

typedef std::map<int, font> fontmap;

struct formatting_options
{
   enum halign {align_left, align_right, align_center, align_justify, align_error};
   enum valign {va_normal, va_sub, va_sup};
   bool chpBold, chpItalic, chpUnderline;
   valign chpVAlign;
   int chpFontSize, chpHighlight;
   color chpFColor, chpBColor;
   font chpFont;
   int papLeft, papRight, papFirst;
   int papBefore, papAfter;
   halign papAlign;
   bool papInTbl;
   formatting_options()
   {
      chpBold=chpItalic=chpUnderline=false;
      chpVAlign=va_normal;
      chpFontSize=chpHighlight=0;
      papLeft=papRight=papFirst=papBefore=papAfter=0;
      papAlign=align_left;
      papInTbl=false;
   }
   bool operator==(const formatting_options &opt) // tests only for character options
   {
      return chpBold==opt.chpBold && chpItalic==opt.chpItalic 
             && chpUnderline==opt.chpUnderline && chpVAlign==opt.chpVAlign
             && chpFontSize==opt.chpFontSize
             && chpFColor==opt.chpFColor && chpBColor==opt.chpBColor
             && chpHighlight==opt.chpHighlight && chpFont==opt.chpFont;
   }
   bool operator!=(const formatting_options &opt) // tests only for character options
   {
      return !(*this==opt);
   }
   formatting_options &operator=(const formatting_options &opt)
   {
      chpBold=opt.chpBold; chpItalic=opt.chpItalic;
      chpUnderline=opt.chpUnderline; chpVAlign=opt.chpVAlign;
      chpFontSize=opt.chpFontSize; 
      chpFColor=opt.chpFColor; chpBColor=opt.chpBColor;
      chpHighlight=opt.chpHighlight; chpFont=opt.chpFont;
      papLeft=opt.papLeft; papRight=opt.papRight;
      papFirst=opt.papFirst; papBefore=opt.papBefore; papAfter=opt.papAfter;
      papAlign=opt.papAlign; papInTbl=opt.papInTbl;
      return *this;
   }
   std::string get_par_str() const;
};

typedef std::stack<formatting_options> fo_stack;

typedef std::deque<formatting_options> fo_deque;

class formatter {
 private:
   fo_deque opt_stack;
 public:
   std::string format(const formatting_options &opt);
   std::string close();
   void clear() { opt_stack.clear(); }
};

class html_text {
 private:
   const formatting_options &opt;
   formatter fmt;
   std::string text;
 public:
   html_text(const formatting_options &_opt) : opt(_opt) {}
   const std::string &str() { return text; }
   template <class T> void write(T s)
   {
      text+=fmt.format(opt)+s;
   }
   std::string close() { return fmt.close(); }
//   void write(char c) { write(std::string()+c); }
   void clear() { text.clear(); fmt.clear(); }
};

#endif