summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/font-ext.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-08-21 18:56:35 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-08-21 18:56:35 +0200
commit1f5a6c986423b9116645f85c88ec7d4acd18c3f5 (patch)
tree3de05684301a0e7b34afc8b482ef673b902cc52c /tex/context/base/mkiv/font-ext.lua
parent65ed578259121f17a365b97956d19d67e0be8f60 (diff)
downloadcontext-1f5a6c986423b9116645f85c88ec7d4acd18c3f5.tar.gz
2016-08-21 16:33:00
Diffstat (limited to 'tex/context/base/mkiv/font-ext.lua')
-rw-r--r--tex/context/base/mkiv/font-ext.lua185
1 files changed, 112 insertions, 73 deletions
diff --git a/tex/context/base/mkiv/font-ext.lua b/tex/context/base/mkiv/font-ext.lua
index 2fc85c266..16e201bd3 100644
--- a/tex/context/base/mkiv/font-ext.lua
+++ b/tex/context/base/mkiv/font-ext.lua
@@ -6,7 +6,9 @@ if not modules then modules = { } end modules ['font-ext'] = {
license = "see context related readme files"
}
-local next, type, byte = next, type, string.byte
+local next, type, tonumber = next, type, tonumber
+local formatters = string.formatters
+local byte = string.byte
local utfchar = utf.char
local context = context
@@ -79,6 +81,8 @@ expansions.classes = classes
expansions.vectors = vectors
-- beware, pdftex itself uses percentages * 10
+--
+-- todo: get rid of byte() here
classes.preset = { stretch = 2, shrink = 2, step = .5, factor = 1 }
@@ -978,37 +982,44 @@ registerafmfeature(dimensions_specification)
-- a handy helper (might change or be moved to another namespace)
-local nodepool = nodes.pool
+local nodepool = nodes.pool
+local new_glyph = nodepool.glyph
------ new_special = nodepool.special
------ hpack_node = node.hpack
-local new_glyph = nodepool.glyph
+local helpers = fonts.helpers
+local currentfont = font.current
-local helpers = fonts.helpers
-local currentfont = font.current
+local currentprivate = 0xE000
+local maximumprivate = 0xEFFF
-function helpers.addprivate(tfmdata,name,characterdata)
- local properties = tfmdata.properties
- local privates = properties.privates
- local lastprivate = properties.lastprivate
- if lastprivate then
- lastprivate = lastprivate + 1
+-- 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)
+ v = currentprivate
+ if currentprivate < maximumprivate then
+ currentprivate = currentprivate + 1
else
- lastprivate = 0xE000
+ -- 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 name then
- privates[name] = lastprivate
- end
- properties.lastprivate = lastprivate
- tfmdata.characters[lastprivate] = characterdata
- if properties.finalized then
- properties.lateprivates = true
+ if not name then
+ name = formatters["anonymous_private_0x%05X"](currentprivate)
end
- return lastprivate
+ local usedprivate = sharedprivates[name]
+ privates[name] = usedprivate
+ characters[usedprivate] = characterdata
+ return usedprivate
end
local function getprivateslot(id,name)
@@ -1021,69 +1032,64 @@ local function getprivateslot(id,name)
return privates and privates[name]
end
-helpers.getprivateslot = getprivateslot
-
--- was originally meant for missing chars:
---
--- local char = tfmdata.characters[p]
--- local commands = char.commands
--- if commands then
--- local fake = hpack_node(new_special(commands[1][2]))
--- fake.width = char.width
--- fake.height = char.height
--- fake.depth = char.depth
--- return fake
--- else
-
local function getprivatenode(tfmdata,name)
- local id = tfmdata.properties.id
- local p = getprivateslot(id,name)
- if p then
+ if type(tfmdata) == "number" then
+ tfmdata = fontdata[tfmdata]
+ end
+ local properties = tfmdata.properties
+ local font = properties.id
+ local slot = getprivateslot(font,name)
+ if slot then
-- todo: set current attribibutes
- return new_glyph(id,p)
+ local char = tfmdata.characters[slot]
+ local tonode = char.tonode
+ if tonode then
+ return tonode(font,char)
+ else
+ return new_glyph(font,slot)
+ end
end
end
-helpers.getprivatenode = getprivatenode
-
-function helpers.hasprivate(tfmdata,name)
+local function getprivatecharornode(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
-
-implement {
- name = "getprivatechar",
- arguments = "string",
- actions = function(name)
- local p = getprivateslot(name)
- if p then
- context(utfchar(p))
+ local font = properties.id
+ local slot = getprivateslot(font,name)
+ if slot then
+ -- todo: set current attribibutes
+ local char = tfmdata.characters[slot]
+ local tonode = char.tonode
+ if tonode then
+ return "node", tonode(tfmdata,char)
+ else
+ return "char", slot
end
end
-}
+end
-implement {
- name = "getprivatemathchar",
- arguments = "string",
- actions = function(name)
- local p = getprivateslot(family_font(0),name)
- if p then
- context(utfchar(p))
- end
+helpers.getprivateslot = getprivateslot
+helpers.getprivatenode = getprivatenode
+helpers.getprivatecharornode = getprivatecharornode
+
+function helpers.getprivates(tfmdata)
+ if type(tfmdata) == "number" then
+ tfmdata = fontdata[tfmdata]
end
-}
+ local properties = tfmdata.properties
+ return properties and properties.privates
+end
-implement {
- name = "getprivateslot",
- arguments = "string",
- actions = function(name)
- local p = getprivateslot(name)
- if p then
- context(p)
- 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
-- relatively new:
@@ -1116,3 +1122,36 @@ do
}
end
+
+implement {
+ name = "getprivatechar",
+ arguments = "string",
+ actions = function(name)
+ local p = getprivateslot(name)
+ if p then
+ context(utfchar(p))
+ end
+ end
+}
+
+implement {
+ name = "getprivatemathchar",
+ arguments = "string",
+ actions = function(name)
+ local p = getprivateslot(family_font(0),name)
+ if p then
+ context(utfchar(p))
+ end
+ end
+}
+
+implement {
+ name = "getprivateslot",
+ arguments = "string",
+ actions = function(name)
+ local p = getprivateslot(name)
+ if p then
+ context(p)
+ end
+ end
+}