summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/char-fio.lua
blob: b1f652eedb0b9ed447c8ed689e2e67e247016049 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
if not modules then modules = { } end modules ['char-fio'] = {
    version   = 1.001,
    comment   = "companion to char-ini.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

-- % directives="filters.utf.reorder=false"


local next = next

-- --

local sequencers      = utilities.sequencers
local appendaction    = sequencers.appendaction
local enableaction    = sequencers.enableaction
local disableaction   = sequencers.disableaction

local utffilters      = characters.filters.utf

local textfileactions = resolvers.openers.helpers.textfileactions
local textlineactions = resolvers.openers.helpers.textlineactions

appendaction (textfileactions,"system","characters.filters.utf.reorder")
disableaction(textfileactions,         "characters.filters.utf.reorder")

appendaction (textlineactions,"system","characters.filters.utf.reorder")
disableaction(textlineactions,         "characters.filters.utf.reorder")

appendaction (textfileactions,"system","characters.filters.utf.collapse")   -- not per line
disableaction(textfileactions,         "characters.filters.utf.collapse")

appendaction (textfileactions,"system","characters.filters.utf.decompose")  -- not per line
disableaction(textfileactions,         "characters.filters.utf.decompose")

local report    = logs.reporter("unicode filter")
local reporting = "no"

-- this is messy as for performance reasons i don't want this to happen
-- per line by default

local enforced = {
    ["characters.filters.utf.collapse"]  = true,
    ["characters.filters.utf.decompose"] = true,
    ["characters.filters.utf.reorder"]   = false,
}

function utffilters.enable()
    -- only used one time (normally)
    for k, v in next, enforced do
        if v then
            if reporting == "yes" then
                report("%a enabled",k)
            end
            enableaction(textfileactions,k)
        else
            if reporting == "yes" then
                report("%a not enabled",k)
            end
        end
    end
    reporting = "never"
end

local function configure(what,v)
    if v == "" then
        report("%a unset",what)
    elseif v == "line" then
        disableaction(textfileactions,what)
        enableaction (textlineactions,what)
    elseif not toboolean(v) then
        if reporting ~= "never" then
            report("%a disabled",what)
            reporting = "yes"
        end
        enforced[what] = false
        disableaction(textfileactions,what)
        disableaction(textlineactions,what)
    else -- true or text
        enableaction (textfileactions,what)
        disableaction(textlineactions,what)
    end
end

-- first line:
--
-- % directives="filters.utf.collapse=true"

directives.register("filters.utf.reorder",   function(v) configure("characters.filters.utf.reorder",  v) end)
directives.register("filters.utf.collapse",  function(v) configure("characters.filters.utf.collapse", v) end)
directives.register("filters.utf.decompose", function(v) configure("characters.filters.utf.decompose",v) end)

utffilters.setskippable {
    "mkiv", "mkvi",
    "mkix", "mkxi",
    "mkxl", "mklx",
}

interfaces.implement {
    name     = "enableutf",
    onlyonce = true,
    actions  = utffilters.enable
}