Panda3D

textFont.h
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 textFont.h
10 * @author drose
11 * @date 2002-02-08
12 */
13
14 #ifndef TEXTFONT_H
15 #define TEXTFONT_H
16
17 #include "pandabase.h"
18
19 #include "textGlyph.h"
20 #include "typedReferenceCount.h"
21 #include "namable.h"
22 #include "pmap.h"
23 #include "pointerTo.h"
24
25 /**
26 * An encapsulation of a font; i.e. a set of glyphs that may be assembled
27 * together by a TextNode to represent a string of text.
28 *
29 * This is just an abstract interface; see StaticTextFont or DynamicTextFont
30 * for an actual implementation.
31 */
32 class EXPCL_PANDA_TEXT TextFont : public TypedReferenceCount, public Namable {
33 public:
34 TextFont();
35 TextFont(const TextFont &copy);
36
37 PUBLISHED:
38 virtual ~TextFont();
39
40 enum RenderMode {
41 // Each glyph is a single textured rectangle
42 RM_texture,
43
44 // Each glyph is a lot of line segments
45 RM_wireframe,
46
47 // Each glyph is a lot of triangles
48 RM_polygon,
49
50 // a 3-D outline, like a cookie cutter
51 RM_extruded,
52
53 // combination of RM_extruded and RM_polygon
54 RM_solid,
55
56 RM_distance_field,
57
58 // Returned by string_render_mode() for an invalid match.
59 RM_invalid,
60 };
61
62 virtual PT(TextFont) make_copy() const=0;
63
64 INLINE bool is_valid() const;
65 INLINE operator bool () const;
66 INLINE PN_stdfloat get_line_height() const;
67 INLINE void set_line_height(PN_stdfloat line_height);
68 MAKE_PROPERTY(valid, is_valid);
69 MAKE_PROPERTY(line_height, get_line_height, set_line_height);
70
71 INLINE PN_stdfloat get_space_advance() const;
72 INLINE void set_space_advance(PN_stdfloat space_advance);
73 MAKE_PROPERTY(space_advance, get_space_advance, set_space_advance);
74
75 INLINE CPT(TextGlyph) get_glyph(int character);
76
77 virtual PN_stdfloat get_kerning(int first, int second) const;
78
79 virtual void write(std::ostream &out, int indent_level) const;
80
81 public:
82 INLINE PN_stdfloat get_total_poly_margin() const;
83
84 virtual bool get_glyph(int character, CPT(TextGlyph) &glyph)=0;
85 TextGlyph *get_invalid_glyph();
86
87 static RenderMode string_render_mode(const std::string &string);
88
89 private:
90 void make_invalid_glyph();
91
92 protected:
93 bool _is_valid;
94 PN_stdfloat _line_height;
95 PN_stdfloat _space_advance;
96 PN_stdfloat _total_poly_margin;
97 PT(TextGlyph) _invalid_glyph;
98
99 public:
100 static TypeHandle get_class_type() {
101 return _type_handle;
102 }
103 static void init_type() {
104 TypedReferenceCount::init_type();
105 register_type(_type_handle, "TextFont",
106 TypedReferenceCount::get_class_type());
107 }
108 virtual TypeHandle get_type() const {
109 return get_class_type();
110 }
111 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
112
113 private:
114 static TypeHandle _type_handle;
115 };
116
117 EXPCL_PANDA_TEXT std::ostream &operator << (std::ostream &out, TextFont::RenderMode rm);
118 EXPCL_PANDA_TEXT std::istream &operator >> (std::istream &in, TextFont::RenderMode &rm);
119
120 #include "textFont.I"
121
122 #endif
Namable
A base class for all things which can have a name.
Definition: namable.h:26
TextFont
An encapsulation of a font; i.e.
Definition: textFont.h:32
TextGlyph
A representation of a single glyph (character) from a font.
Definition: textGlyph.h:28
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypedReferenceCount
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
Definition: typedReferenceCount.h:31
namable.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
textFont.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
textGlyph.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
typedReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.