Home | All Classes | Grouped Classes | Index | Search

Class CL_Font

Draws text using system fonts or glyph sprites. More...

Derived from: none
Derived by: none
Group: Display (Fonts)

#include <ClanLib/display.h>

Construction:

CL_Font

Constructs a font.

Attributes:

get_delims

Returns delimiters string.

get_width_offset

Returns width offset.

get_height_offset

Returns height offset.

get_scale

Returns current scale.

get_alpha

Returns current alpha.

get_color

Returns current color.

get_blend_func

Returns blending functions.

get_glyph_rot_hotspot

Returns glyph rotation hotspot.

get_alignment

Returns translation hotspot.

get_height

Returns the drawn height of the entire font or a string.

get_width

Returns the drawn width of a character or string.

get_size

Returns the drawn size of a string.

bounding_rect

Calculate the rectangle that would be occupied by a draw operation.

is_glyph

Returns whether or not a glyph exists for a given character

resource

Resource owning this font, if any.

Operations:

operator =

Copy assignment operator.

bool

Return true if the CL_Font object is valid

draw

Draws text to a graphic context.

draw_to_gb

Inserts data into a CL_GlyphBuffer, treating the glyphs already there as part of a previous draw_to_gb().

draw_glyph

Draws a single glyph to a given spot.

draw_character

Draws a single character to a given spot.

set_delims

Sets delimiters string.

set_width_offset

Sets width offset.

set_height_offset

Sets height offset.

set_scale

Sets scale for x and y directions individually.

set_alpha

Sets transparency.

set_color

Sets the color.

set_blend_func

Sets blending functions.

set_glyph_rot_hotspot

Sets glyph rotation hotspot.

set_alignment

Sets translation hotspot.

get_glyphs

Detailed description:

!group=Display/Fonts! !header=display.h!

A font can be constructed either from a CL_Sprite (aka a bitmap font) or from a system font A bitmap font uses a CL_Sprite as the source for the font glyphs (letters), where each frame frame in the sprite represents one glyph. A string (letter_chars) is then describing which character each glyph corresponds to. If the sprite contains the letters ABCZXY123 in that order, then the string should be "ABCZXY123". A system font uses the underlaying windowing system to create the font glyphs. This means that in Windows you can choose any TTF font, and same applies to X11 if the font server supports it.

Newlines always have a width of zero. Other than that, characters for which glyphs weren't specified have the width of a space.

Unlike CL_Surface and CL_Sprite, scaling affects the calculation of any bounding rectangles (such as the result returned by draw(), bounding_rect(), or get_size(), or the rectangle calculated internally by draw() for alignment). This is because scaling the CL_Font is effectively just changing the point size of the glyphs, and that affects all sorts of things, such as word wrapping.

Word wrapping works automatically whenever you pass CL_Font a destination rectangle or size with non-zero width. CL_Font uses the delims string (which can be changed using the set_delims() method) to determine where divisions between words are. Word wrapping does allow blank characters (characters for which there isn't a glyph supplied) to extend over the border line; this helps wrapped text to remain flush.



Questions or comments, write to the
ClanLib mailing list.