summaryrefslogtreecommitdiff
path: root/scripts/context/lua/mtx-colors.lua
blob: 1c3f8cf82673cd4f0a42d3589a8e2fd57e9e794f (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
if not modules then modules = { } end modules ['mtx-colors'] = {
    version   = 1.001,
    comment   = "companion to mtxrun.lua",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

-- todo: fc-cache -v en check dirs, or better is: fc-cat -v | grep Directory

local helpinfo = [[
<?xml version="1.0"?>
<application>
 <metadata>
  <entry name="name">mtx-colors</entry>
  <entry name="detail">ConTeXt Color Management</entry>
  <entry name="version">0.10</entry>
 </metadata>
 <flags>
  <category name="basic">
   <subcategory>
    <flag name="table"><short>show icc table</short></flag>
   </subcategory>
  </category>
 </flags>
 <examples>
  <category>
   <title>Example</title>
   <subcategory>
    <example><command>mtxrun --script color --table somename</command></example>
   </subcategory>
  </category>
 </examples>
</application>
]]

local application = logs.application {
    name     = "mtx-colors",
    banner   = "ConTeXt Color Management 0.10",
    helpinfo = helpinfo,
}

local report = application.report

if not fontloader then fontloader = fontforge end

dofile(resolvers.findfile("colo-icc.lua","tex"))

scripts        = scripts        or { }
scripts.colors = scripts.colors or { }

function scripts.colors.table()
    local files = environment.files
    if #files > 0 then
        for i=1,#files do
            local profile, okay, message = colors.iccprofile(files[i])
            if not okay then
                report(message)
            else
                report(table.serialize(profile,"profile"))
            end
        end
    else
        local files = resolvers.findfiles("*.icc")
        if #files > 0 then
            for i=1,#files do
                report(files[i])
            end
        else
            report("no file(s) given" )
        end
    end
end

--~ local track = environment.argument("track")
--~ if track then trackers.enable(track) end

if environment.argument("table") then
    scripts.colors.table()
elseif environment.argument("exporthelp") then
    application.export(environment.argument("exporthelp"),environment.files[1])
else
    application.help()
end