summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2012-01-27 13:23:38 +0100
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2012-01-27 13:23:38 +0100
commitc4cde957643af62d7291e27520b2f823d096fbee (patch)
tree99b6f895fcc323ee7fff16ce25cce762d4178e99
parent0e9875dc02be12d84c42ff6458172cfac8cf7e07 (diff)
downloadcyrillicnumbers-c4cde957643af62d7291e27520b2f823d096fbee.tar.gz
font titlo funcs; some docstrings
-rw-r--r--tex/context/third/cyrillicnumbers/cyrillicnumbers.lua84
-rw-r--r--tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkiv8
2 files changed, 65 insertions, 27 deletions
diff --git a/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua b/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua
index 72ed5e4..62c634d 100644
--- a/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua
+++ b/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua
@@ -29,7 +29,7 @@ local iowrite = io.write
local mathceil = math.ceil
local mathfloor = math.floor
local tableconcat = table.concat
-local tablemaxn = table.maxn
+--local tablemaxn = table.maxn
local tableinsert = table.insert
local utf8char = unicode.utf8.char
local utf8len = unicode.utf8.len
@@ -77,14 +77,9 @@ local cyrillic_100k = utf8char(0x488) -- combining hundred thousands sign
local cyrillic_1m = utf8char(0x489) -- combining million sign
local cyrillic_titlo = utf8char(0x483) -- combining titlo
-cyrnum.last_synonyms = {
- final = true,
- last = true,
- right = true,
- rightmost = true,
- ["false"] = true,
-}
-
+--[[ldx--
+<p>Some string synonyms for user convenience.</p>
+--ldx]]--
cyrnum.yes_synonyms = {
yes = true,
yeah = true,
@@ -97,9 +92,28 @@ cyrnum.no_synonyms = {
["false"] = true,
}
+--[[ldx--
+<p><type>m</type> for rounded down middle position, <type>l</type> for final
+position. Will default to initial position otherwise.</p>
+--ldx]]--
+cyrnum.position_synonyms = {
+ final = "l",
+ last = "l",
+ right = "l",
+ rightmost = "l",
+ ["false"] = "l",
+ middle = "m",
+ center = "m",
+ ["true"] = "m",
+}
+
+--[[ldx--
+<p>Digits above the thirds require special markers, some of which need to be
+placed before, others after the determined character.</p>
+--ldx]]--
local handle_plus1k = function (digit)
local before, after
- if digit == 7 then
+ if digit == 7 then
after = cyrillic_1m
elseif cyrnum.prefer100k and digit == 6 then
after = cyrillic_100k
@@ -116,9 +130,14 @@ end
-- [4] = print this after character (e.g. million signs)
-- }
+--[[ldx--
+<p>The base list of digits denotes empty (zero) digits with "false" values
+instead of characters. The function <type>digits_only</type> will extract only
+the nonempty digit values, returning a list.</p>
+--ldx]]--
local digits_only = function (list)
local result = { }
- for i=1, tablemaxn(list) do
+ for i=1, #list do
local elm = list[i]
if type(elm) == "string" then
local before, after
@@ -131,21 +150,37 @@ local digits_only = function (list)
return result
end
-local lreverse = function(list)local r={}for i=tablemaxn(list),1,-1 do r[#r+1]=list[i]end return r end
+--[[ldx--
+<p>The different ways for drawing the <italic>titlo</italic> are stored inside
+a table. Basically, the options are to use the titlos symbol that is provided
+by the font or to draw the titlo in <l n="metapost"/>.</p>
+--ldx]]--
+local lreverse = function(list)local r={}for i=#list,1,-1 do r[#r+1]=list[i]end return r end
local start_titlo, stop_titlo = [[\cyrnumdrawtitlo{]], "}"
local titlofuncs = {
font = function (list)
+ local result, titlopos = { }, #list
if cyrnum.titlolocation == "l" then
- local result = lreverse(list)
- result[#result+1] = cyrillic_titlo
- return result
+ titlopos = 1
+ elseif cyrnum.titlolocation == "m" then
+ titlopos = mathceil(#list/2)
end
- -- “middle” (“m”) or whatever
- local pos = mathceil(tablemaxn(list)/2)
- tableinsert(list, mathceil(tablemaxn(list)/2), cyrillic_titlo)
- return lreverse(list)
+ for i=#list, 1, -1 do
+ local char, digit, before, after = list[i][1], list[i][2], list[i][3], list[i][4]
+ if before then
+ result[#result+1] = before
+ end
+ result[#result+1] = char
+ if after then
+ result[#result+1] = after
+ end
+ if i == titlopos then
+ result[#result+1] = cyrillic_titlo
+ end
+ end
+ return result
end,
mp = function (list)
local result = { }
@@ -155,9 +190,9 @@ local titlofuncs = {
if titlotype == true then -- number
titlostart = (#list >= titlospan) and titlospan or #list
end
- for i=tablemaxn(list), 1, -1 do
- --local char, digit, before, after = list[i][1], list[i][2], list[i][
- local char, digit, before, after = unpack(list[i])
+ for i=#list, 1, -1 do
+ local char, digit, before, after = list[i][1], list[i][2], list[i][3], list[i][4]
+ --local char, digit, before, after = unpack(list[i])
if i == titlostart then
result[#result+1] = start_titlo
end
@@ -175,10 +210,13 @@ local titlofuncs = {
no = function (x) return x end,
}
+--[[ldx--
+<p>Concatenation of the digit list has to take into account different conditions: whether the user requests the dot markers to be added, whether a titlo is requested etc.</p>
+--ldx]]--
local concat_cyrillic_nums = function (list, upper)
local result = ""
local digits = digits_only(list) -- strip placeholders
- local nlist, ndigits = tablemaxn(list), tablemaxn(digits)
+ local nlist, ndigits = #list, #digits
dbg(list)
--dbg(digits)
local titlo = titlofuncs[cyrnum.placetitlo]
diff --git a/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkiv b/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkiv
index 600bee4..24e7b56 100644
--- a/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkiv
+++ b/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkiv
@@ -37,7 +37,7 @@
\s!parent=\v!cyrnum,
setup=\v!list,
style=\v!no,
- type=module,
+ type=module,
version=hg-tip,
]
@@ -47,9 +47,9 @@
\startluacode
local tc = thirddata.cyrnum
tc.placetitlo = "\cyrnumparameter{\v!titlo}"
- tc.titlolocation = tc.last_synonyms["\cyrnumparameter{\v!titlolocation}"] and "l" or "m"
- tc.prefer100k = tc. yes_synonyms["\cyrnumparameter{\v!preferhundredk}"] or false
- tc.drawdots = tc. yes_synonyms["\cyrnumparameter{\v!dots}"] or false
+ tc.titlolocation = tc.position_synonyms["\cyrnumparameter{\v!titlolocation}"] or "f"
+ tc.prefer100k = tc. yes_synonyms["\cyrnumparameter{\v!preferhundredk}"] or false
+ tc.drawdots = tc. yes_synonyms["\cyrnumparameter{\v!dots}"] or false
tc.dotsymbol = "\cyrnumparameter{\v!dotsymbol}"
local span = "\cyrnumparameter{\v!titlospan}"