### /u/sy/beebe/src/awk/afm-width-statistics.awk, Tue Jun 5 08:43:49 2001 ### Edit by Nelson H. F. Beebe ### ==================================================================== ### Collect statistics on font widths from one or more .afm (Adobe Font ### Metric) files. ### ### Usage: ### awk -f afm-width-statistics.awk afm-file(s) ### ### [08-Sep-2001] -- use StartCharMetrics value, instead of counting ### characters, and add new_font() to reset counters ### [05-Jun-2001] -- original version ### ==================================================================== BEGIN { LAST_FILENAME = "" } { gsub("\r","") } # strip CRs (CRLF -> LF) $1 == "FontName" { new_font($2) } $1 == "StartCharMetrics" { Nchars[FontName] = $2 } $1 == "C" { do_C(0 + $2, 0 + $5) } END { report() } ### ==================================================================== function do_C(chnum,width) { ## Typical lines: ## C 48 ; WX 719 ; N zero ; B 63 -7 675 723 ; ## C 63 ; WX 292 ; N question ; B 41 -5 258 723 ; ## C -1 ; WX 813 ; N Acircumflex ; B 12 0 815 840 ; Width[FontName] += width if ((48 <= chnum) && (chnum <= 57)) # digit { NNUM[FontName]++ Number_Width[FontName] += width } else if ((65 <= chnum) && (chnum <= 90)) { UCNUM[FontName]++ UC_Width[FontName] += width } else if ((97 <= chnum) && (chnum <= 122)) { LCNUM[FontName]++ LC_Width[FontName] += width } } function max(a,b) { return ((a > b) ? a : b) } function new_font(s) { FontName = s last_filename = FILENAME LCNUM[FontName] = 0 LC_Width[FontName] = 0 NNUM[FontName] = 0 Number_Width[FontName] = 0 UCNUM[FontName] = 0 UC_Width[FontName] = 0 } function report( font,sort_pipe) { printf("%s\n", \ "----------------------------------------------------------------------------------------"); printf("%-39s\t%s\n", \ "", \ " Average Character Widths"); printf("%-31s\t%7s\t%7s\t%7s\t%7s\t%7s\t%7s\n", \ "FontName", \ "Chars", \ "Letters", \ "All", \ "Digits", \ "Upper", \ "Lower") printf("%s\n", \ "----------------------------------------------------------------------------------------"); sort_pipe = "sort -t'\t' -k 3n -k 1f -u" for (font in Nchars) { printf("%-39s\t%7d\t%7.2f\t%7.2f\t%7.2f\t%7.2f\t%7.2f\n", \ font, \ Nchars[font], \ (UC_Width[font] + LC_Width[font])/max(1,UCNUM[font] + LCNUM[font]), \ Width[font]/max(1,Nchars[font]), \ Number_Width[font]/max(1,NNUM[font]), \ UC_Width[font]/max(1,UCNUM[font]), \ LC_Width[font]/max(1,LCNUM[font])) | sort_pipe } close(sort_pipe) printf("%s\n", \ "----------------------------------------------------------------------------------------"); }