inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_sg_text_style 00005 #define inlib_sg_text_style 00006 00007 #include "../vec3f" 00008 00009 #include "sfs" 00010 #include "node" 00011 #include "styles" 00012 #include "enums" 00013 #include "style_parser" 00014 00015 namespace inlib { 00016 namespace sg { 00017 00018 class text_style : public node { 00019 static const std::string& s_class() { 00020 static const std::string s_v("inlib::sg::text_style"); 00021 return s_v; 00022 } 00023 public: 00024 sf<bool> visible; 00025 sf_vec<colorf,float> color; 00026 sf<float> transparency; 00027 sf_vec<colorf,float> back_color; 00028 sf<float> back_transparency; 00029 sf<float> back_shadow; 00030 00031 sf_string modeling; 00032 sf_string font; 00033 sf<float> font_size; 00034 sf_string encoding; 00035 sf<bool> smoothing; 00036 sf<bool> hinting; 00037 sf_enum<sg::hjust> hjust; 00038 sf_enum<sg::vjust> vjust; 00039 sf<float> scale; 00040 // For 3D text : 00041 sf_vec<vec3f,float> x_orientation; 00042 sf_vec<vec3f,float> y_orientation; 00043 // For bitmap text : 00044 sf<bool> rotated; 00045 00046 // for text_hershey : 00047 sf<float> line_width; 00048 sf<lpat> line_pattern; 00049 sf<bool> enforced; 00050 sf_vec<vec3f,float> translation; 00051 00052 // for text_freetype tessellation : 00053 sf_enum<winding_type> front_face; 00054 private: 00055 void add_fields(){ 00056 add_field(&visible); 00057 add_field(&color); 00058 add_field(&transparency); 00059 00060 add_field(&modeling); 00061 add_field(&font); 00062 add_field(&font_size); 00063 add_field(&encoding); 00064 add_field(&smoothing); 00065 add_field(&hinting); 00066 add_field(&hjust); 00067 add_field(&vjust); 00068 add_field(&scale); 00069 add_field(&x_orientation); 00070 add_field(&y_orientation); 00071 add_field(&rotated); 00072 00073 add_field(&line_width); 00074 add_field(&line_pattern); 00075 add_field(&enforced); 00076 add_field(&translation); 00077 00078 add_field(&front_face); 00079 } 00080 public: //actions 00081 virtual node* copy() const {return new text_style(*this);} 00082 virtual const std::string& s_cls() const {return s_class();} 00083 public: 00084 text_style() 00085 :node() 00086 ,visible(true) 00087 ,color(colorf::black()) 00088 ,transparency(0) 00089 ,back_color(colorf::white()) 00090 ,back_transparency(0) 00091 ,back_shadow(0) 00092 ,modeling() 00093 ,font(font_hershey()) 00094 ,font_size(10) 00095 ,encoding(encoding_none()) 00096 ,smoothing(false) 00097 ,hinting(false) 00098 ,hjust(left) 00099 ,vjust(bottom) 00100 ,scale(1) 00101 ,x_orientation(vec3f(1,0,0)) 00102 ,y_orientation(vec3f(0,1,0)) 00103 ,rotated(false) 00104 ,line_width(1) 00105 ,line_pattern(line_solid) 00106 ,enforced(false) 00107 ,translation(vec3f(0,0,0)) 00108 ,front_face(winding_ccw) 00109 { 00110 add_fields(); 00111 } 00112 virtual ~text_style(){} 00113 public: 00114 text_style(const text_style& a_from) 00115 :node(a_from),visible(a_from.visible) 00116 ,color(a_from.color) 00117 ,transparency(a_from.transparency) 00118 ,back_color(a_from.back_color) 00119 ,back_transparency(a_from.back_transparency) 00120 ,back_shadow(a_from.back_shadow) 00121 ,modeling(a_from.modeling) 00122 ,font(a_from.font) 00123 ,font_size(a_from.font_size) 00124 ,encoding(a_from.encoding) 00125 ,smoothing(a_from.smoothing) 00126 ,hinting(a_from.hinting) 00127 ,hjust(a_from.hjust) 00128 ,vjust(a_from.vjust) 00129 ,scale(a_from.scale) 00130 ,x_orientation(a_from.x_orientation) 00131 ,y_orientation(a_from.y_orientation) 00132 ,rotated(a_from.rotated) 00133 ,line_width(a_from.line_width) 00134 ,line_pattern(a_from.line_pattern) 00135 ,enforced(a_from.enforced) 00136 ,translation(a_from.translation) 00137 ,front_face(a_from.front_face) 00138 { 00139 add_fields(); 00140 } 00141 text_style& operator=(const text_style& a_from){ 00142 visible = a_from.visible; 00143 color = a_from.color; 00144 transparency = a_from.transparency; 00145 back_color = a_from.back_color; 00146 back_transparency = a_from.back_transparency; 00147 back_shadow = a_from.back_shadow; 00148 modeling = a_from.modeling; 00149 font = a_from.font; 00150 font_size = a_from.font_size; 00151 encoding = a_from.encoding; 00152 smoothing = a_from.smoothing; 00153 hinting = a_from.hinting; 00154 hjust = a_from.hjust; 00155 vjust = a_from.vjust; 00156 scale = a_from.scale; 00157 x_orientation = a_from.x_orientation; 00158 y_orientation = a_from.y_orientation; 00159 rotated = a_from.rotated; 00160 line_width = a_from.line_width; 00161 line_pattern = a_from.line_pattern; 00162 enforced = a_from.enforced; 00163 translation = a_from.translation; 00164 front_face = a_from.front_face; 00165 return *this; 00166 } 00167 public: 00168 bool from_string(std::ostream& a_out,const cmaps_t& a_cmaps, 00169 const std::string& a_s){ 00170 style_parser sp; 00171 00172 sp.visible(visible.value()); 00173 sp.color(color.value()); 00174 sp.transparency(transparency.value()); 00175 sp.back_color(back_color.value()); 00176 sp.back_transparency(back_transparency.value()); 00177 sp.back_shadow(back_shadow.value()); 00178 sp.modeling(modeling.value()); 00179 sp.font(font.value()); 00180 sp.font_size(font_size.value()); 00181 sp.encoding(encoding.value()); 00182 sp.smoothing(smoothing.value()); 00183 sp.hinting(hinting.value()); 00184 sp.scale(scale.value()); 00185 //sp.angle(angle.value()); 00186 //sp.x_orientation(x_orientation.value()); 00187 //sp.y_orientation(y_orientation.value()); 00188 //sp.rotated(rotated.value()); 00189 sp.line_width(line_width.value()); 00190 sp.line_pattern(line_pattern.value()); 00191 sp.enforced(enforced.value()); 00192 sp.translation(translation.value()); 00193 sp.front_face(front_face.value()); 00194 00195 if(!sp.parse(a_out,a_cmaps,a_s)) { 00196 a_out << "inlib::sg::text_style::from_string :" 00197 << " parse failed." 00198 << std::endl; 00199 return false; 00200 } 00201 00202 visible.value(sp.visible()); 00203 color.value(sp.color()); 00204 transparency.value(sp.transparency()); 00205 back_color.value(sp.back_color()); 00206 back_transparency.value(sp.back_transparency()); 00207 back_shadow.value(sp.back_shadow()); 00208 modeling.value(sp.modeling()); 00209 font.value(sp.font()); 00210 font_size.value(sp.font_size()); 00211 encoding.value(sp.encoding()); 00212 smoothing.value(sp.smoothing()); 00213 hinting.value(sp.hinting()); 00214 scale.value(sp.scale()); 00215 //angle.value(sp.angle()); 00216 //x_orientation.value(sp.x_orientation()); 00217 //y_orientation.value(sp.y_orientation()); 00218 //rotated.value(sp.rotated()); 00219 line_width.value(sp.line_width()); 00220 line_pattern.value(sp.line_pattern()); 00221 enforced.value(sp.enforced()); 00222 translation.value(sp.translation()); 00223 front_face = sp.front_face(); 00224 00225 return true; 00226 } 00227 }; 00228 00229 }} 00230 00231 #endif