src/drv_ekan.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. VF_Init_Driver_EKanji
  2. ek_create
  3. ek_close
  4. mag_mode_1
  5. ek_get_metric1
  6. ek_get_fontbbx1
  7. ek_get_bitmap1
  8. ek_get_outline1
  9. mag_mode_2
  10. ek_get_metric2
  11. ek_get_fontbbx2
  12. ek_get_bitmap2
  13. ek_get_font_prop
  14. ek_file_init
  15. ek_file_read
  16. ek_debug
  17. ek_debug2

   1 /*
   2  * drv_ekan.c -  A font driver for eKanji format fonts.
   3  * by Hirotsugu Kakugawa
   4  *
   5  *  8 Dec 1999  First implementation.
   6  * 18 Oct 2001  Fixed memory leak.
   7  */
   8 /*
   9  * Copyright (C) 1999-2001  Hirotsugu Kakugawa. 
  10  * All rights reserved.
  11  *
  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.
  23  */
  24 
  25 
  26 #include  "config.h"
  27 #include  <stdio.h>
  28 #include  <stdlib.h>
  29 #ifdef HAVE_UNISTD_H
  30 #  include <unistd.h>
  31 #endif
  32 #include  <ctype.h>
  33 #include  <math.h>
  34 #include  "VFlib-3_6.h"
  35 #include  "VFsys.h"
  36 #include  "vflibcap.h"
  37 #include  "ccv.h"
  38 #include  "sexp.h"
  39 #include  "str.h"
  40 #include  "path.h"
  41 #include  "fsearch.h"
  42 #include  "bitmap.h"
  43 #include  "ekan.h"
  44 
  45 struct s_font_ek {
  46   char    *font_path;
  47   char    *font_name;
  48   char    *font_file;
  49   int      font_dot_size;
  50   double   point_size;
  51   int      pixel_size;
  52   double   dpi_x, dpi_y;
  53   double   mag;
  54   double   aspect;
  55   int      ccv_id;
  56   int      direction;
  57   double    vec_bbxul_x, vec_bbxul_y;
  58   double    vec_next_x, vec_next_y;
  59   long     nchars;
  60   int      mock_encoding; 
  61   long     mock_enc_arg; 
  62   SEXP_ALIST  props;
  63 };
  64 typedef struct s_font_ek  *FONT_EK;
  65 
  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"
  88 
  89 
  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*);
 105 
 106 
 107 Private int    ek_debug(char);
 108 Private int    ek_debug2(char type, char *str);
 109 
 110 Private VF_BITMAP  ek_file_read(FONT_EK font_ek, long cp);
 111 Private void       ek_file_init(FONT_EK font_ek);
 112 
 113 
 114 
 115 
 116 Public int
 117 VF_Init_Driver_EKanji(void)
     /* [<][>][^][v][top][bottom][index][help] */
 118 {
 119   int   z;
 120   char *p;
 121   SEXP  s1, s2;
 122   struct s_capability_table  ct[30];
 123 
 124   z = 0;
 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;
 137   /* VF_CAPE_DPI */  
 138   ct[z].cap = VF_CAPE_DPI;               ct[z].type = CAPABILITY_STRING;
 139   ct[z].ess = CAPABILITY_OPTIONAL;       ct[z++].val = &default_dpi;
 140   /* VF_CAPE_DPI_X */
 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;
 143   /* VF_CAPE_DPI_Y */
 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;
 164   /* VF_CAPE_DEBUG */
 165   ct[z].cap = VF_CAPE_DEBUG;             ct[z].type = CAPABILITY_STRING;
 166   ct[z].ess = CAPABILITY_OPTIONAL;       ct[z++].val = &default_debug_mode;
 167   /* end */
 168   ct[z].cap = NULL; ct[z].type = 0; ct[z].ess = 0; ct[z++].val = NULL;
 169 
 170   if (vf_cap_GetParsedClassDefault(FONTCLASS_NAME, ct, NULL, NULL) 
 171       == VFLIBCAP_PARSED_ERROR)
 172     return -1;
 173 
 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));
 177 
 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;
 183 
 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;
 189 
 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));
 198 
 199   v_default_aspect = 1.0;
 200   if (default_aspect != NULL)
 201     v_default_aspect = atof(vf_sexp_get_cstring(default_aspect));
 202 
 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;
 210     } else {
 211       fprintf(stderr, "VFlib warning: Unknown writing direction: %s\n", p);
 212     }
 213   }
 214 
 215   switch(v_default_direction){
 216   default:
 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;
 222     break;
 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;
 228     break;
 229   }
 230 
 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));
 236   }
 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));
 242   }
 243 
 244   env_debug_mode = getenv(DEBUG_ENV_NAME);
 245 
 246   VF_InstallFontDriver(FONTCLASS_NAME, (DRIVER_FUNC_TYPE)ek_create);
 247 
 248   return 0;
 249 }
 250 
 251 
 252 Private int
 253 ek_create(VF_FONT font, char *font_class, 
     /* [<][>][^][v][top][bottom][index][help] */
 254           char *font_name, int implicit, SEXP entry)
 255 {
 256   FONT_EK  font_ek;
 257   FILE     *fp;
 258   int      val, len;
 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;
 264   SEXP     cap_mock_enc;
 265   SEXP     fontdirs, s1, s2;
 266   char    *charset, *encoding, *font_charset, *font_encoding;
 267   int      z;
 268   struct s_capability_table  ct[30];
 269 
 270   z = 0;
 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;
 301   /* VF_CAPE_DPI */
 302   ct[z].cap = VF_CAPE_DPI;              ct[z].type = CAPABILITY_STRING;
 303   ct[z].ess = CAPABILITY_OPTIONAL;      ct[z++].val = &cap_dpi;
 304   /* VF_CAPE_DPI_X */
 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;
 307   /* VF_CAPE_DPI_Y */
 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;
 310   /* VF_CAPE_MAG */
 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;
 331   /* end */
 332   ct[z].cap = NULL; ct[z].type = 0; ct[z].ess = 0; ct[z++].val  = NULL;
 333 
 334 
 335   val = -1;
 336   font_file = font_name;
 337   fontdirs = default_fontdirs;
 338   font_ek = NULL;
 339 
 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)
 346       return -1;
 347     if (cap_fontdirs != NULL)
 348       fontdirs = cap_fontdirs;
 349     if (cap_font != NULL){
 350       font_file = vf_sexp_get_cstring(cap_font);
 351     } else {
 352       /* Use font name as font file name if font file name is not given. */
 353       font_file = font_name;
 354     }
 355   }
 356 
 357   if (ek_debug('f'))
 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){
 362     if (ek_debug('f'))
 363       printf("eKanji font file not found\n");
 364     vf_error = VF_ERR_NO_FONT_FILE;
 365     goto End; 
 366   }
 367   if (ek_debug('f'))
 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;
 371     goto End; 
 372   }
 373 
 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;
 385 
 386   ALLOC_IF_ERR(font_ek, struct s_font_ek){
 387     vf_error = VF_ERR_NO_MEMORY;
 388     goto End; 
 389   }
 390 
 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;
 401   font_ek->mag           = 1.0;
 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;
 410 
 411   charset       = NULL;
 412   encoding      = NULL;
 413   font_charset  = NULL;
 414   font_encoding = NULL;
 415 
 416   if (implicit == 0){
 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);
 421       if (len > 0){
 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;
 431         } else {
 432           fprintf(stderr, 
 433                   "VFlib warning: unknown keyword `%s' in capability %s\n",
 434                   p, VF_CAPE_EK_MOCK_FONT_ENC);
 435         }
 436       }
 437       if (len > 1){
 438         p = vf_sexp_get_cstring(vf_sexp_cadr(cap_mock_enc));
 439         if (*p == '-'){ 
 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);
 444         } else {
 445           sscanf(p, "%li", &font_ek->mock_enc_arg);
 446         }
 447       }
 448     }
 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));
 453     if (cap_dpi != NULL)
 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));
 459     if (cap_mag != NULL)
 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;
 479       } else {
 480         fprintf(stderr, "VFlib warning: Unknown writing direction: %s\n", p);
 481       }
 482     }
 483     switch(font_ek->direction){
 484     default:
 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;
 490       break;
 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;
 496       break;
 497     }
 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));
 503     }
 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));
 509     }
 510     if (cap_props != NULL)
 511       font_ek->props = cap_props;
 512   }
 513 
 514   if ((font_ek->font_file = vf_strdup(font_file)) == NULL){
 515     vf_error = VF_ERR_NO_MEMORY;
 516     goto End;
 517   }
 518   if ((font_ek->font_name = vf_strdup(font_name)) == NULL){
 519     vf_error = VF_ERR_NO_MEMORY;
 520     goto End;
 521   }
 522 
 523   if (ek_debug('c')){
 524     printf("VFlib EK: cs=%s, enc=%s, font_cs=%s, font_enc=%s\n",
 525            charset, encoding, font_charset, font_encoding);
 526   }
 527 
 528   font_ek->ccv_id = -1;
 529   if ((charset != NULL) && (encoding != NULL)
 530       && (font_charset != NULL) && (font_encoding != NULL)){
 531     font_ek->ccv_id 
 532       = vf_ccv_require(charset, encoding, font_charset, font_encoding);
 533   } else {
 534     ;  /* need warning ? */
 535   }
 536   if (ek_debug('c')) 
 537     printf("VFlib EK: ccv id  %d\n", font_ek->ccv_id);
 538 
 539   font->private = font_ek;
 540   val = 0;
 541 
 542 End:
 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);
 553     if (val < 0)
 554       vf_sexp_free1(&cap_props);
 555   }
 556   if (val < 0){
 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); 
 561     }
 562     vf_free(font_ek); 
 563   }
 564 
 565   return val;
 566 }
 567 
 568 
 569 Private int
 570 ek_close(VF_FONT font)
     /* [<][>][^][v][top][bottom][index][help] */
 571 {
 572   FONT_EK  font_ek;
 573 
 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); 
 580   vf_free(font_ek); 
 581 
 582   return 0; 
 583 }
 584 
 585 
 586 
 587 
 588 Private void
 589 mag_mode_1(FONT_EK font_ek, VF_FONT font, 
     /* [<][>][^][v][top][bottom][index][help] */
 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)
 595 {
 596   double  mx, my, dpix, dpiy, ps, asp;
 597 
 598   if ((ps = font->point_size) < 0)
 599     if ((ps = font_ek->point_size) < 0)
 600       ps = v_default_point_size;
 601 
 602   if (ret_point_size != NULL)
 603     *ret_point_size = ps;
 604 
 605   asp = (v_default_aspect * font_ek->aspect);
 606 
 607   mx = mag_x * font_ek->mag * font->mag_x * asp;
 608   my = mag_y * font_ek->mag * font->mag_y;
 609 
 610   if (ret_mag_x != NULL)
 611     *ret_mag_x = mx;
 612   if (ret_mag_y != NULL)
 613     *ret_mag_y = my;
 614 
 615   if ((font->dpi_x > 0) && (font->dpi_y > 0)){
 616     dpix = font->dpi_x;
 617     dpiy = font->dpi_y;
 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;
 621   } else {
 622     dpix = v_default_dpi_x;
 623     dpiy = v_default_dpi_y;
 624   }
 625 
 626   if (ret_dpix != NULL)
 627     *ret_dpix = dpix;
 628   if (ret_dpiy != NULL)
 629     *ret_dpiy = dpiy;
 630 
 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);
 635 
 636 #if 0
 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);
 645 #endif
 646 
 647 }
 648 
 649 
 650 Private int
 651 ek_get_metric1(VF_FONT font, long code_point, VF_METRIC1 metric, 
     /* [<][>][^][v][top][bottom][index][help] */
 652                double mag_x, double mag_y)
 653 {
 654   FONT_EK    font_ek;
 655   double     bbx_w, bbx_h, dpix, dpiy;
 656   long       cp;
 657 
 658   if (   ((font_ek = (FONT_EK)font->private) == NULL)
 659       || (metric == NULL)){
 660     fprintf(stderr, "VFlib internal error: in ek_get_metric1()\n");
 661     abort();
 662   }
 663 
 664   cp = code_point;
 665   if (font_ek->ccv_id >= 0){
 666     cp = vf_ccv_conv(font_ek->ccv_id, code_point);
 667     if (ek_debug('C')) 
 668       printf("VFlib EK: CCV  0x%lx => 0x%lx\n", code_point, cp);
 669   }
 670   if (cp < 0)
 671     return -1;
 672 
 673   mag_mode_1(font_ek, font, mag_x, mag_y, 
 674              NULL, &bbx_w, &bbx_h, NULL, NULL, &dpix, &dpiy);
 675 
 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;
 682 
 683   return 0;
 684 }
 685 
 686 Private int
 687 ek_get_fontbbx1(VF_FONT font, double mag_x, double mag_y,
     /* [<][>][^][v][top][bottom][index][help] */
 688                   double *w_p, double *h_p, double *xoff_p, double *yoff_p)
 689 {
 690   FONT_EK    font_ek;
 691   double     bbx_w, bbx_h, dpix, dpiy;
 692 
 693   if ((font_ek = (FONT_EK)font->private) == NULL){
 694     fprintf(stderr, "VFlib internal error: in ek_get_fontbbx1()\n");
 695     abort();
 696   }
 697 
 698   mag_mode_1(font_ek, font, mag_x, mag_y, 
 699              NULL, &bbx_w, &bbx_h, NULL, NULL, &dpix, &dpiy);
 700 
 701   *w_p = bbx_w;
 702   *h_p = bbx_h;
 703   *xoff_p = bbx_w * font_ek->vec_bbxul_x;
 704   *yoff_p = bbx_h * (1.0 - font_ek->vec_bbxul_y);
 705 
 706   return 0;
 707 }
 708 
 709 Private VF_BITMAP
 710 ek_get_bitmap1(VF_FONT font, long code_point,
     /* [<][>][^][v][top][bottom][index][help] */
 711                double mag_x, double mag_y)
 712 {
 713   FONT_EK      font_ek;
 714   VF_BITMAP    bm0, bm;
 715   double       bbx_w, bbx_h;
 716   long         cp;
 717 
 718   if ((font_ek = (FONT_EK)font->private) == NULL){
 719     fprintf(stderr, "VFlib internal error: in ek_get_bitmap1()\n");
 720     abort();
 721   }
 722 
 723   cp = code_point;
 724   if (font_ek->ccv_id >= 0){
 725     cp = vf_ccv_conv(font_ek->ccv_id, code_point);
 726     if (ek_debug('C')) 
 727       printf("VFlib EK: CCV  0x%lx => 0x%lx\n", code_point, cp);
 728   }
 729   if (cp < 0)
 730     return NULL;
 731 
 732   if ((bm0 = ek_file_read(font_ek, cp)) == NULL)
 733     return NULL;
 734   /* note: bm0 should not be released*/
 735 
 736   mag_mode_1(font_ek, font, mag_x, mag_y, 
 737              NULL, &bbx_w, &bbx_h, NULL, NULL, NULL, NULL);
 738 
 739   bm = VF_MakeScaledBitmap(bm0, 
 740                            bbx_w/(double)font_ek->font_dot_size, 
 741                            bbx_h/(double)font_ek->font_dot_size);
 742 
 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);
 747   
 748   return  bm;
 749 }
 750 
 751 
 752 Private VF_OUTLINE
 753 ek_get_outline1(VF_FONT font, long code_point,
     /* [<][>][^][v][top][bottom][index][help] */
 754                   double mag_x, double mag_y)
 755 {
 756   FONT_EK       font_ek;
 757   long          cp;
 758   VF_BITMAP     bm;
 759   VF_OUTLINE    ol;
 760   double        ps, dpi_x, dpi_y, bbx_w, bbx_h;
 761 
 762   if ((font_ek = (FONT_EK)font->private) == NULL){
 763     fprintf(stderr, "VFlib internal error: in ek_get_metric1()\n");
 764     abort();
 765   }
 766 
 767   cp = code_point;
 768   if (font_ek->ccv_id >= 0){
 769     cp = vf_ccv_conv(font_ek->ccv_id, code_point);
 770     if (ek_debug('C')) 
 771       printf("VFlib EK: CCV  0x%lx => 0x%lx\n", code_point, cp);
 772   }
 773   if (cp < 0)
 774     return NULL;
 775 
 776   if ((bm = ek_get_bitmap1(font, cp, mag_x, mag_y)) == NULL)
 777     return NULL;
 778 
 779   mag_mode_1(font_ek, font, mag_x, mag_y, 
 780              &ps, &bbx_w, &bbx_h, NULL, NULL, &dpi_x, &dpi_y);
 781   
 782   ol = vf_bitmap_to_outline(bm, bbx_w, bbx_h, dpi_x, dpi_y, ps, 1, 1);
 783   VF_FreeBitmap(bm);
 784 
 785   return ol;
 786 }
 787 
 788 
 789 Private void
 790 mag_mode_2(FONT_EK font_ek, VF_FONT font, 
     /* [<][>][^][v][top][bottom][index][help] */
 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)
 795 {
 796   int     ps;
 797   double  mx, my, asp;
 798 
 799   if ((ps = font->pixel_size) < 0)
 800     if ((ps = font_ek->pixel_size) < 0)
 801       ps = v_default_pixel_size;
 802 
 803   asp = (v_default_aspect * font_ek->aspect);
 804 
 805   mx = mag_x * font_ek->mag * font->mag_x * asp;
 806   my = mag_y * font_ek->mag * font->mag_y;
 807 
 808   if (ret_pixel_size != NULL)
 809     *ret_pixel_size = ps;
 810 
 811   if (ret_magx != NULL)
 812     *ret_magx = mx;
 813   if (ret_magy != NULL)
 814     *ret_magy = my;
 815 
 816   if (ret_bbx_w != NULL)
 817     *ret_bbx_w = mx * ps;
 818   if (ret_bbx_h != NULL)
 819     *ret_bbx_h = my * ps;
 820 }
 821 
 822 
 823 Private int
 824 ek_get_metric2(VF_FONT font, long code_point, VF_METRIC2 metric, 
     /* [<][>][^][v][top][bottom][index][help] */
 825                  double mag_x, double mag_y)
 826 {
 827   FONT_EK    font_ek;
 828   double     bbx_w, bbx_h;
 829   long       cp;
 830 
 831   if (   ((font_ek = (FONT_EK)font->private) == NULL)
 832       || (metric == NULL)){
 833     fprintf(stderr, "VFlib internal error: in ek_get_metric2()\n");
 834     abort();
 835   }
 836 
 837   cp = code_point;
 838   if (font_ek->ccv_id >= 0){
 839     cp = vf_ccv_conv(font_ek->ccv_id, code_point);
 840     if (ek_debug('C')) 
 841       printf("VFlib EK: CCV  0x%lx => 0x%lx\n", code_point, cp);
 842   }
 843   if (cp < 0)
 844     return 0;
 845 
 846   mag_mode_2(font_ek, font, mag_x, mag_y, NULL, NULL, NULL, &bbx_w, &bbx_h);
 847 
 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);
 854 
 855   return 0;
 856 }
 857 
 858 
 859 Private int
 860 ek_get_fontbbx2(VF_FONT font, double mag_x, double mag_y,
     /* [<][>][^][v][top][bottom][index][help] */
 861                   int *w_p, int *h_p, int *xoff_p, int *yoff_p)
 862 {
 863   FONT_EK    font_ek;
 864   double     bbx_w, bbx_h;
 865 
 866   if ((font_ek = (FONT_EK)font->private) == NULL){
 867     fprintf(stderr, "VFlib internal error: in ek_get_fontbbx2()\n");
 868     abort();
 869   }
 870 
 871   mag_mode_2(font_ek, font, mag_x, mag_y, NULL, NULL, NULL, &bbx_w, &bbx_h);
 872 
 873   *w_p  = toint(bbx_w);
 874   *h_p  = toint(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));
 877 
 878   return 0;
 879 }
 880 
 881 
 882 Private VF_BITMAP
 883 ek_get_bitmap2(VF_FONT font, long code_point, 
     /* [<][>][^][v][top][bottom][index][help] */
 884                  double mag_x, double mag_y)
 885 {
 886   FONT_EK     font_ek;
 887   VF_BITMAP   bm0, bm;
 888   double      bbx_w, bbx_h, mx, my;
 889   long        cp;
 890 
 891   if ((font_ek = (FONT_EK)font->private) == NULL){
 892     fprintf(stderr, "VFlib internal error: in ek_get_bitmap2()\n");
 893     abort();
 894   }
 895 
 896   cp = code_point;
 897   if (font_ek->ccv_id >= 0){
 898     cp = vf_ccv_conv(font_ek->ccv_id, code_point);
 899     if (ek_debug('C')) 
 900       printf("VFlib EK: CCV  0x%lx => 0x%lx\n", code_point, cp);
 901   }
 902   if (cp < 0)
 903     return NULL;
 904 
 905   if ((bm0 = ek_file_read(font_ek, cp)) == NULL)
 906     return NULL;
 907   /* note: bm0 should not be released*/
 908 
 909   mag_mode_2(font_ek, font, mag_x, mag_y, NULL, &mx, &my, &bbx_w, &bbx_h);
 910 
 911   bm = VF_MakeScaledBitmap(bm0, 
 912                            bbx_w/(double)font_ek->font_dot_size, 
 913                            bbx_h/(double)font_ek->font_dot_size);
 914 
 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);
 919 
 920   return bm;
 921 }
 922 
 923 
 924 Private char*
 925 ek_get_font_prop(VF_FONT font, char *prop_name)
     /* [<][>][^][v][top][bottom][index][help] */
 926      /* CALLER MUST RELEASE RETURNED STRING */
 927 {
 928   FONT_EK   font_ek;
 929   char        str[512];
 930   double      ps, dpix, dpiy;
 931   SEXP        v;
 932 
 933   if ((font_ek = (FONT_EK)font->private) == NULL){
 934     fprintf(stderr, "VFlib: Internal error in ek_get_font_prop()\n");
 935     abort();
 936   }
 937   
 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)));
 942   }
 943 
 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);
 960     } 
 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);
 976     } 
 977   }
 978 
 979   return NULL; 
 980 }
 981 
 982 
 983 
 984 
 985 Private void
 986 ek_file_init(FONT_EK font_ek)
     /* [<][>][^][v][top][bottom][index][help] */
 987 {
 988   FILE  *fp; 
 989   long   len;
 990   int    bw;
 991 
 992   if (font_ek == NULL)
 993     return;
 994 
 995   font_ek->nchars = 0;  
 996 
 997   if (font_ek->font_dot_size <= 0)
 998     return;
 999 
1000   if ((fp = vf_fm_OpenBinaryFileStream(font_ek->font_path)) == NULL)
1001     return;
1002   
1003   fseek(fp, 0, SEEK_END);
1004   len = ftell(fp);
1005 
1006   bw = (font_ek->font_dot_size + 7) / 8;
1007   font_ek->nchars = len / (font_ek->font_dot_size * bw);
1008 
1009   if (ek_debug('f')){
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);
1013   }
1014 }
1015 
1016 
1017 Private VF_BITMAP
1018 ek_file_read(FONT_EK font_ek, long cp)
     /* [<][>][^][v][top][bottom][index][help] */
1019      /* CALLER SHOULD NOT RELEASE RETURNED OBJECT */
1020 {
1021   int                 y;
1022   long                m0, m1;
1023   FILE               *fp;
1024   static VF_BITMAP    bmbuff = NULL;
1025   static int          bw = -1;
1026 
1027   if (font_ek->font_dot_size <= 0)
1028     return NULL;
1029 
1030   switch (font_ek->mock_encoding){
1031   case MOCK_FONT_ENC_RAW:
1032     break;
1033   case MOCK_FONT_ENC_SUBBLOCKS_94X94:
1034     m0 = cp / 0x100;
1035     m1 = cp % 0x100;
1036     if ((m0 < 0x21) || (0x7e < m0) || (m1 < 0x21) || (0x7e < m1)){
1037       cp = -1;
1038     } else {
1039       m0 -= 0x21;
1040       m1 -= 0x21;
1041       cp = m0 * 94 + m1 + font_ek->mock_enc_arg * 94 * 94 + 1;
1042     }
1043     break;
1044   case MOCK_FONT_ENC_SUBBLOCKS_94X60:
1045     m0 = cp / 0x100;
1046     m1 = cp % 0x100;
1047     if ((m0 < 0x30) || ((0x4d < m0)&&(m0 < 0x50)) || (0x6d < m0) 
1048         || (m1 < 0x21) || (0x7e < m1)){
1049       cp = -1;
1050     } else {
1051       if (m0 >= 0x50)
1052         m0 -= 2;
1053       m0 -= 0x30;
1054       m1 -= 0x21;
1055       cp = m0 * 94 + m1 + font_ek->mock_enc_arg*94*60 + 1;
1056     }
1057     break;
1058   case MOCK_FONT_ENC_WITH_OFFSET:
1059 #if 0
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);
1063 #endif
1064     cp = cp + font_ek->mock_enc_arg;
1065     break;
1066   default:
1067     fprintf(stderr, "VFlib internal error: Cannot happen. ek_file_read()\n");
1068     abort();
1069   }
1070 
1071   if ((cp < 0) || (font_ek->nchars <= 0) || (font_ek->nchars < cp)){
1072     vf_error = VF_ERR_ILL_CODE_POINT;
1073     return NULL;
1074   }
1075 
1076   if ((bmbuff == NULL) || (bw != font_ek->font_dot_size)){
1077     if (bmbuff != NULL){
1078       vf_free_bitmap(bmbuff);
1079       bmbuff = NULL;
1080       bw = -1;
1081     }
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){
1085       bw = -1;
1086       vf_error = VF_ERR_NO_MEMORY;
1087       return NULL;
1088     }
1089   }
1090   
1091   if ((fp = vf_fm_OpenBinaryFileStream(font_ek->font_path)) == NULL)
1092     return NULL;
1093 
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);
1097   }
1098 
1099   return  bmbuff;
1100 }
1101 
1102 
1103 
1104 Private int
1105 ek_debug(char type)
     /* [<][>][^][v][top][bottom][index][help] */
1106 {
1107   int   v;
1108   char  *p0;
1109 
1110   v = FALSE;
1111   if (env_debug_mode != NULL){
1112     if ((v = ek_debug2(type, env_debug_mode)) == TRUE)
1113       return TRUE;
1114   }
1115 
1116   if (default_debug_mode == NULL)
1117     return FALSE;
1118   if ((p0 = vf_sexp_get_cstring(default_debug_mode)) == NULL)
1119     return FALSE;
1120   return ek_debug2(type, p0);
1121 }
1122 
1123 Private int
1124 ek_debug2(char type, char *p0)
     /* [<][>][^][v][top][bottom][index][help] */
1125 {
1126   char  *p;
1127 
1128   for (p = p0; *p != '\0'; p++){
1129     if (*p == type)
1130       return TRUE;
1131   }
1132   for (p = p0; *p != '\0'; p++){
1133     if (*p == '*')
1134       return TRUE;
1135   }
1136   return FALSE;
1137 }
1138 
1139 
1140 /*EOF*/

/* [<][>][^][v][top][bottom][index][help] */