GNU Unifont: src/hangul.h Source File

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

hangul.h
Go to the documentation of this file.
1/**
2 @file hangul.h
3
4 @brief Define constants and function prototypes for using Hangul glyphs.
5
6 @author Paul Hardy
7
8 @copyright Copyright © 2023 Paul Hardy
9*/
10/*
11 LICENSE:
12
13 This program is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
25*/
26
27#ifndef _HANGUL_H_
28#define _HANGUL_H_
29
30#include <stdlib.h>
31
32
33#define MAXLINE 256 ///< Length of maximum file input line.
34
35#define EXTENDED_HANGUL /* Use rare Hangul code points beyond U+1100 */
36
37/* Definitions to move Hangul .hex file contents into the Private Use Area. */
38#define PUA_START 0xE000
39#define PUA_END 0xE8FF
40#define MAX_GLYPHS (PUA_END - PUA_START + 1) /* Maximum .hex file glyphs */
41
42/*
43 Unicode ranges for Hangul choseong, jungseong, and jongseong.
44
45 U+1100..U+11FF is the main range of modern and ancient Hangul jamo.
46 U+A960..U+A97C is the range for extended Hangul choseong.
47 U+D7B0..U+D7C6 is the range for extended Hangul jungseong.
48 U+D7CB..U+D7FB is the range for extended Hangul jongseong.
49*/
50#define CHO_UNICODE_START 0x1100 ///< Modern Hangul choseong start
51#define CHO_UNICODE_END 0x115E ///< Hangul Jamo choseong end
52#define CHO_EXTA_UNICODE_START 0xA960 ///< Hangul Extended-A choseong start
53#define CHO_EXTA_UNICODE_END 0xA97C ///< Hangul Extended-A choseong end
54
55#define JUNG_UNICODE_START 0x1161 ///< Modern Hangul jungseong start
56#define JUNG_UNICODE_END 0x11A7 ///< Modern Hangul jungseong end
57#define JUNG_EXTB_UNICODE_START 0xD7B0 ///< Hangul Extended-B jungseong start
58#define JUNG_EXTB_UNICODE_END 0xD7C6 ///< Hangul Extended-B jungseong end
59
60#define JONG_UNICODE_START 0x11A8 ///< Modern Hangul jongseong start
61#define JONG_UNICODE_END 0x11FF ///< Modern Hangul jongseong end
62#define JONG_EXTB_UNICODE_START 0xD7CB ///< Hangul Extended-B jongseong start
63#define JONG_EXTB_UNICODE_END 0xD7FB ///< Hangul Extended-B jongseong end
64
65
66/*
67 Number of modern and ancient letters in hangul-base.hex file.
68*/
69#define NCHO_MODERN 19 ///< 19 modern Hangul Jamo choseong
70#define NCHO_ANCIENT 76 ///< ancient Hangul Jamo choseong
71#define NCHO_EXTA 29 ///< Hangul Extended-A choseong
72#define NCHO_EXTA_RSRVD 3 ///< Reserved at end of Extended-A choseong
73
74#define NJUNG_MODERN 21 ///< 21 modern Hangul Jamo jungseong
75#define NJUNG_ANCIENT 50 ///< ancient Hangul Jamo jungseong
76#define NJUNG_EXTB 23 ///< Hangul Extended-B jungseong
77#define NJUNG_EXTB_RSRVD 4 ///< Reserved at end of Extended-B junseong
78
79#define NJONG_MODERN 27 ///< 28 modern Hangul Jamo jongseong
80#define NJONG_ANCIENT 61 ///< ancient Hangul Jamo jongseong
81#define NJONG_EXTB 49 ///< Hangul Extended-B jongseong
82#define NJONG_EXTB_RSRVD 4 ///< Reserved at end of Extended-B jonseong
83
84
85/*
86 Number of variations of each component in a Johab 6/3/1 arrangement.
87*/
88#define CHO_VARIATIONS 6 ///< 6 choseong variations
89#define JUNG_VARIATIONS 3 ///< 3 jungseong variations
90#define JONG_VARIATIONS 1 ///< 1 jongseong variation
91
92/*
93 Starting positions in the hangul-base.hex file for each component.
94*/
95/// Location of first choseong (location 0x0000 is a blank glyph)
96#define CHO_HEX 0x0001
97
98/// Location of first ancient choseong
99#define CHO_ANCIENT_HEX (CHO_HEX + CHO_VARIATIONS * NCHO_MODERN)
100
101/// U+A960 Extended-A choseong
102#define CHO_EXTA_HEX (CHO_ANCIENT_HEX + CHO_VARIATIONS * NCHO_ANCIENT)
103
104/// U+A97F Extended-A last location in .hex file, including reserved Unicode code points at end
105#define CHO_LAST_HEX (CHO_EXTA_HEX + CHO_VARIATIONS * (NCHO_EXTA + NCHO_EXTA_RSRVD) - 1)
106
107/// Location of first jungseong (will be 0x2FB)
108#define JUNG_HEX (CHO_LAST_HEX + 1)
109
110/// Location of first ancient jungseong
111#define JUNG_ANCIENT_HEX (JUNG_HEX + JUNG_VARIATIONS * NJUNG_MODERN)
112
113/// U+D7B0 Extended-B jungseong
114#define JUNG_EXTB_HEX (JUNG_ANCIENT_HEX + JUNG_VARIATIONS * NJUNG_ANCIENT)
115
116/// U+D7CA Extended-B last location in .hex file, including reserved Unicode code points at end
117#define JUNG_LAST_HEX (JUNG_EXTB_HEX + JUNG_VARIATIONS * (NJUNG_EXTB + NJUNG_EXTB_RSRVD) - 1)
118
119/// Location of first jongseong (will be 0x421)
120#define JONG_HEX (JUNG_LAST_HEX + 1)
121
122/// Location of first ancient jongseong
123#define JONG_ANCIENT_HEX (JONG_HEX + JONG_VARIATIONS * NJONG_MODERN)
124
125/// U+D7CB Extended-B jongseong
126#define JONG_EXTB_HEX (JONG_ANCIENT_HEX + JONG_VARIATIONS * NJONG_ANCIENT)
127
128/// U+D7FF Extended-B last location in .hex file, including reserved Unicode code points at end
129#define JONG_LAST_HEX (JONG_EXTB_HEX + JONG_VARIATIONS * (NJONG_EXTB + NJONG_EXTB_RSRVD) - 1)
130
131/* Common modern and ancient Hangul Jamo range */
132#define JAMO_HEX 0x0500 ///< Start of U+1100..U+11FF glyphs
133#define JAMO_END 0x05FF ///< End of U+1100..U+11FF glyphs
134
135/* Hangul Jamo Extended-A range */
136#define JAMO_EXTA_HEX 0x0600 ///< Start of U+A960..U+A97F glyphs
137#define JAMO_EXTA_END 0x061F ///< End of U+A960..U+A97F glyphs
138
139/* Hangul Jamo Extended-B range */
140#define JAMO_EXTB_HEX 0x0620 ///< Start of U+D7B0..U+D7FF glyphs
141#define JAMO_EXTB_END 0x066F ///< End of U+D7B0..U+D7FF glyphs
142
143/*
144 These values allow enumeration of all modern and ancient letters.
145
146 If RARE_HANGUL is defined, include Hangul code points above U+11FF.
147*/
148#ifdef EXTENDED_HANGUL
149
150#define TOTAL_CHO (NCHO_MODERN + NCHO_ANCIENT + NCHO_EXTA )
151#define TOTAL_JUNG (NJUNG_MODERN + NJUNG_ANCIENT + NJUNG_EXTB)
152#define TOTAL_JONG (NJONG_MODERN + NJONG_ANCIENT + NJONG_EXTB)
153
154#else
155
156#define TOTAL_CHO (NCHO_MODERN + NCHO_ANCIENT )
157#define TOTAL_JUNG (NJUNG_MODERN + NJUNG_ANCIENT)
158#define TOTAL_JONG (NJONG_MODERN + NJONG_ANCIENT)
159
160#endif
161
162
163/*
164 Function Prototypes.
165*/
166
167unsigned hangul_read_base8 (FILE *infp, unsigned char base[][32]);
168unsigned hangul_read_base16 (FILE *infp, unsigned base[][16]);
169
170void hangul_decompose (unsigned codept,
171 int *initial, int *medial, int *final);
172unsigned hangul_compose (int initial, int medial, int final);
173
174void hangul_hex_indices (int choseong, int jungseong, int jongseong,
175 int *cho_index, int *jung_index, int *jong_index);
176void hangul_variations (int choseong, int jungseong, int jongseong,
177 int *cho_var, int *jung_var, int *jong_var);
178int is_wide_vowel (int vowel);
179int cho_variation (int choseong, int jungseong, int jongseong);
180int jung_variation (int choseong, int jungseong, int jongseong);
181int jong_variation (int choseong, int jungseong, int jongseong);
182
183void hangul_syllable (int choseong, int jungseong, int jongseong,
184 unsigned char hangul_base[][32], unsigned char *syllable);
185int glyph_overlap (unsigned *glyph1, unsigned *glyph2);
186void combine_glyphs (unsigned *glyph1, unsigned *glyph2,
187 unsigned *combined_glyph);
188void one_jamo (unsigned glyph_table [MAX_GLYPHS][16],
189 unsigned jamo, unsigned *jamo_glyph);
190void combined_jamo (unsigned glyph_table [MAX_GLYPHS][16],
191 unsigned cho, unsigned jung, unsigned jong,
192 unsigned *combined_glyph);
193void print_glyph_txt (FILE *fp, unsigned codept, unsigned *this_glyph);
194void print_glyph_hex (FILE *fp, unsigned codept, unsigned *this_glyph);
195
196
197#endif
print_glyph_hex
void print_glyph_hex(FILE *fp, unsigned codept, unsigned *this_glyph)
Print one glyph in Unifont hexdraw hexadecimal string style.
Definition: unihangul-support.c:692
one_jamo
void one_jamo(unsigned glyph_table[MAX_GLYPHS][16], unsigned jamo, unsigned *jamo_glyph)
Convert Hangul Jamo choseong, jungseong, and jongseong into a glyph.
Definition: unihangul-support.c:717
combined_jamo
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.
Definition: unihangul-support.c:787
print_glyph_txt
void print_glyph_txt(FILE *fp, unsigned codept, unsigned *this_glyph)
Print one glyph in Unifont hexdraw plain text style.
Definition: unihangul-support.c:656
hangul_read_base8
unsigned hangul_read_base8(FILE *infp, unsigned char base[][32])
Read hangul-base.hex file into a unsigned char array.
Definition: unihangul-support.c:63
is_wide_vowel
int is_wide_vowel(int vowel)
Whether vowel has rightmost vertical stroke to the right.
Definition: unihangul-support.c:434
hangul_hex_indices
void hangul_hex_indices(int choseong, int jungseong, int jongseong, int *cho_index, int *jung_index, int *jong_index)
Determine index values to the bitmaps for a syllable's components.
Definition: unihangul-support.c:249
hangul_decompose
void hangul_decompose(unsigned codept, int *initial, int *medial, int *final)
Decompose a Hangul Syllables code point into three letters.
Definition: unihangul-support.c:167
glyph_overlap
int glyph_overlap(unsigned *glyph1, unsigned *glyph2)
See if two glyphs overlap.
Definition: unihangul-support.c:613
hangul_variations
void hangul_variations(int choseong, int jungseong, int jongseong, int *cho_var, int *jung_var, int *jong_var)
Determine the variations of each letter in a Hangul syllable.
Definition: unihangul-support.c:298
combine_glyphs
void combine_glyphs(unsigned *glyph1, unsigned *glyph2, unsigned *combined_glyph)
Combine two glyphs into one glyph.
Definition: unihangul-support.c:637
jong_variation
int jong_variation(int choseong, int jungseong, int jongseong)
Return the Johab 6/3/1 jongseong variation.
Definition: unihangul-support.c:558
cho_variation
int cho_variation(int choseong, int jungseong, int jongseong)
Return the Johab 6/3/1 choseong variation for a syllable.
Definition: unihangul-support.c:350
jung_variation
int jung_variation(int choseong, int jungseong, int jongseong)
Return the Johab 6/3/1 jungseong variation.
Definition: unihangul-support.c:524
hangul_syllable
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.
Definition: unihangul-support.c:583
hangul_compose
unsigned hangul_compose(int initial, int medial, int final)
Compose a Hangul syllable into a code point, or 0 if none exists.
Definition: unihangul-support.c:201
hangul_read_base16
unsigned hangul_read_base16(FILE *infp, unsigned base[][16])
Read hangul-base.hex file into a unsigned array.
Definition: unihangul-support.c:116
MAX_GLYPHS
#define MAX_GLYPHS
An OpenType font has at most 65536 glyphs.
Definition: hex2otf.c:85