Panda3D
Loading...
Searching...
No Matches
geomTextGlyph.cxx
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 geomTextGlyph.cxx
10 * @author drose
11 * @date 2005-03-31
12 */
13
14#include "geomTextGlyph.h"
15#include "datagramIterator.h"
16#include "bamReader.h"
17#include "indent.h"
18
19TypeHandle GeomTextGlyph::_type_handle;
20
21
22/**
23 *
24 */
25GeomTextGlyph::
26GeomTextGlyph(const TextGlyph *glyph, const GeomVertexData *data) :
27 Geom(data)
28{
29 // Initially, there is only one glyph in the Geom. There might be
30 // additional Glyphs later when we flatten the graph and call Geom::unify().
31 if (glyph != nullptr) {
32 _glyphs.reserve(1);
33 _glyphs.push_back(glyph);
34 }
35}
36
37/**
38 *
39 */
40GeomTextGlyph::
41GeomTextGlyph(const GeomVertexData *data) :
42 Geom(data)
43{
44 // With this constructor, there are no glyphs initially.
45}
46
47/**
48 *
49 */
50GeomTextGlyph::
51GeomTextGlyph(const GeomTextGlyph &copy) :
52 Geom(copy),
53 _glyphs(copy._glyphs)
54{
55}
56
57/**
58 *
59 */
60GeomTextGlyph::
61GeomTextGlyph(const Geom &copy, const TextGlyph *glyph) :
62 Geom(copy)
63{
64 if (glyph != nullptr) {
65 _glyphs.reserve(1);
66 _glyphs.push_back(glyph);
67 }
68}
69
70/**
71 *
72 */
73void GeomTextGlyph::
74operator = (const GeomTextGlyph &copy) {
76 _glyphs = copy._glyphs;
77}
78
79/**
80 *
81 */
82GeomTextGlyph::
83~GeomTextGlyph() {
84}
85
86/**
87 * Returns a newly-allocated Geom that is a shallow copy of this one. It will
88 * be a different Geom pointer, but its internal data may or may not be shared
89 * with that of the original Geom.
90 */
92make_copy() const {
93 return new GeomTextGlyph(*this);
94}
95
96/**
97 * Copies the primitives from the indicated Geom into this one. This does
98 * require that both Geoms contain the same fundamental type primitives, both
99 * have a compatible shade model, and both use the same GeomVertexData. Both
100 * Geoms must also be the same specific class type (i.e. if one is a
101 * GeomTextGlyph, they both must be.)
102 *
103 * Returns true if the copy is successful, or false otherwise (because the
104 * Geoms were mismatched).
105 */
107copy_primitives_from(const Geom *other) {
108 if (!Geom::copy_primitives_from(other)) {
109 return false;
110 }
111
112 const GeomTextGlyph *tother;
113 DCAST_INTO_R(tother, other, false);
114
115 // Also copy the glyph pointers.
116 _glyphs.reserve(_glyphs.size() + tother->_glyphs.size());
117 _glyphs.insert(_glyphs.end(), tother->_glyphs.begin(), tother->_glyphs.end());
118
119 return true;
120}
121
122/**
123 * Records the reference count of the other Geom within this Geom, as if the
124 * primitives were copied in via copy_primitives_from() (but does not actually
125 * copy any primitives). This is particularly necessary for GeomTextGlyph's
126 * reference counting mechanism.
127 *
128 * Does nothing if the other Geom is not a GeomTextGlyph.
129 */
131count_geom(const Geom *other) {
132 if (other->is_of_type(GeomTextGlyph::get_class_type())) {
133 const GeomTextGlyph *tother;
134 DCAST_INTO_V(tother, other);
135
136 _glyphs.reserve(_glyphs.size() + tother->_glyphs.size());
137 _glyphs.insert(_glyphs.end(), tother->_glyphs.begin(), tother->_glyphs.end());
138 }
139}
140
141/**
142 *
143 */
144void GeomTextGlyph::
145output(std::ostream &out) const {
146 Geom::output(out);
147 out << ", glyphs: [";
148 Glyphs::const_iterator gi;
149 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
150 const TextGlyph *glyph = (*gi);
151 nassertv(glyph != nullptr);
152 out << " " << glyph->get_character();
153 }
154 out << " ]";
155}
156
157/**
158 *
159 */
160void GeomTextGlyph::
161write(std::ostream &out, int indent_level) const {
162 Geom::write(out, indent_level);
163 indent(out, indent_level)
164 << "Glyphs: [";
165 Glyphs::const_iterator gi;
166 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
167 const TextGlyph *glyph = (*gi);
168 nassertv(glyph != nullptr);
169 out << " " << glyph->get_character();
170 }
171 out << " ]\n";
172}
173
174/**
175 * Adds a glyph to the list of glyphs referenced by this Geom.
176 */
178add_glyph(const TextGlyph *glyph) {
179 _glyphs.push_back(glyph);
180}
181
182/**
183 * Factory method to generate a GeomTextGlyph object
184 */
189
190/**
191 * Factory method to generate a GeomTextGlyph object
192 */
194make_GeomTextGlyph(const FactoryParams &params) {
195 GeomTextGlyph *me = new GeomTextGlyph(nullptr,
196 nullptr);
197 DatagramIterator scan;
198 BamReader *manager;
199
200 parse_params(params, scan, manager);
201 me->fillin(scan, manager);
202 return me;
203}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition bamReader.I:275
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
A class to retrieve the individual data elements previously stored in a Datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition factory.I:73
This is a specialization on Geom for containing a primitive intended to represent a TextGlyph.
virtual Geom * make_copy() const
Returns a newly-allocated Geom that is a shallow copy of this one.
static void register_with_read_factory()
Factory method to generate a GeomTextGlyph object.
void add_glyph(const TextGlyph *glyph)
Adds a glyph to the list of glyphs referenced by this Geom.
virtual bool copy_primitives_from(const Geom *other)
Copies the primitives from the indicated Geom into this one.
static TypedWritable * make_GeomTextGlyph(const FactoryParams &params)
Factory method to generate a GeomTextGlyph object.
void count_geom(const Geom *other)
Records the reference count of the other Geom within this Geom, as if the primitives were copied in v...
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
Definition geom.h:54
virtual bool copy_primitives_from(const Geom *other)
Copies the primitives from the indicated Geom into this one.
Definition geom.cxx:954
void operator=(const Geom &copy)
The copy assignment operator is not pipeline-safe.
Definition geom.cxx:71
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
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition typedObject.I:28
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.