Panda3D
Public Types | Public Member Functions | List of all members
PNMTextMaker Class Reference

This object uses the Freetype library to generate text directly into an image. More...

#include "pnmTextMaker.h"

Inheritance diagram for PNMTextMaker:

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 &copy)
 
 PNMTextMaker (const PNMTextMaker &copy)
 
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...
 
PNMTextGlyphget_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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PNMTextMaker() [1/2]

PNMTextMaker::PNMTextMaker ( const Filename font_filename,
int  face_index 
)
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.

◆ PNMTextMaker() [2/2]

PNMTextMaker::PNMTextMaker ( const char *  font_data,
int  data_length,
int  face_index 
)
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.

Member Function Documentation

◆ calc_width() [1/2]

int PNMTextMaker::calc_width ( const std::string &  text)
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().

◆ calc_width() [2/2]

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().

◆ generate_into() [1/2]

int PNMTextMaker::generate_into ( const std::string &  text,
PNMImage dest_image,
int  x,
int  y 
)
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.

◆ generate_into() [2/2]

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().

◆ get_distance_field_radius()

int PNMTextMaker::get_distance_field_radius ( ) const
inline

Returns the radius previously set with set_distance_field_radius, or 0 otherwise.

Definition at line 116 of file pnmTextMaker.I.

◆ get_fg()

const LColor & PNMTextMaker::get_fg ( ) const
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.

◆ get_glyph()

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().

◆ get_interior()

const LColor & PNMTextMaker::get_interior ( ) const
inline

Returns the color that will be used to render the interior portions of hollow fonts.

Definition at line 98 of file pnmTextMaker.I.

◆ is_valid()

bool PNMTextMaker::is_valid ( ) const
inline

Returns true if the PNMTextMaker is valid and ready to generate text, false otherwise.

Definition at line 19 of file pnmTextMaker.I.

◆ set_distance_field_radius()

void PNMTextMaker::set_distance_field_radius ( int  radius)
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.

◆ set_fg()

void PNMTextMaker::set_fg ( const LColor &  fg)
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.

◆ set_interior()

void PNMTextMaker::set_interior ( const LColor &  interior)
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.

◆ set_interior_flag()

void PNMTextMaker::set_interior_flag ( bool  interior_flag)
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.


The documentation for this class was generated from the following files: