00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "geomTextGlyph.h"
00016
00017 #ifdef HAVE_FREETYPE
00018
00019 #include "datagramIterator.h"
00020 #include "bamReader.h"
00021 #include "indent.h"
00022
00023 TypeHandle GeomTextGlyph::_type_handle;
00024
00025
00026
00027
00028
00029
00030
00031 GeomTextGlyph::
00032 GeomTextGlyph(DynamicTextGlyph *glyph, const GeomVertexData *data) :
00033 Geom(data)
00034 {
00035
00036
00037
00038 if (glyph != (DynamicTextGlyph *)NULL) {
00039 _glyphs.reserve(1);
00040 _glyphs.push_back(glyph);
00041 glyph->_geom_count++;
00042 }
00043 }
00044
00045
00046
00047
00048
00049
00050 GeomTextGlyph::
00051 GeomTextGlyph(const GeomVertexData *data) :
00052 Geom(data)
00053 {
00054
00055 }
00056
00057
00058
00059
00060
00061
00062 GeomTextGlyph::
00063 GeomTextGlyph(const GeomTextGlyph ©) :
00064 Geom(copy),
00065 _glyphs(copy._glyphs)
00066 {
00067 Glyphs::iterator gi;
00068 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
00069 DynamicTextGlyph *glyph = (*gi);
00070 nassertv(glyph != (DynamicTextGlyph *)NULL);
00071 glyph->_geom_count++;
00072 }
00073 }
00074
00075
00076
00077
00078
00079
00080 void GeomTextGlyph::
00081 operator = (const GeomTextGlyph ©) {
00082 Geom::operator = (copy);
00083
00084 Glyphs::iterator gi;
00085 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
00086 DynamicTextGlyph *glyph = (*gi);
00087 nassertv(glyph != (DynamicTextGlyph *)NULL);
00088 glyph->_geom_count--;
00089 nassertv((*gi)->_geom_count >= 0);
00090 }
00091 _glyphs = copy._glyphs;
00092 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
00093 DynamicTextGlyph *glyph = (*gi);
00094 nassertv(glyph != (DynamicTextGlyph *)NULL);
00095 glyph->_geom_count++;
00096 }
00097 }
00098
00099
00100
00101
00102
00103
00104 GeomTextGlyph::
00105 ~GeomTextGlyph() {
00106 Glyphs::iterator gi;
00107 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
00108 DynamicTextGlyph *glyph = (*gi);
00109 nassertv(glyph != (DynamicTextGlyph *)NULL);
00110 glyph->_geom_count--;
00111 nassertv(glyph->_geom_count >= 0);
00112 }
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 Geom *GeomTextGlyph::
00124 make_copy() const {
00125 return new GeomTextGlyph(*this);
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 bool GeomTextGlyph::
00143 copy_primitives_from(const Geom *other) {
00144 if (!Geom::copy_primitives_from(other)) {
00145 return false;
00146 }
00147
00148 const GeomTextGlyph *tother;
00149 DCAST_INTO_R(tother, other, false);
00150
00151
00152 Glyphs::const_iterator gi;
00153 for (gi = tother->_glyphs.begin(); gi != tother->_glyphs.end(); ++gi) {
00154 _glyphs.push_back(*gi);
00155 (*gi)->_geom_count++;
00156 }
00157
00158 return true;
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 void GeomTextGlyph::
00174 count_geom(const Geom *other) {
00175 if (other->is_of_type(GeomTextGlyph::get_class_type())) {
00176 const GeomTextGlyph *tother;
00177 DCAST_INTO_V(tother, other);
00178
00179 Glyphs::const_iterator gi;
00180 for (gi = tother->_glyphs.begin(); gi != tother->_glyphs.end(); ++gi) {
00181 _glyphs.push_back(*gi);
00182 (*gi)->_geom_count++;
00183 }
00184 }
00185 }
00186
00187
00188
00189
00190
00191
00192 void GeomTextGlyph::
00193 output(ostream &out) const {
00194 Geom::output(out);
00195 out << ", glyphs: [";
00196 Glyphs::const_iterator gi;
00197 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
00198 DynamicTextGlyph *glyph = (*gi);
00199 nassertv(glyph != (DynamicTextGlyph *)NULL);
00200 out << " " << glyph->get_character();
00201 }
00202 out << " ]";
00203 }
00204
00205
00206
00207
00208
00209
00210 void GeomTextGlyph::
00211 write(ostream &out, int indent_level) const {
00212 Geom::write(out, indent_level);
00213 indent(out, indent_level)
00214 << "Glyphs: [";
00215 Glyphs::const_iterator gi;
00216 for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
00217 DynamicTextGlyph *glyph = (*gi);
00218 nassertv(glyph != (DynamicTextGlyph *)NULL);
00219 out << " " << glyph->get_character();
00220 }
00221 out << " ]\n";
00222 }
00223
00224
00225
00226
00227
00228
00229 void GeomTextGlyph::
00230 register_with_read_factory() {
00231 BamReader::get_factory()->register_factory(get_class_type(), make_GeomTextGlyph);
00232 }
00233
00234
00235
00236
00237
00238
00239 TypedWritable* GeomTextGlyph::
00240 make_GeomTextGlyph(const FactoryParams ¶ms) {
00241 GeomTextGlyph *me = new GeomTextGlyph((DynamicTextGlyph *)NULL,
00242 (GeomVertexData *)NULL);
00243 DatagramIterator scan;
00244 BamReader *manager;
00245
00246 parse_params(params, scan, manager);
00247 me->fillin(scan, manager);
00248 return me;
00249 }
00250
00251 #endif // HAVE_FREETYPE