src/jfmbi.c
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- vf_tfm_builtin_jfm_chartype
- vf_tfm_builtin_jfm_metric
1 /*
2 * jfmbi.c - built-in JFM
3 *
4 * 9 Dec 1999 Added built-in JFM feature.
5 */
6 /*
7 * Copyright (C) 1999 Hirotsugu Kakugawa.
8 * All rights reserved.
9 *
10 * This file is part of the VFlib Library. This library is free
11 * software; you can redistribute it and/or modify it under the terms of
12 * the GNU Library General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your
14 * option) any later version. This library is distributed in the hope
15 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
16 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17 * PURPOSE. See the GNU Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23 #include "config.h"
24 #include "with.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <ctype.h>
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
32 #include "VFlib-3_6.h"
33 #include "VFsys.h"
34 #include "metric.h"
35 #include "jfmbi.h"
36
37
38
39 struct s_jfm_builtin_chartype_info {
40 int char_code;
41 int char_type;
42 };
43
44 static struct s_jfm_builtin_chartype_info
45 jfm_builtin_chartype_info_table_h[] = {
46 /* obtained by running mkbijfm.scm */
47 {0x2122, 9},
48 {0x2123, 9},
49 {0x2124, 8},
50 {0x2125, 8},
51 {0x2126, 4},
52 {0x2127, 4},
53 {0x2128, 4},
54 {0x2129, 5},
55 {0x212a, 4},
56 {0x212b, 2},
57 {0x212c, 2},
58 {0x212d, 4},
59 {0x212e, 4},
60 {0x212f, 5},
61 {0x2130, 5},
62 {0x2133, 5},
63 {0x2135, 5},
64 {0x2136, 3},
65 {0x2137, 3},
66 {0x2139, 3},
67 {0x213e, 4},
68 {0x2142, 4},
69 {0x2143, 4},
70 {0x2146, 4},
71 {0x2147, 4},
72 {0x2148, 5},
73 {0x2149, 5},
74 {0x214a, 6},
75 {0x214b, 1},
76 {0x214c, 6},
77 {0x214d, 1},
78 {0x214e, 6},
79 {0x214f, 1},
80 {0x2150, 6},
81 {0x2151, 1},
82 {0x2152, 6},
83 {0x2153, 1},
84 {0x2154, 6},
85 {0x2155, 1},
86 {0x2156, 6},
87 {0x2157, 1},
88 {0x2158, 6},
89 {0x2159, 1},
90 {0x215a, 6},
91 {0x215b, 1},
92 {0x2168, 3},
93 {0x2169, 3},
94 {0x216a, 3},
95 {0x216b, 5},
96 {0x216c, 5},
97 {0x216d, 5},
98 {0x2170, 3},
99 {0x2171, 3},
100 {0x2172, 3},
101 {0x2178, 5},
102 {0x2421, 3},
103 {0x2423, 3},
104 {0x2425, 3},
105 {0x2426, 7},
106 {0x2427, 3},
107 {0x2429, 3},
108 {0x242f, 7},
109 {0x2430, 7},
110 {0x2431, 7},
111 {0x2432, 7},
112 {0x2439, 7},
113 {0x243a, 7},
114 {0x2443, 3},
115 {0x2463, 3},
116 {0x2465, 3},
117 {0x2467, 3},
118 {0x246a, 7},
119 {0x246e, 3},
120 {0x2521, 3},
121 {0x2522, 10},
122 {0x2523, 3},
123 {0x2524, 10},
124 {0x2525, 3},
125 {0x2526, 10},
126 {0x2527, 3},
127 {0x2529, 3},
128 {0x252a, 10},
129 {0x252f, 11},
130 {0x2530, 11},
131 {0x2531, 10},
132 {0x2532, 10},
133 {0x2535, 10},
134 {0x2536, 10},
135 {0x253d, 10},
136 {0x253e, 10},
137 {0x253f, 11},
138 {0x2540, 11},
139 {0x2541, 10},
140 {0x2542, 10},
141 {0x2543, 3},
142 {0x2544, 10},
143 {0x2545, 10},
144 {0x2546, 7},
145 {0x2547, 7},
146 {0x2548, 10},
147 {0x2549, 10},
148 {0x254a, 10},
149 {0x254e, 12},
150 {0x2555, 10},
151 {0x2556, 10},
152 {0x2557, 10},
153 {0x255f, 10},
154 {0x2561, 10},
155 {0x2563, 3},
156 {0x2564, 7},
157 {0x2565, 3},
158 {0x2567, 3},
159 {0x2569, 10},
160 {0x256a, 10},
161 {0x256e, 3},
162 {0x256f, 10},
163 {0x2572, 10},
164 {0x2575, 3},
165 {0x2576, 3},
166 {0x2577, 3},
167 };
168
169 static struct s_jfm_builtin_chartype_info
170 jfm_builtin_chartype_info_table_v[] = {
171 /* obtained by running mkbijfm.scm */
172 {0x2122, 2},
173 {0x2123, 2},
174 {0x2124, 1},
175 {0x2125, 1},
176 {0x2126, 7},
177 {0x2129, 4},
178 {0x212a, 4},
179 {0x2133, 3},
180 {0x2134, 3},
181 {0x2135, 3},
182 {0x2136, 3},
183 {0x2137, 3},
184 {0x2139, 3},
185 {0x213d, 5},
186 {0x213e, 7},
187 {0x2142, 7},
188 {0x2143, 7},
189 {0x2144, 5},
190 {0x2145, 5},
191 {0x2146, 6},
192 {0x2147, 8},
193 {0x2148, 6},
194 {0x2149, 8},
195 {0x214a, 6},
196 {0x214b, 8},
197 {0x214c, 6},
198 {0x214d, 8},
199 {0x214e, 6},
200 {0x214f, 8},
201 {0x2150, 6},
202 {0x2151, 8},
203 {0x2152, 6},
204 {0x2153, 8},
205 {0x2154, 6},
206 {0x2155, 8},
207 {0x2156, 6},
208 {0x2157, 8},
209 {0x2158, 6},
210 {0x2159, 8},
211 {0x215a, 6},
212 {0x215b, 8},
213 {0x2421, 3},
214 {0x2423, 3},
215 {0x2425, 3},
216 {0x2427, 3},
217 {0x2429, 3},
218 {0x2443, 3},
219 {0x2463, 3},
220 {0x2465, 3},
221 {0x2467, 3},
222 {0x246e, 3},
223 {0x2521, 3},
224 {0x2523, 3},
225 {0x2525, 3},
226 {0x2527, 3},
227 {0x2529, 3},
228 {0x2543, 3},
229 {0x2563, 3},
230 {0x2565, 3},
231 {0x2567, 3},
232 {0x256e, 3},
233 {0x2575, 3},
234 {0x2576, 3},
235 };
236
237 Glocal int
238 vf_tfm_builtin_jfm_chartype(long code_point, int dir_h)
/* [<][>][^][v][top][bottom][index][help] */
239 {
240 int n, nh, nv, hi, lo, m;
241 struct s_jfm_builtin_chartype_info *tbl;
242
243 nh = sizeof(jfm_builtin_chartype_info_table_h)
244 / sizeof(struct s_jfm_builtin_chartype_info);
245 nv = sizeof(jfm_builtin_chartype_info_table_v)
246 / sizeof(struct s_jfm_builtin_chartype_info);
247
248 if (dir_h == 1){
249 n = nh;
250 tbl = jfm_builtin_chartype_info_table_h;
251 } else {
252 n = nv;
253 tbl = jfm_builtin_chartype_info_table_v;
254 }
255
256 if ((code_point < tbl[0].char_code) || (tbl[n-1].char_code < code_point))
257 return 0;
258
259 lo = 0;
260 hi = n - 1;
261 while (lo < hi){
262 m = (lo + hi) / 2;
263 if (tbl[m].char_code == code_point)
264 return tbl[m].char_type;
265 if (code_point < tbl[m].char_code)
266 hi = m-1;
267 else
268 lo = m+1;
269 }
270
271 return 0;
272 }
273
274
275 struct s_jfm_builtin_metrics_info {
276 int char_type;
277 double wd, ht, dp;
278 };
279
280 static struct s_jfm_builtin_metrics_info
281 jfm_builtin_metrics_info_table_h[] = {
282 /* obtained by running mkbijfm2.scm */
283 { 0, 0.962216, 0.777588, 0.138855},
284 { 1, 0.504013, 0.777588, 0.138855},
285 { 2, 0.353665, 0.777588, 0.138855},
286 { 3, 0.747434, 0.777588, 0.138855},
287 { 4, 0.353665, 0.777588, 0.138855},
288 { 5, 0.504013, 0.777588, 0.138855},
289 { 6, 0.504013, 0.777588, 0.138855},
290 { 7, 0.962216, 0.777588, 0.138855},
291 { 8, 0.353665, 0.777588, 0.138855},
292 { 9, 0.504013, 0.777588, 0.138855},
293 {10, 0.962216, 0.777588, 0.138855},
294 {11, 0.962216, 0.777588, 0.138855},
295 {12, 0.962216, 0.777588, 0.138855}
296 };
297
298 static struct s_jfm_builtin_metrics_info
299 jfm_builtin_metrics_info_table_v[] = {
300 /* obtained by running mkbijfm2.scm */
301 { 0, 0.962216, 0.458221, 0.458221},
302 { 1, 0.481108, 0.458221, 0.458221},
303 { 2, 0.481108, 0.458221, 0.458221},
304 { 3, 0.747434, 0.458221, 0.458221},
305 { 4, 0.962216, 0.458221, 0.458221},
306 { 5, 0.962216, 0.458221, 0.458221},
307 { 6, 0.481108, 0.458221, 0.458221},
308 { 7, 0.481108, 0.458221, 0.458221},
309 { 8, 0.481108, 0.458221, 0.458221},
310 };
311
312
313 Glocal VF_METRIC1
314 vf_tfm_builtin_jfm_metric(long code_point, VF_METRIC1 metric,
/* [<][>][^][v][top][bottom][index][help] */
315 int dir_h, double design_size)
316 {
317 int ct;
318 double w, h, d;
319 struct s_jfm_builtin_metrics_info *tbl;
320
321 if ((ct = vf_tfm_builtin_jfm_chartype(code_point, dir_h)) < 0)
322 return NULL;
323
324 if (dir_h == 1){
325 tbl = jfm_builtin_metrics_info_table_h;
326 } else {
327 tbl = jfm_builtin_metrics_info_table_v;
328 }
329
330 if (metric == NULL){
331 if ((metric = vf_alloc_metric1()) == NULL)
332 return NULL;
333 }
334
335 w = design_size * tbl[ct].wd;
336 h = design_size * tbl[ct].ht;
337 d = design_size * tbl[ct].dp;
338
339 if (dir_h == 1){
340 metric->bbx_width = w;
341 metric->bbx_height = h + d;
342 metric->off_x = 0;
343 metric->off_y = h;
344 metric->mv_x = w;
345 metric->mv_y = 0;
346 } else {
347 metric->bbx_width = h + d;
348 metric->bbx_height = w;
349 metric->off_x = -d;
350 metric->off_y = 0;
351 metric->mv_x = 0;
352 metric->mv_y = -w;
353 }
354
355 return metric;
356 }
357
358 /*EOF*/