Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
vpFont Class Reference

#include <visp3/core/vpFont.h>

Public Types

enum  vpFontFamily { GENERIC_MONOSPACE, TRUETYPE_FILE }
 

Public Member Functions

 vpFont (unsigned int height=16, const vpFontFamily &fontFamily=TRUETYPE_FILE, const std::string &ttfFilename=std::string(VISP_RUBIK_REGULAR_FONT_RESOURCES))
 
 ~vpFont ()
 
bool drawText (vpImage< unsigned char > &I, const std::string &text, const vpImagePoint &position, unsigned char color) const
 
bool drawText (vpImage< unsigned char > &I, const std::string &text, const vpImagePoint &position, unsigned char color, unsigned char background) const
 
bool drawText (vpImage< vpRGBa > &I, const std::string &text, const vpImagePoint &position, const vpColor &color) const
 
bool drawText (vpImage< vpRGBa > &I, const std::string &text, const vpImagePoint &position, const vpColor &color, const vpColor &background) const
 
unsigned int getHeight () const
 
vpImagePoint getMeasure (const std::string &text) const
 
bool setHeight (unsigned int height)
 

Detailed Description

Font drawing functions for image.

Examples:
testGenericTracker.cpp, and testImageDraw.cpp.

Definition at line 55 of file vpFont.h.

Member Enumeration Documentation

◆ vpFontFamily

Enumerator
GENERIC_MONOSPACE 
TRUETYPE_FILE 

Definition at line 58 of file vpFont.h.

Constructor & Destructor Documentation

◆ vpFont()

vpFont::vpFont ( unsigned int  height = 16,
const vpFontFamily fontFamily = TRUETYPE_FILE,
const std::string &  ttfFilename = std::string(VISP_RUBIK_REGULAR_FONT_RESOURCES) 
)

Creates a new font class with given height.

Note
The vpFontFamily::GENERIC_MONOSPACE font supports ASCII characters only. It was generated on the base of the generic monospace font from Gdiplus.
Parameters
[in]height: Initial font height value in pixels. By default it is equal to 16 pixels.
[in]fontFamily: Font family in TTF format.
[in]ttfFilename: Path to the TTF file if needed. Can contain multiple paths separated by ;character. The first valid path that is found is used.

Definition at line 2268 of file vpFont.cpp.

◆ ~vpFont()

vpFont::~vpFont ( )

Destructor.

Definition at line 2276 of file vpFont.cpp.

Member Function Documentation

◆ drawText() [1/4]

bool vpFont::drawText ( vpImage< unsigned char > &  I,
const std::string &  text,
const vpImagePoint position,
unsigned char  color 
) const

Draws a text at the image.

Parameters
[in,out]I: Image where we draw text.
[in]text: A text to draw.
[in]position: A position to draw text.
[in]color: A color of the text.
Returns
A result of the operation.
Examples:
testGenericTracker.cpp, and testImageDraw.cpp.

Definition at line 2291 of file vpFont.cpp.

◆ drawText() [2/4]

bool vpFont::drawText ( vpImage< unsigned char > &  I,
const std::string &  text,
const vpImagePoint position,
unsigned char  color,
unsigned char  background 
) const

Draws a text at the image. Fills the text background by given color.

Parameters
[in,out]I: Image where we draw text.
[in]text: A text to draw.
[in]position: A position to draw text.
[in]color: A color of the text.
[in]background: Background color.
Returns
a result of the operation.

Definition at line 2308 of file vpFont.cpp.

◆ drawText() [3/4]

bool vpFont::drawText ( vpImage< vpRGBa > &  I,
const std::string &  text,
const vpImagePoint position,
const vpColor color 
) const

Draws a text at the image.

Parameters
[in,out]I: Image where we draw text.
[in]text: A text to draw.
[in]position: A position to draw text.
[in]color: A color of the text.
Returns
A result of the operation.

Definition at line 2324 of file vpFont.cpp.

◆ drawText() [4/4]

bool vpFont::drawText ( vpImage< vpRGBa > &  I,
const std::string &  text,
const vpImagePoint position,
const vpColor color,
const vpColor background 
) const

Draws a text at the image. Fills the text background by given color.

Parameters
[in,out]I: Image where we draw text.
[in]text: A text to draw.
[in]position: A position to draw text.
[in]color: A color of the text.
[in]background: Background color.
Returns
a result of the operation.

Definition at line 2341 of file vpFont.cpp.

◆ getHeight()

unsigned int vpFont::getHeight ( ) const

Gets height of the font in pixels.

Returns
Current height of the font.

Definition at line 2352 of file vpFont.cpp.

◆ getMeasure()

vpImagePoint vpFont::getMeasure ( const std::string &  text) const

Gets text bounding box size.

Returns
The width (j) and height (i) of the text bounding box.
Examples:
testImageDraw.cpp.

Definition at line 2362 of file vpFont.cpp.

◆ setHeight()

bool vpFont::setHeight ( unsigned int  height)

Sets a new height value to font.

Parameters
[in]height: A new height value in pixels.
Returns
A result of the operation.

Definition at line 2374 of file vpFont.cpp.