FTGL: FTFont Class Reference

FTGL 2.1.3~rc5

Public Member Functions | Protected Member Functions | Friends
FTFont Class Referenceabstract

FTFont is the public interface for the FTGL library. More...

`#include <FTFont.h>`

Inheritance diagram for FTFont:
[legend]

## Public Member Functions
virtual | ~FTFont ()
virtual bool | Attach (const char *fontFilePath)
| Attach auxilliary file to font e.g font metrics. More...
virtual bool | Attach (const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
| Attach auxilliary data to font e.g font metrics, from memory. More...
virtual void | GlyphLoadFlags (FT_Int flags)
| Set the glyph loading flags. More...
virtual bool | CharMap (FT_Encoding encoding)
| Set the character map for the face. More...
virtual unsigned int | CharMapCount () const
| Get the number of character maps in this face. More...
virtual FT_Encoding * | CharMapList ()
| Get a list of character maps in this face. More...
virtual bool | FaceSize (const unsigned int size, const unsigned int res=72)
| Set the char size for the current face. More...
virtual unsigned int | FaceSize () const
| Get the current face size in points (1/72 inch). More...
virtual void | Depth (float depth)
| Set the extrusion distance for the font. More...
virtual void | Outset (float outset)
| Set the outset distance for the font. More...
virtual void | Outset (float front, float back)
| Set the front and back outset distances for the font. More...
virtual void | UseDisplayList (bool useList)
| Enable or disable the use of Display Lists inside FTGL. More...
virtual float | Ascender () const
| Get the global ascender height for the face. More...
virtual float | Descender () const
| Gets the global descender height for the face. More...
virtual float | LineHeight () const
| Gets the line spacing for the font. More...
virtual FTBBox | BBox (const char *string, const int len=-1, FTPoint position=FTPoint(), FTPoint spacing=FTPoint())
| Get the bounding box for a string. More...
void | BBox (const char *string, float &llx, float &lly, float &llz, float &urx, float &ury, float &urz)
| Get the bounding box for a string (deprecated). More...
virtual FTBBox | BBox (const wchar_t *string, const int len=-1, FTPoint position=FTPoint(), FTPoint spacing=FTPoint())
| Get the bounding box for a string. More...
void | BBox (const wchar_t *string, float &llx, float &lly, float &llz, float &urx, float &ury, float &urz)
| Get the bounding box for a string (deprecated). More...
virtual float | Advance (const char *string, const int len=-1, FTPoint spacing=FTPoint())
| Get the advance for a string. More...
virtual float | Advance (const wchar_t *string, const int len=-1, FTPoint spacing=FTPoint())
| Get the advance for a string. More...
virtual FTPoint | Render (const char *string, const int len=-1, FTPoint position=FTPoint(), FTPoint spacing=FTPoint(), int renderMode=FTGL::RENDER_ALL)
| Render a string of characters. More...
virtual FTPoint | Render (const wchar_t *string, const int len=-1, FTPoint position=FTPoint(), FTPoint spacing=FTPoint(), int renderMode=FTGL::RENDER_ALL)
| Render a string of characters. More...
virtual FT_Error | Error () const
| Queries the Font for errors. More...

## Protected Member Functions
| FTFont (char const *fontFilePath)
| Open and read a font file. More...
| FTFont (const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
| Open and read a font from a buffer in memory. More...
virtual FTGlyph * | MakeGlyph (FT_GlyphSlot slot)=0
| Construct a glyph of the correct type. More...

## Friends
class | FTBitmapFont
class | FTBufferFont
class | FTExtrudeFont
class | FTOutlineFont
class | FTPixmapFont
class | FTPolygonFont
class | FTTextureFont
class | FTFontImpl

## Detailed Description

FTFont is the public interface for the FTGL library.

Specific font classes are derived from this class. It uses the helper classes FTFace and FTSize to access the Freetype library. This class is abstract and deriving classes must implement the protected `MakeGlyph` function to create glyphs of the appropriate type.

It is good practice after using these functions to test the error code returned. `FT_Error Error()`. Check the freetype file fterrdef.h for error definitions.

See also
  FTFace
  FTSize

Definition at line 56 of file FTFont.h.

## Constructor & Destructor Documentation

## ◆ FTFont() [1/2]

FTFont::FTFont | ( | char const * | fontFilePath | ) |
| protected

Open and read a font file.

Sets Error flag.

Parameters

  fontFilePath | font file path.

## ◆ FTFont() [2/2]

FTFont::FTFont | ( | const unsigned char * | pBufferBytes,
|  | size_t | bufferSizeInBytes
| ) |  |
| protected

Open and read a font from a buffer in memory.

Sets Error flag. The buffer is owned by the client and is NOT copied by FTGL. The pointer must be valid while using FTGL.

Parameters

  pBufferBytes | the in-memory buffer
  bufferSizeInBytes | the length of the buffer in bytes

## ◆ ~FTFont()

virtual FTFont::~FTFont | ( |  | ) |
| virtual

## Member Function Documentation

## ◆ Advance() [1/2]

virtual float FTFont::Advance | ( | const char * | string,
|  | const int | len = `-1`,
|  | FTPoint | spacing = `FTPoint()`
| ) |  |
| virtual

Get the advance for a string.

Parameters

  string | 'C' style string to be checked.
  len | The length of the string. If < 0 then all characters will be checked until a null character is encountered (optional).
  spacing | A displacement vector to add after each character has been checked (optional).

Returns
  The string's advance width.

Referenced by BBox().

## ◆ Advance() [2/2]

virtual float FTFont::Advance | ( | const wchar_t * | string,
|  | const int | len = `-1`,
|  | FTPoint | spacing = `FTPoint()`
| ) |  |
| virtual

Get the advance for a string.

Parameters

  string | A wchar_t string
  len | The length of the string. If < 0 then all characters will be checked until a null character is encountered (optional).
  spacing | A displacement vector to add after each character has been checked (optional).

Returns
  The string's advance width.

## ◆ Ascender()

virtual float FTFont::Ascender | ( |  | ) | const
| virtual

Get the global ascender height for the face.

Returns
  Ascender height

## ◆ Attach() [1/2]

virtual bool FTFont::Attach | ( | const char * | fontFilePath | ) |
| virtual

Attach auxilliary file to font e.g font metrics.

Note: not all font formats implement this function.

Parameters

  fontFilePath | auxilliary font file path.

Returns
  `true` if file has been attached successfully.

## ◆ Attach() [2/2]

virtual bool FTFont::Attach | ( | const unsigned char * | pBufferBytes,
|  | size_t | bufferSizeInBytes
| ) |  |
| virtual

Attach auxilliary data to font e.g font metrics, from memory.

Note: not all font formats implement this function.

Parameters

  pBufferBytes | the in-memory buffer.
  bufferSizeInBytes | the length of the buffer in bytes.

Returns
  `true` if file has been attached successfully.

## ◆ BBox() [1/4]

virtual FTBBox FTFont::BBox | ( | const char * | string,
|  | const int | len = `-1`,
|  | FTPoint | position = `FTPoint()`,
|  | FTPoint | spacing = `FTPoint()`
| ) |  |
| virtual

Get the bounding box for a string.

Parameters

  string | A char buffer.
  len | The length of the string. If < 0 then all characters will be checked until a null character is encountered (optional).
  position | The pen position of the first character (optional).
  spacing | A displacement vector to add after each character has been checked (optional).

Returns
  The corresponding bounding box.

Referenced by BBox().

## ◆ BBox() [2/4]

void FTFont::BBox | ( | const char * | string,
|  | float & | llx,
|  | float & | lly,
|  | float & | llz,
|  | float & | urx,
|  | float & | ury,
|  | float & | urz
| ) |  |
| inline

Get the bounding box for a string (deprecated).

Parameters

  string | A char buffer.
  llx | Lower left near x coordinate.
  lly | Lower left near y coordinate.
  llz | Lower left near z coordinate.
  urx | Upper right far x coordinate.
  ury | Upper right far y coordinate.
  urz | Upper right far z coordinate.

Definition at line 251 of file FTFont.h.

References BBox(), FTBBox::Lower(), FTBBox::Upper(), FTPoint::Xf(), FTPoint::Yf(), and FTPoint::Zf().

## ◆ BBox() [3/4]

virtual FTBBox FTFont::BBox | ( | const wchar_t * | string,
|  | const int | len = `-1`,
|  | FTPoint | position = `FTPoint()`,
|  | FTPoint | spacing = `FTPoint()`
| ) |  |
| virtual

Get the bounding box for a string.

Parameters

  string | A wchar_t buffer.
  len | The length of the string. If < 0 then all characters will be checked until a null character is encountered (optional).
  position | The pen position of the first character (optional).
  spacing | A displacement vector to add after each character has been checked (optional).

Returns
  The corresponding bounding box.

## ◆ BBox() [4/4]

void FTFont::BBox | ( | const wchar_t * | string,
|  | float & | llx,
|  | float & | lly,
|  | float & | llz,
|  | float & | urx,
|  | float & | ury,
|  | float & | urz
| ) |  |
| inline

Get the bounding box for a string (deprecated).

Parameters

  string | A wchar_t buffer.
  llx | Lower left near x coordinate.
  lly | Lower left near y coordinate.
  llz | Lower left near z coordinate.
  urx | Upper right far x coordinate.
  ury | Upper right far y coordinate.
  urz | Upper right far z coordinate.

Definition at line 286 of file FTFont.h.

References Advance(), BBox(), Error(), FTBBox::Lower(), Render(), FTGL::RENDER_ALL, FTBBox::Upper(), FTPoint::Xf(), FTPoint::Yf(), and FTPoint::Zf().

## ◆ CharMap()

virtual bool FTFont::CharMap | ( | FT_Encoding | encoding | ) |
| virtual

Set the character map for the face.

Parameters

  encoding | Freetype enumerate for char map code.

Returns
  `true` if charmap was valid and set correctly.

## ◆ CharMapCount()

virtual unsigned int FTFont::CharMapCount | ( |  | ) | const
| virtual

Get the number of character maps in this face.

Returns
  character map count.

## ◆ CharMapList()

virtual FT_Encoding* FTFont::CharMapList | ( |  | ) |
| virtual

Get a list of character maps in this face.

Returns
  pointer to the first encoding.

## ◆ Depth()

virtual void FTFont::Depth | ( | float | depth | ) |
| virtual

Set the extrusion distance for the font.

Only implemented by FTExtrudeFont

Parameters

  depth | The extrusion distance.

## ◆ Descender()

virtual float FTFont::Descender | ( |  | ) | const
| virtual

Gets the global descender height for the face.

Returns
  Descender height

## ◆ Error()

virtual FT_Error FTFont::Error | ( |  | ) | const
| virtual

Queries the Font for errors.

Returns
  The current error code.

Referenced by BBox().

## ◆ FaceSize() [1/2]

virtual bool FTFont::FaceSize | ( | const unsigned int | size,
|  | const unsigned int | res = `72`
| ) |  |
| virtual

Set the char size for the current face.

Parameters

  size | the face size in points (1/72 inch)
  res | the resolution of the target device.

Returns
  `true` if size was set correctly

## ◆ FaceSize() [2/2]

virtual unsigned int FTFont::FaceSize | ( |  | ) | const
| virtual

Get the current face size in points (1/72 inch).

Returns
  face size

## ◆ GlyphLoadFlags()

virtual void FTFont::GlyphLoadFlags | ( | FT_Int | flags | ) |
| virtual

Set the glyph loading flags.

By default, fonts use the most sensible flags when loading a font's glyph using FT_Load_Glyph(). This function allows to override the default flags.

Parameters

  flags | The glyph loading flags.

## ◆ LineHeight()

virtual float FTFont::LineHeight | ( |  | ) | const
| virtual

Gets the line spacing for the font.

Returns
  Line height

## ◆ MakeGlyph()

virtual FTGlyph* FTFont::MakeGlyph | ( | FT_GlyphSlot | slot | ) |
| protectedpure virtual

Construct a glyph of the correct type.

Clients must override the function and return their specialised FTGlyph.

Parameters

  slot | A FreeType glyph slot.

Returns
  An FT****Glyph or `null` on failure.

Implemented in FTExtrudeFont, FTBitmapFont, FTOutlineFont, FTPixmapFont, FTPolygonFont, FTTextureFont, and FTBufferFont.

## ◆ Outset() [1/2]

virtual void FTFont::Outset | ( | float | outset | ) |
| virtual

Set the outset distance for the font.

Only implemented by FTOutlineFont, FTPolygonFont and FTExtrudeFont

Parameters

  outset | The outset distance.

## ◆ Outset() [2/2]

virtual void FTFont::Outset | ( | float | front,
|  | float | back
| ) |  |
| virtual

Set the front and back outset distances for the font.

Only implemented by FTExtrudeFont

Parameters

  front | The front outset distance.
  back | The back outset distance.

## ◆ Render() [1/2]

virtual FTPoint FTFont::Render | ( | const char * | string,
|  | const int | len = `-1`,
|  | FTPoint | position = `FTPoint()`,
|  | FTPoint | spacing = `FTPoint()`,
|  | int | renderMode = `FTGL::RENDER_ALL`
| ) |  |
| virtual

Render a string of characters.

Parameters

  string | 'C' style string to be output.
  len | The length of the string. If < 0 then all characters will be displayed until a null character is encountered (optional).
  position | The pen position of the first character (optional).
  spacing | A displacement vector to add after each character has been displayed (optional).
  renderMode | Render mode to use for display (optional).

Returns
  The new pen position after the last character was output.

Referenced by BBox().

## ◆ Render() [2/2]

virtual FTPoint FTFont::Render | ( | const wchar_t * | string,
|  | const int | len = `-1`,
|  | FTPoint | position = `FTPoint()`,
|  | FTPoint | spacing = `FTPoint()`,
|  | int | renderMode = `FTGL::RENDER_ALL`
| ) |  |
| virtual

Render a string of characters.

Parameters

  string | wchar_t string to be output.
  len | The length of the string. If < 0 then all characters will be displayed until a null character is encountered (optional).
  position | The pen position of the first character (optional).
  spacing | A displacement vector to add after each character has been displayed (optional).
  renderMode | Render mode to use for display (optional).

Returns
  The new pen position after the last character was output.

## ◆ UseDisplayList()

virtual void FTFont::UseDisplayList | ( | bool | useList | ) |
| virtual

Enable or disable the use of Display Lists inside FTGL.

Parameters

  useList | `true` turns ON display lists. `false` turns OFF display lists.

## Friends And Related Function Documentation

## ◆ FTBitmapFont

friend class FTBitmapFont
| friend

Definition at line 78 of file FTFont.h.

## ◆ FTBufferFont

friend class FTBufferFont
| friend

Definition at line 79 of file FTFont.h.

## ◆ FTExtrudeFont

friend class FTExtrudeFont
| friend

Definition at line 80 of file FTFont.h.

## ◆ FTFontImpl

friend class FTFontImpl
| friend

Definition at line 367 of file FTFont.h.

## ◆ FTOutlineFont

friend class FTOutlineFont
| friend

Definition at line 81 of file FTFont.h.

## ◆ FTPixmapFont

friend class FTPixmapFont
| friend

Definition at line 82 of file FTFont.h.

## ◆ FTPolygonFont

friend class FTPolygonFont
| friend

Definition at line 83 of file FTFont.h.

## ◆ FTTextureFont

friend class FTTextureFont
| friend

Definition at line 84 of file FTFont.h.

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

- FTFont.h