Panda3D
pnmTextMaker.I
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.I
10  * @author drose
11  * @date 2003-09-07
12  */
13 
14 /**
15  * Returns true if the PNMTextMaker is valid and ready to generate text, false
16  * otherwise.
17  */
18 INLINE bool PNMTextMaker::
19 is_valid() const {
20  return _is_valid;
21 }
22 
23 /**
24  *
25  */
26 INLINE void PNMTextMaker::
27 set_align(PNMTextMaker::Alignment align_type) {
28  _align = align_type;
29 }
30 
31 /**
32  *
33  */
34 INLINE PNMTextMaker::Alignment PNMTextMaker::
35 get_align() const {
36  return _align;
37 }
38 
39 /**
40  * Sets the flag that indicates whether the interior of hollow fonts is
41  * identified as a preprocess as each glyph is loaded. If this flag is true,
42  * you may specify an interior color along with a fg and bg color when you
43  * place text; if the flag is false, the interior color is ignored.
44  *
45  * It is generally best to set_native_antialias(0) when using this feature.
46  * Also, this works best when the pixel size is not very small.
47  */
48 INLINE void PNMTextMaker::
49 set_interior_flag(bool interior_flag) {
50  if (_interior_flag != interior_flag) {
51  _interior_flag = interior_flag;
52  empty_cache();
53  }
54 }
55 
56 /**
57  *
58  */
59 INLINE bool PNMTextMaker::
60 get_interior_flag() const {
61  return _interior_flag;
62 }
63 
64 /**
65  * Sets the foreground color of text that will be generated by future calls to
66  * generate_into(). This is the color that all of the "on" pixels in the font
67  * will show as.
68  */
69 INLINE void PNMTextMaker::
70 set_fg(const LColor &fg) {
71  _fg = fg;
72 }
73 
74 /**
75  * Returns the foreground color of text that will be generated by future calls
76  * to generate_into().
77  */
78 INLINE const LColor &PNMTextMaker::
79 get_fg() const {
80  return _fg;
81 }
82 
83 /**
84  * Sets the color that will be used to render the interior portions of hollow
85  * fonts in future calls to generate_into(). This is respected only if
86  * interior_flag is true.
87  */
88 INLINE void PNMTextMaker::
89 set_interior(const LColor &interior) {
90  _interior = interior;
91 }
92 
93 /**
94  * Returns the color that will be used to render the interior portions of
95  * hollow fonts.
96  */
97 INLINE const LColor &PNMTextMaker::
98 get_interior() const {
99  return _interior;
100 }
101 
102 /**
103  * If this is set to something other than 0, Panda will generate a signed
104  * distance field with the given radius.
105  */
106 INLINE void PNMTextMaker::
107 set_distance_field_radius(int distance_field_radius) {
108  _distance_field_radius = distance_field_radius;
109 }
110 
111 /**
112  * Returns the radius previously set with set_distance_field_radius, or 0
113  * otherwise.
114  */
115 INLINE int PNMTextMaker::
117  return _distance_field_radius;
118 }
119 
120 /**
121  * Generates a single line of text into the indicated image at the indicated
122  * position; the return value is the total width in pixels.
123  */
124 INLINE int PNMTextMaker::
125 generate_into(const std::string &text, PNMImage &dest_image, int x, int y) {
126  TextEncoder encoder;
127  encoder.set_text(text);
128  return generate_into(encoder.get_wtext(), dest_image, x, y);
129 }
130 
131 /**
132  * Returns the width in pixels of the indicated line of text.
133  */
134 INLINE int PNMTextMaker::
135 calc_width(const std::string &text) {
136  TextEncoder encoder;
137  encoder.set_text(text);
138  return calc_width(encoder.get_wtext());
139 }
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
This class can be used to convert text between multiple representations, e.g.
Definition: textEncoder.h:33
const LColor & get_fg() const
Returns the foreground color of text that will be generated by future calls to generate_into().
Definition: pnmTextMaker.I:79
int generate_into(const std::string &text, PNMImage &dest_image, int x, int y)
Generates a single line of text into the indicated image at the indicated position; the return value ...
Definition: pnmTextMaker.I:125
set_text
Changes the text that is stored in the encoder.
Definition: textEncoder.h:124
void set_distance_field_radius(int radius)
If this is set to something other than 0, Panda will generate a signed distance field with the given ...
Definition: pnmTextMaker.I:107
void set_interior(const LColor &interior)
Sets the color that will be used to render the interior portions of hollow fonts in future calls to g...
Definition: pnmTextMaker.I:89
int get_distance_field_radius() const
Returns the radius previously set with set_distance_field_radius, or 0 otherwise.
Definition: pnmTextMaker.I:116
void set_interior_flag(bool interior_flag)
Sets the flag that indicates whether the interior of hollow fonts is identified as a preprocess as ea...
Definition: pnmTextMaker.I:49
int calc_width(const std::string &text)
Returns the width in pixels of the indicated line of text.
Definition: pnmTextMaker.I:135
bool is_valid() const
Returns true if the PNMTextMaker is valid and ready to generate text, false otherwise.
Definition: pnmTextMaker.I:19
void set_fg(const LColor &fg)
Sets the foreground color of text that will be generated by future calls to generate_into().
Definition: pnmTextMaker.I:70
const std::wstring & get_wtext() const
Returns the text associated with the TextEncoder, as a wide-character string.
Definition: textEncoder.I:456
const LColor & get_interior() const
Returns the color that will be used to render the interior portions of hollow fonts.
Definition: pnmTextMaker.I:98