Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/text/dynamicTextFont.h

Go to the documentation of this file.
00001 // Filename: dynamicTextFont.h
00002 // Created by:  drose (08Feb02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef DYNAMICTEXTFONT_H
00020 #define DYNAMICTEXTFONT_H
00021 
00022 #include "pandabase.h"
00023 
00024 #ifdef HAVE_FREETYPE
00025 
00026 #include "config_text.h"
00027 #include "textFont.h"
00028 #include "dynamicTextGlyph.h"
00029 #include "dynamicTextPage.h"
00030 #include "filename.h"
00031 #include "pvector.h"
00032 #include "pmap.h"
00033 
00034 #include <ft2build.h>
00035 #include FT_FREETYPE_H
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //       Class : DynamicTextFont
00039 // Description : A DynamicTextFont is a special TextFont object that
00040 //               rasterizes its glyphs from a standard font file
00041 //               (e.g. a TTF file) on the fly.  It requires the
00042 //               FreeType 2.0 library (or any higher,
00043 //               backward-compatible version).
00044 ////////////////////////////////////////////////////////////////////
00045 class EXPCL_PANDA DynamicTextFont : public TextFont {
00046 PUBLISHED:
00047   DynamicTextFont(const Filename &font_filename, int face_index = 0);
00048   DynamicTextFont(const char *font_data, int data_length, int face_index);
00049   virtual ~DynamicTextFont();
00050 
00051   INLINE bool set_point_size(float point_size);
00052   INLINE float get_point_size() const;
00053 
00054   INLINE bool set_pixels_per_unit(float pixels_per_unit);
00055   INLINE float get_pixels_per_unit() const;
00056 
00057   INLINE bool set_scale_factor(float scale_factor);
00058   INLINE float get_scale_factor() const;
00059 
00060   INLINE void set_texture_margin(int texture_margin);
00061   INLINE int get_texture_margin() const;
00062   INLINE void set_poly_margin(float poly_margin);
00063   INLINE float get_poly_margin() const;
00064 
00065   INLINE void set_page_size(int x_size, int y_size);
00066   INLINE int get_page_x_size() const;
00067   INLINE int get_page_y_size() const;
00068 
00069   INLINE void set_minfilter(Texture::FilterType filter);
00070   INLINE Texture::FilterType get_minfilter() const;
00071   INLINE void set_magfilter(Texture::FilterType filter);
00072   INLINE Texture::FilterType get_magfilter() const;
00073   INLINE void set_anisotropic_degree(int anisotropic_degree);
00074   INLINE int get_anisotropic_degree() const;
00075 
00076   INLINE static void set_update_cleared_glyphs(bool update_cleared_glyphs);
00077   INLINE static bool get_update_cleared_glyphs();
00078 
00079   int get_num_pages() const;
00080   DynamicTextPage *get_page(int n) const;
00081 
00082   int garbage_collect();
00083   void update_texture_memory();
00084   void clear();
00085 
00086   virtual void write(ostream &out, int indent_level) const;
00087 
00088 public:
00089   virtual bool get_glyph(int character, const TextGlyph *&glyph);
00090 
00091 private:
00092   void initialize();
00093   void update_filters();
00094   bool reset_scale();
00095   DynamicTextGlyph *make_glyph(int glyph_index);
00096   void copy_bitmap_to_texture(const FT_Bitmap &bitmap, DynamicTextGlyph *glyph);
00097   void copy_bitmap_to_pnmimage(const FT_Bitmap &bitmap, PNMImage &image);
00098   void copy_pnmimage_to_texture(const PNMImage &image, DynamicTextGlyph *glyph);
00099   DynamicTextGlyph *slot_glyph(int x_size, int y_size);
00100 
00101   static void initialize_ft_library();
00102 
00103   float _point_size;
00104   float _tex_pixels_per_unit;
00105   float _scale_factor;
00106   float _font_pixels_per_unit;
00107   int _texture_margin;
00108   float _poly_margin;
00109   int _page_x_size, _page_y_size;
00110   static bool _update_cleared_glyphs;
00111 
00112   Texture::FilterType _minfilter;
00113   Texture::FilterType _magfilter;
00114   int _anisotropic_degree;
00115 
00116   typedef pvector< PT(DynamicTextPage) > Pages;
00117   Pages _pages;
00118   int _preferred_page;
00119 
00120   // This doesn't need to be a reference-counting pointer, because the
00121   // reference to each glyph is kept by the DynamicTextPage object.
00122   typedef pmap<int, DynamicTextGlyph *> Cache;
00123   Cache _cache;
00124 
00125   // This is a list of the glyphs that do not have any printable
00126   // properties (e.g. space), but still have an advance measure.  We
00127   // store them here to keep their reference counts; they also appear
00128   // in the above table.
00129   typedef pvector< PT(DynamicTextGlyph) > EmptyGlyphs;
00130   EmptyGlyphs _empty_glyphs;
00131 
00132   FT_Face _face;
00133 
00134   // This string is used to hold the data read from the font file in
00135   // vfs mode.  Since the FreeType library keeps pointers into this
00136   // data, we have to keep it around.
00137   string _raw_font_data;
00138 
00139   static FT_Library _ft_library;
00140   static bool _ft_initialized;
00141   static bool _ft_ok;
00142 
00143 public:
00144   static TypeHandle get_class_type() {
00145     return _type_handle;
00146   }
00147   static void init_type() {
00148     TextFont::init_type();
00149     register_type(_type_handle, "DynamicTextFont",
00150                   TextFont::get_class_type());
00151   }
00152   virtual TypeHandle get_type() const {
00153     return get_class_type();
00154   }
00155   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00156 
00157 private:
00158   static TypeHandle _type_handle;
00159 
00160   friend class TextNode;
00161 };
00162 
00163 #include "dynamicTextFont.I"
00164 
00165 #endif  // HAVE_FREETYPE
00166 
00167 #endif

Generated on Fri May 2 00:44:15 2003 for Panda by doxygen1.3