summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/fontspec/fontspec.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-05-28 15:52:45 +0000
committerKarl Berry <karl@freefriends.org>2010-05-28 15:52:45 +0000
commit2da77d0cc0ada0dede0a76ef2823d3ad34db2fa7 (patch)
tree9a93a2bddbc18388c99cdab50c88e17ae82048de /Master/texmf-dist/tex/latex/fontspec/fontspec.lua
parent881ee118259a2f9961f7cef4e1b26bcf65488346 (diff)
fontspec beta 1 (27may10)
git-svn-id: svn://tug.org/texlive/trunk@18558 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/fontspec/fontspec.lua')
-rw-r--r--Master/texmf-dist/tex/latex/fontspec/fontspec.lua207
1 files changed, 207 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/fontspec/fontspec.lua b/Master/texmf-dist/tex/latex/fontspec/fontspec.lua
new file mode 100644
index 00000000000..05e28c2124a
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/fontspec/fontspec.lua
@@ -0,0 +1,207 @@
+--
+-- This is file `fontspec.lua',
+-- generated with the docstrip utility.
+--
+-- The original source files were:
+--
+-- fontspec.dtx (with options: `lua')
+--
+-- _________________________________________
+-- The fontspec package for XeLaTeX/LuaLaTeX
+-- (C) 2004--2010 Will Robertson and Khaled Hosny
+--
+-- License information appended.
+--
+--
+fontspec = { }
+
+fontspec.module = {
+ name = "fontspec",
+ version = 2.0,
+ date = "2009/12/04",
+ description = "Advanced font selection for LuaLaTeX.",
+ author = "Khaled Hosny",
+ copyright = "Khaled Hosny",
+ license = "LPPL"
+}
+
+luatexbase.provides_module(fontspec.module)
+
+
+utf = unicode.utf8
+
+function fontspec.log (...) luatexbase.module_log (fontspec.module.name, string.format(...)) end
+function fontspec.warning(...) luatexbase.module_warning(fontspec.module.name, string.format(...)) end
+function fontspec.error (...) luatexbase.module_error (fontspec.module.name, string.format(...)) end
+
+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.ids[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.ids[id].fullname)
+ return true
+ 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.ids[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.ids[id].fullname)
+ return true
+ 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("^[+-]", ""))
+ if id and id > 0 then
+ local otfdata = fonts.ids[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.ids[id].fullname)
+ return true
+ end
+ end
+ end
+ end
+ end
+end
+
+
+local function font_id(str)
+ local id
+ if tex.luatexversion >= 47 then
+ id = font.id(str)
+ else
+ id = token.create(str)[2]
+ end
+ return id
+end
+
+
+local function tempswatrue() fontspec.sprint([[\@tempswatrue]]) end
+local function tempswafalse() fontspec.sprint([[\@tempswafalse]]) end
+
+function fontspec.check_ot_script(fnt, script)
+ if check_script(font_id(fnt), script) then
+ tempswatrue()
+ else
+ tempswafalse()
+ end
+end
+
+function fontspec.check_ot_lang(fnt, lang, script)
+ if check_language(font_id(fnt), lang, script) then
+ tempswatrue()
+ else
+ tempswafalse()
+ end
+end
+
+function fontspec.check_ot_feat(fnt, feat, lang, script)
+ for _, f in ipairs { "+trep", "+tlig", "+anum" } do
+ if feat == f then
+ tempswatrue()
+ return
+ end
+ end
+ if check_feature(font_id(fnt), feat, lang, script) then
+ tempswatrue()
+ else
+ tempswafalse()
+ end
+end
+
+
+function fontspec.get_dimen(fontdimen, csname)
+ local id, h, em, pt
+ if csname == "font" then
+ id = font.current()
+ else
+ id = font_id(csname)
+ end
+ if fontdimen == 8 then
+ h = fonts.ids[id].shared.otfdata.pfminfo.os2_capheight
+ elseif fontdimen == 5 then
+ h = fonts.ids[id].shared.otfdata.pfminfo.os2_xheight
+ end
+ em = fonts.ids[id].shared.otfdata.metadata.units_per_em
+ pt = fonts.ids[id].size / 65536
+ tex.sprint(string.format("%spt", (h/em)*pt))
+end
+
+function fontspec.charglyph(char, csname)
+ local id, c
+ if char then
+ if utf.len(char) > 1 then
+ c = utf.byte(utf.char(char:gsub('"', '0x')))
+ else
+ c = utf.byte(char)
+ end
+
+ if csname then
+ id = font_id(csname)
+ else
+ id = font.current()
+ end
+
+ if font.fonts[id]["characters"][c] then
+ return font.fonts[id]["characters"][c].index
+ else
+ return 0
+ end
+ else
+ return 0
+ end
+end
+
+--
+-- Copyright 2004--2010 Will Robertson <wspr81@gmail.com>
+-- Copyright 2009--2010 Khaled Hosny <khaledhosny@eglug.org>
+--
+-- Distributable under the LaTeX Project Public License,
+-- version 1.3c or higher (your choice). The latest version of
+-- this license is at: http://www.latex-project.org/lppl.txt
+--
+-- This work is "author-maintained" by Will Robertson.
+--
+-- This work consists of this file fontspec.dtx
+-- and the derived files fontspec.sty,
+-- fontspec.lua,
+-- fontspec.cfg,
+-- fontspec.ins,
+-- fontspec-example.ltx,
+-- and fontspec.pdf.
+--
+--
+-- End of file `fontspec.lua'.