Debian Codegraph @

texmf-dist/metapost/bbcard/calendar.mp

raw
1 %% One-page calendar
2 %% Patrick TJ McPhee, 1997
3 %% you are permitted to modify or distribute this file
4 %% any way you like, but please indicate modifications
5 %%
6 %% Instructions: if you run this file through metafont, it will produce a
7 %% one-month calendar for next month, suitable for printing on US letter-size
8 %% paper. You can set two parameters, theyear affects the year for which the
9 %% calendar will be printed, and themonth affects the month. The valid
10 %% range for theyear is 1997 to some year well off in the future, and the
11 %% valid range for themonth is -1 to 12. If themonth is set to -1, calendars
12 %% will be printed for every month in the year. If themonth is set to 0,
13 %% a calendar will be printed for the following month.
14 %% The ouput file for each month is calendar.<themonth>. e.g., the
15 %% file for April would be calendar.4.
16
17 %% fonts used to put up numbers, days of the week and holidays
18 string brandfont;
19 brandfont := "pplr8r";
20 defaultfont:="pplr8r";
21 defaultscale := 2;
22 prologues:=1;
23
24 %% list of holidays. The first element of the array is the month, and the
25 %% second is the day of the month
26 string brands[][];
27
28 brands[12][25] := "Christmas";
29 brands[1][1] = "Hogmany";
30 brands[1][25] = "Robbie Burns";
31 brands[2][14] = "Valentine";
32 brands[11][11] = "Remembrance";
33 brands[11][1] = "All Saints";
34 brands[11][2] = "All Souls";
35 brands[7][1] = "Canada Day";
36
37 %% days of the week
38 string weekdays[];
39 weekdays[1] = "Sunday";
40 weekdays[2] = "Monday";
41 weekdays[3] = "Tuesday";
42 weekdays[4] = "Wednesday";
43 weekdays[5] = "Thursday";
44 weekdays[6] = "Friday";
45 weekdays[7] = "Saturday";
46
47 %% names of the months
48 string mnames[];
49
50 mnames[1] = "January";
51 mnames[2] = "February";
52 mnames[3] = "March";
53 mnames[4] = "April";
54 mnames[5] = "May";
55 mnames[6] = "June";
56 mnames[7] = "July";
57 mnames[8] = "August";
58 mnames[9] = "September";
59 mnames[10] = "October";
60 mnames[11] = "November";
61 mnames[12] = "December";
62
63 %% I don't think anything needs to change below this point to support
64 %% other languages or other anticipated modifications
65
66 % the same as `label', but specify the size
67 vardef alabel@#(expr s,z,sz) = % Position s near z size sz
68 save p; picture p;
69 if picture s: p=s
70 else: p = s infont brandfont scaled sz
71 fi;
72 p shifted (z + labeloffset*laboff@# -
73 (labxf@#*lrcorner p + labyf@#*ulcorner p
74 + (1-labxf@#-labyf@#)*llcorner p
75 )
76 )
77 enddef;
78
79 def brand = draw alabel enddef;
80
81 hoff:=.5in;
82 voff:= hoff;
83
84 width:= 10in;
85 height := 7.5in;
86 margin := .05in;
87 daynameh := .5 in;
88
89 daywidth := (width - 2margin)/7;
90 dayheight := (height - 2margin - daynameh)/5;
91
92 picture frame;
93
94 pickup pencircle scaled 2 pt yscaled .6 pt rotated 135;
95 % pickup penrazor scaled 2 pt rotated 135;
96 bot y1 = voff = bot y8 = top y4 - height = top y5 - height;
97 lft x2 = hoff = lft x3 = rt x6 - width = rt x7 - width;
98 x1 - x4 = 0 = y2 - y7 = y3 - y6 = x5 - x8;
99 x1 - x2 = hoff = y2 - y1 = y4 - y3 = x7 - x8;
100
101 % draw z1..z2---z3..z4---z5..z6---z7..z8---cycle;
102 draw (x3-.25hoff,y4+.25voff){dir(-45)}..z4---z5..z6---z7..{dir(-45)}(x7+.25hoff, .75voff)
103 {dir(135)}..z8---z1..z2---z3..{dir(135)}cycle;
104
105
106 pickup pencircle scaled .6 pt;
107 z1 - z9 = (margin, -margin) = z6 - z14 = z10 - z2 = z13 - z5;
108 z3 - z11 = (-margin, -margin) = z8 - z16 = z12 - z4 = z15 - z7;
109
110 draw z9..z10---z11..z12---z13..z14---z15..z16---cycle;
111
112 for i := 1 upto 6:
113 draw (x10+i*daywidth, y9)--(x10+i*daywidth, y12);
114 endfor;
115
116 for i := 1 upto 5:
117 draw (x10, y9+i*dayheight)--(x15, y9+i*dayheight);
118 endfor;
119
120 for i := 1 upto 7:
121 label(weekdays[i], (x10+(i-.5)*daywidth, y9+5daywidth+.2 daynameh));
122 endfor;
123
124 lftedge := x10;
125 rtedge := x15;
126 botedge := y9;
127
128 frame := currentpicture;
129
130 clearit;
131
132 mdays[1] = 31;
133 mdays[2] = 28;
134 mdays[3] = 31;
135 mdays[4] = 30;
136 mdays[5] = 31;
137 mdays[6] = 30;
138 mdays[7] = 31;
139 mdays[8] = 31;
140 mdays[9] = 30;
141 mdays[10] = 31;
142 mdays[11] = 30;
143 mdays[12] = 31;
144
145 def drawmonth (expr mon, startday) :=
146 beginfig(mon);
147 draw frame;
148
149 numhoff := lftedge + startday*daywidth;
150 numvoff := botedge + 5 * dayheight;
151
152 if startday > 1:
153 undraw (lftedge+daywidth, numvoff-.25 dayheight)..(lftedge+daywidth, numvoff-.75 dayheight);
154 brand (mnames[mon], (lftedge+daywidth,numvoff-.5 dayheight), 3);
155 brand (decimal theyear, (lftedge+daywidth,numvoff-.7 dayheight), 1);
156 fi;
157
158 for i := 1 upto mdays[mon]:
159 if numvoff > botedge:
160 label.lrt(decimal i, (numhoff, numvoff));
161 else:
162 label.ulft(decimal i, (numhoff+daywidth, numvoff));
163 fi;
164 numhoff := numhoff + daywidth;
165
166 if known brands[mon][i]: brand.llft(brands[mon][i], (numhoff,numvoff), 1); fi
167
168 if numhoff >= rtedge:
169 numhoff := lftedge;
170 numvoff := numvoff - dayheight;
171 fi
172 endfor;
173
174 if startday <= 1:
175 undraw (lftedge+6daywidth, numvoff-.25 dayheight)..(lftedge+6daywidth, numvoff-.75 dayheight);
176 brand (mnames[mon], (lftedge+6daywidth,numvoff-.5 dayheight), 3);
177 brand (decimal theyear, (lftedge+6daywidth,numvoff-.7 dayheight), 1);
178 fi;
179
180 currentpicture := currentpicture rotatedaround((4.25in,4.25in),90);
181 endfig;
182 enddef;
183
184 %% if no year is specified, try for the current year
185 if unknown theyear: theyear:=year;
186 elseif theyear=0: theyear:=year;
187 fi;
188 firstday := (3 + (theyear - 1997) + (theyear - 1997) div 4) mod 7;
189
190 %% if no month is specified, try for next month
191 if unknown themonth: themonth := month + 1;
192 elseif themonth=0: themonth := month + 1;
193 fi;
194 if themonth = 13:
195 theyear := theyear+1;
196 themonth := 1;
197 fi;
198
199 if ((theyear mod 4) = 0)
200 and (((theyear mod 100) <> 0) or ((theyear mod 400) = 0)):
201 mdays[2] := 29;
202 fi;
203
204 % special value of themonth: -1 prints the whole year's calendar
205 if themonth = -1:
206 for j = 1 upto 12:
207 drawmonth(j, firstday);
208 firstday := (firstday + mdays[j]) mod 7;
209 endfor;
210 else:
211 for j = 1 upto (themonth-1):
212 firstday := (firstday + mdays[j]) mod 7;
213 endfor;
214 drawmonth(themonth, firstday);
215 fi
216 end;