summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/meta-grd.mkiv
blob: da410ba689de40c020369f6cb494ab1aa51980f5 (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
%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}

%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{grid}{nx,ny,dx,dy,factor,scale,xstep,ystep,xoffset,yoffset,align}
    begingroup ;

        save nx, ny, dx, dy, wd, ht, xstep, ystep, xoffset, yoffset, align, xalign, yalign ;

        numeric nx      ; nx      := \MPvar{nx} ;
        numeric ny      ; ny      := \MPvar{ny} ;
        numeric dx      ; dx      := \MPvar{factor} * \MPvar{scale} * \MPvar{dx} ;
        numeric dy      ; dy      := \MPvar{factor} * \MPvar{scale} * \MPvar{dy} ;
        numeric wd      ; wd      := nx * dx ;
        numeric ht      ; ht      := ny * dy ;
        numeric xstep   ; xstep   := \MPvar{xstep} ;
        numeric ystep   ; ystep   := \MPvar{ystep} ;
        numeric xoffset ; xoffset := \MPvar{xoffset} ;
        numeric yoffset ; yoffset := \MPvar{yoffset} ;
        numeric align   ; align   := \MPvar{align} ;
        numeric xalign  ; xalign  := 0 ;
        numeric yalign  ; yalign  := 0 ;

        if align = 1 :
            xalign := dx/2 ;
            yalign := dy/2 ;
        fi ;

        for i=0 step dx until wd :
            draw (i,0) -- (i,ht) ;
        endfor ;
        for i=0 step dy until ht :
            draw (0,i) -- (wd,i) ;
        endfor ;

        if xstep > 0 :
            for i=1 step xstep until nx :
                draw thetextext.bot(decimal i,(i*dx-xalign,-xoffset)) ;
            endfor ;
        fi ;
        if ystep > 0 :
            for i=1 step ystep until ny :
                draw thetextext.lft(decimal i,(-yoffset,i*dy-yalign)) ;
            endfor ;
        fi ;

    endgroup ;
\stopuseMPgraphic

\unprotect

\unexpanded\def\basegrid
  {\dosingleempty\typo_grid_base}

\def\typo_grid_base[#1]%
  {\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=.25ex,\c!xoffset=\directdummyparameter\c!offset,\c!yoffset=\directdummyparameter\c!offset,
      \c!align=,
      #1]%
   \usedummystyleandcolor\c!style\c!color
   \edef\p_align{\directdummyparameter\c!align}%
   \ifx\p_align\v!middle
      \let\p_align\!!plusone
   \else
      \let\p_align\!!zerocount
   \fi
   \useMPgraphic
    {grid}%
    {nx=\directdummyparameter\c!nx,%
     ny=\directdummyparameter\c!ny,%
     dx=\directdummyparameter\c!dx\directdummyparameter\c!unit,%
     dy=\directdummyparameter\c!dy\directdummyparameter\c!unit,%
     factor=\directdummyparameter\c!factor,%
     scale=\directdummyparameter\c!scale,%
     xstep=\directdummyparameter\c!xstep,%
     ystep=\directdummyparameter\c!ystep,%
     xoffset=\directdummyparameter\c!xoffset,%
     yoffset=\directdummyparameter\c!yoffset,%
     align=\p_align}%
  \egroup}

\let\grid\basegrid

\protect \endinput