15 #include "staticTextFont.h" 16 #include "config_text.h" 20 #include "geomVertexReader.h" 21 #include "geomPoints.h" 22 #include "renderState.h" 26 #include "textureCollection.h" 50 if (_cs == CS_default) {
51 _cs = get_default_coordinate_system();
55 if (_cs != CS_zup_right) {
76 for (
int i = 0; i < num_textures; ++i) {
97 find_characters(_font, RenderState::make_empty());
98 _is_valid = !_glyphs.empty();
102 Glyphs::iterator gi = _glyphs.find(character);
103 if (gi != _glyphs.end()) {
105 _space_advance = glyph->get_advance();
108 set_name(font_def->get_name());
126 void StaticTextFont::
127 write(ostream &out,
int indent_level)
const {
128 indent(out, indent_level)
129 <<
"StaticTextFont " << get_name() <<
"; " 130 << _glyphs.size() <<
" characters available in font:\n";
131 Glyphs::const_iterator gi;
136 static const int num_letters = 26;
137 static const int num_digits = 10;
138 bool lowercase[num_letters];
139 bool uppercase[num_letters];
140 bool digits[num_digits];
142 memset(lowercase, 0,
sizeof(
bool) * num_letters);
143 memset(uppercase, 0,
sizeof(
bool) * num_letters);
144 memset(digits, 0,
sizeof(
bool) * num_digits);
146 int count_lowercase = 0;
147 int count_uppercase = 0;
148 int count_digits = 0;
150 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
151 int ch = (*gi).first;
155 lowercase[ch -
'a'] =
true;
157 }
else if (isupper(ch)) {
159 uppercase[ch -
'A'] =
true;
161 }
else if (isdigit(ch)) {
163 digits[ch -
'0'] =
true;
168 if (count_lowercase == num_letters) {
169 indent(out, indent_level + 2)
170 <<
"All lowercase letters\n";
172 }
else if (count_lowercase > 0) {
173 indent(out, indent_level + 2)
174 <<
"Some lowercase letters: ";
175 for (
int i = 0; i < num_letters; i++) {
177 out << (char)(i +
'a');
183 if (count_uppercase == num_letters) {
184 indent(out, indent_level + 2)
185 <<
"All uppercase letters\n";
187 }
else if (count_uppercase > 0) {
188 indent(out, indent_level + 2)
189 <<
"Some uppercase letters: ";
190 for (
int i = 0; i < num_letters; i++) {
192 out << (char)(i +
'A');
198 if (count_digits == num_digits) {
199 indent(out, indent_level + 2)
202 }
else if (count_digits > 0) {
203 indent(out, indent_level + 2)
205 for (
int i = 0; i < num_digits; i++) {
207 out << (char)(i +
'0');
213 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
214 int ch = (*gi).first;
215 if (ch >= 128 || !isalnum(ch)) {
216 indent(out, indent_level + 2)
218 if (ch < isprint(ch)) {
219 out <<
" = '" << (char)ch <<
"'\n";
236 bool StaticTextFont::
237 get_glyph(
int character,
const TextGlyph *&glyph) {
238 Glyphs::const_iterator gi = _glyphs.find(character);
239 if (gi == _glyphs.end()) {
245 glyph = (*gi).second;
258 void StaticTextFont::
261 CPT(
RenderState) next_net_state = net_state->compose(root->get_state());
267 const Geom *geom = geode->get_geom(i);
269 bool found_points =
false;
270 for (
int j = 0; j < geom->get_num_primitives() && !found_points; j++) {
272 if (primitive->
is_of_type(GeomPoints::get_class_type())) {
288 for (
int i = 0; i < num_children; i++) {
289 find_character_gsets(cr.
get_child(i), ch, dot, state,
303 void StaticTextFont::
305 CPT(
RenderState) next_net_state = net_state->compose(root->get_state());
306 string name = root->get_name();
308 bool all_digits = !name.empty();
309 const char *p = name.c_str();
310 while (all_digits && *p !=
'\0') {
314 all_digits = (isdigit(*p) != 0);
319 int character = atoi(name.c_str());
323 find_character_gsets(root, ch, dot, state, next_net_state);
324 PN_stdfloat width = 0.0;
325 if (dot != (
Geom *)NULL) {
328 GeomVertexReader reader(dot->get_vertex_data(), InternalName::get_vertex());
332 _glyphs[character] =
new TextGlyph(character, ch, state, width);
334 }
else if (name ==
"ds") {
341 find_character_gsets(root, ch, dot, state, next_net_state);
342 if (dot != (
Geom *)NULL) {
345 GeomVertexReader reader(dot->get_vertex_data(), InternalName::get_vertex());
347 _space_advance = 0.25f * _line_height;
353 for (
int i = 0; i < num_children; i++) {
354 find_characters(cr.
get_child(i), next_net_state);
const RenderState * get_geom_state(int n) const
Returns the RenderState associated with the nth geom of the node.
int get_num_children() const
Returns the number of children of the node.
A basic node of the scene graph or data graph.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
SamplerState::FilterType get_magfilter() const
Returns the filter mode of the texture for magnification.
int clear_model_nodes()
Recursively walks through the scene graph at this level and below, looking for ModelNodes, and calls model_node->set_preserve_transform(PT_drop_node) on each one.
void set_magfilter(FilterType filter)
Sets the filtering method that should be used when viewing the texture up close.
int get_num_geoms() const
Returns the number of geoms in the node.
static const LMatrix4f & convert_mat(CoordinateSystem from, CoordinateSystem to)
Returns a matrix that transforms from the indicated coordinate system to the indicated coordinate sys...
TextureCollection find_all_textures() const
Returns a list of a textures applied to geometry at this node and below.
An encapsulation of a font; i.e.
StaticTextFont(PandaNode *font_def, CoordinateSystem cs=CS_default)
The constructor expects the root node to a model generated via egg-mkfont, which consists of a set of...
NodePath attach_new_node(PandaNode *node, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Attaches a new node, with or without existing parents, to the scene graph below the referenced node o...
This is a 4-by-4 transform matrix.
A container for geometry primitives.
const LVecBase3 & get_data3()
Returns the data associated with the read row, expressed as a 3-component value, and advances the rea...
A representation of a single glyph (character) from a font.
Manages a list of Texture objects, as returned by TexturePool::find_all_textures().
void set_quality_level(QualityLevel quality_level)
Sets a hint to the renderer about the desired performance / quality tradeoff for this particular text...
QualityLevel get_quality_level() const
Returns the current quality_level hint.
NodePath copy_to(const NodePath &other, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Functions like instance_to(), except a deep copy is made of the referenced node and all of its descen...
int flatten_light()
Lightly flattens out the hierarchy below this node by applying transforms, colors, and texture matrices from the nodes onto the vertices, but does not remove any nodes.
void set_compression(CompressionMode compression)
Requests that this particular Texture be compressed when it is loaded into texture memory...
TextGlyph * get_invalid_glyph()
Returns a special glyph that can be used as a placeholder for any character not in the font...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
int get_num_textures() const
Returns the number of Textures in the collection.
PandaNode * node() const
Returns the referenced node of the path.
Children get_children(Thread *current_thread=Thread::get_current_thread()) const
Returns an object that can be used to walk through the list of children of the node.
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
float get_data1f()
Returns the data associated with the read row, expressed as a 1-component value, and advances the rea...
void set_minfilter(FilterType filter)
Sets the filtering method that should be used when viewing the texture from a distance.
void set_mat(const LMatrix4 &mat)
Directly sets an arbitrary 4x4 transform matrix.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Texture * get_texture(int index) const
Returns the nth Texture in the collection.
PandaNode * get_child(int n) const
Returns the nth child of the node.
TypeHandle is the identifier used to differentiate C++ class types.
virtual bool is_geom_node() const
A simple downcast check.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
NodePath get_child(int n, Thread *current_thread=Thread::get_current_thread()) const
Returns a NodePath representing the nth child of the referenced node.
A node that holds Geom objects, renderable pieces of geometry.
SamplerState::FilterType get_minfilter() const
Returns the filter mode of the texture for minification.