summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/meta-imp-demo.mkxl
blob: b89a4771bec5cbc7f27d0ed79749915e7f3b8827 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
%D \module
%D   [       file=meta-imp-demo,
%D        version=2021.01.21,
%D          title=\METAPOST\ Graphics,
%D       subtitle=Demo Font,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D This is just a demo of defining a font in \METAPOST. The rendering as well as definitions
%D are delayed till we actually need the glyph.

\startMPcalculation{simplefun}

    picture DemoSnippets[];

    vardef DemoCircle = image(fill fullcircle scaled 10 ;) enddef ;
    vardef DemoCenter = image(fill fullcircle scaled  3 ;) enddef ;

    vardef DemoLeft       = image(fill fullcircle scaled 3 shifted (-5, 0) ;) enddef ;
    vardef DemoRight      = image(fill fullcircle scaled 3 shifted ( 5, 0) ;) enddef ;
    vardef DemoUp         = image(fill fullcircle scaled 3 shifted ( 0, 5) ;) enddef ;
    vardef DemoDown       = image(fill fullcircle scaled 3 shifted ( 0,-5) ;) enddef ;
    vardef DemoLowerLeft  = image(fill fullcircle scaled 3 shifted (-5,-5) ;) enddef ;
    vardef DemoLowerRight = image(fill fullcircle scaled 3 shifted ( 5,-5) ;) enddef ;
    vardef DemoUpperRight = image(fill fullcircle scaled 3 shifted ( 5, 5) ;) enddef ;
    vardef DemoUpperLeft  = image(fill fullcircle scaled 3 shifted (-5, 5) ;) enddef ;

    vardef DemoGlyph =
        composeglyph(DemoSnippets) ;
    enddef ;

    lmt_registerglyphs [
        name     = "demo",
        units    = 10,
        width    = 10,
        height   = 10,
        depth    = 0,
    ] ;

    % we need to set up some basics (signals to the backend and such) at definition
    % time so we just force a bogus shape (zero)

    lmt_registerglyph [
        category = "demo",
    ] ;

\stopMPcalculation

\startluacode

metapost.metafonts.demo = {
    [utf.byte("g")] = {
        code   = "DemoGlyph",
        shapes = {
            { shape = "DemoCircle", color = "gray"    },
            { shape = "DemoLeft",   color = "cyan"    },
            { shape = "DemoUp",     color = "magenta" },
            { shape = "DemoCenter", color = "yellow"  },
        }
    },
    [utf.byte("h")] = {
        code   = "DemoGlyph",
        shapes = {
            { shape = "DemoCircle", color = "gray"  },
            { shape = "DemoRight",  color = "red"   },
            { shape = "DemoDown",   color = "green" },
            { shape = "DemoCenter", color = "blue"  },
        }
    },
    [19] = {
        code   = "DemoGlyph",
        shapes = {
            { shape = "DemoCircle", color = "gray"     },
            { shape = "DemoUp",     color = "darkgray" },
            { shape = "DemoDown",   color = "darkgray" },
            { shape = "DemoLeft",   color = "darkgray" },
            { shape = "DemoRight",  color = "darkgray" },
            { shape = "DemoCenter", color = "darkgray" },
        }
    },
    ["weirdsymbol"] = {
        code   = "DemoGlyph",
        shapes = {
            { shape = "DemoCircle", color = "middlegray" },
            { shape = "DemoUp",     color = "red"        },
            { shape = "DemoDown",   color = "green"      },
            { shape = "DemoLeft",   color = "blue"       },
            { shape = "DemoRight",  color = "magenta"    },
            { shape = "DemoCenter", color = "yellow"     },
        }
    },
    ["weirdersymbol"] = {
        code   = "DemoGlyph",
        shapes = {
         -- { shape = "DemoCircle",     color = "gray"        },
            { shape = "DemoCenter",     color = "darkgray"    },
            { shape = "DemoLowerLeft",  color = "red"         },
            { shape = "DemoLowerRight", color = "green"       },
            { shape = "DemoUpperRight", color = "blue"        },
            { shape = "DemoUpperLeft",  color = "yellow"      },
            { shape = "DemoUp",         color = "darkred"     },
            { shape = "DemoDown",       color = "darkgreen"   },
            { shape = "DemoLeft",       color = "darkblue"    },
            { shape = "DemoRight",      color = "darkmagenta" },
        }
    }
}

\stopluacode

\continueifinputfile{meta-imp-demo.mkxl}

\setuplayout[tight]

\setupbodyfont[dejavu]

\definefontfeature[demo][metapost=demo,metafont=demo]

\definefont[DemoA][Serif*demo]
\definefont[DemoB][Serif*demo sa .5]
\definefont[DemoC][Serif*demo sa .25]

\starttext

    \startbuffer
        x\ruledhbox{gh}%
        x\ruledhbox{\char19}%
        x\privatecharacter{weirdsymbol}%
        x\privatecharacter{weirdersymbol}%
        x%
    \stopbuffer

    \startTEXpage[offset=2pt]
        \DemoA\getbuffer\par
        \DemoB\getbuffer\quad\DemoC\getbuffer\par
    \stopTEXpage

    {\DemoA\ctxlua{fonts.helpers.setmetaglyph {
        category = "demo",
        name     = "whatever",
        code     = "DemoGlyph",
        shapes   = {
            { shape = "DemoCenter",     color = "darkgray"   },
            { shape = "DemoLowerLeft",  color = "darkred"    },
            { shape = "DemoLowerRight", color = "darkgreen"  },
            { shape = "DemoUpperRight", color = "darkblue"   },
            { shape = "DemoUpperLeft",  color = "darkyellow" },
            { shape = "DemoUp",         color = "red"        },
            { shape = "DemoDown",       color = "green"      },
            { shape = "DemoLeft",       color = "blue"       },
            { shape = "DemoRight",      color = "magenta"    },
        }
    }}}

    {\DemoA\setmetaglyph {
        category {demo}
        name     {forever}
        code     {DemoGlyph}
        shapes   {
            { shape {DemoCenter}     color {middlegray} }
            { shape {DemoLowerLeft}  color {darkgray}   }
            { shape {DemoLowerRight} color {darkgray}   }
            { shape {DemoUpperRight} color {darkgray}   }
            { shape {DemoUpperLeft}  color {darkgray}   }
            { shape {DemoUp}         color {lightgray}  }
            { shape {DemoDown}       color {lightgray}  }
            { shape {DemoLeft}       color {lightgray}  }
            { shape {DemoRight}      color {lightgray}  }
        }
    }}

    \startTEXpage[offset=2pt]
        \DemoA
        \privatecharacter{whatever}
        \privatecharacter{forever}
    \stopTEXpage

    \DemoA\setupinterlinespace \dorecurse{10}{\dorecurse{1000}{g h }\par}\page
    \DemoB\setupinterlinespace \dorecurse{20}{\dorecurse{1000}{g h }\par}\page
    \DemoC\setupinterlinespace \dorecurse{30}{\dorecurse{1000}{g h }\par}\page

    \unexpanded\def\MyChar#1%
      {\begingroup
       \DemoA
       \iffontchar\font\privatecharactercode{forever-#1}\else
         \setmetaglyph {
           category {demo}
           name     {forever-#1}
           code     {DemoGlyph}
           shapes   {
               { shape {DemoCenter}     color {middlegray} }
               { shape {DemoLowerLeft}  color {dark#1}     }
               { shape {DemoLowerRight} color {dark#1}     }
               { shape {DemoUpperRight} color {dark#1}     }
               { shape {DemoUpperLeft}  color {dark#1}     }
               { shape {DemoUp}         color {light#1}    }
               { shape {DemoDown}       color {light#1}    }
               { shape {DemoLeft}       color {light#1}    }
               { shape {DemoRight}      color {light#1}    }
           }
         }%
       \fi
       \privatecharacter{forever-#1}%
       \endgroup}

    \dontcomplain

    \dorecurse{1000}{%
        \MyChar{red}\space
        \MyChar{green}\space
        \MyChar{blue}\space
        \MyChar{yellow}\space
    }

    \page

    \start
        \glyphxscale 1200
        \glyphyscale  800
        \dorecurse{1000}{%
            \MyChar{red}\allowbreak
            \MyChar{green}\allowbreak
            \MyChar{blue}\allowbreak
            \MyChar{yellow}\allowbreak
        }
    \stop

\stoptext