Panda3D
 All Classes Functions Variables Enumerations
pnmTextMaker.h
1 // Filename: pnmTextMaker.h
2 // Created by: drose (03Apr02)
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 PNMTEXTMAKER_H
16 #define PNMTEXTMAKER_H
17 
18 #include "pandabase.h"
19 #include "pmap.h"
20 #include "freetypeFont.h"
21 #include "textEncoder.h"
22 
23 #include <ft2build.h>
24 #include FT_FREETYPE_H
25 
26 class Filename;
27 class PNMImage;
28 class PNMTextGlyph;
29 
30 ////////////////////////////////////////////////////////////////////
31 // Class : PNMTextMaker
32 // Description : This object uses the Freetype library to generate
33 // text directly into an image. It is different from
34 // the TextNode/DynamicTextFont interface, which use the
35 // Freetype library to generate text in the scene graph,
36 // to be rendered onscreen via the Panda render
37 // traversal.
38 ////////////////////////////////////////////////////////////////////
39 class EXPCL_PANDA_PNMTEXT PNMTextMaker : public FreetypeFont {
40 PUBLISHED:
41  PNMTextMaker(const Filename &font_filename, int face_index);
42  PNMTextMaker(const char *font_data, int data_length, int face_index);
43  PNMTextMaker(const PNMTextMaker &copy);
44  PNMTextMaker(const FreetypeFont &copy);
45  ~PNMTextMaker();
46 
47  enum Alignment {
48  A_left,
49  A_right,
50  A_center,
51  };
52 
53  INLINE bool is_valid() const;
54 
55  INLINE void set_align(Alignment align_type);
56  INLINE Alignment get_align() const;
57 
58  INLINE void set_interior_flag(bool interior_flag);
59  INLINE bool get_interior_flag() const;
60 
61  INLINE void set_fg(const LColor &fg);
62  INLINE const LColor &get_fg() const;
63 
64  INLINE void set_interior(const LColor &interior);
65  INLINE const LColor &get_interior() const;
66 
67  INLINE int generate_into(const string &text,
68  PNMImage &dest_image, int x, int y);
69  int generate_into(const wstring &text,
70  PNMImage &dest_image, int x, int y);
71  INLINE int calc_width(const string &text);
72  int calc_width(const wstring &text);
73 
74  PNMTextGlyph *get_glyph(int character);
75 
76 private:
77  void initialize();
78  PNMTextGlyph *make_glyph(int glyph_index);
79  void empty_cache();
80 
81  bool _is_valid;
82 
84  Glyphs _glyphs;
85 
86  Alignment _align;
87  bool _interior_flag;
88  LColor _fg;
89  LColor _interior;
90 };
91 
92 #include "pnmTextMaker.I"
93 
94 #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
This object uses the Freetype library to generate text directly into an image.
Definition: pnmTextMaker.h:39
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
A single glyph in a PNMTextMaker.
Definition: pnmTextGlyph.h:27