% Date: 2019/04/05 code := 127; if known debugcables: else: boolean debugcables; debugcables = true; fi beginchar("-",wd#,ht#,dp#); "A knit stitch"; pickup symbol_pen; draw bot (w/2,h-topgap+o) -- top (w/2, -d+bottomgap-o); charbox; endchar; path purlbar; beginchar("=",wd#,ht#,dp#); "A purl stitch"; pickup symbol_pen; lft x1-rt x2 = 0.7standardheight; x1+x2=w; y1=y2=0.5[h,-d]; purlbar = z1--z2; draw purlbar; purlbox; endchar; beginchar(",",incrwidth(0,0),ht#,dp#); "No stitch"; purlbox; endchar; beginchar(".",incrwidth(0,0),ht#,dp#); "No stitch"; charbox; endchar; %Cables kright := incr code; Kright := incr code; pright := incr code; Pright := incr code; nright := incr code; eright := incr code; Nright := incr code; dright := incr code; oright := incr code; Dright := incr code; %if debugcables: kleft := incr code; Kleft := incr code; pleft := incr code; Pleft := incr code; nleft := incr code; eleft := incr code; Nleft := incr code; dleft := incr code; oleft := incr code; Dleft := incr code; %fi % Cable background/foreground blocks (empty cables) cablebgblock := 255; cablefgblock := 254; cablebgblockright := incr code; cablefgblockright := incr code; cablebgblockleft := incr code; cablefgblockleft := incr code; % Grid outlines and empty cables left_cable_grid := incr code; mid_cable_grid := incr code; right_cable_grid_bg := incr code; right_cable_grid_fg := incr code; left_cable_grid_rt := incr code; mid_cable_grid_rt := incr code; right_cable_grid_rt := incr code; % Empty boxes if gridfont: noknitleft := incr code; noknitmid := incr code; noknitright:= incr code; nopurlleft := incr code; nopurlmid := incr code; nopurlright:= incr code; beginchar(noknitleft, if fonttype = counttype: 0 else: wd# fi, ht#, dp#); "Left no stitch"; leftgrid_charbox; endchar; beginchar(noknitmid, if fonttype = counttype: 0 else: wd# fi, ht#, dp#); "Middle no stitch"; topbotgrid_charbox; endchar; beginchar(noknitright, if fonttype = counttype: 0 else: wd# fi, ht#, dp#); "Right no stitch"; rightgrid_charbox; endchar; beginchar(nopurlleft, if fonttype = counttype: 0 else: wd# fi, ht#, dp#); "Left no stitch"; leftgrid_charbox; if fonttype = purltype: fill ( 0,-d)-- (w+nogrid_purlextend,-d)-- (w+nogrid_purlextend, h)-- ( 0, h)--cycle; fi endchar; beginchar(nopurlmid, if fonttype = counttype: 0 else: wd# fi, ht#, dp#); "Middle no stitch"; topbotgrid_charbox; if fonttype = purltype: fill ( -nogrid_purlextend,-d)-- (w+nogrid_purlextend,-d)-- (w+nogrid_purlextend, h)-- ( -nogrid_purlextend, h)--cycle; fi endchar; beginchar(nopurlright, if fonttype = counttype: 0 else: wd# fi, ht#, dp#); "Right no stitch"; rightgrid_charbox; if fonttype = purltype: fill ( -nogrid_purlextend,-d)-- (w,-d)-- (w, h)-- ( -nogrid_purlextend, h)--cycle; fi endchar; ligtable ".": "." =:| noknitleft; ligtable noknitleft: "." |=: noknitright; ligtable noknitright: "." =:| noknitmid; ligtable noknitmid: "." |=: noknitright; ligtable ",": "," =:| nopurlleft; ligtable nopurlleft: "," |=: nopurlright; ligtable nopurlright: "," =:| nopurlmid; ligtable nopurlmid: "," |=: nopurlright; fi % Cable background blocks beginchar(cablebgblock, wd#, ht#, dp#); addto currentpicture also errorsymbol1; endchar; beginchar(cablefgblock, wd#, ht#, dp#); addto currentpicture also errorsymbol1; endchar; beginchar(cablebgblockright, wd#, ht#, dp#); endchar; beginchar(cablefgblockright, wd#, ht#, dp#); endchar; beginchar(cablebgblockleft, wd#, ht#, dp#); endchar; beginchar(cablefgblockleft, wd#, ht#, dp#); endchar; midhoriz := 20; righthoriz := 21; specialhoriz := ASCII"/"; cabletopleft := 15; cablebotleft := 16; cabletopright:= 7; cablebotright:= 8; cableleftslash := 9; cableleftbackslash := 10; cablerightslash := 11; cablerightbackslash := 12; leftslash := 13; rightslash := 14; beginchar("+",wd#,ht#,dp#); "Horizontal cable"; pickup symbol_pen; HCtop = (h-d)/2 + 0.2standardheight; HCbot = (h-d)/2 - 0.2standardheight; HCttop = bot (h-d)/2 + 0.5standardheight + o; HCbbot = top (h-d)/2 - 0.5standardheight - o; y.ul = y.ur = HCtop; y.ll = y.lr = HCbot; x.ul = x.ll = w-x.ur = w-x.lr; x.ur-x.ul = (ht+dp)-2smallgap; symbolpath0 := z.ul--z.ur; symbolpath1 := z.ll--z.lr; draw symbolpath0; draw symbolpath1; symbolpic0 := currentpicture; leftgrid_charbox; endchar; beginchar(midhoriz,wd#,ht#,dp#); "Middle of a horizontal cable"; currentpicture := symbolpic0; topbotgrid_charbox; endchar; beginchar(righthoriz,if fonttype = counttype: 0 else: wd# fi,ht#,dp#); "Right end of a horizontal cable"; currentpicture := symbolpic0; rightgrid_charbox; endchar; ligtable "+": specialhoriz: "+" |=: righthoriz; ligtable righthoriz: "+" |=: righthoriz, specialhoriz =:| midhoriz, righthoriz =:| midhoriz; beginchar(specialhoriz,wd#,ht#,dp#); "Special horizontal cable"; pickup symbol_pen; specialspread = 1.5symbolwidth; y.ul = y.ur = HCtop; y.ll = y.lr = HCbot; x.ul = x.ll = w-x.ur = w-x.lr; x.ur-x.ul = (ht+dp)-2smallgap; draw rt (w/2+specialspread,y.ur)--z.ur; draw rt (w/2+specialspread,y.lr)--z.lr; draw lft (w/2-specialspread,y.ur)--z.ul; draw lft (w/2-specialspread,y.lr)--z.ll; draw (w/2+specialspread,HCttop)--(w/2+specialspread,HCbbot); draw (w/2-specialspread,HCttop)--(w/2-specialspread,HCbbot); topbotgrid_charbox; endchar; beginchar("k",wd#,ht#,dp#); "Knit cable background"; pickup symbol_pen; %if gridfont: %drawdot (w/2, 0.5[botcableheight+cablevertgap,h-topgap]); %else: draw top (w/2, botcableheight+cablevertgap)--bot(w/2,h-topgap); %fi charbox; symbolpic0 := currentpicture; addto currentpicture also errorsymbol1; endchar; beginchar("c",wd#,ht#,dp#); "Knit cable background"; currentpicture := symbolpic0; addto currentpicture also errorsymbol1; endchar; beginchar(kleft,wd#,ht#,dp#); "Knit cable background"; currentpicture := symbolpic0; endchar; beginchar(kright,wd#,ht#,dp#); "Knit cable background"; currentpicture := symbolpic0; endchar; beginchar("p",wd#,ht#,dp#); "Purl cable background"; pickup symbol_pen; %if gridfont: %drawdot (w/2, 0.5[botcableheight+cablevertgap,h-topgap]); %else: draw purlbar; %fi charbox; purlfill; symbolpic0 := currentpicture; addto currentpicture also errorsymbol1; endchar; beginchar("g",wd#,ht#,dp#); "Purl cable background"; currentpicture := symbolpic0; addto currentpicture also errorsymbol1; endchar; beginchar(pright,wd#,ht#,dp#); "Purl cable background"; currentpicture := symbolpic0; endchar; beginchar(pleft,wd#,ht#,dp#); "Purl cable background"; currentpicture := symbolpic0; endchar; beginchar("n",incrwidth(0,1),ht#,dp#); "Back make one"; pickup symbol_pen; drawM(h-topgap, botcableheight+cablevertgap, 0.5wd,symbolwidth); charbox; symbolpic0:=currentpicture; addto currentpicture also errorsymbol1; endchar; beginchar(nright,incrwidth(0,1),ht#,dp#); "Back make one"; currentpicture := symbolpic0; endchar; beginchar(nleft,incrwidth(0,1),ht#,dp#); "Back make one"; currentpicture := symbolpic0; endchar; beginchar("e",incrwidth(0,1),ht#,dp#); "Back purlwise make one"; pickup purl_symbol_pen; drawM(h-topgap, botcableheight+cablevertgap, 0.5wd,purl_symbolwidth); charbox; purlfill; symbolpic0:=currentpicture; addto currentpicture also errorsymbol1; endchar; beginchar(eright,incrwidth(0,1),ht#,dp#); "Back purlwise make one"; currentpicture := symbolpic0; endchar; beginchar(eleft,incrwidth(0,1),ht#,dp#); "Back purlwise make one"; currentpicture := symbolpic0; endchar; beginchar("N",incrwidth(0,1),ht#,dp#); "Front make one"; pickup symbol_pen; drawM(topcableheight-cablevertgap, -d+bottomgap, 0.5wd,symbolwidth); charbox; symbolpic0 := currentpicture; addto currentpicture also errorsymbol1; endchar; beginchar(Nright,incrwidth(0,1),ht#,dp#); "Front make one"; currentpicture := symbolpic0; endchar; beginchar(Nleft,incrwidth(0,1),ht#,dp#); "Front make one"; currentpicture := symbolpic0; endchar; beginchar("d",decrwidth(2,1),ht#,dp#); "Back decrease"; pickup symbol_pen; drawSSK(h-topgap, botcableheight+cablevertgap); charbox; symbolpic0:=currentpicture; addto currentpicture also errorsymbol1; endchar; beginchar(dright,decrwidth(2,1),ht#,dp#); "Back decrease"; fliphoriz(symbolpic0)(currentpicture); endchar; beginchar(dleft,decrwidth(2,1),ht#,dp#); "Back decrease"; currentpicture := symbolpic0; endchar; beginchar("o",decrwidth(2,1),ht#,dp#); "Back purl decrease"; pickup purl_symbol_pen; drawSSK(h-topgap, botcableheight+cablevertgap); charbox; purlfill; symbolpic0:=currentpicture; addto currentpicture also errorsymbol1; endchar; beginchar(oright,decrwidth(2,1),ht#,dp#); "Back purl decrease"; fliphoriz(symbolpic0)(currentpicture); endchar; beginchar(oleft,decrwidth(2,1),ht#,dp#); "Back purl decrease"; currentpicture := symbolpic0;; endchar; beginchar("D",decrwidth(2,1),ht#,dp#); "Front decrease"; pickup symbol_pen; drawSSK(topcableheight-cablevertgap,-d+bottomgap); charbox; symbolpic0:=currentpicture; addto currentpicture also errorsymbol1; endchar; beginchar(Dright,decrwidth(2,1),ht#,dp#); "Front decrease"; fliphoriz(symbolpic0)(currentpicture); endchar; beginchar(Dleft,decrwidth(2,1),ht#,dp#); "Front decrease"; currentpicture := symbolpic0; endchar; beginchar("K",wd#,ht#,dp#); "Knit cable foreground"; pickup symbol_pen; %if gridfont: %drawdot (w/2, 0.5[-d+bottomgap,topcableheight-cablevertgap]); %else: draw top (w/2, -d+bottomgap)--bot(w/2,topcableheight-cablevertgap); %fi charbox; symbolpic0 := currentpicture; addto currentpicture also errorsymbol1; endchar; beginchar("C",wd#,ht#,dp#); "Knit cable foreground"; currentpicture := symbolpic0; addto currentpicture also errorsymbol1; endchar; beginchar(Kright,wd#,ht#,dp#); "Knit cable foreground"; currentpicture := symbolpic0; endchar; beginchar(Kleft,wd#,ht#,dp#); "Knit cable foreground"; currentpicture := symbolpic0; endchar; beginchar("P",wd#,ht#,dp#); "Purl cable foreground"; %if gridfont: %pickup dot_pen; %drawdot (w/2, 0.5[-d+bottomgap,topcableheight-cablevertgap]); %else: pickup symbol_pen; draw purlbar; %fi charbox; purlfill; symbolpic0 := currentpicture; addto currentpicture also errorsymbol1; endchar; beginchar("G",wd#,ht#,dp#); "Purl cable foreground"; currentpicture := symbolpic0; addto currentpicture also errorsymbol1; endchar; beginchar(Pright,wd#,ht#,dp#); "Purl cable foreground"; currentpicture := symbolpic0; endchar; beginchar(Pleft,wd#,ht#,dp#); "Purl cable foreground"; currentpicture := symbolpic0; endchar; beginchar("_",0,ht#,dp#); "Cable bottom connector"; pickup symbol_pen; x2 - x1 = 2wd - cablebargap; 0.5[x1,x2]=0; y1=y2=botcableheight; draw z1--z2; endchar; beginchar("^",0,ht#,dp#); "Cable top connector"; pickup symbol_pen; x2 - x1 = 2wd - cablebargap; 0.5[x1,x2]=0; y1=y2=topcableheight; draw z1--z2; % pickup pensquare scaled symbolwidth; % draw rt (-wd/2,topcableheight) -- lft (wd/2,topcableheight); endchar; beginchar(rightslash,0,ht#,dp#); "Cable right slant connector"; pickup symbol_pen; x4 - x3 = cableslant; 0.5[x3,x4]=0; y3=botcableheight; y4=topcableheight; draw z3--z4; symbolpic0 := currentpicture; endchar; beginchar(leftslash,0,ht#,dp#); "Cable left slant connector"; pickup symbol_pen; x3 - x4 = cableslant; 0.5[x3,x4]=0; y3=botcableheight; y4=topcableheight; draw z3--z4; symbolpic0 := currentpicture; endchar; beginchar(cabletopleft,0,ht#,dp#); "Cable top left connector"; pickup pensquare scaled symbolwidth; rt x2 - lft x1 = wd+2cableextend; lft x1 = -wd + cablebargap/2; y1=y2=topcableheight; symbolpath0 := z1--z2; draw symbolpath0; symbolpic0 := currentpicture; endchar; beginchar(cabletopright,0,ht#,dp#); "Cable top right connector"; currentpicture := symbolpic0 reflectedabout ((0,0),(0,h)); endchar; beginchar(cablebotleft,0,ht#,dp#); "Cable bot left connector"; pickup pensquare scaled symbolwidth; y1=y2=botcableheight; x1 = xpart (point 0 of symbolpath0); x2 = xpart (point 1 of symbolpath0); draw z1--z2; symbolpic0 := currentpicture; endchar; beginchar(cablebotright,0,ht#,dp#); "Cable bot right connector"; currentpicture := symbolpic0 reflectedabout ((0,0),(0,h)); endchar; beginchar(cableleftslash,0,ht#,dp#); "Cable slash connector"; pickup pensquare scaled symbolwidth; y1 = y2 = botcableheight; rt x1 = - cableslant/2; lft x2 = -wd + cablebargap/2; draw z1--z2; symbolpic0 := currentpicture; endchar; beginchar(cablerightbackslash,0,ht#,dp#); "Cable slash connector"; currentpicture := symbolpic0 reflectedabout ((0,0),(0,h)); endchar; beginchar(cableleftbackslash,0,ht#,dp#); "Cable slash connector"; pickup pensquare scaled symbolwidth; y1 = y2 = topcableheight; rt x1 = - cableslant/2; lft x2 = -wd + cablebargap/2; draw z1--z2; symbolpic0 := currentpicture; endchar; beginchar(cablerightslash,0,ht#,dp#); "Cable slash connector"; currentpicture := symbolpic0 reflectedabout ((0,0),(0,h)); endchar; if gridfont: beginchar(left_cable_grid,wd#,ht#,dp#); "Left-end cable outlines"; leftgrid_charbox; endchar; beginchar(mid_cable_grid,wd#,ht#,dp#); "Cable outlines"; topbotgrid_charbox; endchar; beginchar(mid_cable_grid_rt,wd#,ht#,dp#); "Cable outlines"; topbotgrid_charbox; endchar; beginchar(right_cable_grid_bg,wd#,ht#,dp#); "Right-end cable outlines"; rightgrid_charbox; endchar; beginchar(right_cable_grid_fg,wd#,ht#,dp#); "Right-end cable outlines"; rightgrid_charbox; endchar; beginchar(right_cable_grid_rt,wd#,ht#,dp#); "Right-end cable outlines"; rightgrid_charbox; endchar; fi if fonttype = gridtype: ligtable "k": "p": "c": "g": "o": "e": "n": "d": cablebgblock: "k" |=: right_cable_grid_bg, "c" |=: right_cable_grid_bg, "n" |=: right_cable_grid_bg, "d" |=: right_cable_grid_bg, "p" |=: right_cable_grid_bg, "g" |=: right_cable_grid_bg, "e" |=: right_cable_grid_bg, "o" |=: right_cable_grid_bg, cablebgblock |=: right_cable_grid_bg, "K" |=: right_cable_grid_rt, "P" |=: right_cable_grid_rt, "C" |=: right_cable_grid_rt, "G" |=: right_cable_grid_rt, "N" |=: right_cable_grid_rt, "D" |=: right_cable_grid_rt, cablefgblock |=: right_cable_grid_rt, right_cable_grid_rt =:| left_cable_grid, right_cable_grid_bg =:| left_cable_grid; ligtable "K": "P": "C": "G": "N": "D": cablefgblock: "k" |=: right_cable_grid_rt, "c" |=: right_cable_grid_rt, "n" |=: right_cable_grid_rt, "d" |=: right_cable_grid_rt, "p" |=: right_cable_grid_rt, "g" |=: right_cable_grid_rt, "e" |=: right_cable_grid_rt, "o" |=: right_cable_grid_rt, cablebgblock |=: right_cable_grid_rt, "K" |=: right_cable_grid_fg, "P" |=: right_cable_grid_fg, "C" |=: right_cable_grid_fg, "G" |=: right_cable_grid_fg, "N" |=: right_cable_grid_fg, "D" |=: right_cable_grid_fg, cablefgblock |=: right_cable_grid_fg, right_cable_grid_rt =:| left_cable_grid, right_cable_grid_fg =:| left_cable_grid; ligtable right_cable_grid_fg: "k" |=: right_cable_grid_rt, "n" |=: right_cable_grid_rt, "d" |=: right_cable_grid_rt, "p" |=: right_cable_grid_rt, "e" |=: right_cable_grid_rt, "o" |=: right_cable_grid_rt, cablebgblock |=: right_cable_grid_rt, "K" |=: right_cable_grid_fg, "P" |=: right_cable_grid_fg, "C" |=: right_cable_grid_fg, "G" |=: right_cable_grid_fg, "N" |=: right_cable_grid_fg, "D" |=: right_cable_grid_fg, cablefgblock |=: right_cable_grid_fg, right_cable_grid_rt =:| mid_cable_grid, right_cable_grid_fg =:| mid_cable_grid; ligtable right_cable_grid_bg: "k" |=: right_cable_grid_bg, "c" |=: right_cable_grid_bg, "n" |=: right_cable_grid_bg, "d" |=: right_cable_grid_bg, "p" |=: right_cable_grid_bg, "g" |=: right_cable_grid_bg, "e" |=: right_cable_grid_bg, "o" |=: right_cable_grid_bg, cablebgblock |=: right_cable_grid_bg, "K" |=: right_cable_grid_rt, "P" |=: right_cable_grid_rt, "N" |=: right_cable_grid_rt, "D" |=: right_cable_grid_rt, cablefgblock |=: right_cable_grid_rt, right_cable_grid_rt =:| mid_cable_grid, right_cable_grid_bg =:| mid_cable_grid; ligtable right_cable_grid_rt: "k" |=: right_cable_grid_rt, "n" |=: right_cable_grid_rt, "d" |=: right_cable_grid_rt, "p" |=: right_cable_grid_rt, "e" |=: right_cable_grid_rt, "o" |=: right_cable_grid_rt, cablebgblock |=: right_cable_grid_rt, "K" |=: right_cable_grid_rt, "P" |=: right_cable_grid_rt, "N" |=: right_cable_grid_rt, "D" |=: right_cable_grid_rt, cablefgblock |=: right_cable_grid_rt, right_cable_grid_rt =:| mid_cable_grid; fi if fonttype = foretype: for leftglyph = "k", "p", "o", "e", "n", "d", "c", "g", "cablebgblock": if leftglyph = "cablebgblock": leftglyphlig := cablebgblockleft; elseif leftglyph = "c": leftglyphlig := kleft; elseif leftglyph = "g": leftglyphlig := pleft; else: leftglyphlig := scantokens (leftglyph & "left"); fi ligtable if leftglyph = "cablebgblock": cablebgblock else: leftglyph fi: "k" |=:| cablebotleft, "c" |=:| cablebotleft, "n" |=:| cablebotleft, "d" |=:| cablebotleft, "p" |=:| cablebotleft, "g" |=:| cablebotleft, "e" |=:| cablebotleft, "o" |=:| cablebotleft, cablebgblock |=:| cablebotleft, "K" |=:| rightslash, "P" |=:| rightslash, "N" |=:| rightslash, "D" |=:| rightslash, cablefgblock |=:| rightslash, rightslash |=:| cableleftslash, cablebotleft =:| leftglyphlig, cableleftslash =:| leftglyphlig; endfor for leftglyph = "K", "P", "C", "G", "N", "D", "cablefgblock": if leftglyph = "cablefgblock": leftglyphlig := cablefgblockleft; elseif leftglyph = "C": leftglyphlig := Kleft; elseif leftglyph = "G": leftglyphlig := Pleft; else: leftglyphlig := scantokens (leftglyph & "left"); fi ligtable if leftglyph = "cablefgblock": cablefgblock else: leftglyph fi: "K" |=:| cabletopleft, "P" |=:| cabletopleft, "G" |=:| cabletopleft, "C" |=:| cabletopleft, "N" |=:| cabletopleft, "D" |=:| cabletopleft, cablefgblock |=:| cabletopleft, "k" |=:| leftslash, "p" |=:| leftslash, "o" |=:| leftslash, "e" |=:| leftslash, "n" |=:| leftslash, "d" |=:| leftslash, cablebgblock |=:| leftslash, leftslash |=:| cableleftbackslash, cabletopleft =:| leftglyphlig, cableleftbackslash =:| leftglyphlig; endfor ligtable Kright: Pright: Nright: Dright: cablefgblockright: "K" |=: Kright, Kright |=:| cabletopright, "P" |=: Pright, Pright |=:| cabletopright, "N" |=: Nright, Nright |=:| cabletopright, "D" |=: Dright, Dright |=:| cabletopright, cablefgblock |=: cablefgblockright, cablefgblockright |=:| cabletopright; ligtable kright: pright: oright: eright: nright: dright: cablebgblockright: "k" |=: kright, kright |=:| cablebotright, "p" |=: pright, pright |=:| cablebotright, "o" |=: oright, oright |=:| cablebotright, "e" |=: eright, eright |=:| cablebotright, "n" |=: nright, nright |=:| cablebotright, "d" |=: dright, dright |=:| cablebotright, cablebgblock |=: cablebgblockright, cablebgblockright |=:| cablebotright; ligtable rightslash: "K" |=: Kright, Kright |=:| cablerightslash, "P" |=: Pright, Pright |=:| cablerightslash, "N" |=: Nright, Nright |=:| cablerightslash, "D" |=: Dright, Dright |=:| cablerightslash, cablefgblock |=: cablefgblockright, cablefgblockright |=:| cablerightslash; ligtable leftslash: "k" |=: kright, "p" |=: pright, "o" |=: oright, "e" |=: eright, "n" |=: nright, "d" |=: dright, cablebgblock |=: cablebgblockright, kright |=:| cablerightbackslash, nright |=:| cablerightbackslash, dright |=:| cablerightbackslash, pright |=:| cablerightbackslash, eright |=:| cablerightbackslash, oright |=:| cablerightbackslash, cablebgblockright |=:| cablerightbackslash; fi