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