Warning, /include/Geant4/tools/sg/base_freetype is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_sg_base_freetype
0005 #define tools_sg_base_freetype
0006
0007 #include "base_text"
0008 #include "gstos"
0009 #include "sf_string"
0010 #include <map>
0011
0012 // abstract class to handle freetype text.
0013
0014 namespace tools {
0015 namespace sg {
0016
0017 class base_freetype : public base_text, public gstos {
0018 TOOLS_HEADER(base_freetype,tools::sg::base_freetype,base_text)
0019 public:
0020 sf_string font;
0021 sf_enum<winding_type> front_face; //default is ccw.
0022 sf_enum<font_modeling> modeling;
0023 typedef unsigned int unichar;
0024 typedef std::vector<unichar> uniline;
0025 mf_std_vec<unichar> unitext;
0026 public:
0027 virtual const desc_fields& node_desc_fields() const {
0028 TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::base_freetype)
0029 static const desc_fields s_v(parent::node_desc_fields(),4, //WARNING : take care of count.
0030 TOOLS_ARG_FIELD_DESC(font),
0031 TOOLS_ARG_FIELD_DESC(front_face),
0032
0033 TOOLS_ARG_FIELD_DESC_ENUMS_BEG(modeling,3)
0034 TOOLS_ARG_ENUM(font_outline),
0035 TOOLS_ARG_ENUM(font_filled),
0036 TOOLS_ARG_ENUM(font_pixmap)
0037 TOOLS_ARG_FIELD_DESC_ENUMS_END,
0038
0039 TOOLS_ARG_FIELD_DESC(unitext)
0040 );
0041 return s_v;
0042 }
0043 private:
0044 void add_fields(){
0045 add_field(&font);
0046 add_field(&front_face);
0047 add_field(&modeling);
0048 add_field(&unitext);
0049 }
0050 public:
0051 base_freetype()
0052 :parent()
0053 ,gstos()
0054
0055 ,font("")
0056 ,front_face(winding_ccw)
0057 ,modeling(font_filled)
0058 ,unitext()
0059 {
0060 add_fields();
0061 }
0062 virtual ~base_freetype(){}
0063 public:
0064 base_freetype(const base_freetype& a_from)
0065 :parent(a_from)
0066 ,gstos(a_from)
0067
0068 ,font(a_from.font)
0069 ,front_face(a_from.front_face)
0070 ,modeling(a_from.modeling)
0071 ,unitext(a_from.unitext)
0072 ,m_fonts(a_from.m_fonts)
0073 ,m_finders(a_from.m_finders)
0074 {
0075 add_fields();
0076 }
0077
0078 base_freetype& operator=(const base_freetype& a_from){
0079 parent::operator=(a_from);
0080 gstos::operator=(a_from);
0081 font = a_from.font;
0082 front_face = a_from.front_face;
0083 modeling = a_from.modeling;
0084 unitext = a_from.unitext;
0085 m_fonts = a_from.m_fonts;
0086 m_finders = a_from.m_finders;
0087 return *this;
0088 }
0089
0090 public:
0091 static base_freetype* create(const base_freetype& a_ttf) {
0092 return safe_cast<node,base_freetype>(*(a_ttf.copy()));
0093 }
0094 public:
0095 void dump_unitext(std::ostream& a_out) {
0096 a_out << "unitext size : " << unitext.values().size() << std::endl;
0097 std::vector<uniline>::const_iterator vit;
0098 for(vit=unitext.values().begin();vit!=unitext.values().end();++vit) {
0099 const uniline& line = *vit;
0100 a_out << "beg line :" << std::endl;
0101 std::vector<unichar>::const_iterator it;
0102 for(it=line.begin();it!=line.end();++it) {
0103 a_out << ((unsigned int)*it) << std::endl;
0104 }
0105 a_out << "end line." << std::endl;
0106 }
0107 }
0108 public:
0109 typedef const unsigned char*(*font_getter)(unsigned int&);
0110 void add_embedded_font(const std::string& a_name,font_getter a_getter) {
0111 unsigned int size;
0112 const unsigned char* buffer = a_getter(size);
0113 m_fonts[a_name] = embedded_font(size,buffer); //warning: we do not take ownership of buffer.
0114 }
0115 typedef std::pair<unsigned int,const unsigned char*> embedded_font;
0116 void add_embedded_font(const std::string& a_name,unsigned int a_size,const unsigned char* a_buffer) {
0117 //warning: we do not take ownership of a_buffer.
0118 m_fonts[a_name] = embedded_font(a_size,a_buffer);
0119 }
0120 bool find_embedded_font(const std::string& a_name,unsigned int& a_size,const unsigned char*& a_buffer) {
0121 std::map<std::string,embedded_font>::const_iterator it = m_fonts.find(a_name);
0122 if(it==m_fonts.end()) {a_size = 0;a_buffer = 0;return false;}
0123 a_size = (*it).second.first;
0124 a_buffer = (*it).second.second;
0125 return true;
0126 }
0127 public:
0128 typedef bool(*font_finder)(const std::string&,std::string&);
0129 void add_font_finder(font_finder a_finder) {m_finders.push_back(a_finder);}
0130 bool find_font_with_finders(const std::string& a_name,std::string& a_font) {
0131 tools_vforcit(font_finder,m_finders,it) {
0132 if((*it)(a_name,a_font)) return true;
0133 }
0134 a_font.clear();
0135 return false;
0136 }
0137 protected:
0138 std::map<std::string,embedded_font> m_fonts;
0139 std::vector<font_finder> m_finders;
0140 };
0141
0142 }}
0143
0144 #endif