summaryrefslogtreecommitdiff
path: root/tex/context/base/font-aux.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2013-02-13 18:06:00 +0100
committerHans Hagen <pragma@wxs.nl>2013-02-13 18:06:00 +0100
commite85a18b025a884ca31f94408fa5e9d78f8cfd31d (patch)
treec997b733faff3c37545d7998bccacc0cd87c89a7 /tex/context/base/font-aux.lua
parent82bdeb2e18e5047f65bb122aa1b6bdcceb1abb92 (diff)
downloadcontext-e85a18b025a884ca31f94408fa5e9d78f8cfd31d.tar.gz
beta 2013.02.13 18:06
Diffstat (limited to 'tex/context/base/font-aux.lua')
-rw-r--r--tex/context/base/font-aux.lua143
1 files changed, 102 insertions, 41 deletions
diff --git a/tex/context/base/font-aux.lua b/tex/context/base/font-aux.lua
index 5e938ceb9..2a605d224 100644
--- a/tex/context/base/font-aux.lua
+++ b/tex/context/base/font-aux.lua
@@ -7,7 +7,7 @@ if not modules then modules = { } end modules ['font-aux'] = {
}
local tonumber, type = tonumber, type
-local wrap, yield = coroutine.wrap, coroutine.yield
+----- wrap, yield = coroutine.wrap, coroutine.yield
local fonts, font = fonts, font
@@ -18,9 +18,11 @@ local currentfont = font.current
local identifiers = fonts.hashes.identifiers
local sortedkeys = table.sortedkeys
--- for unicode, character in fonts.iterators.characters () do print(k,v) end
--- for unicode, description in fonts.iterators.descriptions() do print(k,v) end
--- for index, glyph in fonts.iterators.glyphs () do print(k,v) end
+-- for unicode, character in fonts.iterators.characters () do print(unicode) end
+-- for unicode, description in fonts.iterators.descriptions() do print(unicode) end
+-- for index, glyph in fonts.iterators.glyphs () do print(index ) end
+
+local function dummy() end
local function checkeddata(data) -- beware, nullfont is the fallback in identifiers
local t = type(data)
@@ -32,22 +34,93 @@ local function checkeddata(data) -- beware, nullfont is the fallback in identifi
return identifiers[data] -- has nullfont as fallback
end
+local function getindices(data)
+ data = checkeddata(data)
+ local indices = { }
+ local characters = data.characters
+ if characters then
+ for unicode, character in next, characters do
+ indices[character.index or unicode] = unicode
+ end
+ end
+ return indices
+end
+
+-- function iterators.characters(data)
+-- data = checkeddata(data)
+-- local characters = data.characters
+-- if characters then
+-- local collected = sortedkeys(characters)
+-- return wrap(function()
+-- for c=1,#collected do
+-- local cc = collected[c]
+-- local dc = characters[cc]
+-- if dc then
+-- yield(cc,dc)
+-- end
+-- end
+-- end)
+-- else
+-- return wrap(function() end)
+-- end
+-- end
+
+-- function iterators.descriptions(data)
+-- data = checkeddata(data)
+-- local characters = data.characters
+-- local descriptions = data.descriptions
+-- if characters and descriptions then
+-- local collected = sortedkeys(characters)
+-- return wrap(function()
+-- for c=1,#collected do
+-- local cc = collected[c]
+-- local dc = descriptions[cc]
+-- if dc then
+-- yield(cc,dc)
+-- end
+-- end
+-- end)
+-- else
+-- return wrap(function() end)
+-- end
+-- end
+
+-- function iterators.glyphs(data)
+-- data = checkeddata(data)
+-- local descriptions = data.descriptions
+-- if descriptions then
+-- local indices = getindices(data)
+-- local collected = sortedkeys(indices)
+-- return wrap(function()
+-- for c=1,#collected do
+-- local cc = collected[c]
+-- local dc = descriptions[indices[cc]]
+-- if dc then
+-- yield(cc,dc)
+-- end
+-- end
+-- end)
+-- else
+-- return wrap(function() end)
+-- end
+-- end
+
function iterators.characters(data)
data = checkeddata(data)
local characters = data.characters
if characters then
- local collected = sortedkeys(characters)
- return wrap(function()
- for c=1,#collected do
- local cc = collected[c]
+ local collected = sortedkeys(characters)
+ local n, i = #collected, 0
+ return function()
+ i = i + 1
+ if i <= n then
+ local cc = collected[i]
local dc = characters[cc]
- if dc then
- yield(cc,dc)
- end
+ return cc, dc or { }
end
- end)
+ end
else
- return wrap(function() end)
+ return dummy
end
end
@@ -57,30 +130,18 @@ function iterators.descriptions(data)
local descriptions = data.descriptions
if characters and descriptions then
local collected = sortedkeys(characters)
- return wrap(function()
- for c=1,#collected do
- local cc = collected[c]
+ local n, i = #collected, 0
+ return function()
+ i = i + 1
+ if i <= n then
+ local cc = collected[i]
local dc = descriptions[cc]
- if dc then
- yield(cc,dc)
- end
+ return cc, dc or { }
end
- end)
- else
- return wrap(function() end)
- end
-end
-
-local function getindices(data)
- data = checkeddata(data)
- local indices = { }
- local characters = data.characters
- if characters then
- for unicode, character in next, characters do
- indices[character.index or unicode] = unicode
end
+ else
+ return dummy
end
- return indices
end
function iterators.glyphs(data)
@@ -89,16 +150,16 @@ function iterators.glyphs(data)
if descriptions then
local indices = getindices(data)
local collected = sortedkeys(indices)
- return wrap(function()
- for c=1,#collected do
- local cc = collected[c]
+ local n, i = #collected, 0
+ return function()
+ i = i + 1
+ if i <= n then
+ local cc = collected[i]
local dc = descriptions[indices[cc]]
- if dc then
- yield(cc,dc)
- end
+ return cc, dc or { }
end
- end)
+ end
else
- return wrap(function() end)
+ return dummy
end
end