diff --git a/extra_fonts/init.lua b/extra_fonts/init.lua index dc7bef8..2a623ed 100644 --- a/extra_fonts/init.lua +++ b/extra_fonts/init.lua @@ -1,7 +1,7 @@ -- -- fonts_extra: A font mod for font_api -- --- This file was generated by `../font_api/tools/make_font.lua` on 2025-10-11 at 11:57. +-- This file was generated by `../font_api/tools/make_font.lua` on 2025-10-12 at 10:26. -- -- Font generated from file sources/pixeldroidBoticRegular.otf with pointsize 16 @@ -10,8 +10,8 @@ font_api.register_font( { version = 2, default = true, - margintop = 3, - linespacing = -2, + margintop = 0, + linespacing = 0, charspacing = 2, texture_height = 39, glyphs_height = 13, @@ -76,3 +76,113 @@ font_api.register_font( }, } ) +-- Font generated from file sources/OldWizard.ttf with pointsize 16 +font_api.register_font( + 'oldwizard', + { + version = 2, + default = true, + margintop = 0, + linespacing = 0, + charspacing = 2, + texture_height = 25674, + glyphs_height = 389, + glyphs = { + [32] = { 18 }, [33] = { 3, 90, 0, 0 }, [34] = { 5, 60, 2, 0 }, + [35] = { 8, 40, 6, 0 }, [36] = { 10, 30, 8, 0 }, + [37] = { 14, 24, 8, 0 }, [38] = { 12, 24, 9, 0 }, + [39] = { 3, 90, 1, 0 }, [40] = { 8, 40, 7, 0 }, + [41] = { 9, 36, 8, 0 }, [42] = { 10, 30, 9, 0 }, + [43] = { 16, 20, 11, 0 }, [44] = { 7, 45, 4, 0 }, + [45] = { 14, 24, 10, 0 }, [46] = { 7, 45, 5, 0 }, + [47] = { 15, 20, 12, 0 }, [48] = { 18, 18, 13, 0 }, + [49] = { 17, 20, 13, 0 }, [50] = { 26, 12, 0, 1 }, + [51] = { 18, 18, 14, 0 }, [52] = { 22, 15, 13, 0 }, + [53] = { 23, 15, 14, 0 }, [54] = { 24, 12, 1, 1 }, + [55] = { 25, 12, 2, 1 }, [56] = { 25, 12, 3, 1 }, + [57] = { 26, 12, 4, 1 }, [58] = { 12, 24, 11, 0 }, + [59] = { 12, 24, 12, 0 }, [60] = { 33, 10, 8, 1 }, + [61] = { 30, 10, 9, 1 }, [62] = { 35, 10, 0, 2 }, + [63] = { 27, 12, 5, 1 }, [64] = { 60, 5, 0, 7 }, + [65] = { 43, 8, 4, 2 }, [66] = { 39, 9, 2, 2 }, + [67] = { 45, 6, 1, 3 }, [68] = { 52, 6, 2, 3 }, + [69] = { 42, 8, 5, 2 }, [70] = { 54, 6, 3, 3 }, + [71] = { 49, 6, 4, 3 }, [72] = { 51, 6, 5, 3 }, + [73] = { 52, 6, 0, 4 }, [74] = { 65, 5, 1, 7 }, + [75] = { 60, 5, 2, 7 }, [76] = { 62, 5, 3, 7 }, + [77] = { 88, 4, 0, 10 }, [78] = { 77, 4, 1, 10 }, + [79] = { 58, 6, 1, 4 }, [80] = { 67, 5, 4, 7 }, + [81] = { 67, 5, 0, 8 }, [82] = { 76, 4, 2, 10 }, + [83] = { 70, 5, 1, 8 }, [84] = { 72, 4, 3, 10 }, + [85] = { 73, 4, 0, 11 }, [86] = { 74, 4, 1, 11 }, + [87] = { 113, 3, 0, 16 }, [88] = { 84, 4, 2, 11 }, + [89] = { 85, 4, 3, 11 }, [90] = { 87, 4, 0, 12 }, + [91] = { 48, 6, 2, 4 }, [92] = { 49, 6, 3, 4 }, + [93] = { 50, 6, 4, 4 }, [94] = { 50, 6, 5, 4 }, + [95] = { 76, 4, 1, 12 }, [96] = { 26, 12, 6, 1 }, + [97] = { 61, 5, 2, 8 }, [98] = { 62, 5, 3, 8 }, + [99] = { 54, 6, 0, 5 }, [100] = { 55, 6, 1, 5 }, + [101] = { 56, 6, 2, 5 }, [102] = { 56, 6, 3, 5 }, + [103] = { 67, 5, 4, 8 }, [104] = { 77, 4, 2, 12 }, + [105] = { 40, 8, 6, 2 }, [106] = { 40, 8, 7, 2 }, + [107] = { 90, 3, 1, 16 }, [108] = { 42, 8, 0, 3 }, + [109] = { 124, 2, 1, 22 }, [110] = { 84, 4, 3, 12 }, + [111] = { 63, 5, 0, 9 }, [112] = { 74, 4, 0, 13 }, + [113] = { 75, 4, 1, 13 }, [114] = { 76, 4, 2, 13 }, + [115] = { 66, 5, 1, 9 }, [116] = { 46, 6, 4, 5 }, + [117] = { 102, 3, 2, 16 }, [118] = { 92, 3, 0, 17 }, + [119] = { 127, 2, 0, 23 }, [120] = { 105, 3, 1, 17 }, + [121] = { 83, 4, 3, 13 }, [122] = { 95, 3, 2, 17 }, + [123] = { 72, 4, 0, 14 }, [124] = { 25, 12, 7, 1 }, + [125] = { 74, 4, 1, 14 }, [126] = { 99, 3, 0, 18 }, + [161] = { 38, 9, 3, 2 }, [162] = { 88, 4, 2, 14 }, + [163] = { 128, 2, 1, 23 }, [164] = { 90, 3, 1, 18 }, + [165] = { 117, 3, 2, 18 }, [166] = { 27, 12, 8, 1 }, + [167] = { 93, 3, 0, 19 }, [168] = { 54, 6, 5, 5 }, + [169] = { 135, 2, 0, 24 }, [170] = { 55, 6, 0, 6 }, + [171] = { 110, 3, 1, 19 }, [172] = { 97, 3, 2, 19 }, + [174] = { 140, 2, 1, 24 }, [175] = { 113, 3, 0, 20 }, + [176] = { 71, 5, 2, 9 }, [177] = { 115, 3, 1, 20 }, + [178] = { 58, 6, 1, 6 }, [179] = { 59, 6, 2, 6 }, + [180] = { 45, 6, 3, 6 }, [181] = { 105, 3, 2, 20 }, + [182] = { 105, 3, 0, 21 }, [183] = { 46, 6, 4, 6 }, + [184] = { 61, 5, 3, 9 }, [185] = { 31, 10, 1, 2 }, + [186] = { 78, 4, 3, 14 }, [187] = { 125, 2, 0, 25 }, + [188] = { 142, 2, 1, 25 }, [189] = { 159, 2, 0, 26 }, + [190] = { 160, 2, 1, 26 }, [191] = { 113, 3, 1, 21 }, + [192] = { 146, 2, 0, 27 }, [193] = { 147, 2, 1, 27 }, + [194] = { 148, 2, 0, 28 }, [195] = { 150, 2, 1, 28 }, + [196] = { 151, 2, 0, 29 }, [197] = { 152, 2, 1, 29 }, + [198] = { 221, 1, 0, 49 }, [199] = { 154, 2, 0, 30 }, + [200] = { 138, 2, 1, 30 }, [201] = { 139, 2, 0, 31 }, + [202] = { 140, 2, 1, 31 }, [203] = { 141, 2, 0, 32 }, + [204] = { 160, 2, 1, 32 }, [205] = { 161, 2, 0, 33 }, + [206] = { 162, 2, 1, 33 }, [207] = { 164, 2, 0, 34 }, + [208] = { 183, 1, 0, 50 }, [209] = { 221, 1, 0, 51 }, + [210] = { 166, 2, 1, 34 }, [211] = { 168, 2, 0, 35 }, + [212] = { 169, 2, 1, 35 }, [213] = { 170, 2, 0, 36 }, + [214] = { 171, 2, 1, 36 }, [215] = { 115, 3, 2, 21 }, + [216] = { 192, 1, 0, 52 }, [217] = { 194, 1, 0, 53 }, + [218] = { 195, 1, 0, 54 }, [219] = { 197, 1, 0, 55 }, + [220] = { 198, 1, 0, 56 }, [221] = { 219, 1, 0, 57 }, + [222] = { 160, 2, 0, 37 }, [223] = { 161, 2, 1, 37 }, + [224] = { 142, 2, 0, 38 }, [225] = { 143, 2, 1, 38 }, + [226] = { 144, 2, 0, 39 }, [227] = { 144, 2, 1, 39 }, + [228] = { 145, 2, 0, 40 }, [229] = { 146, 2, 1, 40 }, + [230] = { 210, 1, 0, 58 }, [231] = { 127, 2, 0, 41 }, + [232] = { 128, 2, 1, 41 }, [233] = { 128, 2, 0, 42 }, + [234] = { 129, 2, 1, 42 }, [235] = { 130, 2, 0, 43 }, + [236] = { 88, 4, 0, 15 }, [237] = { 88, 4, 1, 15 }, + [238] = { 88, 4, 2, 15 }, [239] = { 90, 3, 0, 22 }, + [240] = { 156, 2, 1, 43 }, [241] = { 180, 1, 0, 59 }, + [242] = { 135, 2, 0, 44 }, [243] = { 136, 2, 1, 44 }, + [244] = { 137, 2, 0, 45 }, [245] = { 137, 2, 1, 45 }, + [246] = { 138, 2, 0, 46 }, [247] = { 185, 1, 0, 60 }, + [248] = { 163, 2, 1, 46 }, [249] = { 211, 1, 0, 61 }, + [250] = { 212, 1, 0, 62 }, [251] = { 213, 1, 0, 63 }, + [252] = { 214, 1, 0, 64 }, [253] = { 167, 2, 0, 47 }, + [254] = { 144, 2, 1, 47 }, [255] = { 170, 2, 0, 48 }, + [0] = { 8, 45, 3, 0 }, [8364] = { 243, 1, 0, 65 }, + }, + } +) diff --git a/extra_fonts/params_test.lua b/extra_fonts/params_test.lua index 7754752..d06c322 100644 --- a/extra_fonts/params_test.lua +++ b/extra_fonts/params_test.lua @@ -31,6 +31,13 @@ params = { -- True type font file to get glyphs from (required) file = "sources/pixeldroidBoticRegular.otf", + -- Author(s) of the original font (required) + author = "pixeldroid", + + -- License of the original font (required) + -- Join license text, as a text file, to your mod. + license = "Open Font License", + -- Render pointsize (integer, required) -- Try to find a proper value for a good rendering pointsize = 16, @@ -42,11 +49,11 @@ params = { trim = true, -- Margin added on top of text textures with this font (integer, optional, default 0) - margin_top = 3, + margin_top = 0, -- Space between consecutive lines (integer, optional, default 0) -- Space may be negative to make lines closer. - line_spacing = -2, + line_spacing = 0, -- Space between consecutive chars (integer, optional, default 0) char_spacing = 2, @@ -63,6 +70,63 @@ params = { -- 20a0-20cf Currency Symbols (Limited to Euro symbol) { from = 0x20ac, to = 0x20ac }, }, - } + }, { + -- Registered font name (required) + -- As this name will be use as texture prefix and so repeated many times, + -- avoid long names. A good name would be a single world all lowercase. + name = "oldwizard", + + -- Registered font label (optional, default capitalized name) + -- This is the display name for this font. No need to be concise. + label = "Old Wizard", + + -- True type font file to get glyphs from (required) + file = "sources/OldWizard.ttf", + + -- Author(s) of the original font (required) + author = "Angel", + + -- License of the original font (required) + -- Join license text, as a text file, to your mod. + license = "Public Domain", + + -- URL of the original font (optional) + -- This is an optional field but it is recommended to put an URL + -- if it exists. + url = "http://www.pentacom.jp/pentacom/bitfontmaker2/gallery/?id=168", + + -- Render pointsize (integer, required) + -- Try to find a proper value for a good rendering + pointsize = 16, + + -- Shoud chars be trimmed? (boolean, required) + -- Set it to true to reduce texture size + -- and increase `char_spacing` accordingly. + -- If results are weird, you may try to set it to false. + trim = true, + + -- Margin added on top of text textures with this font (integer, optional, default 0) + margin_top = 0, + + -- Space between consecutive lines (integer, optional, default 0) + -- Space may be negative to make lines closer. + line_spacing = 0, + + -- Space between consecutive chars (integer, optional, default 0) + char_spacing = 2, + + -- 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. + -- Refer to https://en.wikipedia.org/wiki/Unicode + codepoints = { + -- 00a0-00ff Latin-1 Supplement (full except nbsp) + { from = 0x00a1, to = 0x00ff }, + + -- 20a0-20cf Currency Symbols (Limited to Euro symbol) + { from = 0x20ac, to = 0x20ac }, + }, + }, } } diff --git a/extra_fonts/sources/OldWizard.ttf b/extra_fonts/sources/OldWizard.ttf new file mode 100644 index 0000000..227c8c3 Binary files /dev/null and b/extra_fonts/sources/OldWizard.ttf differ diff --git a/extra_fonts/textures/font_botic.png b/extra_fonts/textures/font_botic.png index cdc9daa..bc144f1 100644 Binary files a/extra_fonts/textures/font_botic.png and b/extra_fonts/textures/font_botic.png differ diff --git a/extra_fonts/textures/font_oldwizard.png b/extra_fonts/textures/font_oldwizard.png new file mode 100644 index 0000000..9b0d26c Binary files /dev/null and b/extra_fonts/textures/font_oldwizard.png differ diff --git a/font_api/API.md b/font_api/API.md index 80b1121..80595f7 100644 --- a/font_api/API.md +++ b/font_api/API.md @@ -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. diff --git a/font_api/tools/make_font.lua b/font_api/tools/make_font.lua index 0f58df6..0d20a76 100644 --- a/font_api/tools/make_font.lua +++ b/font_api/tools/make_font.lua @@ -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. diff --git a/font_api/tools/make_font/params.example b/font_api/tools/make_font/params.example index 954086d..0dc41a8 100644 --- a/font_api/tools/make_font/params.example +++ b/font_api/tools/make_font/params.example @@ -10,10 +10,10 @@ params = { -- please avoid long names but keep explicit anyway. 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 = "", - -- A good description would be "... fonts for font_api" + -- A good description would be "... fonts for font_api" 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 = "", + -- Author(s) of the original font (required) + author = "", + + -- License of the original font (required) + -- Join license text, as a text file, to your mod. + 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 = "", + -- Render pointsize (integer, required) -- Try to find a proper value for a good rendering pointsize = , @@ -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 }, }, - } + }, } } diff --git a/signs/nodes.lua b/signs/nodes.lua index 55135a4..f54ead4 100644 --- a/signs/nodes.lua +++ b/signs/nodes.lua @@ -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, + titletexture:gsub("[\\^]", "\\%0"), minetest.formspec_escape(meta:get_string("text"))) if minetest.is_protected(pos, player:get_player_name()) then