Panda3D
 All Classes Functions Variables Enumerations
freetypeFace.h
1 // Filename: freetypeFont.h
2 // Created by: gogg (16Nov09)
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 FREETYPEFACE_H
16 #define FREETYPEFACE_H
17 
18 #include "pandabase.h"
19 
20 #ifdef HAVE_FREETYPE
21 
22 #include "typedReferenceCount.h"
23 #include "namable.h"
24 #include "pmutex.h"
25 #include "mutexHolder.h"
26 
27 #include <ft2build.h>
28 #include FT_FREETYPE_H
29 
30 ////////////////////////////////////////////////////////////////////
31 // Class : FreetypeFont
32 // Description : This is a reference-counted wrapper for the
33 // freetype font face object (FT_Face).
34 // It's used by the FreetypeFont class to store a face
35 // that can be shared between copied instances.
36 ////////////////////////////////////////////////////////////////////
37 class EXPCL_PANDA_PNMTEXT FreetypeFace : public TypedReferenceCount, public Namable {
38 public:
39  FreetypeFace();
40  ~FreetypeFace();
41 
42  FT_Face acquire_face(int char_size, int dpi, int pixel_width, int pixel_height);
43  void release_face(FT_Face face);
44 
45  void set_face(FT_Face face);
46 
47 private:
48  static void initialize_ft_library();
49 
50 private:
51  // This is provided as a permanent storage for the raw font data, if
52  // needed.
53  string _font_data;
54 
55  string _name;
56  FT_Face _face;
57  int _char_size;
58  int _dpi;
59  int _pixel_width;
60  int _pixel_height;
61  Mutex _lock;
62 
63  static FT_Library _ft_library;
64  static bool _ft_initialized;
65  static bool _ft_ok;
66 
67 public:
68  static TypeHandle get_class_type() {
69  return _type_handle;
70  }
71  static void init_type() {
72  TypedReferenceCount::init_type();
73  register_type(_type_handle, "FreetypeFace",
74  TypedReferenceCount::get_class_type());
75  }
76  virtual TypeHandle get_type() const {
77  return get_class_type();
78  }
79  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
80 
81 private:
82  static TypeHandle _type_handle;
83 
84  friend class FreetypeFont;
85 };
86 
87 
88 #include "freetypeFace.I"
89 
90 #endif // HAVE_FREETYPE
91 
92 #endif
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
A standard mutex, or mutual exclusion lock.
Definition: pmutex.h:44
A base class for all things which can have a name.
Definition: namable.h:29
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85