Panda3D

freetypeFont.h

00001 // Filename: freetypeFont.h
00002 // Created by:  drose (07Sep03)
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 FREETYPEFONT_H
00016 #define FREETYPEFONT_H
00017 
00018 #include "pandabase.h"
00019 
00020 #ifdef HAVE_FREETYPE
00021 
00022 #include "config_pnmtext.h"
00023 #include "filename.h"
00024 #include "pvector.h"
00025 #include "pmap.h"
00026 #include "pnmImage.h"
00027 #include "namable.h"
00028 #include "freetypeFace.h"
00029 
00030 #include <ft2build.h>
00031 #include FT_FREETYPE_H
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //       Class : FreetypeFont
00035 // Description : This is a common base class for both DynamicTextFont
00036 //               and PNMTextMaker.  Both of these are utility classes
00037 //               that use the FreeType library to generate glyphs from
00038 //               fonts; this class abstracts out that common wrapper
00039 //               around FreeType.
00040 ////////////////////////////////////////////////////////////////////
00041 class EXPCL_PANDA_PNMTEXT FreetypeFont : public Namable {
00042 protected:
00043   FreetypeFont();
00044   FreetypeFont(const FreetypeFont &copy);
00045 
00046   bool load_font(const Filename &font_filename, int face_index);
00047   bool load_font(const char *font_data, int data_length, int face_index);
00048   void unload_font();
00049 
00050 PUBLISHED:
00051   INLINE ~FreetypeFont();
00052 
00053   INLINE bool set_point_size(PN_stdfloat point_size);
00054   INLINE PN_stdfloat get_point_size() const;
00055 
00056   INLINE bool set_pixels_per_unit(PN_stdfloat pixels_per_unit);
00057   INLINE PN_stdfloat get_pixels_per_unit() const;
00058 
00059   INLINE bool set_pixel_size(PN_stdfloat pixel_size);
00060   INLINE PN_stdfloat get_pixel_size() const;
00061 
00062   INLINE bool set_scale_factor(PN_stdfloat scale_factor);
00063   INLINE PN_stdfloat get_scale_factor() const;
00064 
00065   INLINE void set_native_antialias(bool native_antialias);
00066   INLINE bool get_native_antialias() const;
00067 
00068   INLINE int get_font_pixel_size() const;
00069 
00070   INLINE PN_stdfloat get_line_height() const;
00071   INLINE PN_stdfloat get_space_advance() const;
00072 
00073   INLINE static PN_stdfloat get_points_per_unit();
00074   INLINE static PN_stdfloat get_points_per_inch();
00075 
00076 protected:
00077   INLINE FT_Face acquire_face() const;
00078   INLINE void release_face(FT_Face face) const;
00079 
00080   bool load_glyph(FT_Face face, int glyph_index, bool prerender = true);
00081   void copy_bitmap_to_pnmimage(const FT_Bitmap &bitmap, PNMImage &image);
00082 
00083 private:
00084   bool reset_scale();
00085 
00086 protected:
00087   PN_stdfloat _point_size;
00088   PN_stdfloat _requested_pixels_per_unit;
00089   PN_stdfloat _tex_pixels_per_unit;
00090   PN_stdfloat _requested_scale_factor;
00091   PN_stdfloat _scale_factor;
00092   bool _native_antialias;
00093   PN_stdfloat _font_pixels_per_unit;
00094 
00095   int _font_pixel_size;
00096   PN_stdfloat _line_height;
00097   PN_stdfloat _space_advance;
00098 
00099   PT(FreetypeFace) _face;
00100   int _char_size;
00101   int _dpi;
00102   int _pixel_width;
00103   int _pixel_height;
00104 
00105 protected:
00106   static const PN_stdfloat _points_per_unit;
00107   static const PN_stdfloat _points_per_inch;
00108 };
00109 
00110 #include "freetypeFont.I"
00111 
00112 #endif  // HAVE_FREETYPE
00113 
00114 #endif
 All Classes Functions Variables Enumerations