This object uses the Freetype library to generate text directly into an image. More...
#include "pnmTextMaker.h"
Public Types | |
enum | Alignment { A_left, A_right, A_center } |
Public Member Functions | |
PNMTextMaker (const Filename &font_filename, int face_index) | |
The constructor expects the name of some font file that FreeType can read, along with face_index, indicating which font within the file to load (usually 0). More... | |
PNMTextMaker (const char *font_data, int data_length, int face_index) | |
This constructor works as above, but it takes the font data from an in- memory buffer instead of from a named file. More... | |
PNMTextMaker (const FreetypeFont ©) | |
PNMTextMaker (const PNMTextMaker ©) | |
int | calc_width (const std::string &text) |
Returns the width in pixels of the indicated line of text. More... | |
int | calc_width (const std::wstring &text) |
Returns the width in pixels of the indicated line of text. More... | |
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 is the total width in pixels. More... | |
int | generate_into (const std::wstring &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 is the total width in pixels. More... | |
Alignment | get_align () const |
int | get_distance_field_radius () const |
Returns the radius previously set with set_distance_field_radius, or 0 otherwise. More... | |
const LColor & | get_fg () const |
Returns the foreground color of text that will be generated by future calls to generate_into(). More... | |
PNMTextGlyph * | get_glyph (int character) |
Returns the glyph for the indicated index, or NULL if it is not defined in the font. More... | |
const LColor & | get_interior () const |
Returns the color that will be used to render the interior portions of hollow fonts. More... | |
bool | get_interior_flag () const |
bool | is_valid () const |
Returns true if the PNMTextMaker is valid and ready to generate text, false otherwise. More... | |
void | set_align (Alignment align_type) |
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 radius. More... | |
void | set_fg (const LColor &fg) |
Sets the foreground color of text that will be generated by future calls to generate_into(). More... | |
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 generate_into(). More... | |
void | set_interior_flag (bool interior_flag) |
Sets the flag that indicates whether the interior of hollow fonts is identified as a preprocess as each glyph is loaded. More... | |
This object uses the Freetype library to generate text directly into an image.
It is different from the TextNode/DynamicTextFont interface, which use the Freetype library to generate text in the scene graph, to be rendered onscreen via the Panda render traversal.
Definition at line 35 of file pnmTextMaker.h.
|
explicit |
The constructor expects the name of some font file that FreeType can read, along with face_index, indicating which font within the file to load (usually 0).
Definition at line 29 of file pnmTextMaker.cxx.
|
explicit |
This constructor works as above, but it takes the font data from an in- memory buffer instead of from a named file.
Definition at line 39 of file pnmTextMaker.cxx.
|
inline |
Returns the width in pixels of the indicated line of text.
Definition at line 135 of file pnmTextMaker.I.
References TextEncoder::get_wtext(), and TextEncoder::set_text.
Referenced by generate_into().
int PNMTextMaker::calc_width | ( | const std::wstring & | text | ) |
Returns the width in pixels of the indicated line of text.
Definition at line 124 of file pnmTextMaker.cxx.
References PNMTextGlyph::get_advance(), and get_glyph().
|
inline |
Generates a single line of text into the indicated image at the indicated position; the return value is the total width in pixels.
Definition at line 125 of file pnmTextMaker.I.
References TextEncoder::get_wtext(), and TextEncoder::set_text.
int PNMTextMaker::generate_into | ( | const std::wstring & | 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 is the total width in pixels.
Definition at line 83 of file pnmTextMaker.cxx.
References calc_width(), PNMTextGlyph::get_advance(), get_glyph(), and PNMTextGlyph::place().
|
inline |
Returns the radius previously set with set_distance_field_radius, or 0 otherwise.
Definition at line 116 of file pnmTextMaker.I.
|
inline |
Returns the foreground color of text that will be generated by future calls to generate_into().
Definition at line 79 of file pnmTextMaker.I.
PNMTextGlyph * PNMTextMaker::get_glyph | ( | int | character | ) |
Returns the glyph for the indicated index, or NULL if it is not defined in the font.
Definition at line 140 of file pnmTextMaker.cxx.
Referenced by calc_width(), and generate_into().
|
inline |
Returns the color that will be used to render the interior portions of hollow fonts.
Definition at line 98 of file pnmTextMaker.I.
|
inline |
Returns true if the PNMTextMaker is valid and ready to generate text, false otherwise.
Definition at line 19 of file pnmTextMaker.I.
|
inline |
If this is set to something other than 0, Panda will generate a signed distance field with the given radius.
Definition at line 107 of file pnmTextMaker.I.
|
inline |
Sets the foreground color of text that will be generated by future calls to generate_into().
This is the color that all of the "on" pixels in the font will show as.
Definition at line 70 of file pnmTextMaker.I.
|
inline |
Sets the color that will be used to render the interior portions of hollow fonts in future calls to generate_into().
This is respected only if interior_flag is true.
Definition at line 89 of file pnmTextMaker.I.
|
inline |
Sets the flag that indicates whether the interior of hollow fonts is identified as a preprocess as each glyph is loaded.
If this flag is true, you may specify an interior color along with a fg and bg color when you place text; if the flag is false, the interior color is ignored.
It is generally best to set_native_antialias(0) when using this feature. Also, this works best when the pixel size is not very small.
Definition at line 49 of file pnmTextMaker.I.