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