summaryrefslogtreecommitdiff
path: root/tex/context/base/font-vf.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/font-vf.lua')
-rw-r--r--tex/context/base/font-vf.lua154
1 files changed, 84 insertions, 70 deletions
diff --git a/tex/context/base/font-vf.lua b/tex/context/base/font-vf.lua
index 4f99c47b9..d803636a2 100644
--- a/tex/context/base/font-vf.lua
+++ b/tex/context/base/font-vf.lua
@@ -13,28 +13,35 @@ changes. This will change.</p>
-- define.methods elsewhere !
-fonts = fonts or { }
-fonts.vf = fonts.vf or { }
+local next = next
+local fastcopy = table.fastcopy
-local vf = fonts.vf
-local tfm = fonts.tfm
+local fonts = fonts
+local vf = fonts.vf
+local tfm = fonts.tfm
-fonts.define = fonts.define or { }
-fonts.define.methods = fonts.define.methods or { }
+fonts.define = fonts.define or { }
+local define = fonts.define
+define.methods = define.methods or { }
vf.combinations = vf.combinations or { }
vf.aux = vf.aux or { }
vf.aux.combine = vf.aux.combine or { }
+local combine = vf.aux.combine
-function fonts.define.methods.install(tag, rules)
+function define.methods.install(tag, rules)
vf.combinations[tag] = rules
- fonts.define.methods[tag] = function(specification)
+ define.methods[tag] = function(specification)
return vf.combine(specification,tag)
end
end
-function vf.aux.combine.assign(g, name, from, to, start, force)
- local f, id = vf.aux.combine.load(g,name)
+local function combine_load(g,name)
+ return tfm.read_and_define(name or g.specification.name,g.specification.size)
+end
+
+local function combine_assign(g, name, from, to, start, force)
+ local f, id = combine_load(g,name)
if f and id then
-- optimize for whole range, then just g = f
if not from then from, to = 0, 0xFF00 end
@@ -46,35 +53,31 @@ function vf.aux.combine.assign(g, name, from, to, start, force)
g.fonts[hn] = { id = id } -- no need to be sparse
for i=from,to do
if fc[i] and (force or not gc[i]) then
- gc[i] = table.fastcopy(fc[i]) -- can be optimized
+ gc[i] = fastcopy(fc[i]) -- can be optimized
gc[i].commands = { { 'slot', hn, start } }
gd[i] = fd[i]
end
start = start + 1
end
if not g.parameters and #g.fonts > 0 then -- share this code !
- g.parameters = table.fastcopy(f.parameters)
- g.italicangle = f.italicangle
- g.ascender = f.ascender
- g.descender = f.descender
- g.factor = f.factor -- brrr
+ g.parameters = fastcopy(f.parameters)
+ g.italicangle = f.italicangle
+ g.ascender = f.ascender
+ g.descender = f.descender
+ g.factor = f.factor -- brrr
end
end
end
-function vf.aux.combine.process(g,list)
+local function combine_process(g,list)
if list then
for _,v in next, list do
- (vf.aux.combine.commands[v[1]] or nop)(g,v)
+ (combine.commands[v[1]] or nop)(g,v)
end
end
end
-function vf.aux.combine.load(g,name)
- return tfm.read_and_define(name or g.specification.name,g.specification.size)
-end
-
-function vf.aux.combine.names(g,name,force)
+local function combine_names(g,name,force)
local f, id = tfm.read_and_define(name,g.specification.size)
if f and id then
local fc, gc = f.characters, g.characters
@@ -83,62 +86,73 @@ function vf.aux.combine.names(g,name,force)
local hn = #g.fonts
for k, v in next, fc do
if force or not gc[k] then
- gc[k] = table.fastcopy(v)
+ gc[k] = fastcopy(v)
gc[k].commands = { { 'slot', hn, k } }
gd[i] = fd[i]
end
end
if not g.parameters and #g.fonts > 0 then -- share this code !
- g.parameters = table.fastcopy(f.parameters)
- g.italicangle = f.italicangle
- g.ascender = f.ascender
- g.descender = f.descender
- g.factor = f.factor -- brrr
+ g.parameters = fastcopy(f.parameters)
+ g.italicangle = f.italicangle
+ g.ascender = f.ascender
+ g.descender = f.descender
+ g.factor = f.factor -- brrr
end
end
end
-vf.aux.combine.commands = {
- ["initialize"] = function(g,v) vf.aux.combine.assign (g,g.name) end,
- ["include-method"] = function(g,v) vf.aux.combine.process (g,vf.combinations[v[2]]) end, -- name
- ["copy-parameters"] = function(g,v) vf.aux.combine.parameters(g,v[2]) end, -- name
- ["copy-range"] = function(g,v) vf.aux.combine.assign (g,v[2],v[3],v[4],v[5],true) end, -- name, from-start, from-end, to-start
- ["copy-char"] = function(g,v) vf.aux.combine.assign (g,v[2],v[3],v[3],v[4],true) end, -- name, from, to
- ["fallback-range"] = function(g,v) vf.aux.combine.assign (g,v[2],v[3],v[4],v[5],false) end, -- name, from-start, from-end, to-start
- ["fallback-char"] = function(g,v) vf.aux.combine.assign (g,v[2],v[3],v[3],v[4],false) end, -- name, from, to
- ["copy_names"] = function(g,v) vf.aux.combine.names (g,v[2],true) end,
- ["fallback_names"] = function(g,v) vf.aux.combine.names (g,v[2],false) end,
-}
-
-function vf.combine(specification,tag)
- local g = {
- name = specification.name,
- -- type = 'virtual',
- virtualized = true,
- fonts = { },
- characters = { },
- descriptions = { },
- specification = table.fastcopy(specification)
- }
- vf.aux.combine.process(g,vf.combinations[tag])
- return g
-end
-
-vf.aux.combine.commands["feature"] = function(g,v)
+local combine_feature = function(g,v)
local key, value = v[2], v[3]
if key then
if value == nil then
value = true
end
- if g.specification and g.specification.features.normal then
- g.specification.features.normal[key] = value -- otf?
+ local specification = g.specification
+ if specification then
+ local normalfeatures = specification.features.normal
+ if normalfeatures then
+ normalfeatures[key] = value -- otf?
+ end
end
end
end
+--~ combine.load = combine_load
+--~ combine.assign = combine_assign
+--~ combine.process = combine_process
+--~ combine.names = combine_names
+--~ combine.feature = combine_feature
+
+combine.commands = {
+ ["initialize"] = function(g,v) combine_assign (g,g.name) end,
+ ["include-method"] = function(g,v) combine_process (g,vf.combinations[v[2]]) end, -- name
+ -- ["copy-parameters"] = function(g,v) combine_parameters(g,v[2]) end, -- name
+ ["copy-range"] = function(g,v) combine_assign (g,v[2],v[3],v[4],v[5],true) end, -- name, from-start, from-end, to-start
+ ["copy-char"] = function(g,v) combine_assign (g,v[2],v[3],v[3],v[4],true) end, -- name, from, to
+ ["fallback-range"] = function(g,v) combine_assign (g,v[2],v[3],v[4],v[5],false) end, -- name, from-start, from-end, to-start
+ ["fallback-char"] = function(g,v) combine_assign (g,v[2],v[3],v[3],v[4],false) end, -- name, from, to
+ ["copy-names"] = function(g,v) combine_names (g,v[2],true) end,
+ ["fallback_names"] = function(g,v) combine_names (g,v[2],false) end,
+ ["feature"] = combine_feature,
+}
+
+function vf.combine(specification,tag)
+ local g = {
+ name = specification.name,
+ -- type = 'virtual',
+ virtualized = true,
+ fonts = { },
+ characters = { },
+ descriptions = { },
+ specification = fastcopy(specification),
+ }
+ combine_process(g,vf.combinations[tag])
+ return g
+end
+
-- simple example with features
-fonts.define.methods.install(
+define.methods.install(
"ligatures", {
{ "feature", "liga" } ,
{ "feature", "dlig" } ,
@@ -146,7 +160,7 @@ fonts.define.methods.install(
}
)
---~ fonts.define.methods.install (
+--~ define.methods.install (
--~ "ligatures-x", {
--~ { "feature", "liga" } ,
--~ { "feature", "dlig" } ,
@@ -155,7 +169,7 @@ fonts.define.methods.install(
--~ }
--~ )
---~ fonts.define.methods.install(
+--~ define.methods.install(
--~ "lmsymbol10", {
--~ { "fallback_names", "lmsy10.afm" } ,
--~ { "fallback_names", "msam10.afm" } ,
@@ -166,7 +180,7 @@ fonts.define.methods.install(
-- docu case
---~ fonts.define.methods.install(
+--~ define.methods.install(
--~ "weird", {
--~ { "copy-range", "lmroman10-regular" } ,
--~ { "copy-char", "lmroman10-regular", 65, 66 } ,
@@ -178,7 +192,9 @@ fonts.define.methods.install(
-- demo case -> move to module
-fonts.define.methods["demo-1"] = function(specification)
+-- todo: interface tables in back-ini
+
+define.methods["demo-1"] = function(specification)
local name = specification.name -- symbolic name
local size = specification.size -- given size
local f, id = tfm.read_and_define('lmroman10-regular',size)
@@ -193,19 +209,17 @@ fonts.define.methods["demo-1"] = function(specification)
}
local i_is_of_category = characters.i_is_of_category
local characters, descriptions = f.characters, f.descriptions
- local red = {'special','pdf: 1 0 0 rg'}
- local green = {'special','pdf: 0 1 0 rg'}
- local blue = {'special','pdf: 0 0 1 rg'}
- local black = {'special','pdf: 0 g'}
+ local vfspecials = backends.tables.vfspecials
+ local red, green, blue, black = vfspecials.red, vfspecials.green, vfspecials.blue, vfspecials.black
for u,v in next, characters do
if u and i_is_of_category(u,'lu') then
v.width = capscale*v.width
- v.commands = { red, {'slot',2,u}, black }
+ v.commands = { red, { 'slot', 2, u }, black }
elseif u and i_is_of_category(u,'nd') then
v.width = digscale*v.width
- v.commands = { blue, {'slot',3,u}, black }
+ v.commands = { blue, { 'slot', 3, u }, black }
else
- v.commands = { green, {'slot',1,u}, black }
+ v.commands = { green, { 'slot', 1, u }, black }
end
end
end