From d5dc9e49d4676082f90ee3e0d3170657f72a5b5f Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 17 May 2013 22:26:32 +0000 Subject: fontspec (17may13) git-svn-id: svn://tug.org/texlive/trunk@30529 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/fontspec/fontspec.lua | 192 ++++++++++++++-------- 1 file changed, 122 insertions(+), 70 deletions(-) (limited to 'Master/texmf-dist/tex/latex/fontspec/fontspec.lua') diff --git a/Master/texmf-dist/tex/latex/fontspec/fontspec.lua b/Master/texmf-dist/tex/latex/fontspec/fontspec.lua index cb6a24926e5..9bbb1c78260 100644 --- a/Master/texmf-dist/tex/latex/fontspec/fontspec.lua +++ b/Master/texmf-dist/tex/latex/fontspec/fontspec.lua @@ -15,14 +15,15 @@ -- -fontspec = { } +fontspec = fontspec or {} +local fontspec = fontspec fontspec.module = { name = "fontspec", - version = 2.0, - date = "2009/12/04", + version = 2.4, + date = "2013/05/12", description = "Advanced font selection for LuaLaTeX.", - author = "Khaled Hosny", - copyright = "Khaled Hosny", + author = "Khaled Hosny, Philipp Gesang", + copyright = "Khaled Hosny, Philipp Gesang", license = "LPPL" } @@ -32,58 +33,76 @@ fontspec.log = log fontspec.warning = warn fontspec.error = err -function fontspec.sprint (...) tex.sprint(luatexbase.catcodetables['latex-package'], ...) end -local function check_script(id, script) - local s = string.lower(script) - if id and id > 0 then - local otfdata = fonts.identifiers[id].shared.otfdata - if otfdata then - local features = otfdata.luatex.features - for i,_ in pairs(features) do - for j,_ in pairs(features[i]) do - if features[i][j][s] then - fontspec.log("script '%s' exists in font '%s'", - script, fonts.identifiers[id].fullname) - return true +function fontspec.sprint (...) + tex.sprint(luatexbase.catcodetables['latex-package'], ...) +end +local luaotfload_aux +if luaotfload and luaotfload.aux and luaotfload.aux.slot_of_name then + luaotfload_aux = true +else + luaotfload_aux = false +end + +local check_script, check_language, check_feature, ids + +if luaotfload_aux then + check_script = luaotfload.aux.provides_script + check_language = luaotfload.aux.provides_language + check_feature = luaotfload.aux.provides_feature +else + ids = fonts.identifiers or fonts.ids or fonts.hashes.identifiers -- first two are for backward compatibility + function check_script(id, script) + local s = string.lower(script) + if id and id > 0 then + local otfdata = ids[id].shared.rawdata + if otfdata then + local features = otfdata.resources.features + for i,_ in pairs(features) do + for j,_ in pairs(features[i]) do + if features[i][j][s] then + fontspec.log("script '%s' exists in font '%s'", + script, ids[id].fullname) + return true + end end end end end end -end -local function check_language(id, language, script) - local s = string.lower(script) - local l = string.lower(language) - if id and id > 0 then - local otfdata = fonts.identifiers[id].shared.otfdata - if otfdata then - local features = otfdata.luatex.features - for i,_ in pairs(features) do - for j,_ in pairs(features[i]) do - if features[i][j][s] and features[i][j][s][l] then - fontspec.log("language '%s' for script '%s' exists in font '%s'", - language, script, fonts.identifiers[id].fullname) - return true + function check_language(id, script, language) + local s = string.lower(script) + local l = string.lower(language) + if id and id > 0 then + local otfdata = ids[id].shared.rawdata + if otfdata then + local features = otfdata.resources.features + for i,_ in pairs(features) do + for j,_ in pairs(features[i]) do + if features[i][j][s] and features[i][j][s][l] then + fontspec.log("language '%s' for script '%s' exists in font '%s'", + language, script, ids[id].fullname) + return true + end end end end end end -end -local function check_feature(id, feature, language, script) - local s = string.lower(script) - local l = string.lower(language) - local f = string.lower(feature:gsub("^[+-]", ""):gsub("=.*$", "")) - if id and id > 0 then - local otfdata = fonts.identifiers[id].shared.otfdata - if otfdata then - local features = otfdata.luatex.features - for i,_ in pairs(features) do - if features[i][f] and features[i][f][s] then - if features[i][f][s][l] == true then - fontspec.log("feature '%s' for language '%s' and script '%s' exists in font '%s'", - feature, language, script, fonts.identifiers[id].fullname) - return true + function check_feature(id, script, language, feature) + local s = string.lower(script) + local l = string.lower(language) + local f = string.lower(feature:gsub("^[+-]", ""):gsub("=.*$", "")) + if id and id > 0 then + local otfdata = ids[id].shared.rawdata + if otfdata then + local features = otfdata.resources.features + for i,_ in pairs(features) do + if features[i][f] and features[i][f][s] then + if features[i][f][s][l] == true then + fontspec.log("feature '%s' for language '%s' and script '%s' exists in font '%s'", + feature, language, script, ids[id].fullname) + return true + end end end end @@ -100,7 +119,7 @@ function fontspec.check_ot_script(fnt, script) end end function fontspec.check_ot_lang(fnt, lang, script) - if check_language(font.id(fnt), lang, script) then + if check_language(font.id(fnt), script, lang) then tempswatrue() else tempswafalse() @@ -113,44 +132,77 @@ function fontspec.check_ot_feat(fnt, feat, lang, script) return end end - if check_feature(font.id(fnt), feat, lang, script) then + if check_feature(font.id(fnt), script, lang, feat) then tempswatrue() else tempswafalse() end end -function fontspec.mathfontdimen(fnt, str) - local mathdimens = fonts.identifiers[font.id(fnt)].MathConstants - if mathdimens then - local m = mathdimens[str] - if m then - fontspec.sprint(mathdimens[str]) - fontspec.sprint("sp") +local get_math_dimension +if luaotfload_aux then + get_math_dimension = luaotfload.aux.get_math_dimension +else + get_math_dimension = function(fnt, str) + local mathdimens = ids[font.id(fnt)].MathConstants + if mathdimens then + return mathdimens[str] else - fontspec.sprint("0pt") + return nil end + end +end +function fontspec.mathfontdimen(fnt, str) + local mathdimens = get_math_dimension(fnt, str) + if mathdimens then + fontspec.sprint(mathdimens) + fontspec.sprint("sp") else fontspec.sprint("0pt") end end -local function set_capheight(fontdata) - local capheight - local units = fontdata.units - local size = fontdata.size - local otfdata = fontdata.shared.otfdata +if not luaotfload_aux then + local function set_capheight(fontdata) + local capheight + local shared = fontdata.shared + if shared then + local metadata + local units_per_em + local os2_capheight + local size = fontdata.size or fontdata.parameters.size - if otfdata.pfminfo.os2_capheight > 0 then - capheight = otfdata.pfminfo.os2_capheight / units * size - else - if fontdata.characters[string.byte("X")] then - capheight = fontdata.characters[string.byte("X")].height + if shared.rawdata then --- new otfl + metadata = shared.rawdata.metadata + units_per_em = shared.rawdata.metadata.units_per_em + os2_capheight = metadata.pfminfo.os2_capheight + else --- legacy + metadata = shared.otfdata.metadata + units_per_em = fontdata.units_per_em or fontdata.units + or fontdata.parameters.units + os2_capheight = shared.otfdata.pfminfo.os2_capheight + end + + if os2_capheight > 0 then + capheight = os2_capheight / units_per_em * size + else + local X8 = string.byte"X" + if fontdata.characters[X8] then + capheight = fontdata.characters[X8].height + else + capheight = metadata.ascent / units_per_em * size + end + end else - capheight = otfdata.metadata.ascent / units * size + local X8 = string.byte"X" + if fontdata.characters[X8] then + capheight = fontdata.characters[X8].height + end + end + if capheight then + fontdata.parameters[8] = capheight end end - fontdata.parameters[8] = capheight + luatexbase.add_to_callback("luaotfload.patch_font", set_capheight, "fontspec.set_capheight") end -luatexbase.add_to_callback("luaotfload.patch_font", set_capheight, "fontspec.set_capheight") -- -- Copyright 2004--2013 Will Robertson -- Copyright 2009--2013 Khaled Hosny -- cgit v1.2.3