Panda3D
freetypeFace.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file freetypeFace.h
10  * @author gogg
11  * @date 2009-11-16
12  */
13 
14 #ifndef FREETYPEFACE_H
15 #define FREETYPEFACE_H
16 
17 #include "pandabase.h"
18 
19 #ifdef HAVE_FREETYPE
20 
21 #include "typedReferenceCount.h"
22 #include "namable.h"
23 #include "pmutex.h"
24 #include "mutexHolder.h"
25 
26 #include <ft2build.h>
27 #include FT_FREETYPE_H
28 
29 /**
30  * This is a reference-counted wrapper for the freetype font face object
31  * (FT_Face). It's used by the FreetypeFont class to store a face that can be
32  * shared between copied instances.
33  */
34 class EXPCL_PANDA_PNMTEXT FreetypeFace : public TypedReferenceCount, public Namable {
35 public:
36  FreetypeFace();
37  ~FreetypeFace();
38 
39  FT_Face acquire_face(int char_size, int dpi, int pixel_width, int pixel_height);
40  void release_face(FT_Face face);
41 
42  void set_face(FT_Face face);
43 
44 private:
45  static void initialize_ft_library();
46 
47 private:
48  // This is provided as a permanent storage for the raw font data, if needed.
49  std::string _font_data;
50 
51  std::string _name;
52  FT_Face _face;
53  int _char_size;
54  int _dpi;
55  int _pixel_width;
56  int _pixel_height;
57  Mutex _lock;
58 
59  static FT_Library _ft_library;
60  static bool _ft_initialized;
61  static bool _ft_ok;
62 
63 public:
64  static TypeHandle get_class_type() {
65  return _type_handle;
66  }
67  static void init_type() {
68  TypedReferenceCount::init_type();
69  register_type(_type_handle, "FreetypeFace",
70  TypedReferenceCount::get_class_type());
71  }
72  virtual TypeHandle get_type() const {
73  return get_class_type();
74  }
75  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
76 
77 private:
78  static TypeHandle _type_handle;
79 
80  friend class FreetypeFont;
81 };
82 
83 
84 #include "freetypeFace.I"
85 
86 #endif // HAVE_FREETYPE
87 
88 #endif
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:38
A base class for all things which can have a name.
Definition: namable.h:26
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.