00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "textFont.h"
00016 #include "config_text.h"
00017 #include "string_utils.h"
00018 #include "geomVertexData.h"
00019 #include "geomVertexFormat.h"
00020 #include "geomVertexWriter.h"
00021 #include "geomLinestrips.h"
00022 #include "geom.h"
00023 #include <ctype.h>
00024
00025 TypeHandle TextFont::_type_handle;
00026
00027
00028
00029
00030
00031
00032 TextFont::
00033 TextFont() {
00034 _is_valid = false;
00035 _line_height = 1.0f;
00036 _space_advance = 0.25f;
00037 }
00038
00039
00040
00041
00042
00043
00044 TextFont::
00045 TextFont(const TextFont ©) :
00046 Namable(copy),
00047 _is_valid(copy._is_valid),
00048 _line_height(copy._line_height),
00049 _space_advance(copy._space_advance)
00050 {
00051 }
00052
00053
00054
00055
00056
00057
00058 TextFont::
00059 ~TextFont() {
00060 }
00061
00062
00063
00064
00065
00066
00067 void TextFont::
00068 write(ostream &out, int indent_level) const {
00069 indent(out, indent_level)
00070 << "TextFont " << get_name() << "\n";
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 TextGlyph *TextFont::
00089 get_invalid_glyph() {
00090 if (_invalid_glyph == (TextGlyph *)NULL) {
00091 make_invalid_glyph();
00092 }
00093 return _invalid_glyph;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103 TextFont::RenderMode TextFont::
00104 string_render_mode(const string &string) {
00105 if (cmp_nocase_uh(string, "texture") == 0) {
00106 return RM_texture;
00107 } else if (cmp_nocase_uh(string, "wireframe") == 0) {
00108 return RM_wireframe;
00109 } else if (cmp_nocase_uh(string, "polygon") == 0) {
00110 return RM_polygon;
00111 } else if (cmp_nocase_uh(string, "extruded") == 0) {
00112 return RM_extruded;
00113 } else if (cmp_nocase_uh(string, "solid") == 0) {
00114 return RM_solid;
00115 } else {
00116 return RM_invalid;
00117 }
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127 TextFont::WindingOrder TextFont::
00128 string_winding_order(const string &string) {
00129 if (cmp_nocase_uh(string, "default") == 0) {
00130 return WO_default;
00131 } else if (cmp_nocase_uh(string, "left") == 0) {
00132 return WO_left;
00133 } else if (cmp_nocase_uh(string, "right") == 0) {
00134 return WO_right;
00135 } else {
00136 return WO_invalid;
00137 }
00138 }
00139
00140
00141
00142
00143
00144
00145
00146 void TextFont::
00147 make_invalid_glyph() {
00148 CPT(GeomVertexFormat) vformat = GeomVertexFormat::get_v3();
00149 PT(GeomVertexData) vdata =
00150 new GeomVertexData("invalid_glyph", vformat, GeomEnums::UH_static);
00151
00152 GeomVertexWriter vertex(vdata, InternalName::get_vertex());
00153 vertex.add_data3(_line_height * 0.2, 0.0f, _line_height * 0.1f);
00154 vertex.add_data3(_line_height * 0.5f, 0.0f, _line_height * 0.1f);
00155 vertex.add_data3(_line_height * 0.5f, 0.0f, _line_height * 0.7f);
00156 vertex.add_data3(_line_height * 0.2, 0.0f, _line_height * 0.7f);
00157
00158 PT(GeomPrimitive) prim = new GeomLinestrips(GeomEnums::UH_static);
00159 prim->add_consecutive_vertices(0, 4);
00160 prim->add_vertex(0);
00161 prim->close_primitive();
00162
00163 PT(Geom) geom = new Geom(vdata);
00164 geom->add_primitive(prim);
00165
00166 _invalid_glyph = new TextGlyph(0, geom, RenderState::make_empty(),
00167 _line_height * 0.7f);
00168 }
00169
00170
00171
00172
00173
00174 ostream &
00175 operator << (ostream &out, TextFont::RenderMode rm) {
00176 switch (rm) {
00177 case TextFont::RM_texture:
00178 return out << "texture";
00179 case TextFont::RM_wireframe:
00180 return out << "wireframe";
00181 case TextFont::RM_polygon:
00182 return out << "polygon";
00183 case TextFont::RM_extruded:
00184 return out << "extruded";
00185 case TextFont::RM_solid:
00186 return out << "solid";
00187
00188 case TextFont::RM_invalid:
00189 return out << "invalid";
00190 }
00191
00192 return out << "(**invalid TextFont::RenderMode(" << (int)rm << ")**)";
00193 }
00194
00195
00196
00197
00198
00199 istream &
00200 operator >> (istream &in, TextFont::RenderMode &rm) {
00201 string word;
00202 in >> word;
00203
00204 rm = TextFont::string_render_mode(word);
00205 return in;
00206 }
00207
00208
00209
00210
00211
00212 ostream &
00213 operator << (ostream &out, TextFont::WindingOrder wo) {
00214 switch (wo) {
00215 case TextFont::WO_default:
00216 return out << "default";
00217 case TextFont::WO_left:
00218 return out << "left";
00219 case TextFont::WO_right:
00220 return out << "right";
00221
00222 case TextFont::WO_invalid:
00223 return out << "invalid";
00224 }
00225
00226 return out << "(**invalid TextFont::WindingOrder(" << (int)wo << ")**)";
00227 }
00228
00229
00230
00231
00232
00233 istream &
00234 operator >> (istream &in, TextFont::WindingOrder &wo) {
00235 string word;
00236 in >> word;
00237
00238 wo = TextFont::string_winding_order(word);
00239 return in;
00240 }