diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2010-01-13 22:54:23 +0200 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2010-01-14 18:58:32 +0200 |
commit | d2ef853c06ff6d0806117fe24f2c9ce4af4c8fb2 (patch) | |
tree | 403cc9458cb349f1fe8f2f9ffaa3eaf647313a90 /luaotfload-fonts.lua | |
parent | ca6917bd3fabfe6e48be5bc9668f6a6c430354b7 (diff) | |
download | luaotfload-d2ef853c06ff6d0806117fe24f2c9ce4af4c8fb2.tar.gz |
Our own font names extraction implementation
Instead of using (the faster) fontloader.info, we now fully open the
font to get more usable data, my be it is worth extending
fontloader.info to cover our needs?
Diffstat (limited to 'luaotfload-fonts.lua')
-rw-r--r-- | luaotfload-fonts.lua | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/luaotfload-fonts.lua b/luaotfload-fonts.lua index 5976477..17d81d5 100644 --- a/luaotfload-fonts.lua +++ b/luaotfload-fonts.lua @@ -36,11 +36,57 @@ local function clean(str) return string.gsub(string.lower(str), "[^%a%d]", "") end +local function tprint(t) print(table.serialize(t)) end +function fontloader.fullinfo(filename) + local f, w, m, t, n = nil, nil, nil, { }, { } + f, w = fontloader.open(filename) + m = fontloader.to_table(f) + fontloader.close(f) + m.glyphs, m.gpos, m.gsub, m.kerns, m.lookups, m.map = nil, nil, nil, nil, nil, nil + m.anchor_classes, m.mark_classes, m.horiz_base = nil, nil, nil + if m.names then + for _,v in pairs(m.names) do + if v.lang == "English (US)" then + n.full = v.names.compatfull + n.family = v.names.preffamilyname + n.subfamily = v.names.subfamily + end + end + end + if m.fontstyle_name then + for _,v in pairs(m.fontstyle_name) do + if v.lang == 1033 then + m.style = v.name + end + end + end + t.psname = m.fontname + t.fullname = n.full or m.fullname + t.family = n.family or m.familyname + t.style = n.subfamily or m.style --or t.fullname:gsub(t.family, "") + if not t.style or t.style == "" then + local s = t.psname:split("-") + if s and #s >= 2 then + t.style = s[#s] + end + end + if not t.style then + if n.full and n.family then + t.style = n.full:gsub(n.family, "") + elseif m.fontname and m.familyname then + t.style = m.fontname:gsub(m.familyname, "") + end + end +-- tprint(m) print(w) + m, n = nil, nil + return t +end + local function load_font(filename, names, texmf) local mappings = names.mappings local key if filename then - local info = fontloader.info(filename) + local info = fontloader.fullinfo(filename) if texmf == true then filename = basename(filename) end if info then if type(info) == "table" and #info > 1 then @@ -55,7 +101,7 @@ local function load_font(filename, names, texmf) else key = clean(info.fullname) if not mappings[key] then - mappings[key] = { info.fullname, filename } + mappings[key] = { info.psname, info.fullname, info.family, info.style, filename } else log("Font '%s' already exists.", key) end @@ -128,4 +174,6 @@ luaotfload.fonts.generate = generate if arg[0] == "luaotfload-fonts.lua" then generate() +-- t = fontloader.fullinfo(arg[1]) +-- tprint(t) end |