summaryrefslogtreecommitdiff
path: root/tex/context/base/s-fonts-features.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2013-05-18 00:46:00 +0200
committerHans Hagen <pragma@wxs.nl>2013-05-18 00:46:00 +0200
commitee89a80d8d8082d1e73db02183c539a385884f6f (patch)
tree35ed0af659c2ccdff31f40b30b5f0b6bda641b7b /tex/context/base/s-fonts-features.lua
parentfdf6650bc19c97b288d2a85e3419064608544594 (diff)
downloadcontext-ee89a80d8d8082d1e73db02183c539a385884f6f.tar.gz
beta 2013.05.18 00:46
Diffstat (limited to 'tex/context/base/s-fonts-features.lua')
-rw-r--r--tex/context/base/s-fonts-features.lua89
1 files changed, 87 insertions, 2 deletions
diff --git a/tex/context/base/s-fonts-features.lua b/tex/context/base/s-fonts-features.lua
index 4ee143204..3f4d95096 100644
--- a/tex/context/base/s-fonts-features.lua
+++ b/tex/context/base/s-fonts-features.lua
@@ -11,6 +11,8 @@ moduledata.fonts.features = moduledata.fonts.features or { }
-- for the moment only otf
+local sortedhash = table.sortedhash
+
local NC, NR, bold = context.NC, context.NR, context.bold
function moduledata.fonts.features.showused(specification)
@@ -36,10 +38,10 @@ function moduledata.fonts.features.showused(specification)
local features = fonts.handlers.otf.tables.features
local descriptions = fonts.handlers.otf.features.descriptions
- for feature, keys in table.sortedhash(usedfeatures) do
+ for feature, keys in sortedhash(usedfeatures) do
-- if list.all or (list.otf and rawget(features,feature)) or (list.extra and rawget(descriptions,feature)) then
local done = false
- for k, v in table.sortedhash(keys) do
+ for k, v in sortedhash(keys) do
if done then
NC()
NC()
@@ -72,3 +74,86 @@ function moduledata.fonts.features.showused(specification)
context.stoptabulate()
end
+
+local function collectkerns(tfmdata,feature)
+ local combinations = { }
+ local resources = tfmdata.resources
+ local characters = tfmdata.characters
+ local sequences = resources.sequences
+ local lookuphash = resources.lookuphash
+ local feature = feature or "kern"
+ if sequences then
+ for i=1,#sequences do
+ local sequence = sequences[i]
+ if sequence.features and sequence.features[feature] then
+ local lookuplist = sequence.subtables
+ if lookuplist then
+ for l=1,#lookuplist do
+ local lookupname = lookuplist[l]
+ local lookupdata = lookuphash[lookupname]
+ for unicode, data in next, lookupdata do
+ local kerns = combinations[unicode]
+ if not kerns then
+ kerns = { }
+ combinations[unicode] = kerns
+ end
+ for otherunicode, kern in next, data do
+ if not kerns[otherunicode] and kern ~= 0 then
+ kerns[otherunicode] = kern
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ return combinations
+end
+
+local showkernpair = context.showkernpair
+
+function moduledata.fonts.features.showbasekerns(specification)
+ -- assumes that the font is loaded in base mode
+ local id = tonumber(specification.number)
+ local tfmdata = fonts.hashes.identifiers[id or font.current()]
+ local done = false
+ for unicode, character in sortedhash(tfmdata.characters) do
+ local kerns = character.kerns
+ if kerns then
+ context.par()
+ for othercode, kern in sortedhash(kerns) do
+ showkernpair(unicode,kern,othercode)
+ end
+ context.par()
+ done = true
+ end
+ end
+ if not done then
+ context("no kern pairs found")
+ context.par()
+ end
+end
+
+function moduledata.fonts.features.showallkerns(specification)
+ local id = tonumber(specification.number)
+ local tfmdata = fonts.hashes.identifiers[id or font.current()]
+ local allkerns = collectkerns(tfmdata)
+ local characters = tfmdata.characters
+ if next(allkerns) then
+ for first, pairs in sortedhash(allkerns) do
+ context.par()
+ for second, kern in sortedhash(pairs) do
+ -- local kerns = characters[first].kerns
+ -- if not kerns and pairs[second] then
+ -- -- weird
+ -- end
+ showkernpair(first,kern,second,0)
+ end
+ context.par()
+ end
+ else
+ context("no kern pairs found")
+ context.par()
+ end
+end