Bienvenue sur le site de la LibLapin.
Jetez un coup d'oeil en bas de la page pour choisir votre niveau de documentation en fonction de votre niveau avec la LibLapin.
Pour l'instant, c'est réglé sur 'Manuel complet'. Si c'est votre première fois avec la LibLapin, il vaudrait mieux choisir 'Débutant'.
De même, n'oubliez pas de préciser une version de la bibliothèque.

LibLapin's logo

LibLapin

Text





The text module contains two subparts.

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‌_‌b‌u‌n‌n‌y‌_‌a‌l‌i‌g‌n;

Description

     This enumeration helps you to configure t‌_‌b‌u‌n‌n‌y‌_‌f‌o‌n‌t by allowing you to precise how you want your text to be aligned horizontaly and verticaly.

Symbols




INDEX

typedef struct s_bunny_font
{
     t‌_‌b‌u‌n‌n‌y‌_‌c‌l‌i‌p‌a‌b‌l‌e clipable ;
     size_t _private[3] ;
     const char * string ;
     size_t string_offset ;
     size_t string_len ;
     t‌_‌b‌u‌n‌n‌y‌_‌a‌l‌i‌g‌n halign ;
     t‌_‌b‌u‌n‌n‌y‌_‌a‌l‌i‌g‌n valign ;
     unsigned int color ;
     unsigned int outline ;
     double outline_size ;
     t‌_‌b‌u‌n‌n‌y‌_‌p‌o‌s‌i‌t‌i‌o‌n offset ;
     t‌_‌b‌u‌n‌n‌y‌_‌p‌o‌s‌i‌t‌i‌o‌n glyph_size ;
     t‌_‌b‌u‌n‌n‌y‌_‌p‌o‌s‌i‌t‌i‌o‌n interglyph_space ;

} t‌_‌b‌u‌n‌n‌y‌_‌f‌o‌n‌t;

Description

     This structure is a t‌_‌b‌u‌n‌n‌y‌_‌c‌l‌i‌p‌a‌b‌l‌e with additionnal attributes to handle text writing. It is compatible with every function that takes a t‌_‌b‌u‌n‌n‌y‌_‌f‌o‌n‌t, a t‌_‌b‌u‌n‌n‌y‌_‌c‌l‌i‌p‌a‌b‌l‌e/t‌_‌b‌u‌n‌n‌y‌_‌p‌i‌c‌t‌u‌r‌e or a t‌_‌b‌u‌n‌n‌y‌_‌b‌u‌f‌f‌e‌r.

t‌_‌b‌u‌n‌n‌y‌_‌f‌o‌n‌t can turn around a TTF ressource or a picture ressource. Some functionnalities are not available accordingly to the original type.

This structure is a little wrongly named: the structure itself does not represents a font but more a textbox. The t‌_‌b‌u‌n‌n‌y‌_‌c‌l‌i‌p‌a‌b‌l‌e contained by the t‌_‌b‌u‌n‌n‌y‌_‌f‌o‌n‌t is not the font but where the text will be drawn.

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


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‌_‌b‌u‌n‌n‌y‌_‌f‌o‌n‌t configuration file extend the t‌_‌b‌u‌n‌n‌y‌_‌c‌l‌i‌p‌a‌b‌l‌e configuration file format. You should read it before going on if you do not know it yet. Every t‌_‌b‌u‌n‌n‌y‌_‌c‌l‌i‌p‌a‌b‌l‌e fields are available in the t‌_‌b‌u‌n‌n‌y‌_‌f‌o‌n‌t format.

Mandatory fields
  • RessourceFile, as for t‌_‌b‌u‌n‌n‌y‌_‌c‌l‌i‌p‌a‌b‌l‌e 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‌_‌b‌u‌n‌n‌y‌_‌f‌o‌n‌t.

    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


Description

     Create a t‌_‌b‌u‌n‌n‌y‌_‌f‌o‌n‌t, fully configured after a configuration file.

The returned memory space must be freed with b‌u‌n‌n‌y‌_‌d‌e‌l‌e‌t‌e‌_‌c‌l‌i‌p‌a‌b‌l‌e.

Parameters


Return value


Error values and logs

On error, b‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.

  • EINVAL:

    The sent file was invalid or the ressource file inside was invalid.


Logs written by this function are tagged with "ressource" and "text" labels.


Additional informations

Picture base font format:

See b‌u‌n‌n‌y‌_‌l‌o‌a‌d‌_‌f‌o‌n‌t for more details.




INDEX

k

Description

     Create a t‌_‌b‌u‌n‌n‌y‌_‌f‌o‌n‌t, 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 b‌u‌n‌n‌y‌_‌d‌e‌l‌e‌t‌e‌_‌c‌l‌i‌p‌a‌b‌l‌e.

Parameters


Return value


Error values and logs

On error, b‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.

  • EINVAL:

    The sent file is not a font or not a picture, or the picture is too wide.


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‌_‌b‌u‌n‌n‌y‌_‌f‌o‌n‌t.

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 b‌u‌n‌n‌y‌_‌l‌o‌a‌d‌_‌f‌o‌n‌t will fail with EINVAL in b‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o.




INDEX

typedef struct s_bunny_vector_font_line_coord
{
     int x0;
     int y0;
     int x1;
     int y1;

} t‌_‌b‌u‌n‌n‌y‌_‌v‌e‌c‌t‌o‌r‌_‌f‌o‌n‌t‌_‌l‌i‌n‌e‌_‌c‌o‌o‌r‌d;

Description

     This structure is part of the t‌_‌b‌u‌n‌n‌y‌_‌l‌e‌t‌t‌e‌r 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.

Attributes



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‌_‌b‌u‌n‌n‌y‌_‌l‌e‌t‌t‌e‌r‌_‌t‌a‌b;

Description

     This enumeration helps you understanding the way g‌l‌_‌v‌e‌c‌t‌o‌r‌_‌f‌o‌n‌t store its characters.
LAST_BUNNY_FONT is not a valid character but the size of g‌l‌_‌v‌e‌c‌t‌o‌r‌_‌f‌o‌n‌t in letters.



INDEX


Description

     A collection of structure containing coordinates to draw a very special kind of text. The order of letters can be found in the t‌_‌b‌u‌n‌n‌y‌_‌l‌e‌t‌t‌e‌r‌_‌t‌a‌b enumeration.

     Here is an exemple of game that use g‌l‌_‌v‌e‌c‌t‌o‌r‌_‌f‌o‌n‌t:







INDEX