tbx  0.7.6
Classes | Public Types | Public Member Functions | List of all members
tbx::Font Class Reference

Class to handle painting and measuring text using an outline font. More...

#include <font.h>

Public Types

enum  PaintFlags { FPF_NONE = 0, FPF_JUSTIFY =1, FPF_RUBOUT = 2, FPF_OSUNITS =16 }
 Flags to control font painting operation.
 

Public Member Functions

 Font ()
 Construct an uninitialised font. More...
 
 Font (const std::string &font_name, int width, int height=-1)
 Construct a font with the given name and size. More...
 
 Font (const Font &other)
 Construct a font from another font. More...
 
virtual ~Font ()
 Destructor release the OS Font if no other font objects are using it.
 
int handle () const
 Get RISC OS font handle. More...
 
bool is_valid () const
 Check if this object is assigned to an outline font on the system. More...
 
void set_colours (Colour fore, Colour back, int colourOffset=14)
 Set the colours used to paint this font. More...
 
void read_details (FontDetails &details) const
 Read the details of the font. More...
 
void read_details (FullFontDetails &details) const
 Read the full details of the font. More...
 
std::string identifier () const
 Return full font identifier string for this font. More...
 
Size size () const
 Get the size of the font. More...
 
int height () const
 
int width () const
 
Size size_os () const
 Get the size of the font. More...
 
int height_os () const
 
int width_os () const
 
bool find (const std::string &font_name, int width, int height=-1)
 Find the specified font and attach it to this object. More...
 
bool desktop_font ()
 Sets font to current desktop font. More...
 
void paint (int x, int y, const std::string &text, int flags=Font::FPF_NONE) const
 Paint the font to the screen. More...
 
void paint (int x, int y, const char *text, int length=-1, int flags=Font::FPF_NONE) const
 Paint the font to the screen. More...
 
int string_width_mp (const std::string &text) const
 Get the width of a string. More...
 
int string_width_mp (const char *text, int length=-1) const
 Get width of string in millipoints. More...
 
int string_width_os (const std::string &text) const
 Get the width of a string. More...
 
int string_width_os (const char *text, int length=-1) const
 Get width of string in os units. More...
 
int string_height_os (const std::string &text, int max_width=-1) const
 Get height of string in os units. More...
 
int string_height_os (const char *text, int length=-1, int max_width=-1) const
 Get height of string in os units. More...
 
tbx::Size string_size_os (const std::string &text, int max_width=-1) const
 Get size of string in os units. More...
 
tbx::Size string_size_os (const char *text, int length=-1, int max_width=-1) const
 Get size of string in os units. More...
 
tbx::BBox string_bounds_os (const std::string &text, int max_width=-1) const
 Get bounding box of a string in os units. More...
 
tbx::BBox string_bounds_os (const char *text, int length=-1, int max_width=-1) const
 Get bounding box of string in os units. More...
 
void get_char_bounds_mp (BBox &bounds, char c)
 Get bounding box for a character in millipoints. More...
 
void get_char_bounds_os (BBox &bounds, char c)
 Get bounding box for a character in OS Units. More...
 
int find_split_os (const char *text, int length, int width, int split_char=-1)
 Find index where to split a string to fit in the given width. More...
 
int find_index_xy_os (const char *text, int length, int x, int y)
 Find index in a string of the given co-ordinate, rounded to the nearest caret position. More...
 
BBox bounding_box () const
 Get the bounding box (in os coordinates) of the font. More...
 
void get_bounding_box (BBox &bounds) const
 Get the bounding box (in os coordinates) of the font. More...
 
Fontoperator= (const Font &other)
 Assign a font to the same OS font as another Font object. More...
 
bool operator== (const Font &other)
 Check if this object refers to the same OS font as another object. More...
 
bool operator!= (const Font &other)
 Check if this object does not refer to the same OS font as another object. More...
 

Detailed Description

Class to handle painting and measuring text using an outline font.

Constructor & Destructor Documentation

◆ Font() [1/3]

Font::Font ( )

Construct an uninitialised font.

Copy another font to it or use the find method before using the font.

◆ Font() [2/3]

Font::Font ( const std::string &  fontName,
int  width,
int  height = -1 
)

Construct a font with the given name and size.

You can call the is_valid method to check the font was found.

Parameters
fontNamename of the font to find
width- width of the font
height- height of the font or -1 for same as width

◆ Font() [3/3]

Font::Font ( const Font other)

Construct a font from another font.

This object will become a reference to the same OS font as the other font.

Parameters
otherthe font to copy

Member Function Documentation

◆ bounding_box()

BBox Font::bounding_box ( ) const

Get the bounding box (in os coordinates) of the font.

The bounding box is the minimum sized box that will cover all characters in the font.

Returns
bounds bounding box (min inclusive, max exclusive)

◆ desktop_font()

bool Font::desktop_font ( )

Sets font to current desktop font.

Using this give the full flexibility of the font system to display and measure characters in the desktop font. For simple single line text the WimpFont provides a simpler alternative

Returns
true if desktop font can be read and isn't the old style system font

◆ find()

bool Font::find ( const std::string &  fontName,
int  width,
int  height = -1 
)

Find the specified font and attach it to this object.

If the font is not found then the currently attached font is unchanged.

Parameters
fontNamename of the font to find
width- width of the font
height- height of the font or -1 for same as width
Returns
true if the font has found.

◆ find_index_xy_os()

int Font::find_index_xy_os ( const char *  text,
int  length,
int  x,
int  y 
)

Find index in a string of the given co-ordinate, rounded to the nearest caret position.

Parameters
texttext to measure
lengthto text or -1 if text is zero terminated
xx position relative to beginning of string in OS units.
yy position relative to beginning of string in OS units.
Returns
index in string of the given position.

◆ find_split_os()

int Font::find_split_os ( const char *  text,
int  length,
int  width,
int  split_char = -1 
)

Find index where to split a string to fit in the given width.

Parameters
texttext to measure
lengthto text or -1 to measure all
widthto fit text in in os units
split_charcharacter that causes a split before the line end or -1 if none.
Returns
offset of character for split

◆ get_bounding_box()

void Font::get_bounding_box ( BBox bounds) const

Get the bounding box (in os coordinates) of the font.

The bounding box is the minimum sized box that will cover all characters in the font.

Parameters
boundsupdated with the bounding box (min inclusive, max exclusive)

◆ get_char_bounds_mp()

void Font::get_char_bounds_mp ( BBox bounds,
char  c 
)

Get bounding box for a character in millipoints.

Parameters
boundsbounding box to update with the character size
ccharacter to get the size for.

◆ get_char_bounds_os()

void Font::get_char_bounds_os ( BBox bounds,
char  c 
)

Get bounding box for a character in OS Units.

Parameters
boundsbounding box to update with the character size
ccharacter to get the size for.

◆ handle()

int tbx::Font::handle ( ) const
inline

Get RISC OS font handle.

Returns
RISC OS font handle for the font

◆ height()

int Font::height ( ) const
Get the height of the font
Returns
the height in 1/16th points

◆ height_os()

int Font::height_os ( ) const
Get the height of the font
Returns
the height in OS units

◆ identifier()

std::string Font::identifier ( ) const

Return full font identifier string for this font.

The full font identifier includes the name, transformation matrix and encoding

Returns
font identifier string

◆ is_valid()

bool tbx::Font::is_valid ( ) const
inline

Check if this object is assigned to an outline font on the system.

Returns
true if this is valid

◆ operator!=()

bool Font::operator!= ( const Font other)

Check if this object does not refer to the same OS font as another object.

Parameters
otherfont to compare with
Returns
true if this font does not refer to the same font as the other

◆ operator=()

Font & Font::operator= ( const Font other)

Assign a font to the same OS font as another Font object.

Parameters
otherfont to copy
Returns
reference to this object

◆ operator==()

bool Font::operator== ( const Font other)

Check if this object refers to the same OS font as another object.

Parameters
otherfont to compare with
Returns
true if this font refers to the same font as the other

◆ paint() [1/2]

void Font::paint ( int  x,
int  y,
const char *  text,
int  length = -1,
int  flags = Font::FPF_NONE 
) const

Paint the font to the screen.

Parameters
xleft position
yposition of base line
texttext to paint to the screen
lengthlength of text to paint or -1 for all
flagspaint flags, can NONE or one or more of the following: JUSTIFY - justify the text between x,y and the last graphics move position RUBOUT - rub out area behind text, defined be last two graphics move positions OSUNITS - x and y are specified as OS units, if not they are in millipoints

◆ paint() [2/2]

void Font::paint ( int  x,
int  y,
const std::string &  text,
int  flags = Font::FPF_NONE 
) const

Paint the font to the screen.

Parameters
xleft position
yposition of base line
texttext to paint to the screen
flagspaint flags, can NONE or one or more of the following: JUSTIFY - justify the text between x,y and the last graphics move position RUBOUT - rub out area behind text, defined be last two graphics move positions OSUNITS - x and y are specified as OS units, if not they are in millipoints

◆ read_details() [1/2]

void Font::read_details ( FontDetails details) const

Read the details of the font.

Parameters
detailsstructure to fill in with the details

◆ read_details() [2/2]

void Font::read_details ( FullFontDetails details) const

Read the full details of the font.

The full details of the font are the details plus the font identifier

Parameters
detailsstructure to fill in with the details

◆ set_colours()

void Font::set_colours ( Colour  fore,
Colour  back,
int  colour_offset = 14 
)

Set the colours used to paint this font.

The call creates a gradient of colours from the foreground colour in the centre of the letters to the background colour from the current palette. The shades between the colours are used for anti-aliasing which improves the look of the edges on the screen.

Parameters
foreThe foreground colour
backThe background colour
colour_offsetThe number of colours between the foreground and the background. Defaults to 14 (the maximum).

◆ size()

Size Font::size ( ) const

Get the size of the font.

Returns
size of the font in 16ths of a point

◆ size_os()

Size Font::size_os ( ) const

Get the size of the font.

Returns
size of the font in OS Units

◆ string_bounds_os() [1/2]

tbx::BBox Font::string_bounds_os ( const char *  text,
int  length = -1,
int  max_width = -1 
) const

Get bounding box of string in os units.

Parameters
textstring to measure
lengthlength of string or -1 to measure to terminating char 0
max_widthmaximum width of string is os units or -1 for maximum possible
Returns
bounding box of string in os units

◆ string_bounds_os() [2/2]

tbx::BBox Font::string_bounds_os ( const std::string &  text,
int  max_width = -1 
) const

Get bounding box of a string in os units.

Parameters
textstring to measure
max_widthmaximum width of string is os units or -1 for maximum possible
Returns
bounding box of string in os units

◆ string_height_os() [1/2]

int Font::string_height_os ( const char *  text,
int  length = -1,
int  max_width = -1 
) const

Get height of string in os units.

Parameters
textstring to measure
lengthlength of string or -1 to measure to terminating char 0
max_widthmaximum width of string is os units or -1 for maximum possible
Returns
height of string in os units

◆ string_height_os() [2/2]

int Font::string_height_os ( const std::string &  text,
int  max_width = -1 
) const

Get height of string in os units.

Parameters
textstring to measure
max_widthmaximum width of string is os units or -1 for maximum possible
Returns
height of string in os units

◆ string_size_os() [1/2]

tbx::Size Font::string_size_os ( const char *  text,
int  length = -1,
int  max_width = -1 
) const

Get size of string in os units.

Parameters
textstring to measure
lengthlength of string or -1 to measure to terminating char 0
max_widthmaximum width of string is os units or -1 for maximum possible
Returns
size of of string in os units

◆ string_size_os() [2/2]

tbx::Size Font::string_size_os ( const std::string &  text,
int  max_width = -1 
) const

Get size of string in os units.

Parameters
textstring to measure
max_widthmaximum width of string is os units or -1 for maximum possible
Returns
size of string in os units

◆ string_width_mp() [1/2]

int Font::string_width_mp ( const char *  text,
int  length = -1 
) const

Get width of string in millipoints.

Parameters
textstring to measure
lengthlength of string or -1 to measure to terminating char 0
Returns
width of string in millipoints

◆ string_width_mp() [2/2]

int Font::string_width_mp ( const std::string &  text) const

Get the width of a string.

Parameters
textthe string to measure
Returns
length of string in millipoints

◆ string_width_os() [1/2]

int Font::string_width_os ( const char *  text,
int  length = -1 
) const

Get width of string in os units.

Parameters
textstring to measure
lengthlength of string or -1 to measure to terminating char 0
Returns
width of string in os units

◆ string_width_os() [2/2]

int Font::string_width_os ( const std::string &  text) const

Get the width of a string.

Parameters
textthe string to measure
Returns
length of string in OS units

◆ width()

int Font::width ( ) const
Get the width of the font
Returns
the width in 1/16th points

◆ width_os()

int Font::width_os ( ) const
Get the width of the font
Returns
the width in OS units

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