25 PT(
TextFont) TextProperties::_default_font;
26 bool TextProperties::_loaded_default_font =
false;
37 _small_caps(text_small_caps),
38 _small_caps_scale(text_small_caps_scale),
41 _underscore_height(0.0f),
44 _wordwrap_width(0.0f),
45 _preserve_trailing_whitespace(false),
46 _text_color(1.0f, 1.0f, 1.0f, 1.0f),
47 _shadow_color(0.0f, 0.0f, 0.0f, 1.0f),
48 _shadow_offset(0.0f, 0.0f),
50 _tab_width(text_tab_width),
63 _text_state = copy._text_state;
64 _shadow_state = copy._shadow_state;
72 _specified = copy._specified;
75 _small_caps = copy._small_caps;
76 _small_caps_scale = copy._small_caps_scale;
78 _underscore = copy._underscore;
79 _underscore_height = copy._underscore_height;
81 _indent_width = copy._indent_width;
82 _wordwrap_width = copy._wordwrap_width;
83 _preserve_trailing_whitespace = copy._preserve_trailing_whitespace;
84 _text_color = copy._text_color;
85 _shadow_color = copy._shadow_color;
86 _shadow_offset = copy._shadow_offset;
88 _draw_order = copy._draw_order;
89 _tab_width = copy._tab_width;
90 _glyph_scale = copy._glyph_scale;
91 _glyph_shift = copy._glyph_shift;
92 _text_scale = copy._text_scale;
93 _direction = copy._direction;
96 _shadow_state.clear();
102 bool TextProperties::
104 if (_specified != other._specified) {
108 if ((_specified & F_has_font) && _font != other._font) {
111 if ((_specified & F_has_small_caps) && _small_caps != other._small_caps) {
114 if ((_specified & F_has_small_caps_scale) && _small_caps_scale != other._small_caps_scale) {
117 if ((_specified & F_has_slant) && _slant != other._slant) {
120 if ((_specified & F_has_underscore) && _underscore != other._underscore) {
123 if ((_specified & F_has_underscore_height) && _underscore_height != other._underscore_height) {
126 if ((_specified & F_has_align) && _align != other._align) {
129 if ((_specified & F_has_indent) && _indent_width != other._indent_width) {
132 if ((_specified & F_has_wordwrap) && _wordwrap_width != other._wordwrap_width) {
135 if ((_specified & F_has_preserve_trailing_whitespace) && _preserve_trailing_whitespace != other._preserve_trailing_whitespace) {
138 if ((_specified & F_has_text_color) && _text_color != other._text_color) {
141 if ((_specified & F_has_text_color) && _text_color != other._text_color) {
144 if ((_specified & F_has_shadow_color) && _shadow_color != other._shadow_color) {
147 if ((_specified & F_has_shadow) && _shadow_offset != other._shadow_offset) {
150 if ((_specified & F_has_bin) && _bin != other._bin) {
153 if ((_specified & F_has_draw_order) && _draw_order != other._draw_order) {
156 if ((_specified & F_has_tab_width) && _tab_width != other._tab_width) {
159 if ((_specified & F_has_glyph_scale) && _glyph_scale != other._glyph_scale) {
162 if ((_specified & F_has_glyph_shift) && _glyph_shift != other._glyph_shift) {
165 if ((_specified & F_has_text_scale) && _text_scale != other._text_scale) {
168 if ((_specified & F_has_direction) && _direction != other._direction) {
189 if (other.has_font()) {
192 if (other.has_small_caps()) {
196 if (other.has_slant()) {
199 if (other.has_underscore()) {
202 if (other.has_underscore_height()) {
205 if (other.has_align()) {
208 if (other.has_indent()) {
211 if (other.has_wordwrap()) {
214 if (other.has_text_color()) {
215 set_text_color(other.get_text_color());
217 if (other.has_shadow_color()) {
218 set_shadow_color(other.get_shadow_color());
220 if (other.has_shadow()) {
226 if (other.has_draw_order()) {
229 if (other.has_tab_width()) {
236 if (other.has_glyph_shift()) {
239 if (other.has_glyph_scale()) {
243 if (other.has_text_scale()) {
255 void TextProperties::
256 write(std::ostream &out,
int indent_level)
const {
259 <<
"default properties\n";
264 <<
"with font " << _font->get_name() <<
"\n";
267 <<
"with NULL font\n";
270 if (has_small_caps()) {
274 if (has_small_caps_scale()) {
282 if (has_underscore()) {
286 if (has_underscore_height()) {
294 switch (get_align()) {
308 out <<
"A_boxed_left\n";
312 out <<
"A_boxed_right\n";
316 out <<
"A_boxed_center\n";
323 <<
"indent at " << get_indent() <<
" units.\n";
326 if (has_wordwrap()) {
328 <<
"word-wrapping at " << get_wordwrap() <<
" units.\n";
331 if (has_text_color()) {
333 <<
"text color is " << get_text_color() <<
"\n";
340 if (has_shadow_color()) {
342 <<
"shadow color is " << get_shadow_color() <<
"\n";
347 <<
"bin is " <<
get_bin() <<
"\n";
349 if (has_draw_order()) {
354 if (has_tab_width()) {
359 if (has_glyph_scale()) {
363 if (has_glyph_shift()) {
368 if (has_text_scale()) {
394 if (!_text_state.is_null()) {
398 CPT(
RenderState) state = RenderState::make_empty();
400 if (has_text_color()) {
401 state = state->add_attrib(ColorAttrib::make_flat(get_text_color()));
402 if (get_text_color()[3] != 1.0) {
403 state = state->add_attrib(TransparencyAttrib::make(TransparencyAttrib::M_alpha));
411 std::swap(_text_state, state);
421 if (!_shadow_state.is_null()) {
422 return _shadow_state;
425 CPT(
RenderState) state = RenderState::make_empty();
427 state = state->add_attrib(ColorAttrib::make_flat(get_shadow_color()));
428 if (get_shadow_color()[3] != 1.0) {
429 state = state->add_attrib(TransparencyAttrib::make(TransparencyAttrib::M_alpha));
436 std::swap(_shadow_state, state);
437 return _shadow_state;
446 void TextProperties::
447 load_default_font() {
448 _loaded_default_font =
true;
450 if (!text_default_font.empty()) {
453 if (_default_font !=
nullptr && _default_font->is_valid()) {
459 #ifdef COMPILE_IN_DEFAULT_FONT 462 _default_font =
new DynamicTextFont((
const char *)default_font_data,
463 default_font_size, 0);
465 ((DynamicTextFont *)_default_font.p())->set_winding_order(DynamicTextFont::WO_left);
469 std::string data((
const char *)default_font_data, default_font_size);
473 std::istringstream inz(data);
474 IDecompressStream in(&inz,
false);
478 std::istringstream in(data);
482 if (bam_file.
open_read(in,
"default font stream")) {
483 PT(
PandaNode) node = bam_file.read_node();
484 if (node !=
nullptr) {
489 #endif // HAVE_FREETYPE 490 #endif // COMPILE_IN_DEFAULT_FONT bool is_any_specified() const
Returns true if any properties have been specified, false otherwise.
The principle public interface to reading and writing Bam disk files.
set_align
Specifies the alignment of the text within its margins.
get_small_caps_scale
Returns the scale factor applied to lowercase letters from their uppercase equivalents,...
A basic node of the scene graph or data graph.
get_font
Returns the font currently in use, if any.
bool open_read(const Filename &bam_filename, bool report_errors=true)
Attempts to open the indicated filename for reading.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const RenderState * get_text_state() const
Returns a RenderState object suitable for rendering text with these properties.
set_direction
Specifies the text direction.
set_text_scale
Specifies the factor by which to scale the text, in addition to any scalings imposed by the node,...
void add_properties(const TextProperties &other)
Sets any properties that are explicitly specified in other on this object.
set_glyph_scale
Specifies the factor by which to scale each letter of the text as it is placed, in addition to any sc...
get_direction
Returns the direction of the text as specified by set_direction().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_shadow
Returns the offset of the shadow as set by set_shadow().
get_draw_order
Returns the drawing order set with set_draw_order().
get_underscore
Returns the underscore flag.
set_underscore_height
Specifies the vertical height of the underscore, relative to the text baseline.
get_tab_width
Returns the width set via set_tab_width().
get_slant
Returns the factor by which the text is specified to slant to the right.
An encapsulation of a font; i.e.
get_glyph_scale
Returns the scale factor of each letter as specified by set_glyph_scale().
set_tab_width
Sets the width of each tab stop, in screen units.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A StaticTextFont is loaded up from a model that was previously generated via egg-mkfont,...
has_bin
Returns true if an explicit drawing bin has been set via set_bin(), false otherwise.
set_shadow
Specifies that the text should be drawn with a shadow, by creating a second copy of the text and offs...
get_value
Returns the variable's value.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_draw_order
Sets the drawing order of text created by the TextNode.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_small_caps
Sets the small_caps flag.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
set_wordwrap
Sets the text up to automatically wordwrap when it exceeds the indicated width.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_bin
Returns the drawing bin set with set_bin(), or empty string if no bin has been set.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
set_glyph_shift
Specifies a vertical amount to shift each letter of the text as it is placed.
set_slant
Specifies the factor by which the text slants to the right.
void clear()
Unsets all properties that have been specified so far, and resets the TextProperties structure to its...
set_indent
Specifies the amount of extra space that is inserted before the first character of each line.
static TextFont * load_font(const std::string &filename)
Loads the given filename up into a font, if it has not already been loaded, and returns the new font.
set_bin
Names the CullBin that the text geometry should be assigned to.
This defines the set of visual properties that may be assigned to the individual characters of the te...
get_underscore_height
Returns the vertical height of the underscore; see set_underscore_height().
set_underscore
Sets the underscore flag.
set_small_caps_scale
Sets the scale factor applied to lowercase letters from their uppercase equivalents,...
set_font
Sets the font that will be used when making text.
get_glyph_shift
Returns the vertical shift of each letter as specified by set_glyph_shift().
TypeHandle is the identifier used to differentiate C++ class types.
get_text_scale
Returns the scale factor of the text as specified by set_text_scale().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const RenderState * get_shadow_state() const
Returns a RenderState object suitable for rendering the shadow of this text with these properties.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_small_caps
Returns the small_caps flag.