Open Font Render 1.2
Loading...
Searching...
No Matches
Rendering-related APIs

Macros

#define setDrawPixel(F)   set_drawPixel([&](int32_t x, int32_t y, uint16_t c) { return F(x, y, c); })
 Set function to draw pixel to screen.
 
#define setDrawFastHLine(F)   set_drawFastHLine([&](int32_t x, int32_t y, int32_t w, uint16_t c) { return F(x, y, w, c); })
 Set function to fast draw horizontal line to screen. (Optional)
 
#define setStartWrite(F)   set_startWrite([&](void) { return F(); })
 It is called only once at the beginning of a sequence of drawings. (Optional)
 
#define setEndWrite(F)   set_endWrite([&](void) { return F(); })
 It is called only once at the beginning of a sequence of drawings. (Optional)
 
#define setPrintFunc(F)   set_printFunc([&](const char *s) { return F(s); })
 Specifies the standard output destination for the system. (Optional)
 

Functions

template<typename T >
void OpenFontRender::setDrawer (T &drawer)
 Collectively set up screen control functions.
 
void OpenFontRender::setCacheSize (unsigned int max_faces, unsigned int max_sizes, unsigned long max_bytes)
 Set FreeType cache size.
 
FT_Error OpenFontRender::loadFont (const unsigned char *data, size_t size, uint8_t target_face_index=0)
 Load font from memory.
 
FT_Error OpenFontRender::loadFont (const char *fpath, uint8_t target_face_index=0)
 Load font from external memory.
 
void OpenFontRender::unloadFont ()
 Unload font data.
 
uint16_t OpenFontRender::drawHString (const char *str, int32_t x, int32_t y, uint16_t fg, uint16_t bg, Align align, Drawing drawing, FT_BBox &abbox, FT_Error &error)
 Renders text horizontally.
 
FT_Error OpenFontRender::drawChar (char character, int32_t x=0, int32_t y=0, uint16_t fg=0xFFFF, uint16_t bg=0x0000, Align align=Align::Left)
 Render single character.
 
uint16_t OpenFontRender::drawString (const char *str, int32_t x=0, int32_t y=0, uint16_t fg=0xFFFF, uint16_t bg=0x0000, Layout layout=Layout::Horizontal)
 Renders text.
 
uint16_t OpenFontRender::cdrawString (const char *str, int32_t x=0, int32_t y=0, uint16_t fg=0xFFFF, uint16_t bg=0x0000, Layout layout=Layout::Horizontal)
 Renders text as Top-Center.
 
uint16_t OpenFontRender::rdrawString (const char *str, int32_t x=0, int32_t y=0, uint16_t fg=0xFFFF, uint16_t bg=0x0000, Layout layout=Layout::Horizontal)
 Renders text as Top-Right.
 
uint16_t OpenFontRender::printf (const char *fmt,...)
 Renders text with format specifier.
 
uint16_t OpenFontRender::cprintf (const char *fmt,...)
 Renders text as Top-Center with format specifier.
 
uint16_t OpenFontRender::rprintf (const char *fmt,...)
 Renders text as Top-Right with format specifier.
 
FT_BBox OpenFontRender::calculateBoundingBoxFmt (int32_t x, int32_t y, unsigned int font_size, Align align, Layout layout, const char *fmt,...)
 Calculate text bounding box with format specifier.
 
FT_BBox OpenFontRender::calculateBoundingBox (int32_t x, int32_t y, unsigned int font_size, Align align, Layout layout, const char *str)
 Calculate text bounding box.
 
uint32_t OpenFontRender::getTextWidth (const char *fmt,...)
 Calculate text width.
 
uint32_t OpenFontRender::getTextHeight (const char *fmt,...)
 Calculate text height.
 
unsigned int OpenFontRender::calculateFitFontSizeFmt (uint32_t limit_width, uint32_t limit_height, Layout layout, const char *fmt,...)
 Calculates the maximum font size that will fit the specified format string and the specified rectangle.
 
unsigned int OpenFontRender::calculateFitFontSize (uint32_t limit_width, uint32_t limit_height, Layout layout, const char *str)
 Calculates the maximum font size that will fit the specified string and the specified rectangle.
 

Detailed Description

This is a group of methods related to text rendering.

Macro Definition Documentation

◆ setDrawFastHLine

#define setDrawFastHLine (   F)    set_drawFastHLine([&](int32_t x, int32_t y, int32_t w, uint16_t c) { return F(x, y, w, c); })

Set function to fast draw horizontal line to screen. (Optional)

Parameters
[in](user_func)User function for fast draw horizontal line to screen.
Note
If you set this function, drawing method will be optimized and improve speed.
void example_function (int32_t x, int32_t y, int32_t w, uint16_t c)
Type Name Description
int32_t x Draw position X
int32_t y Draw position Y
int32_t w Draw Length
int32_t c Draw color (16 bit color)

◆ setDrawPixel

#define setDrawPixel (   F)    set_drawPixel([&](int32_t x, int32_t y, uint16_t c) { return F(x, y, c); })

Set function to draw pixel to screen.

Parameters
[in](user_func)User function for draw pixel to screen.
Note
The function to be given must be a function like the one below that takes a specific argument.
void example_function (int32_t x, int32_t y, uint16_t c)
Type Name Description
int32_t x Draw position X
int32_t y Draw position Y
int32_t c Draw color (16 bit color)

◆ setEndWrite

#define setEndWrite (   F)    set_endWrite([&](void) { return F(); })

It is called only once at the beginning of a sequence of drawings. (Optional)

Certain libraries can occupy the bus during continuous drawing to increase the drawing speed.

Parameters
[in](user_func)User function that call after draw to screen.
Note
If you set this function, drawing method will be optimized and improve speed.
void example_function (void)

◆ setPrintFunc

#define setPrintFunc (   F)    set_printFunc([&](const char *s) { return F(s); })

Specifies the standard output destination for the system. (Optional)

Parameters
[in](user_func)User function for output message.
Note
The function to be given must be a function like the one below that takes a specific argument.
void example_function (const char *s)

◆ setStartWrite

#define setStartWrite (   F)    set_startWrite([&](void) { return F(); })

It is called only once at the beginning of a sequence of drawings. (Optional)

Certain libraries can occupy the bus during continuous drawing to increase the drawing speed.

Parameters
[in](user_func)User function that call before draw to screen.
Note
If you set this function, drawing method will be optimized and improve speed.
void example_function (void)

Function Documentation

◆ calculateBoundingBox()

FT_BBox OpenFontRender::calculateBoundingBox ( int32_t  x,
int32_t  y,
unsigned int  font_size,
Align  align,
Layout  layout,
const char *  str 
)

Calculate text bounding box.

Parameters
[in](x)Drawing start position (x-coordinate).
[in](y)Drawing start position (y-coordinate).
[in](font_size)Font size.
[in](align)Text alignment.
[in](layout)Direction of writing.
[in](*str)Target string.
Returns
Smallest rectangle that encloses the drawn string.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateBoundingBoxFmt()

FT_BBox OpenFontRender::calculateBoundingBoxFmt ( int32_t  x,
int32_t  y,
unsigned int  font_size,
Align  align,
Layout  layout,
const char *  fmt,
  ... 
)

Calculate text bounding box with format specifier.

Parameters
[in](x)Drawing start position (x-coordinate).
[in](y)Drawing start position (y-coordinate).
[in](font_size)Font size.
[in](align)Text alignment.
[in](layout)Direction of writing.
[in](*fmt)Format specifier.
[in](...)Arguments for format specifier.
Returns
Smallest rectangle that encloses the drawn string.
Here is the call graph for this function:

◆ calculateFitFontSize()

unsigned int OpenFontRender::calculateFitFontSize ( uint32_t  limit_width,
uint32_t  limit_height,
Layout  layout,
const char *  str 
)

Calculates the maximum font size that will fit the specified string and the specified rectangle.

Parameters
[in](limit_width)Limit width size.
[in](limit_height)Limit height size.
[in](layout)Direction of text writing.
[in](*str)Target string.
Returns
Calculated font size.
Note
This process takes time.
Attention
Note that the calculated font size may not exactly meet the size limit.
This is because the font size is not strictly measured, but only "estimated" by calculation.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateFitFontSizeFmt()

unsigned int OpenFontRender::calculateFitFontSizeFmt ( uint32_t  limit_width,
uint32_t  limit_height,
Layout  layout,
const char *  fmt,
  ... 
)

Calculates the maximum font size that will fit the specified format string and the specified rectangle.

Parameters
[in](limit_width)Limit width size.
[in](limit_height)Limit height size.
[in](layout)Direction of text writing.
[in](*fmt)Format specifier.
[in](...)Arguments for format specifier.
Returns
Calculated font size.
Note
This process takes time.
Attention
Note that the calculated font size may not exactly meet the size limit.
This is because the font size is not strictly measured, but only "estimated" by calculation.
Here is the call graph for this function:

◆ cdrawString()

uint16_t OpenFontRender::cdrawString ( const char *  str,
int32_t  x = 0,
int32_t  y = 0,
uint16_t  fg = 0xFFFF,
uint16_t  bg = 0x0000,
Layout  layout = Layout::Horizontal 
)

Renders text as Top-Center.

Parameters
[in](*str)String to draw.
[in](x)Drawing start position (x-coordinate).
[in](y)Drawing start position (y-coordinate).
[in](fg)16 bit rgb color for text.
[in](bg)16 bit rgb color for background.
[in](layout)Direction of writing.
Returns
Number of characters success to write.
Warning
Vertical is not yet supported (will be implemented in the future).
Deprecated:

It is recommended to use the printf or drawString functions in combination with optional methods such as setAlignment function.

It will be removed in the future.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cprintf()

uint16_t OpenFontRender::cprintf ( const char *  fmt,
  ... 
)

Renders text as Top-Center with format specifier.

Parameters
[in](*fmt)Format specifier.
[in](...)Arguments for format specifier.
Returns
Number of characters success to write.
Deprecated:

It is recommended to use the printf or drawString functions in combination with optional methods such as setAlignment function.

It will be removed in the future.

Here is the call graph for this function:

◆ drawChar()

FT_Error OpenFontRender::drawChar ( char  character,
int32_t  x = 0,
int32_t  y = 0,
uint16_t  fg = 0xFFFF,
uint16_t  bg = 0x0000,
Align  align = Align::Left 
)

Render single character.

Parameters
[in](character)Character to draw.
[in](x)Drawing start position (x-coordinate).
[in](y)Drawing start position (y-coordinate).
[in](fg)16 bit rgb color for text.
[in](bg)16 bit rgb color for background.
[in](align)Text alignment.
Returns
Rendering error.
Here is the call graph for this function:

◆ drawHString()

uint16_t OpenFontRender::drawHString ( const char *  str,
int32_t  x,
int32_t  y,
uint16_t  fg,
uint16_t  bg,
Align  align,
Drawing  drawing,
FT_BBox &  abbox,
FT_Error &  error 
)

Renders text horizontally.

Parameters
[in](*str)String to draw.
[in](x)Drawing start position (x-coordinate).
[in](y)Drawing start position (y-coordinate).
[in](fg)16 bit rgb color for text.
[in](bg)16 bit rgb color for background.
[in](align)Text alignment.
[in](drawing)Mode of draw to screen
[out](&abbox)Bounding box around drawn text.
[out](&error)Rendering error.
Returns
Number of characters success to write.
Note
Direct calls to this function are not recommended. This is because it complicates the call.
Instead, it is recommended to use the printf and drawString functions in combination with optional methods such as setFontColor and setAlignment function.
Here is the caller graph for this function:

◆ drawString()

uint16_t OpenFontRender::drawString ( const char *  str,
int32_t  x = 0,
int32_t  y = 0,
uint16_t  fg = 0xFFFF,
uint16_t  bg = 0x0000,
Layout  layout = Layout::Horizontal 
)

Renders text.

Parameters
[in](*str)String to draw.
[in](x)Drawing start position (x-coordinate).
[in](y)Drawing start position (y-coordinate).
[in](fg)16 bit rgb color for text.
[in](bg)16 bit rgb color for background.
[in](layout)Direction of writing.
Returns
Number of characters success to write.
Attention
Vertical is not yet supported (will be implemented in the future).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTextHeight()

uint32_t OpenFontRender::getTextHeight ( const char *  fmt,
  ... 
)

Calculate text height.

Parameters
[in](*fmt)Format specifier.
[in](...)Arguments for format specifier.
Returns
Text height.
Note
This process takes time.
Here is the call graph for this function:

◆ getTextWidth()

uint32_t OpenFontRender::getTextWidth ( const char *  fmt,
  ... 
)

Calculate text width.

Parameters
[in](*fmt)Format specifier.
[in](...)Arguments for format specifier.
Returns
Text width.
Note
This process takes time.
Here is the call graph for this function:

◆ loadFont() [1/2]

FT_Error OpenFontRender::loadFont ( const char *  fpath,
uint8_t  target_face_index = 0 
)

Load font from external memory.

Parameters
[in](*fpath)Font file path.
[in](target_face_index)Load font index. Default is 0.
Returns
FreeType error code. 0 is success.
Note
SD card access is strongly hardware dependent, so for hardware other than M5Stack and Wio Terminal,
you will need to add file manipulation functions to FileSupport.cpp/.h.
Any better solutions are welcome.
Here is the call graph for this function:

◆ loadFont() [2/2]

FT_Error OpenFontRender::loadFont ( const unsigned char *  data,
size_t  size,
uint8_t  target_face_index = 0 
)

Load font from memory.

Parameters
[in](*data)Font data array.
[in](size)Font data array size.
[in](target_face_index)Load font index. Default is 0.
Returns
FreeType error code. 0 is success.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ printf()

uint16_t OpenFontRender::printf ( const char *  fmt,
  ... 
)

Renders text with format specifier.

Parameters
[in](*fmt)Format specifier.
[in](...)Arguments for format specifier.
Returns
Number of characters success to write.
Here is the call graph for this function:

◆ rdrawString()

uint16_t OpenFontRender::rdrawString ( const char *  str,
int32_t  x = 0,
int32_t  y = 0,
uint16_t  fg = 0xFFFF,
uint16_t  bg = 0x0000,
Layout  layout = Layout::Horizontal 
)

Renders text as Top-Right.

Parameters
[in](*str)String to draw.
[in](x)Drawing start position (x-coordinate).
[in](y)Drawing start position (y-coordinate).
[in](fg)16 bit rgb color for text.
[in](bg)16 bit rgb color for background.
[in](layout)Direction of writing.
Returns
Number of characters success to write.
Warning
Vertical is not yet supported (will be implemented in the future).
Deprecated:

It is recommended to use the printf or drawString functions in combination with optional methods such as setAlignment function.

It will be removed in the future.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rprintf()

uint16_t OpenFontRender::rprintf ( const char *  fmt,
  ... 
)

Renders text as Top-Right with format specifier.

Parameters
[in](*fmt)Format specifier.
[in](...)Arguments for format specifier.
Returns
Number of characters success to write.
Deprecated:

It is recommended to use the printf or drawString functions in combination with optional methods such as setAlignment function.

It will be removed in the future.

Here is the call graph for this function:

◆ setCacheSize()

void OpenFontRender::setCacheSize ( unsigned int  max_faces,
unsigned int  max_sizes,
unsigned long  max_bytes 
)

Set FreeType cache size.

Parameters
[in](max_faces)Maximum number of opened FT_Face objects.
[in](max_sizes)Maximum number of opened FT_Size objects.
[in](max_bytes)Maximum number of bytes to use for cached data.
See also
CACHE_SIZE_NO_LIMIT, CACHE_SIZE_MINIMUM
Note
Default is CACHE_SIZE_MINIMUM.

◆ setDrawer()

template<typename T >
void OpenFontRender::setDrawer ( T &  drawer)
inline

Collectively set up screen control functions.

Template Parameters
(T)Screen control class.
Parameters
[in](&drawer)Instance for screen control.
Attention
To use this function, it must be possible to call the following four methods on the instance given as the argument.
drawPixel(x, y, c), drawFastHLine(x, y, w, c), startWrite(), endWrite()
Note
This function only calls the following four methods internally.
setDrawPixel(), setDrawFastHLine(), setStartWrite(), setEndWrite()
Here is the call graph for this function:

◆ unloadFont()

void OpenFontRender::unloadFont ( )

Unload font data.