The text module contains two subparts.
-
The first part is the one you expect: a module that allows you
to load font and draw text.
-
The second one is made of types and of a single globla variable
that contains coordinates to draw text in a very specific fashion.
This very specific fashion can be display a 3D rotating text or
any kind of demoscene like effect.
The text module header is lapin/text.h
typedef enum e_bunny_align
{
 
BAL_LEFT = 0,
 
BAL_TOP = 0,
 
BAL_MIDDLE = 1,
 
BAL_RIGHT = 2,
 
BAL_BOTTOM = 2,
 
BAL_JUSTIFY = 3,
}
t_bunny_align;
Description
  This enumeration helps you to configure
t_bunny_font by allowing you
to precise how you want your text to be aligned horizontaly and verticaly.
Symbols
-
BAL_LEFT :
  Set to t_bunny_font.halign, it precises the text must be horizontaly
aligned on left.
-
BAL_MIDDLE :
  Set to t_bunny_font.halign, it precises the text must be horizontaly
centered.
-
BAL_RIGHT :
  Set to t_bunny_font.halign, it precises the text must be horizontaly
aligned on right.
-
BAL_TOP :
  Set to t_bunny_font.valign, it precises the text must be verticaly
aligned on top.
-
BAL_MIDDLE :
  Set to t_bunny_font.valign, it precises the text must be verticaly
centered.
-
BAL_BOTTOM :
  Set to t_bunny_font.valign, it precises the text must be verticaly
aligned on bottom.
-
BAL_JUSTIFY :
  Set to t_bunny_font.halign, it precises the text must be stretched
horizontaly thanks to wider spaces between words.
  Set to t_bunny_font.valign, it precises the text must be stretched
verticaly thanks to wider spaces between lines.
INDEX
Known bugs
- Horizontal justify does not work flawlessly.
-
Sometimes, characters that overflow horizontaly, even when
they are drawn on the next line are also drawn on the original one.
-
Valgrind report a buffer overflow of 1 byte.
Attributes
-
t_bunny_clipable clipable:
  The clipable used as base by t_bunny_font.
-
const size_t _private[3]:
  Private fields you must not modify or your program may crash.
-
const char * string:
  The string that will be draw when bunny_draw is called with
the t_bunny_font.
-
size_t string_offset :
  The first index in string that will be displayed.
-
size_t string_len :
  The length of the displayed string.
-
t_bunny_align halign :
  The horizontal alignment of the text.
-
t_bunny_align valign :
  The vertical alignment of the text.
-
unsigned int color :
  The color of the text.
On picture based font, this field is used as color mask, so it will
fully work well only if your font is made of white, gray or black.
A red font, for example, will not become blue if you set blue as color,
but black because it will erase the red component without having
any effects on other components.
-
unsigned int outline :
  The color of the lining that runs around characters.
Currently only available for TTF based t_bunny_font.
-
double outline_size :
  The width of the lining that runs around characters.
Currently only available for TTF based t_bunny_font.
-
t_bunny_position offset :
  The offset in pixels that moves where to text will be written.
-
t_bunny_size glyph_size :
  The size of the glyph. It is copied straight from the glyph_size
parameter of bunny_load_font.
TTF based font use this field as the size of the written text and
only care about size->height.
Picture based font use this field as clip size to extract letters
from the picture containing the font.
-
t_bunny_size interglyph_space :
  Arbiter space betwen characters.
Configuration file format
You can set properties of a t_bunny_front thanks to a file at runtime.
This allow you to get rid of a lot of configuration and to create space
for any outside editor.
INI format and complete field description
The t_bunny_font configuration file extend the t_bunny_clipable configuration file
format. You should read it before going on if you do not know it yet.
Every t_bunny_clipable fields are available in the t_bunny_font format.
Mandatory fields
-
RessourceFile, as for t_bunny_clipable is mandatory. It contains
in this case not the picture that will be painted inside the clipable but
the font that will be used to write. It can be a true type font or a bitmap
font.
RessourceFile="Font file or picture file that will be loaded and used a font."
-
BoxSize is an array of two integers. It define the size in pixel of the
drawing surface of the t_bunny_font.
BoxSize=XSize,YSize
-
GlyphSize is an array of one or two integers.
It define the size of a single character.
For true type font, a single value is enough: it will be used as height.
For bitmap font, two values are required for width and height of the glyph
inside the RessourceFile. If a single value is used, then it will be used
for both width and height, so it could fit for square characters.
GlyphSize=XSize,YSize
GlyphSize=Size
Optionnal fields
-
The String field is the one that will contains the text to display.
Default value of String is "". If several values are set, exploiting
this field like an array, they are concatenated.
String="This is the Bunny Library!"
-
StringOffset allow you to define a subpart of the string to be displayed.
Characters before StringOffset in String will not be drawn.
Default value for StringOffset is 0.
StringOffset=3
-
StringLength allow you to define a subpart of the string to be displayed.
Characters after StringLength + StringOffset in String will not be drawn.
DefaultValue for StringOffset is the length of String.
StringLength=5
-
HorizontalAlign allow you to precise if the text will be aligned on the left
with "Left", the center with "Middle", the right with "Right" or justified with
"Justify".
HorizontalAlign="Left"
-
VerticalAlign allow you to precise if the text will be aligned on the top
with "Top", the center with "Middle", the bottom with "Bottom" or justified with
"Justify".
VerticalAlign="Justify"
-
Color define the color of the text that will be written. It is a collection
of integer between 0 and 255 used as color components.
It can be one field long to create a grey color.
It can be three fields long to create a RGB color with no transparency.
It can be four fields long to create a RGBA mask.
  Color=GreyLevel
  Color=Red,Green,Blue
  Color=Red,Green,Blue,Alpha
-
OutlineColor define the color of the lining of the text that will be written.
It works the same way as Color, it is a collection of integer between 0 and 255
used as components.
It can be one field long to create a grey color.
It can be three fields long to create a RGB color with no transparency.
It can be four fields long to create a RGBA mask.
  OutlineColor=GreyLevel
  OutlineColor=Red,Green,Blue
  OutlineColor=Red,Green,Blue,Alpha
-
OutlineSize is the thickness of the lining of the text.
OutlineSize=5
-
Interglyph is an array of one or two elements matching the space between
each characters on X and Y.
Interglyph=2,3
-
Scrolling is an offset that affect the drawing of the text. It is an array
of two values for X and Y.
Scrolling=10,30
DAB format
Not documented yet.
CSV format
Not documented yet.
XML format
Not documented yet.
LUA format
Not documented yet.
JSON format
Not documented yet.
YAML format
Not documented yet.
LISP format
Not documented yet.
INDEX
Error values and logs
On error, bunny_errno is set to:
Logs written by this function are tagged with "ressource"
and "text" labels.
INDEX
k
Description
  Create a
t_bunny_font, which is a textbox with an integrated font
utility. Supported font types are TTF, PNG, 24 bits BMP and JPG. TTF and
other types are not handled exactly the same way but can be both used
the same way.
The returned memory space must be freed with
bunny_delete_clipable.
Parameters
-
unsigned int width :
  The width of the textbox: the picture which underly the t_bunny_font
structure.
-
unsigned int height :
  The height of the tetxbox: the picture which underly the t_bunny_font
structure.
-
const char *file:
  The file to load that will be used to build the t_bunny_font.
Configuration file can be used.
In this case, width, height and size
are ignored so you should use bunny_load_text instead for more simplicity.
-
const t_bunny_position *glyph_size:
  The size of a single character. TTF fonts are only interested in
height. Picture based font will use this parameter to define
the size of the extracted clip.
Error values and logs
On error, bunny_errno is set to:
Logs written by this function are tagged with "ressource"
and "text" labels.
Additional informations
Picture base font format:
Pictures used as font must be a serie of 128 clips of the sent
glyph_size. If you do not need all glyphs, you can just leave
their space empty, but they have to be there. Each clip will be
associated with a character from the 128 length long ASCII table.
You can have several lines of clips, but pay attention to never have
trailing pixels.
Your characters should be white, gray or black to exploit correctly
the color attribute of t_bunny_font.
You should avoid having picture wider than 4096*409 because a lot
of graphic card will not allow it to be loaded inside them and
bunny_load_font will fail with EINVAL in bunny_errno.
INDEX
Description
  This structure is part of the
t_bunny_letter structure.
It represents a single line in a 2D space, which goes from
(x0, y0) to (x1, y1).
Attributes
-
int x0 :
  The beginning of the line on the X axis.
-
int y0 :
  The beginning of the line on the Y axis.
-
int x1 :
  The end of the line on the X axis.
-
int y1 :
  The end of the line on the Y axis.
INDEX
Description
  This structure contains a specific amount of lines that compose
a letter.
Characters amplitude is 0-20 on both axis.
INDEX
typedef enum e_bunny_letter_tab
{
 
BFT_A,
 
BFT_B,
 
BFT_C,
 
BFT_D,
 
BFT_E,
 
BFT_F,
 
BFT_G,
 
BFT_H,
 
BFT_I,
 
BFT_J,
 
BFT_K,
 
BFT_L,
 
BFT_M,
 
BFT_N,
 
BFT_O,
 
BFT_P,
 
BFT_Q,
 
BFT_R,
 
BFT_S,
 
BFT_T,
 
BFT_U,
 
BFT_V,
 
BFT_W,
 
BFT_X,
 
BFT_Y,
 
BFT_Z,
 
BFT_0,
 
BFT_1,
 
BFT_2,
 
BFT_3,
 
BFT_4,
 
BFT_5,
 
BFT_6,
 
BFT_7,
 
BFT_8,
 
BFT_9,
 
BFT_EXCLAMATION,
 
LAST_BUNNY_FONT
}
t_bunny_letter_tab;
INDEX