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

Functions for converting Hangul letters into syllables. More...

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

Go to the source code of this file.

Functions

unsigned hangul_read_base8 (FILE *infp, unsigned char base[][32])
 Read hangul-base.hex file into a unsigned char array.
 
unsigned hangul_read_base16 (FILE *infp, unsigned base[][16])
 Read hangul-base.hex file into a unsigned array.
 
void hangul_decompose (unsigned codept, int *initial, int *medial, int *final)
 Decompose a Hangul Syllables code point into three letters.
 
unsigned hangul_compose (int initial, int medial, int final)
 Compose a Hangul syllable into a code point, or 0 if none exists.
 
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.
 
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.
 
int cho_variation (int choseong, int jungseong, int jongseong)
 Return the Johab 6/3/1 choseong variation for a syllable.
 
int is_wide_vowel (int vowel)
 Whether vowel has rightmost vertical stroke to the right.
 
int jung_variation (int choseong, int jungseong, int jongseong)
 Return the Johab 6/3/1 jungseong variation.
 
int jong_variation (int choseong, int jungseong, int jongseong)
 Return the Johab 6/3/1 jongseong variation.
 
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.
 
int glyph_overlap (unsigned *glyph1, unsigned *glyph2)
 See if two glyphs overlap.
 
void combine_glyphs (unsigned *glyph1, unsigned *glyph2, unsigned *combined_glyph)
 Combine two glyphs into one glyph.
 
void print_glyph_txt (FILE *fp, unsigned codept, unsigned *this_glyph)
 Print one glyph in Unifont hexdraw plain text style.
 
void print_glyph_hex (FILE *fp, unsigned codept, unsigned *this_glyph)
 Print one glyph in Unifont hexdraw hexadecimal string style.
 
void one_jamo (unsigned glyph_table[MAX_GLYPHS][16], unsigned jamo, unsigned *jamo_glyph)
 Convert Hangul Jamo choseong, jungseong, and jongseong into a glyph.
 
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.
 

Detailed Description

Functions for converting Hangul letters into syllables.

This file contains functions for reading in Hangul letters arranged in a Johab 6/3/1 pattern and composing syllables with them. One function maps an iniital letter (choseong), medial letter (jungseong), and final letter (jongseong) into the Hangul Syllables Unicode block, U+AC00..U+D7A3. Other functions allow formation of glyphs that include the ancient Hangul letters that Hanterm supported. More can be added if desired, with appropriate changes to start positions and lengths defined in "hangul.h".

Author
Paul Hardy

Definition in file unihangul-support.c.

Function Documentation

◆ cho_variation()

int cho_variation ( int  choseong,
int  jungseong,
int  jongseong 
)

Return the Johab 6/3/1 choseong variation for a syllable.

This function takes the two or three (if jongseong is included) letters that comprise a syllable and determine the variation of the initial consonant (choseong).

Each choseong has 6 variations:

Variation Occurrence


0 Choseong with a vertical vowel such as "A". 1 Choseong with a horizontal vowel such as "O". 2 Choseong with a vertical and horizontal vowel such as "WA". 3 Same as variation 0, but with jongseong (final consonant). 4 Same as variation 1, but with jongseong (final consonant). Also a horizontal vowel pointing down, such as U and YU. 5 Same as variation 2, but with jongseong (final consonant). Also a horizontal vowel pointing down with vertical element, such as WEO, WE, and WI.

In addition, if the vowel is horizontal and a downward-pointing stroke as in the modern letters U, WEO, WE, WI, and YU, and in archaic letters YU-YEO, YU-YE, YU-I, araea, and araea-i, then 3 is added to the initial variation of 0 to 2, resulting in a choseong variation of 3 to 5, respectively.

Parameters
[in]choseongThe 1st letter in the syllable.
[in]jungseongThe 2nd letter in the syllable.
[in]jongseongThe 3rd letter in the syllable.
Returns
The choseong variation, 0 to 5.

Definition at line 350 of file unihangul-support.c.

350 {
351 int cho_variation; /* Return value */
352
353 /*
354 The Choseong cho_var is determined by the
355 21 modern + 50 ancient Jungseong, and whether
356 or not the syllable contains a final consonant
357 (Jongseong).
358 */
359 static int choseong_var [TOTAL_JUNG + 1] = {
360 /*
361 Modern Jungseong in positions 0..20.
362 */
363/* Location Variations Unicode Range Vowel # Vowel Names */
364/* -------- ---------- -------------- ------- ----------- */
365/* 0x2FB */ 0, 0, 0, // U+1161..U+1163-->[ 0.. 2] A, AE, YA
366/* 0x304 */ 0, 0, 0, // U+1164..U+1166-->[ 3.. 5] YAE, EO, E
367/* 0x30D */ 0, 0, // U+1167..U+1168-->[ 6.. 7] YEO, YE
368/* 0x313 */ 1, // U+1169 -->[ 8] O
369/* 0x316 */ 2, 2, 2, // U+116A..U+116C-->[ 9..11] WA, WAE, WE
370/* 0x31F */ 1, 4, // U+116D..U+116E-->[12..13] YO, U
371/* 0x325 */ 5, 5, 5, // U+116F..U+1171-->[14..16] WEO, WE, WI
372/* 0x32E */ 4, 1, // U+1172..U+1173-->[17..18] YU, EU
373/* 0x334 */ 2, // U+1174 -->[19] YI
374/* 0x337 */ 0, // U+1175 -->[20] I
375 /*
376 Ancient Jungseong in positions 21..70.
377 */
378/* Location Variations Unicode Range Vowel # Vowel Names */
379/* -------- ---------- -------------- ------- ----------- */
380/* 0x33A: */ 2, 5, 2, // U+1176..U+1178-->[21..23] A-O, A-U, YA-O
381/* 0x343: */ 2, 2, 5, // U+1179..U+117B-->[24..26] YA-YO, EO-O, EU-U
382/* 0x34C: */ 2, 2, 5, // U+117C..U+117E-->[27..29] EO-EU, YEO-O, YEO-U
383/* 0x355: */ 2, 5, 5, // U+117F..U+1181-->[30..32] O-EO, O-E, O-YE,
384/* 0x35E: */ 4, 4, 2, // U+1182..U+1184-->[33..35] O-O, O-U, YO-YA,
385/* 0x367: */ 2, 2, 5, // U+1185..U+1187-->[36..38] YO-YAE, YO-YEO, YO-O,
386/* 0x370: */ 2, 5, 5, // U+1188..U+118A-->[39..41] YO-I, U-A, U-AE,
387/* 0x379: */ 5, 5, 5, // U+118B..U+118D-->[42..44] U-EO-EU, U-YE, U-U,
388/* 0x382: */ 5, 5, 5, // U+118E..U+1190-->[45..47] YU-A, YU-EO, YU-E,
389/* 0x38B: */ 5, 5, 2, // U+1191..U+1193-->[48..50] YU-YEO, YU-YE, YU-U,
390/* 0x394: */ 5, 2, 2, // U+1194..U+1196-->[51..53] YU-I, EU-U, EU-EU,
391/* 0x39D: */ 2, 0, 0, // U+1197..U+1199-->[54..56] YI-U, I-A, I-YA,
392/* 0x3A6: */ 2, 5, 2, // U+119A..U+119C-->[57..59] I-O, I-U, I-EU,
393/* 0x3AF: */ 0, 1, 2, // U+119D..U+119F-->[60..62] I-ARAEA, ARAEA, ARAEA-EO,
394/* 0x3B8: */ 1, 2, 1, // U+11A0..U+11A2-->[63..65] ARAEA-U, ARAEA-I,SSANGARAEA,
395/* 0x3C1: */ 2, 5, 0, // U+11A3..U+11A5-->[66..68] A-EU, YA-U, YEO-YA,
396/* 0x3CA: */ 2, 2, // U+11A6..U+11A7-->[69..70] O-YA, O-YAE,
397#ifdef EXTENDED_HANGUL
398/* 0x3D0: */ 2, 4, 5, // U+D7B0..U+D7B2-->[71..73] O-YEO, O-O-I, YO-A,
399/* 0x3D9: */ 5, 2, 5, // U+D7B3..U+D7B5-->[74..76] YO-AE, YO-EO, U-YEO,
400/* 0x3E2: */ 5, 5, 4, // U+D7B6..U+D7B8-->[77..79] U-I-I, YU-AE, YU-O,
401/* 0x3EB: */ 5, 2, 5, // U+D7B9..U+D7BB-->[80..82] EU-A, EU-EO, EU-E,
402/* 0x3F4: */ 4, 2, 3, // U+D7BC..U+D7BE-->[83..85] EU-O, I-YA-O, I-YAE,
403/* 0x3FD: */ 3, 3, 2, // U+D7BF..U+D7C1-->[86..88] I-YEO, I-YE, I-O-I,
404/* 0x406: */ 2, 2, 0, // U+D7C2..U+D7C4-->[89..91] I-YO, I-YU, I-I,
405/* 0x40F: */ 2, 2, // U+D7C5..U+D7C6-->[92..93] ARAEA-A, ARAEA-E,
406/* 0x415: */ -1 // Mark end of list of vowels.
407#else
408/* 0x310: */ -1 // Mark end of list of vowels.
409#endif
410 };
411
412
413 if (jungseong < 0 || jungseong >= TOTAL_JUNG) {
414 cho_variation = -1;
415 }
416 else {
417 cho_variation = choseong_var [jungseong];
418 if (choseong >= 0 && jongseong >= 0 && cho_variation < 3)
419 cho_variation += 3;
420 }
421
422
423 return cho_variation;
424}
int cho_variation(int choseong, int jungseong, int jongseong)
Return the Johab 6/3/1 choseong variation for a syllable.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ combine_glyphs()

void combine_glyphs ( unsigned *  glyph1,
unsigned *  glyph2,
unsigned *  combined_glyph 
)

Combine two glyphs into one glyph.

Parameters
[in]glyph1The first glyph to overlap.
[in]glyph2The second glyph to overlap.
[out]combined_glyphThe returned combination glyph.

Definition at line 637 of file unihangul-support.c.

638 {
639 int i;
640
641 for (i = 0; i < 16; i++)
642 combined_glyph [i] = glyph1 [i] | glyph2 [i];
643
644 return;
645}
Here is the caller graph for this function:

◆ 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.

This function converts input Hangul choseong, jungseong, and jongseong Unicode code triplets into a Hangul syllable. Any of those with an out of range code point are assigned a blank glyph for combining.

This function performs the following steps:

 1) Determine the sequence number of choseong, jungseong,
    and jongseong, from 0 to the total number of choseong,
    jungseong, or jongseong, respectively, minus one.  The
    sequence for each is as follows:

    a) Choseong: Unicode code points of U+1100..U+115E
       and then U+A960..U+A97C.

    b) Jungseong: Unicode code points of U+1161..U+11A7
       and then U+D7B0..U+D7C6.

    c) Jongseong: Unicode code points of U+11A8..U+11FF
       and then U+D7CB..U+D7FB.

 2) From the choseong, jungseong, and jongseong sequence number,
    determine the variation of choseong and jungseong (there is
    only one jongseong variation, although it is shifted right
    by one column for some vowels with a pair of long vertical
    strokes on the right side).

 3) Convert the variation numbers for the three syllable
    components to index locations in the glyph array.

 4) Combine the glyph array glyphs into a syllable.
Parameters
[in]glyph_tableThe collection of all jamo glyphs.
[in]choThe choseong Unicode code point, 0 or 0x1100..0x115F.
[in]jungThe jungseong Unicode code point, 0 or 0x1160..0x11A7.
[in]jongThe jongseong Unicode code point, 0 or 0x11A8..0x11FF.
[out]combined_glyphThe output glyph, 16 columns in each of 16 rows.

Definition at line 787 of file unihangul-support.c.

789 {
790
791 int i; /* Loop variable. */
792 int cho_num, jung_num, jong_num;
793 int cho_group, jung_group, jong_group;
794 int cho_index, jung_index, jong_index;
795
796 unsigned tmp_glyph[16]; /* Hold shifted jongsung for wide vertical vowel. */
797
798 int cho_variation (int choseong, int jungseong, int jongseong);
799
800 void combine_glyphs (unsigned *glyph1, unsigned *glyph2,
801 unsigned *combined_glyph);
802
803
804 /* Choose a blank glyph for each syllalbe by default. */
805 cho_index = jung_index = jong_index = 0x000;
806
807 /*
808 Convert Unicode code points to jamo sequence number
809 of each letter, or -1 if letter is not in valid range.
810 */
811 if (cho >= 0x1100 && cho <= 0x115E)
812 cho_num = cho - CHO_UNICODE_START;
813 else if (cho >= CHO_EXTA_UNICODE_START &&
816 else
817 cho_num = -1;
818
819 if (jung >= 0x1161 && jung <= 0x11A7)
820 jung_num = jung - JUNG_UNICODE_START;
821 else if (jung >= JUNG_EXTB_UNICODE_START &&
824 else
825 jung_num = -1;
826
827 if (jong >= 0x11A8 && jong <= 0x11FF)
828 jong_num = jong - JONG_UNICODE_START;
829 else if (jong >= JONG_EXTB_UNICODE_START &&
832 else
833 jong_num = -1;
834
835 /*
836 Choose initial consonant (choseong) variation based upon
837 the vowel (jungseong) if both are specified.
838 */
839 if (cho_num < 0) {
840 cho_index = cho_group = 0; /* Use blank glyph for choseong. */
841 }
842 else {
843 if (jung_num < 0 && jong_num < 0) { /* Choseong is by itself. */
844 cho_group = 0;
845 if (cho_index < (NCHO_MODERN + NCHO_ANCIENT))
846 cho_index = cho_num + JAMO_HEX;
847 else /* Choseong is in Hangul Jamo Extended-A range. */
848 cho_index = cho_num - (NCHO_MODERN + NCHO_ANCIENT)
850 }
851 else {
852 if (jung_num >= 0) { /* Valid jungseong with choseong. */
853 cho_group = cho_variation (cho_num, jung_num, jong_num);
854 }
855 else { /* Invalid vowel; see if final consonant is valid. */
856 /*
857 If initial consonant and final consonant are specified,
858 set cho_group to 4, which is the group tha would apply
859 to a horizontal-only vowel such as Hangul "O", so the
860 consonant appears full-width.
861 */
862 cho_group = 0;
863 if (jong_num >= 0) {
864 cho_group = 4;
865 }
866 }
867 cho_index = CHO_HEX + CHO_VARIATIONS * cho_num +
868 cho_group;
869 } /* Choseong combined with jungseong and/or jongseong. */
870 } /* Valid choseong. */
871
872 /*
873 Choose vowel (jungseong) variation based upon the choseong
874 and jungseong.
875 */
876 jung_index = jung_group = 0; /* Use blank glyph for jungseong. */
877
878 if (jung_num >= 0) {
879 if (cho_num < 0 && jong_num < 0) { /* Jungseong is by itself. */
880 jung_group = 0;
881 jung_index = jung_num + JUNG_UNICODE_START;
882 }
883 else {
884 if (jong_num >= 0) { /* If there is a final consonant. */
885 if (jong_num == 3) /* Nieun; choose variation 3. */
886 jung_group = 2;
887 else
888 jung_group = 1;
889 } /* Valid jongseong. */
890 /* If valid choseong but no jongseong, choose jungseong variation 0. */
891 else if (cho_num >= 0)
892 jung_group = 0;
893 }
894 jung_index = JUNG_HEX + JUNG_VARIATIONS * jung_num + jung_group;
895 }
896
897 /*
898 Choose final consonant (jongseong) based upon whether choseong
899 and/or jungseong are present.
900 */
901 if (jong_num < 0) {
902 jong_index = jong_group = 0; /* Use blank glyph for jongseong. */
903 }
904 else { /* Valid jongseong. */
905 if (cho_num < 0 && jung_num < 0) { /* Jongseong is by itself. */
906 jong_group = 0;
907 jong_index = jung_num + 0x4A8;
908 }
909 else { /* There is only one jongseong variation if combined. */
910 jong_group = 0;
911 jong_index = JONG_HEX + JONG_VARIATIONS * jong_num +
912 jong_group;
913 }
914 }
915
916 /*
917 Now that we know the index locations for choseong, jungseong, and
918 jongseong glyphs, combine them into one glyph.
919 */
920 combine_glyphs (glyph_table [cho_index], glyph_table [jung_index],
921 combined_glyph);
922
923 if (jong_index > 0) {
924 /*
925 If the vowel has a vertical stroke that is one column
926 away from the right border, shift this jongseung right
927 by one column to line up with the rightmost vertical
928 stroke in the vowel.
929 */
930 if (is_wide_vowel (jung_num)) {
931 for (i = 0; i < 16; i++) {
932 tmp_glyph [i] = glyph_table [jong_index] [i] >> 1;
933 }
934 combine_glyphs (combined_glyph, tmp_glyph,
935 combined_glyph);
936 }
937 else {
938 combine_glyphs (combined_glyph, glyph_table [jong_index],
939 combined_glyph);
940 }
941 }
942
943 return;
944}
#define NJONG_EXTB
Hangul Extended-B jongseong.
Definition: hangul.h:81
#define NCHO_EXTA
Hangul Extended-A choseong.
Definition: hangul.h:71
#define CHO_VARIATIONS
6 choseong variations
Definition: hangul.h:88
#define JONG_VARIATIONS
1 jongseong variation
Definition: hangul.h:90
#define NJONG_MODERN
28 modern Hangul Jamo jongseong
Definition: hangul.h:79
#define CHO_UNICODE_START
Modern Hangul choseong start.
Definition: hangul.h:50
#define JAMO_EXTA_HEX
Start of U+A960..U+A97F glyphs.
Definition: hangul.h:136
#define JUNG_EXTB_UNICODE_START
Hangul Extended-B jungseong start.
Definition: hangul.h:57
#define JUNG_HEX
Location of first jungseong (will be 0x2FB)
Definition: hangul.h:108
#define NCHO_ANCIENT
ancient Hangul Jamo choseong
Definition: hangul.h:70
#define CHO_EXTA_UNICODE_START
Hangul Extended-A choseong start.
Definition: hangul.h:52
#define NCHO_MODERN
19 modern Hangul Jamo choseong
Definition: hangul.h:69
#define JAMO_HEX
Start of U+1100..U+11FF glyphs.
Definition: hangul.h:132
#define JONG_UNICODE_START
Modern Hangul jongseong start.
Definition: hangul.h:60
#define NJUNG_MODERN
21 modern Hangul Jamo jungseong
Definition: hangul.h:74
#define JUNG_UNICODE_START
Modern Hangul jungseong start.
Definition: hangul.h:55
#define JUNG_VARIATIONS
3 jungseong variations
Definition: hangul.h:89
#define NJONG_ANCIENT
ancient Hangul Jamo jongseong
Definition: hangul.h:80
#define NJUNG_ANCIENT
ancient Hangul Jamo jungseong
Definition: hangul.h:75
#define CHO_HEX
Location of first choseong (location 0x0000 is a blank glyph)
Definition: hangul.h:96
#define JONG_EXTB_UNICODE_START
Hangul Extended-B jongseong start.
Definition: hangul.h:62
#define NJUNG_EXTB
Hangul Extended-B jungseong.
Definition: hangul.h:76
#define JONG_HEX
Location of first jongseong (will be 0x421)
Definition: hangul.h:120
int is_wide_vowel(int vowel)
Whether vowel has rightmost vertical stroke to the right.
void combine_glyphs(unsigned *glyph1, unsigned *glyph2, unsigned *combined_glyph)
Combine two glyphs into one glyph.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ glyph_overlap()

int glyph_overlap ( unsigned *  glyph1,
unsigned *  glyph2 
)

See if two glyphs overlap.

Parameters
[in]glyph1The first glyph, as a 16-row bitmap.
[in]glyph2The second glyph, as a 16-row bitmap.
Returns
0 if no overlaps between glyphs, 1 otherwise.

Definition at line 613 of file unihangul-support.c.

613 {
614 int overlaps; /* Return value; 0 if no overlaps, -1 if overlaps. */
615 int i;
616
617 /* Check for overlaps between the two glyphs. */
618
619 i = 0;
620 do {
621 overlaps = (glyph1[i] & glyph2[i]) != 0;
622 i++;
623 } while (i < 16 && overlaps == 0);
624
625 return overlaps;
626}
Here is the caller graph for this function:

◆ hangul_compose()

unsigned hangul_compose ( int  initial,
int  medial,
int  final 
)

Compose a Hangul syllable into a code point, or 0 if none exists.

This function takes three letters that can form a modern Hangul syllable and returns the corresponding Unicode Hangul Syllables code point in the range 0xAC00 to 0xD7A3.

If a three-letter combination includes one or more archaic letters, it will not map into the Hangul Syllables range. In that case, the returned code point will be 0 to indicate that no valid Hangul Syllables code point exists.

Parameters
[in]initialThe first letter (choseong), 0 to 18.
[in]medialThe second letter (jungseong), 0 to 20.
[in]finalThe third letter (jongseong), 0 to 26 or -1 if none.
Returns
The Unicode Hangul Syllables code point, 0xAC00 to 0xD7A3.

Definition at line 201 of file unihangul-support.c.

201 {
202 unsigned codept;
203
204
205 if (initial >= 0 && initial <= 18 &&
206 medial >= 0 && medial <= 20 &&
207 final >= 0 && final <= 26) {
208
209 codept = 0xAC00;
210 codept += initial * 21 * 28;
211 codept += medial * 28;
212 codept += final + 1;
213 }
214 else {
215 codept = 0;
216 }
217
218 return codept;
219}

◆ hangul_decompose()

void hangul_decompose ( unsigned  codept,
int *  initial,
int *  medial,
int *  final 
)

Decompose a Hangul Syllables code point into three letters.

Decompose a Hangul Syllables code point (U+AC00..U+D7A3) into:

  • Choseong 0-19
  • Jungseong 0-20
  • Jongseong 0-27 or -1 if no jongseong

All letter values are set to -1 if the letters do not form a syllable in the Hangul Syllables range. This function only handles modern Hangul, because that is all that is in the Hangul Syllables range.

Parameters
[in]codeptThe Unicode code point to decode, from 0xAC00 to 0xD7A3.
[out]initialThe 1st letter (choseong) in the syllable.
[out]initialThe 2nd letter (jungseong) in the syllable.
[out]initialThe 3rd letter (jongseong) in the syllable.

Definition at line 167 of file unihangul-support.c.

167 {
168
169 if (codept < 0xAC00 || codept > 0xD7A3) {
170 *initial = *medial = *final = -1;
171 }
172 else {
173 codept -= 0xAC00;
174 *initial = codept / (28 * 21);
175 *medial = (codept / 28) % 21;
176 *final = codept % 28 - 1;
177 }
178
179 return;
180}
Here is the caller graph for this function:

◆ 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.

This function reads these input values for modern and ancient Hangul letters:

  • Choseong number (0 to the number of modern and archaic choseong - 1.
  • Jungseong number (0 to the number of modern and archaic jungseong - 1.
  • Jongseong number (0 to the number of modern and archaic jongseong - 1, or -1 if none.

It then determines the variation of each letter given the combination with the other two letters (or just choseong and jungseong if the jongseong value is -1).

These variations are then converted into index locations within the glyph array that was read in from the hangul-base.hex file. Those index locations can then be used to form a composite syllable.

There is no restriction to only use the modern Hangul letters.

Parameters
[in]choseongThe 1st letter in the syllable.
[in]jungseongThe 2nd letter in the syllable.
[in]jongseongThe 3rd letter in the syllable, or -1 if none.
[out]cho_indexIndex location to the 1st letter variation from the hangul-base.hex file.
[out]jung_indexIndex location to the 2nd letter variation from the hangul-base.hex file.
[out]jong_indexIndex location to the 3rd letter variation from the hangul-base.hex file.

Definition at line 249 of file unihangul-support.c.

250 {
251
252 int cho_variation, jung_variation, jong_variation; /* Letter variations */
253
254 void hangul_variations (int choseong, int jungseong, int jongseong,
256
257
258 hangul_variations (choseong, jungseong, jongseong,
260
261 *cho_index = CHO_HEX + choseong * CHO_VARIATIONS + cho_variation;
262 *jung_index = JUNG_HEX + jungseong * JUNG_VARIATIONS + jung_variation;;
263 *jong_index = jongseong < 0 ? 0x0000 :
265
266 return;
267}
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.
int jong_variation(int choseong, int jungseong, int jongseong)
Return the Johab 6/3/1 jongseong variation.
int jung_variation(int choseong, int jungseong, int jongseong)
Return the Johab 6/3/1 jungseong variation.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hangul_read_base16()

unsigned hangul_read_base16 ( FILE *  infp,
unsigned  base[][16] 
)

Read hangul-base.hex file into a unsigned array.

Read a Hangul base .hex file with separate choseong, jungseong, and jongseong glyphs for syllable formation. The order is:

  • Empty glyph in 0x0000 position.
  • Initial consonants (choseong).
  • Medial vowels and dipthongs (jungseong).
  • Final consonants (jongseong).
  • Individual letter forms in isolation, not for syllable formation.

The letters are arranged with all variations for one letter before continuing to the next letter. In the current encoding, there are 6 variations of choseong, 3 of jungseong, and 1 of jongseong per letter.

Parameters
[in]Inputfile pointer; can be stdin.
[out]Arrayof bit patterns, with 16 16-bit values per letter.
Returns
The maximum code point value read in the file.

Definition at line 116 of file unihangul-support.c.

116 {
117 unsigned codept;
118 unsigned max_codept;
119 int i, j;
120 char instring[MAXLINE];
121
122
123 max_codept = 0;
124
125 while (fgets (instring, MAXLINE, infp) != NULL) {
126 sscanf (instring, "%X", &codept);
127 codept -= PUA_START;
128 /* If code point is within range, add it */
129 if (codept < MAX_GLYPHS) {
130 /* Find the start of the glyph bitmap. */
131 for (i = 1; instring[i] != '\0' && instring[i] != ':'; i++);
132 if (instring[i] == ':') {
133 i++; /* Skip over ':' to get to start of bitmap. */
134 for (j = 0; j < 16; j++) {
135 sscanf (&instring[i], "%4X", &base[codept][j]);
136 i += 4;
137 }
138 if (codept > max_codept) max_codept = codept;
139 }
140 }
141 }
142
143 return max_codept;
144}
#define MAXLINE
Length of maximum file input line.
Definition: hangul.h:33
Here is the caller graph for this function:

◆ hangul_read_base8()

unsigned hangul_read_base8 ( FILE *  infp,
unsigned char  base[][32] 
)

Read hangul-base.hex file into a unsigned char array.

Read a Hangul base .hex file with separate choseong, jungseong, and jongseong glyphs for syllable formation. The order is:

  • Empty glyph in 0x0000 position.
  • Initial consonants (choseong).
  • Medial vowels and dipthongs (jungseong).
  • Final consonants (jongseong).
  • Individual letter forms in isolation, not for syllable formation.

The letters are arranged with all variations for one letter before continuing to the next letter. In the current encoding, there are 6 variations of choseong, 3 of jungseong, and 1 of jongseong per letter.

Parameters
[in]Inputfile pointer; can be stdin.
[out]Arrayof bit patterns, with 32 8-bit values per letter.
Returns
The maximum code point value read in the file.

Definition at line 63 of file unihangul-support.c.

63 {
64 unsigned codept;
65 unsigned max_codept;
66 int i, j;
67 char instring[MAXLINE];
68
69
70 max_codept = 0;
71
72 while (fgets (instring, MAXLINE, infp) != NULL) {
73 sscanf (instring, "%X", &codept);
74 codept -= PUA_START;
75 /* If code point is within range, add it */
76 if (codept < MAX_GLYPHS) {
77 /* Find the start of the glyph bitmap. */
78 for (i = 1; instring[i] != '\0' && instring[i] != ':'; i++);
79 if (instring[i] == ':') {
80 i++; /* Skip over ':' to get to start of bitmap. */
81 for (j = 0; j < 32; j++) {
82 sscanf (&instring[i], "%2hhX", &base[codept][j]);
83 i += 2;
84 }
85 if (codept > max_codept) max_codept = codept;
86 }
87 }
88 }
89
90 return max_codept;
91}
Here is the caller graph for this function:

◆ 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.

This function returns a glyph bitmap comprising up to three Hangul letters that form a syllable. It reads the three component letters (choseong, jungseong, and jungseong), then calls a function that determines the appropriate variation of each letter, returning the letter bitmap locations in the glyph array. Then these letter bitmaps are combined with a logical OR operation to produce a final bitmap, which forms a 16 row by 16 column bitmap glyph.

Parameters
[in]choseongThe 1st letter in the composite glyph.
[in]jungseongThe 2nd letter in the composite glyph.
[in]jongseongThe 3rd letter in the composite glyph.
[in]hangul_baseThe glyphs read from the "hangul_base.hex" file.
Returns
syllable The composite syllable, as a 16 by 16 pixel bitmap.

Definition at line 583 of file unihangul-support.c.

584 {
585
586 int i; /* loop variable */
587 int cho_hex, jung_hex, jong_hex;
588 unsigned char glyph_byte;
589
590
591 hangul_hex_indices (choseong, jungseong, jongseong,
592 &cho_hex, &jung_hex, &jong_hex);
593
594 for (i = 0; i < 32; i++) {
595 glyph_byte = hangul_base [cho_hex][i];
596 glyph_byte |= hangul_base [jung_hex][i];
597 if (jong_hex >= 0) glyph_byte |= hangul_base [jong_hex][i];
598 syllable[i] = glyph_byte;
599 }
600
601 return;
602}
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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Given the three letters that will form a syllable, return the variation of each letter used to form the composite glyph.

This function can determine variations for both modern and archaic Hangul letters; it is not limited to only the letters combinations that comprise the Unicode Hangul Syllables range.

This function reads these input values for modern and ancient Hangul letters:

  • Choseong number (0 to the number of modern and archaic choseong - 1.
  • Jungseong number (0 to the number of modern and archaic jungseong - 1.
  • Jongseong number (0 to the number of modern and archaic jongseong - 1, or -1 if none.

It then determines the variation of each letter given the combination with the other two letters (or just choseong and jungseong if the jongseong value is -1).

Parameters
[in]choseongThe 1st letter in the syllable.
[in]jungseongThe 2nd letter in the syllable.
[in]jongseongThe 3rd letter in the syllable, or -1 if none.
[out]cho_varVariation of the 1st letter from the hangul-base.hex file.
[out]jung_varVariation of the 2nd letter from the hangul-base.hex file.
[out]jong_varVariation of the 3rd letter from the hangul-base.hex file.

Definition at line 298 of file unihangul-support.c.

299 {
300
301 int cho_variation (int choseong, int jungseong, int jongseong);
302 int jung_variation (int choseong, int jungseong, int jongseong);
303 int jong_variation (int choseong, int jungseong, int jongseong);
304
305 /*
306 Find the variation for each letter component.
307 */
308 *cho_var = cho_variation (choseong, jungseong, jongseong);
309 *jung_var = jung_variation (choseong, jungseong, jongseong);
310 *jong_var = jong_variation (choseong, jungseong, jongseong);
311
312
313 return;
314}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_wide_vowel()

int is_wide_vowel ( int  vowel)

Whether vowel has rightmost vertical stroke to the right.

Parameters
[in]vowelVowel number, from 0 to TOTAL_JUNG - 1.
Returns
1 if this vowel's vertical stroke is wide on the right side; else 0.

Definition at line 434 of file unihangul-support.c.

434 {
435 int retval; /* Return value. */
436
437 static int wide_vowel [TOTAL_JUNG + 1] = {
438 /*
439 Modern Jungseong in positions 0..20.
440 */
441/* Location Variations Unicode Range Vowel # Vowel Names */
442/* -------- ---------- -------------- ------- ----------- */
443/* 0x2FB */ 0, 1, 0, // U+1161..U+1163-->[ 0.. 2] A, AE, YA
444/* 0x304 */ 1, 0, 1, // U+1164..U+1166-->[ 3.. 5] YAE, EO, E
445/* 0x30D */ 0, 1, // U+1167..U+1168-->[ 6.. 7] YEO, YE
446/* 0x313 */ 0, // U+1169 -->[ 8] O
447/* 0x316 */ 0, 1, 0, // U+116A..U+116C-->[ 9..11] WA, WAE, WE
448/* 0x31F */ 0, 0, // U+116D..U+116E-->[12..13] YO, U
449/* 0x325 */ 0, 1, 0, // U+116F..U+1171-->[14..16] WEO, WE, WI
450/* 0x32E */ 0, 0, // U+1172..U+1173-->[17..18] YU, EU
451/* 0x334 */ 0, // U+1174 -->[19] YI
452/* 0x337 */ 0, // U+1175 -->[20] I
453 /*
454 Ancient Jungseong in positions 21..70.
455 */
456/* Location Variations Unicode Range Vowel # Vowel Names */
457/* -------- ---------- -------------- ------- ----------- */
458/* 0x33A: */ 0, 0, 0, // U+1176..U+1178-->[21..23] A-O, A-U, YA-O
459/* 0x343: */ 0, 0, 0, // U+1179..U+117B-->[24..26] YA-YO, EO-O, EU-U
460/* 0x34C: */ 0, 0, 0, // U+117C..U+117E-->[27..29] EO-EU, YEO-O, YEO-U
461/* 0x355: */ 0, 1, 1, // U+117F..U+1181-->[30..32] O-EO, O-E, O-YE,
462/* 0x35E: */ 0, 0, 0, // U+1182..U+1184-->[33..35] O-O, O-U, YO-YA,
463/* 0x367: */ 1, 0, 0, // U+1185..U+1187-->[36..38] YO-YAE, YO-YEO, YO-O,
464/* 0x370: */ 0, 0, 1, // U+1188..U+118A-->[39..41] YO-I, U-A, U-AE,
465/* 0x379: */ 0, 1, 0, // U+118B..U+118D-->[42..44] U-EO-EU, U-YE, U-U,
466/* 0x382: */ 0, 0, 1, // U+118E..U+1190-->[45..47] YU-A, YU-EO, YU-E,
467/* 0x38B: */ 0, 1, 0, // U+1191..U+1193-->[48..50] YU-YEO, YU-YE, YU-U,
468/* 0x394: */ 0, 0, 0, // U+1194..U+1196-->[51..53] YU-I, EU-U, EU-EU,
469/* 0x39D: */ 0, 0, 0, // U+1197..U+1199-->[54..56] YI-U, I-A, I-YA,
470/* 0x3A6: */ 0, 0, 0, // U+119A..U+119C-->[57..59] I-O, I-U, I-EU,
471/* 0x3AF: */ 0, 0, 0, // U+119D..U+119F-->[60..62] I-ARAEA, ARAEA, ARAEA-EO,
472/* 0x3B8: */ 0, 0, 0, // U+11A0..U+11A2-->[63..65] ARAEA-U, ARAEA-I,SSANGARAEA,
473/* 0x3C1: */ 0, 0, 0, // U+11A3..U+11A5-->[66..68] A-EU, YA-U, YEO-YA,
474/* 0x3CA: */ 0, 1, // U+11A6..U+11A7-->[69..70] O-YA, O-YAE
475#ifdef EXTENDED_HANGUL
476/* 0x3D0: */ 0, 0, 0, // U+D7B0..U+D7B2-->[71..73] O-YEO, O-O-I, YO-A,
477/* 0x3D9: */ 1, 0, 0, // U+D7B3..U+D7B5-->[74..76] YO-AE, YO-EO, U-YEO,
478/* 0x3E2: */ 1, 1, 0, // U+D7B6..U+D7B8-->[77..79] U-I-I, YU-AE, YU-O,
479/* 0x3EB: */ 0, 0, 1, // U+D7B9..U+D7BB-->[80..82] EU-A, EU-EO, EU-E,
480/* 0x3F4: */ 0, 0, 1, // U+D7BC..U+D7BE-->[83..85] EU-O, I-YA-O, I-YAE,
481/* 0x3FD: */ 0, 1, 0, // U+D7BF..U+D7C1-->[86..88] I-YEO, I-YE, I-O-I,
482/* 0x406: */ 0, 0, 1, // U+D7C2..U+D7C4-->[89..91] I-YO, I-YU, I-I,
483/* 0x40F: */ 0, 1, // U+D7C5..U+D7C6-->[92..93] ARAEA-A, ARAEA-E,
484/* 0x415: */ -1 // Mark end of list of vowels.
485#else
486/* 0x310: */ -1 // Mark end of list of vowels.
487#endif
488 };
489
490
491 if (vowel >= 0 && vowel < TOTAL_JUNG) {
492 retval = wide_vowel [vowel];
493 }
494 else {
495 retval = 0;
496 }
497
498
499 return retval;
500}
Here is the caller graph for this function:

◆ jong_variation()

int jong_variation ( int  choseong,
int  jungseong,
int  jongseong 
)
inline

Return the Johab 6/3/1 jongseong variation.

There is only one jongseong variation, so this function always returns 0. It is a placeholder function for possible future adaptation to other johab encodings.

Parameters
[in]choseongThe 1st letter in the syllable.
[in]jungseongThe 2nd letter in the syllable.
[in]jongseongThe 3rd letter in the syllable.
Returns
The jongseong variation, always 0.

Definition at line 558 of file unihangul-support.c.

558 {
559
560 return 0; /* There is only one Jongseong variation. */
561}
Here is the caller graph for this function:

◆ jung_variation()

int jung_variation ( int  choseong,
int  jungseong,
int  jongseong 
)
inline

Return the Johab 6/3/1 jungseong variation.

This function takes the two or three (if jongseong is included) letters that comprise a syllable and determine the variation of the vowel (jungseong).

Each jungseong has 3 variations:

Variation Occurrence


0 Jungseong with only chungseong (no jungseong). 1 Jungseong with chungseong and jungseong (except nieun). 2 Jungseong with chungseong and jungseong nieun.

Parameters
[in]choseongThe 1st letter in the syllable.
[in]jungseongThe 2nd letter in the syllable.
[in]jongseongThe 3rd letter in the syllable.
Returns
The jungseong variation, 0 to 2.

Definition at line 524 of file unihangul-support.c.

524 {
525 int jung_variation; /* Return value */
526
527 if (jungseong < 0) {
528 jung_variation = -1;
529 }
530 else {
531 jung_variation = 0;
532 if (jongseong >= 0) {
533 if (jongseong == 3)
534 jung_variation = 2; /* Vowel for final Nieun. */
535 else
536 jung_variation = 1;
537 }
538 }
539
540
541 return jung_variation;
542}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
[in]glyph_tableThe collection of all jamo glyphs.
[in]jamoThe Unicode code point, 0 or 0x1100..0x115F.
[out]jamo_glyphThe output glyph, 16 columns in each of 16 rows.

Definition at line 717 of file unihangul-support.c.

718 {
719
720 int i; /* Loop variable */
721 int glyph_index; /* Location of glyph in "hangul-base.hex" array */
722
723
724 /* If jamo is invalid range, use blank glyph, */
725 if (jamo >= 0x1100 && jamo <= 0x11FF) {
726 glyph_index = jamo - 0x1100 + JAMO_HEX;
727 }
728 else if (jamo >= 0xA960 && jamo <= 0xA97F) {
729 glyph_index = jamo - 0xA960 + JAMO_EXTA_HEX;
730 }
731 else if (jamo >= 0xD7B0 && jamo <= 0xD7FF) {
732 glyph_index = jamo - 0x1100 + JAMO_EXTB_HEX;
733 }
734 else {
735 glyph_index = 0;
736 }
737
738 for (i = 0; i < 16; i++) {
739 jamo_glyph [i] = glyph_table [glyph_index] [i];
740 }
741
742 return;
743}
#define JAMO_EXTB_HEX
Start of U+D7B0..U+D7FF glyphs.
Definition: hangul.h:140

◆ print_glyph_hex()

void print_glyph_hex ( FILE *  fp,
unsigned  codept,
unsigned *  this_glyph 
)

Print one glyph in Unifont hexdraw hexadecimal string style.

Parameters
[in]fpThe file pointer for output.
[in]codeptThe Unicode code point to print with the glyph.
[in]this_glyphThe 16-row by 16-column glyph to print.

Definition at line 692 of file unihangul-support.c.

692 {
693
694 int i;
695
696
697 fprintf (fp, "%04X:", codept);
698
699 /* for each this_glyph row */
700 for (i = 0; i < 16; i++) {
701 fprintf (fp, "%04X", this_glyph[i]);
702 }
703 fputc ('\n', fp);
704
705 return;
706}
Here is the caller graph for this function:

◆ print_glyph_txt()

void print_glyph_txt ( FILE *  fp,
unsigned  codept,
unsigned *  this_glyph 
)

Print one glyph in Unifont hexdraw plain text style.

Parameters
[in]fpThe file pointer for output.
[in]codeptThe Unicode code point to print with the glyph.
[in]this_glyphThe 16-row by 16-column glyph to print.

Definition at line 656 of file unihangul-support.c.

656 {
657 int i;
658 unsigned mask;
659
660
661 fprintf (fp, "%04X:", codept);
662
663 /* for each this_glyph row */
664 for (i = 0; i < 16; i++) {
665 mask = 0x8000;
666 fputc ('\t', fp);
667 while (mask != 0x0000) {
668 if (mask & this_glyph [i]) {
669 fputc ('#', fp);
670 }
671 else {
672 fputc ('-', fp);
673 }
674 mask >>= 1; /* shift to next bit in this_glyph row */
675 }
676 fputc ('\n', fp);
677 }
678 fputc ('\n', fp);
679
680 return;
681}
Here is the caller graph for this function: