From a71ae8e01314d0653f785a022a898636cdf54424 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Sat, 13 Jan 2018 12:38:55 +0100 Subject: Version 1.0 --- font_lib/API.md | 80 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 30 deletions(-) (limited to 'font_lib/API.md') diff --git a/font_lib/API.md b/font_lib/API.md index b8bc97a..1b79b55 100644 --- a/font_lib/API.md +++ b/font_lib/API.md @@ -1,6 +1,11 @@ # Font Lib API This document describes Font Lib API. Font Lib creates textures for font display on entities. +## Settings +### default_font +Name of the font to be used when no font is given. The font should be registered. +If no default\_font given or if default\_font given but not registered, the first registered font will be used as default. + ## Provided methods ### get\_text\_size **font\_lib.get\_text\_size(font\_name, text)** @@ -8,9 +13,7 @@ This document describes Font Lib API. Font Lib creates textures for font display Computes size for a given font and text **font\_name**: Font name of registered font to use - **text**: Text to be rendered - **Returns**: rendered text width, height ### make\_line\_texture @@ -19,36 +22,25 @@ Computes size for a given font and text Builds texture part for a text line **font\_name**: Font name of registered font to use - **text**: Text to be rendered - **texturew**: Width of the texture (extra text is not rendered) - **x**: Starting x position in texture - **y**: Vertical position of the line in texture - **Returns**: Texture string ### make\_multiline\_texture -**font\_lib.make\_multiline\_texture(font\_name, text, width, height, maxlines, valign, color)** +**font\_lib.make\_multiline\_texture(font\_name, text, width, height, maxlines, halign, valign, color)** Builds texture for a multiline colored text **font\_name**: Font name of registered font to use - **text**: Text to be rendered - **texturew**: Width of the texture (extra text will be truncated) - **textureh**: Height of the texture - **maxlines**: Maximum number of lines - -**valign**: Vertical text align ("top", "bottom" or "center") - -**color**: Color of the text - +**halign**: Horizontal text align ("left", "right" or "center") (optional) +**valign**: Vertical text align ("top", "bottom" or "center") (optional) +**color**: Color of the text (optional) **Returns**: Texture string ### register\_font @@ -57,34 +49,62 @@ Builds texture for a multiline colored text Registers a new font in font_lib. **font\_name**: Name of the font to register (this name will be used to address the font later) +If registering different sizes of the same font, add size in the font name (e.g. times\_10, times\_12...). +**height**: Font height in pixels (all font textures should have the same height) +**widths** : Array of character widths in pixels, indexed by UTF codepoints -**height**: Height of the font in pixels (all font textures should have the same height) - -**widths** : An array containing the width of each font texture, indexed by its UTF code +Font must have a char 0 which will be used to display any unknown char. All textures corresponding to the indexes in **widths** array should be present in textures directory with a name matching the pattern : **font\__.png** -: Name of the font as given in the first argument - -: UTF code of the char in 4 hexadecimal digits +****: Name of the font as given in the first argument +****: UTF code of the char in 4 hexadecimal digits To ease that declaration, a shell is provided to build a .lua file from the texture files (see provided tools). -### set\_fallback\_font -**function font\_lib.set\_fallback\_font(font\_name)** +## Provided tools + +Still in early stage of development, these tools are helpers to create font mods. -Defines the fallback font to be used instead of given font if not registered. +### make_font_texture.sh -**font\_name**: Name of the font to be used as fallback font (has to be registered) +This scripts takes a .ttf file as input and create one .png file per char, that can be used as font texture. Launch it from your future font mod directory. -## Provided tools +__Advice__ + +This script works much better with pixels font, providing the correct height. There is no antialiasing at all, vector fonts and bad heights gives very ugly results. + +__Syntax__ + +**make\_font\_texture.sh ** + +****: A TTF font file to use to create textures. +****: The font name to be used in font_lib (should be simple, with no spaces). +****: Font height to be rendered. ### make_font_lua.sh -Still in early stage of development. +This script analyses textures in textures directory and creates a font\_.lua files with a call to register_font with images information. Launch it from your future font mod directory. + +Once the font\_.lua created, it can be included by a init.lua file or directly renamed to init.lua if you are creating a simple font mod. + +__Syntax__ + +**make\_font_lua.sh ** + +****: The font name to be used in font_lib (same as given to make\_font\_texture.sh) + +### An exemple generating a font mod + + mkdir font_myfont + cd font_myfont + //tools/make_font_texture.sh myfont.ttf myfont 12 + //tools/make_font_lua.sh myfont + mv font_myfont.lua init.lua + + -This script analyses textures in textures directory and creates a font\_.lua files with a call to register_font with images information. -- cgit v1.2.3 From f3970f641eb60bf92492b6715084273cc1bceb74 Mon Sep 17 00:00:00 2001 From: Thomas--S Date: Thu, 1 Feb 2018 16:54:55 +0100 Subject: Seperate signs API from signs definitions Change modnames from *_lib to *_api --- font_lib/API.md | 110 -------------------------------------------------------- 1 file changed, 110 deletions(-) delete mode 100644 font_lib/API.md (limited to 'font_lib/API.md') diff --git a/font_lib/API.md b/font_lib/API.md deleted file mode 100644 index 1b79b55..0000000 --- a/font_lib/API.md +++ /dev/null @@ -1,110 +0,0 @@ -# Font Lib API -This document describes Font Lib API. Font Lib creates textures for font display on entities. - -## Settings -### default_font -Name of the font to be used when no font is given. The font should be registered. -If no default\_font given or if default\_font given but not registered, the first registered font will be used as default. - -## Provided methods -### get\_text\_size -**font\_lib.get\_text\_size(font\_name, text)** - -Computes size for a given font and text - -**font\_name**: Font name of registered font to use -**text**: Text to be rendered -**Returns**: rendered text width, height - -### make\_line\_texture -**font\_lib.make\_line\_texture(font\_name, text, width, x, y)** - -Builds texture part for a text line - -**font\_name**: Font name of registered font to use -**text**: Text to be rendered -**texturew**: Width of the texture (extra text is not rendered) -**x**: Starting x position in texture -**y**: Vertical position of the line in texture -**Returns**: Texture string - -### make\_multiline\_texture -**font\_lib.make\_multiline\_texture(font\_name, text, width, height, maxlines, halign, valign, color)** - -Builds texture for a multiline colored text - -**font\_name**: Font name of registered font to use -**text**: Text to be rendered -**texturew**: Width of the texture (extra text will be truncated) -**textureh**: Height of the texture -**maxlines**: Maximum number of lines -**halign**: Horizontal text align ("left", "right" or "center") (optional) -**valign**: Vertical text align ("top", "bottom" or "center") (optional) -**color**: Color of the text (optional) -**Returns**: Texture string - -### register\_font -**font\_lib.register_font(font\_name, height, widths)** - -Registers a new font in font_lib. - -**font\_name**: Name of the font to register (this name will be used to address the font later) -If registering different sizes of the same font, add size in the font name (e.g. times\_10, times\_12...). -**height**: Font height in pixels (all font textures should have the same height) -**widths** : Array of character widths in pixels, indexed by UTF codepoints - -Font must have a char 0 which will be used to display any unknown char. - -All textures corresponding to the indexes in **widths** array should be present in textures directory with a name matching the pattern : - -**font\__.png** - -****: Name of the font as given in the first argument -****: UTF code of the char in 4 hexadecimal digits - -To ease that declaration, a shell is provided to build a .lua file from the texture files (see provided tools). - -## Provided tools - -Still in early stage of development, these tools are helpers to create font mods. - -### make_font_texture.sh - -This scripts takes a .ttf file as input and create one .png file per char, that can be used as font texture. Launch it from your future font mod directory. - -__Advice__ - -This script works much better with pixels font, providing the correct height. There is no antialiasing at all, vector fonts and bad heights gives very ugly results. - -__Syntax__ - -**make\_font\_texture.sh ** - -****: A TTF font file to use to create textures. -****: The font name to be used in font_lib (should be simple, with no spaces). -****: Font height to be rendered. - -### make_font_lua.sh - -This script analyses textures in textures directory and creates a font\_.lua files with a call to register_font with images information. Launch it from your future font mod directory. - -Once the font\_.lua created, it can be included by a init.lua file or directly renamed to init.lua if you are creating a simple font mod. - -__Syntax__ - -**make\_font_lua.sh ** - -****: The font name to be used in font_lib (same as given to make\_font\_texture.sh) - -### An exemple generating a font mod - - mkdir font_myfont - cd font_myfont - //tools/make_font_texture.sh myfont.ttf myfont 12 - //tools/make_font_lua.sh myfont - mv font_myfont.lua init.lua - - - - - -- cgit v1.2.3