g4tools  5.4.0
text_style
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_sg_text_style
5 #define tools_sg_text_style
6 
7 #include "../lina/vec3f"
8 
9 #include "sf_vec3f"
10 #include "sf_string"
11 #include "sf_enum"
12 #include "node"
13 #include "enums"
14 #include "style_parser"
15 
16 namespace tools {
17 namespace sg {
18 
19 class text_style : public node {
21 public:
26 
37  // For 3D text :
40  // For bitmap text :
42 
43  // for text_hershey :
48 
49  // for text_freetype tessellation :
51 
52  sf_string options; //for gopaw.
53 public:
54  virtual const desc_fields& node_desc_fields() const {
56  static const desc_fields s_v(parent::node_desc_fields(),21, //WARNING : take care of count.
59 
73 
78 
81  );
82  return s_v;
83  }
84 private:
85  void add_fields(){
87  add_field(&color);
88 
90  add_field(&font);
96  add_field(&hjust);
97  add_field(&vjust);
98  add_field(&scale);
101  add_field(&rotated);
102 
107 
109  add_field(&options);
110  }
111 public:
113  :parent()
114  ,visible(true)
115  ,color(colorf_black())
116  ,back_color(colorf_white())
117  ,back_shadow(0)
118  ,modeling()
119  ,font(font_hershey())
120  ,font_size(10)
123  ,smoothing(false)
124  ,hinting(false)
125  ,hjust(left)
126  ,vjust(bottom)
127  ,scale(1)
128  ,x_orientation(vec3f(1,0,0))
129  ,y_orientation(vec3f(0,1,0))
130  ,rotated(false)
131  ,line_width(1)
133  ,enforced(false)
134  ,translation(vec3f(0,0,0))
136  ,options("")
137  {
138  add_fields();
139  }
140  virtual ~text_style(){}
141 public:
142  text_style(const text_style& a_from)
143  :parent(a_from),visible(a_from.visible)
144  ,color(a_from.color)
145  ,back_color(a_from.back_color)
146  ,back_shadow(a_from.back_shadow)
147  ,modeling(a_from.modeling)
148  ,font(a_from.font)
149  ,font_size(a_from.font_size)
151  ,encoding(a_from.encoding)
152  ,smoothing(a_from.smoothing)
153  ,hinting(a_from.hinting)
154  ,hjust(a_from.hjust)
155  ,vjust(a_from.vjust)
156  ,scale(a_from.scale)
159  ,rotated(a_from.rotated)
160  ,line_width(a_from.line_width)
161  ,line_pattern(a_from.line_pattern)
162  ,enforced(a_from.enforced)
163  ,translation(a_from.translation)
164  ,front_face(a_from.front_face)
165  ,options(a_from.options)
166  {
167  add_fields();
168  }
169  text_style& operator=(const text_style& a_from){
170  parent::operator=(a_from);
171  visible = a_from.visible;
172  color = a_from.color;
173  back_color = a_from.back_color;
174  back_shadow = a_from.back_shadow;
175  modeling = a_from.modeling;
176  font = a_from.font;
177  font_size = a_from.font_size;
178  font_modeling = a_from.font_modeling;
179  encoding = a_from.encoding;
180  smoothing = a_from.smoothing;
181  hinting = a_from.hinting;
182  hjust = a_from.hjust;
183  vjust = a_from.vjust;
184  scale = a_from.scale;
185  x_orientation = a_from.x_orientation;
186  y_orientation = a_from.y_orientation;
187  rotated = a_from.rotated;
188  line_width = a_from.line_width;
189  line_pattern = a_from.line_pattern;
190  enforced = a_from.enforced;
191  translation = a_from.translation;
192  front_face = a_from.front_face;
193  options = a_from.options;
194  return *this;
195  }
196 public:
197  bool from_string(std::ostream& a_out,const cmaps_t& a_cmaps,const std::string& a_s){
198  style_parser sp;
199 
200  sp.visible(visible.value());
201  sp.color(color.value());
202  //sp.transparency(transparency.value());
203  sp.back_color(back_color.value());
204  //sp.back_transparency(back_transparency.value());
206  sp.modeling(modeling.value());
207  sp.font(font.value());
208  sp.font_size(font_size.value());
209  sp.font_modeling(font_modeling.value());
210  sp.encoding(encoding.value());
211  sp.smoothing(smoothing.value());
212  sp.hinting(hinting.value());
213  sp.scale(scale.value());
214  //sp.angle(angle.value());
215  //sp.x_orientation(x_orientation.value());
216  //sp.y_orientation(y_orientation.value());
217  //sp.rotated(rotated.value());
219  sp.line_pattern(line_pattern.value());
220  sp.enforced(enforced.value());
223  sp.options(options.value());
224 
225  if(!sp.parse(a_out,a_cmaps,a_s)) {
226  a_out << "tools::sg::text_style::from_string :"
227  << " parse failed."
228  << std::endl;
229  return false;
230  }
231 
232  visible.value(sp.visible());
233  color.value(sp.color());
234  //transparency.value(sp.transparency());
235  back_color.value(sp.back_color());
236  //back_transparency.value(sp.back_transparency());
238  modeling.value(sp.modeling());
239  font.value(sp.font());
240  font_size.value(sp.font_size());
241  font_modeling.value(sp.font_modeling());
242  encoding.value(sp.encoding());
243  smoothing.value(sp.smoothing());
244  hinting.value(sp.hinting());
245  scale.value(sp.scale());
246  //angle.value(sp.angle());
247  //x_orientation.value(sp.x_orientation());
248  //y_orientation.value(sp.y_orientation());
249  //rotated.value(sp.rotated());
251  line_pattern.value(sp.line_pattern());
252  enforced.value(sp.enforced());
254  front_face = sp.front_face();
255  options = sp.options();
256 
257  return true;
258  }
259 };
260 
261 }}
262 
263 #endif
tools::sg::text_style::font_size
sf< float > font_size
Definition: text_style:29
tools::sg::text_style::enforced
sf< bool > enforced
Definition: text_style:46
tools::sg::style_parser::back_shadow
float back_shadow() const
Definition: style_parser:494
node
tools::sg::text_style::x_orientation
sf_vec3f x_orientation
Definition: text_style:38
tools::sg::text_style::font
sf_string font
Definition: text_style:28
tools::sg::text_style::vjust
sf_enum< sg::vjust > vjust
Definition: text_style:35
tools::sg::style_parser::scale
void scale(float a_v)
Definition: style_parser:566
tools::sg::text_style::hinting
sf< bool > hinting
Definition: text_style:33
style_parser
tools::sg::line_pattern
line_pattern
Definition: enums:10
tools::sg::text_style::text_style
text_style(const text_style &a_from)
Definition: text_style:142
tools::sg::winding_ccw
@ winding_ccw
Definition: enums:105
tools::sg::style_parser::font
void font(const std::string &a_v)
Definition: style_parser:548
tools::sg::hjust
hjust
Definition: enums:73
tools::sg::style_parser::front_face
void front_face(winding_type a_v)
Definition: style_parser:605
tools::sg::style_parser::parse
bool parse(std::ostream &a_out, const cmaps_t &a_cmaps, const std::string &a_s)
Definition: style_parser:624
tools::sg::text_style::line_width
sf< float > line_width
Definition: text_style:44
tools::sg::text_style::modeling
sf_string modeling
Definition: text_style:27
tools::sg::node
Definition: node:28
TOOLS_NODE
#define TOOLS_NODE(a__class, a__sclass, a__parent)
Definition: node:324
tools::sg::sf_vec3f
Definition: sf_vec3f:14
tools::sg::text_style::rotated
sf< bool > rotated
Definition: text_style:41
tools::sg::style_parser::color
void color(const colorf &a_v)
Definition: style_parser:479
tools::sg::style_parser::back_color
void back_color(const colorf &a_v)
Definition: style_parser:485
sf_string
tools::sg::text_style::back_shadow
sf< float > back_shadow
Definition: text_style:25
tools::sg::text_style::visible
sf< bool > visible
Definition: text_style:22
tools::sg::desc_fields
Definition: field_desc:148
tools::sg::text_style::~text_style
virtual ~text_style()
Definition: text_style:140
tools::sg::color
Definition: color:16
tools::sg::text_style::from_string
bool from_string(std::ostream &a_out, const cmaps_t &a_cmaps, const std::string &a_s)
Definition: text_style:197
tools::sg::left
@ left
Definition: enums:74
tools::sg::sf_vec
Definition: sf_vec:15
sf_vec3f
tools::sg::style_parser::font_modeling
void font_modeling(sg::font_modeling a_v)
Definition: style_parser:509
tools::sg::cmaps_t
std::map< std::string, style_colormap > cmaps_t
Definition: style_colormap:536
tools::sg::sf_enum< sg::font_modeling >
tools::sg::text_style::font_modeling
sf_enum< sg::font_modeling > font_modeling
Definition: text_style:30
tools::sg::text_style::smoothing
sf< bool > smoothing
Definition: text_style:32
tools::sg::font_modeling
font_modeling
Definition: enums:91
tools::sg::style_parser
Definition: style_parser:20
tools::sg::style_parser::encoding
void encoding(const std::string &a_v)
Definition: style_parser:524
tools::sg::encoding_none
const std::string & encoding_none()
Definition: strings:38
tools::sg::style_parser::smoothing
void smoothing(bool a_v)
Definition: style_parser:527
tools::sg::vjust
vjust
Definition: enums:79
tools::vec3f
Definition: vec3f:13
tools::sg::bottom
@ bottom
Definition: enums:80
tools::sg::text_style::text_style
text_style()
Definition: text_style:112
tools::sg::text_style::color
sf_vec< colorf, float > color
Definition: text_style:23
tools::sg::text_style::front_face
sf_enum< winding_type > front_face
Definition: text_style:50
tools::sg::style_parser::font_size
void font_size(float a_v)
Definition: style_parser:506
sf_enum
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::text_style::line_pattern
sf< lpat > line_pattern
Definition: text_style:45
tools::sg::node::add_field
void add_field(field *a_field)
Definition: node:128
tools::sg::text_style::hjust
sf_enum< sg::hjust > hjust
Definition: text_style:34
enums
tools::sg::text_style
Definition: text_style:19
tools::sg::text_style::node_desc_fields
virtual const desc_fields & node_desc_fields() const
Definition: text_style:54
tools::sg::style_parser::line_width
void line_width(float a_v)
Definition: style_parser:491
TOOLS_FIELD_DESC_NODE_CLASS
#define TOOLS_FIELD_DESC_NODE_CLASS(a__class)
Definition: field:68
tools::sg::line_solid
@ line_solid
Definition: enums:11
tools::sg::style_parser::visible
void visible(bool a_v)
Definition: style_parser:581
tools::sg::text_style::scale
sf< float > scale
Definition: text_style:36
tools::sg::sf_string
Definition: sf_string:15
tools::sg::text_style::y_orientation
sf_vec3f y_orientation
Definition: text_style:39
tools::sg::style_parser::translation
void translation(const vec3f &a_v)
Definition: style_parser:602
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::sg::font_hershey
const std::string & font_hershey()
Definition: strings:186
tools::sg::text_style::translation
sf_vec3f translation
Definition: text_style:47
tools::sg::style_parser::modeling
void modeling(const std::string &a_v)
Definition: style_parser:515
tools::sg::font_filled
@ font_filled
Definition: enums:93
tools::sg::style_parser::enforced
void enforced(bool a_v)
Definition: style_parser:599
tools::sg::style_parser::options
void options(const std::string &a_v)
Definition: style_parser:593
tools::sg::text_style::operator=
text_style & operator=(const text_style &a_from)
Definition: text_style:169
tools::sg::text_style::options
sf_string options
Definition: text_style:52
tools::sg::style_parser::line_pattern
void line_pattern(lpat a_v)
Definition: style_parser:545
tools::sg::sf< bool >
TOOLS_ARG_FIELD_DESC
#define TOOLS_ARG_FIELD_DESC(a__field)
Definition: field:71
tools::sg::style_parser::hinting
void hinting(bool a_v)
Definition: style_parser:530
tools::sg::text_style::encoding
sf_string encoding
Definition: text_style:31
tools::sg::text_style::back_color
sf_vec< colorf, float > back_color
Definition: text_style:24