Rhino C++ API  8.14
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
ON_FontMetrics Class Reference

#include <opennurbs_font.h>

Public Member Functions

 ON_FontMetrics ()=default
 
 ON_FontMetrics (const ON_FontMetrics &)=default
 
 ~ON_FontMetrics ()=default
 
int Ascent () const
 
bool AscentDescentAndUPMAreValid () const
 
int AscentOfCapital () const
 
int AscentOfI () const
 
int AscentOfx () const
 
int Descent () const
 
void Dump (class ON_TextLog &text_log) const
 
double GlyphScale (double text_height) const
 
bool HeightsAreValid () const
 
bool IsSet () const
 
bool IsSetAndValid () const
 
bool IsUnset () const
 
int LineSpace () const
 
ON_FontMetricsoperator= (const ON_FontMetrics &)=default
 
void SetAscentOfCapital (double ascent_of_capital)
 
void SetAscentOfCapital (int ascent_of_capital)
 
void SetAscentOfI (int ascent_of_capital)
 
void SetAscentOfx (double ascent_of_x)
 
void SetAscentOfx (int ascent_of_x)
 
void SetHeights (double ascent, double descent, double UPM, double line_space)
 
void SetHeights (int ascent, int descent, int UPM, int line_space)
 
void SetStrikeout (double strikeout_position, double strikeout_thickness)
 
void SetStrikeout (int strikeout_position, int strikeout_thickness)
 
void SetUnderscore (double underscore_position, double underscore_thickness)
 
void SetUnderscore (int underscore_position, int underscore_thickness)
 
int StrikeoutPosition () const
 
int StrikeoutThickness () const
 
int UnderscorePosition () const
 
int UnderscoreThickness () const
 
int UPM () const
 

Static Public Member Functions

static const ON_FontMetrics Normalize (const ON_FontMetrics &font_metrics)
 
static const ON_FontMetrics Scale (const ON_FontMetrics &font_metrics, double scale)
 

Static Public Attributes

static const double DefaultLineFeedRatio
 1.6 More...
 
static const ON__UINT32 HeightOfCapitalCodePoint
 'I' More...
 
static const ON_FontMetrics LastResortMetrics
 
static const ON_FontMetrics LastResortNormalizedMetrics
 
static const ON_FontMetrics Unset
 All properties are zero. More...
 

Constructor & Destructor Documentation

◆ ON_FontMetrics() [1/2]

ON_FontMetrics::ON_FontMetrics ( )
default

◆ ~ON_FontMetrics()

ON_FontMetrics::~ON_FontMetrics ( )
default

◆ ON_FontMetrics() [2/2]

ON_FontMetrics::ON_FontMetrics ( const ON_FontMetrics )
default

Member Function Documentation

◆ Ascent()

int ON_FontMetrics::Ascent ( ) const

Returns: Signed distance from the baseline to highest point on a glyph outline.

Remarks: If every glyph outline in the font has (0,0) on the baseline, then Ascent() is the maximum glyph bounding box Y.

Ascent typically includes internal leading, the space used for diacritcial marks above capital latin letters. For this reason, Ascent is typically greater than AscentOfCapital.

Windows: = DWRITE_FONT_METRICS.ascent

◆ AscentDescentAndUPMAreValid()

bool ON_FontMetrics::AscentDescentAndUPMAreValid ( ) const

Returns: True if all of the following are true. UPM() > 0 At least one of Ascent() or Descent() is not zero. Ascent() > Descent() None of UPM(), Ascent(), or Descent() is ON_UNSET_INT_INDEX or -ON_UNSET_INT_INDEX.

◆ AscentOfCapital()

int ON_FontMetrics::AscentOfCapital ( ) const

Returns: The font's typographic capital height.

Remarks: The primary uses of AscentOfCapital() are: 1) Calculate a scale factor to produce text with a user specified "text height". 2) To calculate insertion location for ON::TextVerticalAlignment::Middle and ON::TextVerticalAlignment::Top.

From 2005-2018 opennurbs used the ascent of a capital I. Beginning in 2018 this value is taken from the system font metrics so that fonts designed to render Asian language text, symbols, and emojis will display as expected and lines of text containing multiple fonts will render more clearly.

The value (user specified text height)/AscentOfCapital() is used as the scale factor to render glyphs when user interface has provided a "text height" value.

If the capial height property of a font is not available, the ascent of I or H can be used instead. (There are commonly used fonts where using other glyphs gives undesirable results.)OfI.

Windows: = DWRITE_FONT_METRICS.capHeight Apple: = CTFontGetAscent(...)

◆ AscentOfI()

int ON_FontMetrics::AscentOfI ( ) const

◆ AscentOfx()

int ON_FontMetrics::AscentOfx ( ) const

Returns: The font's typographic x-height.

Remarks: The x-height is used to help select a substitute font to use for missing glyphs.

◆ Descent()

int ON_FontMetrics::Descent ( ) const

Returns: Signed distance from the English baseline to lowest point on a glyph outline.

Remarks: This value is typically negative because glyphs for letters like 'g' and 'j' typically have a portion of their outline below the baseline. However, some fonts have positive descent. If every glyph outline in the font has (0,0) on the baseline, then Descent() is the minimum glyph bounding box Y.

Windows: = -DWRITE_FONT_METRICS.descent

◆ Dump()

void ON_FontMetrics::Dump ( class ON_TextLog text_log) const

◆ GlyphScale()

double ON_FontMetrics::GlyphScale ( double  text_height) const

Description: Parameters: height_of_capital - [in] The desired height of typical capital latin letter glyphs. For fonts like Arial, Helvetica, and Times Roman the heights of the H and I glyphs = font's height of capital. Returns: text_height / AscentOfCapital().

◆ HeightsAreValid()

bool ON_FontMetrics::HeightsAreValid ( ) const

Returns: True if all of the following are true. AscentDescentAndUPMAreValid() is true LineSpace() >= Ascent() - Descent() AscentOfCapital() <= Ascent() AscentOfx() <= Ascent()

◆ IsSet()

bool ON_FontMetrics::IsSet ( ) const

Returns true if at least one metric is not zero.

◆ IsSetAndValid()

bool ON_FontMetrics::IsSetAndValid ( ) const

Returns: True if all of the following are true. HeightsAreValid() is true. AscentOfCapital() > 0

◆ IsUnset()

bool ON_FontMetrics::IsUnset ( ) const

Returns true if all metrics are zero

◆ LineSpace()

int ON_FontMetrics::LineSpace ( ) const

Returns: The positive distance to move the base line when moving to a new line of text.

Remarks: For almost every font used to render English text, LineSpace() > (Ascent() - Descent()).

This metric is sometimes called "height", but that term is often confused with (Ascent() - Descent()).

For fonts designed to render horizontal lines of text, LineSpace() is a vertical distance. For fonts designed to render vertical lines of text, LineSpace() is a horizontal distance. Depending on the context, the direction to move can be up, down, left or right.

Windows: = DWRITE_FONT_METRICS.ascent

  • DWRITE_FONT_METRICS.descent
  • DWRITE_FONT_METRICS.lineGap;

◆ Normalize()

static const ON_FontMetrics ON_FontMetrics::Normalize ( const ON_FontMetrics font_metrics)
static

◆ operator=()

ON_FontMetrics& ON_FontMetrics::operator= ( const ON_FontMetrics )
default

◆ Scale()

static const ON_FontMetrics ON_FontMetrics::Scale ( const ON_FontMetrics font_metrics,
double  scale 
)
static

◆ SetAscentOfCapital() [1/2]

void ON_FontMetrics::SetAscentOfCapital ( double  ascent_of_capital)

◆ SetAscentOfCapital() [2/2]

void ON_FontMetrics::SetAscentOfCapital ( int  ascent_of_capital)

◆ SetAscentOfI()

void ON_FontMetrics::SetAscentOfI ( int  ascent_of_capital)

◆ SetAscentOfx() [1/2]

void ON_FontMetrics::SetAscentOfx ( double  ascent_of_x)

◆ SetAscentOfx() [2/2]

void ON_FontMetrics::SetAscentOfx ( int  ascent_of_x)

◆ SetHeights() [1/2]

void ON_FontMetrics::SetHeights ( double  ascent,
double  descent,
double  UPM,
double  line_space 
)

◆ SetHeights() [2/2]

void ON_FontMetrics::SetHeights ( int  ascent,
int  descent,
int  UPM,
int  line_space 
)

◆ SetStrikeout() [1/2]

void ON_FontMetrics::SetStrikeout ( double  strikeout_position,
double  strikeout_thickness 
)

◆ SetStrikeout() [2/2]

void ON_FontMetrics::SetStrikeout ( int  strikeout_position,
int  strikeout_thickness 
)

◆ SetUnderscore() [1/2]

void ON_FontMetrics::SetUnderscore ( double  underscore_position,
double  underscore_thickness 
)

◆ SetUnderscore() [2/2]

void ON_FontMetrics::SetUnderscore ( int  underscore_position,
int  underscore_thickness 
)

◆ StrikeoutPosition()

int ON_FontMetrics::StrikeoutPosition ( ) const

Returns: Signed distance from baseline to center of strikeout. A positive value indicates the strikeout is above the baseline (common). Remarks: The signed distance from the baseline to the bottom of the strikeout is StrikeoutPosition() - StrikeoutThickness()/2.

◆ StrikeoutThickness()

int ON_FontMetrics::StrikeoutThickness ( ) const

Returns: Thickness of strikeout. Remarks: The signed distance from the baseline to the bottom of the strikeout is StrikeoutPosition() - StrikeoutThickness()/2.

◆ UnderscorePosition()

int ON_FontMetrics::UnderscorePosition ( ) const

Returns: Signed distance from baseline to center of underscore. A negative value indicates the underscore is below the baseline (common). Remarks: The signed distance from the baseline to the bottom of the underscore is UnderscorePosition() - UnderscoreThickness()/2.

◆ UnderscoreThickness()

int ON_FontMetrics::UnderscoreThickness ( ) const

Returns: Thickness of underscore Remarks: The signed distance from the baseline to the bottom of the underscore is UnderscorePosition() - UnderscoreThickness()/2.

◆ UPM()

int ON_FontMetrics::UPM ( ) const

Returns: The "units per EM". This is the height and width of the square grid where the font glyphs are designed.
Remarks: The width of the 'M' glyph in a font can be different from UPM. The height of the 'M' glyph in a font is typically less than UPM. In TrueType fonts, UPM is often a power of two and generally 1024 or 2048. In OpenType fonts, UPM is often 1000. In PostScript fonts, UPM is often 1000.

Windows: = DWRITE_FONT_METRICS.designUnitsPerEm

Member Data Documentation

◆ DefaultLineFeedRatio

const double ON_FontMetrics::DefaultLineFeedRatio
static

1.6

ON_FontMetric::DefaultLineFeedRatio*ON_FontMetrics().AscentOfCapital() can be used to cook up a line space value when using the ON_FontMetrics.LineSpace() value defined by the font is not desired.

◆ HeightOfCapitalCodePoint

const ON__UINT32 ON_FontMetrics::HeightOfCapitalCodePoint
static

'I'

UNICODE code point of the glyph used to determine HeightOfCapital() when no reaonable value is available from the font definition. Currently this is the 'I' glyph. Opennurbs has used 'I' since 2005. It is possible 'H' would work as well. All other glyphs, in particular 'M' and 'W', do not work.

◆ LastResortMetrics

const ON_FontMetrics ON_FontMetrics::LastResortMetrics
static

Used when it is impossible to find font metrics (missing font for example) and something valid is required for a computation. Currently LastResortMetrics.UPM() is 2048 and this value is chosen because it is the largest common UPM found in real fonts encountered in March 2018.

◆ LastResortNormalizedMetrics

const ON_FontMetrics ON_FontMetrics::LastResortNormalizedMetrics
static

Used when it is impossible to find normalized font metrics (missing font for example) and something valid is required for a computation.

◆ Unset

const ON_FontMetrics ON_FontMetrics::Unset
static

All properties are zero.