2
* drv_ekan.c - A font driver for eKanji format fonts.
3
* by Hirotsugu Kakugawa
5
* 8 Dec 1999 First implementation.
6
* 18 Oct 2001 Fixed memory leak.
9
* Copyright (C) 1999-2001 Hirotsugu Kakugawa.
10
* All rights reserved.
12
* This file is part of the VFlib Library. This library is free
13
* software; you can redistribute it and/or modify it under the terms of
14
* the GNU Library General Public License as published by the Free
15
* Software Foundation; either version 2 of the License, or (at your
16
* option) any later version. This library is distributed in the hope
17
* that it will be useful, but WITHOUT ANY WARRANTY; without even the
18
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19
* PURPOSE. See the GNU Library General Public License for more details.
20
* You should have received a copy of the GNU Library General Public
21
* License along with this library; if not, write to the Free Software
22
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34
#include "VFlib-3_6.h"
57
double vec_bbxul_x, vec_bbxul_y;
58
double vec_next_x, vec_next_y;
64
typedef struct s_font_ek *FONT_EK;
66
Private SEXP_LIST default_fontdirs;
67
Private SEXP_STRING default_point_size;
68
Private double v_default_point_size;
69
Private SEXP_STRING default_pixel_size;
70
Private double v_default_pixel_size;
71
Private SEXP_STRING default_font_dot_size;
72
Private int v_default_font_dot_size;
73
Private SEXP_STRING default_dpi, default_dpi_x, default_dpi_y;
74
Private double v_default_dpi_x, v_default_dpi_y;
75
Private SEXP_STRING default_aspect;
76
Private double v_default_aspect;
77
Private SEXP_STRING default_direction;
78
Private int v_default_direction;
79
Private SEXP_LIST default_vec_bbxul;
80
Private double v_default_vec_bbxul_x, v_default_vec_bbxul_y;
81
Private SEXP_LIST default_vec_next;
82
Private double v_default_vec_next_x, v_default_vec_next_y;
83
Private SEXP_ALIST default_properties;
84
Private SEXP_ALIST default_variables;
85
Private SEXP_STRING default_debug_mode;
86
Private char *env_debug_mode = NULL;
87
#define DEBUG_ENV_NAME "VFLIB_EKANJI_DEBUG"
90
Private int ek_create(VF_FONT font, char *font_class,
91
char *font_name, int implicit, SEXP entry);
92
Private int ek_close(VF_FONT font);
93
Private int ek_get_metric1(VF_FONT font, long code_point,
94
VF_METRIC1 metric1, double,double);
95
Private int ek_get_metric2(VF_FONT font, long code_point,
96
VF_METRIC2 metric2, double,double);
97
Private int ek_get_fontbbx1(VF_FONT font,double,double,
98
double*,double*,double*,double*);
99
Private int ek_get_fontbbx2(VF_FONT font, double,double,
100
int*,int*,int*,int*);
101
Private VF_BITMAP ek_get_bitmap1(VF_FONT,long,double,double);
102
Private VF_BITMAP ek_get_bitmap2(VF_FONT,long,double,double);
103
Private VF_OUTLINE ek_get_outline1(VF_FONT,long,double,double);
104
Private char* ek_get_font_prop(VF_FONT,char*);
107
Private int ek_debug(char);
108
Private int ek_debug2(char type, char *str);
110
Private VF_BITMAP ek_file_read(FONT_EK font_ek, long cp);
111
Private void ek_file_init(FONT_EK font_ek);
117
VF_Init_Driver_EKanji(void)
122
struct s_capability_table ct[30];
125
/* VF_CAPE_FONT_DIRECTORIES */
126
ct[z].cap = VF_CAPE_FONT_DIRECTORIES; ct[z].type = CAPABILITY_STRING_LIST0;
127
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_fontdirs;
128
/* VF_CAPE_EK_FONT_DOT_SIZE */
129
ct[z].cap = VF_CAPE_EK_FONT_DOT_SIZE; ct[z].type = CAPABILITY_STRING;
130
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_font_dot_size;
131
/* VF_CAPE_POINT_SIZE */
132
ct[z].cap = VF_CAPE_POINT_SIZE; ct[z].type = CAPABILITY_STRING;
133
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_point_size;
134
/* VF_CAPE_PIXEL_SIZE */
135
ct[z].cap = VF_CAPE_PIXEL_SIZE; ct[z].type = CAPABILITY_STRING;
136
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_pixel_size;
138
ct[z].cap = VF_CAPE_DPI; ct[z].type = CAPABILITY_STRING;
139
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_dpi;
141
ct[z].cap = VF_CAPE_DPI_X; ct[z].type = CAPABILITY_STRING;
142
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_dpi_x;
144
ct[z].cap = VF_CAPE_DPI_Y; ct[z].type = CAPABILITY_STRING;
145
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_dpi_y;
146
/* VF_CAPE_DIRECTION */
147
ct[z].cap = VF_CAPE_DIRECTION; ct[z].type = CAPABILITY_STRING;
148
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_direction;
149
/* VF_CAPE_VECTOR_TO_BBX_UL */
150
ct[z].cap = VF_CAPE_VECTOR_TO_BBX_UL; ct[z].type = CAPABILITY_VECTOR;
151
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_vec_bbxul;
152
/* VF_CAPE_VECTOR_TO_NEXT */
153
ct[z].cap = VF_CAPE_VECTOR_TO_NEXT; ct[z].type = CAPABILITY_VECTOR;
154
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_vec_next;
155
/* VF_CAPE_ASPECT_RATIO */
156
ct[z].cap = VF_CAPE_ASPECT_RATIO; ct[z].type = CAPABILITY_STRING;
157
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_aspect;
158
/* VF_CAPE_PROPERTIES */
159
ct[z].cap = VF_CAPE_PROPERTIES; ct[z].type = CAPABILITY_ALIST;
160
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_properties;
161
/* VF_CAPE_VARIABLE_VALUES */
162
ct[z].cap = VF_CAPE_VARIABLE_VALUES; ct[z].type = CAPABILITY_ALIST;
163
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_variables;
165
ct[z].cap = VF_CAPE_DEBUG; ct[z].type = CAPABILITY_STRING;
166
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &default_debug_mode;
168
ct[z].cap = NULL; ct[z].type = 0; ct[z].ess = 0; ct[z++].val = NULL;
170
if (vf_cap_GetParsedClassDefault(FONTCLASS_NAME, ct, NULL, NULL)
171
== VFLIBCAP_PARSED_ERROR)
174
v_default_font_dot_size = DEFAULT_FONT_DOT_SIZE;
175
if (default_font_dot_size != NULL)
176
v_default_font_dot_size = atoi(vf_sexp_get_cstring(default_font_dot_size));
178
v_default_point_size = DEFAULT_POINT_SIZE;
179
if (default_point_size != NULL)
180
v_default_point_size = atof(vf_sexp_get_cstring(default_point_size));
181
if (v_default_point_size < 0)
182
v_default_point_size = DEFAULT_POINT_SIZE;
184
v_default_pixel_size = DEFAULT_PIXEL_SIZE;
185
if (default_pixel_size != NULL)
186
v_default_pixel_size = atof(vf_sexp_get_cstring(default_pixel_size));
187
if (v_default_pixel_size < 0)
188
v_default_pixel_size = DEFAULT_PIXEL_SIZE;
190
v_default_dpi_x = -1;
191
v_default_dpi_y = -1;
192
if (default_dpi != NULL)
193
v_default_dpi_x = v_default_dpi_y = atof(vf_sexp_get_cstring(default_dpi));
194
if (default_dpi_x != NULL)
195
v_default_dpi_x = atof(vf_sexp_get_cstring(default_dpi_x));
196
if (default_dpi_y != NULL)
197
v_default_dpi_y = atof(vf_sexp_get_cstring(default_dpi_y));
199
v_default_aspect = 1.0;
200
if (default_aspect != NULL)
201
v_default_aspect = atof(vf_sexp_get_cstring(default_aspect));
203
v_default_direction = DEFAULT_DIRECTION;
204
if (default_direction != NULL){
205
p = vf_sexp_get_cstring(default_direction);
206
if ((*p == 'h') || (*p == 'H')){
207
v_default_direction = DIRECTION_HORIZONTAL;
208
} else if ((*p == 'v') || (*p == 'V')){
209
v_default_direction = DIRECTION_VERTICAL;
211
fprintf(stderr, "VFlib warning: Unknown writing direction: %s\n", p);
215
switch(v_default_direction){
217
case DIRECTION_HORIZONTAL:
218
v_default_vec_bbxul_x = 0;
219
v_default_vec_bbxul_y = DEFAULT_TO_REF_PT_H;
220
v_default_vec_next_x = 1.0;
221
v_default_vec_next_y = 0.0;
223
case DIRECTION_VERTICAL:
224
v_default_vec_bbxul_x = DEFAULT_TO_REF_PT_V;
225
v_default_vec_bbxul_y = 0;
226
v_default_vec_next_x = 0.0;
227
v_default_vec_next_y = -1.0;
231
if (default_vec_bbxul != NULL){
232
s1 = vf_sexp_car(default_vec_bbxul);
233
s2 = vf_sexp_cadr(default_vec_bbxul);
234
v_default_vec_bbxul_x = atof(vf_sexp_get_cstring(s1));
235
v_default_vec_bbxul_y = atof(vf_sexp_get_cstring(s2));
237
if (default_vec_next != NULL){
238
s1 = vf_sexp_car(default_vec_next);
239
s2 = vf_sexp_cadr(default_vec_next);
240
v_default_vec_next_x = atof(vf_sexp_get_cstring(s1));
241
v_default_vec_next_y = atof(vf_sexp_get_cstring(s2));
244
env_debug_mode = getenv(DEBUG_ENV_NAME);
246
VF_InstallFontDriver(FONTCLASS_NAME, (DRIVER_FUNC_TYPE)ek_create);
253
ek_create(VF_FONT font, char *font_class,
254
char *font_name, int implicit, SEXP entry)
259
char *path_name, *font_file, *p;
260
SEXP cap_fontdirs, cap_font_dot_size, cap_font, cap_point, cap_pixel;
261
SEXP cap_dpi, cap_dpi_x, cap_dpi_y, cap_mag, cap_aspect;
262
SEXP cap_charset, cap_encoding, cap_font_charset, cap_font_encoding;
263
SEXP cap_props, cap_direction, cap_vec_bbxul, cap_vec_next;
265
SEXP fontdirs, s1, s2;
266
char *charset, *encoding, *font_charset, *font_encoding;
268
struct s_capability_table ct[30];
271
/* VF_CAPE_FONT_CLASS */
272
ct[z].cap = VF_CAPE_FONT_CLASS; ct[z].type = CAPABILITY_STRING;
273
ct[z].ess = CAPABILITY_ESSENTIAL; ct[z++].val = NULL;
274
/* VF_CAPE_EK_FONT_DOT_SIZE */
275
ct[z].cap = VF_CAPE_EK_FONT_DOT_SIZE; ct[z].type = CAPABILITY_STRING;
276
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_font_dot_size;
277
/* VF_CAPE_EK_MOCK_FONT_ENC */
278
ct[z].cap = VF_CAPE_EK_MOCK_FONT_ENC; ct[z].type = CAPABILITY_STRING_LIST0;
279
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_mock_enc;
280
/* VF_CAPE_FONT_DIRECTORIES */
281
ct[z].cap = VF_CAPE_FONT_DIRECTORIES; ct[z].type = CAPABILITY_STRING_LIST0;
282
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_fontdirs;
283
/* VF_CAPE_DIRECTION */
284
ct[z].cap = VF_CAPE_DIRECTION; ct[z].type = CAPABILITY_STRING;
285
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_direction;
286
/* VF_CAPE_VECTOR_TO_BBX_UL */
287
ct[z].cap = VF_CAPE_VECTOR_TO_BBX_UL; ct[z].type = CAPABILITY_VECTOR;
288
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_vec_bbxul;
289
/* VF_CAPE_VECTOR_TO_NEXT */
290
ct[z].cap = VF_CAPE_VECTOR_TO_NEXT; ct[z].type = CAPABILITY_VECTOR;
291
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_vec_next;
292
/* VF_CAPE_FONT_FILE */
293
ct[z].cap = VF_CAPE_FONT_FILE; ct[z].type = CAPABILITY_STRING;
294
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_font;
295
/* VF_CAPE_POINT_SIZE */
296
ct[z].cap = VF_CAPE_POINT_SIZE; ct[z].type = CAPABILITY_STRING;
297
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_point;
298
/* VF_CAPE_PIXEL_SIZE */
299
ct[z].cap = VF_CAPE_PIXEL_SIZE; ct[z].type = CAPABILITY_STRING;
300
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_pixel;
302
ct[z].cap = VF_CAPE_DPI; ct[z].type = CAPABILITY_STRING;
303
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_dpi;
305
ct[z].cap = VF_CAPE_DPI_X; ct[z].type = CAPABILITY_STRING;
306
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_dpi_x;
308
ct[z].cap = VF_CAPE_DPI_Y; ct[z].type = CAPABILITY_STRING;
309
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_dpi_y;
311
ct[z].cap = VF_CAPE_MAG; ct[z].type = CAPABILITY_STRING;
312
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_mag;
313
/* VF_CAPE_ASPECT_RATIO */
314
ct[z].cap = VF_CAPE_ASPECT_RATIO; ct[z].type = CAPABILITY_STRING;
315
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_aspect;
316
/* VF_CAPE_CHARSET */
317
ct[z].cap = VF_CAPE_CHARSET; ct[z].type = CAPABILITY_STRING;
318
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_charset;
319
/* VF_CAPE_ENCODING */
320
ct[z].cap = VF_CAPE_ENCODING; ct[z].type = CAPABILITY_STRING;
321
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_encoding;
322
/* VF_CAPE_FONT_CHARSET */
323
ct[z].cap = VF_CAPE_FONT_CHARSET; ct[z].type = CAPABILITY_STRING;
324
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_font_charset;
325
/* VF_CAPE_FONT_ENCODING */
326
ct[z].cap = VF_CAPE_FONT_ENCODING; ct[z].type = CAPABILITY_STRING;
327
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_font_encoding;
328
/* VF_CAPE_PROPERTIES */
329
ct[z].cap = VF_CAPE_PROPERTIES; ct[z].type = CAPABILITY_ALIST;
330
ct[z].ess = CAPABILITY_OPTIONAL; ct[z++].val = &cap_props;
332
ct[z].cap = NULL; ct[z].type = 0; ct[z].ess = 0; ct[z++].val = NULL;
336
font_file = font_name;
337
fontdirs = default_fontdirs;
340
if (implicit == 1){ /* implicit font */
341
font_file = font_name;
342
} else { /* explicit font */
343
if (vf_cap_GetParsedFontEntry(entry, font_name, ct,
344
default_variables, NULL)
345
== VFLIBCAP_PARSED_ERROR)
347
if (cap_fontdirs != NULL)
348
fontdirs = cap_fontdirs;
349
if (cap_font != NULL){
350
font_file = vf_sexp_get_cstring(cap_font);
352
/* Use font name as font file name if font file name is not given. */
353
font_file = font_name;
358
printf("eKanji font file to open %s\n", font_file);
359
path_name = vf_search_file(font_file, -1, NULL, FALSE, -1,
360
fontdirs, NULL, NULL);
361
if (path_name == NULL){
363
printf("eKanji font file not found\n");
364
vf_error = VF_ERR_NO_FONT_FILE;
368
printf("eKanji Font File: %s ==> %s\n", font_file, path_name);
369
if ((fp = vf_fm_OpenBinaryFileStream(path_name)) == NULL){
370
vf_error = VF_ERR_NO_FONT_FILE;
374
font->font_type = VF_FONT_TYPE_BITMAP;
375
font->get_metric1 = ek_get_metric1;
376
font->get_metric2 = ek_get_metric2;
377
font->get_fontbbx1 = ek_get_fontbbx1;
378
font->get_fontbbx2 = ek_get_fontbbx2;
379
font->get_bitmap1 = ek_get_bitmap1;
380
font->get_bitmap2 = ek_get_bitmap2;
381
font->get_outline = ek_get_outline1;
382
font->get_font_prop = ek_get_font_prop;
383
font->query_font_type = NULL;
384
font->close = ek_close;
386
ALLOC_IF_ERR(font_ek, struct s_font_ek){
387
vf_error = VF_ERR_NO_MEMORY;
391
font_ek->font_path = path_name;
392
font_ek->font_name = NULL;
393
font_ek->font_file = NULL;
394
font_ek->font_dot_size = v_default_font_dot_size;
395
font_ek->mock_encoding = MOCK_FONT_ENC_RAW;
396
font_ek->mock_enc_arg = 0;
397
font_ek->point_size = v_default_point_size;
398
font_ek->pixel_size = v_default_pixel_size;
399
font_ek->dpi_x = v_default_dpi_x;
400
font_ek->dpi_y = v_default_dpi_y;
402
font_ek->aspect = v_default_aspect;
403
font_ek->ccv_id = -1;
404
font_ek->direction = v_default_direction;
405
font_ek->vec_bbxul_x = v_default_vec_bbxul_x;
406
font_ek->vec_bbxul_y = v_default_vec_bbxul_y;
407
font_ek->vec_next_x = v_default_vec_next_x;
408
font_ek->vec_next_y = v_default_vec_next_y;
409
font_ek->props = NULL;
414
font_encoding = NULL;
417
if (cap_font_dot_size != NULL)
418
font_ek->font_dot_size = atoi(vf_sexp_get_cstring(cap_font_dot_size));
419
if (cap_mock_enc != NULL){
420
len = vf_sexp_length(cap_mock_enc);
422
p = vf_sexp_get_cstring(vf_sexp_car(cap_mock_enc));
423
if (vf_strcmp_ci(p, CAPE_MOCK_FONT_ENC_RAW) == 0){
424
font_ek->mock_encoding = MOCK_FONT_ENC_RAW;
425
} else if (vf_strcmp_ci(p, CAPE_MOCK_FONT_ENC_SUBBLOCKS_94X94) == 0){
426
font_ek->mock_encoding = MOCK_FONT_ENC_SUBBLOCKS_94X94;
427
} else if (vf_strcmp_ci(p, CAPE_MOCK_FONT_ENC_SUBBLOCKS_94X60) == 0){
428
font_ek->mock_encoding = MOCK_FONT_ENC_SUBBLOCKS_94X60;
429
} else if (vf_strcmp_ci(p, CAPE_MOCK_FONT_ENC_WITH_OFFSET) == 0){
430
font_ek->mock_encoding = MOCK_FONT_ENC_WITH_OFFSET;
433
"VFlib warning: unknown keyword `%s' in capability %s\n",
434
p, VF_CAPE_EK_MOCK_FONT_ENC);
438
p = vf_sexp_get_cstring(vf_sexp_cadr(cap_mock_enc));
440
sscanf(p+1, "%li", &font_ek->mock_enc_arg);
441
font_ek->mock_enc_arg = -font_ek->mock_enc_arg;
442
} else if (*p == '+'){
443
sscanf(p+1, "%li", &font_ek->mock_enc_arg);
445
sscanf(p, "%li", &font_ek->mock_enc_arg);
449
if (cap_point != NULL)
450
font_ek->point_size = atof(vf_sexp_get_cstring(cap_point));
451
if (cap_pixel != NULL)
452
font_ek->pixel_size = atof(vf_sexp_get_cstring(cap_pixel));
454
font_ek->dpi_x = font_ek->dpi_y = atof(vf_sexp_get_cstring(cap_dpi));
455
if (cap_dpi_x != NULL)
456
font_ek->dpi_x = atof(vf_sexp_get_cstring(cap_dpi_x));
457
if (cap_dpi_y != NULL)
458
font_ek->dpi_y = atof(vf_sexp_get_cstring(cap_dpi_y));
460
font_ek->mag = atof(vf_sexp_get_cstring(cap_mag));
461
if (cap_aspect != NULL)
462
font_ek->aspect = atof(vf_sexp_get_cstring(cap_aspect));
463
if (cap_charset != NULL)
464
charset = vf_sexp_get_cstring(cap_charset);
465
if (cap_encoding != NULL)
466
encoding = vf_sexp_get_cstring(cap_encoding);
467
if (cap_encoding != NULL)
468
font_encoding = vf_sexp_get_cstring(cap_encoding);
469
if (cap_font_charset != NULL)
470
font_charset = vf_sexp_get_cstring(cap_font_charset);
471
if (cap_font_encoding != NULL)
472
font_encoding = vf_sexp_get_cstring(cap_font_encoding);
473
if (cap_direction != NULL){
474
p = vf_sexp_get_cstring(cap_direction);
475
if ((*p == 'h') || (*p == 'H')){
476
font_ek->direction = DIRECTION_HORIZONTAL;
477
} else if ((*p == 'v') || (*p == 'V')){
478
font_ek->direction = DIRECTION_VERTICAL;
480
fprintf(stderr, "VFlib warning: Unknown writing direction: %s\n", p);
483
switch(font_ek->direction){
485
case DIRECTION_HORIZONTAL:
486
font_ek->vec_bbxul_x = v_default_vec_bbxul_x;
487
font_ek->vec_bbxul_y = v_default_vec_bbxul_y;
488
font_ek->vec_next_x = v_default_vec_next_x;
489
font_ek->vec_next_y = v_default_vec_next_y;
491
case DIRECTION_VERTICAL:
492
font_ek->vec_bbxul_x = v_default_vec_bbxul_x;
493
font_ek->vec_bbxul_y = v_default_vec_bbxul_y;
494
font_ek->vec_next_x = v_default_vec_next_x;
495
font_ek->vec_next_y = v_default_vec_next_y;
498
if (cap_vec_bbxul != NULL){
499
s1 = vf_sexp_car(cap_vec_bbxul);
500
s2 = vf_sexp_cadr(cap_vec_bbxul);
501
font_ek->vec_bbxul_x = atof(vf_sexp_get_cstring(s1));
502
font_ek->vec_bbxul_y = atof(vf_sexp_get_cstring(s2));
504
if (default_vec_next != NULL){
505
s1 = vf_sexp_car(default_vec_next);
506
s2 = vf_sexp_cadr(default_vec_next);
507
font_ek->vec_next_x = atof(vf_sexp_get_cstring(s1));
508
font_ek->vec_next_y = atof(vf_sexp_get_cstring(s2));
510
if (cap_props != NULL)
511
font_ek->props = cap_props;
514
if ((font_ek->font_file = vf_strdup(font_file)) == NULL){
515
vf_error = VF_ERR_NO_MEMORY;
518
if ((font_ek->font_name = vf_strdup(font_name)) == NULL){
519
vf_error = VF_ERR_NO_MEMORY;
524
printf("VFlib EK: cs=%s, enc=%s, font_cs=%s, font_enc=%s\n",
525
charset, encoding, font_charset, font_encoding);
528
font_ek->ccv_id = -1;
529
if ((charset != NULL) && (encoding != NULL)
530
&& (font_charset != NULL) && (font_encoding != NULL)){
532
= vf_ccv_require(charset, encoding, font_charset, font_encoding);
534
; /* need warning ? */
537
printf("VFlib EK: ccv id %d\n", font_ek->ccv_id);
539
font->private = font_ek;
543
ek_file_init(font_ek);
544
if (implicit == 0){ /* explicit font */
545
vf_sexp_free2(&cap_fontdirs, &cap_font_dot_size);
546
vf_sexp_free3(&cap_font, &cap_point, &cap_pixel);
547
vf_sexp_free3(&cap_dpi, &cap_dpi_x, &cap_dpi_y);
548
vf_sexp_free2(&cap_mag, &cap_aspect);
549
vf_sexp_free2(&cap_charset, &cap_encoding);
550
vf_sexp_free2(&cap_font_charset, &cap_font_encoding);
551
vf_sexp_free3(&cap_direction, &cap_vec_bbxul, &cap_vec_next);
552
vf_sexp_free1(&cap_mock_enc);
554
vf_sexp_free1(&cap_props);
557
if (font_ek != NULL){
558
vf_free(font_ek->font_path);
559
vf_free(font_ek->font_name);
560
vf_free(font_ek->font_file);
570
ek_close(VF_FONT font)
574
font_ek = (FONT_EK)font->private;
575
if (font_ek->props != NULL)
576
vf_sexp_free1(&font_ek->props);
577
vf_free(font_ek->font_path);
578
vf_free(font_ek->font_name);
579
vf_free(font_ek->font_file);
589
mag_mode_1(FONT_EK font_ek, VF_FONT font,
590
double mag_x, double mag_y,
591
double *ret_point_size,
592
double *ret_bbx_w, double *ret_bbx_h,
593
double *ret_mag_x, double *ret_mag_y,
594
double *ret_dpix, double *ret_dpiy)
596
double mx, my, dpix, dpiy, ps, asp;
598
if ((ps = font->point_size) < 0)
599
if ((ps = font_ek->point_size) < 0)
600
ps = v_default_point_size;
602
if (ret_point_size != NULL)
603
*ret_point_size = ps;
605
asp = (v_default_aspect * font_ek->aspect);
607
mx = mag_x * font_ek->mag * font->mag_x * asp;
608
my = mag_y * font_ek->mag * font->mag_y;
610
if (ret_mag_x != NULL)
612
if (ret_mag_y != NULL)
615
if ((font->dpi_x > 0) && (font->dpi_y > 0)){
618
} else if ((font_ek->dpi_x > 0) && (font_ek->dpi_y > 0)){
619
dpix = font_ek->dpi_x;
620
dpiy = font_ek->dpi_y;
622
dpix = v_default_dpi_x;
623
dpiy = v_default_dpi_y;
626
if (ret_dpix != NULL)
628
if (ret_dpiy != NULL)
631
if (ret_bbx_w != NULL)
632
*ret_bbx_w = dpix * mx * (ps / POINTS_PER_INCH);
633
if (ret_bbx_h != NULL)
634
*ret_bbx_h = dpiy * my * (ps / POINTS_PER_INCH);
637
printf("*** %.3f %.3f %.3f\n", mag_x, font_ek->mag, font->mag_x);
638
printf(" %.3f %.3f %.3f\n", mag_y, font_ek->mag, font->mag_y);
639
printf(" dpix=%.3f font_dpi_x=%.3f\n", dpix, font_dpi_x);
640
printf(" dpiy=%.3f font_dpi_y=%.3f\n", dpiy, font_dpi_y);
641
printf(" asp=%.3f\n", asp);
642
printf(" mx=%.3f, my=%.3f\n", mx, my);
643
if (ret_bbx_w != NULL)
644
printf(" W=%.3f H=%.3f\n", *ret_bbx_w, *ret_bbx_h);
651
ek_get_metric1(VF_FONT font, long code_point, VF_METRIC1 metric,
652
double mag_x, double mag_y)
655
double bbx_w, bbx_h, dpix, dpiy;
658
if ( ((font_ek = (FONT_EK)font->private) == NULL)
659
|| (metric == NULL)){
660
fprintf(stderr, "VFlib internal error: in ek_get_metric1()\n");
665
if (font_ek->ccv_id >= 0){
666
cp = vf_ccv_conv(font_ek->ccv_id, code_point);
668
printf("VFlib EK: CCV 0x%lx => 0x%lx\n", code_point, cp);
673
mag_mode_1(font_ek, font, mag_x, mag_y,
674
NULL, &bbx_w, &bbx_h, NULL, NULL, &dpix, &dpiy);
676
metric->bbx_width = bbx_w;
677
metric->bbx_height = bbx_h;
678
metric->off_x = bbx_w * font_ek->vec_bbxul_x;
679
metric->off_y = bbx_h * font_ek->vec_bbxul_y;
680
metric->mv_x = bbx_w * font_ek->vec_next_x;
681
metric->mv_y = bbx_h * font_ek->vec_next_y;
687
ek_get_fontbbx1(VF_FONT font, double mag_x, double mag_y,
688
double *w_p, double *h_p, double *xoff_p, double *yoff_p)
691
double bbx_w, bbx_h, dpix, dpiy;
693
if ((font_ek = (FONT_EK)font->private) == NULL){
694
fprintf(stderr, "VFlib internal error: in ek_get_fontbbx1()\n");
698
mag_mode_1(font_ek, font, mag_x, mag_y,
699
NULL, &bbx_w, &bbx_h, NULL, NULL, &dpix, &dpiy);
703
*xoff_p = bbx_w * font_ek->vec_bbxul_x;
704
*yoff_p = bbx_h * (1.0 - font_ek->vec_bbxul_y);
710
ek_get_bitmap1(VF_FONT font, long code_point,
711
double mag_x, double mag_y)
718
if ((font_ek = (FONT_EK)font->private) == NULL){
719
fprintf(stderr, "VFlib internal error: in ek_get_bitmap1()\n");
724
if (font_ek->ccv_id >= 0){
725
cp = vf_ccv_conv(font_ek->ccv_id, code_point);
727
printf("VFlib EK: CCV 0x%lx => 0x%lx\n", code_point, cp);
732
if ((bm0 = ek_file_read(font_ek, cp)) == NULL)
734
/* note: bm0 should not be released*/
736
mag_mode_1(font_ek, font, mag_x, mag_y,
737
NULL, &bbx_w, &bbx_h, NULL, NULL, NULL, NULL);
739
bm = VF_MakeScaledBitmap(bm0,
740
bbx_w/(double)font_ek->font_dot_size,
741
bbx_h/(double)font_ek->font_dot_size);
743
bm->off_x = toint(bm->bbx_width * font_ek->vec_bbxul_x);
744
bm->off_y = toint(bm->bbx_height * font_ek->vec_bbxul_y);
745
bm->mv_x = toint(bm->bbx_width * font_ek->vec_next_x);
746
bm->mv_y = toint(bm->bbx_height * font_ek->vec_next_y);
753
ek_get_outline1(VF_FONT font, long code_point,
754
double mag_x, double mag_y)
760
double ps, dpi_x, dpi_y, bbx_w, bbx_h;
762
if ((font_ek = (FONT_EK)font->private) == NULL){
763
fprintf(stderr, "VFlib internal error: in ek_get_metric1()\n");
768
if (font_ek->ccv_id >= 0){
769
cp = vf_ccv_conv(font_ek->ccv_id, code_point);
771
printf("VFlib EK: CCV 0x%lx => 0x%lx\n", code_point, cp);
776
if ((bm = ek_get_bitmap1(font, cp, mag_x, mag_y)) == NULL)
779
mag_mode_1(font_ek, font, mag_x, mag_y,
780
&ps, &bbx_w, &bbx_h, NULL, NULL, &dpi_x, &dpi_y);
782
ol = vf_bitmap_to_outline(bm, bbx_w, bbx_h, dpi_x, dpi_y, ps, 1, 1);
790
mag_mode_2(FONT_EK font_ek, VF_FONT font,
791
double mag_x, double mag_y,
792
double *ret_pixel_size,
793
double *ret_magx, double *ret_magy,
794
double *ret_bbx_w, double *ret_bbx_h)
799
if ((ps = font->pixel_size) < 0)
800
if ((ps = font_ek->pixel_size) < 0)
801
ps = v_default_pixel_size;
803
asp = (v_default_aspect * font_ek->aspect);
805
mx = mag_x * font_ek->mag * font->mag_x * asp;
806
my = mag_y * font_ek->mag * font->mag_y;
808
if (ret_pixel_size != NULL)
809
*ret_pixel_size = ps;
811
if (ret_magx != NULL)
813
if (ret_magy != NULL)
816
if (ret_bbx_w != NULL)
817
*ret_bbx_w = mx * ps;
818
if (ret_bbx_h != NULL)
819
*ret_bbx_h = my * ps;
824
ek_get_metric2(VF_FONT font, long code_point, VF_METRIC2 metric,
825
double mag_x, double mag_y)
831
if ( ((font_ek = (FONT_EK)font->private) == NULL)
832
|| (metric == NULL)){
833
fprintf(stderr, "VFlib internal error: in ek_get_metric2()\n");
838
if (font_ek->ccv_id >= 0){
839
cp = vf_ccv_conv(font_ek->ccv_id, code_point);
841
printf("VFlib EK: CCV 0x%lx => 0x%lx\n", code_point, cp);
846
mag_mode_2(font_ek, font, mag_x, mag_y, NULL, NULL, NULL, &bbx_w, &bbx_h);
848
metric->bbx_width = (int)ceil(bbx_w);
849
metric->bbx_height = (int)ceil(bbx_h);
850
metric->off_x = toint(bbx_w * font_ek->vec_bbxul_x);
851
metric->off_y = toint(bbx_h * font_ek->vec_bbxul_y);
852
metric->mv_x = toint(bbx_w * font_ek->vec_next_x);
853
metric->mv_y = toint(bbx_h * font_ek->vec_next_y);
860
ek_get_fontbbx2(VF_FONT font, double mag_x, double mag_y,
861
int *w_p, int *h_p, int *xoff_p, int *yoff_p)
866
if ((font_ek = (FONT_EK)font->private) == NULL){
867
fprintf(stderr, "VFlib internal error: in ek_get_fontbbx2()\n");
871
mag_mode_2(font_ek, font, mag_x, mag_y, NULL, NULL, NULL, &bbx_w, &bbx_h);
875
*xoff_p = toint(bbx_w * font_ek->vec_bbxul_x);
876
*yoff_p = toint(bbx_w * (font_ek->vec_bbxul_y - 1.0));
883
ek_get_bitmap2(VF_FONT font, long code_point,
884
double mag_x, double mag_y)
888
double bbx_w, bbx_h, mx, my;
891
if ((font_ek = (FONT_EK)font->private) == NULL){
892
fprintf(stderr, "VFlib internal error: in ek_get_bitmap2()\n");
897
if (font_ek->ccv_id >= 0){
898
cp = vf_ccv_conv(font_ek->ccv_id, code_point);
900
printf("VFlib EK: CCV 0x%lx => 0x%lx\n", code_point, cp);
905
if ((bm0 = ek_file_read(font_ek, cp)) == NULL)
907
/* note: bm0 should not be released*/
909
mag_mode_2(font_ek, font, mag_x, mag_y, NULL, &mx, &my, &bbx_w, &bbx_h);
911
bm = VF_MakeScaledBitmap(bm0,
912
bbx_w/(double)font_ek->font_dot_size,
913
bbx_h/(double)font_ek->font_dot_size);
915
bm->off_x = toint(bm->bbx_width * font_ek->vec_bbxul_x);
916
bm->off_y = toint(bm->bbx_height * font_ek->vec_bbxul_y);
917
bm->mv_x = toint(bm->bbx_width * font_ek->vec_next_x);
918
bm->mv_y = toint(bm->bbx_height * font_ek->vec_next_y);
925
ek_get_font_prop(VF_FONT font, char *prop_name)
926
/* CALLER MUST RELEASE RETURNED STRING */
930
double ps, dpix, dpiy;
933
if ((font_ek = (FONT_EK)font->private) == NULL){
934
fprintf(stderr, "VFlib: Internal error in ek_get_font_prop()\n");
938
if ((v = vf_sexp_assoc(prop_name, font_ek->props)) != NULL){
939
return vf_strdup(vf_sexp_get_cstring(vf_sexp_cadr(v)));
940
} else if ((v = vf_sexp_assoc(prop_name, default_properties)) != NULL){
941
return vf_strdup(vf_sexp_get_cstring(vf_sexp_cadr(v)));
944
if (font->mode == 1){
945
mag_mode_1(font_ek, font, 1.0, 1.0,
946
&ps, NULL, NULL, NULL, NULL, &dpix, &dpiy);
947
/**printf("** Mode1 %.3f %.3f %.3f\n", ps, dpix, dpiy);**/
948
if (strcmp(prop_name, "POINT_SIZE") == 0){
949
sprintf(str, "%d", toint(10.0 * ps));
950
return vf_strdup(str);
951
} else if (strcmp(prop_name, "PIXEL_SIZE") == 0){
952
sprintf(str, "%d", toint(ps * dpiy / POINTS_PER_INCH));
953
return vf_strdup(str);
954
} else if (strcmp(prop_name, "RESOLUTION_X") == 0){
955
sprintf(str, "%d", toint(dpix));
956
return vf_strdup(str);
957
} else if (strcmp(prop_name, "RESOLUTION_Y") == 0){
958
sprintf(str, "%d", toint(dpiy));
959
return vf_strdup(str);
961
} else if (font->mode == 2){
962
mag_mode_2(font_ek, font, 1.0, 1.0, &ps, NULL, NULL, NULL, NULL);
963
/**printf("** Mode2 %.3f\n", ps);**/
964
if (strcmp(prop_name, "POINT_SIZE") == 0){
965
sprintf(str, "%d", toint(10.0 * ps * POINTS_PER_INCH / DEFAULT_DPI));
966
return vf_strdup(str);
967
} else if (strcmp(prop_name, "PIXEL_SIZE") == 0){
968
sprintf(str, "%d", toint(ps));
969
return vf_strdup(str);
970
} else if (strcmp(prop_name, "RESOLUTION_X") == 0){
971
sprintf(str, "%d", toint(DEFAULT_DPI));
972
return vf_strdup(str);
973
} else if (strcmp(prop_name, "RESOLUTION_Y") == 0){
974
sprintf(str, "%d", toint(DEFAULT_DPI));
975
return vf_strdup(str);
986
ek_file_init(FONT_EK font_ek)
997
if (font_ek->font_dot_size <= 0)
1000
if ((fp = vf_fm_OpenBinaryFileStream(font_ek->font_path)) == NULL)
1003
fseek(fp, 0, SEEK_END);
1006
bw = (font_ek->font_dot_size + 7) / 8;
1007
font_ek->nchars = len / (font_ek->font_dot_size * bw);
1010
printf("Ekanji File: %s, size: %ld\n", font_ek->font_file, len);
1011
printf(" Dot size: %d, nchars: %ld\n",
1012
font_ek->font_dot_size, font_ek->nchars);
1018
ek_file_read(FONT_EK font_ek, long cp)
1019
/* CALLER SHOULD NOT RELEASE RETURNED OBJECT */
1024
static VF_BITMAP bmbuff = NULL;
1027
if (font_ek->font_dot_size <= 0)
1030
switch (font_ek->mock_encoding){
1031
case MOCK_FONT_ENC_RAW:
1033
case MOCK_FONT_ENC_SUBBLOCKS_94X94:
1036
if ((m0 < 0x21) || (0x7e < m0) || (m1 < 0x21) || (0x7e < m1)){
1041
cp = m0 * 94 + m1 + font_ek->mock_enc_arg * 94 * 94 + 1;
1044
case MOCK_FONT_ENC_SUBBLOCKS_94X60:
1047
if ((m0 < 0x30) || ((0x4d < m0)&&(m0 < 0x50)) || (0x6d < m0)
1048
|| (m1 < 0x21) || (0x7e < m1)){
1055
cp = m0 * 94 + m1 + font_ek->mock_enc_arg*94*60 + 1;
1058
case MOCK_FONT_ENC_WITH_OFFSET:
1060
printf("** 0x%lx, %ld 0x%lx, %ld %d, 0x%lx\n",
1061
cp, cp, cp + font_ek->mock_enc_arg,cp + font_ek->mock_enc_arg,
1062
font_ek->mock_enc_arg, font_ek->mock_enc_arg);
1064
cp = cp + font_ek->mock_enc_arg;
1067
fprintf(stderr, "VFlib internal error: Cannot happen. ek_file_read()\n");
1071
if ((cp < 0) || (font_ek->nchars <= 0) || (font_ek->nchars < cp)){
1072
vf_error = VF_ERR_ILL_CODE_POINT;
1076
if ((bmbuff == NULL) || (bw != font_ek->font_dot_size)){
1077
if (bmbuff != NULL){
1078
vf_free_bitmap(bmbuff);
1082
bw = (font_ek->font_dot_size + 7) / 8;
1083
if ((bmbuff = vf_alloc_bitmap(font_ek->font_dot_size,
1084
font_ek->font_dot_size)) == NULL){
1086
vf_error = VF_ERR_NO_MEMORY;
1091
if ((fp = vf_fm_OpenBinaryFileStream(font_ek->font_path)) == NULL)
1094
fseek(fp, font_ek->font_dot_size * bw * (cp-1), SEEK_SET);
1095
for (y = 0; y < font_ek->font_dot_size; y++){
1096
fread(&bmbuff->bitmap[y * bmbuff->raster], bw, sizeof(unsigned char), fp);
1111
if (env_debug_mode != NULL){
1112
if ((v = ek_debug2(type, env_debug_mode)) == TRUE)
1116
if (default_debug_mode == NULL)
1118
if ((p0 = vf_sexp_get_cstring(default_debug_mode)) == NULL)
1120
return ek_debug2(type, p0);
1124
ek_debug2(char type, char *p0)
1128
for (p = p0; *p != '\0'; p++){
1132
for (p = p0; *p != '\0'; p++){