Panda3D
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  */
17 INLINE TextGlyph::
18 TextGlyph(int character, PN_stdfloat advance) :
19  _character(character),
20  _geom(nullptr),
21  _advance(advance),
22  _has_quad(false)
23 {
24 }
25 
26 /**
27  *
28  */
29 INLINE TextGlyph::
30 TextGlyph(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  */
49 INLINE TextGlyph::
50 TextGlyph(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  */
64 INLINE void TextGlyph::
65 operator = (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  */
79 INLINE int TextGlyph::
80 get_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  */
91 INLINE bool TextGlyph::
92 has_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  */
103 INLINE bool TextGlyph::
104 get_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  */
117 INLINE const RenderState *TextGlyph::
118 get_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  */
127 INLINE PN_stdfloat TextGlyph::
128 get_advance() const {
129  return _advance;
130 }
TextGlyph(int character, PN_stdfloat advance=0)
This constructor makes an empty glyph.
Definition: textGlyph.I:18
A container for geometry primitives.
Definition: geom.h:54
A representation of a single glyph (character) from a font.
Definition: textGlyph.h:28
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
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
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