Panda3D
Public Types | Public Member Functions | Static Public Member Functions

PNMTextMaker Class Reference

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

Inheritance diagram for PNMTextMaker:
FreetypeFont Namable

List of all members.

Public Types

enum  Alignment { ALeft = 0, ARight = 1, ACenter = 2 }

Public Member Functions

 PNMTextMaker (Filename const 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).
 PNMTextMaker (PNMTextMaker const copy)
 PNMTextMaker (string 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.
int calcWidth (string text)
 Returns the width in pixels of the indicated line of text.
int calcWidth (string text)
 Returns the width in pixels of the indicated line of text.
 clearName ()
 Resets the Namable's name to empty.
int generateInto (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.
int generateInto (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.
Alignment getAlign ()
VBase4 const getFg ()
 Returns the foreground color of text that will be generated by future calls to generate_into().
int getFontPixelSize ()
 This is used to report whether the requested pixel size is being only approximated by a fixed-pixel-size font.
PNMTextGlyph getGlyph (int character)
 Returns the glyph for the indicated index, or NULL if it is not defined in the font.
VBase4 const getInterior ()
 Returns the color that will be used to render the interior portions of hollow fonts.
bool getInteriorFlag ()
float getLineHeight ()
 Returns the number of units high each line of text is.
string getName ()
bool getNativeAntialias ()
 Returns whether Freetype's built-in antialias mode is enabled.
float getPixelSize ()
 Returns the size of the font in pixels, as it appears in the texture.
float getPixelsPerUnit ()
 Returns the resolution of the texture map.
float getPointSize ()
 Returns the point size of the font.
float getScaleFactor ()
 Returns the antialiasing scale factor.
float getSpaceAdvance ()
 Returns the number of units wide a space is.
bool hasName ()
 Returns true if the Namable has a nonempty name set, false if the name is empty.
bool isValid ()
 Returns true if the PNMTextMaker is valid and ready to generate text, false otherwise.
 output (ostream out)
 Outputs the Namable.
 setAlign (Alignment align_type)
 setFg (VBase4 const fg)
 Sets the foreground color of text that will be generated by future calls to generate_into().
 setInterior (VBase4 const interior)
 Sets the color that will be used to render the interior portions of hollow fonts in future calls to generate_into().
 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.
 setName (string name)
 setNativeAntialias (bool native_antialias)
 Sets whether the Freetype library's built-in antialias mode is enabled.
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.
bool setPixelsPerUnit (float pixels_per_unit)
 Set the resolution of the texture map, and hence the clarity of the resulting font.
bool setPointSize (float point_size)
 Sets the point size of the font.
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().

Static Public Member Functions

static TypeHandle getClassType ()
static float getPointsPerInch ()
 Returns the number of points in one inch.
static float getPointsPerUnit ()
 Returns the point size of the font that is one Panda unit high.

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

enum Alignment
Enumerator:
ALeft 
ARight 
ACenter 

Constructor & Destructor Documentation

PNMTextMaker ( Filename const  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).

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


Member Function Documentation

int calcWidth ( string  text)

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

int calcWidth ( string  text)

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

clearName ( ) [inherited]

Resets the Namable's name to empty.

Reimplemented in AsyncTask.

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

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

Alignment getAlign ( )
static TypeHandle getClassType ( ) [static, inherited]

Reimplemented in PGItem, PandaNode, PGButton, PGTop, PGEntry, PGMouseWatcherBackground, MouseWatcherRegion, PGVirtualFrame, PGSliderBar, PGScrollFrame, PGWaitBar, ButtonThrower, DataNode, MouseInterfaceNode, DriveInterface, MouseSubregion, MouseWatcher, Trackball, Transform2SG, TextFont, DynamicTextPage, Texture, DynamicTextFont, StaticTextFont, TextNode, ParametricCurve, CubicCurveseg, PiecewiseCurve, HermiteCurve, NurbsCurve, RopeNode, SheetNode, AnimateVerticesRequest, AsyncTask, Material, TextureReloadRequest, VideoTexture, AsyncTaskBase, AsyncTaskChain, AsyncTaskManager, AsyncTaskPause, AsyncTaskSequence, PythonTask, Thread, ExternalThread, MainThread, PythonThread, AnalogNode, ButtonNode, DialNode, MouseAndKeyboard, TrackerNode, VirtualMouse, CollisionNode, CollisionTraverser, CollisionVisualizer, CharacterJoint, MovingPartMatrix, CharacterSlider, MovingPartScalar, Character, PartBundleNode, CharacterJointBundle, PartBundle, AnimGroup, AnimBundle, AnimBundleNode, PartGroup, AnimControl, AnimChannelBase, AnimChannelACMatrixSwitchType, AnimChannelACScalarSwitchType, AnimChannelMatrixDynamic, AnimChannelMatrixXfmTable, AnimChannelScalarDynamic, AnimChannelScalarTable, BindAnimRequest, ModelLoadRequest, MovingPartBase, MovingPartACMatrixSwitchType, MovingPartACScalarSwitchType, FFMpegTexture, FrameRateMeter, SceneGraphAnalyzerMeter, MovieTexture, RigidBodyCombiner, MovieVideo, MovieAudio, InkblotVideo, FfmpegVideo, FfmpegAudio, MicrophoneAudio, UserDataAudio, LensNode, Camera, PlaneNode, GeomNode, Fog, PandaLoader, ModelFlattenRequest, ModelNode, ModelRoot, PolylightNode, PortalNode, UvScrollNode, LightNode, AmbientLight, CallbackNode, LightLensNode, DirectionalLight, LODNode, FadeLODNode, PointLight, SelectiveChildNode, SequenceNode, Spotlight, SwitchNode, and MouseRecorder.

VBase4 const getFg ( )

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

int getFontPixelSize ( ) [inherited]

This is used to report whether the requested pixel size is being only approximated by a fixed-pixel-size font.

This returns 0 in the normal case, in which a scalable font is used, or the fixed-pixel-size font has exactly the requested pixel size.

If this returns non-zero, it is the pixel size of the font that we are using to approximate our desired size.

Reimplemented in DynamicTextFont.

PNMTextGlyph getGlyph ( int  character)

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

VBase4 const getInterior ( )

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

bool getInteriorFlag ( )
float getLineHeight ( ) [inherited]

Returns the number of units high each line of text is.

Reimplemented in DynamicTextFont.

string getName ( ) [inherited]

Reimplemented in DynamicTextFont.

bool getNativeAntialias ( ) [inherited]

Returns whether Freetype's built-in antialias mode is enabled.

See set_native_antialias().

Reimplemented in DynamicTextFont.

float getPixelSize ( ) [inherited]

Returns the size of the font in pixels, as it appears in the texture.

float getPixelsPerUnit ( ) [inherited]

Returns the resolution of the texture map.

See set_pixels_per_unit().

Reimplemented in DynamicTextFont.

float getPointSize ( ) [inherited]

Returns the point size of the font.

Reimplemented in DynamicTextFont.

static float getPointsPerInch ( ) [static, inherited]

Returns the number of points in one inch.

This is a universal typographic convention.

static float getPointsPerUnit ( ) [static, inherited]

Returns the point size of the font that is one Panda unit high.

This is an arbitrary Panda convention for text, and is set to 10.0.

float getScaleFactor ( ) [inherited]

Returns the antialiasing scale factor.

See set_scale_factor().

Reimplemented in DynamicTextFont.

float getSpaceAdvance ( ) [inherited]

Returns the number of units wide a space is.

Reimplemented in DynamicTextFont.

bool hasName ( ) [inherited]

Returns true if the Namable has a nonempty name set, false if the name is empty.

bool isValid ( )

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

output ( ostream  out) [inherited]

Outputs the Namable.

This function simply writes the name to the output stream; most Namable derivatives will probably redefine this.

Reimplemented in PandaNode, MouseWatcherRegion, TextNode, AdaptiveLru, SimpleLru, AsyncTask, Material, AsyncTaskChain, AsyncTaskManager, Thread, CollisionTraverser, PartBundle, AnimGroup, AnimControl, PandaLoader, LightNode, and LightLensNode.

setAlign ( Alignment  align_type)
setFg ( VBase4 const  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 ( VBase4 const  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 ( 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.

setName ( string  name) [inherited]

Reimplemented in PGItem, and AsyncTask.

setNativeAntialias ( bool  native_antialias) [inherited]

Sets whether the Freetype library's built-in antialias mode is enabled.

There are two unrelated ways to achieve antialiasing: with Freetype's native antialias mode, and with the use of a scale_factor greater than one. By default, both modes are enabled.

At low resolutions, some fonts may do better with one mode or the other. In general, Freetype's native antialiasing will produce less blurry results, but may introduce more artifacts.

Reimplemented in DynamicTextFont.

bool setPixelSize ( float  pixel_size) [inherited]

Computes the appropriate pixels_per_unit value to set the size of the font in the texture to the indicated number of pixels.

This is just another way to specify pixels_per_unit().

bool setPixelsPerUnit ( float  pixels_per_unit) [inherited]

Set the resolution of the texture map, and hence the clarity of the resulting font.

This sets the number of pixels in the texture map that are used for each onscreen unit.

Setting this number larger results in an easier to read font, but at the cost of more texture memory.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

Reimplemented in DynamicTextFont.

bool setPointSize ( float  point_size) [inherited]

Sets the point size of the font.

This controls the apparent size of the font onscreen. By convention, a 10 point font is about 1 screen unit high.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

Reimplemented in DynamicTextFont.

bool setScaleFactor ( float  scale_factor) [inherited]

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

This may be set to a number larger than 1.0 to improve the font's antialiasing (since FreeType doesn't really do a swell job of antialiasing by itself). There is some performance implication for setting this different than 1.0.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

Reimplemented in DynamicTextFont.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties