Added facedir node support to display_lib, created font_lib, updated mods accordingly
47
font_lib/API.md
Normal file
@ -0,0 +1,47 @@
|
||||
# Font Lib API
|
||||
This document describes Font Lib API. Font Lib creates textures for font display on entities.
|
||||
|
||||
## Provided methods
|
||||
### get\_line\_width
|
||||
**font\_lib.get\_line\_width(text)**
|
||||
|
||||
Computes line width for a given font height and text
|
||||
**text**: Text to be rendered
|
||||
|
||||
**Returns**: rendered text width
|
||||
|
||||
### make\_line\_texture
|
||||
**font\_lib.make\_line\_texture(text, texturew, x, y)**
|
||||
|
||||
Builds texture part for a text line
|
||||
|
||||
**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(text, texturew, textureh, maxlines, valign, color)**
|
||||
|
||||
Builds texture for a multiline colored text
|
||||
|
||||
**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" or "center")
|
||||
|
||||
**color**: Color of the text
|
||||
|
||||
**Returns**: Texture string
|
||||
|
||||
|
13
font_lib/LICENSE.txt
Normal file
@ -0,0 +1,13 @@
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
14
font_lib/README.md
Normal file
@ -0,0 +1,14 @@
|
||||
# Font Lib
|
||||
|
||||
This library for font display on entities (to be used with display_lib for sign creation).
|
||||
|
||||
**Dependancies**: default
|
||||
|
||||
**License**: WTFPL
|
||||
|
||||
(Font taken from VanessaE's homedecor/signs_lib)
|
||||
|
||||
**API**: See API.md document please.
|
||||
|
||||
|
||||
|
1
font_lib/depends.txt
Normal file
@ -0,0 +1 @@
|
||||
default
|
139
font_lib/init.lua
Normal file
@ -0,0 +1,139 @@
|
||||
-- Font lib mod by P.Y. Rollo
|
||||
--
|
||||
-- License: WTFPL
|
||||
|
||||
font_lib = {}
|
||||
font_lib.path = minetest.get_modpath("font_lib")
|
||||
font_lib.font_height = 10
|
||||
font_lib.font = {}
|
||||
|
||||
-- Get png width, suposing png width is less than 256 (it is the case for all font textures)
|
||||
local function get_png_width(filename)
|
||||
local file=assert(io.open(filename,"rb"))
|
||||
-- All font png are smaller than 256x256 --> read only last byte
|
||||
file:seek("set",19)
|
||||
local w = file:read(1)
|
||||
file:close()
|
||||
return w:byte()
|
||||
end
|
||||
|
||||
-- Computes line width for a given font height and text
|
||||
-- @param text Text to be rendered
|
||||
-- @return Rendered text width
|
||||
function font_lib.get_line_width(text)
|
||||
local char
|
||||
local width = 0
|
||||
|
||||
for p=1,#text
|
||||
do
|
||||
char = text:sub(p,p):byte()
|
||||
if font_lib.font[char] then
|
||||
width = width + font_lib.font[char].width
|
||||
end
|
||||
end
|
||||
|
||||
return width
|
||||
end
|
||||
|
||||
--- Builds texture part for a text line
|
||||
-- @param text Text to be rendered
|
||||
-- @param texturew Width of the texture (extra text is not rendered)
|
||||
-- @param x Starting x position in texture
|
||||
-- @param y Vertical position of the line in texture
|
||||
-- @return Texture string
|
||||
function font_lib.make_line_texture(text, texturew, x, y)
|
||||
local char
|
||||
|
||||
local texture = ""
|
||||
|
||||
for p=1,#text
|
||||
do
|
||||
char = text:sub(p,p):byte()
|
||||
if font_lib.font[char] then
|
||||
-- Add image only if it is visible (at least partly)
|
||||
if x + font_lib.font[char].width >= 0 and x <= texturew then
|
||||
texture = texture..string.format(":%d,%d=%s", x, y, font_lib.font[char].filename)
|
||||
end
|
||||
x = x + font_lib.font[char].width
|
||||
end
|
||||
end
|
||||
return texture
|
||||
end
|
||||
|
||||
local function split_lines(text, maxlines)
|
||||
local splits = text:split("\n")
|
||||
if maxlines then
|
||||
local lines = {}
|
||||
for num = 1,maxlines do
|
||||
lines[num] = splits[num]
|
||||
end
|
||||
return lines
|
||||
else
|
||||
return splits
|
||||
end
|
||||
end
|
||||
|
||||
--- Builds texture for a multiline colored text
|
||||
-- @param text Text to be rendered
|
||||
-- @param texturew Width of the texture (extra text will be truncated)
|
||||
-- @param textureh Height of the texture
|
||||
-- @param maxlines Maximum number of lines
|
||||
-- @param valign Vertical text align ("top" or "center")
|
||||
-- @param color Color of the text
|
||||
-- @return Texture string
|
||||
function font_lib.make_multiline_texture(text, texturew, textureh, maxlines, valign, color)
|
||||
local texture = ""
|
||||
local lines = split_lines(text, maxlines)
|
||||
local y
|
||||
|
||||
if valign == "top" then
|
||||
y = font_lib.font_height / 2
|
||||
else
|
||||
y = (textureh - font_lib.font_height * #lines) / 2 + 1
|
||||
end
|
||||
|
||||
for _, line in pairs(lines) do
|
||||
texture = texture..font_lib.make_line_texture(line, texturew,
|
||||
(texturew - font_lib.get_line_width(line)) / 2, y)
|
||||
y = y + font_lib.font_height
|
||||
end
|
||||
|
||||
texture = string.format("[combine:%dx%d", texturew, textureh)..texture
|
||||
if color then texture = texture.."^[colorize:"..color end
|
||||
|
||||
return texture
|
||||
end
|
||||
|
||||
--- Standard on_display_update entity callback.
|
||||
-- Node should have a corresponding display_entity with size, resolution and maxlines fields and
|
||||
-- optionally valign and color fields
|
||||
-- @param pos Node position
|
||||
-- @param objref Object reference of entity
|
||||
|
||||
function font_lib.on_display_update(pos, objref)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local text = meta:get_string("display_text")
|
||||
|
||||
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
local entity = objref:get_luaentity()
|
||||
|
||||
if entity and ndef.display_entities[entity.name] then
|
||||
local def = ndef.display_entities[entity.name]
|
||||
|
||||
objref:set_properties({
|
||||
textures={font_lib.make_multiline_texture(
|
||||
text, def.size.x*def.resolution.x, def.size.y*def.resolution.y,
|
||||
def.maxlines, def.valign, def.color)},
|
||||
visual_size = def.size
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- Populate fonts table
|
||||
local w, filename
|
||||
for charnum=32,126 do
|
||||
filename = string.format("font_lib_%02x.png", charnum)
|
||||
w = get_png_width(font_lib.path.."/textures/"..filename)
|
||||
font_lib.font[charnum] = {filename=filename, width=w}
|
||||
end
|
||||
|
BIN
font_lib/textures/font_lib_20.png
Normal file
After Width: | Height: | Size: 232 B |
BIN
font_lib/textures/font_lib_21.png
Normal file
After Width: | Height: | Size: 241 B |
BIN
font_lib/textures/font_lib_22.png
Normal file
After Width: | Height: | Size: 235 B |
BIN
font_lib/textures/font_lib_23.png
Normal file
After Width: | Height: | Size: 244 B |
BIN
font_lib/textures/font_lib_24.png
Normal file
After Width: | Height: | Size: 247 B |
BIN
font_lib/textures/font_lib_25.png
Normal file
After Width: | Height: | Size: 247 B |
BIN
font_lib/textures/font_lib_26.png
Normal file
After Width: | Height: | Size: 246 B |
BIN
font_lib/textures/font_lib_27.png
Normal file
After Width: | Height: | Size: 238 B |
BIN
font_lib/textures/font_lib_28.png
Normal file
After Width: | Height: | Size: 242 B |
BIN
font_lib/textures/font_lib_29.png
Normal file
After Width: | Height: | Size: 241 B |
BIN
font_lib/textures/font_lib_2a.png
Normal file
After Width: | Height: | Size: 238 B |
BIN
font_lib/textures/font_lib_2b.png
Normal file
After Width: | Height: | Size: 241 B |
BIN
font_lib/textures/font_lib_2c.png
Normal file
After Width: | Height: | Size: 238 B |
BIN
font_lib/textures/font_lib_2d.png
Normal file
After Width: | Height: | Size: 237 B |
BIN
font_lib/textures/font_lib_2e.png
Normal file
After Width: | Height: | Size: 236 B |
BIN
font_lib/textures/font_lib_2f.png
Normal file
After Width: | Height: | Size: 244 B |
BIN
font_lib/textures/font_lib_30.png
Normal file
After Width: | Height: | Size: 239 B |
BIN
font_lib/textures/font_lib_31.png
Normal file
After Width: | Height: | Size: 239 B |
BIN
font_lib/textures/font_lib_32.png
Normal file
After Width: | Height: | Size: 247 B |
BIN
font_lib/textures/font_lib_33.png
Normal file
After Width: | Height: | Size: 246 B |
BIN
font_lib/textures/font_lib_34.png
Normal file
After Width: | Height: | Size: 247 B |
BIN
font_lib/textures/font_lib_35.png
Normal file
After Width: | Height: | Size: 247 B |
BIN
font_lib/textures/font_lib_36.png
Normal file
After Width: | Height: | Size: 244 B |
BIN
font_lib/textures/font_lib_37.png
Normal file
After Width: | Height: | Size: 242 B |
BIN
font_lib/textures/font_lib_38.png
Normal file
After Width: | Height: | Size: 240 B |
BIN
font_lib/textures/font_lib_39.png
Normal file
After Width: | Height: | Size: 243 B |
BIN
font_lib/textures/font_lib_3a.png
Normal file
After Width: | Height: | Size: 237 B |
BIN
font_lib/textures/font_lib_3b.png
Normal file
After Width: | Height: | Size: 240 B |
BIN
font_lib/textures/font_lib_3c.png
Normal file
After Width: | Height: | Size: 245 B |
BIN
font_lib/textures/font_lib_3d.png
Normal file
After Width: | Height: | Size: 236 B |
BIN
font_lib/textures/font_lib_3e.png
Normal file
After Width: | Height: | Size: 245 B |
BIN
font_lib/textures/font_lib_3f.png
Normal file
After Width: | Height: | Size: 243 B |
BIN
font_lib/textures/font_lib_40.png
Normal file
After Width: | Height: | Size: 259 B |
BIN
font_lib/textures/font_lib_41.png
Normal file
After Width: | Height: | Size: 243 B |
BIN
font_lib/textures/font_lib_42.png
Normal file
After Width: | Height: | Size: 240 B |
BIN
font_lib/textures/font_lib_43.png
Normal file
After Width: | Height: | Size: 246 B |
BIN
font_lib/textures/font_lib_44.png
Normal file
After Width: | Height: | Size: 242 B |
BIN
font_lib/textures/font_lib_45.png
Normal file
After Width: | Height: | Size: 240 B |
BIN
font_lib/textures/font_lib_46.png
Normal file
After Width: | Height: | Size: 241 B |
BIN
font_lib/textures/font_lib_47.png
Normal file
After Width: | Height: | Size: 247 B |
BIN
font_lib/textures/font_lib_48.png
Normal file
After Width: | Height: | Size: 240 B |
BIN
font_lib/textures/font_lib_49.png
Normal file
After Width: | Height: | Size: 236 B |
BIN
font_lib/textures/font_lib_4a.png
Normal file
After Width: | Height: | Size: 240 B |
BIN
font_lib/textures/font_lib_4b.png
Normal file
After Width: | Height: | Size: 246 B |
BIN
font_lib/textures/font_lib_4c.png
Normal file
After Width: | Height: | Size: 238 B |
BIN
font_lib/textures/font_lib_4d.png
Normal file
After Width: | Height: | Size: 249 B |
BIN
font_lib/textures/font_lib_4e.png
Normal file
After Width: | Height: | Size: 243 B |
BIN
font_lib/textures/font_lib_4f.png
Normal file
After Width: | Height: | Size: 243 B |
BIN
font_lib/textures/font_lib_50.png
Normal file
After Width: | Height: | Size: 241 B |
BIN
font_lib/textures/font_lib_51.png
Normal file
After Width: | Height: | Size: 244 B |
BIN
font_lib/textures/font_lib_52.png
Normal file
After Width: | Height: | Size: 238 B |
BIN
font_lib/textures/font_lib_53.png
Normal file
After Width: | Height: | Size: 247 B |
BIN
font_lib/textures/font_lib_54.png
Normal file
After Width: | Height: | Size: 237 B |
BIN
font_lib/textures/font_lib_55.png
Normal file
After Width: | Height: | Size: 238 B |
BIN
font_lib/textures/font_lib_56.png
Normal file
After Width: | Height: | Size: 243 B |
BIN
font_lib/textures/font_lib_57.png
Normal file
After Width: | Height: | Size: 246 B |
BIN
font_lib/textures/font_lib_58.png
Normal file
After Width: | Height: | Size: 245 B |
BIN
font_lib/textures/font_lib_59.png
Normal file
After Width: | Height: | Size: 244 B |
BIN
font_lib/textures/font_lib_5a.png
Normal file
After Width: | Height: | Size: 248 B |
BIN
font_lib/textures/font_lib_5b.png
Normal file
After Width: | Height: | Size: 234 B |
BIN
font_lib/textures/font_lib_5c.png
Normal file
After Width: | Height: | Size: 244 B |
BIN
font_lib/textures/font_lib_5d.png
Normal file
After Width: | Height: | Size: 234 B |
BIN
font_lib/textures/font_lib_5e.png
Normal file
After Width: | Height: | Size: 238 B |
BIN
font_lib/textures/font_lib_5f.png
Normal file
After Width: | Height: | Size: 233 B |
BIN
font_lib/textures/font_lib_60.png
Normal file
After Width: | Height: | Size: 234 B |
BIN
font_lib/textures/font_lib_61.png
Normal file
After Width: | Height: | Size: 245 B |
BIN
font_lib/textures/font_lib_62.png
Normal file
After Width: | Height: | Size: 242 B |
BIN
font_lib/textures/font_lib_63.png
Normal file
After Width: | Height: | Size: 244 B |
BIN
font_lib/textures/font_lib_64.png
Normal file
After Width: | Height: | Size: 243 B |
BIN
font_lib/textures/font_lib_65.png
Normal file
After Width: | Height: | Size: 245 B |
BIN
font_lib/textures/font_lib_66.png
Normal file
After Width: | Height: | Size: 240 B |
BIN
font_lib/textures/font_lib_67.png
Normal file
After Width: | Height: | Size: 243 B |
BIN
font_lib/textures/font_lib_68.png
Normal file
After Width: | Height: | Size: 240 B |
BIN
font_lib/textures/font_lib_69.png
Normal file
After Width: | Height: | Size: 239 B |
BIN
font_lib/textures/font_lib_6a.png
Normal file
After Width: | Height: | Size: 236 B |
BIN
font_lib/textures/font_lib_6b.png
Normal file
After Width: | Height: | Size: 246 B |
BIN
font_lib/textures/font_lib_6c.png
Normal file
After Width: | Height: | Size: 236 B |
BIN
font_lib/textures/font_lib_6d.png
Normal file
After Width: | Height: | Size: 241 B |
BIN
font_lib/textures/font_lib_6e.png
Normal file
After Width: | Height: | Size: 239 B |
BIN
font_lib/textures/font_lib_6f.png
Normal file
After Width: | Height: | Size: 241 B |
BIN
font_lib/textures/font_lib_70.png
Normal file
After Width: | Height: | Size: 242 B |
BIN
font_lib/textures/font_lib_71.png
Normal file
After Width: | Height: | Size: 243 B |
BIN
font_lib/textures/font_lib_72.png
Normal file
After Width: | Height: | Size: 241 B |
BIN
font_lib/textures/font_lib_73.png
Normal file
After Width: | Height: | Size: 242 B |
BIN
font_lib/textures/font_lib_74.png
Normal file
After Width: | Height: | Size: 243 B |
BIN
font_lib/textures/font_lib_75.png
Normal file
After Width: | Height: | Size: 239 B |
BIN
font_lib/textures/font_lib_76.png
Normal file
After Width: | Height: | Size: 244 B |
BIN
font_lib/textures/font_lib_77.png
Normal file
After Width: | Height: | Size: 240 B |
BIN
font_lib/textures/font_lib_78.png
Normal file
After Width: | Height: | Size: 244 B |
BIN
font_lib/textures/font_lib_79.png
Normal file
After Width: | Height: | Size: 241 B |
BIN
font_lib/textures/font_lib_7a.png
Normal file
After Width: | Height: | Size: 246 B |
BIN
font_lib/textures/font_lib_7b.png
Normal file
After Width: | Height: | Size: 239 B |
BIN
font_lib/textures/font_lib_7c.png
Normal file
After Width: | Height: | Size: 232 B |
BIN
font_lib/textures/font_lib_7d.png
Normal file
After Width: | Height: | Size: 239 B |
BIN
font_lib/textures/font_lib_7e.png
Normal file
After Width: | Height: | Size: 239 B |