Progress on vf fonts

This commit is contained in:
Marcel Krüger 2020-06-18 01:38:20 +02:00
parent 23d93b55ac
commit bb955cb1c3
2 changed files with 23 additions and 8 deletions

View File

@ -53,14 +53,33 @@ function font.define(f)
font.fonts[i] = f font.fonts[i] = f
return i return i
end end
callback_register('define_font', function(name, size) local function base_define_font_cb(name, size)
local f = read_tfm(name, size) local f = read_tfm(name, size)
if not f then return end
local vf = read_vf(name, size)
if vf then
local fonts = {}
f.fonts = fonts
for i, f in next, vf.fonts do
if vf.id then
fonts[i] = f
else
fonts[i] = {id = assert(base_define_font_cb(f.name, f.size))}
end
end
f.type = 'virtual'
local realchars = f.characters
for cp, char in next, vf.characters do
assert(realchars[cp]).commands = char.commands
end
end
local id = font.define(f) local id = font.define(f)
if status.ini_version then if status.ini_version then
lua.prepared_code[#lua.prepared_code+1] = string.format("assert(%i == font.define(font.read_tfm(%q, %i)))", id, name, size) lua.prepared_code[#lua.prepared_code+1] = string.format("assert(%i == font.define(font.read_tfm(%q, %i)))", id, name, size)
end end
return id return id
end) end
callback_register('define_font', base_define_font_cb)
callback_register('find_log_file', function(name) return name end) callback_register('find_log_file', function(name) return name end)
do do
local function normal_find_data_file(name) local function normal_find_data_file(name)

View File

@ -354,14 +354,14 @@ local function do_commands(p, c, f, fid, x, y, outer, ...)
nodehandler[getid(cmd)](p, cmd, x, y, nil, ...) nodehandler[getid(cmd)](p, cmd, x, y, nil, ...)
x = x + getwidth(cmd) x = x + getwidth(cmd)
elseif cmd[1] == "font" then elseif cmd[1] == "font" then
current_font = fonts[cmd[2]] current_font = assert(fonts[cmd[2]], "invalid font requested")
elseif cmd[1] == "char" then elseif cmd[1] == "char" then
local n = direct.new'glyph' local n = direct.new'glyph'
setsubtype(n, 256) setsubtype(n, 256)
setfont(n, current_font.id, cmd[2]) setfont(n, current_font.id, cmd[2])
nodehandler.glyph(p, n, x, y, outer, ...) nodehandler.glyph(p, n, x, y, outer, ...)
direct.free(n)
x = x + getwidth(n) x = x + getwidth(n)
direct.free(n)
elseif cmd[1] == "slot" then elseif cmd[1] == "slot" then
local n = direct.new'glyph' local n = direct.new'glyph'
setsubtype(n, 256) setsubtype(n, 256)
@ -401,10 +401,6 @@ local function do_commands(p, c, f, fid, x, y, outer, ...)
-- else -- else
-- NOP, comment and invalid commands ignored -- NOP, comment and invalid commands ignored
end end
if #commands ~= 1 then error[[Unsupported command number]] end
if commands[1][1] ~= "node" then error[[Unsupported command name]] end
commands = commands[1][2]
nodehandler[getid(commands)](p, commands, x, y, nil, ...)
end end
end end
function nodehandler.glyph(p, n, x, y, ...) function nodehandler.glyph(p, n, x, y, ...)