Panda3D

textFont.h

00001 // Filename: textFont.h
00002 // Created by:  drose (08Feb02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef TEXTFONT_H
00016 #define TEXTFONT_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "textGlyph.h"
00021 #include "typedReferenceCount.h"
00022 #include "namable.h"
00023 #include "pmap.h"
00024 #include "pointerTo.h"
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : TextFont
00028 // Description : An encapsulation of a font; i.e. a set of glyphs that
00029 //               may be assembled together by a TextNode to represent
00030 //               a string of text.
00031 //
00032 //               This is just an abstract interface; see
00033 //               StaticTextFont or DynamicTextFont for an actual
00034 //               implementation.
00035 ////////////////////////////////////////////////////////////////////
00036 class EXPCL_PANDA_TEXT TextFont : public TypedReferenceCount, public Namable {
00037 public:
00038   TextFont();
00039   TextFont(const TextFont &copy);
00040 
00041 PUBLISHED:
00042   virtual ~TextFont();
00043 
00044   enum RenderMode {
00045     // Each glyph is a single textured rectangle
00046     RM_texture,
00047 
00048     // Each glyph is a lot of line segments
00049     RM_wireframe,
00050 
00051     // Each glyph is a lot of triangles
00052     RM_polygon,
00053 
00054     // a 3-D outline, like a cookie cutter
00055     RM_extruded,
00056 
00057     // combination of RM_extruded and RM_polygon
00058     RM_solid,
00059 
00060     // Returned by string_render_mode() for an invalid match.
00061     RM_invalid,
00062   };
00063 
00064   enum WindingOrder {
00065     WO_default,
00066     WO_left,
00067     WO_right,
00068 
00069     WO_invalid,
00070   };
00071 
00072   virtual PT(TextFont) make_copy() const=0;
00073 
00074   INLINE bool is_valid() const;
00075   INLINE operator bool () const;
00076   INLINE PN_stdfloat get_line_height() const;
00077   INLINE void set_line_height(PN_stdfloat line_height);
00078 
00079   INLINE PN_stdfloat get_space_advance() const;
00080   INLINE void set_space_advance(PN_stdfloat space_advance);
00081 
00082   virtual void write(ostream &out, int indent_level) const;
00083 
00084 public:
00085   virtual bool get_glyph(int character, const TextGlyph *&glyph)=0;
00086   TextGlyph *get_invalid_glyph();
00087 
00088   static RenderMode string_render_mode(const string &string);
00089   static WindingOrder string_winding_order(const string &string);
00090 
00091 private:
00092   void make_invalid_glyph();
00093 
00094 protected:
00095   bool _is_valid;
00096   PN_stdfloat _line_height;
00097   PN_stdfloat _space_advance;
00098   PT(TextGlyph) _invalid_glyph;
00099 
00100 public:
00101   static TypeHandle get_class_type() {
00102     return _type_handle;
00103   }
00104   static void init_type() {
00105     TypedReferenceCount::init_type();
00106     register_type(_type_handle, "TextFont",
00107                   TypedReferenceCount::get_class_type());
00108   }
00109   virtual TypeHandle get_type() const {
00110     return get_class_type();
00111   }
00112   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00113 
00114 private:
00115   static TypeHandle _type_handle;
00116 };
00117 
00118 EXPCL_PANDA_TEXT ostream &operator << (ostream &out, TextFont::RenderMode rm);
00119 EXPCL_PANDA_TEXT istream &operator >> (istream &in, TextFont::RenderMode &rm);
00120 EXPCL_PANDA_TEXT ostream &operator << (ostream &out, TextFont::WindingOrder wo);
00121 EXPCL_PANDA_TEXT istream &operator >> (istream &in, TextFont::WindingOrder &wo);
00122 
00123 #include "textFont.I"
00124 
00125 #endif
 All Classes Functions Variables Enumerations