/* unipagecount - program to count the number of glyphs defined in each page of 256 bytes, and print them in an 8 x 8 grid. Input is from stdin. Output is to stdout. Synopsis: unipagecount < font_file.hex > count.txt unipagecount -phex_page_num < font_file.hex -- just 256 points unipagecount -h < font_file.hex -- HTML table unipagecount -l < font_file.hex -- linked HTML table Author: Paul Hardy, unifoundry unifoundry.com, December 2007 Copyright (C) 2007-2008 Paul Hardy This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #define MAXBUF 256 /* maximum input line size */ int main(int argc, char *argv[]) { char inbuf[MAXBUF]; /* Max 256 characters in an input line */ int i, j; /* loop variables */ unsigned page; /* unicode page (256 bytes wide) */ unsigned unichar; /* unicode character */ int pagecount[256] = {256 * 0}; int onepage=0; /* set to one if printing character grid for one page */ int pageno=0; /* page number selected if only examining one page */ int html=0; /* =0: print plain text; =1: print HTML */ int links=0; /* =1: print HTML links; =0: don't print links */ void mkftable(); /* make (print) flipped HTML table */ size_t strlen(); if (argc > 1 && argv[1][0] == '-') { /* Parse option */ switch (argv[1][1]) { case 'p': /* specified -p -- use given page number */ sscanf(&argv[1][2], "%x", &pageno); if (pageno >= 0 && pageno <= 255) onepage = 1; break; case 'h': /* print HTML table instead of text table */ html = 1; break; case 'l': /* print hyperlinks in HTML table */ links = 1; html = 1; break; } } /* Initialize pagecount to account for noncharacters. */ if (!onepage) { pagecount[0xfd] = 32; /* for U+FDD0..U+FDEF */ pagecount[0xff] = 2; /* for U+FFFE, U+FFFF */ } /* Read one line at a time from input. The format is: : where is the hexadecimal Unicode character position in the range 00..FF and is the sequence of hexadecimal digits of the character, laid out in a grid from left to right, top to bottom. The character is assumed to be 16 rows of variable width. */ while (fgets(inbuf, MAXBUF-1, stdin) != NULL) { sscanf(inbuf, "%X", &unichar); page = unichar >> 8; if (onepage) { /* only increment counter if this is page we want */ if (page == pageno) { /* character is in the page we want */ pagecount[unichar & 0xff]++; /* mark character as covered */ } } else { /* counting all characters in all pages */ /* Don't add in noncharacters (U+FDD0..U+FDEF, U+FFFE, U+FFFF) */ if (unichar < 0xfdd0 || (unichar > 0xfdef && unichar < 0xfffe)) pagecount[page]++; } } if (html) { mkftable(pagecount, links); } else { /* Otherwise, print plain text table */ fprintf(stdout, " 0 1 2 3 4 5 6 7 8 9 A B C D E F\n"); for (i=0; i<0x10; i++) { fprintf(stdout,"%X ", i); /* row header */ for (j=0; j<0x10; j++) { if (onepage) { if (pagecount[i*16+j]) fprintf(stdout," * "); else fprintf(stdout," . "); } else { fprintf(stdout, "%3X ", pagecount[i*16+j]); } } fprintf(stdout,"\n"); } } exit(0); } /* mkftable - function to create an HTML table to show flipped bmp files in a 16 by 16 grid. */ void mkftable(int pagecount[256], int links) { int i, j; int count; unsigned bgcolor; printf("\n"); printf("\n"); printf("\n"); printf(" \n"); for (i = 0x0; i <= 0xF; i++) { printf(" \n"); for (j = 0x0; j <= 0xF; j++) { count = pagecount[ (i << 4) | j ]; /* print link in cell if links == 1 */ if (i < 0xd || (i == 0xd && j < 0x8) || (i == 0xf && j > 0x8)) { /* background color is light green if completely done */ if (count == 0x100) bgcolor = 0xccffcc; /* otherwise background is a shade of yellow to orange to red */ else bgcolor = 0xff0000 | (count << 8) | (count >> 1); printf(" \n"); } else if (i == 0xd) { if (j == 0x8) { printf(" \n"); } /* otherwise don't print anything more columns in this row */ } else if (i == 0xe) { if (j == 0x0) { printf(" \n"); } /* otherwise don't print any more columns in this row */ } else if (i == 0xf) { if (j == 0x0) { printf(" \n"); } } } printf(" \n"); } printf("
"); printf("GNU Unifont Page Coverage
(Green=100%%, Red=0%%)
", bgcolor); printf("%X%X", i, j, i, j); printf(""); printf("Surrogate Pairs"); printf(""); printf("Private Use"); printf(""); printf("Private Use"); printf("
\n"); printf("\n"); printf("\n"); return; }