w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

kanji.c
Go to the documentation of this file.
1 /*
2  * utilities for japanese
3  */
4 
5 #include "defs.h"
6 #include "global.h"
7 
8 /* jsubfont */
9 #include "jsub.h"
10 
11 char *jsf_names[] = {
12  "",
13  "jsy",
14  "jroma",
15  "jhira",
16  "jkata",
17  "jgreek",
18  "jrussian",
19  "jkeisen",
20  "jka",
21  "jkb",
22  "jkc",
23  "jkd",
24  "jke",
25  "jkf",
26  "jkg",
27  "jkh",
28  "jki",
29  "jkj",
30  "jkk",
31  "jkl",
32  "jkm",
33  "jkn",
34  "jko",
35  "jkp",
36  "jkq",
37  "jkr",
38  "jks",
39  "jkt",
40  "jku",
41  "jkv",
42  "jkw",
43  "jkx",
44  "jky",
45  "jkz",
46  NULL
47 };
48 
49 getjsubfont(n, subend)
50 char *n;
51 char **subend;
52 {
53  int f;
54 
55  for (f = 1; f <= NJSUBS; f++)
56  if (!strncmp(n, jsf_names[f], strlen(jsf_names[f]))) {
57  *subend = n + strlen(jsf_names[f])-1;
58  return f;
59  }
60  return 0;
61 }
62 
63 #define hex(c) (c>='a' ? c-'a'+10 : c-'0')
64 
65 getdcode(n, subend)
66 char *n;
67 char **subend;
68 {
69  if (*n == CSUB_SEP && *(n+3) == CSUB_SEP) {
70  *subend = n+3;
71  return (hex(*(n+1))*16+hex(*(n+2)));
72  }
73  return 0;
74 }
75 
76 #define kushift(c) (c+0x20)
77 #define tenshift(c) (c+0x20)
78 
79 void
81 short f, c;
82 unsigned short *ku, *ten;
83 {
84  int n;
85 
86  if (f <= 7) {
87  if (f == 1) {
88  if (c >= 100) {
89  *ku = kushift(2);
90  *ten = tenshift(c-100);
91  } else {
92  *ku = kushift(1);
93  *ten = tenshift(c);
94  }
95  } else if (f == 2) {
96  *ku = kushift(3);
97  *ten = tenshift(c-32);
98  } else {
99  *ku = kushift(f+1);
100  *ten = tenshift(c);
101  }
102  } else if (f <= 19) { /* Daiichi Suijun */
103  n = (f-8)*256+c;
104  *ku = kushift((n/94)+16);
105  *ten = tenshift((n%94)+1);
106  } else { /* Daini Suijun */
107  n = (f-20)*256+c;
108  *ku = kushift((n/94)+48);
109  *ten = tenshift((n%94)+1);
110  }
111 }
112 
113 void
115 short ku, ten;
116 unsigned short *f, *c;
117 {
118  int n;
119 
120  ku -= 0x20;
121  ten -= 0x20;
122  *f = 1;
123  *c = 1;
124  if (ku <= 0 || (9 <= ku && ku <= 15) || ku > 84) {
125  Warning("invalid ku in jis (%x, %x)", ku+0x20, ten+0x20);
126  return;
127  }
128  if (ten < 1 || ten > 94) {
129  Warning("invalid ten in jis (%x, %x)", ku+0x20, ten+0x20);
130  return;
131  }
132  if (ku <= 8) {
133  if (ku == 1) {
134  *f = 1;
135  *c = ten;
136  } else if (ku == 2) {
137  *f = 1;
138  *c = ten+100;
139  } else if (ku == 3) {
140  *f = 2;
141  *c = ten+32;
142  } else {
143  *f = ku-1;
144  *c = ten;
145  }
146  } else if (ku <= 47) { /* Daiich Suijun */
147  n = (ku-16)*94+ten-1;
148  *f = (n/256)+8;
149  *c = n%256;
150  } else { /* Daini Suijun */
151  n = (ku-48)*94+ten-1;
152  *f = (n/256)+20;
153  *c = n%256;
154  }
155 }
156 
157 void
159 unsigned short s, c;
160 unsigned short *ku, *ten;
161 {
162  if (c >= 128) {
163  *ku = s+1;
164  *ten = c-128;
165  } else {
166  *ku = s;
167  *ten = c;
168  }
169 }
170 
171 #if 0
172 void
173 dcode_to_jis(f, c, ku, ten)
174 unsigned short f, c;
175 unsigned short *ku, *ten;
176 {
177  if (c >= 128) {
178  *ku = f*2+0x20;
179  *ten = c-128;
180  } else {
181  *ku = f*2+0x1f;
182  *ten = c;
183  }
184 }
185 #endif
186 
187 void
189 unsigned short ku, ten;
190 unsigned short *f, *c;
191 {
192  *f = (unsigned short)(ku-0x21)/2 + 1;
193  *c = (ku%2 == 1) ? ten : ten+128;
194 }
195 
197 
198 /* fname is obtained by substituting subfont of sname.
199  * if ini, initial match, otherwise strict match.
200  * sb and se points subfont part of fname.
201  */
202 match_subf(sname, fname, ini, sb, se)
203 char *sname, *fname;
205 char **sb, **se;
206 {
207  *sb = NULL;
208  for (; *sname != '\0'; sname++, fname++) {
209  if (*sname == '%') {
210  if (*++sname == 'j') {
211  if ((foundjsubf = getjsubfont(fname, se)) == 0)
212  return FALSE;
213  } else if (*sname == 'c') {
214  if (*fname == CSUB_SEP && *(fname+3) == CSUB_SEP) {
215  *se = fname+3;
216  } else
217  return FALSE;
218  } else if (*sname == 'd') {
219  if ('0' <= *fname && *fname <= '9') {
220  for (fname++; '0' <= *fname && *fname <= '9'; fname++)
221  ;
222  --fname;
223  continue;
224  } else
225  return FALSE;
226  } else
227  return FALSE;
228  *sb = fname;
229  fname = *se;
230  } else if (*sname != *fname)
231  return FALSE;
232  }
233  if (*fname == '\0')
234  return TRUE;
235  else
236  return ini;
237 }
238 
239 void
240 subst_subf(fname, sname, sb, se)
241 char *fname, *sname;
242 char *sb, *se;
243 {
244  char *s;
245 
246  for (; *sname != '\0'; sname++) {
247  if (*sname == '%') {
248  sname++;
249  for (s = sb; s <= se; s++, fname++)
250  *fname = *s;
251  } else
252  *fname++ = *sname;
253  }
254  *fname = '\0';
255 }
256 
257 /* converts jis code to 94*94 code intex,
258  * but if jis is out of range, return -1
259  */
261 int jis;
262 {
263  int kanji, c1, c2;
264 
265  if ((kanji = jis - 0x2121) < 0)
266  return -1;
267  c1 = (kanji>>8)&0xff;
268  if (c1 >= 94)
269  return -1;
270  c2 = kanji&0xff;
271  if (c2 >= 94)
272  return -1;
273  return (c1*94 + c2);
274 }
275 
277 int idx;
278 {
279  return ((idx/94)*256 + (idx%94) + 0x2121);
280 }
281 
283 short f, c;
284 {
285  unsigned short ku, ten;
286 
287  jsub_to_jis(f, c, &ku, &ten);
288  return jis_to_idx94(ku*256+ten);
289 }
290 
292 int idx;
293 {
294  int i1, i2, c1, c2;
295 
296  i1 = idx/94;
297  i2 = idx%94;
298  if ((i1 & 1) == 0) {
299  if (i1 < 0x3e) c1 = i1/2 + 0x81;
300  else c1 = i1/2 + 0xc1;
301  if (i2 >= 0x3f) c2 = i2 + 0x41;
302  else c2 = i2 + 0x40;
303  } else {
304  if (i1 < 0x3e) c1 = i1/2 + 0x81;
305  else c1 = i1/2 + 0xc1;
306  c2 = i2 + 0x9f;
307  }
308  return (c1*256 + c2);
309 }
310 
312 int jis;
313 {
314  return jis+0x8080;
315 }
316 
318 int jis;
319 {
320  return idx94_to_sjis(jis_to_idx94(jis));
321 }
#define kanji
Definition: aptex-macros.h:366
#define n
Definition: t4ht.c:1290
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
void Warning(const char *sb1, const char *sb2)
Definition: detex.c:4677
#define ku(c)
Definition: decompfont.c:104
#define ten(c)
Definition: decompfont.c:105
#define NJSUBS
Definition: jsub.h:1
#define CSUB_SEP
Definition: jsub.h:11
void subst_subf(char *fname, char *sname, char *sb, char *se)
Definition: kanji.c:232
jis_to_idx94(unsigned int jis)
Definition: kanji.c:252
void jis_to_jsub(short ku, short ten, unsigned short *f, unsigned short *c)
Definition: kanji.c:114
void code_to_jis(unsigned short s, unsigned short c, unsigned short *ku, unsigned short *ten)
Definition: kanji.c:158
getdcode(char *n, char **subend)
Definition: kanji.c:65
getjsubfont(char *n, char **subend)
Definition: kanji.c:49
match_subf(char *sname, char *fname, int ini, char **sb, char **se)
Definition: kanji.c:202
int foundjsubf
Definition: kanji.c:196
void jis_to_dcode(unsigned short ku, unsigned short ten, unsigned short *f, unsigned short *c)
Definition: kanji.c:188
char * jsf_names[]
Definition: kanji.c:11
void jsub_to_jis(short f, short c, unsigned short *ku, unsigned short *ten)
Definition: kanji.c:80
int __BOOLEAN__
Definition: defs.h:174
idx94_to_sjis(int idx)
Definition: kanji.c:291
jis_to_euc(int jis)
Definition: kanji.c:311
idx94_to_std(int idx)
Definition: kanji.c:276
#define tenshift(c)
Definition: kanji.c:77
jsub_to_idx94(short f, short c)
Definition: kanji.c:282
jis_to_sjis(int jis)
Definition: kanji.c:317
#define kushift(c)
Definition: kanji.c:76
#define hex(c)
Definition: kanji.c:63
mpz_t * f
Definition: gen-fib.c:34
#define s
Definition: afcover.h:80
#define c(n)
Definition: gpos-common.c:150
#define NULL
Definition: ftobjs.h:61
FT_UInt idx
Definition: cffcmap.c:135
FILE * ini
Definition: splitup.c:53
int strncmp()
char * fname
Definition: plain2.c:121
#define c2
Definition: t1io.c:53
#define c1
Definition: t1io.c:52
*job_name strlen((char *) job_name) - 4)