tbx
0.7.5
|
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 |
Get the height of the font. More... | |
int | width () const |
Get the width of the font. More... | |
Size | size_os () const |
Get the size of the font. More... | |
int | height_os () const |
Get the height of the font. More... | |
int | width_os () const |
Get the width of the font. More... | |
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... | |
Font & | operator= (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... | |
Class to handle painting and measuring text using an outline font.
Font::Font | ( | ) |
Construct an uninitialised font.
Copy another font to it or use the find method before using the font.
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.
fontName | name of the font to find |
width | - width of the font |
height | - height of the font or -1 for same as width |
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.
other | the font to copy |
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.
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
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.
fontName | name of the font to find |
width | - width of the font |
height | - height of the font or -1 for same as width |
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.
text | text to measure |
length | to text or -1 if text is zero terminated |
x | x position relative to beginning of string in OS units. |
y | y position relative to beginning of string in OS units. |
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.
text | text to measure |
length | to text or -1 to measure all |
width | to fit text in in os units |
split_char | character that causes a split before the line end or -1 if none. |
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.
bounds | updated with the bounding box (min inclusive, max exclusive) |
void Font::get_char_bounds_mp | ( | BBox & | bounds, |
char | c | ||
) |
Get bounding box for a character in millipoints.
bounds | bounding box to update with the character size |
c | character to get the size for. |
void Font::get_char_bounds_os | ( | BBox & | bounds, |
char | c | ||
) |
Get bounding box for a character in OS Units.
bounds | bounding box to update with the character size |
c | character to get the size for. |
|
inline |
Get RISC OS font handle.
int Font::height | ( | ) | const |
Get the height of the font.
int Font::height_os | ( | ) | const |
Get the height of the font.
std::string Font::identifier | ( | ) | const |
Return full font identifier string for this font.
The full font identifier includes the name, transformation matrix and encoding
|
inline |
Check if this object is assigned to an outline font on the system.
bool Font::operator!= | ( | const Font & | other | ) |
Check if this object does not refer to the same OS font as another object.
other | font to compare with |
Assign a font to the same OS font as another Font object.
other | font to copy |
bool Font::operator== | ( | const Font & | other | ) |
Check if this object refers to the same OS font as another object.
other | font to compare with |
void Font::paint | ( | int | x, |
int | y, | ||
const std::string & | text, | ||
int | flags = Font::FPF_NONE |
||
) | const |
Paint the font to the screen.
x | left position |
y | position of base line |
text | text to paint to the screen |
flags | paint 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 |
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.
x | left position |
y | position of base line |
text | text to paint to the screen |
length | length of text to paint or -1 for all |
flags | paint 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 |
void Font::read_details | ( | FontDetails & | details | ) | const |
Read the details of the font.
details | structure to fill in with the details |
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
details | structure to fill in with the details |
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.
fore | The foreground colour |
back | The background colour |
colour_offset | The number of colours between the foreground and the background. Defaults to 14 (the maximum). |
Size Font::size | ( | ) | const |
Get the size of the font.
Size Font::size_os | ( | ) | const |
Get the size of the font.
tbx::BBox Font::string_bounds_os | ( | const std::string & | text, |
int | max_width = -1 |
||
) | const |
Get bounding box of a string in os units.
text | string to measure max_width maximum width of string is os units or -1 for maximum possible |
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.
text | string to measure |
length | length of string or -1 to measure to terminating char 0 max_width maximum width of string is os units or -1 for maximum possible |
int Font::string_height_os | ( | const std::string & | text, |
int | max_width = -1 |
||
) | const |
Get height of string in os units.
text | string to measure max_width maximum width of string is os units or -1 for maximum possible |
int Font::string_height_os | ( | const char * | text, |
int | length = -1 , |
||
int | max_width = -1 |
||
) | const |
Get height of string in os units.
text | string to measure |
length | length of string or -1 to measure to terminating char 0 max_width maximum width of string is os units or -1 for maximum possible |
tbx::Size Font::string_size_os | ( | const std::string & | text, |
int | max_width = -1 |
||
) | const |
Get size of string in os units.
text | string to measure max_width maximum width of string is os units or -1 for maximum possible |
tbx::Size Font::string_size_os | ( | const char * | text, |
int | length = -1 , |
||
int | max_width = -1 |
||
) | const |
Get size of string in os units.
text | string to measure |
length | length of string or -1 to measure to terminating char 0 max_width maximum width of string is os units or -1 for maximum possible |
int Font::string_width_mp | ( | const std::string & | text | ) | const |
Get the width of a string.
text | the string to measure |
int Font::string_width_mp | ( | const char * | text, |
int | length = -1 |
||
) | const |
Get width of string in millipoints.
text | string to measure |
length | length of string or -1 to measure to terminating char 0 |
int Font::string_width_os | ( | const std::string & | text | ) | const |
Get the width of a string.
text | the string to measure |
int Font::string_width_os | ( | const char * | text, |
int | length = -1 |
||
) | const |
Get width of string in os units.
text | string to measure |
length | length of string or -1 to measure to terminating char 0 |
int Font::width | ( | ) | const |
Get the width of the font.
int Font::width_os | ( | ) | const |
Get the width of the font.