From ef85671565a0b9d7a5c1ad5d4fec49e9e9a589c4 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Wed, 2 Mar 2011 20:32:23 +0200 Subject: Reinstate our changes to font-xtx.lua --- otfl-font-xtx.lua | 140 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 124 insertions(+), 16 deletions(-) (limited to 'otfl-font-xtx.lua') diff --git a/otfl-font-xtx.lua b/otfl-font-xtx.lua index 505e085..1396199 100644 --- a/otfl-font-xtx.lua +++ b/otfl-font-xtx.lua @@ -40,47 +40,155 @@ local list = { } specifiers.colonizedpreference = "file" +local function isstyle(s) + local style = string.lower(s):split("/") + for _,v in ipairs(style) do + if v == "b" then + list.style = "bold" + elseif v == "i" then + list.style = "italic" + elseif v == "bi" or v == "ib" then + list.style = "bolditalic" + elseif v:find("^s=") then + list.optsize = v:split("=")[2] + elseif v == "aat" or v == "icu" or v == "gr" then + logs.report("load font", "unsupported font option: %s", v) + elseif not v:is_empty() then + list.style = v:gsub("[^%a%d]", "") + end + end +end + +fonts = fonts or { } +fonts.otf = fonts.otf or { } + +local otf = fonts.otf + +otf.tables = otf.tables or { } + +otf.tables.defaults = { + dflt = { + "ccmp", "locl", "rlig", "liga", "clig", + "kern", "mark", "mkmk", + }, + arab = { + "ccmp", "locl", "isol", "fina", "fin2", + "fin3", "medi", "med2", "init", "rlig", + "calt", "liga", "cswh", "mset", "curs", + "kern", "mark", "mkmk", + }, + deva = { + "ccmp", "locl", "init", "nukt", "akhn", + "rphf", "blwf", "half", "pstf", "vatu", + "pres", "blws", "abvs", "psts", "haln", + "calt", "blwm", "abvm", "dist", "kern", + "mark", "mkmk", + }, + khmr = { + "ccmp", "locl", "pref", "blwf", "abvf", + "pstf", "pres", "blws", "abvs", "psts", + "clig", "calt", "blwm", "abvm", "dist", + "kern", "mark", "mkmk", + }, + thai = { + "ccmp", "locl", "liga", "kern", "mark", + "mkmk", + }, + hang = { + "ccmp", "ljmo", "vjmo", "tjmo", + }, +} + +otf.tables.defaults.beng = otf.tables.defaults.deva +otf.tables.defaults.guru = otf.tables.defaults.deva +otf.tables.defaults.gujr = otf.tables.defaults.deva +otf.tables.defaults.orya = otf.tables.defaults.deva +otf.tables.defaults.taml = otf.tables.defaults.deva +otf.tables.defaults.telu = otf.tables.defaults.deva +otf.tables.defaults.knda = otf.tables.defaults.deva +otf.tables.defaults.mlym = otf.tables.defaults.deva +otf.tables.defaults.sinh = otf.tables.defaults.deva + +otf.tables.defaults.syrc = otf.tables.defaults.arab +otf.tables.defaults.mong = otf.tables.defaults.arab +otf.tables.defaults.nko = otf.tables.defaults.arab + +otf.tables.defaults.tibt = otf.tables.defaults.khmr + +otf.tables.defaults.lao = otf.tables.defaults.thai + +local function parse_script(script) + if otf.tables.scripts[script] then + local dflt + if otf.tables.defaults[script] then + logs.report("load font", "auto-selecting default features for script: %s", script) + dflt = otf.tables.defaults[script] + else + logs.report("load font", "auto-selecting default features for script: dflt (was %s)", script) + dflt = otf.tables.defaults["dflt"] + end + for _,v in next, dflt do + list[v] = "yes" + end + else + logs.report("load font", "unknown script: %s", script) + end +end + +specifiers.colonizedpreference = "file" + local function issome () list.lookup = specifiers.colonizedpreference end local function isfile () list.lookup = 'file' end local function isname () list.lookup = 'name' end local function thename(s) list.name = s end local function issub (v) list.sub = v end -local function iscrap (s) list.crap = string.lower(s) end -local function istrue (s) list[s] = 'yes' end -local function isfalse(s) list[s] = 'no' end -local function iskey (k,v) list[k] = v end - local function istrue (s) list[s] = true end local function isfalse(s) list[s] = false end +local function iskey (k,v) + if k == "script" then + parse_script(v) + end + list[k] = v +end local P, S, R, C = lpeg.P, lpeg.S, lpeg.R, lpeg.C local spaces = P(" ")^0 local namespec = (1-S("/:("))^0 -- was: (1-S("/: ("))^0 -local crapspec = spaces * P("/") * (((1-P(":"))^0)/iscrap) * spaces -local filename = (P("file:")/isfile * (namespec/thename)) + (P("[") * P(true)/isname * (((1-P("]"))^0)/thename) * P("]")) +local filespec = (R("az", "AZ") * P(":"))^-1 * (1-S(":("))^1 +local stylespec = spaces * P("/") * (((1-P(":"))^0)/isstyle) * spaces +local filename = (P("file:")/isfile * (filespec/thename)) + (P("[") * P(true)/isname * (((1-P("]"))^0)/thename) * P("]")) local fontname = (P("name:")/isname * (namespec/thename)) + P(true)/issome * (namespec/thename) local sometext = (R("az","AZ","09") + S("+-."))^1 local truevalue = P("+") * spaces * (sometext/istrue) local falsevalue = P("-") * spaces * (sometext/isfalse) -local keyvalue = (C(sometext) * spaces * P("=") * spaces * C(sometext))/iskey +local keyvalue = P("+") + (C(sometext) * spaces * P("=") * spaces * C(sometext))/iskey local somevalue = sometext/istrue local subvalue = P("(") * (C(P(1-S("()"))^1)/issub) * P(")") -- for Kim local option = spaces * (keyvalue + falsevalue + truevalue + somevalue) * spaces local options = P(":") * spaces * (P(";")^0 * option)^0 -local pattern = (filename + fontname) * subvalue^0 * crapspec^0 * options^0 +local pattern = (filename + fontname) * subvalue^0 * stylespec^0 * options^0 local function colonized(specification) -- xetex mode list = { } lpegmatch(pattern,specification.specification) - -- for k, v in next, list do - -- list[k] = is_boolean(v) - -- if type(list[a]) == "nil" then - -- list[k] = v - -- end - -- end - list.crap = nil -- style not supported, maybe some day + if list.style then + specification.style = list.style + list.style = nil + end + if list.optsize then + specification.optsize = list.optsize + list.optsize = nil + end if list.name then + if resolvers.findfile(list.name, "tfm") then + list.lookup = "file" + list.name = file.addsuffix(list.name, "tfm") + elseif resolvers.findfile(list.name, "ofm") then + list.lookup = "file" + list.name = file.addsuffix(list.name, "ofm") + end + specification.name = list.name list.name = nil end -- cgit v1.2.3