Panda3D
 All Classes Functions Variables Enumerations
dynamicTextFont.I
1 // Filename: dynamicTextFont.I
2 // Created by: drose (08Feb02)
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: DynamicTextFont::get_name
18 // Access: Published
19 // Description: Disambiguates the get_name() method between that
20 // inherited from TextFont and that inherited from
21 // FreetypeFont.
22 ////////////////////////////////////////////////////////////////////
23 INLINE const string &DynamicTextFont::
24 get_name() const {
25  return TextFont::get_name();
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: DynamicTextFont::set_point_size
30 // Access: Published
31 // Description: Sets the point size of the font. This controls the
32 // apparent size of the font onscreen. By convention, a
33 // 10 point font is about 1 screen unit high.
34 //
35 // This should only be called before any characters have
36 // been requested out of the font, or immediately after
37 // calling clear().
38 ////////////////////////////////////////////////////////////////////
39 INLINE bool DynamicTextFont::
40 set_point_size(PN_stdfloat point_size) {
41  // If this assertion fails, you didn't call clear() first. RTFM.
42  nassertr(get_num_pages() == 0, false);
43 
44  return FreetypeFont::set_point_size(point_size);
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: DynamicTextFont::get_point_size
49 // Access: Published
50 // Description: Returns the point size of the font.
51 ////////////////////////////////////////////////////////////////////
52 INLINE PN_stdfloat DynamicTextFont::
53 get_point_size() const {
54  return FreetypeFont::get_point_size();
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: DynamicTextFont::set_pixels_per_unit
59 // Access: Published
60 // Description: Set the resolution of the texture map, and hence the
61 // clarity of the resulting font. This sets the number
62 // of pixels in the texture map that are used for each
63 // onscreen unit.
64 //
65 // Setting this number larger results in an easier to
66 // read font, but at the cost of more texture memory.
67 //
68 // This should only be called before any characters have
69 // been requested out of the font, or immediately after
70 // calling clear().
71 ////////////////////////////////////////////////////////////////////
72 INLINE bool DynamicTextFont::
73 set_pixels_per_unit(PN_stdfloat pixels_per_unit) {
74  // If this assertion fails, you didn't call clear() first. RTFM.
75  nassertr(get_num_pages() == 0, false);
76 
77  return FreetypeFont::set_pixels_per_unit(pixels_per_unit);
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: DynamicTextFont::get_pixels_per_unit
82 // Access: Published
83 // Description: Returns the resolution of the texture map. See
84 // set_pixels_per_unit().
85 ////////////////////////////////////////////////////////////////////
86 INLINE PN_stdfloat DynamicTextFont::
87 get_pixels_per_unit() const {
88  return FreetypeFont::get_pixels_per_unit();
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: DynamicTextFont::set_scale_factor
93 // Access: Published
94 // Description: Sets the factor by which the font is rendered larger
95 // by the FreeType library before being filtered down to
96 // its actual size in the texture as specified by
97 // set_pixels_per_unit(). This may be set to a number
98 // larger than 1.0 to improve the font's antialiasing
99 // (since FreeType doesn't really do a swell job of
100 // antialiasing by itself). There is some performance
101 // implication for setting this different than 1.0, but
102 // it is probably small.
103 //
104 // This should only be called before any characters have
105 // been requested out of the font, or immediately after
106 // calling clear().
107 ////////////////////////////////////////////////////////////////////
108 INLINE bool DynamicTextFont::
109 set_scale_factor(PN_stdfloat scale_factor) {
110  // If this assertion fails, you didn't call clear() first. RTFM.
111  nassertr(get_num_pages() == 0, false);
112 
113  return FreetypeFont::set_scale_factor(scale_factor);
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: DynamicTextFont::get_scale_factor
118 // Access: Published
119 // Description: Returns the antialiasing scale factor. See
120 // set_scale_factor().
121 ////////////////////////////////////////////////////////////////////
122 INLINE PN_stdfloat DynamicTextFont::
123 get_scale_factor() const {
124  return FreetypeFont::get_scale_factor();
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: DynamicTextFont::set_native_antialias
129 // Access: Published
130 // Description: Sets whether the Freetype library's built-in
131 // antialias mode is enabled. There are two unrelated
132 // ways to achieve antialiasing: with Freetype's native
133 // antialias mode, and with the use of a scale_factor
134 // greater than one. By default, both modes are
135 // enabled.
136 //
137 // At low resolutions, some fonts may do better with one
138 // mode or the other. In general, Freetype's native
139 // antialiasing will produce less blurry results, but
140 // may introduce more artifacts.
141 ////////////////////////////////////////////////////////////////////
142 INLINE void DynamicTextFont::
143 set_native_antialias(bool native_antialias) {
144  // If this assertion fails, you didn't call clear() first. RTFM.
145  nassertv(get_num_pages() == 0);
146 
147  FreetypeFont::set_native_antialias(native_antialias);
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function: DynamicTextFont::get_native_antialias
152 // Access: Published
153 // Description: Returns whether Freetype's built-in antialias mode is
154 // enabled. See set_native_antialias().
155 ////////////////////////////////////////////////////////////////////
156 INLINE bool DynamicTextFont::
157 get_native_antialias() const {
158  return FreetypeFont::get_native_antialias();
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: DynamicTextFont::get_font_pixel_size
163 // Access: Published
164 // Description: This is used to report whether the requested pixel
165 // size is being only approximated by a fixed-pixel-size
166 // font. This returns 0 in the normal case, in which a
167 // scalable font is used, or the fixed-pixel-size font
168 // has exactly the requested pixel size.
169 //
170 // If this returns non-zero, it is the pixel size of the
171 // font that we are using to approximate our desired
172 // size.
173 ////////////////////////////////////////////////////////////////////
174 INLINE int DynamicTextFont::
175 get_font_pixel_size() const {
176  return FreetypeFont::get_font_pixel_size();
177 }
178 
179 ////////////////////////////////////////////////////////////////////
180 // Function: DynamicTextFont::get_line_height
181 // Access: Published
182 // Description: Returns the number of units high each line of text
183 // is.
184 ////////////////////////////////////////////////////////////////////
185 INLINE PN_stdfloat DynamicTextFont::
186 get_line_height() const {
187  return TextFont::get_line_height();
188 }
189 
190 ////////////////////////////////////////////////////////////////////
191 // Function: DynamicTextFont::get_space_advance
192 // Access: Published
193 // Description: Returns the number of units wide a space is.
194 ////////////////////////////////////////////////////////////////////
195 INLINE PN_stdfloat DynamicTextFont::
196 get_space_advance() const {
198 }
199 
200 ////////////////////////////////////////////////////////////////////
201 // Function: DynamicTextFont::set_texture_margin
202 // Access: Published
203 // Description: Sets the number of pixels of padding that is added
204 // around the border of each glyph before adding it to
205 // the texture map. This reduces the bleed in from
206 // neighboring glyphs in the texture map.
207 ////////////////////////////////////////////////////////////////////
208 INLINE void DynamicTextFont::
209 set_texture_margin(int texture_margin) {
210  _texture_margin = texture_margin;
211 }
212 
213 ////////////////////////////////////////////////////////////////////
214 // Function: DynamicTextFont::get_texture_margin
215 // Access: Published
216 // Description: Returns the number of pixels of padding that is added
217 // around the border of each glyph in the texture map.
218 // See set_texture_margin().
219 ////////////////////////////////////////////////////////////////////
220 INLINE int DynamicTextFont::
221 get_texture_margin() const {
222  return _texture_margin;
223 }
224 
225 ////////////////////////////////////////////////////////////////////
226 // Function: DynamicTextFont::set_poly_margin
227 // Access: Published
228 // Description: Sets the number of pixels of padding that is included
229 // around each glyph in the generated polygons. This
230 // helps prevent the edges of the glyphs from being cut
231 // off at small minifications. It is not related to the
232 // amount of extra pixels reserved in the texture map
233 // (but it should be set somewhat smaller than this
234 // number, which is controlled by set_texture_margin(),
235 // to prevent bleed-in from neighboring letters in the
236 // texture).
237 ////////////////////////////////////////////////////////////////////
238 INLINE void DynamicTextFont::
239 set_poly_margin(PN_stdfloat poly_margin) {
240  _poly_margin = poly_margin;
241 }
242 
243 ////////////////////////////////////////////////////////////////////
244 // Function: DynamicTextFont::get_poly_margin
245 // Access: Published
246 // Description: Returns the number of pixels of padding that is
247 // included around each glyph in the generated polygons.
248 // See set_poly_margin().
249 ////////////////////////////////////////////////////////////////////
250 INLINE PN_stdfloat DynamicTextFont::
251 get_poly_margin() const {
252  return _poly_margin;
253 }
254 
255 ////////////////////////////////////////////////////////////////////
256 // Function: DynamicTextFont::set_page_size
257 // Access: Published
258 // Description: Sets the x, y size of the textures that are created
259 // for the DynamicTextFont.
260 ////////////////////////////////////////////////////////////////////
261 INLINE void DynamicTextFont::
262 set_page_size(int x_size, int y_size) {
263  _page_x_size = x_size;
264  _page_y_size = y_size;
265 }
266 
267 ////////////////////////////////////////////////////////////////////
268 // Function: DynamicTextFont::get_page_x_size
269 // Access: Published
270 // Description: Returns the x size of the textures that are created
271 // for the DynamicTextFont. See set_page_size().
272 ////////////////////////////////////////////////////////////////////
273 INLINE int DynamicTextFont::
274 get_page_x_size() const {
275  return _page_x_size;
276 }
277 
278 ////////////////////////////////////////////////////////////////////
279 // Function: DynamicTextFont::get_page_y_size
280 // Access: Published
281 // Description: Returns the y size of the textures that are created
282 // for the DynamicTextFont. See set_page_size().
283 ////////////////////////////////////////////////////////////////////
284 INLINE int DynamicTextFont::
285 get_page_y_size() const {
286  return _page_y_size;
287 }
288 
289 ////////////////////////////////////////////////////////////////////
290 // Function: DynamicTextFont::set_minfilter
291 // Access: Published
292 // Description: Sets the filter type used when minimizing the
293 // textures created for this font.
294 ////////////////////////////////////////////////////////////////////
295 INLINE void DynamicTextFont::
296 set_minfilter(SamplerState::FilterType filter) {
297  _minfilter = filter;
298  update_filters();
299 }
300 
301 ////////////////////////////////////////////////////////////////////
302 // Function: DynamicTextFont::get_minfilter
303 // Access: Published
304 // Description: Returns the filter type used when minimizing the
305 // textures created for this font.
306 ////////////////////////////////////////////////////////////////////
307 INLINE SamplerState::FilterType DynamicTextFont::
308 get_minfilter() const {
309  return _minfilter;
310 }
311 
312 ////////////////////////////////////////////////////////////////////
313 // Function: DynamicTextFont::set_magfilter
314 // Access: Published
315 // Description: Sets the filter type used when enlarging the
316 // textures created for this font.
317 ////////////////////////////////////////////////////////////////////
318 INLINE void DynamicTextFont::
319 set_magfilter(SamplerState::FilterType filter) {
320  _magfilter = filter;
321  update_filters();
322 }
323 
324 ////////////////////////////////////////////////////////////////////
325 // Function: DynamicTextFont::get_magfilter
326 // Access: Published
327 // Description: Returns the filter type used when enlarging the
328 // textures created for this font.
329 ////////////////////////////////////////////////////////////////////
330 INLINE SamplerState::FilterType DynamicTextFont::
331 get_magfilter() const {
332  return _magfilter;
333 }
334 
335 ////////////////////////////////////////////////////////////////////
336 // Function: DynamicTextFont::set_anisotropic_degree
337 // Access: Published
338 // Description: Enables or disables anisotropic filtering on the
339 // textures created for this font. The default value is
340 // specified by the text-anisotropic-degree variable.
341 // See Texture::set_anisotropic_degree().
342 ////////////////////////////////////////////////////////////////////
343 INLINE void DynamicTextFont::
344 set_anisotropic_degree(int anisotropic_degree) {
345  _anisotropic_degree = anisotropic_degree;
346  update_filters();
347 }
348 
349 ////////////////////////////////////////////////////////////////////
350 // Function: DynamicTextFont::get_anisotropic_degree
351 // Access: Published
352 // Description: Returns the current anisotropic degree for textures
353 // created for this font. See set_anisotropic_degree().
354 ////////////////////////////////////////////////////////////////////
355 INLINE int DynamicTextFont::
356 get_anisotropic_degree() const {
357  return _anisotropic_degree;
358 }
359 
360 ////////////////////////////////////////////////////////////////////
361 // Function: DynamicTextFont::set_render_mode
362 // Access: Published
363 // Description: Specifies the way the glyphs on this particular font
364 // are generated. The default is RM_texture, which is
365 // the only mode supported for bitmap fonts. Other modes
366 // are possible for most modern fonts.
367 ////////////////////////////////////////////////////////////////////
368 INLINE void DynamicTextFont::
369 set_render_mode(DynamicTextFont::RenderMode render_mode) {
370  _render_mode = render_mode;
371 }
372 
373 ////////////////////////////////////////////////////////////////////
374 // Function: DynamicTextFont::get_render_mode
375 // Access: Published
376 // Description: Returns the way the glyphs on this particular font
377 // are generated. See set_render_mode().
378 ////////////////////////////////////////////////////////////////////
379 INLINE DynamicTextFont::RenderMode DynamicTextFont::
380 get_render_mode() const {
381  return _render_mode;
382 }
383 
384 ////////////////////////////////////////////////////////////////////
385 // Function: DynamicTextFont::set_winding_order
386 // Access: Published
387 // Description: Specifies an explicitly winding order on this
388 // particular font. This is only necessary if the
389 // render_mode is RM_polygon or RM_solid, and only if
390 // FreeType appears to guess wrong on this font.
391 // Normally, you should leave this at WO_default.
392 ////////////////////////////////////////////////////////////////////
393 INLINE void DynamicTextFont::
394 set_winding_order(DynamicTextFont::WindingOrder winding_order) {
395  _winding_order = winding_order;
396 }
397 
398 ////////////////////////////////////////////////////////////////////
399 // Function: DynamicTextFont::get_winding_order
400 // Access: Published
401 // Description: Returns the winding order set via set_winding_order().
402 ////////////////////////////////////////////////////////////////////
403 INLINE DynamicTextFont::WindingOrder DynamicTextFont::
404 get_winding_order() const {
405  return _winding_order;
406 }
407 
408 ////////////////////////////////////////////////////////////////////
409 // Function: DynamicTextFont::set_fg
410 // Access: Published
411 // Description: Changes the color of the foreground pixels of the
412 // font as they are rendered into the font texture. The
413 // default is (1, 1, 1, 1), or opaque white, which
414 // allows text created with the font to be colored
415 // individually. Normally, you would not change this
416 // unless you really need a particular color effect to
417 // appear in the font itself.
418 //
419 // This should only be called before any characters have
420 // been requested out of the font, or immediately after
421 // calling clear().
422 ////////////////////////////////////////////////////////////////////
423 INLINE void DynamicTextFont::
424 set_fg(const LColor &fg) {
425  // If this assertion fails, you didn't call clear() first. RTFM.
426  nassertv(get_num_pages() == 0);
427 
428  _fg = fg;
429  determine_tex_format();
430 }
431 
432 ////////////////////////////////////////////////////////////////////
433 // Function: DynamicTextFont::get_fg
434 // Access: Published
435 // Description: Returns the color of the foreground pixels of the
436 // font as they are rendered into the font texture.
437 // See set_fg().
438 ////////////////////////////////////////////////////////////////////
439 INLINE const LColor &DynamicTextFont::
440 get_fg() const {
441  return _fg;
442 }
443 
444 ////////////////////////////////////////////////////////////////////
445 // Function: DynamicTextFont::set_bg
446 // Access: Published
447 // Description: Changes the color of the background pixels of the
448 // font as they are rendered into the font texture. The
449 // default is (1, 1, 1, 0), or transparent white, which
450 // allows text created with the font to be colored
451 // individually. (Note that it should not generally be
452 // (0, 0, 0, 0), which would tend to bleed into the
453 // foreground color, unless you have also specified a
454 // outline color of (0, 0, 0, 1)) .
455 //
456 // Normally, you would not change this unless you really
457 // need a particular color effect to appear in the font
458 // itself.
459 //
460 // This should only be called before any characters have
461 // been requested out of the font, or immediately after
462 // calling clear().
463 ////////////////////////////////////////////////////////////////////
464 INLINE void DynamicTextFont::
465 set_bg(const LColor &bg) {
466  // If this assertion fails, you didn't call clear() first. RTFM.
467  nassertv(get_num_pages() == 0);
468 
469  _bg = bg;
470  determine_tex_format();
471 }
472 
473 ////////////////////////////////////////////////////////////////////
474 // Function: DynamicTextFont::get_bg
475 // Access: Published
476 // Description: Returns the color of the background pixels of the
477 // font as they are rendered into the font texture.
478 // See set_bg().
479 ////////////////////////////////////////////////////////////////////
480 INLINE const LColor &DynamicTextFont::
481 get_bg() const {
482  return _bg;
483 }
484 
485 
486 ////////////////////////////////////////////////////////////////////
487 // Function: DynamicTextFont::set_outline
488 // Access: Published
489 // Description: Sets up the font to have an outline around each font
490 // letter. This is achieved via a Gaussian post-process
491 // as each letter is generated; there is some runtime
492 // cost for this effect, but it is minimal as each
493 // letter is normally generated only once and then
494 // cached.
495 //
496 // The color is the desired color of the outline, width
497 // is the number of points beyond the letter that the
498 // outline extends (a typical font is 10 points high),
499 // and feather is a number in the range 0.0 .. 1.0 that
500 // controls the softness of the outline. Set the width
501 // to 0.0 to disable the outline.
502 //
503 // This should only be called before any characters have
504 // been requested out of the font, or immediately after
505 // calling clear().
506 ////////////////////////////////////////////////////////////////////
507 INLINE void DynamicTextFont::
508 set_outline(const LColor &outline_color, PN_stdfloat outline_width,
509  PN_stdfloat outline_feather) {
510  // If this assertion fails, you didn't call clear() first. RTFM.
511  nassertv(get_num_pages() == 0);
512 
513  _outline_color = outline_color;
514  _outline_width = outline_width;
515  _outline_feather = outline_feather;
516  determine_tex_format();
517 }
518 
519 ////////////////////////////////////////////////////////////////////
520 // Function: DynamicTextFont::get_outline_color
521 // Access: Published
522 // Description: Returns the color of the outline pixels of the
523 // font as they are rendered into the font texture.
524 // See set_outline().
525 ////////////////////////////////////////////////////////////////////
526 INLINE const LColor &DynamicTextFont::
527 get_outline_color() const {
528  return _outline_color;
529 }
530 
531 ////////////////////////////////////////////////////////////////////
532 // Function: DynamicTextFont::get_outline_width
533 // Access: Published
534 // Description: Returns the width of the outline pixels of the
535 // font, as the number of points beyond each letter.
536 // See set_outline().
537 ////////////////////////////////////////////////////////////////////
538 INLINE PN_stdfloat DynamicTextFont::
539 get_outline_width() const {
540  return _outline_width;
541 }
542 
543 ////////////////////////////////////////////////////////////////////
544 // Function: DynamicTextFont::get_outline_feather
545 // Access: Published
546 // Description: Returns the softness of the outline pixels of the
547 // font, as a value in the range 0.0 to 1.0.
548 // See set_outline().
549 ////////////////////////////////////////////////////////////////////
550 INLINE PN_stdfloat DynamicTextFont::
551 get_outline_feather() const {
552  return _outline_feather;
553 }
554 
555 ////////////////////////////////////////////////////////////////////
556 // Function: DynamicTextFont::get_tex_format
557 // Access: Published
558 // Description: Returns the texture format used to render the
559 // individual pages. This is set automatically
560 // according to the colors selected.
561 ////////////////////////////////////////////////////////////////////
562 INLINE Texture::Format DynamicTextFont::
563 get_tex_format() const {
564  return _tex_format;
565 }
566 
567 ////////////////////////////////////////////////////////////////////
568 // Function: DynamicTextFont::ContourPoint::Constructor
569 // Access: Public
570 // Description:
571 ////////////////////////////////////////////////////////////////////
572 INLINE DynamicTextFont::ContourPoint::
573 ContourPoint(const LPoint2 &p, const LVector2 &in, const LVector2 &out) :
574  _p(p), _in(in), _out(out)
575 {
576 }
577 
578 ////////////////////////////////////////////////////////////////////
579 // Function: DynamicTextFont::ContourPoint::Constructor
580 // Access: Public
581 // Description:
582 ////////////////////////////////////////////////////////////////////
583 INLINE DynamicTextFont::ContourPoint::
584 ContourPoint(PN_stdfloat px, PN_stdfloat py, PN_stdfloat tx, PN_stdfloat ty) :
585  _p(px, py), _in(tx, ty), _out(tx, ty)
586 {
587 }
588 
589 ////////////////////////////////////////////////////////////////////
590 // Function: DynamicTextFont::connect_to
591 // Access: Public
592 // Description: Connects the indicated point to the next point, whose
593 // tangent is given. The given tangent becomes the out
594 // tangent at this point. If the in tangent and out
595 // tangent are sufficiently close, they will be smoothed
596 // together.
597 ////////////////////////////////////////////////////////////////////
598 INLINE void DynamicTextFont::ContourPoint::
599 connect_to(const LVector2 &out) {
600  _out = out;
601  if (_in.dot(_out) > 0.7071) {
602  // Less than 45 degrees of difference: smooth them.
603  LVector2 av = (_in + _out) * 0.5f;
604  av.normalize();
605  _in = av;
606  _out = av;
607  }
608 }
609 
610 
611 INLINE ostream &
612 operator << (ostream &out, const DynamicTextFont &dtf) {
613  return out << dtf.get_name();
614 }
bool normalize()
Normalizes the vector in place.
Definition: lvecBase2.h:680
PN_stdfloat get_space_advance() const
Returns the number of units wide a space is.
Definition: textFont.I:66
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This is a two-component vector offset.
Definition: lvector2.h:91
This is a two-component point in space.
Definition: lpoint2.h:92
PN_stdfloat get_line_height() const
Returns the number of units high each line of text is.
Definition: textFont.I:45