Chemical Data Processing Library C++ API - Version 1.1.1
Public Member Functions | List of all members
CDPL::Vis::CairoFontMetrics Class Reference

Implements the FontMetrics interface for the Cairo rendering backend. More...

#include <CairoFontMetrics.hpp>

+ Inheritance diagram for CDPL::Vis::CairoFontMetrics:

Public Member Functions

 CairoFontMetrics (const CairoPointer< cairo_t > &cairo_ctxt)
 Constructs a font metrics object that operates on the Cairo drawing context specified by cairo_ctxt. More...
 
 ~CairoFontMetrics ()
 Destructor. More...
 
void setFont (const Font &font)
 Specifies the font for which to obtain the metrics. More...
 
double getAscent () const
 Returns the ascent of the font. More...
 
double getDescent () const
 Returns the descent of the font. More...
 
double getHeight () const
 Returns the height of the font. More...
 
double getLeading () const
 Returns the leading of the font. More...
 
double getWidth (const std::string &str) const
 Returns the total advance width for the characters in the string str. More...
 
double getWidth (char ch) const
 Returns the advance width for the character ch. More...
 
void getBounds (const std::string &str, Rectangle2D &bounds) const
 Returns the total bounding rectangle for the characters in the string str. More...
 
void getBounds (char ch, Rectangle2D &bounds) const
 Returns the bounding rectangle of the character ch relative to the left-most point on the baseline. More...
 
- Public Member Functions inherited from CDPL::Vis::FontMetrics
virtual ~FontMetrics ()
 Virtual destructor. More...
 

Detailed Description

Implements the FontMetrics interface for the Cairo rendering backend.

For more information about the Cairo 2D Graphics Library see [CAIRO].

Constructor & Destructor Documentation

◆ CairoFontMetrics()

CDPL::Vis::CairoFontMetrics::CairoFontMetrics ( const CairoPointer< cairo_t > &  cairo_ctxt)

Constructs a font metrics object that operates on the Cairo drawing context specified by cairo_ctxt.

Parameters
cairo_ctxtThe Cairo drawing context.
Exceptions
Base::NullPointerExceptionif cairo_ctxt is null.

◆ ~CairoFontMetrics()

CDPL::Vis::CairoFontMetrics::~CairoFontMetrics ( )

Destructor.

Member Function Documentation

◆ setFont()

void CDPL::Vis::CairoFontMetrics::setFont ( const Font font)
virtual

Specifies the font for which to obtain the metrics.

Parameters
fontSpecifies the font for which to retrieve the metrics.

Implements CDPL::Vis::FontMetrics.

◆ getAscent()

double CDPL::Vis::CairoFontMetrics::getAscent ( ) const
virtual

Returns the ascent of the font.

The ascent is the maximum distance from the baseline to the highest position characters extend to. Some font designers break this rule, e.g. when they put more than one accent on top of a character, or to accommodate an unusual character in an exotic language, so it is possible (though rare) that this value will be too small.

Returns
The ascent of the font.
See also
getDescent()

Implements CDPL::Vis::FontMetrics.

◆ getDescent()

double CDPL::Vis::CairoFontMetrics::getDescent ( ) const
virtual

Returns the descent of the font.

The descent is the distance from the baseline to the lowest position characters extend to. Some font designers break this rule, e.g. to accommodate an unusual character in an exotic language, so it is possible (though rare) that this value will be too small.

Returns
The descent of the font.
See also
getAscent()

Implements CDPL::Vis::FontMetrics.

◆ getHeight()

double CDPL::Vis::CairoFontMetrics::getHeight ( ) const
virtual

Returns the height of the font.

The returned height is the sum of the ascent and descent plus some possible implementation dependent extra space.

Returns
The height of the font.

Implements CDPL::Vis::FontMetrics.

◆ getLeading()

double CDPL::Vis::CairoFontMetrics::getLeading ( ) const
virtual

Returns the leading of the font.

The leading, or interline spacing, is the logical amount of space to be reserved between the descent of one line of text and the ascent of the next line.

Returns
The leading of the font.

Implements CDPL::Vis::FontMetrics.

◆ getWidth() [1/2]

double CDPL::Vis::CairoFontMetrics::getWidth ( const std::string &  str) const
virtual

Returns the total advance width for the characters in the string str.

The advance is the distance from the leftmost point to the rightmost point on the string's baseline. Note that the advance of a string is not necessarily the sum of the advances of its characters.

Parameters
strThe string to be measured.
Returns
The total advance width for the characters in str.

Implements CDPL::Vis::FontMetrics.

◆ getWidth() [2/2]

double CDPL::Vis::CairoFontMetrics::getWidth ( char  ch) const
virtual

Returns the advance width for the character ch.

The advance width is the distance from the leftmost point to the rightmost point on the character's baseline.

Parameters
chThe character to be measured.
Returns
The advance width for ch.

Implements CDPL::Vis::FontMetrics.

◆ getBounds() [1/2]

void CDPL::Vis::CairoFontMetrics::getBounds ( const std::string &  str,
Rectangle2D bounds 
) const
virtual

Returns the total bounding rectangle for the characters in the string str.

The bounding rectangle always covers at least the set of pixels the text would cover if drawn at (0, 0). Note that the bounding rectangle may extend to the left of (0, 0), e.g. for italicized fonts, and that the width of the returned rectangle might be different than what the getWidth() method returns. Furthermore, the bounding rectangle usually extends both above and below the baseline.

Parameters
strThe string for which to calculate the bounding rectangle.
boundsA rectangle holding the calculated bounds.
Note
Newline characters are processed as normal characters, not as linebreaks.

Implements CDPL::Vis::FontMetrics.

◆ getBounds() [2/2]

void CDPL::Vis::CairoFontMetrics::getBounds ( char  ch,
Rectangle2D bounds 
) const
virtual

Returns the bounding rectangle of the character ch relative to the left-most point on the baseline.

Note that the bounding rectangle may extend to the left of (0, 0), e.g. for italicized fonts, and that the text output may cover all pixels in the bounding rectangle. Furthermore, the bounding rectangle usually extends both above and below the baseline.

Parameters
chThe character for which to calculate the bounding rectangle.
boundsA rectangle holding the calculated bounds.

Implements CDPL::Vis::FontMetrics.


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