diff options
author | Hans Hagen <pragma@wxs.nl> | 2020-02-16 10:59:14 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2020-02-16 10:59:14 +0100 |
commit | 8e11d447440b44990432ac838953a8cde4ef914f (patch) | |
tree | f30b2ff2d8a10f1aff50e1522d968618a97f067c /tex/context/base/mkiv/meta-imp-threesix.mkxl | |
parent | 43fc66771a0c9d27cc0b7fe7a69392ea313bd0ca (diff) | |
download | context-8e11d447440b44990432ac838953a8cde4ef914f.tar.gz |
2020-02-11 16:39:00
Diffstat (limited to 'tex/context/base/mkiv/meta-imp-threesix.mkxl')
-rw-r--r-- | tex/context/base/mkiv/meta-imp-threesix.mkxl | 253 |
1 files changed, 253 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/meta-imp-threesix.mkxl b/tex/context/base/mkiv/meta-imp-threesix.mkxl new file mode 100644 index 000000000..277aa85f7 --- /dev/null +++ b/tex/context/base/mkiv/meta-imp-threesix.mkxl @@ -0,0 +1,253 @@ +% not yet a module + +\startluacode + local gsub, utfbyte = string.gsub, utf.byte + + -- The font from DEK's facs9b.ps (I wish I was clever enough to understand all the good + -- stuff in there): + + local font36 = { + ["0"] = [[00111100 01111110 11000011 11000011 11000011 11000011 01111110 00111100]], + ["1"] = [[00011100 11111100 11101100 00001100 00001100 00001100 11111111 11111111]], + ["2"] = [[00111110 01110011 01110011 00000011 00001110 00111000 11110001 11111111]], + ["3"] = [[01111110 01100110 00000110 00111100 00000110 11100111 11100111 01111110]], + ["4"] = [[00001110 00011110 00110110 01100110 11111111 11111111 00000110 00001110]], + ["5"] = [[01111110 01111110 01000000 01111100 01000111 00000011 11000111 11111110]], + ["6"] = [[01111110 01100110 11000000 11011100 11100110 11000011 01100011 01111110]], + ["7"] = [[11111111 11111111 10000111 10001110 00011100 00011100 00011100 00011100]], + ["8"] = [[01111110 01100110 01100110 00111100 11000011 11000011 11000011 01111110]], + ["9"] = [[01111110 11000110 11000011 01100111 00111011 00000011 01100110 01111110]], + ["A"] = [[000110000 000111000 001111100 001101100 011001110 011111110 010000110 111100111]], + ["B"] = [[1111100 1110110 0110110 0111100 0110011 0110011 1110011 1111100]], + ["C"] = [[01111101 11110011 11100001 11100001 11100000 11100000 11100001 01111110]], + ["D"] = [[11111100 11100010 01100011 01100011 01100011 01100011 11100010 11111100]], + ["E"] = [[1111111 1110001 0110101 0111100 0110100 0110001 1110001 1111111]], + ["F"] = [[11111111 11100001 01100101 01111100 01100100 01100000 11111000 11111000]], + ["G"] = [[01111010 11100110 11100010 11100000 11100111 11100010 11100010 01111100]], + ["H"] = [[11100111 11100111 01000010 01111110 01000010 01000010 11100111 11100111]], + ["I"] = [[1111111 1111111 0011000 0011000 0011000 0011000 1111111 1111111]], + ["J"] = [[01111111 01111111 00000110 00000110 11110110 01100110 01100110 00111100]], + ["K"] = [[11101110 11100100 01101000 01110000 01111000 01101100 11100110 11101111]], + ["L"] = [[111111000 111111000 011000000 011000000 011000000 011000011 111000011 111111111]], + ["M"] = [[1100000011 1110000111 0111111110 0100110010 0100110010 0100000010 1100000011 1100000011]], + ["N"] = [[11000011 11100011 01110010 01111010 01011110 01001110 11100110 11100010]], + ["O"] = [[01111110 11000011 11000011 11000011 11000011 11000011 11000011 01111110]], + ["P"] = [[11111110 11100011 01100011 01111110 01100000 01100000 11111000 11111000]], + ["Q"] = [[01111100 11000110 11000110 11000110 11000110 11001110 11000110 01111101]], + ["R"] = [[11111100 11100110 01100110 01111100 01101000 01100100 11100010 11100111]], + ["S"] = [[01111110 11100001 11100001 01111000 00011110 10000111 11000011 10111110]], + ["T"] = [[1111111111 1100110011 1100110011 0000110000 0000110000 0000110000 0001111000 0001111000]], + ["U"] = [[111101111 111101111 011000010 011000010 011000010 011000010 011000010 001111100]], + ["V"] = [[11111000111 11111000111 01110000010 00110000100 00111000100 00011001000 00001101000 00001110000]], + ["W"] = [[111000000111 111000000111 110000000010 011000000100 011001000100 001101101000 001101101000 000110110000]], + ["X"] = [[1111001110 1111000110 0001101000 0000110000 0000110000 0001011000 0110001111 0111001111]], + ["Y"] = [[111100011 111100011 011000010 001110100 000111000 000011000 001111110 001111110]], + ["Z"] = [[11111111 10000111 00001110 00011100 00111000 01110000 11100001 11111111]], + } + + local f_code = string.formatters["ThreeSix(%s);"] + local replace = { ["0"] = "N;", ["1"] = "Y;", [" "] = "L;" } + + local function remap(str) + -- permit abundant spacing (bonus) + str = gsub(str,"%s+", " ") + -- remap what we got to macro calls + str = gsub(str,".",replace) + -- return the result + return str + end + + function MP.registerthreesix(name) + fonts.dropins.registerglyphs { + name = name, + units = 12, + usecolor = true, + preamble = "InitializeThreeSix;", + } + for u, v in table.sortedhash(font36) do + local ny = 8 + local nx = (#v - ny + 1) // ny + local height = ny * 1.1 - 0.1 + local width = nx * 1.1 - 0.1 + fonts.dropins.registerglyph { + category = name, + unicode = utfbyte(u), + width = width, + height = height, + code = f_code(remap(v)), + } + end + end + + MP.registerthreesix("fontthreesix") +\stopluacode + +% \startMPcalculation{simplefun} +% def InitializeThreeSix = +% save Y, N, L, S ; save dx, dy, nx, ny ; +% save shape, fillcolor, mypen, random, currentpen, spread, hoffset ; +% string shape, fillcolor, mypen ; boolean random ; pen currentpen ; +% dx := 11/10 ; +% dy := - 11/10 ; +% nx := - dx ; +% ny := 0 ; +% shape := getparameterdefault "mpsfont" "shape" "circle" ; +% random := hasoption "mpsfont" "random" "true" ; +% fillcolor := getparameterdefault "mpsfont" "color" "" ; +% mypen := getparameterdefault "mpsfont" "pen" "" ; +% spread := getparameterdefault "mpsfont" "spread" 0 ; +% hoffset := 12 * spread / 2 ; +% currentpen := pencircle +% if mypen = "fancy" : +% xscaled 1/20 yscaled 2/20 rotated 45 +% else : +% scaled 1/20 +% fi ; +% if shape == "square" : +% def S = +% unitsquare if random : randomized 1/10 fi +% shifted (nx,ny) +% enddef ; +% elseif shape = "diamond" : +% def S = +% unitdiamond if random : randomized 1/10 fi +% shifted (nx,ny) +% enddef ; +% else : +% def S = +% unitcircle if random : randomizedcontrols 1/20 fi +% shifted (nx,ny) +% enddef ; +% fi ; +% def N = +% nx := nx + dx ; +% draw S ; +% enddef ; +% if fillcolor = "random" : +% def Y = +% nx := nx + dx ; +% fillup S withcolor white randomized (2/3,2/3,2/3) ; +% enddef ; +% elseif fillcolor = "" : +% def Y = +% nx := nx + dx ; +% fillup S ; +% enddef ; +% else : +% def Y = +% nx := nx + dx ; +% fillup S withcolor fillcolor ; +% enddef ; +% fi ; +% def L = +% nx := - dx ; +% ny := ny + dy ; +% enddef ; +% enddef ; +% +% vardef ThreeSix (text code) = +% InitializeThreeSix ; +% draw image (code) shifted (hoffset,-ny) ; +% enddef ; +% \stopMPcalculation + +\startMPcalculation{simplefun} + def InitializeThreeSix = + save Y, N, L, S ; + % save dx, dy, nx, ny ; + save shape, fillcolor, mypen, random, threesixpen, spread, hoffset ; + string shape, fillcolor, mypen ; boolean random ; pen threesixpen ; + % dx := 11/10 ; + % dy := - 11/10 ; + % nx := - dx ; + % ny := 0 ; + shape := getparameterdefault "mpsfont" "shape" "circle" ; + random := hasoption "mpsfont" "random" "true" ; + fillcolor := getparameterdefault "mpsfont" "color" "" ; + mypen := getparameterdefault "mpsfont" "pen" "" ; + spread := getparameterdefault "mpsfont" "spread" 0 ; + hoffset := 12 * spread / 2 ; + threesixpen := pencircle + if mypen = "fancy" : + xscaled 1/20 yscaled 2/20 rotated 45 + else : + scaled 1/20 + fi ; + if shape == "square" : + def S = + unitsquare if random : randomized 1/10 fi + shifted (nx,ny) + enddef ; + elseif shape = "diamond" : + def S = + unitdiamond if random : randomized 1/10 fi + shifted (nx,ny) + enddef ; + else : + def S = + unitcircle if random : randomizedcontrols 1/20 fi + shifted (nx,ny) + enddef ; + fi ; + def N = + nx := nx + dx ; + draw S ; + enddef ; + if fillcolor = "random" : + def Y = + nx := nx + dx ; + fillup S withcolor white randomized (2/3,2/3,2/3) ; + enddef ; + elseif fillcolor = "" : + def Y = + nx := nx + dx ; + fillup S ; + enddef ; + else : + def Y = + nx := nx + dx ; + fillup S withcolor fillcolor ; + enddef ; + fi ; + def L = + nx := - dx ; + ny := ny + dy ; + enddef ; + enddef ; + + vardef ThreeSix (text code) = + save dx, dy, nx, ny ; + dx := 11/10 ; + dy := - 11/10 ; + nx := - dx ; + ny := 0 ; + pickup threesixpen ; + draw image (code) shifted (hoffset,-ny) ; + enddef ; +\stopMPcalculation + +\definefontfeature % black and white, with some spread + [fontthreesix] + [default] + [metapost=fontthreesix] + +\definefontfeature % color, with some spread + [fontthreesix-tweak] + [default] + [metapost={category=fontthreesix,spread=.1}] + +\definefontfeature % color, with some spread + [fontthreesix-color] + [default] + [metapost={category=fontthreesix,shape=diamond,color=random,pen=fancy,spread=.1}] + +\definefontfeature % color, tight + [fontthreesix-initial] + [metapost={category=fontthreesix,color=random,shape=circle}] % units? + +\definefont[DEKFontA][Serif*fontthreesix] +\definefont[DEKFontB][Serif*fontthreesix-color] +\definefont[DEKFontC][Serif*fontthreesix-initial] +\definefont[DEKFontD][Serif*fontthreesix-tweak] + +\endinput |