summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/char-fio.lua
blob: fa69d9356ace6b0d0279f8d37c70efe9f06cc605 (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
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")
disableaction(textfileactions,         "characters.filters.utf.collapse")

appendaction (textfileactions,"system","characters.filters.utf.decompose")
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 == "line" then
        disableaction(textfileactions,what)
        enableaction (textlineactions,what)
    elseif not toboolean(v) then
        if reporting ~= "never" then
            report("%a disabled",k)
            reporting = "yes"
        end
        enforced[what] = false
        disableaction(textfileactions,what)
        disableaction(textlineactions,what)
    else -- true or text
        enableaction (textfileactions,what)
        disableaction(textlineactions,what)
    end
end

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" }

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