From 4962a4a9bc747e2ba62331c652a1802922509365 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Fri, 15 Jan 2010 08:18:40 +0200 Subject: Support auto-detecting font style We now support XeTeX's syntax, try: \input luaotfload.sty \font\termesr ={TeX Gyre Termes:+liga} at 10pt \font\termesb ={TeX Gyre Termes/B:+liga} at 10pt \font\termesi ={TeX Gyre Termes/I:+liga} at 10pt \font\termesbi={TeX Gyre Termes/BI:+liga} at 10pt \font\termesib={TeX Gyre Termes/IB:+liga} at 10pt \termesr What a nice day fi fl ffi ffl ff\par \termesb What a nice day fi fl ffi ffl ff\par \termesi What a nice day fi fl ffi ffl ff\par \termesbi What a nice day fi fl ffi ffl ff\par \termesib What a nice day fi fl ffi ffl ff\par \bye --- otfl-font-def.lua | 4 ++-- otfl-font-xtx.lua | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/otfl-font-def.lua b/otfl-font-def.lua index 02369cc..99cc5e1 100644 --- a/otfl-font-def.lua +++ b/otfl-font-def.lua @@ -241,7 +241,7 @@ end function define.resolvers.name(specification) local resolve = fonts.names.resolve if resolve then - specification.resolved, specification.sub = fonts.names.resolve(specification.name,specification.sub) + specification.resolved, specification.sub = fonts.names.resolve(specification.name,specification.sub,specification.style) if specification.resolved then specification.forced = file.extname(specification.resolved) specification.name = file.removesuffix(specification.resolved) @@ -254,7 +254,7 @@ end function define.resolvers.spec(specification) local resolvespec = fonts.names.resolvespec if resolvespec then - specification.resolved, specification.sub = fonts.names.resolvespec(specification.name,specification.sub) + specification.resolved, specification.sub = fonts.names.resolvespec(specification.name,specification.sub,specification.style) if specification.resolved then specification.forced = file.extname(specification.resolved) specification.name = file.removesuffix(specification.resolved) diff --git a/otfl-font-xtx.lua b/otfl-font-xtx.lua index 56bedf9..ac4ebb1 100644 --- a/otfl-font-xtx.lua +++ b/otfl-font-xtx.lua @@ -62,12 +62,23 @@ local list = { } fonts.define.specify.colonized_default_lookup = "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 list.style == "ib" then + list.style = "bolditalic" + end + end +end local function issome () list.lookup = fonts.define.specify.colonized_default_lookup 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 --KH local function isfalse(s) list[s] = 'no' end local function isfalse(s) list[s] = nil end -- see mpg/luaotfload#4 @@ -75,7 +86,7 @@ local function iskey (k,v) list[k] = v end local spaces = lpeg.P(" ")^0 local namespec = (1-lpeg.S("/:("))^0 -- was: (1-lpeg.S("/: ("))^0 -local crapspec = spaces * lpeg.P("/") * (((1-lpeg.P(":"))^0)/iscrap) * spaces +local crapspec = spaces * lpeg.P("/") * (((1-lpeg.P(":"))^0)/isstyle) * spaces local filename = (lpeg.P("file:")/isfile * (namespec/thename)) + (lpeg.P("[") * lpeg.P(true)/isname * (((1-lpeg.P("]"))^0)/thename) * lpeg.P("]")) local fontname = (lpeg.P("name:")/isname * (namespec/thename)) + lpeg.P(true)/issome * (namespec/thename) local sometext = (lpeg.R("az") + lpeg.R("AZ") + lpeg.R("09"))^1 @@ -98,7 +109,10 @@ function fonts.define.specify.colonized(specification) -- xetex mode 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.name then specification.name = list.name list.name = nil -- cgit v1.2.3