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