summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/scrp-ini.lua
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2011-06-01 08:54:21 +0000
committerTaco Hoekwater <taco@elvenkind.com>2011-06-01 08:54:21 +0000
commitd7ccb42582f85acf30568913610ccf4d602023fb (patch)
tree7292e3545a420676878e7451b68892d360c62cb6 /Master/texmf-dist/tex/context/base/scrp-ini.lua
parent2d62a6fe9b80def59c392268022f1f9a2d6e358f (diff)
commit context 2011.05.18
git-svn-id: svn://tug.org/texlive/trunk@22719 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/scrp-ini.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/scrp-ini.lua250
1 files changed, 161 insertions, 89 deletions
diff --git a/Master/texmf-dist/tex/context/base/scrp-ini.lua b/Master/texmf-dist/tex/context/base/scrp-ini.lua
index b28c297d0bd..ef036cdf686 100644
--- a/Master/texmf-dist/tex/context/base/scrp-ini.lua
+++ b/Master/texmf-dist/tex/context/base/scrp-ini.lua
@@ -6,39 +6,53 @@ if not modules then modules = { } end modules ['scrp-ini'] = {
license = "see context related readme files"
}
+-- we need to rewrite this a bit ... rather old code
+
+local attributes, nodes, node = attributes, nodes, node
+
+local texwrite = tex.write
+
local trace_analyzing = false trackers.register("scripts.analyzing", function(v) trace_analyzing = v end)
local trace_injections = false trackers.register("scripts.injections", function(v) trace_injections = v end)
+local report_preprocessing = logs.reporter("scripts","preprocessing")
+
+local allocate = utilities.storage.allocate
+
local set_attribute = node.set_attribute
local has_attribute = node.has_attribute
-local first_character = node.first_character
+local first_glyph = node.first_glyph or node.first_character
local traverse_id = node.traverse_id
-local glyph = node.id('glyph')
-local glue = node.id('glue')
-local penalty = node.id('penalty')
+local texsetattribute = tex.setattribute
+
+local nodecodes = nodes.nodecodes
+local unsetvalue = attributes.unsetvalue
+
+local glyph_code = nodecodes.glyph
+local glue_code = nodecodes.glue
-local fcs = (fonts.color and fonts.color.set) or function() end
-local fcr = (fonts.color and fonts.color.reset) or function() end
+local a_preproc = attributes.private('preproc')
+local a_prestat = attributes.private('prestat')
-local state = attributes.private('state')
-local preproc = attributes.private('preproc')
-local prestat = attributes.private('prestat')
+local fontdata = fonts.hashes.identifiers
-local fontdata = fonts.ids
+local setnodecolor = nodes.tracers.colors.set
-scripts = scripts or { }
-scripts.handlers = scripts.handlers or { }
+scripts = scripts or { }
+local scripts = scripts
-scripts.names = scripts.names or { }
-scripts.numbers = scripts.numbers or { }
-scripts.hash = scripts.hash or { }
+scripts.hash = scripts.hash or { }
+local hash = scripts.hash
-storage.register("scripts/hash", scripts.hash, "scripts.hash")
+local handlers = allocate()
+scripts.handlers = handlers
-if not next(scripts.hash) then
+storage.register("scripts/hash", hash, "scripts.hash")
- local hash = {
+if not next(hash) then
+
+ hash = { -- no local
--
-- half width opening parenthesis
[0x0028] = "half_width_open",
@@ -159,26 +173,121 @@ if not next(scripts.hash) then
for i=0x01160,0x011A7 do if not hash[i] then hash[i] = "jamo_medial" end end
for i=0x011A8,0x011FF do if not hash[i] then hash[i] = "jamo_final" end end
+ for i=0x01200,0x0139F do hash[i] = "ethiopic_syllable" end
+
+ hash[0x01361] = "ethiopic_word"
+ hash[0x01362] = "ethiopic_sentence"
+
scripts.hash = hash
end
-scripts.colors = { -- todo: just named colors
- korean = "font:isol",
- chinese = "font:rest",
- full_width_open = "font:init",
- full_width_close = "font:fina",
- half_width_open = "font:init",
- half_width_close = "font:fina",
- hyphen = "font:medi",
- non_starter = "font:isol",
- jamo_initial = "font:init",
- jamo_medial = "font:medi",
- jamo_final = "font:fina",
+local numbertodataset = allocate()
+local numbertohandler = allocate()
+
+--~ storage.register("scripts/hash", hash, "scripts.hash")
+
+scripts.numbertodataset = numbertodataset
+
+function scripts.installmethod(handler)
+ local name = handler.name
+ handlers[name] = handler
+ local attributes = { }
+ local datasets = handler.datasets
+ if not datasets or not datasets.default then
+ report_preprocessing("missing (default) dataset in script '%s'",name)
+ end
+ setmetatable(attributes, {
+ __index = function(t,k)
+ local v = datasets[k] or datasets.default
+ local a = unsetvalue
+ if v then
+ v.name = name -- for tracing
+ a = #numbertodataset + 1
+ numbertodataset[a] = v
+ numbertohandler[a] = handler
+ end
+ t[k] = a
+ return a
+ end
+ } )
+ handler.attributes = attributes
+end
+
+function scripts.installdataset(specification) -- global overload
+ local method = specification.method
+ local name = specification.name
+ local dataset = specification.dataset
+ if method and name and dataset then
+ local parent = specification.parent or ""
+ local handler = handlers[method]
+ if handler then
+ local datasets = handler.datasets
+ if datasets then
+ local defaultset = datasets.default
+ if defaultset then
+ if parent ~= "" then
+ local p = datasets[parent]
+ if p then
+ defaultset = p
+ else
+ report_preprocessing("dataset, unknown parent '%s' for method '%s'",parent,method)
+ end
+ end
+ setmetatable(dataset,defaultset)
+ local existing = datasets[name]
+ if existing then
+ for k, v in next, existing do
+ existing[k] = dataset
+ end
+ else
+ datasets[name] = dataset
+ end
+ else
+ report_preprocessing("dataset, no default for method '%s'",method)
+ end
+ else
+ report_preprocessing("dataset, no datasets for method '%s'",method)
+ end
+ else
+ report_preprocessing("dataset, no method '%s'",method)
+ end
+ else
+ report_preprocessing("dataset, invalid specification") -- maybe report table
+ end
+end
+
+function scripts.set(name,method,preset)
+ local handler = handlers[method]
+ texsetattribute(a_preproc,handler and handler.attributes[preset] or unsetvalue)
+end
+
+function scripts.reset()
+ texsetattribute(handler.attributes[preset])
+end
+
+-- the following tables will become a proper installer (move to cjk/eth)
+local scriptcolors = allocate { -- todo: just named colors
+ korean = "trace:0",
+ chinese = "trace:0",
+ full_width_open = "trace:1",
+ full_width_close = "trace:2",
+ half_width_open = "trace:3",
+ half_width_close = "trace:4",
+ hyphen = "trace:5",
+ non_starter = "trace:6",
+ jamo_initial = "trace:7",
+ jamo_medial = "trace:8",
+ jamo_final = "trace:9",
+ ethiopic_syllable = "trace:1",
+ ethiopic_word = "trace:2",
+ ethiopic_sentence = "trace:3",
}
-scripts.number_to_kind = {
+scripts.colors = scriptcolors
+
+local numbertocategory = allocate { -- rather bound to cjk ... will be generalized
"korean",
"chinese",
"full_width_open",
@@ -190,62 +299,23 @@ scripts.number_to_kind = {
"jamo_initial",
"jamo_medial",
"jamo_final",
+ "ethiopic_syllable",
+ "ethiopic_word",
+ "ethiopic_sentence",
}
-scripts.kind_to_number = {
- korean = 1,
- chinese = 2,
- full_width_open = 3,
- full_width_close = 4,
- half_width_open = 5,
- half_width_close = 6,
- hyphen = 7,
- non_starter = 8,
- jamo_initial = 9,
- jamo_medial = 10,
- jamo_final = 11,
-}
-
-local kind_to_number = scripts.kind_to_number
-local number_to_kind = scripts.number_to_kind
-
--- no, this time loading the lua always precedes the definitions
---
--- storage.register("scripts/names", scripts.names, "scripts.names")
--- storage.register("scripts/numbers", scripts.numbers, "scripts.numbers")
-
-local handlers = scripts.handlers
-local names = scripts.names
-local numbers = scripts.numbers
-local hash = scripts.hash
-local colors = scripts.colors
-
--- maybe also process
-
-function scripts.install(handler)
- local name = handler.name
- if not names[name] then
- local n = #numbers + 1
- numbers[n] = name
- names[name] = n
- handlers[n] = handler
- end
- return names[name]
-end
-
-function scripts.define(name)
- tex.write(names[name] or attributes.unsetvalue)
-end
+local categorytonumber = allocate(table.swapped(numbertocategory)) -- could be one table
--- some time i will make a fonts.originals[id]
+scripts.categorytonumber = categorytonumber
+scripts.numbertocategory = numbertocategory
local function colorize(start,stop)
- for n in traverse_id(glyph,start) do
- local kind = number_to_kind[has_attribute(n,prestat)]
+ for n in traverse_id(glyph_code,start) do
+ local kind = numbertocategory[has_attribute(n,a_prestat)]
if kind then
- local ac = colors[kind]
+ local ac = scriptcolors[kind]
if ac then
- fcs(n,ac)
+ setnodecolor(n,ac)
end
end
if n == stop then
@@ -257,9 +327,11 @@ end
local function traced_process(head,first,last,process,a)
if start ~= last then
local f, l = first, last
- logs.report("preprocess","before %s: %s",names[a] or "?",nodes.tosequence(f,l))
+ local name = numbertodataset[a]
+ name = name and name.name or "?"
+ report_preprocessing("before %s: %s",name,nodes.tosequence(f,l))
process(head,first,last)
- logs.report("preprocess","after %s: %s", names[a] or "?",nodes.tosequence(f,l))
+ report_preprocessing("after %s: %s", name,nodes.tosequence(f,l))
end
end
@@ -269,7 +341,7 @@ end
-- one of the time consuming functiions:
function scripts.preprocess(head)
- local start = first_character(head)
+ local start = first_glyph(head)
if not start then
return head, false
else
@@ -277,8 +349,8 @@ function scripts.preprocess(head)
local done, first, last, ok = false, nil, nil, false
while start do
local id = start.id
- if id == glyph then
- local a = has_attribute(start,preproc)
+ if id == glyph_code then
+ local a = has_attribute(start,a_preproc)
if a then
if a ~= last_a then
if first then
@@ -296,20 +368,20 @@ function scripts.preprocess(head)
first, last = nil, nil
end
last_a = a
- local handler = handlers[a]
+ local handler = numbertohandler[a]
normal_process = handler.process
end
if normal_process then
local f = start.font
if f ~= lastfont then
- originals = fontdata[f].originals
+ originals = fontdata[f].resources.originals
lastfont = f
end
local c = start.char
if originals then c = originals[c] or c end
local h = hash[c]
if h then
- set_attribute(start,prestat,kind_to_number[h])
+ set_attribute(start,a_prestat,categorytonumber[h])
if not first then
first, last = start, start
else
@@ -347,7 +419,7 @@ function scripts.preprocess(head)
end
first, last = nil, nil
end
- elseif id == glue then
+ elseif id == glue_code then
if ok then
-- continue
elseif first then