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;
204 int ini;
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
219  return FALSE;
220  *sb = fname;
221  fname = *se;
222  } else if (*sname != *fname)
223  return FALSE;
224  }
225  if (*fname == '\0')
226  return TRUE;
227  else
228  return ini;
229 }
230 
231 void
232 subst_subf(fname, sname, sb, se)
233 char *fname, *sname;
234 char *sb, *se;
235 {
236  char *s;
237 
238  for (; *sname != '\0'; sname++) {
239  if (*sname == '%') {
240  sname++;
241  for (s = sb; s <= se; s++, fname++)
242  *fname = *s;
243  } else
244  *fname++ = *sname;
245  }
246  *fname = '\0';
247 }
248 
249 /* converts jis code to 94*94 code intex,
250  * but if jis is out of range, return -1
251  */
253 unsigned int jis;
254 {
255  int kanji, c1, c2;
256 
257  if ((kanji = jis - 0x2121) < 0)
258  return -1;
259  c1 = (kanji>>8)&0xff;
260  if (c1 >= 94)
261  return -1;
262  c2 = kanji&0xff;
263  if (c2 >= 94)
264  return -1;
265  return (c1*94 + c2);
266 }
267 
268 #ifdef UNDEF
270 int idx;
271 {
272  return ((idx/94)*256 + (idx%94) + 0x2121);
273 }
274 
275 jsub_to_idx94(f, c)
276 short f, c;
277 {
278  unsigned short ku, ten;
279 
280  jsub_to_jis(f, c, &ku, &ten);
281  return jis_to_idx94(ku*256+ten);
282 }
283 
285 int idx;
286 {
287  int i1, i2, c1, c2;
288 
289  i1 = idx/94;
290  i2 = idx%94;
291  if ((i1 & 1) == 0) {
292  if (i1 < 0x3e) c1 = i1/2 + 0x81;
293  else c1 = i1/2 + 0xc1;
294  if (i2 >= 0x3f) c2 = i2 + 0x41;
295  else c2 = i2 + 0x40;
296  } else {
297  if (i1 < 0x3e) c1 = i1/2 + 0x81;
298  else c1 = i1/2 + 0xc0;
299  c2 = i2 + 0x9f;
300  }
301  return (c1*256 + c2);
302 }
303 #endif
#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
#define tenshift(c)
Definition: kanji.c:77
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
#define kushift(c)
Definition: kanji.c:76
void jis_to_dcode(unsigned short ku, unsigned short ten, unsigned short *f, unsigned short *c)
Definition: kanji.c:188
#define hex(c)
Definition: kanji.c:63
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
idx94_to_sjis(int idx)
Definition: kanji.c:291
idx94_to_std(int idx)
Definition: kanji.c:276
jsub_to_idx94(short f, short c)
Definition: kanji.c:282
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)