1
0
mirror of https://github.com/pyrollo/display_modpack.git synced 2025-10-16 00:55:36 +02:00
This commit is contained in:
Pierre-Yves Rollo
2025-10-15 08:33:05 +02:00
parent cf7c962487
commit 73c0924ef6
9 changed files with 281 additions and 21 deletions

View File

@@ -1,3 +1,7 @@
## TODO:
* Update documentation with new format
* add information about texture having to be escaped in formspecs with `:gsub("[\\^]", "\\%0")`
# Font API
This document describes Font API. Font API creates textures for font display on entities.

View File

@@ -2,8 +2,8 @@
-- A font mod generator for font_api
--
-- This files generates only code and textures - should not be translated
-- This is an utility script for code and texture generator,
-- not intended to be tranlslated.
-- TODO : detect and manage fixed width fonts
@@ -192,7 +192,7 @@ local function make_final_texture(font)
local glyph_y = 0
table.sort(font.tile_widths)
print(" Computing positions")
-- Compute positions
for _, tile_width in ipairs(font.tile_widths) do
for _, codepoint in ipairs(font.by_width[tile_width]) do
@@ -211,6 +211,8 @@ local function make_final_texture(font)
end
end
print(" Composing texture")
-- Compose texture
command(string.format(
"convert -size %dx%d xc:transparent %s",
@@ -218,6 +220,7 @@ local function make_final_texture(font)
))
for codepoint, n in pairs(font.glyph_ns) do
print(codepoint)
local w = math.floor(texture_width / n)
local x = w * font.glyph_xs[codepoint]
local y = font.glyphs_height * font.glyph_ys[codepoint]
@@ -266,12 +269,12 @@ local function process_font(font)
font.glyph_widths = {} -- Exact width of reach glyph
font.glyphs_height = 0 -- Max height of all glyphs
print("Read available glyphs")
print(" Reading available glyphs")
-- Available codepoints from file
font.cp = read_available_codepoints(font.file)
print("Compute glyphs properties")
print(" Computing glyphs properties")
-- Special char: unknown char
-- We use size of glyph "0" (rounded) but it would be better to get size from ttx
@@ -294,7 +297,7 @@ local function process_font(font)
end
end
print("Create final texture")
print(" Creating final texture")
make_final_texture(font)
@@ -338,15 +341,17 @@ font_api.register_font(
{
version = 2,
default = true,
margintop = 3,
linespacing = -2,
charspacing = 2,
margintop = %d,
linespacing = %d,
charspacing = %d,
texture_height = %d,
glyphs_height = %d,
glyphs = %s,
}
)
]], font.file, font.pointsize, font.name, font.texture_height, font.glyphs_height, glyphs)
]], font.file, font.pointsize, font.name,
font.margin_top, font.line_spacing, font.char_spacing,
font.texture_height, font.glyphs_height, glyphs)
end
--
@@ -357,7 +362,14 @@ for _, font in ipairs(params.fonts) do
process_font(font)
end
print("All fonts processed, writing mod files")
--
-- Write init.lua
--
print(" Writing init.lua")
local file = io.open(mod_dir .. "/init.lua", "w")
file:write(string.format([[
@@ -379,6 +391,7 @@ file:close()
--
-- Write mod.conf
--
print(" Writing mod.conf")
local file = io.open(mod_dir .. "/mod.conf", "w")
file:write(string.format([[
@@ -388,4 +401,59 @@ description = %s
depends = font_api
]], params.mod_name, params.mod_title, params.mod_description))
--
-- Write README.md
--
print(" Writing README.md")
local function list(t)
return #t == 1 and t[1] or
table.concat(t, ", ", 1, #t - 1) .. " and " .. t[#t]
end
local font_labels = {}
for _, font in ipairs(params.fonts) do
table.insert(font_name, font.label)
end
local function font_description(font)
local orignal = string.format("%s by %s", font.label, font.author)
if font.url and font.url ~= "" then
original = string.format("[%s](%s)", original, font.url)
end
return string.format([[
![%s font preview](screenshot_%s.png)
**Original font**: %s
**License**: %s
]], font.label, font.name, orignal, font.license)
end
local file = io.open(mod_dir .. "/README.md", "w")
file:write(string.format([[
# %s minetest mod for font API
This mod adds %s to Font API mod (from [display_modpack](https://github.com/pyrollo/display_modpack)).
For more information, see the [forum topic](https://forum.minetest.net/viewtopic.php?t=13563) at the Minetest forums.
]], params.mod_title, list(font_labels)))
file:write([[
**Dependancies**: font_api
**License**: code under LGPL v2.1
]])
if #params.fonts > 1 then
for _, font in ipairs(params.fonts) do
file:write("## %s font\n", font.label)
file:write(font_description(font))
end
else
file:write(font_description(params.font[1]))
end
-- This font includes uppercase, lowercase and many accentuated latin letters, greek and cyrillic letters.

View File

@@ -10,10 +10,10 @@ params = {
-- please avoid long names but keep explicit anyway.
mod_name = "<your mod name>",
-- If only one font, have font in title, like "xxx font"
-- If only one font, have font in title, like "xxx font"
mod_title = "<your mod title>",
-- A good description would be "... fonts for font_api"
-- A good description would be "... fonts for font_api"
mod_description = "<your mod description>",
-- List of fons to include to the mod.
@@ -31,6 +31,20 @@ params = {
-- True type font file to get glyphs from (required)
file = "<your font true type font>",
-- Author(s) of the original font (required)
author = "<author or list of authors>",
-- License of the original font (required)
-- Join license text, as a text file, to your mod.
license = "<name of the license>",
-- URL of the original font (optional)
-- If there is an URL about this font, it is recommended to have it
-- here. It should be URL of font project if it exists or at least
-- an URL where to download the font with details about author and
-- license.
url = "<URL>",
-- Render pointsize (integer, required)
-- Try to find a proper value for a good rendering
pointsize = <proper rendering height>,
@@ -54,7 +68,7 @@ params = {
-- Extra codepoints to include to font mod (optional, default none)
-- Codepoints from 0x0020 to 0x007f (ASCII) are always included.
-- Codepoint 0x0020 is always considered as a space.
-- Codepoints not existing in font file will be ignored.
-- Codepoints not existing in font file will be ignored.
-- Refer to https://en.wikipedia.org/wiki/Unicode
codepoints = {
-- 00a0-00ff Latin-1 Supplement (full except nbsp)
@@ -78,6 +92,6 @@ params = {
-- 20a0-20cf Currency Symbols (Limited to Euro symbol)
{ from = 0x20ac, to = 0x20ac },
},
}
},
}
}