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