% Date: 2019/04/05 picture symbolpic[]; beginchar(5,wd#,ht#,dp#); "Top and bottom outlines"; pickup pensquare scaled gridwidth; if (fonttype = gridtype) or (fonttype = bothtype): draw (0,-d)--(w,-d); draw (0,h)--(w,h); fi 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; code := 127; beginchar("-",wd#,ht#,dp#); "A knit stitch"; charbox; endchar; beginchar("=",wd#,ht#,dp#); "A purl stitch"; purlbox; endchar; beginchar(".",incrwidth(0,0),ht#,dp#); "No stitch"; fill (0.5(w-standardheight),-d+bottomgap) -- (0.5(w-standardheight),h-topgap) -- (0.5(w+standardheight),h-topgap) -- (0.5(w+standardheight),-d+bottomgap) -- cycle; symbolpic0 := currentpicture; charbox; endchar; beginchar(",",incrwidth(0,0),ht#,dp#); "Purl no stitch"; currentpicture := symbolpic0; purlbox; endchar; % Cables cablelinewidth#:=0.4pt#; define_blacker_pixels(cablelinewidth); pickup pencircle scaled cablelinewidth; cable_pen := savepen; % The one-letter cells beginchar("p",wd#,ht#,dp#); "Purl cable background"; currentpicture := errorsymbol1; purlbox; endchar; beginchar("P",wd#,ht#,dp#); "Purl cable foreground"; currentpicture := errorsymbol1; purlbox; endchar; beginchar("k",wd#,ht#,dp#); "Knit cable background"; currentpicture := errorsymbol1; charbox; endchar; beginchar("K",wd#,ht#,dp#); "Knit cable foreground"; currentpicture := errorsymbol1; charbox; endchar; beginchar("g",wd#,ht#,dp#); "Purl cable background"; currentpicture := errorsymbol1; purlbox; endchar; beginchar("G",wd#,ht#,dp#); "Purl cable foreground"; currentpicture := errorsymbol1; purlbox; endchar; beginchar("c",wd#,ht#,dp#); "Knit cable background"; currentpicture := errorsymbol1; charbox; endchar; beginchar("C",wd#,ht#,dp#); "Knit cable foreground"; currentpicture := errorsymbol1; charbox; endchar; beginchar("d",wd#,ht#,dp#); "White knit cable background"; currentpicture := errorsymbol1; charbox; endchar; beginchar("D",wd#,ht#,dp#); "White knit cable foreground"; currentpicture := errorsymbol1; charbox; endchar; beginchar("n",wd#,ht#,dp#); "Odd knit cable background"; currentpicture := errorsymbol1; charbox; endchar; beginchar("N",wd#,ht#,dp#); "Odd knit cable foreground"; currentpicture := errorsymbol1; charbox; endchar; beginchar("e",wd#,ht#,dp#); "Odd twist"; currentpicture := errorsymbol1; charbox; endchar; beginchar("o",wd#,ht#,dp#); "Odd twist"; currentpicture := errorsymbol1; charbox; endchar; % Horizontal cables horizcablegap# := 0.3 wd#; define_pixels(horizcablegap); beginchar("+",wd#,ht#,dp#); "Left end of a horizontal cable"; charbox; pickup pensquare scaled cablelinewidth; x1=x4=horizcablegap; x2=x3=w; bot y1=bot y2= -d+bottomgap; top y3=top y4=h-topgap; if (fonttype = gridtype) or (fonttype = bothtype): draw lft z3--rt z4; draw rt z1--lft z2; draw rt z4--rt z1; fi if fonttype = purltype: fill (0,-d)--(w,-d)--z2--z1--z4--z3--(w,h)--(0,h)--cycle; fi symbolpic0 := currentpicture; endchar; midhoriz := 20; righthoriz := 21; specialhoriz := ASCII"/"; beginchar(midhoriz,wd#,ht#,dp#); "Middle of a horizontal cable"; charbox; pickup pensquare scaled cablelinewidth; x1=x4=gridwidth/2; x2=x3=w-gridwidth/2; bot y1=bot y2= -d+bottomgap; top y3=top y4=h-topgap; if (fonttype = gridtype) or (fonttype = bothtype): draw rt z1--lft z2; draw lft z3--rt z4; fi if fonttype = purltype: fill z1--z2--(w,-d)--(0,-d)--cycle; fill z4--z3--(w,h)--(0,h)--cycle; fi labels(1,2,3,4); endchar; beginchar(specialhoriz,wd#,ht#,dp#); "Special horizontal cable"; charbox; pickup pensquare scaled cablelinewidth; x1=x4=gridwidth/2; x2=x3=w-gridwidth/2; bot y1=bot y2= -d+bottomgap; top y3=top y4=h-topgap; x5=x6; x7=x8; x7-x5 = y3-y2; 0.5[x7,x5]=0.5w; y5=y7=-d+gridwidth/2; y6=y8=h-gridwidth/2; if (fonttype = gridtype) or (fonttype = bothtype): draw top z5--bot z6; draw top z7--bot z8; draw rt z1--lft (x5,y2); draw rt (x7,y2)--lft z2; draw lft z3--rt(x7,y3); draw lft(x5,y4)--rt z4; fi if fonttype = purltype: fill (x1,y5)--z1--(x5,y1)--z5--cycle; fill (x2,y7)--z2--(x7,y2)--z7--cycle; fill (x3,y8)--z3--(x8,y3)--z8--cycle; fill (x4,y6)--z4--(x6,y4)--z6--cycle; fi labels(1,2,3,4,5,6,7,8); endchar; beginchar(righthoriz,if fonttype = counttype: 0 else: wd# fi,ht#,dp#); "Right end of a horizontal cable"; fliphoriz(symbolpic0)(currentpicture); endchar; ligtable "+": specialhoriz: "+" |=: righthoriz; ligtable righthoriz: "+" |=: righthoriz, specialhoriz =:| midhoriz, righthoriz =:| midhoriz; % Setup for the standard cables numeric cableleft[][][]; numeric cableright[][][]; numeric whitecableleft[][][]; numeric whitecableright[][][]; numeric twistleft[][]; numeric twistright[][]; numeric revcableleft[][]; numeric revcableright[][]; numeric topcableleft[][]; numeric topcableright[][]; numeric botcableleft[][]; numeric botcableright[][]; for sts = 2 upto 3: cableright[0][sts][0] := incr code; beginchar(code, (sts)*wd#,ht#,dp#); decimal sts&" cable background stitches"; addto currentpicture also errorsymbol[sts]; charbox; endchar; cableleft[sts][0][0] := incr code; beginchar(code, (sts)*wd#,ht#,dp#); decimal sts&" cable foreground stitches"; addto currentpicture also errorsymbol[sts]; charbox; endchar; revcableright[0][sts] := incr code; beginchar(code, (sts)*wd#,ht#,dp#); decimal sts&" twist background stitches"; addto currentpicture also errorsymbol[sts]; purlbox; endchar; revcableleft[sts][0] := incr code; beginchar(code, (sts)*wd#,ht#,dp#); decimal sts&" twist foreground stitches"; addto currentpicture also errorsymbol[sts]; purlbox; endchar; endfor % Draw the cables if known slantcutoff: else: slantcutoff = 0; fi for backsts = 1 upto 3: for frontsts = 1 upto 3: for midsts = 0 upto if frontsts = backsts: if frontsts < 3: frontsts else: 0 fi else: 0 fi: cableleft[frontsts][backsts][midsts] = incr code; cableright[frontsts][backsts][midsts] = incr code; whitecableleft[frontsts][backsts][midsts] = incr code; whitecableright[frontsts][backsts][midsts] = incr code; if midsts = 0: topcableleft[frontsts][backsts] = incr code; topcableright[frontsts][backsts] = incr code; botcableleft[frontsts][backsts] = incr code; botcableright[frontsts][backsts] = incr code; twistleft[frontsts][backsts] = incr code; twistright[frontsts][backsts] = incr code; revcableleft[frontsts][backsts] = incr code; revcableright[frontsts][backsts] = incr code; fi symbolpic0 := nullpicture; symbolpic1 := nullpicture; symbolpic2 := nullpicture; totsts := frontsts + backsts + midsts; if (frontsts+backsts+midsts)*wd# < symbolmaxwd#: beginchar(cableleft[frontsts][backsts][midsts],totsts * wd#,ht#,dp#); % Cable/cable front "Cable " & decimal(frontsts) & " over " &decimal(backsts) & " over " &decimal(midsts); frontstroke := cablelinewidth * ((backsts+midsts)++1); backstroke := cablelinewidth * ((frontsts+midsts)++1)/2; charbox; % Have to do it here so the grid type fonts have stuff if (fonttype = gridtype) or (fonttype = bothtype): % Define top and bottom points for k=0 upto totsts: z.bot[k] = (k*wd,-d); z.top[k] = (k*wd,h); penpos.bot[k] (frontstroke, 0); penpos.top[k] (frontstroke, 0); endfor for k=0 upto totsts: labels(bot[k],top[k],bot[k]l,bot[k]r,top[k]l,top[k]r); endfor % Draw the lines on the front cable if slantcutoff > (backsts+midsts-1): for k=1 upto frontsts-1: penstroke z.top[k]e -- z.bot[k+backsts+midsts]e; endfor fi % Draw the left and right lines of the front cable pair temp; temp = (0,whatever); temp = whatever[z.top0l,z.bot[backsts+midsts]l]; fill z.top0r--z.bot[backsts+midsts]r -- z.bot[backsts+midsts]l--temp--z.top0--cycle; pair temp; temp = (w,whatever); temp = whatever[z.bot[totsts]r,z.top[frontsts]r]; fill z.top[frontsts]r--z.top[frontsts]l--z.bot[totsts]l --z.bot[totsts]--temp--cycle; symbolpic1 := currentpicture; % Save this pic for twist front % Draw the back lines pair slip; slip = whatever[(-backstroke,0),(frontsts+midsts,1)+(-backstroke,0)]; slip = whatever * (-backsts,1); % Define some more points for k=0 upto backsts: z.ur[k] = whatever [z.top0,z.bot[backsts+midsts]]; z.ur[k] = whatever [z.bot[k],z.top[frontsts+midsts+k]]; z.ll[k] = whatever [z.bot[totsts],z.top[frontsts]]; z.ll[k] = whatever [z.bot[k],z.top[frontsts+midsts+k]]; endfor % Top back lines fill z.top[totsts]+(-backstroke,0) -- z.top[totsts] -- z.top[totsts]+(0,-ypart(slip)) -- z.ll[backsts]-slip -- z.ll[backsts]+slip --cycle; if midsts > 0: fill z.top[frontsts+midsts]+(-backstroke,0) -- z.top[frontsts+midsts]+(backstroke,0) -- z.ll[0]-slip -- z.ll[0]+slip --cycle; fi if slantcutoff > (frontsts+midsts-1): for k=1 upto backsts-1: fill z.top[frontsts+midsts+k]+(-backstroke,0) -- z.top[frontsts+midsts+k]+(backstroke,0) -- z.ll[k]-slip -- z.ll[k]+slip --cycle; endfor fi symbolpic2 := currentpicture; % Bottom back lines fill z.bot[0]+(backstroke,0) -- z.bot[0] -- z.bot[0]+(0,ypart(slip)) -- z.ur[0]+slip -- z.ur[0]-slip --cycle; if midsts > 0: fill z.bot[backsts]+(backstroke,0) -- z.bot[backsts]-(backstroke,0) -- z.ur[backsts]+slip -- z.ur[backsts]-slip --cycle; fi if slantcutoff > (frontsts+midsts-1): for k=1 upto backsts-1: fill z.bot[k]+(backstroke,0) -- z.bot[k]-(backstroke,0) -- z.ur[k]+slip -- z.ur[k]-slip --cycle; endfor fi fi if fonttype = purltype: z.L = whatever[(0,-d),((frontsts+midsts)*wd,h)]; z.L = whatever[(0,h),((backsts+midsts)*wd,-d)]; z.R = whatever[(w,-d),(w-(backsts+midsts)*wd,h)]; z.R = whatever[(w,h),(w-(frontsts+midsts)*wd,-d)]; if midsts = 0: else: z.top1 = (frontsts*wd,h); z.top2 = ((frontsts+midsts)*wd,h); z.bot1 = (frontsts*wd,-d); z.bot2 = ((frontsts+midsts)*wd,-d); z.top3 = whatever[z.top1,(w,-d)]; z.top3 = whatever[z.top2,(0,-d)]; z.bot3 = whatever[z.bot1,(w,h)]; z.bot3 = whatever[z.bot2,(0,h)]; fill z.top1 -- z.top2 -- z.top3 -- cycle; fill z.bot1 -- z.bot2 -- z.bot3 -- cycle; fi fill (0,-d) -- z.L -- (0,h) --cycle; fill (w,-d) -- z.R -- (w,h) --cycle; fi symbolpic0 := currentpicture; endchar; beginchar(cableright[frontsts][backsts][midsts],totsts * wd#,ht#,dp#); "Cable right " & decimal(frontsts) & " over " &decimal(backsts); currentpicture := symbolpic0 reflectedabout ((w/2,0),(w/2,h)); endchar; beginchar(whitecableleft[frontsts][backsts][midsts],totsts * wd#,ht#,dp#); "White cable " & decimal(frontsts) & " over " &decimal(backsts); if fonttype <> purltype: currentpicture := symbolpic0; fi endchar; beginchar(whitecableright[frontsts][backsts][midsts],totsts * wd#,ht#,dp#); "White cable " & decimal(frontsts) & " over " &decimal(backsts); if fonttype <> purltype: currentpicture := symbolpic0 reflectedabout ((w/2,0),(w/2,h)); fi endchar; if midsts = 0: beginchar(twistleft[frontsts][backsts],totsts * wd#,ht#,dp#); % Twist/twist front "Twist " & decimal(frontsts) & " over " &decimal(backsts); charbox; if fonttype <> purltype: currentpicture := symbolpic1; % Draw some missing lines for k=1 upto backsts-1: z.bot[k] = (k*wd,-d); x.slant.bot[k] = k*wd; z.slant.bot[k] = whatever[(0,h),(backsts*wd,-d)]; draw z.bot[k]--z.slant.bot[k]; z.top[k] = ((frontsts+k)*wd,h); x.slant.top[k] = (frontsts+k)*wd; z.slant.top[k] = whatever[(frontsts*wd,h),(w,-d)]; %whatever[(w,-d),(w-backsts*wd,h)]; draw z.top[k]--z.slant.top[k]; endfor else: fill (0,h)--(wd*backsts,-d)--(0,-d)--cycle; % Bottom triangle fill (w,-d)--(wd*frontsts,h)--(w,h)--cycle; % Top triangle fi symbolpic1 := currentpicture; endchar; beginchar(twistright[frontsts][backsts],totsts * wd#,ht#,dp#); "Twist " & decimal(frontsts) & " over " &decimal(backsts); currentpicture := symbolpic1 reflectedabout ((w/2,0),(w/2,h)); endchar; beginchar(topcableleft[frontsts][backsts],totsts * wd#,ht#,dp#); % Twist/twist front "Cable " & decimal(frontsts) & " over " &decimal(backsts); z.R = whatever[(w,-d),(w-(backsts+midsts)*wd,h)]; z.R = whatever[(w,h),(w-(frontsts+midsts)*wd,-d)]; charbox; if fonttype <> purltype: currentpicture := symbolpic2; else: fill (0,h)--(wd*backsts,-d)--(0,-d)--cycle; % Bottom left triangle fill (w,-d) -- z.R -- (w,h) --cycle; % Right triangle fi symbolpic2 := currentpicture; endchar; beginchar(topcableright[frontsts][backsts],totsts * wd#,ht#,dp#); "Cable " & decimal(frontsts) & " over " &decimal(backsts); currentpicture := symbolpic2 reflectedabout ((w/2,0),(w/2,h)); endchar; beginchar(botcableleft[frontsts][backsts],totsts * wd#,ht#,dp#); "Cable " & decimal(frontsts) & " over " &decimal(backsts); currentpicture := symbolpic2 rotatedaround ((w/2,(h-d)/2),180); endchar; beginchar(botcableright[frontsts][backsts],totsts * wd#,ht#,dp#); "Cable " & decimal(frontsts) & " over " &decimal(backsts); currentpicture := symbolpic2 reflectedabout ((0,(h-d)/2),(w,(h-d)/2)); endchar; beginchar(revcableleft[frontsts][backsts],totsts * wd#,ht#,dp#); % Reverse cable/twist back "Reverse cable left " & decimal(frontsts) & " over " &decimal(backsts); if fonttype <> purltype: currentpicture := symbolpic0; else: purlbox; fi endchar; beginchar(revcableright[frontsts][backsts],totsts * wd#,ht#,dp#); "Reverse cable " & decimal(frontsts) & " over " &decimal(backsts); if fonttype <> purltype: currentpicture := symbolpic0 reflectedabout ((w/2,0),(w/2,h)); else: purlbox; fi endchar; fi else: beginchar(cableleft[frontsts][backsts][midsts],0pt#,ht#,dp#); endchar; beginchar(cableright[frontsts][backsts][midsts],0pt#,ht#,dp#); endchar; beginchar(whitecableleft[frontsts][backsts][midsts],0pt#,ht#,dp#); endchar; beginchar(whitecableright[frontsts][backsts][midsts],0pt#,ht#,dp#); endchar; if midsts = 0: beginchar(twistleft[frontsts][backsts],0pt#,ht#,dp#); endchar; beginchar(twistright[frontsts][backsts],0pt#,ht#,dp#); endchar; beginchar(topcableleft[frontsts][backsts],0pt#,ht#,dp#); endchar; beginchar(topcableright[frontsts][backsts],0pt#,ht#,dp#); endchar; beginchar(botcableleft[frontsts][backsts],0pt#,ht#,dp#); endchar; beginchar(botcableright[frontsts][backsts],0pt#,ht#,dp#); endchar; beginchar(revcableleft[frontsts][backsts],0pt#,ht#,dp#); endchar; beginchar(revcableright[frontsts][backsts],0pt#,ht#,dp#); endchar; fi fi endfor endfor endfor % Ligatures to let kkKK turn into a cable if fonttype <> counttype: cableright[0][1][0] := ASCII"k"; cableleft[1][0][0] := ASCII"K"; revcableright[0][1] := ASCII"p"; revcableleft[1][0] := ASCII"P"; ligtable "c": "k" =: cableright[0][1+1][0], "c" =: cableright[0][1+1][0], "p" =: cableright[1][1][1], "K" =: cableright[1][1][0], "D" =: whitecableright[1][1][0], "N" =: topcableright[1][1]; ligtable "C": "K" =: cableleft[1+1][0][0], "C" =: cableleft[1+1][0][0], "p" =: twistleft[1][1], "k" =: cableleft[1][1][0], "d" =: whitecableleft[1][1][0], "n" =: topcableleft[1][1], "e" =: botcableleft[1][1], "o" =: botcableleft[1][1]; ligtable "g": "p" =: revcableright[0][1+1], "g" =: revcableright[0][1+1], "K" =: twistright[1][1], "P" =: revcableright[1][1], "N" =: botcableright[1][1]; ligtable "G": "P" =: revcableleft[1+1][0], "G" =: revcableleft[1+1][0], "p" =: revcableleft[1][1]; for sts = 1 upto 3: ligtable cableright[0][sts][0]: if sts < 3: "k" =: cableright[0][sts+1][0], "c" =: cableright[0][sts+1][0], "p" =: cableright[sts][sts][1], fi "K" =: cableright[1][sts][0], "D" =: whitecableright[1][sts][0], "N" =: topcableright[1][sts]; ligtable cableleft[sts][0][0]: if sts < 3: "K" =: cableleft[sts+1][0][0], "C" =: cableleft[sts+1][0][0], fi "p" =: twistleft[sts][1], "k" =: cableleft[sts][1][0], "d" =: whitecableleft[sts][1][0], "n" =: topcableleft[sts][1], "e" =: botcableleft[sts][1], "o" =: botcableleft[sts][1]; ligtable revcableright[0][sts]: if sts < 3: "p" =: revcableright[0][sts+1], "g" =: revcableright[0][sts+1], fi "K" =: twistright[1][sts], "P" =: revcableright[1][sts], "N" =: botcableright[1][sts]; ligtable revcableleft[sts][0]: if sts < 3: "P" =: revcableleft[sts+1][0], "G" =: revcableleft[sts+1][0], fi "p" =: revcableleft[sts][1]; endfor for sts = 1 upto 2: ligtable cableleft[sts][sts][1]: if sts > 1: "p" =: cableleft[sts][sts][2], fi "k" =: cableleft[sts][sts][1], "d" =: whitecableleft[sts][sts][1]; ligtable cableright[sts][sts][1]: if sts > 1: "p" =: cableright[sts][sts][2], fi "K" =: cableright[sts][sts][1], "D" =: whitecableright[sts][sts][1]; ligtable whitecableleft[sts][sts][1]: "d" =: whitecableleft[sts][sts][1]; ligtable whitecableright[sts][sts][1]: "D" =: whitecableright[sts][sts][1]; endfor if 6wd# < symbolmaxwd#: ligtable cableleft[2][2][2]: "k" =: cableleft[2][2][2], "d" =: whitecableleft[2][2][2]; ligtable cableright[2][2][2]: "K" =: cableright[2][2][2], "D" =: whitecableright[2][2][2]; ligtable whitecableleft[2][2][2]: "d" =: whitecableleft[2][2][2]; ligtable whitecableright[2][2][2]: "D" =: whitecableright[2][2][2]; fi for backsts = 1 upto 3: for frontsts = 1 upto 3: if frontsts < 3: ligtable cableright[frontsts][backsts][0]: "K" =: cableright[frontsts+1][backsts][0], "N" =: topcableright[frontsts+1][backsts], "D" =: whitecableright[frontsts+1][backsts][0]; ligtable whitecableright[frontsts][backsts][0]: "D" =: whitecableright[frontsts+1][backsts][0]; ligtable topcableright[frontsts][backsts]: "N" =: topcableright[frontsts+1][backsts]; ligtable botcableright[frontsts][backsts]: "N" =: botcableright[frontsts+1][backsts]; ligtable twistright[frontsts][backsts]: "K" =: twistright[frontsts+1][backsts], "N" =: botcableright[frontsts+1][backsts]; ligtable revcableright[frontsts][backsts]: "P" =: revcableright[frontsts+1][backsts]; fi if backsts < 3: ligtable cableleft[frontsts][backsts][0]: "k" =: cableleft[frontsts][backsts+1][0], "n" =: topcableleft[frontsts][backsts+1], "d" =: whitecableleft[frontsts][backsts+1][0]; ligtable whitecableleft[frontsts][backsts][0]: "d" =: whitecableleft[frontsts][backsts+1][0]; ligtable topcableleft[frontsts][backsts]: "n" =: topcableleft[frontsts][backsts+1]; ligtable botcableleft[frontsts][backsts]: "e" =: botcableleft[frontsts][backsts+1], "o" =: botcableleft[frontsts][backsts+1]; ligtable twistleft[frontsts][backsts]: if frontsts < 3: if backsts <= frontsts: "k" =: cableleft[frontsts][frontsts][backsts], "d" =: whitecableleft[frontsts][frontsts][backsts], fi fi "e" =: botcableleft[frontsts][backsts+1], "o" =: botcableleft[frontsts][backsts+1], "p" =: twistleft[frontsts][backsts+1]; ligtable revcableleft[frontsts][backsts]: "p" =: revcableleft[frontsts][backsts+1]; fi endfor endfor fi