Panda3D
freetypeFont.h
1 // Filename: freetypeFont.h
2 // Created by: drose (07Sep03)
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 FREETYPEFONT_H
16 #define FREETYPEFONT_H
17 
18 #include "pandabase.h"
19 
20 #ifdef HAVE_FREETYPE
21 
22 #include "config_pnmtext.h"
23 #include "filename.h"
24 #include "pvector.h"
25 #include "pmap.h"
26 #include "pnmImage.h"
27 #include "namable.h"
28 #include "freetypeFace.h"
29 
30 #include <ft2build.h>
31 #include FT_FREETYPE_H
32 
33 ////////////////////////////////////////////////////////////////////
34 // Class : FreetypeFont
35 // Description : This is a common base class for both DynamicTextFont
36 // and PNMTextMaker. Both of these are utility classes
37 // that use the FreeType library to generate glyphs from
38 // fonts; this class abstracts out that common wrapper
39 // around FreeType.
40 ////////////////////////////////////////////////////////////////////
41 class EXPCL_PANDA_PNMTEXT FreetypeFont : public Namable {
42 protected:
43  FreetypeFont();
44  FreetypeFont(const FreetypeFont &copy);
45 
46  bool load_font(const Filename &font_filename, int face_index);
47  bool load_font(const char *font_data, int data_length, int face_index);
48  void unload_font();
49 
50 PUBLISHED:
51  INLINE ~FreetypeFont();
52 
53  INLINE bool set_point_size(PN_stdfloat point_size);
54  INLINE PN_stdfloat get_point_size() const;
55 
56  INLINE bool set_pixels_per_unit(PN_stdfloat pixels_per_unit);
57  INLINE PN_stdfloat get_pixels_per_unit() const;
58 
59  INLINE bool set_pixel_size(PN_stdfloat pixel_size);
60  INLINE PN_stdfloat get_pixel_size() const;
61 
62  INLINE bool set_scale_factor(PN_stdfloat scale_factor);
63  INLINE PN_stdfloat get_scale_factor() const;
64 
65  INLINE void set_native_antialias(bool native_antialias);
66  INLINE bool get_native_antialias() const;
67 
68  INLINE int get_font_pixel_size() const;
69 
70  INLINE PN_stdfloat get_line_height() const;
71  INLINE PN_stdfloat get_space_advance() const;
72 
73  INLINE static PN_stdfloat get_points_per_unit();
74  INLINE static PN_stdfloat get_points_per_inch();
75 
76 protected:
77  INLINE FT_Face acquire_face() const;
78  INLINE void release_face(FT_Face face) const;
79 
80  bool load_glyph(FT_Face face, int glyph_index, bool prerender = true);
81  void copy_bitmap_to_pnmimage(const FT_Bitmap &bitmap, PNMImage &image);
82 
83 private:
84  bool reset_scale();
85 
86 protected:
87  PN_stdfloat _point_size;
88  PN_stdfloat _requested_pixels_per_unit;
89  PN_stdfloat _tex_pixels_per_unit;
90  PN_stdfloat _requested_scale_factor;
91  PN_stdfloat _scale_factor;
92  bool _native_antialias;
93  PN_stdfloat _font_pixels_per_unit;
94 
95  int _font_pixel_size;
96  PN_stdfloat _line_height;
97  PN_stdfloat _space_advance;
98 
99  PT(FreetypeFace) _face;
100  int _char_size;
101  int _dpi;
102  int _pixel_width;
103  int _pixel_height;
104 
105 protected:
106  static const PN_stdfloat _points_per_unit;
107  static const PN_stdfloat _points_per_inch;
108 };
109 
110 #include "freetypeFont.I"
111 
112 #endif // HAVE_FREETYPE
113 
114 #endif
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:68
A base class for all things which can have a name.
Definition: namable.h:29
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44