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

Generate arbitrary hangul syllables. More...

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

Go to the source code of this file.

Data Structures

struct  PARAMS
 

Functions

int main (int argc, char *argv[])
 Program entry point. More...
 
void parse_args (int argc, char *argv[], struct PARAMS *params)
 Parse command line arguments.
 
void get_hex_range (char *instring, unsigned *start, unsigned *end)
 Scan a hexadecimal range from a character string.
 

Detailed Description

Generate arbitrary hangul syllables.

Input is a Unifont .hex file such as the "hangul-base.hex" file that is included in the Unifont package.

The default program parameters will generate the Unicode Hangul Syllables range of U+AC00..U+D7A3. The syllables will appear in this order:

 For each modern choseong {
    For each modern jungseong {
       Output syllable of choseong and jungseong
       For each modern jongseong {
          Output syllable of choseong + jungseong + jongseong
       }
    }
 }

By starting the jongseong code point at one before the first valid jongseong, the first inner loop iteration will add a blank glyph for the jongseong portion of the syllable, so only the current choseong and jungseong will be output first.

Author
Paul Hardy

Definition in file unigen-hangul.c.

Function Documentation

◆ main()

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

Program entry point.

Default parameters for Hangul syllable generation.

Definition at line 69 of file unigen-hangul.c.

69  {
70 
71  int i; /* loop variable */
72  unsigned codept;
73  unsigned max_codept;
74  unsigned glyph[MAX_GLYPHS][16];
75  unsigned tmp_glyph [16]; /* To build one combined glyph at a time. */
76  int cho, jung, jong; /* The 3 components in a Hangul syllable. */
77 
78  /// Default parameters for Hangul syllable generation.
79  struct PARAMS params = { 0xAC00, /* Starting output Unicode code point */
80  0x1100, /* First modern choseong */
81  0x1112, /* Last modern choseong */
82  0x1161, /* First modern jungseong */
83  0x1175, /* Last modern jungseong */
84  0x11A7, /* One before first modern jongseong */
85  0x11C2, /* Last modern jongseong */
86  stdin, /* Default input file pointer */
87  stdout /* Default output file pointer */
88  };
89 
90  void parse_args (int argc, char *argv[], struct PARAMS *params);
91 
92  unsigned hangul_read_base16 (FILE *infp, unsigned glyph[][16]);
93 
94  void print_glyph_hex (FILE *fp, unsigned codept, unsigned *this_glyph);
95 
96  void combined_jamo (unsigned glyph [MAX_GLYPHS][16],
97  unsigned cho, unsigned jung, unsigned jong,
98  unsigned *combined_glyph);
99 
100 
101  if (argc > 1) {
102  parse_args (argc, argv, &params);
103 
104 #ifdef DEBUG
105  fprintf (stderr,
106  "Range: (U+%04X, U+%04X, U+%04X) to (U+%04X, U+%04X, U+%04X)\n",
107  params.cho_start, params.jung_start, params.jong_start,
108  params.cho_end, params.jung_end, params.jong_end);
109 #endif
110  }
111 
112  /*
113  Initialize glyph array to all zeroes.
114  */
115  for (codept = 0; codept < MAX_GLYPHS; codept++) {
116  for (i = 0; i < 16; i++) glyph[codept][i] = 0x0000;
117  }
118 
119  /*
120  Read Hangul base glyph file.
121  */
122  max_codept = hangul_read_base16 (params.infp, glyph);
123  if (max_codept > 0x8FF) {
124  fprintf (stderr, "\nWARNING: Hangul glyph range exceeds PUA space.\n\n");
125  }
126 
127  codept = params.starting_codept; /* First code point to output */
128 
129  for (cho = params.cho_start; cho <= params.cho_end; cho++) {
130  for (jung = params.jung_start; jung <= params.jung_end; jung++) {
131  for (jong = params.jong_start; jong <= params.jong_end; jong++) {
132 
133 #ifdef DEBUG
134  fprintf (params.outfp,
135  "(U+%04X, U+%04X, U+%04X)\n",
136  cho, jung, jong);
137 #endif
138  combined_jamo (glyph, cho, jung, jong, tmp_glyph);
139  print_glyph_hex (params.outfp, codept, tmp_glyph);
140  codept++;
141  if (jong == JONG_UNICODE_END)
142  jong = JONG_EXTB_UNICODE_START - 1; /* Start Extended-B range */
143  }
144  if (jung == JUNG_UNICODE_END)
145  jung = JUNG_EXTB_UNICODE_START - 1; /* Start Extended-B range */
146  }
147  if (cho == CHO_UNICODE_END)
148  cho = CHO_EXTA_UNICODE_START - 1; /* Start Extended-A range */
149  }
150 
151  if (params.infp != stdin) fclose (params.infp);
152  if (params.outfp != stdout) fclose (params.outfp);
153 
154  exit (EXIT_SUCCESS);
155 }
void print_glyph_hex(FILE *fp, unsigned codept, unsigned *this_glyph)
Print one glyph in Unifont hexdraw hexadecimal string style.
void combined_jamo(unsigned glyph_table[MAX_GLYPHS][16], unsigned cho, unsigned jung, unsigned jong, unsigned *combined_glyph)
Convert Hangul Jamo choseong, jungseong, and jongseong into a glyph.
#define JONG_UNICODE_END
Modern Hangul jongseong end.
Definition: hangul.h:61
#define JUNG_EXTB_UNICODE_START
Hangul Extended-B jungseong start.
Definition: hangul.h:57
#define CHO_EXTA_UNICODE_START
Hangul Extended-A choseong start.
Definition: hangul.h:52
#define CHO_UNICODE_END
Hangul Jamo choseong end.
Definition: hangul.h:51
#define JONG_EXTB_UNICODE_START
Hangul Extended-B jongseong start.
Definition: hangul.h:62
#define JUNG_UNICODE_END
Modern Hangul jungseong end.
Definition: hangul.h:56
unsigned hangul_read_base16(FILE *infp, unsigned base[][16])
Read hangul-base.hex file into a unsigned array.
#define MAX_GLYPHS
An OpenType font has at most 65536 glyphs.
Definition: hex2otf.c:85
void parse_args(int argc, char *argv[], struct PARAMS *params)
Parse command line arguments.
Here is the call graph for this function: