summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/metapost/mpcolornames/spec-svgnam-def.awk
blob: 060be65b733ba73bd90b3da285fd9a4d1e489a4d (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
### file spec-svgnam-def.awk
### Copyright 2009, 2011 Stephan Hennig
#
# This work may be distributed and/or modified under the conditions of
# the LaTeX Project Public License, either version 1.3 of this license
# or (at your option) any later version.  The latest version of this
# license is in http://www.latex-project.org/lppl.txt
#
BEGIN {
    FS = ",|;|}"
    i = 0
}
# file version
/\[[0-9]+\/[0-9]+\/[0-9]+ v[0-9.]+[a-z]* .*\]/ {
    match($0, "v[0-9.]+[a-z]*")
    version = substr($0, RSTART, RLENGTH)
}
# RGB color spec
/[a-z]+,[0-9.]+,[0-9.]+,[0-9.]+[;}]/ {
    i++
    name[i] = $1
    r[i] = $2
    g[i] = $3
    b[i] = $4
#    print name[i] "=(" r[i] "," g[i] "," b[i] ")"
}
END {
    print "Found " i " SVG colors (" version ")."
# Build file mpcolornames-spec-svgnam-def.mp.
    file = "mpcolornames-spec-svgnam-def.mp"
    print "%%% file " file > file
    print "%%% Copyright 2009, 2011 Stephan Hennig" >> file
    print "%" >> file
    print "% This work may be distributed and/or modified under the conditions of" >> file
    print "% the LaTeX Project Public License, either version 1.3 of this license" >> file
    print "% or (at your option) any later version.  The latest version of this" >> file
    print "% license is in http://www.latex-project.org/lppl.txt" >> file
    print "%" >> file
    print "def _mpcolornames_spec_svgnam_def=" >> file
    print "rgbcolor" >> file
    for (j = 1; j < i; j++) print name[j] "," >> file
    print name[i] ";" >> file
    for (j = 1; j <= i; j++) print name[j] ":=(" r[j] "," g[j] "," b[j] ");" >> file
    print "enddef;" >> file
    print "endinput" >> file

# Build file proof-spec-svgnam-def.mp.
    file = "proof-spec-svgnam-def.mp"
    print "%%% file " file > file
    print "input proof-mpcolornames" >> file
    print "defaultcolormodel := 5;% RGB" >> file
    print "specname := \"svgnam-def\";" >> file
    for (j = 1; j <= i; j++) print "proof(" name[j] ");" >> file
    print "end" >> file

# Build file tab-spec-svgnam-def.tex.
    file = "tab-spec-svgnam-def.tex"
    print "%%% file " file > file
    print "\\vspace{\\floatsep}" >> file
    print "\\begin{multicols}{4}[\\noindent\\parbox{\\textwidth}{%" >> file
    print "    \\captionof{table}{RGB colors from SVG specification.}%" >> file
    print "    \\label{tab:spec-svgnam-def}%" >> file
    print "    \\footnotesize Taken from file \\texttt{svgnam.def} " version " as distributed by \\LaTeX\\ package \\name{xcolor} (" i " colors)." >> file
    print "  }]" >> file
    print "  \\raggedcolumns" >> file
    print "  \\setlength{\\parindent}{0pt}" >> file
    print "  \\ttfamily\\small\\color{mpcolor}" >> file
    for (j = 1; j <= i; j++) print "\\colorproof[svgnam-def]{" name[j] "}\\par" >> file
    print "\\end{multicols}" >> file
}