Skip to content
Open
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This modpack provides mods with dynamic display. Mods are :
- **[font_api](https://github.com/pyrollo/display_modpack/tree/master/font_api)**: A library for displaying fonts on entities;
- **[signs_api](https://github.com/pyrollo/display_modpack/tree/master/signs_api)**: A library for the easy creation of signs;
- **[font_metro](https://github.com/pyrollo/display_modpack/tree/master/font_metro)**: A font mod used as default font (includes uppercase, lowercase and accentuated latin letters, usual signs, cyrillic and greek letters)
- **[unifont](https://github.com/pyrollo/display_modpack/tree/master/unifont)**: A lightweight (~2MB) font mod with full Unicode Plane 0 charset (63000+ chars)

- **[boards](https://github.com/pyrollo/display_modpack/tree/master/boards)**: A mod providing school boards (includes *tiny cursive font*, a handwriting style font);
- **[ontime_clocks](https://github.com/pyrollo/display_modpack/tree/master/ontime_clocks)**: A mod providing clocks which display the ingame time;
Expand Down
7 changes: 5 additions & 2 deletions font_api/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Font definition table used by **font_api.register_font** and **font\_api.Font:ne
* `margintop` (optional): Margin (in texture pixels) added on top of each char texture.
* `marginbottom` (optional): Margin (in texture pixels) added at bottom of each char texture.
* `linespacing` (optional): Spacing (in texture pixels) between each lines.
* `getglyph` (optional, advanced usage): Function that takes a Unicode codepoint (number) and returns a custom texture string for the glyph instead of the default `font_{name}_{codepoint}.png` (see *Additional Requirements* below). The texture string can contain filters like `^[sheet` and will be properly escaped when combined.

`margintop`, `marginbottom` and `linespacing` can be negative numbers (default 0) and are to be used to adjust various font styles to each other.

Expand All @@ -118,7 +119,7 @@ Font attributes effects on several lines:\

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 :
All textures corresponding to the indexes in widths array should be present in textures directory with a name matching the pattern (unless using a custom `getglyph` function):

> font\_**{font_name}**_**{utf_code}**.png

Expand Down Expand Up @@ -189,7 +190,7 @@ Returns line(s) height. Takes care of top and bottom margins and line spacing.
Returns the width of a text line. Beware, if line contains any new line char, they are ignored.
* `line`: Line of text which the width will be computed.

### font:renter(text, texturew, textureh, style)
### font:render(text, texturew, textureh, style)
Builds texture for a multiline colored text.
* `text`: Text to be rendered.
* `texturew`: Width of the texture (extra text will be truncated).
Expand All @@ -199,3 +200,5 @@ Builds texture for a multiline colored text.
- `halign`: Horizontal text align: "left"/"center"/"right" (default "center")
- `valign`: Vertical text align: "top"/"middle"/"bottom" (default "middle")
- `color`: Color of the text (default black)

Note: When used in formspec, be sure to **escape** the texture string with `minetest.formspec_escape`.
1 change: 1 addition & 0 deletions font_api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ You can add fonts by installing fonts mod. Be aware that each font comes with nu
Font mods can be found here:

* [Metro](https://github.com/pyrollo/display_modpack/tree/master/font_metro): A multipurpose font with many chars (uppercase, lowercase and accentuated latin letters, usual signs, cyrillic and greek letters).
* [unifont](https://github.com/pyrollo/display_modpack/tree/master/unifont): A lightweight duospaced font with full Unicode Plane 0 charset (63000+ characters).
* [OldWizard](https://github.com/pyrollo/font_oldwizard): An old style gothic font.
* [Botic](https://github.com/pyrollo/font_botic): A scifi style font.

Expand Down
12 changes: 10 additions & 2 deletions font_api/font.lua
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ function Font:make_text_texture(text, texturew, textureh, maxlines,
end

--- Render text with the font in a view
-- Note: When used in formspec, be sure to escape the texture string with
-- `minetest.formspec_escape`.
--
-- @param text Text to be rendered
-- @param texturew Width (in pixels) of the texture (extra text will be truncated)
-- @param textureh Height (in pixels) of the texture (extra text will be truncated)
Expand Down Expand Up @@ -229,7 +232,7 @@ function Font:render(text, texturew, textureh, style)
return ""
end

local x, y, codepoint
local x, y, codepoint, glyph
local texture = ""
local textheight = self:get_height(#lines)

Expand Down Expand Up @@ -258,8 +261,13 @@ function Font:render(text, texturew, textureh, style)

-- Add image only if it is visible (at least partly)
if x + self.widths[codepoint] >= 0 and x <= texturew then
if self.getglyph == nil then
glyph = string.format("font_%s_%04x.png", self.name, codepoint)
else
glyph = self.getglyph(codepoint):gsub("[\\^:]", "\\%0")
end
texture = texture..
string.format(":%d,%d=font_%s_%04x.png", x, y, self.name, codepoint)
string.format(":%d,%d=%s", x, y, glyph)
end
x = x + self.widths[codepoint]
end
Expand Down
2 changes: 1 addition & 1 deletion font_api/fontform.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ local function show_font_formspec(playername)
font:get_height()*1.2, 1, "center", "top", "#fff")
fs = string.format(
"%simage[0.1,%s;4.5,0.8;%s]button_exit[0,%s;4,1;font_%s;]",
fs, line-0.9, texture, line-1, font.name)
fs, line-0.9, minetest.formspec_escape(texture), line-1, font.name)
end
minetest.show_formspec(context.playername, modname..':font_list', fs)
end
Expand Down
8 changes: 7 additions & 1 deletion font_api/registry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,14 @@ end
-- UTF codepoints
-- @key margintop (optional) Margin (in texture pixels) added on top of each
-- char texture.
-- @key marginbottom (optional) dded at bottom of each char texture.
-- @key marginbottom (optional) Margin (in texture pixels) added at bottom of
-- each char texture.
-- @key linespacing (optional) Spacing (in texture pixels) between each lines.
-- @key getglyph (optional, advanced usage) Function that takes a Unicode
-- codepoint (number) and returns a custom texture string for the glyph instead
-- of the default `font_{name}_{codepoint}.png`. The texture string can contain
-- filters like `^[sheet` and will be properly escaped when combined.
--
-- margintop, marginbottom and linespacing can be negative numbers (default 0)
-- and are to be used to adjust various font styles to each other.

Expand Down
2 changes: 1 addition & 1 deletion signs/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ local function display_poster(pos, node, player)
image[0,-0.2;8.4,2;%s]
style_type[textarea;textcolor=#111]
textarea[0.3,1.5;7,8;;%s;]]=],
titletexture,
minetest.formspec_escape(titletexture),
minetest.colorize("#111",
minetest.formspec_escape(meta:get_string("text"))))

Expand Down
24 changes: 24 additions & 0 deletions unifont/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Unifont for Minetest: Full Unicode Plane 0 charset (60000+ characters!)

![Screenshot](screenshot.png)

GNU Unifont (v14.0.01) for Font API mod (from [display_modpack](https://github.com/pyrollo/display_modpack)).

- Full Unicode Basic Multilingual Plane (BMP) with 63485 characters
- Lightweight, data only ~2MB in size
- Duospaced (glyphs in either 8x16 or 16x16)

Requires `font_api` mod.

## Trivia

- You can use Unicode fullwidth forms (U+FF01--FF5E) to display wider letters & numbers (as shown in the screenshot above)
- GNU Unifont is also the same font used in Minecraft for Unicode display.

## Copyright

Copyright 2021 SyiMyuZya

License: [GPL 3.0 or later](https://www.gnu.org/licenses/gpl-3.0.html)

GNU Unifont: ©️ GNU Unifont authors, licensed under GPL version 2.0 or later
1 change: 1 addition & 0 deletions unifont/depends.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
font_api
Loading