1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1996 by Sun Microsystems, Inc.
23  */
24 
25 
26 #include "common_han.h"
27 #include "common_utf.h"
28 
29 /****  _ J O H A P 8 2 _ T O _ U T F 8  ****/
30 
_johap82_to_utf8(hcode_type ojh_code)31 hcode_type _johap82_to_utf8(hcode_type ojh_code)
32 {
33 	/* Only for Hangul code */
34 	hcode_type utf_code;
35 	hcode_type unicode;
36 	unsigned int x, y, z;
37 
38         /* Hangul only conversion. */
39         if (ojh_code.code < 0xA421 || 0xF3BC < ojh_code.code) {
40 		utf_code.code = 0;	/* Not Hangul */
41 		return(utf_code);
42 	}
43 
44 	x = ojh_code.johap.chosung - 0x0A;  /* 0x0A = 'Kyoug' */
45 	y = ojh_code.johap.joongsung;
46 	y = y - (y / 4 + 2);
47 	z = ojh_code.johap.jongsung - 1;
48 
49 	if (x > 18 || y > 20 || z > 29) {
50 		utf_code.code = 0;	/* Not Hangul */
51 		return(utf_code);
52 	}
53 
54 	unicode.code = (unsigned int)(x*588 + y*28 + z)
55 			+ 0xAC00;
56 		/* 588 = 21(Joongsung Number) * 28(Jongsung Number) */
57 
58 	utf_code = _uni_to_utf8(unicode);
59 
60 	return(utf_code);
61 
62 }  /* end of hcode_type johap82_to_utf8(hcode_type ojh_code) */
63