summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/fonts/source/public/knitting/knit_symbols.mf
blob: e0fb61c80af1e571c87ca8f85d9a2b2d7d138b85 (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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
% Date: 2019/04/05

% Don't flash pictures of the characters as you draw them.
% This is dizzying, and UNIX can't do it anyway.
displaying := 0;

% If you want actual documentation, say 
% "mf knitnn" and then
% "gftodvi knitnn.2602gf" and then
% "dvipdfm knitnn"
% at a command prompt in the directory containing this file.
% This will give you a PDF with big pictures of all the characters in 
% the font with the important points labeled.

if known ps_output:
	font_coding_scheme := "T1-WGL4.enc";
fi

def purlfill = 
	if fonttype = purltype:
	fill 
	( -purlextend,-d-purlextend)--
	(w+purlextend,-d-purlextend)--
	(w+purlextend, h+purlextend)--
	( -purlextend, h+purlextend)--cycle;
	fi
enddef;

purltype = 0;
gridtype = 1;
foretype = 2;
bothtype = 3; % Both the grid and the symbols
counttype = 4;

if fonttype = counttype:
	% extra_endchar := extra_endchar & " pickup pencircle scaled 0.2pt; if w>0: draw (0,-d)--(0,h); draw (w,-d)--(w,h); fi ";
fi

def nogrid_charbox =
  if (fonttype = purltype) or (fonttype = gridtype):
  	currentpicture := nullpicture;
  fi
  enddef;
  
def leftgrid_charbox = 
  if (fonttype = purltype): currentpicture := nullpicture; fi
  if (fonttype = gridtype): currentpicture := nullpicture; fi
  if (fonttype = gridtype) or (fonttype = bothtype):
  	pickup pensquare scaled gridwidth;  
  	draw lft (w,h)--(0,h);
  	draw (0,h)--(0,-d);
  	draw (0,-d)--lft (w,-d);
  fi
enddef;

def rightgrid_charbox = 
  if (fonttype = purltype): currentpicture := nullpicture; fi
  if (fonttype = gridtype): currentpicture := nullpicture; fi
  if (fonttype = gridtype) or (fonttype = bothtype):
  	pickup pensquare scaled gridwidth;  
  	draw (w,h)--rt (0,h);
  	draw (w,h)--(w,-d);
  	draw rt (0,-d)--(w,-d);
  fi
enddef;

def topbotgrid_charbox = 
  if (fonttype = purltype): currentpicture := nullpicture; fi
  if (fonttype = gridtype): currentpicture := nullpicture; fi
  if (fonttype = gridtype) or (fonttype = bothtype):
  	pickup pensquare scaled gridwidth;  
  	draw (w,h)--(0,h);
  	draw (0,-d)--(w,-d);
  fi
enddef;

if gridfont:
def charbox =
	if fonttype = purltype:
		currentpicture := nullpicture;
	fi
	if fonttype = gridtype: currentpicture := nullpicture; fi
	if (fonttype = gridtype) or (fonttype = bothtype):
		pickup pencircle scaled gridwidth;
		fill (-gridwidth/2,-d-gridwidth/2)--(w+gridwidth/2,-d-gridwidth/2)--
			(w+gridwidth/2,h+gridwidth/2)--(-gridwidth/2,h+gridwidth/2)--cycle;
		if (w>0):
			unfill (gridwidth/2,-d+gridwidth/2)--(w-gridwidth/2,-d+gridwidth/2)--
		 	(w-gridwidth/2,h-gridwidth/2)--(gridwidth/2,h-gridwidth/2)--cycle;
		fi
	  fi
 enddef; 
else:
def charbox = nogrid_charbox enddef;
fi

def purlbox = charbox; purlfill; enddef;

% We don't need any symbols in the counting fonts because we will never
% actually show them and clearing them saves a bit of disk space.
if fonttype = counttype:
	def charbox = currentpicture := nullpicture; enddef;
	def purlbox = currentpicture := nullpicture; enddef;
fi

  picture symbolpic[];    
  path symbolpath[];

def fliphoriz(text beginning, ending) =
  ending := (beginning) reflectedabout ((.5w,0),(.5w,h));
  enddef;
def flipvert(text beginning, ending) =
  ending := (beginning) reflectedabout ((0,(h-d)/2),(w,(h-d)/2));
  ending := (ending) shifted (0,bottomgap-topgap);
  enddef;
  
pair arrowpoint;

def definearrow(text thepath, arrowlength, endpath) =
  
  arrowpoint := point infinity of thepath;  
  arrowdir := angle(direction infinity of thepath);
  endpath := arrowpoint + ((1,0) rotated (arrowdir+150) scaled arrowlength)
             --arrowpoint + ((1,0) rotated arrowdir scaled 0.5symbolwidth)
             --arrowpoint + ((1,0) rotated (arrowdir-150) scaled arrowlength)
             ; 
  enddef;

% Error symbols (glyphs that should not happen)

if known debugcables: else: boolean debugcables; debugcables = true; fi

picture errorsymbol[];
for k=1,2,3:
	errorsymbol[k] = nullpicture;
endfor
if debugcables:
	errorslashes = 4;
	if (fonttype=foretype) or (fonttype=bothtype):
		for j=1,2,3:
			for k=(1/errorslashes) step (1/errorslashes) until 0.99:
				addto errorsymbol[j] doublepath ((0,k[-dp,ht])--(k[wd,0],.001pt+ht)) withpen (pencircle scaled symbolwidth);
				addto errorsymbol[j] doublepath ((j*wd,k[-dp,ht])--(k[j*wd,(j-1)*wd],.001pt-dp)) withpen (pencircle scaled symbolwidth);
			endfor
			for k=0 step (1/errorslashes) until (j-1):
				addto errorsymbol[j] doublepath ((k*wd,-dp)--((k+1)*wd,ht)) withpen (pencircle scaled symbolwidth);
			endfor
		endfor
	fi
fi

% Arrow symbols
  
beginchar("s",wd#,ht#,dp#); "Slip one left"; 
  pickup symbol_pen;
  y1 = y2 = (h-d)/2-offset; 
  0.5[x1,x2]=w/2;
  rt x2 - lft x1 = ht+dp-2*smallgap;
  symbolpath0 := z1--z2;
  definearrow(symbolpath0)((x2-x1)/3)(symbolpath1);
  draw symbolpath0;
  draw symbolpath1;
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  charbox; endchar;
  
beginchar("S",wd#,ht#,dp#); "Slip one right";  
	fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  charbox; endchar;
  
beginchar("[",wd#,ht#,dp#); "Slip one left knitwise"; 
  pickup symbol_pen;
  y1 = y2 = (h-d)/2-offset; 
  0.5[x1,x2]=w/2;
  rt x2 - lft x1 = ht+dp-2*0.3[smallgap,mingap];
  symbolpath0 := z1--z2;
  definearrow(symbolpath0)((x2-x1)/3)(symbolpath1);
  draw symbolpath0;
  draw symbolpath1;
  0.5[y3,y4] = y1;
  0.5[x3,x4] = 0.5[lft x1, lft xpart point 0 of symbolpath1];
  z4 = z3+whatever*(1,2);
  y4-y3 = 1.5 ypart (point 2 of symbolpath1 - point 0 of symbolpath1);
  draw z3--z4;
  labels(1,2,3,4);
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  charbox; endchar;

beginchar("]",wd#,ht#,dp#); "Slip one right knitwise";  
	fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
	flipvert(currentpicture)(currentpicture);
  charbox; endchar;
  

beginchar("h",decrwidth(1,0),ht#,dp#); "Drop stitch"; 
  pickup symbol_pen;
  y1 = bot h-small_topgap;
  y2 = top -d+small_bottomgap;
  x1 = x2 =w/2;
  symbolpath0 := z1--z2;
  definearrow(symbolpath0)((y1-y2)/3)(symbolpath1);
  draw symbolpath0;
  draw symbolpath1;
  charbox; endchar;
  
beginchar("H",incrwidth(0,1),ht#,dp#); "Up arrow";  
  pickup symbol_pen;
  y1 = bot h-small_topgap;
  y2 = top -d+small_bottomgap;
  x1 = x2 =w/2;
  symbolpath0 := z1--z2;
  definearrow(reverse symbolpath0)((y1-y2)/3)(symbolpath1);
  draw symbolpath0;
  draw symbolpath1;
  charbox; endchar;

% Miscellaneous symbols

beginchar("O",incrwidth(0,1),ht#,dp#); "Yarn over";
  pickup symbol_pen;
  top z1 = (0.5w, h-topgap+o);
  bot z3 = (0.5w, bottomgap-d-o);
  x2-x4 = y1-y3; 0.5[x2,x4]=0.5w;
  y2 = y4 = 0.5[y1,y3];
  penpos1(symbolwidth,90);
  penpos2(symbolwidth,0);
  penpos3(symbolwidth,270);
  penpos4(symbolwidth,180);
  penstroke z1e..z2e..z3e..z4e..cycle;
  purlbox; endchar;

beginchar("@",wd#,ht#,dp#); "Bead";
  pickup symbol_pen;
  z1 = (0.5w, 0.667h);
  z3 = (x1,-d+h-y1);
  x2-x4 = y1-y3; 0.5[x2,x4]=0.5w;
  y2 = y4 = 0.5[y1,y3];
  fill z1..z2..z3..z4..cycle;
  unfill fullcircle scaled 0.3333(y1-y3) shifted 0.5[z1,z3];  
  charbox; endchar;

beginchar(ditto,incrwidth(0,0),ht#,dp#); "Wrap and turn"; 
  pickup symbol_pen;  
  z0 = 0.4[z1,z3] = 0.5[z2,z4];  
  x3=x1=w/2; y2=y4; y3-y1=x4-x2;
  
  z5 = z3 + 1.5((x4-x2)/2,0);
  z6 = z5 + ((x4-x2)/2,0) rotated 150;
  z7 = z5 + ((x4-x2)/2,0) rotated -150;
  
  y6 = h-wrapturngap;
  y1 = -d+wrapturngap;
  
  top (1-2spiralgap)[z0,z3]+(whatever,symbolwidth) = bot z7;
  
  symbolpath0 := 
  	(1-2spiralgap)[z0,z2]
  	..(1-2spiralgap)[z0,z3]
  	..(1-spiralgap)[z0,z4]
  	..z1
  	..z2
  	..z3{right}--z5;
  definearrow(symbolpath0)((x4-x2)/2)(symbolpath1);  
  draw symbolpath0;
  draw symbolpath1;
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  nogrid_charbox; endchar;
beginchar(19,incrwidth(0,0),ht#,dp#); "Reverse wrap and turn";
  fliphoriz(symbolpic0)(currentpicture); 
  currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  nogrid_charbox; endchar;
  
ligtable
ditto:
	ditto =: 19;
ligtable
"-":
"=":
	ditto |=: 19;
	
	
def drawM(expr topheight, bottomheight, mwidth, penwidth) =
  pickup pensquare scaled penwidth;
  rt x3 - lft x1 = 1.43 (y7-y1) = mwidth;
  y1 = y2 = y3;
  bot y7 = y8 = y9;
  topheight - y7 = y1-bottomheight;
  y4 = y10; y5 = y6;
  y8 - y5 = 0.4(x2 - x1);
  y8 - y4 = 1.6(y8 - y5);
  x1 = x7; x5 = x2; x6 = x3;
  x4 - x1 = x10 - x2 = 0.3penwidth;
  x8 = 0.6[x1,x2]; x9 - x2 = x8 - x1;
  x3 - x2 = x2 - x1;
  x1 = w - x3; 
  penpos1  (penwidth, 0);
  penpos7  (penwidth, 0);
  penpos5  (penwidth, 0);
  penpos6  (penwidth, 0);
  penpos2  (penwidth, 0);
  penpos3  (penwidth, 0);
  penpos4  (penwidth-2(x4-x1), 180);
  penpos10 (penwidth-2(x4-x1), 180);
  penpos8  (penwidth, 90);
  penpos9  (penwidth, 90);
  %draw z4{up}..z8{right}..z5{down}; draw z10{up}..z9{right}..z6{down};
  penstroke z1e--z7e;
  penstroke z4e{up}..z8e..z5e{down}--z2e; penstroke z10e{up}..z9e..z6e{down}--z3e;
  labels(1,2,3,4,5,6,7,8,9,10,4l,4r);
enddef;
 
beginchar("*",wd#,ht#,dp#); "Special instructions";
  pickup symbol_pen;     
  top z1 = (w/2,h-topgap+o);
  bot z2 = (w/2, -d+bottomgap-o);
  z3 - z4 = (z1-z2) rotated 60;
  z5 - z6 = (z1-z2) rotated 120;
  0.5[z3,z4] = 0.5 [z5,z6] = 0.5[z1,z2];
  for k=1,3,5:
  	z[k]' = 0.25[z[k],z[k+1]];
  	0.5[z[k+1]',z[k]']=0.5[z1,z2];
  	z[k]'' = 0.5[z[k],z[k+1]];
  	penpos[k]'(symbolwidth, angle (z[k]-z[k+1])+90);
  	penpos[k+1]'(symbolwidth, angle (z[k]-z[k+1])+90);
  	penpos[k]''((1/sqrt(3))*symbolwidth, angle (z[k]-z[k+1])+90);
  	draw z[k]--z[k]'; draw z[k+1]--z[k+1]';
  	penstroke z[k]'e{z[k+1]-z[k]}..z[k]''e..{z[k+1]-z[k]}z[k+1]'e;
  endfor
charbox; endchar;

%beginchar("a",wd#,ht#,dp#); "Small bobble";  
%  pickup symbol_pen;
%  top z1 = (0.5w, h-small_topgap+o);
%  bot z3 = (0.5w, small_bottomgap-d-o);
%  x2-x4 = y1-y3; 0.5[x2,x4]=0.5w;
%  y2 = y4 = 0.5[y1,y3];
%  pickup pensquare scaled symbolwidth rotated 45;
%  draw z1--z2; draw z2--z3; draw z3--z4; draw z4--z1;
%  drawdot 0.5[z1,z3];
%charbox; endchar;
beginchar(0,wd#,ht#,dp#); "Large bobble";  
  pickup symbol_pen;
  top z0 = (w/2, h-min_topgap) if offset=0: + (0,o) fi;
  bot z2 = (w/2, -d+min_bottomgap) if offset=0: - (0,o) fi;
  0.5[z1,z3] = 0.5[z0,z2];
  z1-z3 = (z2-z0) rotated 90;
  draw z0..z1..z2..z3..cycle;
charbox; endchar;


def drawhat(expr linewd) =
	pickup symbol_pen;
	top z1 = (w/2, h-min_topgap+o);
	x3-x1 = x1-x2; y3=y2;
	x3-x2 = standardheight;
	y1-y3 = (x1-x2);
	z3l = z3 + ((linewd/2,0) rotated (angle (z1-z3)-90));
	z3m = z3 + ((linewd/2,0) rotated (angle (z3-z1)));
	0.5[z3l,z3r] = z3;
	z2l = z2 + ((linewd/2,0) rotated (angle (z2-z1)-90));
	z2m = z2 + ((linewd/2,0) rotated (angle (z2-z1)));
	0.5[z2l,z2r] = z2;
	z1r = z3r + whatever*(z1-z3);
	z1r = z2r + whatever*(z2-z1);
	z1l3-z1 = z3l-z3;
	z1l2-z1 = z2l-z2;
	fill z3l---z1l3..z1l2---z2l..z2m..z2r---z1r---z3r..z3m..cycle;
enddef;

% Increases and decreases

beginchar(1,wd#,ht#,dp#); "Make 1 from N";
	% Fontforge keeps mangling this symbol, so I'm doing it the slow, hard, but reliable way.
	drawhat(symbolwidth);
	symbolpic0 := currentpicture; symbolpicwd0 := w;
	charbox; endchar;
beginchar(2,wd#,ht#,dp#); "Purl make 1 from N"; 
	drawhat(purl_symbolwidth);
	symbolpic1 := currentpicture; symbolpicwd1 := w;
	purlbox; endchar;
beginchar(3,wd#,ht#,dp#); "Make N from 1"; 
	flipvert(symbolpic0)(currentpicture); currentpicture := currentpicture shifted ((w-symbolpicwd0)/2,0);
	charbox; endchar;
beginchar(4,wd#,ht#,dp#); "Purl make N from 1";
	flipvert(symbolpic1)(currentpicture); currentpicture := currentpicture shifted ((w-symbolpicwd1)/2,0);
	purlbox; endchar;

beginchar("U",incrwidth(0,1),ht#,dp#); "Cast on"; 
	pickup symbol_pen; 
	bot y1 = bot y3 = -d+bottomgap;
	x1 = 0; x3 = w; x2 = w/2; top y2 = h-topgap;
	draw z1{right}..z2{left}..z3{right};
	nogrid_charbox; endchar;
beginchar("f",decrwidth(1,0),ht#,dp#); "Bind off knitwise"; 
	pickup symbol_pen; 
	x3-x1=wd; 0.5[x1,x3]=w/2; x2 = 0.5[x1,x3];
	y1 = y3 = (h-d)/2; top y2 = h-topgap;
	bot z4 = (w/2, -d+bottomgap);
	symbolpath0 := z1..z2{right}..z3;
	draw symbolpath0;
	%draw z4--bot z1;
	nogrid_charbox; endchar;
beginchar("F",decrwidth(1,0),ht#,dp#); "Bind off purlwise";
  if fonttype <> purltype:
	pickup purl_symbol_pen; 
	draw symbolpath0;
	fi
	nogrid_charbox; purlfill; endchar;
beginchar("Z",incrwidth(1,3),ht#,dp#); "Knit one doubly elongated"; 
 	pickup symbol_pen; 
  0.5[z1,z7] = top (w/2, -d+min_bottomgap);
  y1 = y7;
  x7 - x1 = 0.8(x8 - x0);
  0.5[x0,x8] = w/2;
  y0 = y8 = 0.5[y1,y2];
  x8 - x0 = y2 - y1;
  0.5[z2,z6] = bot (w/2, h-min_topgap);
  y2 = y6;
  x6 - x2 = 0.7(x7-x1);
  0.5[x3,x5] = w/2;
  y3 = y5 = 0.2[y1,y2];
  x5 - x3 = 0.5(x7-x1);

  x4 = w/2; y4 = y2;

   endangle := 110;
   midtension := 2;
   sidetension := 2;

	draw 
	z1{dir endangle}
	..z0{up}
	..z2{right}
	..tension sidetension
	..z3{left}
	..tension midtension
	..z4{right}
	..tension midtension
	..z5{left}
	..tension sidetension
	..z6{right}
	..z8{down}
	..z7{dir(-endangle)};
	
	charbox; endchar;

beginchar("z",incrwidth(1,2),ht#,dp#); "Knit one elongated"; 
	pickup symbol_pen; 
  0.5[z1,z5] = top (w/2, -d+small_bottomgap);
  y1 = y5;
  x5 - x1 = 0.8(x6-x0);
  0.5[x0,x6] = w/2;
  y0 = y6 = 0.5[y1,y2];
  x6 - x0 = y2 - y1;
  0.5[z2,z4] = bot (w/2, h-small_topgap);
  y2 = y4;
  x4 - x2 = 0.6(x5-x1);
  x3 = w/2; y3 = 0.2[y1,y2];

   endangle := 110;
   midtension := 1.5;

	draw 
	z1{dir endangle}..z0{up}..z2{right}..tension midtension..z3{left}
	..tension midtension..z4{right}..z6{down}..z5{dir(-endangle)};
	
	charbox; endchar;
beginchar("9",incrwidth(1,2),ht#,dp#); "CYCA knit one elongated";
	pickup symbol_pen;
	y0l=y0r; y1l=y1r; y2l=y2r;
	x0r=wd-x0l;
	x1r=wd-x1l;
	x2r=wd-x2l;
	z0l = top rt (mingap-ho,-d+small_bottomgap-o);
	y1l = bot h-small_topgap;
	x2r-x2l = y1l-y0l+2(smallgap-mingap-o/2);
	x1l = 0.23[x2l,x2r];
	y2l = 0.7[y0l,y1l];
	draw z0l..tension 3..z1l{left}..z2l{down}..tension 1.5..
		z2r{up}..z1r{left}..tension 3..z0r;
	labels(0l,1l,2l,0r,1r,2r);
	currentpicture := currentpicture shifted ((w-wd)/2,0);
	charbox; endchar;

	

beginchar(25,wd#/2,ht#,dp#); "Left end of a wide increase";
  pickup pensquare xscaled wideinctip yscaled wideincline;
  z1 = (w+cableextend,(h-topgap-d+bottomgap)/2);
  x2 = w/3; top y2 = h-min_topgap+o;
  fill bot lft z2{down}..bot z1{right}--top z1{left}..top rt z2{up}--top lft z2---cycle;
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  leftgrid_charbox; endchar;
beginchar(22,wd#/2,ht#,dp#); "Extender for a wide increase/decrease";
  z1 = (w+cableextend,(h-topgap-d+bottomgap)/2);
  x2 = 0-cableextend; y2 = y1;
  pickup pensquare scaled wideincline;
  draw rt z2 -- lft z1;
  topbotgrid_charbox; endchar;
beginchar(26,wd#/2,ht#,dp#); "Right end of a wide increase";
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);  rightgrid_charbox; endchar;
beginchar(27,wd#/2,ht#,dp#); "Left end of a wide decrease";
  flipvert(symbolpic0)(currentpicture); currentpicture := currentpicture shifted ((w-symbolpicwd0)/2,0);  leftgrid_charbox; endchar;
beginchar(28,wd#/2,ht#,dp#); "Right end of a wide decrease";
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);  flipvert(currentpicture)(currentpicture); rightgrid_charbox; endchar;

beginchar(29,wd#,ht#,dp#); "Middle of a wide increase";
  pickup pensquare xscaled wideinctip yscaled wideincline;
  z1 = (-cableextend,(h-topgap-d+bottomgap)/2);
  z3 = (w+cableextend,(h-topgap-d+bottomgap)/2);
  x2 = w/2; bot y2 = -d+min_bottomgap-o;
  %draw z1{right}..z2{down};
  fill bot lft z2{up}..bot z1{left}--top z1{right}..top rt z2---bot rt z2--cycle;
  %draw z3{left}..z2{down};
  fill bot rt z2{up}..bot z3{right}--top z3{left}..top lft z2---bot lft z2--cycle;
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  topbotgrid_charbox;
 endchar;
beginchar(30,wd#,ht#,dp#); "Middle of a wide decrease";
  flipvert(symbolpic0)(currentpicture); currentpicture := currentpicture shifted ((w-symbolpicwd0)/2,0);
  topbotgrid_charbox;
  endchar;

if 5*wd# < symbolmaxwd#:

beginchar(31,if fonttype = counttype: decrwidth(5,1) else: 5wd# fi,ht#,dp#); "Make 1 from 5";
  pickup pensquare xscaled wideinctip yscaled wideincline;
  top z1 = (w/2,h-min_topgap+o);
  x2 = wd/3; bot y2 = bot y3 = -d+min_bottomgap-o;
  x3 - x1 = x1 - x2;
  z4 = 0.5[z1,z2]; z5 = 0.5[z1,z3];
  %draw z2{up}..z4{right}..z1{up};
  %draw z3{up}..z5{left}..z1{up};

	fill bot lft z2---top lft z2..top z4{right}..top lft z1{up}--top rt  z1---bot rt  z1..bot z4{left }..bot rt z2{down}--cycle;
	fill bot rt  z3---top rt  z3..top z5{left }..top rt  z1{up}--top lft z1---bot lft z1..bot z5{right}..bot lft z3{down}--cycle;

  charbox; endchar;
fi

beginchar("~",incrwidth(0,0),ht#,dp#); "Empty box (spacer)"; endchar;
beginchar("`",if fonttype = counttype: 0 else: 0.5wd# fi,ht#,dp#); "Empty box (spacer)"; endchar;
beginchar("'",if fonttype = counttype: 0 else: 0.5wd# fi,ht#,dp#); "Empty box (spacer)"; 
	if fonttype = purltype: fill (0,-d)--(w,-d)--(w,h)--(0,h)--cycle; fi
	endchar;


beginchar("m",incrwidth(0,1),ht#,dp#); "Make one";  
  pickup symbol_pen;
  drawM(h-topgap, -d+bottomgap, 0.5(h+d),symbolwidth);
  charbox; endchar;
beginchar("M",incrwidth(0,1),ht#,dp#); "Make one purlwise";  
  pickup purl_symbol_pen;
  drawM(h-topgap, -d+bottomgap, 0.5(h+d),purl_symbolwidth);
  purlbox; endchar;
  
%def drawB(expr topgap, bottomgap, symbolwidth) = 
%  x1 = x2 = x3; x4 = x5 = x6; x7=x8 + 0.05(x7-x1);
%  y1 = y4; y2 = y5; y3 = y6; y7 = 0.5[y1,y2]; y8 = 0.5[y2,y3];
%  top y3 = h-topgap; bot y1 = -d+bottomgap;
%  y2 = 0.51[y1,y3];
%  x7-x1 = 1.3(y2-y1);
%  x7-x6 = 0.7(x7-x1);
%  0.5[x7,x1]=w/2+ho;
%  z9=z10=z5; z11=rt z2;
%  
%  penpos11(symbolwidth,-90);
%  penpos5(symbolwidth,-90);
%  penpos8(symbolwidth,0);
%  penpos6(symbolwidth,90);
%  penpos2(symbolwidth,180);
%  penpos4(symbolwidth,-90);
%  penpos7(symbolwidth,0);
%  z10l=z5l; z9l=z5r; z10r = 0.4[z5,z5r];
%  z9r-z9l=z10l-z10r;
%  y3r=y6r; y3l=y6l; x3r=x2r=x1r; x3l=x2l=x1l;
%  y1r=y4r; y1l=y4l;
%  penstroke z11e--z5e--z10e{right}..z8e..z6e---z3e--z2e--z1e---z4e..z7e..z9e{left};
%
%enddef;
%  
%
%beginchar("b",wd#,ht#,dp#); "Knit tbl";  
%  pickup symbol_pen;
%  drawB(topgap, bottomgap, symbolwidth);
%  charbox; endchar;
%beginchar("B",wd#,ht#,dp#); "Purl tbl";
%  pickup purl_symbol_pen;
%  drawB(topgap, bottomgap, purl_symbolwidth);
%  purlbox; endchar;

beginchar("|",if fonttype <> counttype: overlinewd# else: 0 fi,ht#,dp#); "Divider";  
  if (fonttype = foretype) or (fonttype = bothtype):
  fill(0,-d-gridwidth/2-purlextend)--(0,h+gridwidth/2+purlextend)  
  	--(w,h+gridwidth/2+purlextend)--(w,-d-gridwidth/2-purlextend)
  	--cycle;
  fi
endchar;

%Twists

path twistpath[];

  pair time;

beginchar("x",incrwidth(0,1),ht#,dp#); "Twist slanting right";
  pickup symbol_pen;
  bot lft z0 = (0.5w-0.4 standardheight-ho,-d+small_bottomgap-o);
  bot rt  z4 = (0.5w+0.4 standardheight+ho,-d+small_bottomgap-o);
  top z2 = (0.5w, h-topgap+o);
  x3-x1 = 0.8(x0-x4); 0.5[x1,x3] = w/2;
  y1 = y3 = 0.7[y0,y2];
  twistpath0:=z0{curl 0.1}..z1{up}..z2..z3{down}..z4{curl 0.1};

  pathdir0 = angle (direction 0 of twistpath0);
  pathdir4 = angle (direction 4 of twistpath0);

  penpos0(symbolwidth, (pathdir0 + 90));
  penpos1(symbolwidth, 180);
  penpos2(symbolwidth, 270);
  penpos3(symbolwidth, 360);
  penpos4(symbolwidth, (pathdir4 + 90));

  z5 = z0; z6 = z1;
  penpos5(eraserwidth, (pathdir0 + 90));
  penpos6(eraserwidth, 180);

  time := (z5l{direction 0 of twistpath0}..z6l{up}) intersectiontimes
	(z3l{down}..z4l{direction 4 of twistpath0});
  twistpath1 := subpath (ypart(time),1) of (z3l{down}..z4l{direction 4 of twistpath0});
  time := (z5l{direction 0 of twistpath0}..z6l{up}) intersectiontimes
	(z3r{down}..z4r{direction 4 of twistpath0});
  twistpath2 := subpath (ypart(time),1) of (z3r{down}..z4r{direction 4 of twistpath0});
  fill twistpath1 & (point infinity of twistpath1--point infinity of twistpath2)
	& reverse twistpath 2 &
	(point 0 of twistpath2--point 0 of twistpath1) & cycle;

  time := (z5r{direction 0 of twistpath0}..z6r{up}) intersectiontimes
	(z3l{down}..z4l{direction 4 of twistpath0});
  twistpath1 := subpath (0,ypart(time)) of (z3l{down}..z4l{direction 4 of twistpath0});
  time := (z5r{direction 0 of twistpath0}..z6r{up}) intersectiontimes
	(z3r{down}..z4r{direction 4 of twistpath0});
  twistpath2:= subpath (0,ypart(time)) of (z3r{down}..z4r{direction 4 of twistpath0});
  fill twistpath1 & (point infinity of twistpath1--point infinity of twistpath2)
	& reverse twistpath 2 &
	(point 0 of twistpath2--point 0 of twistpath1) & cycle;

  penstroke z0e{direction 0 of twistpath0}..
	z1e{up}..z2e{left}..z3e{down}
	;%..z4e{direction 4 of twistpath0};

  symbolpic0 := currentpicture; symbolpicwd0 := w;
  labels(0,1,2,3,4,5);
  charbox; endchar;  
  
  numeric t[];
  
beginchar("t",incrwidth(0,1),ht#,dp#); "Twist slanting left";
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  charbox; endchar;
  
beginchar("X",incrwidth(0,1),ht#,dp#); "Purl right twist";
  currentpicture := symbolpic0; currentpicture := currentpicture shifted ((w-symbolpicwd0)/2,0);
  purlbox; endchar;
beginchar("T",incrwidth(0,1),ht#,dp#); "Purl left twist";
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  purlbox; endchar;

beginchar("b",wd#,ht#,dp#); "Right upside-down twist";
  flipvert(symbolpic0)(currentpicture); currentpicture := currentpicture shifted ((w-symbolpicwd0)/2,0);
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  charbox; endchar;  
beginchar("q",wd#,ht#,dp#); "Left upside-down twist";
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  charbox; endchar;
beginchar("Q",wd#,ht#,dp#); "Purl right upside-down twist";
  currentpicture := symbolpic0; currentpicture := currentpicture shifted ((w-symbolpicwd0)/2,0);
  purlbox; endchar;
beginchar("B",wd#,ht#,dp#); "Purl left upside-down twist";
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  purlbox; endchar;
  
%2/1 increases and decreases

def drawSSK(expr topheight,bottom) =
  bot rt  z1 = (0.5w+0.5 (topheight-bottom)+ho,bottom-o);
  top lft z2 = (0.5w-0.5 (topheight-bottom),   topheight+o);
  bot lft z3 = (0.5w-0.5 (topheight-bottom),   bottom-o);
  symbolpath0 := z1--z2--z3;
  draw symbolpath0;
enddef;
  
beginchar("<",decrwidth(2,1),ht#,dp#); "SSK or left-slant cable";
  pickup symbol_pen;
  drawSSK(h-topgap,-d+bottomgap);
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  charbox; endchar;  
beginchar(">",decrwidth(2,1),ht#,dp#); "k2tog or right-slant cable";
  fliphoriz(symbolpic0)(currentpicture); 
  currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  charbox; endchar;
  
beginchar("0",incrwidth(1,2),ht#,dp#); "Make 2 from 1";
  flipvert(symbolpic0)(currentpicture); 
  charbox; endchar;
beginchar("#",incrwidth(1,2),ht#,dp#); "Make 2 from 1";
  flipvert(symbolpic0)(currentpicture); 
  fliphoriz(currentpicture)(currentpicture); 
  charbox; endchar;

beginchar(";",decrwidth(2,1),ht#,dp#); "P2tog";  
  pickup purl_symbol_pen;
  draw symbolpath0;
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  purlbox; endchar;  
beginchar(":",decrwidth(2,1),ht#,dp#); "SSP";
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  purlbox; endchar;
  
beginchar("j",incrwidth(0,1),ht#,dp#); "Lifted increase slanting left";
  pickup symbol_pen;
  top lft z1 = (0.5w-0.5 standardheight-ho,h-topgap+o);
  bot  rt z2 = (0.5w+0.5 standardheight,   -d+bottomgap-o);
  symbolpath0 := z2--z1;
  definearrow(symbolpath0)((y1-y2)/3)(symbolpath1);  
  draw symbolpath0; 
  draw symbolpath1;
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  charbox; endchar;
beginchar("i",incrwidth(0,1),ht#,dp#); "Lifted increase slanting right";
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  charbox; endchar;
beginchar("J",incrwidth(0,1),ht#,dp#); "Purl increase slanting right";
  pickup purl_symbol_pen;
  draw symbolpath0; 
  draw symbolpath1;
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  purlbox; endchar;
beginchar("I",incrwidth(0,1),ht#,dp#); "Purl increase slanting left";  
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  purlbox; endchar;

beginchar("(",wd#,ht#,dp#); "Left-slanting line";
  pickup symbol_pen;
  top lft z1 = (0.5w-0.5 standardheight-ho,h-topgap+o);
  bot  rt z2 = (0.5w+0.5 standardheight,   -d+bottomgap-o);
  symbolpath0 := z2--z1;
	draw symbolpath0;
  charbox; endchar;
beginchar(")",wd#,ht#,dp#); "Right-slanting line";
  pickup symbol_pen;
	draw symbolpath0;
	fliphoriz(currentpicture)(currentpicture);
  charbox; endchar;
  
beginchar("y",incrwidth(1,2),ht#,dp#); "Knit front and back";
  pickup symbol_pen;
  bot lft z1 = (0.5w-0.495 Vwidth-ho,-d+bottomgap-o);
  top  rt z2 = (0.5w+0.495 Vwidth+ho,h-topgap+o);
  bot  rt z3 = (0.5w+0.495 Vwidth+ho,-d+bottomgap-o);
  top lft z4 = (0.5w-0.495 Vwidth-ho,h-topgap+o);
  % For some reason, mf2pt1 doesn't like it if I use 0.5 Vwidth
  z5 = whatever[z1,z2] = whatever[z3,z4];
  draw z1--z2;
  draw z4--z5;
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  charbox; endchar;  
beginchar("u",incrwidth(1,2),ht#,dp#); "Knit back and front";
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  charbox; endchar;
beginchar("4",decrwidth(2,1),ht#,dp#); "Alternative SSK";
  flipvert(symbolpic0)(currentpicture); currentpicture := currentpicture shifted ((w-symbolpicwd0)/2,0);
  charbox; endchar;
beginchar("5",decrwidth(2,1),ht#,dp#); "Alternative K2tog";
  flipvert(symbolpic0)(currentpicture); currentpicture := currentpicture shifted ((w-symbolpicwd0)/2,0);
  fliphoriz(currentpicture)(currentpicture);
  charbox; endchar;
 
  
  
beginchar("7",incrwidth(1,2),ht#,dp#); "Alt front and back";
  pickup symbol_pen;
	x0 = x1 = x2;
	bot y0 = -d+small_bottomgap;
	top y1 = h-small_topgap;
	0.5[x3+ho,x0] = w/2;
	z3 = z2 + whatever*(-1.2,1);
	y3 = 0.9[y0,y1];
	y2 = 0.4[y0,y1];
	draw z2--z3; draw z1--z0;
	symbolpic0 := currentpicture; symbolpicwd0 := w;
	charbox; endchar;
beginchar("8",incrwidth(1,2),ht#,dp#); "Alt back and front";
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  charbox; endchar;
	


beginchar("v",incrwidth(1,2),ht#,dp#); "Generic make 2 from 1";
  pickup symbol_pen;
  top  rt z1 = (0.5w+0.5 Vwidth+ho,h-topgap+o);
  bot y2 = -d+bottomgap-o; x2 = 0.5[x1,x3];
  top lft z3 = (0.5w-0.5 Vwidth-ho,h-topgap+o);
  symbolpath0 := z1--z2--z3;
  draw symbolpath0;
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  charbox; endchar;  
beginchar("V",incrwidth(1,2),ht#,dp#); "Purl make 2 from 1";  
  pickup purl_symbol_pen;
  draw symbolpath0;
  symbolpic1 := currentpicture; symbolpicwd1 := w;
  purlbox; endchar;
beginchar("6",wd#,ht#,dp#); "V with bar";
  pickup symbol_pen;
  currentpicture := symbolpic0; currentpicture := currentpicture shifted ((w-symbolpicwd0)/2,0);
  0.5[x0,x1]=w/2;
  y0=y1=0.6[-d+bottomgap,h-topgap];
  rt x1-lft x0 = Wwidth;
  draw z0--z1;
  charbox; endchar;  

beginchar("!",decrwidth(2,1),ht#,dp#); "Make 1 from 2";  
	flipvert(symbolpic0)(currentpicture); currentpicture := currentpicture shifted ((w-symbolpicwd0)/2,0);
  charbox; endchar;
beginchar("2",decrwidth(2,1),ht#,dp#); "Make 1 from 2 purlwise";  
	flipvert(symbolpic1)(currentpicture); currentpicture := currentpicture shifted ((w-symbolpicwd1)/2,0);
   purlbox; endchar;

%Double decreases and increases
  
beginchar("w",incrwidth(1,3),ht#,dp#); "make 3 from 1";
  pickup symbol_pen;
  top lft z1 = (0.5w-0.5 Wwidth-ho,h-small_topgap+o);
  bot z2 = (0.5w,-d+small_bottomgap-o);
  top  rt z3 = (0.5w+0.5 Wwidth+ho, h-small_topgap+o);
  z4 = 0.5[z1,z3];
  symbolpath0 := z1--z2--z3;
  draw symbolpath0;
  symbolpath1 := z2--z4;
  draw symbolpath1;
  charbox; endchar;  
beginchar("W",incrwidth(1,3),ht#,dp#); "Purl make 3 from 1";  
  pickup purl_symbol_pen;
  draw symbolpath0; draw symbolpath1;
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  purlbox; endchar;
beginchar("Y",incrwidth(1,3),ht#,dp#); "Make 3 from 1 with YO center";
  pickup symbol_pen;
  draw symbolpath0;
  top z4 = (0.5w, h-small_topgap+o);
  bot z5 = z4 - (0, 0.5Wwidth); %Better way?
  z6-z7 = (z4-z5) rotated 90; 0.5[z6,z7]=0.5[z4,z5];
  draw z4..z6..z5..z7..cycle;
  charbox; endchar;  

beginchar("E",incrwidth(1,3),ht#,dp#); "make 3 from 1 with purl center";
  pickup symbol_pen;
	if (fonttype = foretype) or (fonttype = bothtype):
	  currentpicture := symbolpic0; currentpicture := currentpicture shifted ((w-symbolpicwd0)/2,0);
	fi
	charbox;
	if (fonttype = purltype):
	  z1 = point 0 of symbolpath0;
	  z2 = point 1 of symbolpath0;
	  z3 = point 2 of symbolpath0;
	  fill z1--z2--z3--cycle;
	fi
  endchar;  

beginchar("&",incrwidth(1,3),ht#,dp#); "make 3 from 1 with knit center";
  pickup symbol_pen;
	if (fonttype = foretype) or (fonttype = bothtype):
	  currentpicture := symbolpic0; currentpicture := currentpicture shifted ((w-symbolpicwd0)/2,0);
	fi
	charbox;
	if (fonttype = purltype):
	  z1 = point 0 of symbolpath0;
	  z2 = point 1 of symbolpath0;
	  z3 = point 2 of symbolpath0;
	  fill z1--z2--z3--%z1--(0,h)--
	  		(w,h)--(w,-d)--(0,-d)--(0,h)--cycle;
	fi
  endchar;  

beginchar("A",decrwidth(3,1),ht#,dp#); "Make 1 from 3";
  pickup symbol_pen;
  bot lft z1 = (0.5w-0.5 biggerheight-ho,-d+small_bottomgap-o);
  bot  rt z3 = (0.5w+0.5 biggerheight+ho,-d+small_bottomgap-o);
  top z2 = (xpart z4, h-small_topgap+o);
  z4 = 0.5[z1,z3];
  symbolpath0 := z1--z2--z3;
  symbolpath1 := z2--z4;
  draw symbolpath0;
  draw symbolpath1;
  labels(1,2,3,4);
  charbox; endchar;  
beginchar("3",decrwidth(3,1),ht#,dp#); "Purl make 1 from 3";
  pickup purl_symbol_pen;
  draw symbolpath0;
  draw symbolpath1;
  purlbox; endchar;

beginchar("R",decrwidth(3,1),ht#,dp#); "k3tog";
  pickup symbol_pen;
  finesymbolwidth := 4/7symbolwidth;
  top  rt z0 = (0.5w+0.5 biggerheight,   h-small_topgap+o);
  bot lft z1 = (0.5w-0.5 biggerheight-ho,-d+small_bottomgap-o);
  bot  rt z3 = (0.5w+0.5 biggerheight,   -d+small_bottomgap-o);
   
  % The line z0--z4 is halfway between z0--z1 and z0--z3 as angles
  z4 = whatever[z1,z3];
  z4 = z0+whatever*(dir 0.5[angle(z1-z0),angle(z3-z0)]);
  z5 = 0.5[z1,z3];

  z2 = 0.5[z4,z5];

  z1' = 0.5[z1,z0];
  z3' = 0.2[z3,z0];	
  z2'' = z0;
  z2' = 0.2[z2,z2''];  
  penpos1(symbolwidth, -90+angle (z0-z1));
  penpos1'(symbolwidth, -90+angle (z0-z1));
  penpos3(symbolwidth, 0);
  penpos3'(symbolwidth, 0);
  
  z1''l = whatever[z1l,z1'l];
  z1''l = z0 + whatever*((z1-z0) rotated 90);
  penpos1''(finesymbolwidth, -90+angle (z0-z1));
  
  z3''r = (x3r,y0);
  penpos3''(finesymbolwidth, 0);

  penpos2(symbolwidth, -90+angle (z2''-z2));
  penpos2'(symbolwidth, -90+angle (z2''-z2));
  penpos2''(finesymbolwidth, -90+angle (z2''-z2));
  
  symbolpath1 := z1''l..z1'l---z1l..z1r---z1'r..z1''r;
  symbolpath2 := z2''l..z2'l---z2l..z2r---z2'r..z2''r;
  symbolpath3 := z3''l..z3'l---z3l..z3r---z3'r..z3''r;
  % Not penstroke because we want the endpoints to be rounded
  
  numeric t[];
  (t12,t21) = symbolpath1 intersectiontimes symbolpath2;
  (t23,t32) = symbolpath2 intersectiontimes symbolpath3;
  fill (subpath(0,t12) of symbolpath1 
  	-- subpath (t21,t23) of symbolpath2
  	-- subpath (t32,infinity) of symbolpath3
  	-- z3''r{z3''r-z3'r}..{z1-z0}cycle
  	);
  %pickup pencircle scaled 0.01pt;
  %draw symbolpath2; draw symbolpath3;

  symbolpic0 := currentpicture; symbolpicwd0 := w;
  labels(1,2,3,1',2',3',1r,1l,2r,2l,3r,3l,1'r,1'l,2'r,2'l,3'r,3'l, 1''r,1''l);
  
  symbolpath0 := z1--z0--z3--z2;
  charbox; endchar;  
beginchar("L",decrwidth(3,1),ht#,dp#); "SSSK";

	%draw subpath(0,2) of symbolpath0; 
	%draw point 3 of symbolpath0--point 1 of symbolpath0;
  fliphoriz(symbolpic0)(currentpicture);
  %currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  charbox; endchar;

beginchar("r",decrwidth(3,1),ht#,dp#); "LRC";
  pickup symbol_pen;
  bot lft z1 = (0.5w-0.5 biggerheight-ho,-d+small_bottomgap-o);
  top  rt z2 = (0.5w+0.5 biggerheight+ho,h-small_topgap+o);
  bot  rt z3 = (0.5w+0.5 biggerheight+ho,-d+small_bottomgap-o);
  top lft z4 = (0.5w-0.5 biggerheight-ho,h-small_topgap+o);
  x5 = 0.5w; y5 = 0.53[y1,y4];
  x6=x5; y6=y1;
  draw z1..z5..z2;
  draw z3--z5;
  draw z5--z6;
  
  symbolpic0 := currentpicture; symbolpicwd0 := w;
  labels(1,2,3,4,5,6,7);
  charbox; endchar;  
beginchar("l",decrwidth(3,1),ht#,dp#); "RLC";
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);
  charbox; endchar;
  
beginchar("a",decrwidth(3,1),ht#,dp#); "LRC";
  pickup symbol_pen;
  bot lft z1 = (0.5w-0.5 biggerheight-ho,-d+small_bottomgap-o);
  top  rt z2 = (0.5w+0.5 biggerheight+ho,h-small_topgap+o);
  bot  rt z3 = (0.5w+0.5 biggerheight+ho,-d+small_bottomgap-o);
  top lft z4 = (0.5w-0.5 biggerheight-ho,h-small_topgap+o);
  x5 = 0.5w; y5 = 0.6[y1,y4];
  top z6 = (0.5w, h-small_topgap+o);
  bot z7 = (0.5w, -d+small_bottomgap-o);
  draw z1--z5;
  draw z3--z5;
  draw z6--z7;
  charbox; endchar;  
  
% Rownumber triangles (modified from manfnt.mf)
  
trianglecharwd# = 19/3 pt#;

beginchar("}", trianglecharwd#, 6.25pt#, 0); "Triangle pointing right";
  if (fonttype = foretype) or (fonttype = bothtype):
  x1=x2=w-x3-max(purlextend, 0.5gridwidth)=4/3pt; y3=.5h;
  y1-y3=y3-y2; 
  y1-y2 = 1.3*(x3-x1); 
  % For an equilateral triangle, use 2/sqrt 3 = 1.1547
  fill z1--z2--z3--cycle;
  fi
  symbolpic0 := currentpicture; 
  labels(1,2,3); endchar;

beginchar("{", trianglecharwd#, 6.25pt#, 0); "Triangle pointing left";
  fliphoriz(symbolpic0)(currentpicture);
  endchar;

  
% Wrapped stitches

beginchar("?",wd#,ht#,dp#); "Left end of wrapped stitches";  
	pickup symbol_pen;
	x0r = x1r = x2r = w;
	y0r-y1r = y1r-y2r;
	y0m=y0r; y1m=y1r; y2m=y2r;
	y0l-y0r = y1l-y1r = y2l-y2r;
	
	if gridfont:
		h-small_topgap+o = top y0l;
		bot y2r = small_bottomgap-d;
		y1l = 2/3[y1r,y0r];
		x2l+ho = h-y0l+o;
		x0m = 0.4[x0l,x0r];
		x2m = 0.5[x2l,x2r];	
		z0l = z2l + whatever*(1,3);
		wraplines := 3;
	else:
		h-small_topgap-top y0r = bot y2r-small_bottomgap+d;	
		if (topgap>standardgap) or (bottomgap>standardgap): 
			wraplines := 2; else: wraplines:=3; fi
		if wraplines = 2: 
			y0r - y2r = 1.5(h-small_topgap-top y0r); 
			lft x2l+ho = smallgap;
		else:
			y0r - y1r = 1.5(h-small_topgap-top y0r); 
			lft x2l+ho = mingap;
		fi
		x0m = 0.2[x0l,x0r];
		x2m = 0.3[x2l,x2r];	
		y0l = 0.6[y0r,h-small_topgap+o];
		z0l = z2l + whatever*(1,4);
	fi
	
	z1l=whatever[z0l,z2l];
	z1m=whatever[z0m,z2m];
	pickup pensquare scaled symbolwidth;
	draw lft z0r--rt (0,y0r);
	if wraplines=3: draw lft z1r--rt (0,y1r); fi
	draw lft z2r--rt (0,y2r);
	symbolpic1 := currentpicture; symbolpicwd1 := w;
	currentpicture := nullpicture;	
	draw lft z0r---rt z0m;
	if wraplines=3: draw lft z1r---rt z1m; fi
	draw lft z2r---rt z2m;
	pickup symbol_pen;
	draw z0m{left}..z0l;
	if wraplines=3: draw z1m{left}..z1l; fi
	draw z2m{left}..z2l;	
	
	if gridfont: else:
	  draw bot (w/2,h-small_topgap+o) -- top (w/2, -d+small_bottomgap-o);
 	fi
	
	symbolpic0 := currentpicture; symbolpicwd0 := w;	
	labels(0r,0m,0l,1r,1m,1l,2r,2m,2l);
  charbox; endchar;
  
beginchar(23,wd#,ht#,dp#); "Middle of wrapped stitches";  
	pickup symbol_pen;
	currentpicture := symbolpic1; currentpicture := currentpicture shifted ((w-symbolpicwd1)/2,0);
	if gridfont: else:
  draw bot (w/2,h-small_topgap+o) -- top (w/2, -d+small_bottomgap-o);
  fi
 charbox; endchar;
beginchar(24,wd#,ht#,dp#); "Right end of wrapped stitches";  
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);  
  charbox; endchar;

ligtable "?":
 	"?" |=: 24;
ligtable 24:
	"?" |=: 24,
	24 =:| 23;
	
beginchar("1",wd#,ht#,dp#); "Left end of single-wrapped stitches";  
	pickup symbol_pen;
	x1r=w;
	y1m=y1r;
	
	if gridfont:
		if wd>ht+dp:
			y1l-y1r = (h+d)/3;
		else:
			y1l-y1r = (h+d)/4;
		fi
	else:
		y1l-y1r = (h+d)/5;
	fi
	x1m = 0.1[x1r,x1l];
	h-topgap+o-y1l = 1/2(y1r+d-bottomgap);
	rt x1l+ho = standardgap;
	wraplines := 1;
	if y1r<bottomgap-d: message("Your single-wrapped stitch symbol is too tall."); fi
	
	pickup pensquare scaled symbolwidth;
	draw lft z1r--rt (0,y1r);
	symbolpic1 := currentpicture; symbolpicwd1 := w;
	currentpicture := nullpicture;	
	draw lft z1r---rt z1m;
	pickup symbol_pen;
	draw z1m{left}..z1l;
	
	if gridfont: else:
	  draw bot (w/2,h-topgap+o) -- top (w/2, -d+bottomgap-o);
 	fi
	
	symbolpic0 := currentpicture; symbolpicwd0 := w;	
	labels(1r,1m,1l);
  charbox; endchar;
  
beginchar(17,wd#,ht#,dp#); "Middle of wrapped stitches";  
	pickup symbol_pen;
	currentpicture := symbolpic1; currentpicture := currentpicture shifted ((w-symbolpicwd1)/2,0);
	if gridfont: else:
  draw bot (w/2,h-small_topgap+o) -- top (w/2, -d+small_bottomgap-o);
  fi
 charbox; endchar;
beginchar(18,decrwidth(1,0),ht#,dp#); "Right end of wrapped stitches";  
  fliphoriz(symbolpic0)(currentpicture); currentpicture := currentpicture shifted (-(w-symbolpicwd0)/2,0);  
  charbox; endchar;

ligtable "1":
 	"1" |=: 18;
ligtable 18:
	"1" |=: 18,
	18 =:| 17;
	
% Outlines

if gridfont:

beginchar(5,wd#,ht#,dp#); "Top and bottom outlines";
	topbotgrid_charbox; endchar;

beginchar(6,0,ht#,dp#); "Vertical grid line";
	pickup pensquare scaled gridwidth;
	if (fonttype = gridtype) or (fonttype = bothtype):
	draw (0,-d)--(0,h);
	fi
endchar;
  
fi