40 nassertv(font_def !=
nullptr);
45 if (_cs == CS_default) {
46 _cs = get_default_coordinate_system();
50 if (_cs != CS_zup_right) {
57 LMatrix4 mat = LMatrix4::convert_mat(_cs, CS_zup_right);
70 for (
int i = 0; i < num_textures; ++i) {
91 find_characters(_font, RenderState::make_empty());
92 _is_valid = !_glyphs.empty();
96 Glyphs::iterator gi = _glyphs.find(character);
97 if (gi != _glyphs.end()) {
102 set_name(font_def->get_name());
116 void StaticTextFont::
117 write(std::ostream &out,
int indent_level)
const {
119 <<
"StaticTextFont " << get_name() <<
"; " 120 << _glyphs.size() <<
" characters available in font:\n";
121 Glyphs::const_iterator gi;
125 static const int num_letters = 26;
126 static const int num_digits = 10;
127 bool lowercase[num_letters];
128 bool uppercase[num_letters];
129 bool digits[num_digits];
131 memset(lowercase, 0,
sizeof(
bool) * num_letters);
132 memset(uppercase, 0,
sizeof(
bool) * num_letters);
133 memset(digits, 0,
sizeof(
bool) * num_digits);
135 int count_lowercase = 0;
136 int count_uppercase = 0;
137 int count_digits = 0;
139 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
140 int ch = (*gi).first;
144 lowercase[ch -
'a'] =
true;
146 }
else if (isupper(ch)) {
148 uppercase[ch -
'A'] =
true;
150 }
else if (isdigit(ch)) {
152 digits[ch -
'0'] =
true;
157 if (count_lowercase == num_letters) {
158 indent(out, indent_level + 2)
159 <<
"All lowercase letters\n";
161 }
else if (count_lowercase > 0) {
162 indent(out, indent_level + 2)
163 <<
"Some lowercase letters: ";
164 for (
int i = 0; i < num_letters; i++) {
166 out << (char)(i +
'a');
172 if (count_uppercase == num_letters) {
173 indent(out, indent_level + 2)
174 <<
"All uppercase letters\n";
176 }
else if (count_uppercase > 0) {
177 indent(out, indent_level + 2)
178 <<
"Some uppercase letters: ";
179 for (
int i = 0; i < num_letters; i++) {
181 out << (char)(i +
'A');
187 if (count_digits == num_digits) {
188 indent(out, indent_level + 2)
191 }
else if (count_digits > 0) {
192 indent(out, indent_level + 2)
194 for (
int i = 0; i < num_digits; i++) {
196 out << (char)(i +
'0');
202 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
203 int ch = (*gi).first;
204 if (ch >= 128 || !isalnum(ch)) {
205 indent(out, indent_level + 2)
207 if (ch < isprint(ch)) {
208 out <<
" = '" << (char)ch <<
"'\n";
221 bool StaticTextFont::
222 get_glyph(
int character, CPT(
TextGlyph) &glyph) {
223 Glyphs::const_iterator gi = _glyphs.find(character);
224 if (gi == _glyphs.end()) {
230 glyph = (*gi).second;
239 void StaticTextFont::
242 CPT(
RenderState) next_net_state = net_state->compose(root->get_state());
248 const Geom *geom = geode->get_geom(i);
250 bool found_points =
false;
251 for (
size_t j = 0; j < geom->get_num_primitives() && !found_points; ++j) {
253 if (primitive->
is_of_type(GeomPoints::get_class_type())) {
268 for (
int i = 0; i < num_children; i++) {
269 find_character_gsets(cr.
get_child(i), ch, dot, state,
280 void StaticTextFont::
282 CPT(
RenderState) next_net_state = net_state->compose(root->get_state());
283 std::string name = root->get_name();
285 bool all_digits = !name.empty();
286 const char *p = name.c_str();
287 while (all_digits && *p !=
'\0') {
290 all_digits = (isdigit(*p) != 0);
295 int character = atoi(name.c_str());
299 find_character_gsets(root, ch, dot, state, next_net_state);
300 PN_stdfloat width = 0.0;
301 if (dot !=
nullptr) {
304 GeomVertexReader reader(dot->get_vertex_data(), InternalName::get_vertex());
308 _glyphs[character] =
new TextGlyph(character, ch, state, width);
310 }
else if (name ==
"ds") {
317 find_character_gsets(root, ch, dot, state, next_net_state);
318 if (dot !=
nullptr) {
321 GeomVertexReader reader(dot->get_vertex_data(), InternalName::get_vertex());
322 LVecBase3 data = reader.get_data3();
323 _line_height = data[2];
324 _total_poly_margin = data[0];
325 _space_advance = 0.25f * _line_height;
331 for (
int i = 0; i < num_children; i++) {
332 find_characters(cr.
get_child(i), next_net_state);
get_geom_state
Returns the RenderState associated with the nth geom of the node.
get_advance
Returns the distance by which the character pointer should be advanced after placing this character; ...
A basic node of the scene graph or data graph.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_magfilter
Returns the filter mode of the texture for magnification.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int flatten_light()
Analyzes the geometry below this node and reports the number of vertices, triangles,...
PandaNode * get_child(size_t n) const
Returns the nth child of the node.
set_magfilter
Sets the filtering method that should be used when viewing the texture up close.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
int clear_model_nodes()
Recursively walks through the scene graph at this level and below, looking for ModelNodes,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_quality_level
Returns the current quality_level hint.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TextureCollection find_all_textures() const
Returns a list of a textures applied to geometry at this node and below.
get_minfilter
Returns the filter mode of the texture for minification.
An encapsulation of a font; i.e.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
size_t get_num_children() const
Returns the number of children of the node.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
set_minfilter
Sets the filtering method that should be used when viewing the texture from a distance.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A container for geometry primitives.
get_children
Returns an object that can be used to walk through the list of children of the node.
A representation of a single glyph (character) from a font.
Manages a list of Texture objects, as returned by TexturePool::find_all_textures().
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...
get_num_textures
Returns the number of Textures in the collection.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PT(TextFont) StaticTextFont
Returns a new copy of the same font.
set_compression
Requests that this particular Texture be compressed when it is loaded into texture memory.
PandaNode * node() const
Returns the referenced node of the path.
set_quality_level
Sets a hint to the renderer about the desired performance / quality tradeoff for this particular text...
get_num_geoms
Returns the number of geoms in 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_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.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_texture
Returns the nth Texture in the collection.