#! /usr/bin/awk -f # # awk script to convert KiCAD font. BEGIN { print "/* Automatically converted font */" missed = 0 printstats = 1 code0 = 82 # ascii code for R scale = 50 base = 9 fontend = "" symdef = "DEL" cap_height = -21 x_height = -14 sym_height = -16 sup_offset = -13 sub_offset = 6 # transformations props # SX SY OY transf["!"] = "-1 +1 0" # revert transf["-"] = "+1 -1 "x_height # invert small transf["="] = "+1 -1 "cap_height # invert cap transf["~"] = "+1 -1 "sym_height # invert symbol transf["+"] = "-1 -1 "x_height # turn small transf["%"] = "-1 -1 "cap_height # turn cap transf["*"] = "-1 -1 "sym_height # turn symbol transf["^"] = "+1 +1 "sup_offset # superscript transf["`"] = "-1 +1 "sup_offset # superscript reversed transf["."] = "+1 +1 "sub_offset # subscript transf[","] = "-1 +1 "sub_offset # subscript reversed } function ntochar(x) { return sprintf("%c",x+code0) } function cname(glyph) { if(substr(glyph,1,1) in transf) { return substr(glyph,2) } else { return glyph } } function gsx(glyph, tr) { if(substr(glyph,1,1) in transf) { tr = transf[substr(glyph,1,1)] return 0+substr(tr,1,2) } else { return 1; } } function gsy(glyph, tr) { if(substr(glyph,1,1) in transf) { tr = transf[substr(glyph,1,1)] return 0+substr(tr,4,2) } else { return 1; } } function goy(glyph, tr) { #print "// "substr(glyph,1,1) if(substr(glyph,1,1) in transf) { tr = transf[substr(glyph,1,1)] return 0+substr(tr,7) } else { return 0; } } function graph(glyph, subst, ofx, ofy, sx, sy, cn, data, i, j, o, c) { if(subst=="")subst=symdef if(ofx=="") ofx = 0 if(ofy=="") ofy = 0 if(!(cname(glyph) in fontnst)) { print " /* glyph "glyph" not found!!! */" glyph = subst } sx = gsx(glyph) sy = gsy(glyph) ofy += goy(glyph) + base #print "/* g ofx="ofx" ofy="ofy" */" cn = cname(glyph) data = "" for(i = 0; i0) data = data " R" for(j = 0; j0 && $2=="~" || $2=="S") { xright = $4/scale fontmr[name] = $4/scale # print "//Right:" xright } else if($4<=0 && $2=="~" || $2=="P") { xleft = $4/scale fontml[name] = $4/scale # print "//Left:" xleft } } $1 == "ENDDEF" { metr = ntochar(xleft) ntochar(xright) fontnst[name] = nst fontuse[name] = 0 fi[name] = name } # parsing font index $1 == "font" { print fontend print "const static char* "$2"[] =" print "{" fontend = "};" } $1 == "startchar" { codeno = $2 } $1 == "+" || $1 == "+w" || $1 == "+p" { comx = 0 rem = (codeno%16)?"":sprintf(" /* U+%X %s %s */", codeno, $2, $3) #print "// c "codeno codeno+=1 str = compose() met = ("+w"==$1) ? metric2($2, $3, 0, ofx2) : ("+p"==$1) ? metric2($3, $2, ofx2, 0) : metric($2) print " \""cesc(met str) "\","rem } $1 == "+(" { comx = 0 rem = (codeno%16)?"":sprintf(" /* U+%X %s %s */", codeno, $2, $3) #print "// c "codeno codeno+=1 str = compose(comx) gf = $2 gp = $2 } $1 == "+|" { comx = comx + dist(gp, $2) #print "// "comx str = str " R" compose(comx) gp = $2 } $1 == "+)" { comx = comx + dist(gp, $2) #print "// "comx str = str " R" compose(comx) met = metric2(gf, $2, 0, comx) print " \"" cesc(met str) "\","rem } $1 == "skipcodes" { #print " // skip "$2 for(i = 0; i<$2; i++) { print " \""cesc(metric(symdef) graph(symdef))"\"," ((codeno%16)?"":sprintf(" /* U+%X */", codeno)) codeno += 1 } } $1 == "//" { print " /* "$0" */" } $1 == "stats" { printstats = $2 } END { print fontend if(printstats) { if(missed>0) print "/* Missed glyphs: " missed " */" print "/* --- unused glyphs --- */" for(f in fi) { if(0==fontuse[f]) print "/* "f" */" } } }