Home | All Classes | Grouped Classes | Index | Search
Draws text in bitmap and system fonts. More...
Derived from:
none
Derived by:
none
Group: Display (Fonts)
#include <ClanLib/display.h>
Construction:
Constructs a font. |
Subclasses:
The return type for draw(), draw_to_gb(), and test_draw(). |
Attributes:
Returns width offset. | |
Returns height offset. | |
Returns baseline. | |
Returns current scale. | |
Returns current alpha. | |
Returns current color. | |
Returns blending functions. | |
Returns angle of glyph rotation. | |
Returns glyph rotation hotspot. | |
Returns angle in degrees of total rotation. | |
Returns the rotation hotspot. | |
Returns translation hotspot. | |
Returns the drawn height of the entire font or a string. | |
Returns the drawn width of a character or string. | |
Returns the drawn size of a string. | |
Returns the glyphs as a CL_Sprite. | |
Returns the glyph-index for a specific letter. | |
Resource owning this sprite, if any. | |
Gets the return value of a draw() without drawing anything. |
Operations:
Copy assignment operator. | |
Draws text to a graphic context. | |
Insert glyphs and the font into a CL_GlyphBuffer. | |
Set width offset. | |
Set height offset. | |
Set baseline. | |
Set scale for x and y directions individually. | |
Sets transparency. | |
Sets the color. | |
Sets blending functions. | |
Sets absolute rotation angle for individual glyphs. | |
Adds angle to current angle for individual glyphs. | |
Sets glyph rotation hotspot. | |
Sets absolute total rotation angle in degrees. | |
Adds angle in degrees to current total angle. | |
Sets total rotation hotspot. | |
Sets translation hotspot. |
Detailed description:
A font can be either constructed from bitmap or from system font (or loaded from a resource as either).
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".
To cut out letters for a bitmap font efficiently, have a look at the alpha clipper in CL_SpriteDescription.
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.
When a font is constructed based on an existing sprite, the sprite is copied into the font, and several properties are changed. Many properties of the font directly change the sprite's properties: the functions that do this are marked 'This property is set inside the glyphs sprite' in the documentation. In addition, when the sprite is immediately loaded, its translation and rotation hotspots are set to origin_top_left:0:0. The translation hotspot of the sprite is important to positioning in general, and cannot be changed within the font's internal sprite by the user. If you need to change it you can always do your own drawing by copying the sprite out using the get_glyphs() method. The rotation hotspot inside the font's internal sprite can be set directly using CL_Font::set_glyph_rotation_hotspot(), but at the cost of making total rotation (i.e. changes to the CL_Font's angle) produce illegible though still vaguely valid results.
Like CL_Surface and CL_Sprite, rotation does not affect the calcluation of any bounding rectangles (such as the result returned by draw() or bounding_rect(), or the rectangle calculated internally by draw() for alignment). However, the height and width offset properties still affect these calcluations, and so does the scale (since 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.)