Panda3D
Loading...
Searching...
No Matches
textGlyph.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 textGlyph.I
10 * @author drose
11 * @date 2002-02-08
12 */
13
14/**
15 * This constructor makes an empty glyph.
16 */
18TextGlyph(int character, PN_stdfloat advance) :
19 _character(character),
20 _geom(nullptr),
21 _advance(advance),
22 _has_quad(false)
23{
24}
25
26/**
27 *
28 */
29INLINE TextGlyph::
30TextGlyph(int character, const Geom *geom,
31 const RenderState *state, PN_stdfloat advance) :
32 _character(character),
33 _geom(geom),
34 _state(state),
35 _advance(advance),
36 _has_quad(false)
37{
38 if (geom != nullptr) {
39 check_quad_geom();
40 }
41 if (_state == nullptr) {
42 _state = RenderState::make_empty();
43 }
44}
45
46/**
47 *
48 */
49INLINE TextGlyph::
50TextGlyph(const TextGlyph &copy) :
51 _character(copy._character),
52 _geom(copy._geom),
53 _state(copy._state),
54 _advance(copy._advance),
55 _has_quad(copy._has_quad),
56 _quad_dimensions(copy._quad_dimensions),
57 _quad_texcoords(copy._quad_texcoords)
58{
59}
60
61/**
62 *
63 */
64INLINE void TextGlyph::
65operator = (const TextGlyph &copy) {
66 _character = copy._character;
67 _geom = copy._geom;
68 _state = copy._state;
69 _advance = copy._advance;
70 _has_quad = copy._has_quad;
71 _quad_dimensions = copy._quad_dimensions;
72 _quad_texcoords = copy._quad_texcoords;
73}
74
75/**
76 * Returns the Unicode value that corresponds to the character this glyph
77 * represents.
78 */
79INLINE int TextGlyph::
80get_character() const {
81 return _character;
82}
83
84/**
85 * Returns true if this glyph contains the definition for a simple quad,
86 * rather than a more complex piece of geometry.
87 *
88 * You may still call get_geom() even if this returns true, which will
89 * synthesize a Geom for this quad.
90 */
91INLINE bool TextGlyph::
92has_quad() const {
93 return _has_quad;
94}
95
96/**
97 * Assuming that this glyph is representable as a textured quad, returns its
98 * dimensions and UV range. Returns false if it is not representable as a
99 * quad, or if it is whitespace.
100 *
101 * The order of the components is left, bottom, right, top.
102 */
103INLINE bool TextGlyph::
104get_quad(LVecBase4 &dimensions, LVecBase4 &texcoords) const {
105 if (!_has_quad) {
106 return false;
107 }
108
109 dimensions = _quad_dimensions;
110 texcoords = _quad_texcoords;
111 return true;
112}
113
114/**
115 * Returns the state in which the glyph should be rendered.
116 */
117INLINE const RenderState *TextGlyph::
118get_state() const {
119 return _state;
120}
121
122/**
123 * Returns the distance by which the character pointer should be advanced
124 * after placing this character; i.e. the approximate width the character
125 * takes up on the line.
126 */
127INLINE PN_stdfloat TextGlyph::
128get_advance() const {
129 return _advance;
130}
A container for geometry primitives.
Definition geom.h:54
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition renderState.h:47
A representation of a single glyph (character) from a font.
Definition textGlyph.h:28
get_character
Returns the Unicode value that corresponds to the character this glyph represents.
Definition textGlyph.h:44
TextGlyph(int character, PN_stdfloat advance=0)
This constructor makes an empty glyph.
Definition textGlyph.I:18
get_state
Returns the state in which the glyph should be rendered.
Definition textGlyph.h:45
bool has_quad() const
Returns true if this glyph contains the definition for a simple quad, rather than a more complex piec...
Definition textGlyph.I:92
get_advance
Returns the distance by which the character pointer should be advanced after placing this character; ...
Definition textGlyph.h:46
bool get_quad(LVecBase4 &dimensions, LVecBase4 &texcoords) const
Assuming that this glyph is representable as a textured quad, returns its dimensions and UV range.
Definition textGlyph.I:104