Panda3D
Loading...
Searching...
No Matches
textProperties.I
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file textProperties.I
10 * @author drose
11 * @date 2004-04-06
12 */
13
14/**
15 *
16 */
17INLINE bool TextProperties::
18operator != (const TextProperties &other) const {
19 return !operator == (other);
20}
21
22/**
23 * Returns true if any properties have been specified, false otherwise.
24 */
26is_any_specified() const {
27 return (_specified != 0);
28}
29
30/**
31 * Specifies the default font to be used for any TextNode whose font is
32 * uninitialized or NULL. See set_font().
33 */
36 // If the user overrides the default, we don't need to try to load whatever
37 // it would have been.
38 _loaded_default_font = true;
39 _default_font = font;
40}
41
42/**
43 * Specifies the default font to be used for any TextNode whose font is
44 * uninitialized or NULL. See set_font().
45 */
48 if (!_loaded_default_font) {
49 load_default_font();
50 }
51 return _default_font;
52}
53
54/**
55 * Sets the font that will be used when making text. If this is set to NULL,
56 * the default font will be used, which can be set via set_default_font().
57 */
58INLINE void TextProperties::
59set_font(TextFont *font) {
60 _font = font;
61 _specified |= F_has_font;
62}
63
64/**
65 * Restores the default font to the text.
66 */
67INLINE void TextProperties::
68clear_font() {
69 _font.clear();
70 _specified &= ~F_has_font;
71}
72
73/**
74 *
75 */
76INLINE bool TextProperties::
77has_font() const {
78 return (_specified & F_has_font) != 0;
79}
80
81/**
82 * Returns the font currently in use, if any. If no font is in use, this
83 * returns the default font.
84 */
86get_font() const {
87 return has_font() ? _font.p() : get_default_font();
88}
89
90/**
91 * Sets the small_caps flag. When this is set, lowercase letters are
92 * generated as scaled-down versions of their uppercase equivalents. This is
93 * particularly useful to set for fonts that do not have lowercase letters.
94 *
95 * It is also a good idea to set this for a (dynamic) font that has already
96 * implemented lowercase letters as scaled-down versions of their uppercase
97 * equivalents, since without this flag the texture memory may needlessly
98 * duplicate equivalent glyphs for upper and lowercase letters. Setting this
99 * flag causes the texture memory to share the mixed-case letters.
100 *
101 * The amount by which the lowercase letters are scaled is specified by
102 * set_small_caps_scale().
103 */
104INLINE void TextProperties::
105set_small_caps(bool small_caps) {
106 _small_caps = small_caps;
107 _specified |= F_has_small_caps;
108}
109
110/**
111 *
112 */
113INLINE void TextProperties::
114clear_small_caps() {
115 _small_caps = false;
116 _specified &= ~F_has_small_caps;
117}
118
119/**
120 *
121 */
122INLINE bool TextProperties::
123has_small_caps() const {
124 return (_specified & F_has_small_caps) != 0;
125}
126
127/**
128 * Returns the small_caps flag. See set_small_caps().
129 */
130INLINE bool TextProperties::
131get_small_caps() const {
132 return _small_caps;
133}
134
135/**
136 * Sets the scale factor applied to lowercase letters from their uppercase
137 * equivalents, when the small_caps flag is in effect. See set_small_caps().
138 * Normally, this will be a number less than one.
139 */
140INLINE void TextProperties::
141set_small_caps_scale(PN_stdfloat small_caps_scale) {
142 _small_caps_scale = small_caps_scale;
143}
144
145/**
146 *
147 */
148INLINE void TextProperties::
149clear_small_caps_scale() {
150 _small_caps_scale = text_small_caps_scale;
151 _specified &= ~F_has_small_caps_scale;
152}
153
154/**
155 *
156 */
157INLINE bool TextProperties::
158has_small_caps_scale() const {
159 return (_specified & F_has_small_caps_scale) != 0;
160}
161
162/**
163 * Returns the scale factor applied to lowercase letters from their uppercase
164 * equivalents, when the small_caps flag is in effect. See set_small_caps()
165 * and set_small_caps_scale().
166 */
167INLINE PN_stdfloat TextProperties::
168get_small_caps_scale() const {
169 return _small_caps_scale;
170}
171
172/**
173 * Specifies the factor by which the text slants to the right.
174 */
175INLINE void TextProperties::
176set_slant(PN_stdfloat slant) {
177 _slant = slant;
178 _specified |= F_has_slant;
179}
180
181/**
182 *
183 */
184INLINE void TextProperties::
185clear_slant() {
186 _slant = 0.0f;
187 _specified &= ~F_has_slant;
188}
189
190/**
191 *
192 */
193INLINE bool TextProperties::
194has_slant() const {
195 return (_specified & F_has_slant) != 0;
196}
197
198/**
199 * Returns the factor by which the text is specified to slant to the right.
200 */
201INLINE PN_stdfloat TextProperties::
202get_slant() const {
203 return _slant;
204}
205
206/**
207 * Sets the underscore flag. When this is set, the text is underscored with a
208 * one-pixel line the same color as the text foreground, drawn at the
209 * baseline.
210 */
211INLINE void TextProperties::
212set_underscore(bool underscore) {
213 _underscore = underscore;
214 _specified |= F_has_underscore;
215}
216
217/**
218 *
219 */
220INLINE void TextProperties::
221clear_underscore() {
222 _underscore = false;
223 _specified &= ~F_has_underscore;
224}
225
226/**
227 *
228 */
229INLINE bool TextProperties::
230has_underscore() const {
231 return (_specified & F_has_underscore) != 0;
232}
233
234/**
235 * Returns the underscore flag. See set_underscore().
236 */
237INLINE bool TextProperties::
238get_underscore() const {
239 return _underscore;
240}
241
242/**
243 * Specifies the vertical height of the underscore, relative to the text
244 * baseline. This only has meaning if the underscore mode is enabled with
245 * set_underscore().
246 */
247INLINE void TextProperties::
248set_underscore_height(PN_stdfloat underscore_height) {
249 _underscore_height = underscore_height;
250 _specified |= F_has_underscore_height;
251}
252
253/**
254 *
255 */
256INLINE void TextProperties::
257clear_underscore_height() {
258 _underscore_height = 0.0f;
259 _specified &= ~F_has_underscore_height;
260}
261
262/**
263 *
264 */
265INLINE bool TextProperties::
266has_underscore_height() const {
267 return (_specified & F_has_underscore_height) != 0;
268}
269
270/**
271 * Returns the vertical height of the underscore; see set_underscore_height().
272 */
273INLINE PN_stdfloat TextProperties::
274get_underscore_height() const {
275 return has_underscore_height() ? _underscore_height : text_default_underscore_height;
276}
277
278/**
279 * Specifies the alignment of the text within its margins.
280 */
281INLINE void TextProperties::
282set_align(TextProperties::Alignment align_type) {
283 _align = align_type;
284 _specified |= F_has_align;
285}
286
287/**
288 * Restores the default alignment of the text.
289 */
290INLINE void TextProperties::
291clear_align() {
292 _align = A_left;
293 _specified &= ~F_has_align;
294}
295
296/**
297 *
298 */
299INLINE bool TextProperties::
300has_align() const {
301 return (_specified & F_has_align) != 0;
302}
303
304/**
305 *
306 */
307INLINE TextProperties::Alignment TextProperties::
308get_align() const {
309 return _align;
310}
311
312/**
313 * Specifies the amount of extra space that is inserted before the first
314 * character of each line. This can be thought of as a left margin.
315 */
316INLINE void TextProperties::
317set_indent(PN_stdfloat indent) {
318 _indent_width = indent;
319 _specified |= F_has_indent;
320}
321
322/**
323 * Removes the indent setting from the text. Text will be as wide as it is.
324 */
325INLINE void TextProperties::
326clear_indent() {
327 _indent_width = 0.0f;
328 _specified &= ~F_has_indent;
329}
330
331/**
332 *
333 */
334INLINE bool TextProperties::
335has_indent() const {
336 return (_specified & F_has_indent) != 0;
337}
338
339/**
340 *
341 */
342INLINE PN_stdfloat TextProperties::
343get_indent() const {
344 return _indent_width;
345}
346
347/**
348 * Sets the text up to automatically wordwrap when it exceeds the indicated
349 * width. This can be thought of as a right margin or margin width.
350 */
351INLINE void TextProperties::
352set_wordwrap(PN_stdfloat wordwrap) {
353 _wordwrap_width = wordwrap;
354 _specified |= F_has_wordwrap;
355}
356
357/**
358 * Removes the wordwrap setting from the text. Text will be as wide as it is.
359 */
360INLINE void TextProperties::
362 _wordwrap_width = 0.0f;
363 _specified &= ~F_has_wordwrap;
364}
365
366/**
367 *
368 */
369INLINE bool TextProperties::
370has_wordwrap() const {
371 return (_specified & F_has_wordwrap) != 0;
372}
373
374/**
375 *
376 */
377INLINE PN_stdfloat TextProperties::
378get_wordwrap() const {
379 return _wordwrap_width;
380}
381
382/**
383 * Sets the preserve_trailing_whitespace flag. When this is set, trailing
384 * whitespace at the end of the line is not stripped when the text is
385 * wordwrapped (it is stripped by default). Since the trailing whitespace is
386 * invisible, this is important primarily for determining the proper width of
387 * a frame or card behind the text.
388 */
389INLINE void TextProperties::
390set_preserve_trailing_whitespace(bool preserve_trailing_whitespace) {
391 _preserve_trailing_whitespace = preserve_trailing_whitespace;
392 _specified |= F_has_preserve_trailing_whitespace;
393}
394
395/**
396 *
397 */
398INLINE void TextProperties::
399clear_preserve_trailing_whitespace() {
400 _preserve_trailing_whitespace = false;
401 _specified &= ~F_has_preserve_trailing_whitespace;
402}
403
404/**
405 *
406 */
407INLINE bool TextProperties::
408has_preserve_trailing_whitespace() const {
409 return (_specified & F_has_preserve_trailing_whitespace) != 0;
410}
411
412/**
413 * Returns the preserve_trailing_whitespace flag. See
414 * set_preserve_trailing_whitespace().
415 */
416INLINE bool TextProperties::
418 return _preserve_trailing_whitespace;
419}
420
421/**
422 *
423 */
424INLINE void TextProperties::
425set_text_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a) {
426 set_text_color(LColor(r, g, b, a));
427}
428
429/**
430 *
431 */
432INLINE void TextProperties::
433set_text_color(const LColor &text_color) {
434 _text_color = text_color;
435 _specified |= F_has_text_color;
436 _text_state.clear();
437}
438
439/**
440 * Removes the text color specification; the text will be colored whatever it
441 * was in the source font file.
442 */
443INLINE void TextProperties::
445 _text_color.set(1.0f, 1.0f, 1.0f, 1.0f);
446 _specified &= ~F_has_text_color;
447 _text_state.clear();
448}
449
450/**
451 *
452 */
453INLINE bool TextProperties::
454has_text_color() const {
455 return (_specified & F_has_text_color) != 0;
456}
457
458/**
459 *
460 */
461INLINE LColor TextProperties::
462get_text_color() const {
463 return _text_color;
464}
465
466/**
467 *
468 */
469INLINE void TextProperties::
470set_shadow_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a) {
471 set_shadow_color(LColor(r, g, b, a));
472}
473
474/**
475 *
476 */
477INLINE void TextProperties::
478set_shadow_color(const LColor &shadow_color) {
479 _shadow_color = shadow_color;
480 _specified |= F_has_shadow_color;
481 _shadow_state.clear();
482}
483
484/**
485 * Removes the shadow color specification.
486 */
487INLINE void TextProperties::
489 _shadow_color.set(0.0f, 0.0f, 0.0f, 1.0f);
490 _specified &= ~F_has_shadow_color;
491 _shadow_state.clear();
492}
493
494/**
495 *
496 */
497INLINE bool TextProperties::
498has_shadow_color() const {
499 return (_specified & F_has_shadow_color) != 0;
500}
501
502/**
503 *
504 */
505INLINE LColor TextProperties::
506get_shadow_color() const {
507 return _shadow_color;
508}
509
510/**
511 * Specifies that the text should be drawn with a shadow, by creating a second
512 * copy of the text and offsetting it slightly behind the first.
513 */
514INLINE void TextProperties::
515set_shadow(PN_stdfloat xoffset, PN_stdfloat yoffset) {
516 set_shadow(LVecBase2(xoffset, yoffset));
517}
518
519/**
520 * Specifies that the text should be drawn with a shadow, by creating a second
521 * copy of the text and offsetting it slightly behind the first.
522 */
523INLINE void TextProperties::
524set_shadow(const LVecBase2 &shadow_offset) {
525 _shadow_offset = shadow_offset;
526 _specified |= F_has_shadow;
527}
528
529/**
530 * Specifies that a shadow will not be drawn behind the text.
531 */
532INLINE void TextProperties::
533clear_shadow() {
534 _specified &= ~F_has_shadow;
535 _shadow_offset.set(0.0f, 0.0f);
536}
537
538/**
539 *
540 */
541INLINE bool TextProperties::
542has_shadow() const {
543 return (_specified & F_has_shadow) != 0;
544}
545
546/**
547 * Returns the offset of the shadow as set by set_shadow(). It is an error to
548 * call this if has_shadow() is false.
549 */
550INLINE LVector2 TextProperties::
551get_shadow() const {
552 return _shadow_offset;
553}
554
555/**
556 * Names the CullBin that the text geometry should be assigned to. If this is
557 * set, then a CullBinAttrib will be created to explicitly place each
558 * component in the named bin.
559 *
560 * The draw_order value will also be passed to each CullBinAttrib as
561 * appropriate; this is particularly useful if this names a CullBinFixed, e.g.
562 * "fixed".
563 */
564INLINE void TextProperties::
565set_bin(const std::string &bin) {
566 _bin = bin;
567 _specified |= F_has_bin;
568 _text_state.clear();
569 _shadow_state.clear();
570}
571
572/**
573 * Removes the effect of a previous call to set_bin(). Text will be drawn in
574 * whatever bin it would like to be drawn in, with no explicit ordering.
575 */
576INLINE void TextProperties::
577clear_bin() {
578 _bin = std::string();
579 _specified &= ~F_has_bin;
580 _text_state.clear();
581 _shadow_state.clear();
582}
583
584/**
585 * Returns true if an explicit drawing bin has been set via set_bin(), false
586 * otherwise.
587 */
588INLINE bool TextProperties::
589has_bin() const {
590 return (_specified & F_has_bin) != 0;
591}
592
593/**
594 * Returns the drawing bin set with set_bin(), or empty string if no bin has
595 * been set.
596 */
597INLINE const std::string &TextProperties::
598get_bin() const {
599 return _bin;
600}
601
602/**
603 * Sets the drawing order of text created by the TextNode. This is actually
604 * the draw order of the card and frame. The shadow is drawn at
605 * _draw_order+1, and the text at _draw_order+2.
606 *
607 * This affects the sorting order assigned to the nodes as they are created,
608 * and also is passed to whatever bin may be assigned via set_bin().
609 *
610 * The return value is the first unused draw_order number, e.g. _draw_order +
611 * 3.
612 */
613INLINE int TextProperties::
614set_draw_order(int draw_order) {
615 _draw_order = draw_order;
616 _specified |= F_has_draw_order;
617 _text_state.clear();
618 _shadow_state.clear();
619 return _draw_order + 3;
620}
621
622/**
623 *
624 */
625INLINE void TextProperties::
626clear_draw_order() {
627 _draw_order = 1;
628 _specified &= ~F_has_draw_order;
629 _text_state.clear();
630 _shadow_state.clear();
631}
632
633/**
634 *
635 */
636INLINE bool TextProperties::
637has_draw_order() const {
638 return (_specified & F_has_draw_order) != 0;
639}
640
641/**
642 * Returns the drawing order set with set_draw_order().
643 */
644INLINE int TextProperties::
645get_draw_order() const {
646 return _draw_order;
647}
648
649/**
650 * Sets the width of each tab stop, in screen units. A tab character embedded
651 * in the text will advance the horizontal position to the next tab stop.
652 */
653INLINE void TextProperties::
654set_tab_width(PN_stdfloat tab_width) {
655 _tab_width = tab_width;
656 _specified |= F_has_tab_width;
657}
658
659/**
660 *
661 */
662INLINE void TextProperties::
663clear_tab_width() {
664 _tab_width = text_tab_width;
665 _specified &= ~F_has_tab_width;
666}
667
668/**
669 *
670 */
671INLINE bool TextProperties::
672has_tab_width() const {
673 return (_specified & F_has_tab_width) != 0;
674}
675
676/**
677 * Returns the width set via set_tab_width().
678 */
679INLINE PN_stdfloat TextProperties::
680get_tab_width() const {
681 return _tab_width;
682}
683
684/**
685 * Specifies the factor by which to scale each letter of the text as it is
686 * placed, in addition to any scales inherited from the node or from
687 * set_text_scale(). This can be used (possibly in conjunction with
688 * set_glyph_shift()) to implement superscripting or subscripting.
689 *
690 * The glyph scale is cumulative when applied to nested TextProperties. It is
691 * intended primarily for implementing superscripts, not for scaling the text
692 * in general. See also set_text_scale(), which is intended primarily for
693 * scaling the text in general, and is not cumulative.
694 */
695INLINE void TextProperties::
696set_glyph_scale(PN_stdfloat glyph_scale) {
697 _glyph_scale = glyph_scale;
698 _specified |= F_has_glyph_scale;
699}
700
701/**
702 *
703 */
704INLINE void TextProperties::
705clear_glyph_scale() {
706 _specified &= ~F_has_glyph_scale;
707 _glyph_scale = 0.0f;
708}
709
710/**
711 *
712 */
713INLINE bool TextProperties::
714has_glyph_scale() const {
715 return (_specified & F_has_glyph_scale) != 0;
716}
717
718/**
719 * Returns the scale factor of each letter as specified by set_glyph_scale().
720 */
721INLINE PN_stdfloat TextProperties::
722get_glyph_scale() const {
723 return _glyph_scale;
724}
725
726/**
727 * Specifies a vertical amount to shift each letter of the text as it is
728 * placed. This can be used (possibly in conjunction with set_glyph_scale())
729 * to implement superscripting or subscripting.
730 */
731INLINE void TextProperties::
732set_glyph_shift(PN_stdfloat glyph_shift) {
733 _glyph_shift = glyph_shift;
734 _specified |= F_has_glyph_shift;
735}
736
737/**
738 *
739 */
740INLINE void TextProperties::
741clear_glyph_shift() {
742 _specified &= ~F_has_glyph_shift;
743 _glyph_shift = 0.0f;
744}
745
746/**
747 *
748 */
749INLINE bool TextProperties::
750has_glyph_shift() const {
751 return (_specified & F_has_glyph_shift) != 0;
752}
753
754/**
755 * Returns the vertical shift of each letter as specified by
756 * set_glyph_shift().
757 */
758INLINE PN_stdfloat TextProperties::
759get_glyph_shift() const {
760 return _glyph_shift;
761}
762
763/**
764 * Specifies the factor by which to scale the text, in addition to any
765 * scalings imposed by the node, as well as in addition to the glyph scale.
766 *
767 * The text scale is not cumulative when applied to nested TextProperties.
768 * See also set_glyph_scale(), which is cumulative.
769 */
770INLINE void TextProperties::
771set_text_scale(PN_stdfloat text_scale) {
772 _text_scale = text_scale;
773 _specified |= F_has_text_scale;
774}
775
776/**
777 *
778 */
779INLINE void TextProperties::
780clear_text_scale() {
781 _specified &= ~F_has_text_scale;
782 _text_scale = 0.0f;
783}
784
785/**
786 *
787 */
788INLINE bool TextProperties::
789has_text_scale() const {
790 return (_specified & F_has_text_scale) != 0;
791}
792
793/**
794 * Returns the scale factor of the text as specified by set_text_scale().
795 */
796INLINE PN_stdfloat TextProperties::
797get_text_scale() const {
798 return _text_scale;
799}
800
801/**
802 * Specifies the text direction. If none is specified, it will be guessed
803 * based on the contents of the string.
804 *
805 * @since 1.10.0
806 */
807INLINE void TextProperties::
808set_direction(Direction direction) {
809 _direction = direction;
810 _specified |= F_has_direction;
811}
812
813/**
814 * Clears the text direction setting. If no text direction is specified, it
815 * will be guessed based on the contents of the string.
816 *
817 * @since 1.10.0
818 */
819INLINE void TextProperties::
821 _specified &= ~F_has_direction;
822 _direction = D_ltr;
823}
824
825/**
826 * @since 1.10.0
827 */
828INLINE bool TextProperties::
829has_direction() const {
830 return (_specified & F_has_direction) != 0;
831}
832
833/**
834 * Returns the direction of the text as specified by set_direction().
835 *
836 * @since 1.10.0
837 */
838INLINE TextProperties::Direction TextProperties::
839get_direction() const {
840 return _direction;
841}
An encapsulation of a font; i.e.
Definition textFont.h:32
This defines the set of visual properties that may be assigned to the individual characters of the te...
set_glyph_shift
Specifies a vertical amount to shift each letter of the text as it is placed.
set_underscore_height
Specifies the vertical height of the underscore, relative to the text baseline.
get_slant
Returns the factor by which the text is specified to slant to the right.
set_shadow
Specifies that the text should be drawn with a shadow, by creating a second copy of the text and offs...
get_draw_order
Returns the drawing order set with set_draw_order().
set_align
Specifies the alignment of the text within its margins.
clear_bin
Removes the effect of a previous call to set_bin().
get_underscore_height
Returns the vertical height of the underscore; see set_underscore_height().
get_small_caps
Returns the small_caps flag.
get_glyph_shift
Returns the vertical shift of each letter as specified by set_glyph_shift().
clear_font
Restores the default font to the text.
clear_shadow
Specifies that a shadow will not be drawn behind the text.
set_draw_order
Sets the drawing order of text created by the TextNode.
set_wordwrap
Sets the text up to automatically wordwrap when it exceeds the indicated width.
clear_indent
Removes the indent setting from the text.
clear_shadow_color
Removes the shadow color specification.
get_preserve_trailing_whitespace
Returns the preserve_trailing_whitespace flag.
clear_direction
Clears the text direction setting.
get_glyph_scale
Returns the scale factor of each letter as specified by set_glyph_scale().
set_underscore
Sets the underscore flag.
set_font
Sets the font that will be used when making text.
set_small_caps_scale
Sets the scale factor applied to lowercase letters from their uppercase equivalents,...
set_tab_width
Sets the width of each tab stop, in screen units.
get_shadow
Returns the offset of the shadow as set by set_shadow().
get_bin
Returns the drawing bin set with set_bin(), or empty string if no bin has been set.
clear_text_color
Removes the text color specification; the text will be colored whatever it was in the source font fil...
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_font
Returns the font currently in use, if any.
get_small_caps_scale
Returns the scale factor applied to lowercase letters from their uppercase equivalents,...
get_underscore
Returns the underscore flag.
clear_wordwrap
Removes the wordwrap setting from the text.
bool is_any_specified() const
Returns true if any properties have been specified, false otherwise.
set_indent
Specifies the amount of extra space that is inserted before the first character of each line.
static void set_default_font(TextFont *)
Specifies the default font to be used for any TextNode whose font is uninitialized or NULL.
get_direction
Returns the direction of the text as specified by set_direction().
get_tab_width
Returns the width set via set_tab_width().
has_bin
Returns true if an explicit drawing bin has been set via set_bin(), false otherwise.
clear_align
Restores the default alignment of the text.
set_preserve_trailing_whitespace
Sets the preserve_trailing_whitespace flag.
static TextFont * get_default_font()
Specifies the default font to be used for any TextNode whose font is uninitialized or NULL.
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,...
get_text_scale
Returns the scale factor of the text as specified by set_text_scale().
set_small_caps
Sets the small_caps flag.
set_slant
Specifies the factor by which the text slants to the right.
set_bin
Names the CullBin that the text geometry should be assigned to.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20