summaryrefslogtreecommitdiff
path: root/metapost/context/base/mpiv/mp-crop.mpiv
blob: 00bcdcb4454e3dd54c2f2399ab0d8e68c5535d0d (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
%D \module
%D   [       file=mp-crop.mpiv,
%D        version=2011.06.23,
%D          title=\CONTEXT\ \METAPOST\ graphics,
%D       subtitle=Cropmarks,
%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.

if known context_crop : endinput ; fi ;

boolean context_crop ; context_crop := true ;

vardef crop_marks_lines (expr box, len, offset, nx, ny) =
    save p ; picture p ; save w, h, x, y ; numeric w, h, x, y ;
    p := image (
        x := if nx = 0 : 1 else : nx - 1 fi ;
        y := if ny = 0 : 1 else : ny - 1 fi ;
        w := bbwidth (box) / x ;
        h := bbheight(box) / y ;
        for i=0 upto y :
            draw ((llcorner box) -- (llcorner box) shifted (-len,0)) shifted (-offset,i*h) ;
            draw ((lrcorner box) -- (lrcorner box) shifted ( len,0)) shifted ( offset,i*h) ;
        endfor ;
        for i=0 upto x :
            draw ((llcorner box) -- (llcorner box) shifted (0,-len)) shifted (i*w,-offset) ;
            draw ((ulcorner box) -- (ulcorner box) shifted (0, len)) shifted (i*w, offset) ;
        endfor ;
    ) ;
    setbounds p to box ;
    p
enddef ;

vardef crop_marks_cmyk =
    save p ; picture p ; p := image (
        fill ulcircle   scaled 12.5 withcolor (1,0,0,0) ;
        fill urcircle   scaled 12.5 withcolor (0,1,0,0) ;
        fill lrcircle   scaled 12.5 withcolor (0,0,1,0) ;
        fill llcircle   scaled 12.5 withcolor (0,0,0,1) ;
        draw (-10,0) -- (10,0) ;
        draw (0,-10) -- (0,10) ;
        draw fullcircle scaled 12.5 ;
    ) ;
    setbounds p to fullsquare scaled 20 ;
    p
enddef ;

vardef crop_marks_gray =
    save p ; picture p ; p := image (
        fill ulcircle   scaled 12.5 withcolor (0.00) ;
        fill urcircle   scaled 12.5 withcolor (0.25) ;
        fill lrcircle   scaled 12.5 withcolor (0.50) ;
        fill llcircle   scaled 12.5 withcolor (0.75) ;
        draw (-10,0) -- (10,0) ;
        draw (0,-10) -- (0,10) ;
        draw (-6,0) -- (6,0) withcolor white ;
        draw (0,-6) -- (0,6) withcolor white  ;
        draw fullcircle scaled 12.5 ;
    ) ;
    setbounds p to fullsquare scaled 20 ;
    p
enddef ;

vardef crop_marks_cmykrgb =
    save p ; picture p ; p := image (
        fill ulcircle   scaled 15 withcolor (1,0,0) ;
        fill urcircle   scaled 15 withcolor (0,1,0) ;
        fill lrcircle   scaled 15 withcolor (0,0,1) ;
        fill llcircle   scaled 15 withcolor (.5,.5,.5) ;
        fill ulcircle   scaled 10 withcolor (1,0,0,0) ;
        fill urcircle   scaled 10 withcolor (0,1,0,0) ;
        fill lrcircle   scaled 10 withcolor (0,0,1,0) ;
        fill llcircle   scaled 10 withcolor (0,0,0,1) ;
        draw (-10,0) -- (10,0) ;
        draw (0,-10) -- (0,10) ;
        draw fullcircle scaled 10 ;
        draw fullcircle scaled 15 ;
    ) ;
    setbounds p to fullsquare scaled 20 ;
    p
enddef ;

vardef crop_color(expr c, h, w, dx, dy, ts) =
    image (
        save p ; path p ;
        for i=1 upto 6 :
            p := fullsquare
                xscaled w
                yscaled h
                shifted (dx,dy-i*h) ;
            fill p
                withcolor (crop_colors[i]*c) ;
            draw textext("\format{'@0.2f'," & decimal crop_colors[i] & "}")
                scaled ts
                shifted center p withcolor white ;
        endfor ;
    )
enddef ;

vardef crop_gray(expr c, h, w, dx, dy, ts) =
    image (
        save p ; path p ;
        for i=.05 step .05 until 1 :
            p := fullsquare
                xscaled w
                yscaled h
                shifted (20*(i-1)*w+dx,dy) ;
            fill p
                withcolor (i*c) ;
            draw textext("\format{'@0.2f'," & decimal i & "}")
                scaled ts
                shifted center p withcolor white ;
        endfor ;
    )
enddef ;

% draw crop_marks_cmyk shifted llcorner more ;
% draw crop_marks_cmyk shifted lrcorner more ;
% draw crop_marks_cmyk shifted ulcorner more ;
% draw crop_marks_cmyk shifted urcorner more ;

def page_marks_add_color(expr width, height, length, offset) = % todo: namespace

    path page ; page := fullsquare xscaled width yscaled height ;
    path more ; more := page enlarged (offset+length/2,offset+length/2) ;

    numeric crop_colors[] ;
    crop_colors[1] := 1 ;
    crop_colors[2] := 0.95 ;
    crop_colors[3] := 0.75 ;
    crop_colors[4] := 0.50 ;
    crop_colors[5] := 0.25 ;
    crop_colors[6] := 0.05 ;

    numeric h ; h := height / 20 ;
    numeric w ; w := width  / 20 ;
    numeric d ; d := offset + length/2 ;

    draw crop_color((1,0,0,0),h,length,xpart ulcorner page - d, 10h,length/20) ;
    draw crop_color((0,1,0,0),h,length,xpart ulcorner page - d,3.5h,length/20) ;
    draw crop_color((0,0,1,0),h,length,xpart ulcorner page - d, -3h,length/20) ;

    draw crop_color((0,1,1,0),h,length,xpart urcorner page + d, 10h,length/20) ;
    draw crop_color((1,0,1,0),h,length,xpart urcorner page + d,3.5h,length/20) ;
    draw crop_color((1,1,0,0),h,length,xpart urcorner page + d, -3h,length/20) ;

    draw crop_gray((0,0,0,1),length,  w,-xpart llcorner page,-ypart llcorner page + d            ,w/20) ;
    draw crop_gray((1,0,0,0),length/3,w,-xpart llcorner page, ypart llcorner page - d + 1length/3,w/20) ;
    draw crop_gray((0,1,0,0),length/3,w,-xpart llcorner page, ypart llcorner page - d - 0length/3,w/20) ;
    draw crop_gray((0,0,1,0),length/3,w,-xpart llcorner page, ypart llcorner page - d - 1length/3,w/20) ;

    setbounds currentpicture to page ;

enddef ;

def page_marks_add_marking(expr width, height, length, offset) = % todo: namespace

    path page ; page := fullsquare xscaled width yscaled height ;
    path more ; more := page enlarged (offset+length/2,offset+length/2) ;

    draw crop_marks_gray shifted center(topboundary    more) shifted (0, offset+length);
    draw crop_marks_cmyk shifted center(bottomboundary more) shifted (0,-offset-length);

    setbounds currentpicture to page ;

enddef ;

def page_marks_add_lines(expr width, height, length, offset, nx, ny) = % todo: namespace

    path page ; page := fullsquare xscaled width yscaled height ;
    path more ; more := page enlarged (offset+length/2,offset+length/2) ;

    draw crop_marks_lines(page,length,offset,nx,ny) ;

    setbounds currentpicture to page ;

enddef ;

def page_marks_add_number(expr width, height, length, offset, n) = % todo: namespace

    path page ; page := fullsquare xscaled width yscaled height ;
    path more ; more := page enlarged (offset+length/2,offset+length/2) ;

    for s=llcorner more, lrcorner more, ulcorner more, urcorner more :
        draw textext(decimal n) shifted s ;
    endfor ;

    setbounds currentpicture to page ;

enddef ;