GNU Unifont: src/unipagecount.c File Reference

GNU Unifont 15.1.03 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.

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

## 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 59 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 70 of file unipagecount.c.

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

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