summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/meta-grd.mkxl
blob: 99db410c6ccbd962dc4d80010f9e2fcafe20b520 (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
%D \module
%D   [       file=meta-grd,
%D        version=2012.06.28,
%D          title=\METAPOST\ Graphics,
%D       subtitle=grids,
%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.

\writestatus{loading}{MetaPost Graphics / Grids}

\unprotect

%D This used to be a \TEX\ method, and a rather old one too. We keep it around but
%D in a more modern way.
%D
%D \startbuffer
%D \basegrid
%D   [nx=8,ny=5,
%D    dx=.5,dy=.25,
%D    unit=cm,scale=2,factor=1,
%D    offset=1ex,xstep=2,ystep=1,
%D    align=middle,style=\tt\tx]
%D \stopbuffer
%D
%D \typebuffer
%D
%D \placefigure
%D   {An example of a grid.}
%D   {\getbuffer}

\startuseMPgraphic{meta:grd:basegrid}
    begingroup ;

        save nx, ny, dx, dy, ox, oy, sx, sy ;

        sc := \directdummyparameter\c!factor*\directdummyparameter\c!scale ;
        nx := \directdummyparameter\c!nx ;
        ny := \directdummyparameter\c!ny ;
        dx := \MPdpar\directdummyparameter\c!dx * sc ;
        dy := \MPdpar\directdummyparameter\c!dy * sc ;
        ox := \MPdpar\directdummyparameter\c!xoffset ;
        oy := \MPdpar\directdummyparameter\c!yoffset ;
        sx := \directdummyparameter\c!xstep ;
        sy := \directdummyparameter\c!ystep ;

        if "\directdummyparameter\c!align" = "\v!middle" :
            ax := dx / 2 ;
            ay := dy / 2 ;
        else :
            ax := 0 ;
            ay := 0 ;
        fi ;

        draw lmt_grid [ nx = nx, ny = ny, dx = 1, dy = 1 ]
            xyscaled (dx,dy) shifted (ax, ay)
            withpen pencircle scaled \MPdpar\directdummyparameter\c!rulethickness\space
            withcolor "\directdummyparameter\c!rulecolor" ;

        draw image (
            if sx > 0 :
                for i=1 step sx until nx :
                    draw thetextext.bot(decimal i,(i*dx-ax,oy));
                endfor ;
            fi ;
            if sy > 0 :
                for i=1 step sy until ny :
                    draw thetextext.lft(decimal i,(ox,i*dy-ay)) ;
                endfor ;
            fi ;
        )
            withcolor "\directdummyparameter\c!color" ;

    endgroup ;
\stopuseMPgraphic

\permanent\tolerant\protected\def\basegrid[#1]%
  {\dontleavehmode
   \hbox\bgroup
   \getdummyparameters
     [\c!nx=10,\c!ny=10,%
      \c!dx=.5,\c!dy=.5,%
      \c!xstep=0,\c!ystep=0,%
      \c!unit=\s!cm,\c!scale=1,\c!factor=1,%
      \c!offset=.25\exheight,%
      \c!xoffset=\directdummyparameter\c!offset,%
      \c!yoffset=\directdummyparameter\c!offset,%
      \c!align=,%
      \c!color=\currentcolorname,%
      \c!rulecolor=\currentcolorname,%
      \c!rulethickness=\linewidth,%
      #1]%
   \usedummystyleandcolor\c!style\c!color
   \setexpandeddummyparameter\c!dx{\directdummyparameter\c!dx\directdummyparameter\c!unit}%
   \setexpandeddummyparameter\c!dy{\directdummyparameter\c!dy\directdummyparameter\c!unit}%
   \useMPgraphic{meta:grd:basegrid}%
   \egroup}

\aliased\let\grid\basegrid

\protect \endinput