GNU Unifont 15.1.04
Pan-Unicode font with complete Unicode Plane 0 coverage and partial coverage of higher planes
johab2syllables.c File Reference

Create the Unicode Hangul Syllables block from component letters. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hangul.h"
Include dependency graph for johab2syllables.c:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 The main function.
 
void print_help ()
 Print a help message.
 

Detailed Description

Create the Unicode Hangul Syllables block from component letters.

This program reads in a "hangul-base.hex" file containing Hangul letters in Johab 6/3/1 format and outputs a Unifont .hex format file covering the Unicode Hangul Syllables range of U+AC00..U+D7A3.

Author
Paul Hardy

Definition in file johab2syllables.c.

Function Documentation

◆ main()

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

The main function.

Definition at line 42 of file johab2syllables.c.

42 {
43 int i; /* Loop variables */
44 int arg_count; /* index into *argv[] */
45 unsigned codept;
46 unsigned max_codept;
47 unsigned char hangul_base[MAX_GLYPHS][32];
48 int initial, medial, final; /* Base glyphs for a syllable. */
49 unsigned char syllable[32]; /* Syllable glyph built for output. */
50
51 FILE *infp = stdin; /* Input Hangul Johab 6/3/1 file */
52 FILE *outfp = stdout; /* Output Hangul Syllables file */
53
54 /* Print a help message */
55 void print_help ();
56
57 /* Read the file containing Hangul base glyphs. */
58 unsigned hangul_read_base8 (FILE *infp, unsigned char hangul_base[][32]);
59
60 /* Given a Hangul Syllables code point, determine component glyphs. */
61 void hangul_decompose (unsigned codept, int *, int *, int *);
62
63 /* Given letters in a Hangul syllable, return a glyph. */
64 void hangul_syllable (int choseong, int jungseong, int jongseong,
65 unsigned char hangul_base[][32],
66 unsigned char *syllable);
67
68
69 /*
70 If there are command line arguments, parse them.
71 */
72 arg_count = 1;
73
74 while (arg_count < argc) {
75 /* If input file is specified, open it for read access. */
76 if (strncmp (argv [arg_count], "-i", 2) == 0) {
77 arg_count++;
78 if (arg_count < argc) {
79 infp = fopen (argv [arg_count], "r");
80 if (infp == NULL) {
81 fprintf (stderr, "\n*** ERROR: Cannot open %s for input.\n\n",
82 argv [arg_count]);
83 exit (EXIT_FAILURE);
84 }
85 }
86 }
87 /* If output file is specified, open it for write access. */
88 else if (strncmp (argv [arg_count], "-o", 2) == 0) {
89 arg_count++;
90 if (arg_count < argc) {
91 outfp = fopen (argv [arg_count], "w");
92 if (outfp == NULL) {
93 fprintf (stderr, "\n*** ERROR: Cannot open %s for output.\n\n",
94 argv [arg_count]);
95 exit (EXIT_FAILURE);
96 }
97 }
98 }
99 /* If help is requested, print help message and exit. */
100 else if (strncmp (argv [arg_count], "-h", 2) == 0 ||
101 strncmp (argv [arg_count], "--help", 6) == 0) {
102 print_help ();
103 exit (EXIT_SUCCESS);
104 }
105
106 arg_count++;
107 }
108
109
110 /*
111 Initialize entire glyph array to zeroes in case the input
112 file skips over some code points.
113 */
114 for (codept = 0; codept < MAX_GLYPHS; codept++) {
115 for (i = 0; i < 32; i++) hangul_base[codept][i] = 0;
116 }
117
118 /*
119 Read the entire "hangul-base.hex" file into an array
120 organized as hangul_base [code_point][glyph_byte].
121 The Hangul glyphs are 16 columns wide, which is
122 two bytes, by 16 rows, for a total of 2 * 16 = 32 bytes.
123 */
124 max_codept = hangul_read_base8 (infp, hangul_base);
125 if (max_codept > 0x8FF) {
126 fprintf (stderr, "\nWARNING: Hangul glyph range exceeds PUA space.\n\n");
127 }
128
129 /*
130 For each glyph in the Unicode Hangul Syllables block,
131 form a composite glyph of choseong + jungseong +
132 optional jongseong and output it in Unifont .hex format.
133 */
134 for (codept = 0xAC00; codept < 0xAC00 + 19 * 21 * 28; codept++) {
135 hangul_decompose (codept, &initial, &medial, &final);
136
137 hangul_syllable (initial, medial, final, hangul_base, syllable);
138
139 fprintf (outfp, "%04X:", codept);
140
141 for (i = 0; i < 32; i++) {
142 fprintf (outfp, "%02X", syllable[i]);
143 }
144 fputc ('\n', outfp);
145 }
146
147 exit (EXIT_SUCCESS);
148}
unsigned hangul_read_base8(FILE *infp, unsigned char base[][32])
Read hangul-base.hex file into a unsigned char array.
void hangul_decompose(unsigned codept, int *initial, int *medial, int *final)
Decompose a Hangul Syllables code point into three letters.
void hangul_syllable(int choseong, int jungseong, int jongseong, unsigned char hangul_base[][32], unsigned char *syllable)
Given letters in a Hangul syllable, return a glyph.
void print_help()
Print a help message.
Here is the call graph for this function:

◆ print_help()

void print_help ( )

Print a help message.

Definition at line 155 of file johab2syllables.c.

155 {
156
157 printf ("\ngen-hangul [options]\n\n");
158 printf (" Generates Hangul syllables from an input Unifont .hex file encoded\n");
159 printf (" in Johab 6/3/1 format. The output is the Unicode Hangul Syllables\n");
160 printf (" range, U+AC00..U+D7A3.\n\n");
161 printf (" This program demonstrates forming Hangul syllables without shifting\n");
162 printf (" the final consonant (jongseong) when combined with a vowel having\n");
163 printf (" a long double vertical stroke. For a program that demonstrtes\n");
164 printf (" shifting jongseong in those cases, see unigen-hangul, which is what\n");
165 printf (" creates the Unifont Hangul Syllables block.\n\n");
166
167 printf (" This program may be invoked with the following command line options:\n\n");
168
169 printf (" Option Parameters Function\n");
170 printf (" ------ ---------- --------\n");
171 printf (" -h, --help Print this message and exit.\n\n");
172 printf (" -i input_file Unifont hangul-base.hex formatted input file.\n\n");
173 printf (" -o output_file Unifont .hex format output file.\n\n");
174 printf (" Example:\n\n");
175 printf (" johab2syllables -i hangul-base.hex -o hangul-syllables.hex\n\n");
176
177 return;
178}
Here is the caller graph for this function: