Debian Codegraph @

texmf-dist/fonts/source/public/bartel-chess-fonts/pkbase.mf

raw
1 % This is
2 % pkbase.mf
3 %
4 % Copyright (C) 1989-92 by Elmar Bartel.
5 %
6 % This program is free software; you can redistribute it and/or modify
7 % it under the terms of the GNU General Public License as published by
8 % the Free Software Foundation; either version 1, or (at your option)
9 % any later version.
10 %
11 % This program is distributed in the hope that it will be useful,
12 % but WITHOUT ANY WARRANTY; without even the implied warranty of
13 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 % GNU General Public License for more details.
15 %
16 % You should have received a copy of the GNU General Public License
17 % along with this program; if not, write to the Free Software
18 % Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 %
20 % correcting the size of qs to make it a good pixelcount
21 if .5qs <> good.x .5qs:
22 qs:= qs if qs# * hppp > round(qs): + else: - fi 1;
23 fi
24
25 % the center of the field
26 pair Center; Center = (qs/2,qs/2);
27
28 picture BlackMan, WhiteMan, NeutralMan, OuterShape;
29
30 % Some definitions for numbering the characters
31 %
32 % Numbers of the pieces
33 Pawn = 0; Knight = 1; Bishop = 2; Rook = 3; Queen = 4; King = 5;
34 % Geometric pieces
35 Circle = 145;
36 % Offsets for colors of the pieces
37 White = 0; Neutral = 6; Black = 12;
38 % Offsets for the background
39 OnWhite = 0; OnBlack = 18;
40 % Offsets for the turning
41 LeftTurned = 36; RightTurned = 72; UpSideDown = 108;
42
43 % Makros for turning
44 def TurnLeft(expr p) =
45 p rotatedaround (Center,90);
46 enddef;
47
48 def TurnRight(expr p) =
49 p rotatedaround (Center,-90);
50 enddef;
51
52 def TurnUpSideDown(expr p) =
53 p rotatedaround (Center,180);
54 enddef;
55
56 %
57 % Macros for shorten and lengthening paths
58 %
59 % ShortenPath: The given path is shorted at both ends, with the
60 % real amount of pixels given
61 % ShortenBegin, ShortenEnd: The same as above for one end only
62 % LengthenPath: The path is elongated at both ends with a straight
63 % line, in the direction of the path at the end
64 % LengthenBegin, LengthenEnd: The same as above for one end only
65 %
66 def Perpend(expr d,p,real) =
67 begingroup
68 save dd; pair dd;
69 dd = d/length(d);
70 (p+100*(dd rotated 90) -- p+100*(dd rotated -90)) shifted (dd*real)
71 endgroup;
72 enddef;
73 def ShortenPath(expr p,real) =
74 begingroup
75 save pa,pe; path pa,pe;
76 pa = Perpend(direction 0 of p,point 0 of p,real);
77 pe = Perpend(-direction length(p) of p,point length(p) of p,real);
78 subpath (
79 xpart(p intersectiontimes pa),
80 xpart(p intersectiontimes pe)) of p
81 endgroup
82 enddef;
83 def ShortenBegin(expr p,real) =
84 begingroup
85 save pa; path pa;
86 pa = Perpend(direction 0 of p,point 0 of p,real);
87 subpath (xpart(p intersectiontimes pa),length(p)) of p
88 endgroup
89 enddef;
90 def ShortenEnd(expr p,real) =
91 begingroup
92 save pe; path pe;
93 pe = Perpend(-direction length(p) of p,point length(p) of p,real);
94 subpath (0, xpart(p intersectiontimes pe)) of p
95 endgroup
96 enddef;
97 def LengthenBegin(expr p,real) =
98 begingroup
99 save dd; pair dd;
100 dd= direction 0 of p; dd:= dd/length(dd);
101 point 0 of p - real*dd -- p
102 endgroup
103 enddef;
104 def LengthenEnd(expr p,real) =
105 begingroup
106 save dd; pair dd;
107 dd= direction length(p) of p; dd:= dd/length(dd);
108 p -- point length(p) of p + real*dd
109 endgroup
110 enddef;
111 def Lengthen(expr p,real) =
112 begingroup
113 save db; pair db;
114 save de; pair de;
115 db= direction 0 of p; db:= db/length(db);
116 de= direction length(p) of p; de:= de/length(de);
117 point 0 of p - real*db -- p -- point length(p) of p + real*de
118 endgroup
119 enddef;
120 %
121 % This macro is used bye ParallelPath
122 %
123 def NewPoint(expr p,t,dist) =
124 { begingroup pair Dir;
125 Dir= direction t of p; %show p; show t; show Dir;
126 Dir
127 endgroup }
128 (point t of p + (Dir rotated 90)*(dist/length(Dir)))
129 enddef;
130
131 % Macro for getting a path parallel to the given path, in distance dist
132 %
133 def ParallelPath(expr p,dist) =
134 begingroup
135 save Dir; pair Dir; Dir = direction 0 of p;
136
137 ((point 0 of p)+(Dir rotated 90)*(dist/length(Dir))) {Dir}
138 for t=.5 step .5 until length(p):
139 .. NewPoint(p,t,dist)
140 endfor
141 endgroup
142 enddef;
143
144 def DefineFootBows(
145 % This macro depends on the values of qs and BottomSpace
146 % and uses the makro ParallelPath.
147 % It is used to generate the bottom bows of King, Queen and Bishop
148 expr BottomDist, %This is the space to BottomSpace
149 BowOneWidth, %This is the width of the main bow
150 FootHeight, %Distance from bottom of Bow0 to top of Bow3
151 BowTwoLoc, %Relative location of Bow2 between Bow3 and
152 % Bow1. 0 means position at position at Bow1,
153 % 1.0 means position at Bow3.
154 WidthToHeight, %Ratio of BowOneWidth/2 to Bowheight
155 BowTwoLen, %Length of Bow2 relative to Bow1
156 BowThreeLen %Lenght of Bow3 relative to Bow1
157 ) =
158
159 % All parameters are in pixels when not otherwise statet.
160 % Points are numbered from 0 to 3 from lower to upper
161 % Points to the left have suffix l, right suffix r
162 % points without further suffix are in the center of the bows
163
164 path Bow[];
165 numeric BowHeight;
166 numeric l[],x[]l,x[]r,x[],y[]l,y[]r,y[];
167
168 BowHeight = BowOneWidth*WidthToHeight/2;
169
170 % We start with the first bow
171 x1r + x1l = qs; x1r - x1l = BowOneWidth;
172 y1 = BottomSpace + 2*BowHeight + BottomDist;
173 x1 = .5qs;
174 y1l = y1r = y1 - BowHeight;
175 Bow1 = z1l .. {right} z1 .. z1r;
176
177 z0 = z1 shifted (down*2*BowHeight);
178 Bow0 = z1r .. {left} z0 .. z1l;
179
180 Bow3= ParallelPath(Bow1,FootHeight-2*BowHeight);
181 l3 = length(Bow3);
182 cu:= (1-BowThreeLen)/2;
183 Bow3:= subpath (cu*l3,(1-cu)*l3) of Bow3;
184 z3l = point 0 of Bow3;
185 z3 = point .5*length(Bow3) of Bow3;
186 z3r = point infinity of Bow3;
187
188 %show point 0 of reverse Bow3;
189 %show z3r;
190
191 Bow2= ParallelPath(Bow1,(FootHeight-2*BowHeight)*BowTwoLoc);
192 l2 = length(Bow2);
193 cu:= (1-BowTwoLen)/2;
194 Bow2:= subpath (cu*l2,(1-cu)*l2) of Bow2;
195 z2l = point 0 of Bow2;
196 z2 = point .5length(Bow3) of Bow2;
197 z2r = point infinity of Bow2;
198 labels(1l,1,1r,2l,2r,3l,3r);
199 enddef;
200 %
201 % Macro for generation the neutral piece from two pictures
202 % given as Parameter
203 def MakeNeutral(expr White,Black) =
204 if unknown LeftHalft: picture LeftHalf; fi
205 LeftHalf:= Black;
206 cull LeftHalf keeping (1,infinity);
207 addto LeftHalf contour (unitsquare yscaled qs xscaled (qs/2));
208 cull LeftHalf keeping (2,2);
209
210 if unknown RightHalf: picture RightHalf; fi
211 RightHalf:= White;
212 cull RightHalf keeping (1,infinity);
213 addto RightHalf contour (unitsquare yscaled qs xscaled (qs/2) shifted (qs/2,0));
214 cull RightHalf keeping (2,2);
215 NeutralMan:= LeftHalf;
216 addto NeutralMan also RightHalf;
217 enddef;
218 %
219 % Makro to get a grid of real output pixels when proofing
220 def PixelGrid(expr PixPerInch, w) =
221 if proofing > 0:
222 begingroup
223 numeric d;
224 d = pixels_per_inch/PixPerInch;
225 makegrid(0,for i=d step d until w: ,i endfor)(0,for i=d step d until w: ,i endfor)
226 endgroup;
227 fi;
228 enddef;