summaryrefslogtreecommitdiffstats
path: root/loader/kon2/lib/coding.c
blob: 4e1846d0895ff19e36ae7c775c86a23d31d89e9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * KON2 - Kanji ON Console -
 * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY TAKASHI MANABE ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * 
 */

#include	<config.h>
#include	<types.h>

#include	<stdio.h>
#include	<errno.h>
#include	<string.h>

#include	<interface.h>
#include	<fnld.h>

static u_int JISX0208(u_char ch1, u_char ch2)
{
    if (ch1 > 0x2A)
	return((ch2 - 0x41 + (ch1 - 0x26) * 96) << 5);
    else
	return((ch2 - 0x21 + (ch1 - 0x21) * 96) << 5);
}

#ifdef	MINI_KON

#define	GB2312	NULL
#define	BIG5	NULL
#define	KSC5601	NULL

#else

static u_int GB2312(u_char ch1, u_char ch2)
{
    if (ch1 > 0x29)
	return(((ch1 - 0x27) * 94 + ch2 - 0x21) << 5);
    else
	return(((ch1 - 0x21) * 94 + ch2 - 0x21) << 5);
}

static u_int BIG5(u_char ch1, u_char ch2)
{
    if (ch2 < 0xA1)
	return(((ch1 - 0xA1) * 157 + ch2 - 0x40) << 5);
    else
	return(((ch1 - 0xA1) * 157 + 63 + ch2 - 0xA1) << 5);
}

static u_int KSC5601(u_char ch1, u_char ch2)
{
    if (ch1 > 0x2D)
	return((ch2 - 0x21 + (ch1 - 0x24) * 96) << 5);
    else
	return((ch2 - 0x21 + (ch1 - 0x21) * 96) << 5);
}

#endif

static u_int FldJISX0208(u_char ch1, u_char ch2)
{
    return(JISX0208(ch1&0x7F, ch2&0x7F));
}

#ifdef	MINI_KON

#define	FldGB2312	NULL
#define	FldKSC5601	NULL

#else

static u_int FldKSC5601(u_char ch1, u_char ch2)
{
    return(KSC5601(ch1&0x7F, ch2&0x7F));
}

static u_int FldGB2312(u_char ch1, u_char ch2)
{
    return(GB2312(ch1&0x7F, ch2&0x7F));
}

#endif

struct fontRegs fSRegs[] = {
    /* latin1(French, Spanish, ...) */
    {    NULL, 0,      "ISO8859-1", NULL, 0, 0, 'B', 'A', 0},
    /* latin2 */
    {    NULL, 0,      "ISO8859-2", NULL, 0, 0, 'B', 'B', 0},
    /* latin3 */
    {    NULL, 0,      "ISO8859-3", NULL, 0, 0, 'B', 'C', 0},
    /* latin4 */
    {    NULL, 0,      "ISO8859-4", NULL, 0, 0, 'B', 'D', 0},
    /* Russian */
    {    NULL, 0,      "ISO8859-5", NULL, 0, 0, 'B', 'L', 0},
    /* Arabic */
    {    NULL, 0,      "ISO8859-6", NULL, 0, 0, 'B', 'G', 0},
    /* Greek */
    {    NULL, 0,      "ISO8859-7", NULL, 0, 0, 'B', 'F', 0},
    /* Hebrew */
    {    NULL, 0,      "ISO8859-8", NULL, 0, 0, 'B', 'H', 0},
    /* latin5 */
    {    NULL, 0,      "ISO8859-9", NULL, 0, 0, 'B', 'M', 0},
    /* Japanese */
    {    NULL, 0,"JISX0201.1976-0", NULL, 0, 0, 'J', 'I', 0},
    {    NULL, 0,             NULL, NULL, 0, 0,   0,   0, 0}
};

struct fontLoaderRegs fldSRegs[] = {
    {       NULL,   0xFF},
    {       NULL,   0xFF},
    {       NULL,   0xFF},
    {       NULL,   0xFF},
    {       NULL,   0xFF},
    {       NULL,   0xFF},
    {       NULL,   0xFF},
    {       NULL,   0xFF},
    {       NULL,   0xFF},
    {       NULL,   0xFF},
    {       NULL,      0},
};

struct fontRegs fDRegs[] = {
    /* DF_GB2312 */
    {  GB2312, 0,  "GB2312.1980-0", NULL, 0, 0, 'A', 0, 0},
    /* DF_JISX0208 */
    {JISX0208, 0,"JISX0208.1983-0", NULL, 0, 0, 'B', 0, 0},
    /* DF_KSC5601 */
    { KSC5601, 0, "KSC5601.1987-0", NULL, 0, 0, 'C', 0, 0},
    /* DF_JISX0212 */
    {JISX0208, 0,       "JISX0212", NULL, 0, 0, 'D', 0, 0},
    /* DF_BIG5_0 */
    {    BIG5, 0,     "BIG5.HKU-0", NULL, 0, 0, '0', 0, 0},
    /* DF_BIG5_1 */
    {    BIG5, 0,     "BIG5.HKU-0", NULL, 0, 0, '1', 0, 0},
    {    NULL, 0,             NULL, NULL, 0, 0,   0, 0, 0}
};

struct fontLoaderRegs fldDRegs[] = {
    {  FldGB2312,      0},
    {FldJISX0208, 0x7424},
    { FldKSC5601, 0x7D7E},
    {FldJISX0208, 0x7424},
    {       BIG5,      0},
    {       BIG5,      0},
    {       NULL,      0}
};

int CodingByRegistry(char *reg)
{
    int i;

    i = 0;
    while (fSRegs[i].registry) {
	if (!strncasecmp(fSRegs[i].registry, reg, strlen(reg)))
	    return(i|CHR_SFLD);
	i ++;
    }
    i = 0;
    while (fDRegs[i].registry) {
	if (!strncasecmp(fDRegs[i].registry, reg, strlen(reg)))
	    return(i|CHR_DFLD);
	i ++;
    }
    return(-1);
}