diff options
author | Context Git Mirror Bot <phg42.2a@gmail.com> | 2016-03-26 13:38:18 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2016-03-26 13:38:18 +0100 |
commit | 788487819ccf38a8478cc2afd88e0c0b088d0ec1 (patch) | |
tree | 215addbe3b9e293c2958227e7fc8923880b2e71f /tex/context/base/mkiv/lpdf-ini.lua | |
parent | adfe72d5a0c9d7bdc1bd7bc8faabb4d05e21d70a (diff) | |
download | context-788487819ccf38a8478cc2afd88e0c0b088d0ec1.tar.gz |
2016-03-26 13:07:00
Diffstat (limited to 'tex/context/base/mkiv/lpdf-ini.lua')
-rw-r--r-- | tex/context/base/mkiv/lpdf-ini.lua | 74 |
1 files changed, 63 insertions, 11 deletions
diff --git a/tex/context/base/mkiv/lpdf-ini.lua b/tex/context/base/mkiv/lpdf-ini.lua index e2a85bccf..0d96abb7d 100644 --- a/tex/context/base/mkiv/lpdf-ini.lua +++ b/tex/context/base/mkiv/lpdf-ini.lua @@ -12,6 +12,7 @@ local setmetatable, getmetatable, type, next, tostring, tonumber, rawset = setme local char, byte, format, gsub, concat, match, sub, gmatch = string.char, string.byte, string.format, string.gsub, table.concat, string.match, string.sub, string.gmatch local utfchar, utfbyte, utfvalues = utf.char, utf.byte, utf.values local sind, cosd, floor, max, min = math.sind, math.cosd, math.floor, math.max, math.min +local sort = table.sort local lpegmatch, P, C, R, S, Cc, Cs = lpeg.match, lpeg.P, lpeg.C, lpeg.R, lpeg.S, lpeg.Cc, lpeg.Cs local formatters = string.formatters local isboolean = string.is_boolean @@ -369,34 +370,85 @@ local f_tonumber = formatters["%F"] local tostring_a, tostring_d +-- tostring_d = function(t,contentonly,key) +-- if next(t) then +-- local r, rn = { }, 0 +-- for k, v in next, t do +-- -- for k, v in sortedhash(t) do -- can be an option +-- rn = rn + 1 +-- local tv = type(v) +-- if tv == "string" then +-- r[rn] = f_key_value(k,toeight(v)) +-- elseif tv == "number" then +-- r[rn] = f_key_number(k,v) +-- -- elseif tv == "unicode" then -- can't happen +-- -- r[rn] = f_key_value(k,tosixteen(v)) +-- elseif tv == "table" then +-- local mv = getmetatable(v) +-- if mv and mv.__lpdftype then +-- -- if v == t then +-- -- report_objects("ignoring circular reference in dirctionary") +-- -- r[rn] = f_key_null(k) +-- -- else +-- r[rn] = f_key_value(k,tostring(v)) +-- -- end +-- elseif v[1] then +-- r[rn] = f_key_value(k,tostring_a(v)) +-- else +-- r[rn] = f_key_value(k,tostring_d(v)) +-- end +-- else +-- r[rn] = f_key_value(k,tostring(v)) +-- end +-- end +-- if contentonly then +-- return concat(r," ") +-- elseif key then +-- return f_key_dictionary(key,r) +-- else +-- return f_dictionary(r) +-- end +-- elseif contentonly then +-- return "" +-- else +-- return "<< >>" +-- end +-- end + tostring_d = function(t,contentonly,key) if next(t) then - local r, rn = { }, 0 - for k, v in next, t do - rn = rn + 1 + local r, n = { }, 0 + for k in next, t do + n = n + 1 + r[n] = k + end + sort(r) + for i=1,n do + local k = r[i] + local v = t[k] local tv = type(v) if tv == "string" then - r[rn] = f_key_value(k,toeight(v)) + r[i] = f_key_value(k,toeight(v)) elseif tv == "number" then - r[rn] = f_key_number(k,v) + r[i] = f_key_number(k,v) -- elseif tv == "unicode" then -- can't happen - -- r[rn] = f_key_value(k,tosixteen(v)) + -- r[i] = f_key_value(k,tosixteen(v)) elseif tv == "table" then local mv = getmetatable(v) if mv and mv.__lpdftype then -- if v == t then -- report_objects("ignoring circular reference in dirctionary") - -- r[rn] = f_key_null(k) + -- r[i] = f_key_null(k) -- else - r[rn] = f_key_value(k,tostring(v)) + r[i] = f_key_value(k,tostring(v)) -- end elseif v[1] then - r[rn] = f_key_value(k,tostring_a(v)) + r[i] = f_key_value(k,tostring_a(v)) else - r[rn] = f_key_value(k,tostring_d(v)) + r[i] = f_key_value(k,tostring_d(v)) end else - r[rn] = f_key_value(k,tostring(v)) + r[i] = f_key_value(k,tostring(v)) end end if contentonly then |