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

Inheritance diagram for PNMTextMaker:
FreetypeFont Namable

Public Types

enum  Alignment { A_left = 0, A_right = 1, A_center = 2 }
 
- Public Types inherited from FreetypeFont
enum  WindingOrder { WO_default = 0, WO_left = 1, WO_right = 2, WO_invalid = 3 }
 

Public Member Functions

 __init__ (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...
 
 __init__ (const FreetypeFont copy)
 
 __init__ (const PNMTextMaker copy)
 
 __init__ (str 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...
 
int calcWidth (str text)
 Returns the width in pixels of the indicated line of text. More...
 
int calcWidth (str text)
 Returns the width in pixels of the indicated line of text. More...
 
int generateInto (str 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 generateInto (str 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...
 
PNMTextMaker::Alignment getAlign ()
 
int getDistanceFieldRadius ()
 Returns the radius previously set with set_distance_field_radius, or 0 otherwise. More...
 
const LColor getFg ()
 Returns the foreground color of text that will be generated by future calls to generate_into(). More...
 
PNMTextGlyph getGlyph (int character)
 Returns the glyph for the indicated index, or NULL if it is not defined in the font. More...
 
const LColor getInterior ()
 Returns the color that will be used to render the interior portions of hollow fonts. More...
 
bool getInteriorFlag ()
 
bool isValid ()
 Returns true if the PNMTextMaker is valid and ready to generate text, false otherwise. More...
 
 setAlign (PNMTextMaker::Alignment align_type)
 
 setDistanceFieldRadius (int radius)
 If this is set to something other than 0, Panda will generate a signed distance field with the given radius. More...
 
 setFg (const LColor fg)
 Sets the foreground color of text that will be generated by future calls to generate_into(). More...
 
 setInterior (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...
 
 setInteriorFlag (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...
 
- Public Member Functions inherited from FreetypeFont
int getFontPixelSize ()
 This is used to report whether the requested pixel size is being only approximated by a fixed-pixel-size font. More...
 
float getLineHeight ()
 Returns the number of units high each line of text is. More...
 
bool getNativeAntialias ()
 Returns whether Freetype's built-in antialias mode is enabled. More...
 
float getPixelSize ()
 Returns the size of the font in pixels, as it appears in the texture. More...
 
float getPixelsPerUnit ()
 Returns the resolution of the texture map. More...
 
float getPointSize ()
 Returns the point size of the font. More...
 
float getScaleFactor ()
 Returns the antialiasing scale factor. More...
 
float getSpaceAdvance ()
 Returns the number of units wide a space is. More...
 
FreetypeFont::WindingOrder getWindingOrder ()
 Returns the winding order set via set_winding_order(). More...
 
 setNativeAntialias (bool native_antialias)
 Sets whether the Freetype library's built-in antialias mode is enabled. More...
 
bool setPixelSize (float pixel_size)
 Computes the appropriate pixels_per_unit value to set the size of the font in the texture to the indicated number of pixels. More...
 
bool setPixelsPerUnit (float pixels_per_unit)
 Set the resolution of the texture map, and hence the clarity of the resulting font. More...
 
bool setPointSize (float point_size)
 Sets the point size of the font. More...
 
bool setScaleFactor (float scale_factor)
 Sets the factor by which the font is rendered larger by the FreeType library before being filtered down to its actual size in the texture as specified by set_pixels_per_unit(). More...
 
 setWindingOrder (FreetypeFont::WindingOrder winding_order)
 Specifies an explicitly winding order on this particular font. More...
 
- Public Member Functions inherited from Namable
 __init__ (const Namable)
 
 __init__ (str initial_name)
 
 clearName ()
 Resets the Namable's name to empty. More...
 
str getName ()
 
bool hasName ()
 Returns true if the Namable has a nonempty name set, false if the name is empty. More...
 
 output (Ostream out)
 Outputs the Namable. More...
 
 setName (str name)
 

Additional Inherited Members

- Static Public Member Functions inherited from FreetypeFont
static float getPointsPerInch ()
 Returns the number of points in one inch. More...
 
static float getPointsPerUnit ()
 Returns the point size of the font that is one Panda unit high. More...
 
- Static Public Member Functions inherited from Namable
static TypeHandle getClassType ()
 
- Public Attributes inherited from FreetypeFont
FreetypeFont::WindingOrder winding_order
 Returns the winding order set via set_winding_order(). More...
 
- Public Attributes inherited from Namable
const String name
 

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.

Member Enumeration Documentation

◆ Alignment

enum Alignment
Enumerator
A_left 
A_right 
A_center 

Member Function Documentation

◆ __init__() [1/4]

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

◆ __init__() [2/4]

__init__ ( const FreetypeFont  copy)

◆ __init__() [3/4]

__init__ ( const PNMTextMaker  copy)

◆ __init__() [4/4]

__init__ ( str  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.

◆ calcWidth() [1/2]

int calcWidth ( str  text)

Returns the width in pixels of the indicated line of text.

◆ calcWidth() [2/2]

int calcWidth ( str  text)

Returns the width in pixels of the indicated line of text.

◆ generateInto() [1/2]

int generateInto ( str  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.

◆ generateInto() [2/2]

int generateInto ( str  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.

◆ getAlign()

◆ getDistanceFieldRadius()

int getDistanceFieldRadius ( )

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

◆ getFg()

const LColor getFg ( )

Returns the foreground color of text that will be generated by future calls to generate_into().

◆ getGlyph()

PNMTextGlyph getGlyph ( int  character)

Returns the glyph for the indicated index, or NULL if it is not defined in the font.

◆ getInterior()

const LColor getInterior ( )

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

◆ getInteriorFlag()

bool getInteriorFlag ( )

◆ isValid()

bool isValid ( )

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

◆ setAlign()

setAlign ( PNMTextMaker::Alignment  align_type)

◆ setDistanceFieldRadius()

setDistanceFieldRadius ( int  radius)

If this is set to something other than 0, Panda will generate a signed distance field with the given radius.

◆ setFg()

setFg ( const LColor  fg)

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.

◆ setInterior()

setInterior ( const LColor  interior)

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.

◆ setInteriorFlag()

setInteriorFlag ( bool  interior_flag)

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.