meta-imp-clock.mkxl /size: 3579 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=meta-imp-clock,
3%D        version=2021.01.21,
4%D          title=\METAPOST\ Graphics,
5%D       subtitle=Demo Clock Font,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D This is just a demo of defining a font in \METAPOST. The rendering as well as definitions
15%D are delayed till we actually need the glyph. A crazy examples made in crazy times.
16
17\startMPcalculation{simplefun}
18
19    % the 0 in getparameterdefault makes sure we convert to a number
20
21    picture DemoClocks[];
22
23    vardef ClockCircle =
24        image(draw fullcircle scaled 10 ;)
25    enddef ;
26
27    vardef ClockPoints =
28        image (
29            for i=1 upto 12 :
30                draw (0,5) rotated ((360 * i) / 12) withpen pencircle scaled 1 ;
31            endfor ;
32        )
33    enddef ;
34
35    vardef ClockTicks =
36        image (
37            for i=1 upto 12 :
38                draw ((0,4.5)--(0,5.5)) rotated ((360 * i) / 12) ;
39            endfor ;
40        )
41    enddef ;
42
43    vardef ClockCenter =
44        image (
45            draw origin withpen pencircle scaled 1 ;
46        )
47    enddef ;
48
49    vardef ClockHour =
50        image(
51            draw (origin -- (0,4)) rotated (
52              - 360 * (getparameterdefault "mpsfont" "hour"   0) / 12
53              - 360 * (getparameterdefault "mpsfont" "minute" 0) / (60 * 12)
54
55        ) )
56    enddef ;
57
58    vardef ClockMinute =
59        image(
60            draw (origin -- (0,5)) rotated (
61              - 360 * (getparameterdefault "mpsfont" "minute" 0) / 60
62            )
63        )
64    enddef ;
65
66    vardef DemoClock =
67        composeglyph(DemoClocks) ;
68    enddef ;
69
70    lmt_registerglyphs [
71        name     = "clock",
72        units    = 10,
73        width    = 10,
74        height   = 10,
75        depth    = 0,
76    ] ;
77
78    lmt_registerglyph [
79        category = "clock",
80    ] ;
81
82\stopMPcalculation
83
84% \startluacode
85%     metapost.metafonts.clock = { }
86% \stopluacode
87
88\continueifinputfile{meta-imp-clock.mkxl}
89
90% \enableexperiments[fonts.compact]
91
92\nopdfcompression
93
94\setuplayout[tight]
95
96\setupbodyfont[dejavu]
97
98\definefontfeature[clock][metapost=clock,metafont=clock]
99
100\definefont[ClockFont][Serif*clock]
101
102\starttext
103
104\protected\def\MyClock#1#2%
105  {\begingroup
106   \ClockFont
107   \iffontchar\font\privatecharactercode{CLOCK:#1:#2}\else
108     % We could move this out to a helper \MyClockMake{#1}{#2} but normally
109     % it's efficient enough. (If we trace a lot it matters more.)
110     \setmetaglyph {
111       category {clock}
112       name     {CLOCK:#1:#2}
113       code     {DemoClock}
114       hour     {#1}
115       minute   {#2}
116       shapes   {
117            { shape {ClockCircle}  color {darkred}    }
118            { shape {ClockTicks}   color {middlegray} }
119          % { shape {ClockBullets} color {middlegray} }
120            { shape {ClockHour}    color {darkgreen}  }
121            { shape {ClockMinute}  color {darkblue}   }
122            { shape {ClockCenter}  color {middlegray} }
123       }
124     }%
125   \fi
126   \setalternate{\twodigits{#1}:\twodigits{#2}}% cut'n'paste in acrobat
127   \privatecharacter{CLOCK:#1:#2}%
128   \endgroup}
129
130\dorecurse{8}{
131    \begingroup
132        \glyphxscale \numexpr 1000+#100\relax
133        \glyphyscale \glyphxscale
134        \veryraggedright
135        \dostepwiserecurse{0}{60}{1}{
136            \MyClock{3}{##1}\hskip\zeropoint plus \onepoint\allowbreak% space
137        }
138        \blank
139    \endgroup
140}
141\stoptext
142