diff options
author | Hans Hagen <pragma@wxs.nl> | 2019-02-22 20:29:46 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2019-02-22 20:29:46 +0100 |
commit | 7b271baae19db1528fbe6621bdf50af89a5a336b (patch) | |
tree | 4fc24a8f2be20aa90e90f6e1bcb62d69f4946235 /tex/context/base/mkiv/font-prv.lua | |
parent | 67b9965fe473d18f13ed4c40f1e4e008eb870322 (diff) | |
download | context-7b271baae19db1528fbe6621bdf50af89a5a336b.tar.gz |
2019-02-22 19:43:00
Diffstat (limited to 'tex/context/base/mkiv/font-prv.lua')
-rw-r--r-- | tex/context/base/mkiv/font-prv.lua | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/font-prv.lua b/tex/context/base/mkiv/font-prv.lua new file mode 100644 index 000000000..20c06d2e5 --- /dev/null +++ b/tex/context/base/mkiv/font-prv.lua @@ -0,0 +1,78 @@ +if not modules then modules = { } end modules ['font-prv'] = { + version = 1.001, + comment = "companion to font-ini.mkiv and hand-ini.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local type = type +local formatters = string.formatters + +local fonts = fonts +local helpers = fonts.helpers +local fontdata = fonts.hashes.identifiers + +local setmetatableindex = table.setmetatableindex + +local currentprivate = fonts.privateoffsets.textextrabase +local maximumprivate = currentprivate + 0xFFF + +local extraprivates = { } +helpers.extraprivates = extraprivates + +function fonts.helpers.addextraprivate(name,f) + extraprivates[#extraprivates+1] = { name, f } +end + +-- if we run out of space we can think of another range but by sharing we can +-- use these privates for mechanisms like alignments-on-character and such + +local sharedprivates = setmetatableindex(function(t,k) + local v = currentprivate + if currentprivate < maximumprivate then + currentprivate = currentprivate + 1 + else + -- reuse last slot, todo: warning + end + t[k] = v + return v +end) + +function helpers.addprivate(tfmdata,name,characterdata) + local properties = tfmdata.properties + local characters = tfmdata.characters + local privates = properties.privates + if not privates then + privates = { } + properties.privates = privates + end + if not name then + name = formatters["anonymous_private_0x%05X"](currentprivate) + end + local usedprivate = sharedprivates[name] + privates[name] = usedprivate + characters[usedprivate] = characterdata + return usedprivate +end + +function helpers.getprivates(tfmdata) + if type(tfmdata) == "number" then + tfmdata = fontdata[tfmdata] + end + local properties = tfmdata.properties + return properties and properties.privates +end + +function helpers.hasprivate(tfmdata,name) + if type(tfmdata) == "number" then + tfmdata = fontdata[tfmdata] + end + local properties = tfmdata.properties + local privates = properties and properties.privates + return privates and privates[name] or false +end + +function helpers.privateslot(name) + return rawget(sharedprivates,name) +end |