diff options
author | Karl Berry <karl@freefriends.org> | 2013-05-06 22:01:04 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-05-06 22:01:04 +0000 |
commit | f5404c03d41c0cf6039679818e8c0e2929c32949 (patch) | |
tree | 5c9d6c9a7f6148271d565e403294dedaab7c6129 /Master/texmf-dist/tex/luatex/luaotfload/luaotfload.lua | |
parent | 849cac0ff436060e322aade5217a2a5f9847fec9 (diff) |
luaotfload (6may13)
git-svn-id: svn://tug.org/texlive/trunk@30246 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luaotfload/luaotfload.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luaotfload/luaotfload.lua | 404 |
1 files changed, 294 insertions, 110 deletions
diff --git a/Master/texmf-dist/tex/luatex/luaotfload/luaotfload.lua b/Master/texmf-dist/tex/luatex/luaotfload/luaotfload.lua index 9a5b769fff7..343abc5f830 100644 --- a/Master/texmf-dist/tex/luatex/luaotfload/luaotfload.lua +++ b/Master/texmf-dist/tex/luatex/luaotfload/luaotfload.lua @@ -7,151 +7,335 @@ -- luaotfload.dtx (with options: `lua') -- This is a generated file. -- --- Copyright (C) 2009-2013 by by Elie Roux <elie.roux@telecom-bretagne.eu> --- and Khaled Hosny <khaledhosny@eglug.org> --- (Support: <lualatex-dev@tug.org>.) +-- Copyright (C) 2009-2013 +-- by Elie Roux <elie.roux@telecom-bretagne.eu> +-- and Khaled Hosny <khaledhosny@eglug.org> +-- and Philipp Gesang <philipp.gesang@alumni.uni-heidelberg.de> -- --- This work is under the CC0 license. +-- Home: https://github.com/lualatex/luaotfload +-- Support: <lualatex-dev@tug.org>. +-- +-- This work is under the GPL v2.0 license. -- -- This work consists of the main source file luaotfload.dtx -- and the derived files -- luaotfload.sty, luaotfload.lua -- -module("luaotfload", package.seeall) +luaotfload = luaotfload or {} +local luaotfload = luaotfload + +config = config or { } +config.luaotfload = config.luaotfload or { } +------.luaotfload.resolver = config.luaotfload.resolver or "normal" +config.luaotfload.resolver = config.luaotfload.resolver or "cached" +config.luaotfload.definer = config.luaotfload.definer or "patch" +config.luaotfload.loglevel = config.luaotfload.loglevel or 1 +config.luaotfload.color_callback = config.luaotfload.color_callback or "pre_linebreak_filter" +--luaotfload.prefer_merge = config.luaotfload.prefer_merge or true luaotfload.module = { name = "luaotfload", - version = 1.29, - date = "2013/04/25", + version = 2.2, + date = "2013/04/29", description = "OpenType layout system.", author = "Elie Roux & Hans Hagen", copyright = "Elie Roux", - license = "CC0" + license = "GPL v2.0" } -local error, warning, info, log = luatexbase.provides_module(luaotfload.module) -kpse.init_prog("", 600, "/") -local luatex_version = 60 +local luatexbase = luatexbase + +local type, next = type, next +local setmetatable = setmetatable +local find_file = kpse.find_file +local lfsisfile = lfs.isfile +local stringfind = string.find +local stringformat = string.format +local stringmatch = string.match +local stringsub = string.sub + +local add_to_callback, create_callback = + luatexbase.add_to_callback, luatexbase.create_callback +local reset_callback, call_callback = + luatexbase.reset_callback, luatexbase.call_callback + +local dummy_function = function () end + + +luaotfload.font_definer = "patch" --- | ^^e2^^80^^9cgeneric^^e2^^80^^9d | ^^e2^^80^^9cold^^e2^^80^^9d + +local error, warning, info, log = + luatexbase.provides_module(luaotfload.module) + +luaotfload.error = error +luaotfload.warning = warning +luaotfload.info = info +luaotfload.log = log + + +local luatex_version = 76 if tex.luatexversion < luatex_version then warning("LuaTeX v%.2f is old, v%.2f is recommended.", tex.luatexversion/100, luatex_version /100) end -function luaotfload.loadmodule(name) - local tofind = "otfl-"..name - local found = kpse.find_file(tofind,"tex") - if found then - log("loading file %s.", found) - dofile(found) - else - error("file %s not found.", tofind) + + +local fl_prefix = "luaotfload" -- ^^e2^^80^^9cluatex^^e2^^80^^9d for luatex-plain +local loadmodule = function (name) + require(fl_prefix .."-"..name) +end + +local Cs, P, lpegmatch = lpeg.Cs, lpeg.P, lpeg.match + +local p_dot, p_slash = P".", P"/" +local p_suffix = (p_dot * (1 - p_dot - p_slash)^1 * P(-1)) / "" +local p_removesuffix = Cs((p_suffix + 1)^1) + +local find_vf_file = function (name) + local fullname = find_file(name, "ovf") + if not fullname then + --fullname = find_file(file.removesuffix(name), "ovf") + fullname = find_file(lpegmatch(p_removesuffix, name), "ovf") + end + if fullname then + log("loading virtual font file %s.", fullname) end + return fullname end -luaotfload.loadmodule("luat-dum.lua") -- not used in context at all -luaotfload.loadmodule("luat-ovr.lua") -- override some luat-dum functions -luaotfload.loadmodule("data-con.lua") -- maybe some day we don't need this one -tex.attribute[0] = 0 -luaotfload.loadmodule("font-ini.lua") -luaotfload.loadmodule("node-dum.lua") -luaotfload.loadmodule("node-inj.lua") -function attributes.private(name) - local attr = "otfl@" .. name - local number = luatexbase.attributes[attr] - if not number then - number = luatexbase.new_attribute(attr) + + +local starttime = os.gettimeofday() + +local trapped_register = callback.register +callback.register = dummy_function + + +do + local new_attribute = luatexbase.new_attribute + local the_attributes = luatexbase.attributes + + attributes = attributes or { } + + attributes.private = function (name) + local attr = "luaotfload@" .. name --- used to be: ^^e2^^80^^9cotfl@^^e2^^80^^9d + local number = the_attributes[attr] + if not number then + number = new_attribute(attr) + end + return number end - return number end -luaotfload.loadmodule("font-tfm.lua") -luaotfload.loadmodule("font-cid.lua") -luaotfload.loadmodule("font-ott.lua") -luaotfload.loadmodule("font-map.lua") -luaotfload.loadmodule("font-otf.lua") -luaotfload.loadmodule("font-otd.lua") -luaotfload.loadmodule("font-oti.lua") -luaotfload.loadmodule("font-otb.lua") -luaotfload.loadmodule("font-otn.lua") -luaotfload.loadmodule("font-ota.lua") -luaotfload.loadmodule("font-otc.lua") -luaotfload.loadmodule("font-def.lua") -luaotfload.loadmodule("font-xtx.lua") -luaotfload.loadmodule("font-dum.lua") -if fonts and fonts.tfm and fonts.tfm.readers then - fonts.tfm.readers.ofm = fonts.tfm.readers.tfm + + +local context_environment = { } + +local push_namespaces = function () + log("push namespace for font loader") + local normalglobal = { } + for k, v in next, _G do + normalglobal[k] = v + end + return normalglobal end -luaotfload.loadmodule("font-nms.lua") -luaotfload.loadmodule("font-clr.lua") -luatexbase.create_callback("luaotfload.patch_font", "simple", function() end) -local function def_font(...) - local fontdata = fonts.define.read(...) - if type(fontdata) == "table" and fontdata.shared then - local otfdata = fontdata.shared.otfdata - if otfdata.metadata.math then - local mc = { } - for k,v in next, otfdata.metadata.math do - if k:find("Percent") then - -- keep percent values as is - mc[k] = v - else - mc[k] = v / fontdata.units * fontdata.size + +local pop_namespaces = function (normalglobal, isolate) + if normalglobal then + local _G = _G + local mode = "non-destructive" + if isolate then mode = "destructive" end + log("pop namespace from font loader -- " .. mode) + for k, v in next, _G do + if not normalglobal[k] then + context_environment[k] = v + if isolate then + _G[k] = nil end end - -- for \overwithdelims - mc.FractionDelimiterSize = 1.01 * fontdata.size - mc.FractionDelimiterDisplayStyleSize = 2.39 * fontdata.size - - fontdata.MathConstants = mc end - luatexbase.call_callback("luaotfload.patch_font", fontdata) + for k, v in next, normalglobal do + _G[k] = v + end + -- just to be sure: + setmetatable(context_environment,_G) + else + log("irrecoverable error during pop_namespace: no globals to restore") + os.exit() end - return fontdata -end ---fonts.define.resolvers.file = fonts.define.resolvers.name -containers.cleanname = function (name) - return (string.gsub(string.lower(name),"[^%w%d\128\255]+","-")) end -fonts.mode = "node" -local register_base_sub = fonts.otf.features.register_base_substitution -local gsubs = { - "ss01", "ss02", "ss03", "ss04", "ss05", - "ss06", "ss07", "ss08", "ss09", "ss10", - "ss11", "ss12", "ss13", "ss14", "ss15", - "ss16", "ss17", "ss18", "ss19", "ss20", -} -for _,v in next, gsubs do - register_base_sub(v) +luaotfload.context_environment = context_environment +luaotfload.push_namespaces = push_namespaces +luaotfload.pop_namespaces = pop_namespaces + +local our_environment = push_namespaces() + + +tex.attribute[0] = 0 + + +loadmodule"merged.lua" +---loadmodule"font-odv.lua" --- <= Devanagari support from Context + +if fonts then + + if not fonts._merge_loaded_message_done_ then + --- a program talking first person -- HH sure believes in strong AI ... + log[[^^e2^^80^^9cI am using the merged version of 'luaotfload.lua' here. If]] + log[[ you run into problems or experience unexpected behaviour,]] + log[[ and if you have ConTeXt installed you can try to delete the]] + log[[ file 'luaotfload-font-merged.lua' as I might then use the]] + log[[ possibly updated libraries. The merged version is not]] + log[[ supported as it is a frozen instance. Problems can be]] + log[[ reported to the ConTeXt mailing list.^^e2^^80^^9d]] + end + fonts._merge_loaded_message_done_ = true + +else--- the loading sequence is known to change, so this might have to + --- be updated with future updates! + --- do not modify it though unless there is a change to the merged + --- package! + loadmodule("l-lua.lua") + loadmodule("l-lpeg.lua") + loadmodule("l-function.lua") + loadmodule("l-string.lua") + loadmodule("l-table.lua") + loadmodule("l-io.lua") + loadmodule("l-file.lua") + loadmodule("l-boolean.lua") + loadmodule("l-math.lua") + loadmodule("util-str.lua") + loadmodule('luatex-basics-gen.lua') + loadmodule('data-con.lua') + loadmodule('luatex-basics-nod.lua') + loadmodule('font-ini.lua') + loadmodule('font-con.lua') + loadmodule('luatex-fonts-enc.lua') + loadmodule('font-cid.lua') + loadmodule('font-map.lua') + loadmodule('luatex-fonts-syn.lua') + loadmodule('luatex-fonts-tfm.lua') + loadmodule('font-oti.lua') + loadmodule('font-otf.lua') + loadmodule('font-otb.lua') + loadmodule('node-inj.lua') + loadmodule('font-ota.lua') + loadmodule('font-otn.lua') + loadmodule('font-otp.lua')--- since 2013-04-23 + loadmodule('luatex-fonts-lua.lua') + loadmodule('font-def.lua') + loadmodule('luatex-fonts-def.lua') + loadmodule('luatex-fonts-ext.lua') + loadmodule('luatex-fonts-cbk.lua') +end --- non-merge fallback scope + + +pop_namespaces(our_environment, false)-- true) + +log("fontloader loaded in %0.3f seconds", os.gettimeofday()-starttime) + + +callback.register = trapped_register + + +add_to_callback("pre_linebreak_filter", + nodes.simple_font_handler, + "luaotfload.node_processor", + 1) +add_to_callback("hpack_filter", + nodes.simple_font_handler, + "luaotfload.node_processor", + 1) +add_to_callback("find_vf_file", + find_vf_file, "luaotfload.find_vf_file") + +loadmodule"lib-dir.lua" --- required by luaofload-database.lua +loadmodule"override.lua" --- ^^e2^^80^^9cluat-ovr^^e2^^80^^9d + +logs.set_loglevel(config.luaotfload.loglevel) + +loadmodule"loaders.lua" --- ^^e2^^80^^9cfont-pfb^^e2^^80^^9d new in 2.0, added 2011 +loadmodule"database.lua" --- ^^e2^^80^^9cfont-nms^^e2^^80^^9d +loadmodule"colors.lua" --- ^^e2^^80^^9cfont-clr^^e2^^80^^9d + + +local request_resolvers = fonts.definers.resolvers +local formats = fonts.formats +formats.ofm = "type1" + +request_resolvers.file = function (specification) + local found = fonts.names.crude_file_lookup(specification.name) + --local found = fonts.names.crude_file_lookup_verbose(specification.name) + specification.name = found[1] + --if format then specification.forced = format end end -luatexbase.add_to_callback("pre_linebreak_filter", - nodes.simple_font_handler, - "luaotfload.pre_linebreak_filter") -luatexbase.add_to_callback("hpack_filter", - nodes.simple_font_handler, - "luaotfload.hpack_filter") -luatexbase.reset_callback("define_font") -luatexbase.add_to_callback("define_font", - def_font, - "luaotfload.define_font", 1) -luatexbase.add_to_callback("find_vf_file", - fonts.vf.find, - "luaotfload.find_vf_file") -local function set_sscale_diments(fontdata) - local mc = fontdata.MathConstants - if mc then - if mc["ScriptPercentScaleDown"] then - fontdata.parameters[10] = mc.ScriptPercentScaleDown - else -- resort to plain TeX default - fontdata.parameters[10] = 70 - end - if mc["ScriptScriptPercentScaleDown"] then - fontdata.parameters[11] = mc.ScriptScriptPercentScaleDown - else -- resort to plain TeX default - fontdata.parameters[11] = 50 + + +--request_resolvers.anon = request_resolvers.name + +local type1_formats = { "tfm", "ofm", } + +request_resolvers.anon = function (specification) + local name = specification.name + for i=1, #type1_formats do + local format = type1_formats[i] + if resolvers.findfile(name, format) then + specification.name = file.addsuffix(name, format) + return end end + request_resolvers.name(specification) +end + +request_resolvers.path = function (specification) + local exists, _ = lfsisfile(specification.name) + if not exists then -- resort to file: lookup + request_resolvers.file(specification) + end end -luatexbase.add_to_callback("luaotfload.patch_font", set_sscale_diments, "unicodemath.set_sscale_diments") + +create_callback("luaotfload.patch_font", "simple", dummy_function) + + +local read_font_file = fonts.definers.read + +--- spec -> size -> id -> tmfdata +local patch_defined_font = function (specification, size, id) + local tfmdata = read_font_file(specification, size, id) + if type(tfmdata) == "table" and tfmdata.shared then + --- We need to test for the ^^e2^^80^^9cshared^^e2^^80^^9d field here + --- or else the fontspec capheight callback will + --- operate on tfm fonts. + call_callback("luaotfload.patch_font", tfmdata) + end + return tfmdata +end + +caches.compilemethod = "both" + +reset_callback("define_font") + + +local font_definer = config.luaotfload.definer + +if font_definer == "generic" then + add_to_callback("define_font", + fonts.definers.read, + "luaotfload.define_font", + 1) +elseif font_definer == "patch" then + add_to_callback("define_font", + patch_defined_font, + "luaotfload.define_font", + 1) +end + +loadmodule"features.lua" --- contains what was ^^e2^^80^^9cfont-ltx^^e2^^80^^9d and ^^e2^^80^^9cfont-otc^^e2^^80^^9d +loadmodule"auxiliary.lua" --- additionaly high-level functionality (new) + +-- vim:tw=71:sw=4:ts=4:expandtab + -- -- End of File `luaotfload.lua'. |