Top |
enum | GrxFontWeight |
enum | GrxFontSlant |
enum | GrxFontWidth |
enum | GrxTextHAlign |
enum | GrxTextVAlign |
GrxFont | |
GrxTextOptions |
The library supports loadable fonts. When in memory they are bitmapped (i.e. not scalable!) fonts.
Under the hood, it uses fontconfig and freetype2. This means than fontconfig
must be configured to allow using bitmap fonts, otherwise grx_font_load()
will not be able to find any fonts. You can also use the fontconfig command
line tools to help find availble fonts. For example, fc-list ":scalable=False"
will list all bitmap fonts.
To bypass fontconfig, use grx_font_load_from_file()
instead.
GrxFont * grx_font_load_from_file (const gchar *filename
,GError **err
);
Loads a font from a file. Only loads the first font face in the file.
the font or NULL
if there was an error
such as the font was not found.
[transfer full][nullable]
GrxFont * grx_font_load_full (const gchar *family
,gint size
,gint dpi
,GrxFontWeight weight
,GrxFontSlant slant
,GrxFontWidth width
,gboolean monospace
,const gchar *lang
,const gchar *script
,GError **err
);
Loads the font that best matches the parameters.
Uses fontconfig for font matching.
family |
the font family name or |
[nullable] |
size |
the preferred size in points or -1 for any size |
|
dpi |
the screen resolution or -1 to ignore dpi |
|
weight |
the font weight (e.g. bold) or -1 for any weight |
|
slant |
the font slant (e.g. italic) or -1 for any slant |
|
width |
the font width (e.g. narrow) or -1 for any width |
|
monospace |
set to |
|
lang |
a RFC-3066-style language code or |
[nullable] |
script |
an ISO 15924 script code or |
[nullable] |
err |
pointer to hold an error |
GrxFont * grx_font_load (const gchar *family
,gint size
,GError **err
);
Loads the font that best matches the parameters.
Uses fontconfig for font matching. This function is dpi aware, so the result depends on the currently selected video driver and possibly the video mode.
family |
the font family name or |
[nullable] |
size |
the preferred size or -1 for any size |
|
err |
pointer to hold an error |
void
grx_font_unref (GrxFont *font
);
Decreases the reference count on font
.
When the reference count reaches 0, font
is freed.
const gchar *
grx_font_get_family (GrxFont *font
);
Gets the name of the font family.
const gchar *
grx_font_get_style (GrxFont *font
);
Gets the name of the font style.
gint
grx_font_get_height (GrxFont *font
);
Gets the height of the font in pixels.
gint
grx_font_get_width (GrxFont *font
);
Gets the width of the font in pixels.
gint grx_font_dump (GrxFont *font
,GrxContext *context
,gint start
,GrxColor fg
,GrxColor bg
);
Draws as many glyphs as possible in the clip box of the specified context.
If all of the glyphs do no fit, an index will be returned. This index can
be passed to start
to draw the next "page" of glyphs.
gint grx_font_get_char_width (GrxFont *font
,gunichar c
);
Gets the width of a character using the specified font.
gint grx_font_get_char_height (GrxFont *font
,gunichar c
);
Gets the height of a character using the specified font.
gint grx_font_get_text_width (GrxFont *font
,const gchar *text
);
Gets the width of a string using the specified font.
The string must contain valid UTF-8. Check using g_utf8_validate()
first if
text
is from an unknown source.
gint grx_font_get_text_height (GrxFont *font
,const gchar *text
);
Gets the height of a string using the specified font.
The string must contain valid UTF-8. Check using g_utf8_validate()
first if
text
is from an unknown source.
void grx_draw_text (const gchar *text
,gint x
,gint y
,GrxTextOptions *options
);
Draws the text at the specified coordinates using options
.
The position of the text relative to the coordinates will depend on the
alignment given in options
.
text |
The text to draw |
|
x |
The x coordinate |
|
y |
The y coordinate |
|
options |
GrxTextOptions to control how the text is drawn |
GrxTextOptions * grx_text_options_new (GrxFont *font
,GrxColor fg
);
Allocate a text options structure with background color set to GRX_COLOR_NONE, horizontal alignment of GRX_TEXT_HALIGN_LEFT and vertival alignment of GRX_TEXT_VALIGN_TOP.
This structure is passed to text drawing functions to provide information on how to draw the text.
GrxTextOptions * grx_text_options_new_full (GrxFont *font
,GrxColor fg
,GrxColor bg
,GrxTextHAlign h_align
,GrxTextVAlign v_align
);
Allocate a text options structure.
This structure is passed to text drawing functions to provide information on how to draw the text.
GrxTextOptions *
grx_text_options_ref (GrxTextOptions *options
);
Increases the reference count to options
.
void
grx_text_options_unref (GrxTextOptions *options
);
Decreases the reference count on options
.
When the reference count reaches 0, options
is freed.
GrxFont *
grx_text_options_get_font (GrxTextOptions *options
);
Gets the font.
void grx_text_options_set_font (GrxTextOptions *options
,GrxFont *font
);
Sets the font.
GrxColor
grx_text_options_get_fg_color (GrxTextOptions *options
);
Gets the forground color.
void grx_text_options_set_fg_color (GrxTextOptions *options
,GrxColor fg
);
Sets the forground color.
GrxColor
grx_text_options_get_bg_color (GrxTextOptions *options
);
Gets the background color.
void grx_text_options_set_bg_color (GrxTextOptions *options
,GrxColor bg
);
Sets the background color.
GrxTextHAlign
grx_text_options_get_h_align (GrxTextOptions *options
);
Gets the horizontal alignment.
void grx_text_options_set_h_align (GrxTextOptions *options
,GrxTextHAlign h_align
);
Sets the horizontal alignment.
GrxTextVAlign
grx_text_options_get_v_align (GrxTextOptions *options
);
Gets the vertical alignment.
void grx_text_options_set_v_align (GrxTextOptions *options
,GrxTextVAlign v_align
);
Sets the vertical alignment.