summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkxl/meta-imp-clock.mkxl
blob: 0612113ea4276dfb1ff3d5d813e98adfd72683cd (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
%D \module
%D   [       file=meta-imp-clock,
%D        version=2021.01.21,
%D          title=\METAPOST\ Graphics,
%D       subtitle=Demo Clock 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. A crazy examples made in crazy times.

\startMPcalculation{simplefun}

    % the 0 in getparameterdefault makes sure we convert to a number

    picture DemoClocks[];

    vardef ClockCircle =
        image(draw fullcircle scaled 10 ;)
    enddef ;

    vardef ClockPoints =
        image (
            for i=1 upto 12 :
                draw (0,5) rotated ((360 * i) / 12) withpen pencircle scaled 1 ;
            endfor ;
        )
    enddef ;

    vardef ClockTicks =
        image (
            for i=1 upto 12 :
                draw ((0,4.5)--(0,5.5)) rotated ((360 * i) / 12) ;
            endfor ;
        )
    enddef ;

    vardef ClockCenter =
        image (
            draw origin withpen pencircle scaled 1 ;
        )
    enddef ;

    vardef ClockHour =
        image(
            draw (origin -- (0,4)) rotated (
              - 360 * (getparameterdefault "mpsfont" "hour"   0) / 12
              - 360 * (getparameterdefault "mpsfont" "minute" 0) / (60 * 12)

        ) )
    enddef ;

    vardef ClockMinute =
        image(
            draw (origin -- (0,5)) rotated (
              - 360 * (getparameterdefault "mpsfont" "minute" 0) / 60
            )
        )
    enddef ;

    vardef DemoClock =
        composeglyph(DemoClocks) ;
    enddef ;

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

    lmt_registerglyph [
        category = "clock",
    ] ;

\stopMPcalculation

% \startluacode
%     metapost.metafonts.clock = { }
% \stopluacode

\continueifinputfile{meta-imp-clock.mkxl}

% \enableexperiments[fonts.compact]

\nopdfcompression

\setuplayout[tight]

\setupbodyfont[dejavu]

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

\definefont[ClockFont][Serif*clock]

\starttext

\unexpanded\def\MyClock#1#2%
  {\begingroup
   \ClockFont
   \iffontchar\font\privatecharactercode{CLOCK:#1:#2}\else
     % We could move this out to a helper \MyClockMake{#1}{#2} but normally
     % it's efficient enough. (If we trace a lot it matters more.)
     \setmetaglyph {
       category {clock}
       name     {CLOCK:#1:#2}
       code     {DemoClock}
       hour     {#1}
       minute   {#2}
       shapes   {
            { shape {ClockCircle}  color {darkred}    }
            { shape {ClockTicks}   color {middlegray} }
          % { shape {ClockBullets} color {middlegray} }
            { shape {ClockHour}    color {darkgreen}  }
            { shape {ClockMinute}  color {darkblue}   }
            { shape {ClockCenter}  color {middlegray} }
       }
     }%
   \fi
   \setalternate{\twodigits{#1}:\twodigits{#2}}% cut'n'paste in acrobat
   \privatecharacter{CLOCK:#1:#2}%
   \endgroup}

\dorecurse{8}{
    \begingroup
        \glyphxscale \numexpr 1000+#100\relax
        \glyphyscale \glyphxscale
        \veryraggedright
        \dostepwiserecurse{0}{60}{1}{
            \MyClock{3}{##1}\hskip\zeropoint plus \onepoint\allowbreak% space
        }
        \blank
    \endgroup
}
\stoptext