pack-ori.lmt /size: 2150 b    last modification: 2023-12-21 09:44
1if not modules then modules = { } end modules ['pack-ori'] = {
2    version   = 1.001,
3    comment   = "companion to supp-box.mkiv",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9local context   = context
10local implement = interfaces.implement
11local variables = interfaces.variables
12
13local settings_to_array = utilities.parsers.settings_to_array
14
15local orientation = {
16    [variables.up]     = 0x000,
17    [variables.left]   = 0x001,
18    [variables.down]   = 0x002,
19    [variables.right]  = 0x003,
20    [variables.top]    = 0x004,
21    [variables.bottom] = 0x005,
22}
23local vertical = {
24    [variables.line]   = 0x000,
25    [variables.top]    = 0x010,
26    [variables.bottom] = 0x020,
27    [variables.middle] = 0x030,
28}
29local horizontal = {
30    [variables.middle]     = 0x000,
31    [variables.flushleft]  = 0x100,
32    [variables.flushright] = 0x200,
33    [variables.left]       = 0x300, -- why not 0x100
34    [variables.right]      = 0x400, -- why not 0x200
35}
36
37implement {
38    name      = "toorientation",
39    public    = true,
40    arguments = {
41        {
42            { "horizontal",  "string" },
43            { "vertical",    "string" },
44            { "orientation", "string" },
45        }
46    },
47    actions   = function(t)
48        local n = 0
49        local m = t.horizontal  if m then n = n | (horizontal [m] or 0) end
50        local m = t.vertical    if m then n = n | (vertical   [m] or 0) end
51        local m = t.orientation if m then n = n | (orientation[m] or 0) end
52     -- logs.report("orientation","0x%03X : %s",n,table.sequenced(t))
53        context(n)
54    end,
55}
56
57implement {
58    name      = "stringtoorientation",
59    public    = true,
60    arguments = "string",
61    actions   = function(s)
62        local n = 0
63        local t = settings_to_array(s)
64        local m = t[1] if m then n = n | (horizontal [m] or 0) end
65        local m = t[2] if m then n = n | (vertical   [m] or 0) end
66        local m = t[3] if m then n = n | (orientation[m] or 0) end
67     -- logs.report("orientation","0x%03X : %s",n,s)
68        context(n)
69    end,
70}
71