GNU Unifont: src/unibdf2hex.c Source File

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

unibdf2hex.c
Go to the documentation of this file.
1/**
2 @file unibdf2hex.c
3
4 @brief unibdf2hex - Convert a BDF file into a unifont.hex file
5
6 @author Paul Hardy, January 2008
7
8 @copyright Copyright (C) 2008, 2013 Paul Hardy
9
10 Note: currently this has hard-coded code points for glyphs extracted
11 from Wen Quan Yi to create the Unifont source file "wqy.hex".
12*/
13/*
14 LICENSE:
15
16 This program is free software: you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation, either version 2 of the License, or
19 (at your option) any later version.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
28*/
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33
34#define UNISTART 0x3400 ///< First Unicode code point to examine
35#define UNISTOP 0x4DBF ///< Last Unicode code point to examine
36
37#define MAXBUF 256 ///< Maximum allowable input file line length - 1
38
39
40/**
41 @brief The main function.
42
43 @return Exit status is always 0 (successful termination).
44*/
45int
46main()
47{
48 int i;
49 int digitsout; /* how many hex digits we output in a bitmap */
50 int thispoint;
51 char inbuf[MAXBUF];
52 int bbxx, bbxy, bbxxoff, bbxyoff;
53
54 int descent=4; /* font descent wrt baseline */
55 int startrow; /* row to start glyph */
56 unsigned rowout;
57
58 while (fgets (inbuf, MAXBUF - 1, stdin) != NULL) {
59 if (strncmp (inbuf, "ENCODING ", 9) == 0) {
60 sscanf (&inbuf[9], "%d", &thispoint); /* get code point */
61 /*
62 If we want this code point, get the BBX (bounding box) and
63 BITMAP information.
64 */
65 if ((thispoint >= 0x2E80 && thispoint <= 0x2EFF) || // CJK Radicals Supplement
66 (thispoint >= 0x2F00 && thispoint <= 0x2FDF) || // Kangxi Radicals
67 (thispoint >= 0x2FF0 && thispoint <= 0x2FFF) || // Ideographic Description Characters
68 (thispoint >= 0x3001 && thispoint <= 0x303F) || // CJK Symbols and Punctuation (U+3000 is a space)
69 (thispoint >= 0x3100 && thispoint <= 0x312F) || // Bopomofo
70 (thispoint >= 0x31A0 && thispoint <= 0x31BF) || // Bopomofo extend
71 (thispoint >= 0x31C0 && thispoint <= 0x31EF) || // CJK Strokes
72 (thispoint >= 0x3400 && thispoint <= 0x4DBF) || // CJK Unified Ideographs Extension A
73 (thispoint >= 0x4E00 && thispoint <= 0x9FCF) || // CJK Unified Ideographs
74 (thispoint >= 0xF900 && thispoint <= 0xFAFF)) // CJK Compatibility Ideographs
75 {
76 while (fgets (inbuf, MAXBUF - 1, stdin) != NULL &&
77 strncmp (inbuf, "BBX ", 4) != 0); /* find bounding box */
78
79 sscanf (&inbuf[4], "%d %d %d %d", &bbxx, &bbxy, &bbxxoff, &bbxyoff);
80 while (fgets (inbuf, MAXBUF - 1, stdin) != NULL &&
81 strncmp (inbuf, "BITMAP", 6) != 0); /* find bitmap start */
82 fprintf (stdout, "%04X:", thispoint);
83 digitsout = 0;
84 /* Print initial blank rows */
85 startrow = descent + bbxyoff + bbxy;
86
87 /* Force everything to 16 pixels wide */
88 for (i = 16; i > startrow; i--) {
89 fprintf (stdout,"0000");
90 digitsout += 4;
91 }
92 while (fgets (inbuf, MAXBUF - 1, stdin) != NULL &&
93 strncmp (inbuf, "END", 3) != 0) { /* copy bitmap until END */
94 sscanf (inbuf, "%X", &rowout);
95 /* Now force glyph to a 16x16 grid even if they'd fit in 8x16 */
96 if (bbxx <= 8) rowout <<= 8; /* shift left for 16x16 glyph */
97 rowout >>= bbxxoff;
98 fprintf (stdout, "%04X", rowout);
99 digitsout += 4;
100 }
101
102 /* Pad for 16x16 glyph */
103 while (digitsout < 64) {
104 fprintf (stdout,"0000");
105 digitsout += 4;
106 }
107 fprintf (stdout,"\n");
108 }
109 }
110 }
111 exit (0);
112}
MAXBUF
#define MAXBUF
Maximum allowable input file line length - 1.
Definition: unibdf2hex.c:37
main
int main()
The main function.
Definition: unibdf2hex.c:46