diff options
-rw-r--r-- | src/luaotfload-auxiliary.lua | 26 | ||||
-rw-r--r-- | src/luaotfload-features.lua | 38 | ||||
-rw-r--r-- | src/luaotfload-letterspace.lua | 9 | ||||
-rw-r--r-- | src/luaotfload-main.lua | 23 | ||||
-rwxr-xr-x | src/luaotfload-tool.lua | 76 |
5 files changed, 103 insertions, 69 deletions
diff --git a/src/luaotfload-auxiliary.lua b/src/luaotfload-auxiliary.lua index e544dd7..e482aba 100644 --- a/src/luaotfload-auxiliary.lua +++ b/src/luaotfload-auxiliary.lua @@ -100,17 +100,21 @@ luaotfload_callbacks [#luaotfload_callbacks + 1] = { "patch_font", set_sscale_dimens, "set_sscale_dimens", } +local default_units = 1000 + --- fontobj -> int local lookup_units = function (fontdata) - local metadata = fontdata.shared and fontdata.shared.rawdata.metadata - if metadata and metadata.units then - return metadata.units - elseif fontdata.parameters and fontdata.parameters.units then - return fontdata.parameters.units - elseif fontdata.units then --- v1.x - return fontdata.units + local units = fontdata.units + if units and units > 0 then return units end + local shared = fontdata.shared if not shared then return default_units end + local rawdata = shared.rawdata if not rawdata then return default_units end + local metadata = rawdata.metadata if not metadata then return default_units end + local capheight = metadata.capheight if not capheight then return default_units end + local units = metadata.units or fontdata.units + if not units or units == 0 then + return default_units end - return 1000 + return units end --[[doc-- @@ -213,8 +217,9 @@ local query_ascender = function (fontdata) local metadata = rawdata.metadata if not metadata then return false end local ascender = parameters.ascender or metadata.ascender if not ascender then return false end - local units = metadata.units if units == 0 then return false end local size = parameters.size if not size then return false end + local units = lookup_units (fontdata) + if not units or units == 0 then return false end return ascender * size / units end @@ -224,8 +229,9 @@ local query_capheight = function (fontdata) local rawdata = shared.rawdata if not rawdata then return false end local metadata = rawdata.metadata if not metadata then return false end local capheight = metadata.capheight if not capheight then return false end - local units = metadata.units if units == 0 then return false end local size = parameters.size if not size then return false end + local units = lookup_units (fontdata) + if not units or units == 0 then return false end return capheight * size / units end diff --git a/src/luaotfload-features.lua b/src/luaotfload-features.lua index 5e9bf7b..5152fab 100644 --- a/src/luaotfload-features.lua +++ b/src/luaotfload-features.lua @@ -74,7 +74,7 @@ local defined_combos = 0 local handle_combination = function (combo, spec) defined_combos = defined_combos + 1 if not combo [1] then - report ("both", 0, "load", + report ("both", 0, "features", "combo %d: Empty font combination requested.", defined_combos) return false @@ -91,7 +91,7 @@ local handle_combination = function (combo, spec) tablesort (combo, cmp_by_idx) --- pass 1: skim combo and resolve fonts - report ("both", 0, "load", "combo %d: combining %d fonts.", + report ("both", 2, "features", "combo %d: combining %d fonts.", defined_combos, n) for i = 1, n do local cur = combo [i] @@ -101,18 +101,18 @@ local handle_combination = function (combo, spec) if fnt then local chars = cur.chars if chars == true then - report ("both", 0, "load", + report ("both", 2, "features", " *> %.2d: fallback font %d at rank %d.", i, id, idx) else - report ("both", 0, "load", + report ("both", 2, "features", " *> %.2d: include font %d at rank %d (%d items).", i, id, idx, (chars and #chars or 0)) end chain [#chain + 1] = { fnt, chars, idx = idx } fontids [#fontids + 1] = { id = id } else - report ("both", 0, "load", + report ("both", 0, "features", " *> %.2d: font %d at rank %d unknown, skipping.", n, id, idx) --- TODO might instead attempt to define the font at this point @@ -122,14 +122,14 @@ local handle_combination = function (combo, spec) local nc = #chain if nc == 0 then - report ("both", 0, "load", + report ("both", 0, "features", " *> no valid font (of %d) in combination.", n) return false end local basefnt = chain [1] [1] if nc == 1 then - report ("both", 0, "load", + report ("both", 0, "features", " *> combination boils down to a single font (%s) \z of %d initially specified; not pursuing this any \z further.", basefnt.fullname, n) @@ -168,27 +168,28 @@ local handle_combination = function (combo, spec) for j = 1, #def do local this = def [j] if type (this) == "number" then - report ("both", 0, "load", + report ("both", 2, "features", " *> [%d][%d]: import codepoint U+%.4X", i, j, this) pickchr (this) elseif type (this) == "table" then local lo, hi = unpack (this) - report ("both", 0, "load", + report ("both", 2, "features", " *> [%d][%d]: import codepoint range U+%.4X--U+%.4X", i, j, lo, hi) for uc = lo, hi do pickchr (uc) end else - report ("both", 0, "load", + report ("both", 0, "features", " *> item no. %d of combination definition \z %d not processable.", j, i) end end end - report ("both", 0, "load", + report ("both", 2, "features", " *> font %d / %d: imported %d glyphs into combo.", i, nc, cnt) end + spec.lookup = "combo" spec.file = basefnt.filename spec.name = stringformat ("luaotfload<%d>", defined_combos) spec.features = { normal = { spec.specification } } @@ -1081,7 +1082,7 @@ local apply_default_features = function (speclist) or (scripts[script] and script) or "dflt" if support_incomplete[script] then - report("log", 0, "load", + report("log", 0, "features", "Support for the requested script: " .. "%q may be incomplete.", script) end @@ -1090,13 +1091,13 @@ local apply_default_features = function (speclist) end speclist.script = script - report("log", 1, "load", + report("log", 2, "features", "Auto-selecting default features for script: %s.", script) local requested = default_features.defaults[script] if not requested then - report("log", 1, "load", + report("log", 2, "features", "No default features for script %q, falling back to \"dflt\".", script) requested = default_features.defaults.dflt @@ -1157,8 +1158,7 @@ local handle_slashed = function (modifiers) optsize = tonumber(mod[2]) elseif mod == false then --- ignore - report("log", 0, - "load", "unsupported font option: %s", v) + report("log", 0, "features", "unsupported font option: %s", v) elseif supported[mod] then style = supported[mod] elseif not stringis_empty(mod) then @@ -1189,9 +1189,9 @@ local handle_request = function (specification) --- in an anonymous lookup; --- we try to behave as friendly as possible --- just go with it ... - report("log", 1, "load", "invalid request %q of type anon", + report("log", 1, "features", "invalid request %q of type anon", specification.specification) - report("log", 1, "load", + report("log", 1, "features", "use square bracket syntax or consult the documentation.") --- The result of \fontname must be re-feedable into \font --- which is expected by the Latex font mechanism. Now this @@ -1255,7 +1255,7 @@ end if as_script == true then --- skip the remainder of the file fonts.names.handle_request = handle_request - report ("log", 5, "load", + report ("log", 5, "features", "Exiting early from luaotfload-features.lua.") return else diff --git a/src/luaotfload-letterspace.lua b/src/luaotfload-letterspace.lua index 40b3015..78df1d7 100644 --- a/src/luaotfload-letterspace.lua +++ b/src/luaotfload-letterspace.lua @@ -28,9 +28,6 @@ local setfield = nodedirect.setfield local field_setter = function (name) return function (n, ...) setfield (n, name, ...) end end local field_getter = function (name) return function (n, ...) getfield (n, name, ...) end end ---- As of December 2014 the faster ``node.direct.*`` interface is ---- preferred. - local getfont = nodedirect.getfont local getid = nodedirect.getid @@ -351,7 +348,7 @@ kerncharacters = function (head) end start = c setfield(s, "components", nil) - free_node(s) + --free_node(s) --> double free with multipart components c = getfield (start, "components") end end @@ -416,7 +413,7 @@ kerncharacters = function (head) else local kern = 0 local kerns = prevchardata.kerns - if kerns then kern = kerns[lastchar] end + if kerns then kern = kerns[lastchar] or kern end krn = kern + quaddata[lastfont]*krn -- here insert_node_before(head,start,kern_injector(fillup,krn)) end @@ -491,7 +488,7 @@ kerncharacters = function (head) --- font doesn’t contain the glyph else local kerns = prevchardata.kerns - if kerns then kern = kerns[lastchar] end + if kerns then kern = kerns[lastchar] or kern end end end krn = kern + quaddata[lastfont]*krn -- here diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua index 9e8d088..25be3db 100644 --- a/src/luaotfload-main.lua +++ b/src/luaotfload-main.lua @@ -13,9 +13,30 @@ local luaotfload = luaotfload luaotfload.log = luaotfload.log or { } luaotfload.version = "2.7" luaotfload.loaders = { } -luaotfload.min_luatex_version = 95 --- i. e. 0.95 +luaotfload.min_luatex_version = { 0, 95, 0 } --- i. e. 0.95.0 luaotfload.fontloader_package = "reference" --- default: from current Context +if not tex or not tex.luatexversion then + error "this program must be run in TeX mode" --- or call tex.initialize() =) +else + --- version check + local major = tex.luatexversion / 100 + local minor = tex.luatexversion % 100 + local revision = tex.luatexrevision --[[ : string ]] + local revno = tonumber (revision) + local minimum = luaotfload.min_luatex_version + if major < minimum [1] or minor < minimum [2] + or revno and revno < minimum [3] + then + texio.write_nl ("term and log", + string.format ("\tFATAL ERROR\n\z + \tLuaotfload requires a Luatex version >= %d.%d.%d.\n\z + \tPlease update your TeX distribution!\n\n", + (unpack or table.unpack) (minimum))) + error "version check failed" + end +end + local authors = "\z Hans Hagen,\z Khaled Hosny,\z diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua index 376aa39..35dc9b3 100755 --- a/src/luaotfload-tool.lua +++ b/src/luaotfload-tool.lua @@ -7,10 +7,11 @@ -- LICENSE: GPL v2.0 ----------------------------------------------------------------------- -luaotfload = luaotfload or { } -local version = "2.7" -luaotfload.version = version -luaotfload.self = "luaotfload-tool" +luaotfload = luaotfload or { } +local version = "2.7" +luaotfload.version = version +luaotfload.min_luatex_version = { 0, 95, 0 } --- i. e. 0.95.0 +luaotfload.self = "luaotfload-tool" --[[doc-- @@ -33,16 +34,6 @@ see the luaotfload documentation for more info. Report bugs to kpse.set_program_name "luatex" ---[[doc-- - - We test for Lua 5.1 by means of capability detection to see if - we’re running an outdated Luatex. If so, we bail. - - \url{http://lua-users.org/wiki/LuaVersionCompatibility} - ---doc]]-- - - local iowrite = io.write local kpsefind_file = kpse.find_file local mathfloor = math.floor @@ -59,19 +50,32 @@ local texiowrite = texio.write local tonumber = tonumber local type = type -local runtime -if _G.getfenv ~= nil then -- 5.1 or LJ - if _G.jit ~= nil then - runtime = { "jit", jit.version } - else - runtime = { "stock", _VERSION } - print "FATAL ERROR" - print "Luaotfload requires a Luatex version >=0.76." - print "Please update your TeX distribution!" - os.exit (-1) - end -else -- 5.2 - runtime = { "stock", _VERSION } +do + local runtime = _G.jit and { "jit" , jit.version } + or { "stock", _VERSION } + local stats = status and status.list () + local minimum = luaotfload.min_luatex_version + local actual = { 0, 0, 0 } + if stats then + local major = stats.luatex_version / 100 + local minor = stats.luatex_version % 100 + local revision = stats.luatex_revision --[[ : string ]] + local revno = tonumber (revision) + actual = { major, minor, revno or 0 } + end + + if actual [1] < minimum [1] or actual [2] < minimum [2] + or actual [3] < minimum [3] + then + texio.write_nl ("term and log", + string.format ("\tFATAL ERROR\n\z + \tLuaotfload requires a Luatex version >= %d.%d.%d.\n\z + \tPlease update your TeX distribution!\n\n", + (unpack or table.unpack) (minimum))) + error "version check failed" + end + luaotfload.runtime = runtime + luaotfload.luatex_version = actual end local C, Ct, P, S = lpeg.C, lpeg.Ct, lpeg.P, lpeg.S @@ -336,15 +340,21 @@ local version_msg = function ( ) local out = function (...) texiowrite_nl (stringformat (...)) end local uname = os.uname () local meta = fonts.names.getmetadata () - local info = status.list () + + local runtime = luaotfload.runtime + local actual = luaotfload.luatex_version + local status = config.luaotfload.status + local notes = status and status.notes or { } + out (about, luaotfload.self) out ("%s version: %q", luaotfload.self, version) - out ("Revision: %q", config.luaotfload.status.notes.revision) + if notes.description then + out ("Luaotfload: %q", notes.description) + end + out ("Revision: %q", notes.revision) out ("Lua interpreter: %s; version %q", runtime[1], runtime[2]) --[[out ("Luatex SVN revision: %d", info.luatex_svn)]] --> SVN r5624 - out ("Luatex version: %.2f.%d", - info.luatex_version / 100, - info.luatex_revision) + out ("Luatex version: %d.%d", actual [1], actual [2]) out ("Platform: type=%s name=%s", os.type, os.name) local uname_vars = tablesortedkeys (uname) @@ -356,7 +366,7 @@ local version_msg = function ( ) out("No database metadata available.") else out ("Index: version=%q created=%q modified=%q", - config.luaotfload.status.notes.revision, + meta.version or "too old", meta.created or "ages ago", meta.modified or "ages ago") end |