GNU Unifont: src/unipagecount.c File Reference

GNU Unifont 15.0.02 Pan-Unicode font with complete Unicode Plane 0 coverage and partial coverage of higher planes

Macros | Functions
unipagecount.c File Reference

unipagecount - Count the number of glyphs defined in each page of 256 code points More...

`#include <stdio.h>`
`#include <stdlib.h>`
Include dependency graph for unipagecount.c:

Go to the source code of this file.

## Macros
#define | MAXBUF 256
| Maximum input line size - 1. More...

## Functions
int | main (int argc, char *argv[])
| The main function. More...
void | mkftable (unsigned plane, int pagecount[256], int links)
| Create an HTML table linked to PNG images. More...

## Detailed Description

unipagecount - Count the number of glyphs defined in each page of 256 code points

Author
  Paul Hardy, unifoundry <at> unifoundry.com, December 2007

Copyright
  Copyright (C) 2007, 2008, 2013, 2014 Paul Hardy

This program counts the number of glyphs that are defined in each "page" of 256 code points, and prints the counts in an 8 x 8 grid. Input is from stdin. Output is to stdout.

The background color of each cell in a 16-by-16 grid of 256 code points is shaded to indicate percentage coverage. Red indicates 0% coverage, green represents 100% coverage, and colors in between pure red and pure green indicate partial coverage on a scale.

Each code point range number can be a hyperlink to a PNG file for that 256-code point range's corresponding bitmap glyph image.

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 -P1 -h < font.hex > count.html  -- Plane 1, HTML out
          unipagecount -l < font_file.hex              -- linked HTML table

Definition in file unipagecount.c.

## Macro Definition Documentation

## ◆ MAXBUF

#define MAXBUF 256

Maximum input line size - 1.

Definition at line 56 of file unipagecount.c.

## Function Documentation

## ◆ main()

int main | ( | int | argc,
|  | char * | argv[]
| ) |  |

The main function.

Parameters

  [in] | argc | The count of command line arguments.
  [in] | argv | Pointer to array of command line arguments.

Returns
  This program exits with status 0.

Definition at line 67 of file unipagecount.c.

68{
69
70 char inbuf[MAXBUF]; /* Max 256 characters in an input line */
71 int i, j; /* loop variables */
72 unsigned plane=0; /* Unicode plane number, 0 to 0x16 */
73 unsigned page; /* unicode page (256 bytes wide) */
74 unsigned unichar; /* unicode character */
75 int pagecount[256] = {256 * 0};
76 int onepage=0; /* set to one if printing character grid for one page */
77 int pageno=0; /* page number selected if only examining one page */
78 int html=0; /* =0: print plain text; =1: print HTML */
79 int links=0; /* =1: print HTML links; =0: don't print links */
80 void mkftable(); /* make (print) flipped HTML table */
81
82 size_t strlen();
83
84 if (argc > 1 && argv[1][0] == '-') { /* Parse option */
85 plane = 0;
86 for (i = 1; i < argc; i++) {
87 switch (argv[i][1]) {
88 case 'p': /* specified -p<hexpage> -- use given page number */
89 sscanf (&argv[1][2], "%x", &pageno);
90 if (pageno >= 0 && pageno <= 255) onepage = 1;
91 break;
92 case 'h': /* print HTML table instead of text table */
93 html = 1;
94 break;
95 case 'l': /* print hyperlinks in HTML table */
96 links = 1;
97 html = 1;
98 break;
99 case 'P': /* Plane number specified */
100 plane = atoi(&argv[1][2]);
101 break;
102 }
103 }
104 }
105 /*
106 Initialize pagecount to account for noncharacters.
107 */
108 if (!onepage && plane==0) {
109 pagecount[0xfd] = 32; /* for U+FDD0..U+FDEF */
110 }
111 pagecount[0xff] = 2; /* for U+nnFFFE, U+nnFFFF */
112 /*
113 Read one line at a time from input. The format is:
114
115 <hexpos>:<hexbitmap>
116
117 where <hexpos> is the hexadecimal Unicode character position
118 in the range 00..FF and <hexbitmap> is the sequence of hexadecimal
119 digits of the character, laid out in a grid from left to right,
120 top to bottom. The character is assumed to be 16 rows of variable
121 width.
122 */
123 while (fgets (inbuf, MAXBUF-1, stdin) != NULL) {
124 sscanf (inbuf, "%X", &unichar);
125 page = unichar >> 8;
126 if (onepage) { /* only increment counter if this is page we want */
127 if (page == pageno) { /* character is in the page we want */
128 pagecount[unichar & 0xff]++; /* mark character as covered */
129 }
130 }
131 else { /* counting all characters in all pages */
132 if (plane == 0) {
133 /* Don't add in noncharacters (U+FDD0..U+FDEF, U+FFFE, U+FFFF) */
134 if (unichar < 0xfdd0 || (unichar > 0xfdef && unichar < 0xfffe))
135 pagecount[page]++;
136 }
137 else {
138 if ((page >> 8) == plane) { /* code point is in desired plane */
139 pagecount[page & 0xFF]++;
140 }
141 }
142 }
143 }
144 if (html) {
145 mkftable (plane, pagecount, links);
146 }
147 else { /* Otherwise, print plain text table */
148 if (plane > 0) fprintf (stdout, " ");
149 fprintf (stdout,
150 " 0 1 2 3 4 5 6 7 8 9 A B C D E F\n");
151 for (i=0; i<0x10; i++) {
152 fprintf (stdout,"%02X%X ", plane, i); /* row header */
153 for (j=0; j<0x10; j++) {
154 if (onepage) {
155 if (pagecount[i*16+j])
156 fprintf (stdout," * ");
157 else
158 fprintf (stdout," . ");
159 }
160 else {
161 fprintf (stdout, "%3X ", pagecount[i*16+j]);
162 }
163 }
164 fprintf (stdout,"\n");
165 }
166
167 }
168 exit (0);
169}
mkftable
void mkftable(unsigned plane, int pagecount[256], int links)
Create an HTML table linked to PNG images.
Definition: unipagecount.c:185
MAXBUF
#define MAXBUF
Maximum input line size - 1.
Definition: unipagecount.c:56
Here is the call graph for this function:

## ◆ mkftable()

void mkftable | ( | unsigned | plane,
|  | int | pagecount[256],
|  | int | links
| ) |  |

Create an HTML table linked to PNG images.

This function creates an HTML table to show PNG files in a 16 by 16 grid. The background color of each "page" of 256 code points is shaded from red (for 0% coverage) to green (for 100% coverage).

Parameters

  [in] | plane | The Unicode plane, 0..17.
  [in] | pagecount | Array with count of glyphs in each 256 code point range.
  [in] | links | 1 = generate hyperlinks, 0 = do not generate hyperlinks.

Definition at line 185 of file unipagecount.c.

186{
187 int i, j;
188 int count;
189 unsigned bgcolor;
190
191 printf ("<html>\n");
192 printf ("<body>\n");
193 printf ("<table border=\"3\" align=\"center\">\n");
194 printf (" <tr><th colspan=\"16\" bgcolor=\"#ffcc80\">");
195 printf ("GNU Unifont Glyphs<br>with Page Coverage for Plane %d<br>(Green=100%%, Red=0%%)</th></tr>\n", plane);
196 for (i = 0x0; i <= 0xF; i++) {
197 printf (" <tr>\n");
198 for (j = 0x0; j <= 0xF; j++) {
199 count = pagecount[ (i << 4) | j ];
200
201 /* print link in cell if links == 1 */
202 if (plane != 0 || (i < 0xd || (i == 0xd && j < 0x8) || (i == 0xf && j > 0x8))) {
203 /* background color is light green if completely done */
204 if (count == 0x100) bgcolor = 0xccffcc;
205 /* otherwise background is a shade of yellow to orange to red */
206 else bgcolor = 0xff0000 | (count << 8) | (count >> 1);
207 printf (" <td bgcolor=\"#%06X\">", bgcolor);
208 if (plane == 0)
209 printf ("<a href=\"png/plane%02X/uni%02X%X%X.png\">%X%X</a>", plane, plane, i, j, i, j);
210 else
211 printf ("<a href=\"png/plane%02X/uni%02X%X%X.png\">%02X%X%X</a>", plane, plane, i, j, plane, i, j);
212 printf ("</td>\n");
213 }
214 else if (i == 0xd) {
215 if (j == 0x8) {
216 printf (" <td align=\"center\" colspan=\"8\" bgcolor=\"#cccccc\">");
217 printf ("<b>Surrogate Pairs</b>");
218 printf ("</td>\n");
219 } /* otherwise don't print anything more columns in this row */
220 }
221 else if (i == 0xe) {
222 if (j == 0x0) {
223 printf (" <td align=\"center\" colspan=\"16\" bgcolor=\"#cccccc\">");
224 printf ("<b>Private Use Area</b>");
225 printf ("</td>\n");
226 } /* otherwise don't print any more columns in this row */
227 }
228 else if (i == 0xf) {
229 if (j == 0x0) {
230 printf (" <td align=\"center\" colspan=\"9\" bgcolor=\"#cccccc\">");
231 printf ("<b>Private Use Area</b>");
232 printf ("</td>\n");
233 }
234 }
235 }
236 printf (" </tr>\n");
237 }
238 printf ("</table>\n");
239 printf ("</body>\n");
240 printf ("</html>\n");
241
242 return;
243}
Here is the caller graph for this function: