Chemical Data Processing Library C++ API - Version 1.2.0
Public Member Functions | List of all members
CDPL::Vis::FontMetrics Class Referenceabstract

An interface class with methods that provide information about the metrics of a font. More...

#include <FontMetrics.hpp>

+ Inheritance diagram for CDPL::Vis::FontMetrics:

Public Member Functions

virtual ~FontMetrics ()
 Virtual destructor. More...
 
virtual void setFont (const Font &font)=0
 Specifies the font for which to obtain the metrics. More...
 
virtual double getAscent () const =0
 Returns the ascent of the font. More...
 
virtual double getDescent () const =0
 Returns the descent of the font. More...
 
virtual double getHeight () const =0
 Returns the height of the font. More...
 
virtual double getLeading () const =0
 Returns the leading of the font. More...
 
virtual double getWidth (const std::string &str) const =0
 Returns the total advance width for the characters in the string str. More...
 
virtual double getWidth (char ch) const =0
 Returns the advance width for the character ch. More...
 
virtual void getBounds (const std::string &str, Rectangle2D &bounds) const =0
 Returns the total bounding rectangle for the characters in the string str. More...
 
virtual void getBounds (char ch, Rectangle2D &bounds) const =0
 Returns the bounding rectangle of the character ch relative to the left-most point on the baseline. More...
 

Detailed Description

An interface class with methods that provide information about the metrics of a font.

Implementations of the FontMetrics interface provide height and width information for a given font and specific character glyphs in that font. Once a font has been specified with setFont(), there are several methods that operate on the font.

The methods

return basic size properties of the font. The ascent is the maximum amount by which characters ascend above the baseline, and the descent is the maximum amount by which characters descend below the baseline. 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. The height metric is the sum of the ascent and descent plus some implementation dependent extra space.

For single characters or strings, the advance width can be obtained by getWidth(). The advance width specifies the distance to a position on the baseline where the next character(s) should be drawn. A bounding rectangle large enough to contain the rendered glyph of a character, or a set of glyphs for a string, can be retrieved by getBounds().

Constructor & Destructor Documentation

◆ ~FontMetrics()

virtual CDPL::Vis::FontMetrics::~FontMetrics ( )
inlinevirtual

Virtual destructor.

Ren

Member Function Documentation

◆ setFont()

virtual void CDPL::Vis::FontMetrics::setFont ( const Font font)
pure virtual

Specifies the font for which to obtain the metrics.

Parameters
fontSpecifies the font for which to retrieve the metrics.

Implemented in CDPL::Vis::QtFontMetrics, and CDPL::Vis::CairoFontMetrics.

◆ getAscent()

virtual double CDPL::Vis::FontMetrics::getAscent ( ) const
pure 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()

Implemented in CDPL::Vis::QtFontMetrics, and CDPL::Vis::CairoFontMetrics.

◆ getDescent()

virtual double CDPL::Vis::FontMetrics::getDescent ( ) const
pure 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()

Implemented in CDPL::Vis::QtFontMetrics, and CDPL::Vis::CairoFontMetrics.

◆ getHeight()

virtual double CDPL::Vis::FontMetrics::getHeight ( ) const
pure 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.

Implemented in CDPL::Vis::QtFontMetrics, and CDPL::Vis::CairoFontMetrics.

◆ getLeading()

virtual double CDPL::Vis::FontMetrics::getLeading ( ) const
pure 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.

Implemented in CDPL::Vis::QtFontMetrics, and CDPL::Vis::CairoFontMetrics.

◆ getWidth() [1/2]

virtual double CDPL::Vis::FontMetrics::getWidth ( const std::string &  str) const
pure 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.

Implemented in CDPL::Vis::QtFontMetrics, and CDPL::Vis::CairoFontMetrics.

◆ getWidth() [2/2]

virtual double CDPL::Vis::FontMetrics::getWidth ( char  ch) const
pure 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.

Implemented in CDPL::Vis::QtFontMetrics, and CDPL::Vis::CairoFontMetrics.

◆ getBounds() [1/2]

virtual void CDPL::Vis::FontMetrics::getBounds ( const std::string &  str,
Rectangle2D bounds 
) const
pure 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.

Implemented in CDPL::Vis::QtFontMetrics, and CDPL::Vis::CairoFontMetrics.

◆ getBounds() [2/2]

virtual void CDPL::Vis::FontMetrics::getBounds ( char  ch,
Rectangle2D bounds 
) const
pure 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.

Implemented in CDPL::Vis::QtFontMetrics, and CDPL::Vis::CairoFontMetrics.


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