summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/pack-ori.lua
blob: a786b19ef13da38f988808cfb525380a150f6d48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
if not modules then modules = { } end modules ['pack-ori'] = {
    version   = 1.001,
    comment   = "companion to supp-box.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local context   = context
local implement = interfaces.implement
local variables = interfaces.variables

local settings_to_array = utilities.parsers.settings_to_array

local orientation = {
    [variables.up]     = 0x000,
    [variables.left]   = 0x001,
    [variables.down]   = 0x002,
    [variables.right]  = 0x003,
    [variables.top]    = 0x004,
    [variables.bottom] = 0x005,
}
local vertical = {
    [variables.line]   = 0x000,
    [variables.top]    = 0x010,
    [variables.bottom] = 0x020,
    [variables.middle] = 0x030,
}
local horizontal = {
    [variables.middle]     = 0x000,
    [variables.flushleft]  = 0x100,
    [variables.flushright] = 0x200,
    [variables.left]       = 0x300,
    [variables.right]      = 0x400,
}

implement {
    name      = "toorientation",
    public    = true,
    arguments = {
        {
            { "horizontal",  "string" },
            { "vertical",    "string" },
            { "orientation", "string" },
        }
    },
    actions   = function(t)
        local n = 0
        local m = t.horizontal  if m then n = n | (horizontal [m] or 0) end
        local m = t.vertical    if m then n = n | (vertical   [m] or 0) end
        local m = t.orientation if m then n = n | (orientation[m] or 0) end
     -- logs.report("orientation","0x%03X : %s",n,table.sequenced(t))
        context(n)
    end,
}

implement {
    name      = "stringtoorientation",
    public    = true,
    arguments = "string",
    actions   = function(s)
        local n = 0
        local t = settings_to_array(s)
        local m = t[1] if m then n = n | (horizontal [m] or 0) end
        local m = t[2] if m then n = n | (vertical   [m] or 0) end
        local m = t[3] if m then n = n | (orientation[m] or 0) end
     -- logs.report("orientation","0x%03X : %s",n,s)
        context(n)
    end,
}