Panda3D
dynamicTextFont.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 dynamicTextFont.I
10  * @author drose
11  * @date 2002-02-08
12  */
13 
14 /**
15  * Disambiguates the get_name() method between that inherited from TextFont
16  * and that inherited from FreetypeFont.
17  */
18 INLINE const std::string &DynamicTextFont::
19 get_name() const {
20  return TextFont::get_name();
21 }
22 
23 /**
24  * Sets the point size of the font. This controls the apparent size of the
25  * font onscreen. By convention, a 10 point font is about 1 screen unit high.
26  *
27  * This should only be called before any characters have been requested out of
28  * the font, or immediately after calling clear().
29  */
30 INLINE bool DynamicTextFont::
31 set_point_size(PN_stdfloat point_size) {
32  // If this assertion fails, you didn't call clear() first. RTFM.
33  nassertr(get_num_pages() == 0, false);
34 
35  return FreetypeFont::set_point_size(point_size);
36 }
37 
38 /**
39  * Returns the point size of the font.
40  */
41 INLINE PN_stdfloat DynamicTextFont::
42 get_point_size() const {
43  return FreetypeFont::get_point_size();
44 }
45 
46 /**
47  * Set the resolution of the texture map, and hence the clarity of the
48  * resulting font. This sets the number of pixels in the texture map that are
49  * used for each onscreen unit.
50  *
51  * Setting this number larger results in an easier to read font, but at the
52  * cost of more texture memory.
53  *
54  * This should only be called before any characters have been requested out of
55  * the font, or immediately after calling clear().
56  */
57 INLINE bool DynamicTextFont::
58 set_pixels_per_unit(PN_stdfloat pixels_per_unit) {
59  // If this assertion fails, you didn't call clear() first. RTFM.
60  nassertr(get_num_pages() == 0, false);
61 
62  return FreetypeFont::set_pixels_per_unit(pixels_per_unit);
63 }
64 
65 /**
66  * Returns the resolution of the texture map. See set_pixels_per_unit().
67  */
68 INLINE PN_stdfloat DynamicTextFont::
69 get_pixels_per_unit() const {
70  return FreetypeFont::get_pixels_per_unit();
71 }
72 
73 /**
74  * Sets the factor by which the font is rendered larger by the FreeType
75  * library before being filtered down to its actual size in the texture as
76  * specified by set_pixels_per_unit(). This may be set to a number larger
77  * than 1.0 to improve the font's antialiasing (since FreeType doesn't really
78  * do a swell job of antialiasing by itself). There is some performance
79  * implication for setting this different than 1.0, but it is probably small.
80  *
81  * This should only be called before any characters have been requested out of
82  * the font, or immediately after calling clear().
83  */
84 INLINE bool DynamicTextFont::
85 set_scale_factor(PN_stdfloat scale_factor) {
86  // If this assertion fails, you didn't call clear() first. RTFM.
87  nassertr(get_num_pages() == 0, false);
88 
89  return FreetypeFont::set_scale_factor(scale_factor);
90 }
91 
92 /**
93  * Returns the antialiasing scale factor. See set_scale_factor().
94  */
95 INLINE PN_stdfloat DynamicTextFont::
96 get_scale_factor() const {
97  return FreetypeFont::get_scale_factor();
98 }
99 
100 /**
101  * Sets whether the Freetype library's built-in antialias mode is enabled.
102  * There are two unrelated ways to achieve antialiasing: with Freetype's
103  * native antialias mode, and with the use of a scale_factor greater than one.
104  * By default, both modes are enabled.
105  *
106  * At low resolutions, some fonts may do better with one mode or the other.
107  * In general, Freetype's native antialiasing will produce less blurry
108  * results, but may introduce more artifacts.
109  */
110 INLINE void DynamicTextFont::
111 set_native_antialias(bool native_antialias) {
112  // If this assertion fails, you didn't call clear() first. RTFM.
113  nassertv(get_num_pages() == 0);
114 
115  FreetypeFont::set_native_antialias(native_antialias);
116 }
117 
118 /**
119  * Returns whether Freetype's built-in antialias mode is enabled. See
120  * set_native_antialias().
121  */
122 INLINE bool DynamicTextFont::
123 get_native_antialias() const {
124  return FreetypeFont::get_native_antialias();
125 }
126 
127 /**
128  * This is used to report whether the requested pixel size is being only
129  * approximated by a fixed-pixel-size font. This returns 0 in the normal
130  * case, in which a scalable font is used, or the fixed-pixel-size font has
131  * exactly the requested pixel size.
132  *
133  * If this returns non-zero, it is the pixel size of the font that we are
134  * using to approximate our desired size.
135  */
136 INLINE int DynamicTextFont::
137 get_font_pixel_size() const {
138  return FreetypeFont::get_font_pixel_size();
139 }
140 
141 /**
142  * Returns the number of units high each line of text is.
143  */
144 INLINE PN_stdfloat DynamicTextFont::
145 get_line_height() const {
146  return TextFont::get_line_height();
147 }
148 
149 /**
150  * Returns the number of units wide a space is.
151  */
152 INLINE PN_stdfloat DynamicTextFont::
153 get_space_advance() const {
155 }
156 
157 /**
158  * Sets the number of pixels of padding that is added around the border of
159  * each glyph before adding it to the texture map. This reduces the bleed in
160  * from neighboring glyphs in the texture map.
161  */
162 INLINE void DynamicTextFont::
163 set_texture_margin(int texture_margin) {
164  _texture_margin = texture_margin;
165 }
166 
167 /**
168  * Returns the number of pixels of padding that is added around the border of
169  * each glyph in the texture map. See set_texture_margin().
170  */
171 INLINE int DynamicTextFont::
172 get_texture_margin() const {
173  return _texture_margin;
174 }
175 
176 /**
177  * Sets the number of pixels of padding that is included around each glyph in
178  * the generated polygons. This helps prevent the edges of the glyphs from
179  * being cut off at small minifications. It is not related to the amount of
180  * extra pixels reserved in the texture map (but it should be set somewhat
181  * smaller than this number, which is controlled by set_texture_margin(), to
182  * prevent bleed-in from neighboring letters in the texture).
183  */
184 INLINE void DynamicTextFont::
185 set_poly_margin(PN_stdfloat poly_margin) {
186  _poly_margin = poly_margin;
187 }
188 
189 /**
190  * Returns the number of pixels of padding that is included around each glyph
191  * in the generated polygons. See set_poly_margin().
192  */
193 INLINE PN_stdfloat DynamicTextFont::
194 get_poly_margin() const {
195  return _poly_margin;
196 }
197 
198 /**
199  * Sets the x, y size of the textures that are created for the
200  * DynamicTextFont.
201  */
202 INLINE void DynamicTextFont::
203 set_page_size(const LVecBase2i &page_size) {
204  _page_size = page_size;
205 }
206 
207 /**
208  * Sets the x, y size of the textures that are created for the
209  * DynamicTextFont.
210  */
211 INLINE void DynamicTextFont::
212 set_page_size(int x_size, int y_size) {
213  _page_size.set(x_size, y_size);
214 }
215 
216 /**
217  * Returns the size of the textures that are created for the DynamicTextFont.
218  * See set_page_size().
219  */
220 INLINE const LVecBase2i &DynamicTextFont::
221 get_page_size() const {
222  return _page_size;
223 }
224 
225 /**
226  * Returns the x size of the textures that are created for the
227  * DynamicTextFont. See set_page_size().
228  */
229 INLINE int DynamicTextFont::
230 get_page_x_size() const {
231  return _page_size.get_x();
232 }
233 
234 /**
235  * Returns the y size of the textures that are created for the
236  * DynamicTextFont. See set_page_size().
237  */
238 INLINE int DynamicTextFont::
239 get_page_y_size() const {
240  return _page_size.get_y();
241 }
242 
243 /**
244  * Sets the filter type used when minimizing the textures created for this
245  * font.
246  */
247 INLINE void DynamicTextFont::
248 set_minfilter(SamplerState::FilterType filter) {
249  _minfilter = filter;
250  update_filters();
251 }
252 
253 /**
254  * Returns the filter type used when minimizing the textures created for this
255  * font.
256  */
257 INLINE SamplerState::FilterType DynamicTextFont::
258 get_minfilter() const {
259  return _minfilter;
260 }
261 
262 /**
263  * Sets the filter type used when enlarging the textures created for this
264  * font.
265  */
266 INLINE void DynamicTextFont::
267 set_magfilter(SamplerState::FilterType filter) {
268  _magfilter = filter;
269  update_filters();
270 }
271 
272 /**
273  * Returns the filter type used when enlarging the textures created for this
274  * font.
275  */
276 INLINE SamplerState::FilterType DynamicTextFont::
277 get_magfilter() const {
278  return _magfilter;
279 }
280 
281 /**
282  * Enables or disables anisotropic filtering on the textures created for this
283  * font. The default value is specified by the text-anisotropic-degree
284  * variable. See Texture::set_anisotropic_degree().
285  */
286 INLINE void DynamicTextFont::
287 set_anisotropic_degree(int anisotropic_degree) {
288  _anisotropic_degree = anisotropic_degree;
289  update_filters();
290 }
291 
292 /**
293  * Returns the current anisotropic degree for textures created for this font.
294  * See set_anisotropic_degree().
295  */
296 INLINE int DynamicTextFont::
297 get_anisotropic_degree() const {
298  return _anisotropic_degree;
299 }
300 
301 /**
302  * Specifies the way the glyphs on this particular font are generated. The
303  * default is RM_texture, which is the only mode supported for bitmap fonts.
304  * Other modes are possible for most modern fonts.
305  */
306 INLINE void DynamicTextFont::
307 set_render_mode(DynamicTextFont::RenderMode render_mode) {
308  _render_mode = render_mode;
309 }
310 
311 /**
312  * Returns the way the glyphs on this particular font are generated. See
313  * set_render_mode().
314  */
315 INLINE DynamicTextFont::RenderMode DynamicTextFont::
316 get_render_mode() const {
317  return _render_mode;
318 }
319 
320 /**
321  * Changes the color of the foreground pixels of the font as they are rendered
322  * into the font texture. The default is (1, 1, 1, 1), or opaque white, which
323  * allows text created with the font to be colored individually. Normally,
324  * you would not change this unless you really need a particular color effect
325  * to appear in the font itself.
326  *
327  * This should only be called before any characters have been requested out of
328  * the font, or immediately after calling clear().
329  */
330 INLINE void DynamicTextFont::
331 set_fg(const LColor &fg) {
332  // If this assertion fails, you didn't call clear() first. RTFM.
333  nassertv(get_num_pages() == 0);
334 
335  _fg = fg;
336  determine_tex_format();
337 }
338 
339 /**
340  * Returns the color of the foreground pixels of the font as they are rendered
341  * into the font texture. See set_fg().
342  */
343 INLINE const LColor &DynamicTextFont::
344 get_fg() const {
345  return _fg;
346 }
347 
348 /**
349  * Changes the color of the background pixels of the font as they are rendered
350  * into the font texture. The default is (1, 1, 1, 0), or transparent white,
351  * which allows text created with the font to be colored individually. (Note
352  * that it should not generally be (0, 0, 0, 0), which would tend to bleed
353  * into the foreground color, unless you have also specified a outline color
354  * of (0, 0, 0, 1)) .
355  *
356  * Normally, you would not change this unless you really need a particular
357  * color effect to appear in the font itself.
358  *
359  * This should only be called before any characters have been requested out of
360  * the font, or immediately after calling clear().
361  */
362 INLINE void DynamicTextFont::
363 set_bg(const LColor &bg) {
364  // If this assertion fails, you didn't call clear() first. RTFM.
365  nassertv(get_num_pages() == 0);
366 
367  _bg = bg;
368  determine_tex_format();
369 }
370 
371 /**
372  * Returns the color of the background pixels of the font as they are rendered
373  * into the font texture. See set_bg().
374  */
375 INLINE const LColor &DynamicTextFont::
376 get_bg() const {
377  return _bg;
378 }
379 
380 
381 /**
382  * Sets up the font to have an outline around each font letter. This is
383  * achieved via a Gaussian post-process as each letter is generated; there is
384  * some runtime cost for this effect, but it is minimal as each letter is
385  * normally generated only once and then cached.
386  *
387  * The color is the desired color of the outline, width is the number of
388  * points beyond the letter that the outline extends (a typical font is 10
389  * points high), and feather is a number in the range 0.0 .. 1.0 that controls
390  * the softness of the outline. Set the width to 0.0 to disable the outline.
391  *
392  * This should only be called before any characters have been requested out of
393  * the font, or immediately after calling clear().
394  */
395 INLINE void DynamicTextFont::
396 set_outline(const LColor &outline_color, PN_stdfloat outline_width,
397  PN_stdfloat outline_feather) {
398  // If this assertion fails, you didn't call clear() first. RTFM.
399  nassertv(get_num_pages() == 0);
400 
401  _outline_color = outline_color;
402  _outline_width = outline_width;
403  _outline_feather = outline_feather;
404  determine_tex_format();
405 }
406 
407 /**
408  * Returns the color of the outline pixels of the font as they are rendered
409  * into the font texture. See set_outline().
410  */
411 INLINE const LColor &DynamicTextFont::
412 get_outline_color() const {
413  return _outline_color;
414 }
415 
416 /**
417  * Returns the width of the outline pixels of the font, as the number of
418  * points beyond each letter. See set_outline().
419  */
420 INLINE PN_stdfloat DynamicTextFont::
421 get_outline_width() const {
422  return _outline_width;
423 }
424 
425 /**
426  * Returns the softness of the outline pixels of the font, as a value in the
427  * range 0.0 to 1.0. See set_outline().
428  */
429 INLINE PN_stdfloat DynamicTextFont::
430 get_outline_feather() const {
431  return _outline_feather;
432 }
433 
434 /**
435  * Returns the texture format used to render the individual pages. This is
436  * set automatically according to the colors selected.
437  */
438 INLINE Texture::Format DynamicTextFont::
439 get_tex_format() const {
440  return _tex_format;
441 }
442 
443 
444 INLINE std::ostream &
445 operator << (std::ostream &out, const DynamicTextFont &dtf) {
446  return out << dtf.get_name();
447 }
get_line_height
Returns the number of units high each line of text is.
Definition: textFont.h:69
get_space_advance
Returns the number of units wide a space is.
Definition: textFont.h:73