Panda3D
pnmTextMaker.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 pnmTextMaker.h
10  * @author drose
11  * @date 2002-04-03
12  */
13 
14 #ifndef PNMTEXTMAKER_H
15 #define PNMTEXTMAKER_H
16 
17 #include "pandabase.h"
18 #include "pmap.h"
19 #include "freetypeFont.h"
20 #include "textEncoder.h"
21 
22 #include <ft2build.h>
23 #include FT_FREETYPE_H
24 
25 class Filename;
26 class PNMImage;
27 class PNMTextGlyph;
28 
29 /**
30  * This object uses the Freetype library to generate text directly into an
31  * image. It is different from the TextNode/DynamicTextFont interface, which
32  * use the Freetype library to generate text in the scene graph, to be
33  * rendered onscreen via the Panda render traversal.
34  */
35 class EXPCL_PANDA_PNMTEXT PNMTextMaker : public FreetypeFont {
36 PUBLISHED:
37  explicit PNMTextMaker(const Filename &font_filename, int face_index);
38  explicit PNMTextMaker(const char *font_data, int data_length, int face_index);
39  explicit PNMTextMaker(const FreetypeFont &copy);
40  PNMTextMaker(const PNMTextMaker &copy);
41  ~PNMTextMaker();
42 
43  enum Alignment {
44  A_left,
45  A_right,
46  A_center,
47  };
48 
49  INLINE bool is_valid() const;
50 
51  INLINE void set_align(Alignment align_type);
52  INLINE Alignment get_align() const;
53 
54  INLINE void set_interior_flag(bool interior_flag);
55  INLINE bool get_interior_flag() const;
56 
57  INLINE void set_fg(const LColor &fg);
58  INLINE const LColor &get_fg() const;
59 
60  INLINE void set_interior(const LColor &interior);
61  INLINE const LColor &get_interior() const;
62 
63  INLINE void set_distance_field_radius(int radius);
64  INLINE int get_distance_field_radius() const;
65 
66  INLINE int generate_into(const std::string &text,
67  PNMImage &dest_image, int x, int y);
68  int generate_into(const std::wstring &text,
69  PNMImage &dest_image, int x, int y);
70  INLINE int calc_width(const std::string &text);
71  int calc_width(const std::wstring &text);
72 
73  PNMTextGlyph *get_glyph(int character);
74 
75 private:
76  void initialize();
77  PNMTextGlyph *make_glyph(int glyph_index);
78  void empty_cache();
79 
80  bool _is_valid;
81 
83  Glyphs _glyphs;
84 
85  Alignment _align;
86  bool _interior_flag;
87  LColor _fg;
88  LColor _interior;
89  int _distance_field_radius;
90 };
91 
92 #include "pnmTextMaker.I"
93 
94 #endif
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap< int, PNMTextGlyph * >
PNMImage
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:58
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PNMTextMaker
This object uses the Freetype library to generate text directly into an image.
Definition: pnmTextMaker.h:35
PNMTextGlyph
A single glyph in a PNMTextMaker.
Definition: pnmTextGlyph.h:25
pnmTextMaker.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
textEncoder.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Filename
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
freetypeFont.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.