Debian Codegraph @

texmf-dist/tex/luatex/luaotfload/fontloader-fonts-def.lua

raw
1 if not modules then modules = { } end modules ['luatex-fonts-def'] = {
2 version = 1.001,
3 comment = "companion to luatex-*.tex",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7 }
8
9 if context then
10 os.exit()
11 end
12
13 local fonts = fonts
14
15 -- A bit of tuning for definitions.
16
17 fonts.constructors.namemode = "specification" -- somehow latex needs this (changed name!) => will change into an overload
18
19 -- tricky: we sort of bypass the parser and directly feed all into
20 -- the sub parser
21
22 function fonts.definers.getspecification(str)
23 return "", str, "", ":", str
24 end
25
26 -- the generic name parser (different from context!)
27
28 local list = { } -- we could pass Carg but let's keep the old one
29
30 local function issome () list.lookup = 'name' end -- xetex mode prefers name (not in context!)
31 local function isfile () list.lookup = 'file' end
32 local function isname () list.lookup = 'name' end
33 local function thename(s) list.name = s end
34 local function issub (v) list.sub = v end
35 local function iscrap (s) list.crap = string.lower(s) end
36 local function iskey (k,v) list[k] = v end
37 local function istrue (s) list[s] = true end
38 local function isfalse(s) list[s] = false end
39
40 local P, S, R, C, Cs = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cs
41
42 local spaces = P(" ")^0
43 local namespec = Cs((P("{")/"") * (1-S("}"))^0 * (P("}")/"") + (1-S("/:("))^0)
44 local crapspec = spaces * P("/") * (((1-P(":"))^0)/iscrap) * spaces
45 local filename_1 = P("file:")/isfile * (namespec/thename)
46 local filename_2 = P("[") * P(true)/isfile * (((1-P("]"))^0)/thename) * P("]")
47 local fontname_1 = P("name:")/isname * (namespec/thename)
48 local fontname_2 = P(true)/issome * (namespec/thename)
49 local sometext = R("az","AZ","09")^1
50 local somekey = R("az","AZ","09")^1
51 local somevalue = (P("{")/"")*(1-P("}"))^0*(P("}")/"") + (1-S(";"))^1
52 local truevalue = P("+") * spaces * (sometext/istrue)
53 local falsevalue = P("-") * spaces * (sometext/isfalse)
54 local keyvalue = (C(somekey) * spaces * P("=") * spaces * C(somevalue))/iskey
55 local somevalue = sometext/istrue
56 local subvalue = P("(") * (C(P(1-S("()"))^1)/issub) * P(")") -- for Kim
57 local option = spaces * (keyvalue + falsevalue + truevalue + somevalue) * spaces
58 local options = P(":") * spaces * (P(";")^0 * option)^0
59
60 local pattern = (filename_1 + filename_2 + fontname_1 + fontname_2)
61 * subvalue^0 * crapspec^0 * options^0
62
63 function fonts.definers.analyze(str,size)
64 local specification = fonts.definers.makespecification(str,nil,nil,nil,":",nil,size)
65 list = { }
66 lpeg.match(pattern,str)
67 list.crap = nil
68 if list.name then
69 specification.name = list.name
70 list.name = nil
71 end
72 if list.lookup then
73 specification.lookup = list.lookup
74 list.lookup = nil
75 end
76 if list.sub then
77 specification.sub = list.sub
78 list.sub = nil
79 end
80 specification.features.normal = fonts.handlers.otf.features.normalize(list)
81 list = nil
82 return specification
83 end
84
85 function fonts.definers.applypostprocessors(tfmdata)
86 local postprocessors = tfmdata.postprocessors
87 if postprocessors then
88 for i=1,#postprocessors do
89 local extrahash = postprocessors[i](tfmdata) -- after scaling etc
90 if type(extrahash) == "string" and extrahash ~= "" then
91 -- e.g. a reencoding needs this
92 extrahash = string.gsub(lower(extrahash),"[^a-z]","-")
93 tfmdata.properties.fullname = format("%s-%s",tfmdata.properties.fullname,extrahash)
94 end
95 end
96 end
97 return tfmdata
98 end