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

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

#include <QtFontMetrics.hpp>

+ Inheritance diagram for CDPL::Vis::QtFontMetrics:

Public Member Functions

 QtFontMetrics (QPaintDevice *paint_dev=0)
 Constructs a font metrics object for Qt's default font and the given paint device. More...
 
 ~QtFontMetrics ()
 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 Qt rendering backend.

QtFontMetrics is implemented by wrapping a corresponding QFontMetrics instance created for the font specified by setFont(). For more information about QFontMetrics and the Qt Toolkit see [QTDOC].

Constructor & Destructor Documentation

◆ QtFontMetrics()

CDPL::Vis::QtFontMetrics::QtFontMetrics ( QPaintDevice *  paint_dev = 0)

Constructs a font metrics object for Qt's default font and the given paint device.

Parameters
paint_devA pointer to the Qt paint device, or null if unspecified.

◆ ~QtFontMetrics()

CDPL::Vis::QtFontMetrics::~QtFontMetrics ( )

Destructor.

Member Function Documentation

◆ setFont()

void CDPL::Vis::QtFontMetrics::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::QtFontMetrics::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::QtFontMetrics::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::QtFontMetrics::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::QtFontMetrics::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::QtFontMetrics::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::QtFontMetrics::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::QtFontMetrics::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::QtFontMetrics::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: