src/drv_mojikmap.c

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

FUNCTIONS

This source file includes following functions.
  1. VF_Init_Driver_Mojikmap
  2. mojikmap_create
  3. mojikmap_close
  4. release_mem
  5. mojikmap_get_metric1
  6. mojikmap_get_fontbbx1
  7. mojikmap_get_bitmap1
  8. mojikmap_get_outline
  9. mojikmap_get_metric2
  10. mojikmap_get_fontbbx2
  11. mojikmap_get_bitmap2
  12. mojikmap_get_font_prop
  13. mojikmap_query_font_type
  14. font_mapping
  15. mojik_delayed_open
  16. debug_on

   1 /*
   2  * drv_mojikmap.c - A font driver for mapping to mojikyo fonts.
   3  *   This font driver provides a single virtual mojikyo font which is
   4  *   internally mapped to real font files.
   5  *
   6  * by Hirotsugu Kakugawa
   7  *
   8  *  8 Dec 1999  First implementation.
   9  *
  10  */
  11 /*
  12  * Copyright (C) 1999  Hirotsugu Kakugawa. 
  13  * All rights reserved.
  14  *
  15  * This file is part of the VFlib Library.  This library is free
  16  * software; you can redistribute it and/or modify it under the terms of
  17  * the GNU Library General Public License as published by the Free
  18  * Software Foundation; either version 2 of the License, or (at your
  19  * option) any later version.  This library is distributed in the hope
  20  * that it will be useful, but WITHOUT ANY WARRANTY; without even the
  21  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  22  * PURPOSE.  See the GNU Library General Public License for more details.
  23  * You should have received a copy of the GNU Library General Public
  24  * License along with this library; if not, write to the Free Software
  25  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  26  */
  27 
  28 #include  "config.h"
  29 #include  <stdio.h>
  30 #include  <stdlib.h>
  31 #ifdef HAVE_UNISTD_H
  32 #  include <unistd.h>
  33 #endif
  34 #include  <ctype.h>
  35 #include  "VFlib-3_6.h"
  36 #include  "VFsys.h"
  37 #include  "vflibcap.h"
  38 #include  "cache.h"
  39 #include  "sexp.h"
  40 #include  "str.h"
  41 #include  "path.h"
  42 #include  "ccv.h"
  43 #include  "mojikmap.h"
  44 
  45 
  46 #define  DELAYED_OPEN  
  47 
  48 #define SUBFONT_NOT_OPENED_YET  -2
  49 #define SUBFONT_NOT_EXIST       -1
  50 
  51 #define CCV_NOT_TRIED  -2
  52 #define CCV_NOT_EXIST  -1
  53 
  54 
  55 
  56 struct s_font_mojikmap {
  57   char     *font_name;
  58   int       div_scheme;
  59   char     *subfont_name;
  60   int       nsubfonts;
  61   int      *subfont_fids;
  62   int       ttf_subfont_enc;     /* when div_scheme is TTF */
  63   int       ttf_subfont_ccv_id;  /* when div_scheme is TTF */
  64   SEXP      props;
  65 };
  66 typedef struct s_font_mojikmap  *FONT_MOJIKMAP;
  67 
  68 
  69 Private SEXP_ALIST   default_properties = NULL;
  70 Private SEXP_ALIST   default_variables  = NULL;
  71 Private SEXP_STRING  default_debug_mode = NULL;
  72 
  73 
  74 Private int         mojikmap_create(VF_FONT,char*,char*,int,SEXP);
  75 Private int         mojikmap_close(VF_FONT);
  76 Private int         mojikmap_get_metric1(VF_FONT,long,VF_METRIC1,
  77                                       double,double);
  78 Private int         mojikmap_get_metric2(VF_FONT,long,VF_METRIC2,
  79                                       double,double);
  80 Private int         mojikmap_get_fontbbx1(VF_FONT,double,double,
  81                                        double*,double*,double*,double*);
  82 Private int         mojikmap_get_fontbbx2(VF_FONT,double,double, 
  83                                        int*,int*,int*,int*);
  84 Private VF_BITMAP   mojikmap_get_bitmap1(VF_FONT,long,double,double);
  85 Private VF_BITMAP   mojikmap_get_bitmap2(VF_FONT,long,double,double);
  86 Private VF_OUTLINE  mojikmap_get_outline(VF_FONT,long,double,double);
  87 Private char*       mojikmap_get_font_prop(VF_FONT,char*);
  88 Private int         mojikmap_query_font_type(VF_FONT,long);
  89 Private void        release_mem(FONT_MOJIKMAP);
  90 Private int         font_mapping(VF_FONT,FONT_MOJIKMAP,long,long*);
  91 Private int         mojik_delayed_open(VF_FONT,FONT_MOJIKMAP,int);
  92 Private int         debug_on(char type);
  93 
  94 
  95 Public int
  96 VF_Init_Driver_Mojikmap(void)
     /* [<][>][^][v][top][bottom][index][help] */
  97 {
  98   struct s_capability_table  ct[10];
  99   int  z;
 100 
 101   z = 0;
 102   /* VF_CAPE_PROPERTIES */
 103   ct[z].cap = VF_CAPE_PROPERTIES;      ct[z].type = CAPABILITY_ALIST;
 104   ct[z].ess = CAPABILITY_OPTIONAL;     ct[z++].val = &default_properties;
 105   /* VF_CAPE_VARIABLE_VALUES */
 106   ct[z].cap = VF_CAPE_VARIABLE_VALUES; ct[z].type = CAPABILITY_ALIST;
 107   ct[z].ess = CAPABILITY_OPTIONAL;     ct[z++].val = &default_variables;
 108   /* VF_CAPE_DEBUG */
 109   ct[z].cap = VF_CAPE_DEBUG;           ct[z].type = CAPABILITY_STRING;
 110   ct[z].ess = CAPABILITY_OPTIONAL;     ct[z++].val = &default_debug_mode;
 111   /* end */
 112   ct[z].cap = NULL; ct[z].type = 0; ct[z].ess = 0; ct[z++].val = NULL;
 113 
 114   if (vf_cap_GetParsedClassDefault(FONTCLASS_NAME_MOJIKMAP, ct, NULL, NULL) 
 115       == VFLIBCAP_PARSED_ERROR)
 116     return -1;
 117 
 118   VF_InstallFontDriver(FONTCLASS_NAME_MOJIKMAP, 
 119                        (DRIVER_FUNC_TYPE)mojikmap_create);
 120 
 121   return 0;
 122 }
 123 
 124 
 125 Private int
 126 mojikmap_create(VF_FONT font, char *font_class,
     /* [<][>][^][v][top][bottom][index][help] */
 127              char *font_name, int implicit, SEXP entry)
 128 {
 129   FONT_MOJIKMAP  font_mojikmap;
 130   SEXP        cap_div_scheme, cap_subfont_name, cap_ttf_subfont_enc, cap_props;
 131   char       *s1;
 132   int         i;
 133   struct s_capability_table  ct[20];
 134   int  z;
 135 
 136   z = 0;
 137   /* VF_CAPE_FONT_CLASS */
 138   ct[z].cap = VF_CAPE_FONT_CLASS;          ct[z].type = CAPABILITY_STRING;
 139   ct[z].ess = CAPABILITY_ESSENTIAL;        ct[z++].val = NULL;
 140   /* VF_CAPE_DIV_SCHEME */
 141   ct[z].cap = VF_CAPE_DIV_SCHEME;          ct[z].type = CAPABILITY_STRING;
 142   ct[z].ess = CAPABILITY_OPTIONAL;         ct[z++].val = &cap_div_scheme;
 143   /* VF_CAPE_SUB_FONT_NAME */
 144   ct[z].cap = VF_CAPE_SUBFONT_NAME;        ct[z].type = CAPABILITY_STRING;
 145   ct[z].ess = CAPABILITY_OPTIONAL;         ct[z++].val = &cap_subfont_name;
 146   /* VF_CAPE_TTF_SUBFONT_ENC */
 147   ct[z].cap = VF_CAPE_TTF_SUBFONT_ENC;     ct[z].type = CAPABILITY_STRING;
 148   ct[z].ess = CAPABILITY_OPTIONAL;         ct[z++].val = &cap_ttf_subfont_enc;
 149   /* VF_CAPE_PROPERTIES */
 150   ct[z].cap = VF_CAPE_PROPERTIES;          ct[z].type = CAPABILITY_ALIST;
 151   ct[z].ess = CAPABILITY_OPTIONAL;         ct[z++].val = &cap_props;
 152   /* end */
 153   ct[z].cap = NULL; ct[z].type = 0; ct[z].ess = 0; ct[z++].val = NULL;
 154 
 155 
 156   /* No support for implicit fonts */
 157   if (implicit == 1)  
 158     return -1;
 159 
 160   /* Only supports explicit fonts */
 161   if (vf_cap_GetParsedFontEntry(entry, font_name, ct, default_variables, NULL) 
 162       == VFLIBCAP_PARSED_ERROR)
 163     return -1;
 164 
 165   font->font_type       = -1;  /* Use mojikmap_query_font_type() */
 166   font->get_metric1     = mojikmap_get_metric1;
 167   font->get_metric2     = mojikmap_get_metric2;
 168   font->get_fontbbx1    = mojikmap_get_fontbbx1;
 169   font->get_fontbbx2    = mojikmap_get_fontbbx2;
 170   font->get_bitmap1     = mojikmap_get_bitmap1;
 171   font->get_bitmap2     = mojikmap_get_bitmap2;
 172   font->get_outline     = mojikmap_get_outline;
 173   font->get_font_prop   = mojikmap_get_font_prop;
 174   font->query_font_type = mojikmap_query_font_type;
 175   font->close           = mojikmap_close;
 176 
 177   ALLOC_IF_ERR(font_mojikmap, struct s_font_mojikmap){
 178     vf_error = VF_ERR_NO_MEMORY;
 179     return -1;
 180   }
 181   if ((font_mojikmap->font_name = vf_strdup(font_name)) == NULL){
 182     vf_error = VF_ERR_NO_MEMORY;
 183     vf_free(font_mojikmap);
 184     return -1;
 185   }
 186 
 187   font_mojikmap->font_name    = NULL;
 188   font_mojikmap->div_scheme   = DIVISION_SCHEME_TTF;
 189   font_mojikmap->subfont_name = NULL;
 190   font_mojikmap->subfont_fids = NULL;
 191   font_mojikmap->ttf_subfont_ccv_id = CCV_NOT_TRIED;
 192   font_mojikmap->ttf_subfont_enc    = -1;
 193   font_mojikmap->props        = default_properties;
 194 
 195   /* implicit == 0 */
 196 
 197   if (cap_props != NULL){
 198     font_mojikmap->props = cap_props;
 199   }
 200 
 201   if (cap_div_scheme != NULL){
 202     s1 = vf_sexp_get_cstring(cap_div_scheme);
 203     if ((vf_strcmp_ci(s1, "ttf") == 0)
 204         || (vf_strcmp_ci(s1, "truetype") == 0)){
 205       font_mojikmap->div_scheme = DIVISION_SCHEME_TTF;
 206     } else if ((vf_strcmp_ci(s1, "type1") == 0) 
 207                || (vf_strcmp_ci(s1, "pfb") == 0)){
 208       font_mojikmap->div_scheme = DIVISION_SCHEME_TYPE1;      
 209     } else {
 210       fprintf(stderr, 
 211               "VFlib warning: unknown division scheme name for "
 212               "capability '%s' in definition of font %s.\n",
 213               VF_CAPE_DIV_SCHEME, font_name);
 214       font_mojikmap->div_scheme = DIVISION_SCHEME_TTF;
 215     }
 216   }
 217 
 218   if (cap_subfont_name != NULL){
 219     font_mojikmap->subfont_name
 220       = vf_strdup(vf_sexp_get_cstring(cap_subfont_name));
 221   } else {
 222     if (font_mojikmap->div_scheme == DIVISION_SCHEME_TTF){
 223       font_mojikmap->subfont_name = vf_strdup(DEFAULT_SUBFONT_NAME_TTF);
 224     } else {
 225       font_mojikmap->subfont_name = vf_strdup(DEFAULT_SUBFONT_NAME_TYPE1);
 226     }
 227   }
 228 
 229   switch (font_mojikmap->div_scheme){
 230   case DIVISION_SCHEME_TTF:
 231     font_mojikmap->nsubfonts = 21;
 232     font_mojikmap->ttf_subfont_enc = DEFAULT_TTF_SUBFONT_ENC;
 233     if (cap_ttf_subfont_enc != NULL){
 234       s1 = vf_sexp_get_cstring(cap_ttf_subfont_enc); 
 235       if (vf_strcmp_ci(s1, "unicode") == 0){
 236         font_mojikmap->ttf_subfont_enc = TTF_SUBFONT_ENC_UNICODE;
 237       } else if ((vf_strcmp_ci(s1, "ISO2022") == 0)
 238                  || (vf_strcmp_ci(s1, "ISO-2022") == 0)
 239                  || (vf_strcmp_ci(s1, "JIS") == 0)){
 240         font_mojikmap->ttf_subfont_enc = TTF_SUBFONT_ENC_JIS;
 241       }
 242     }
 243     break;
 244   case DIVISION_SCHEME_TYPE1:
 245     font_mojikmap->nsubfonts = 21*TYPE1_NSUBS;
 246     font_mojikmap->ttf_subfont_enc = -1;
 247     break;
 248   }
 249 
 250   ALLOCN_IF_ERR(font_mojikmap->subfont_fids, int, font_mojikmap->nsubfonts){
 251     vf_error = VF_ERR_NO_MEMORY;
 252     goto CANT_OPEN;
 253   }
 254   for (i = 0; i < font_mojikmap->nsubfonts; i++)
 255     font_mojikmap->subfont_fids[i] = SUBFONT_NOT_OPENED_YET;
 256 
 257 #ifndef DELAYED_OPEN
 258   switch (font_mojikmap->div_scheme){
 259   case DIVISION_SCHEME_TTF:
 260     for (i = 0; i < font_mojikmap->nsubfonts; i++){
 261       sprintf(subfont_name, font_mojikmap->subfont_name, i+101);
 262       if (font->mode == 1){
 263         font_mojikmap->subfont_fids[i]
 264           = VF_OpenFont1(subfont_name, font->dpi_x, font->dpi_y, 
 265                          font->point_size, font->mag_x, font->mag_y);
 266       } else if (font->mode == 2){
 267         font_mojikmap->subfont_fids[i]
 268           = VF_OpenFont2(subfont_name, 
 269                          font->pixel_size, font->mag_x, font->mag_y);
 270       } else {
 271         fprintf(stderr, "VFlib: Internal error in mojikmap_create()\n");
 272         abort();
 273       }
 274       if (font_mojikmap->subfont_fids[i] < 0){
 275         font_mojikmap->subfont_fids[i] = SUBFONT_NOT_EXIST;
 276       }
 277       if (debug_on('f'))
 278         printf("VFlib mojikmap: subfont  name=%s fid=%d\n",
 279                subfont_name, font_mojikmap->subfont_fids[i]);
 280     }
 281     break;
 282   case DIVISION_SCHEME_TYPE1:
 283     for (i = 0; i < font_mojikmap->nsubfonts; i++){
 284       for (j = 0; j < TYPE1_NSUBS; j++){
 285         sprintf(subfont_name, font_mojikmap->subfont_name, i+101, j+6);
 286         if (font->mode == 1){
 287           font_mojikmap->subfont_fids[i*TYPE1_NSUBS + j]
 288             = VF_OpenFont1(subfont_name, font->dpi_x, font->dpi_y, 
 289                            font->point_size, font->mag_x, font->mag_y);
 290         } else if (font->mode == 2){
 291           font_mojikmap->subfont_fids[i*TYPE1_NSUBS + j]
 292             = VF_OpenFont2(subfont_name, 
 293                            font->pixel_size, font->mag_x, font->mag_y);
 294         } else {
 295           fprintf(stderr, "VFlib: Internal error in mojikmap_create()\n");
 296           abort();
 297         }
 298         if (font_mojikmap->subfont_fids[i*TYPE1_NSUBS + j] < 0){
 299           font_mojikmap->subfont_fids[i*TYPE1_NSUBS + j] = SUBFONT_NOT_EXIST;
 300         }
 301         if (debug_on('f'))
 302           printf("VFlib mojikmap: subfont  name=%s fid=%d\n",
 303                  subfont_name, font_mojikmap->subfont_fids[i*TYPE1_NSUBS + j]);
 304       }
 305     }
 306     break;
 307   }
 308 #endif /* DELAYED_OPEN */
 309 
 310   font->private = font_mojikmap;
 311   vf_sexp_free3(&cap_div_scheme, &cap_subfont_name, &cap_ttf_subfont_enc);
 312   return 0;
 313 
 314 
 315 CANT_OPEN:
 316   vf_sexp_free3(&cap_div_scheme, &cap_subfont_name, &cap_ttf_subfont_enc);
 317   vf_error = VF_ERR_NO_FONT_ENTRY;
 318   release_mem(font_mojikmap);
 319   return -1;
 320 }
 321 
 322 
 323 Private int
 324 mojikmap_close(VF_FONT font)
     /* [<][>][^][v][top][bottom][index][help] */
 325 {
 326   release_mem((FONT_MOJIKMAP)(font->private));
 327 
 328   return 0; 
 329 }
 330 
 331 
 332 Private void
 333 release_mem(FONT_MOJIKMAP font_mojikmap)
     /* [<][>][^][v][top][bottom][index][help] */
 334 {
 335   int  i;
 336 
 337   if (font_mojikmap != NULL){
 338     vf_free(font_mojikmap->font_name);
 339     vf_free(font_mojikmap->subfont_name);
 340     vf_sexp_free1(&font_mojikmap->props);
 341     for (i = 0; i < font_mojikmap->nsubfonts; i++){
 342       if (font_mojikmap->subfont_fids[i] >= 0)
 343         VF_CloseFont(font_mojikmap->subfont_fids[i]);
 344     }
 345     vf_free(font_mojikmap);
 346   }
 347 }
 348 
 349 
 350 Private int
 351 mojikmap_get_metric1(VF_FONT font, long code_point, VF_METRIC1 metric,
     /* [<][>][^][v][top][bottom][index][help] */
 352                   double mag_x, double mag_y)
 353 {
 354   FONT_MOJIKMAP  font_mojikmap;
 355   int            fid;
 356   long           cp;
 357   
 358   if (metric == NULL){
 359     fprintf(stderr, "VFlib internal error: in mojikmap_get_metric1()\n");
 360     abort();
 361   }
 362 
 363   if ((font_mojikmap = (FONT_MOJIKMAP)font->private) == NULL){
 364     fprintf(stderr, "VFlib internal error in mojikmap class.\n");
 365     abort();
 366   }
 367 
 368   if ((fid = font_mapping(font, font_mojikmap, code_point, &cp)) < 0)
 369     return -1;
 370   if (cp < 0)
 371     return -1;
 372 
 373   VF_GetMetric1(fid, cp, metric, mag_x, mag_y);
 374 
 375   return 0;
 376 }
 377 
 378 
 379 Private int
 380 mojikmap_get_fontbbx1(VF_FONT font, double mag_x, double mag_y,
     /* [<][>][^][v][top][bottom][index][help] */
 381                    double *w_p, double *h_p, double *xoff_p, double *yoff_p)
 382 {
 383   FONT_MOJIKMAP  font_mojikmap;
 384   int         fid, i;
 385   double      w, h, xoff, yoff;
 386   
 387   if ((font_mojikmap = (FONT_MOJIKMAP)font->private) == NULL){
 388     fprintf(stderr, "VFlib internal error in mojikmap class.\n");
 389     abort();
 390   }
 391 
 392   *w_p = *h_p = *xoff_p = *yoff_p = 0;
 393   w = h = xoff = yoff = 0;
 394   for (i = 0; i < font_mojikmap->nsubfonts; i++){
 395     if ((fid = font_mojikmap->subfont_fids[i]) < 0)
 396       continue;
 397     if (VF_GetFontBoundingBox1(fid, mag_x, mag_y, &w, &h, &xoff, &yoff) < 0)
 398       continue;
 399     if (w > *w_p)
 400       *w_p = w;
 401     if (h > *h_p)
 402       *h_p = h;
 403     if (xoff < *xoff_p)
 404       *xoff_p = xoff;
 405     if (yoff > *yoff_p)
 406       *yoff_p = yoff;
 407   }
 408 
 409   return 0;
 410 }
 411 
 412 Private VF_BITMAP
 413 mojikmap_get_bitmap1(VF_FONT font, long code_point,
     /* [<][>][^][v][top][bottom][index][help] */
 414                   double mag_x, double mag_y)
 415 {
 416   FONT_MOJIKMAP  font_mojikmap;
 417   int            fid;
 418   long           cp;
 419 
 420   if ((font_mojikmap = (FONT_MOJIKMAP)font->private) == NULL){
 421     fprintf(stderr, "VFlib internal error in mojikmap class.\n");
 422     abort();
 423   }
 424   if ((fid = font_mapping(font, font_mojikmap, code_point, &cp)) < 0)
 425     return NULL;
 426   if (cp < 0)
 427     return NULL;
 428 
 429   return VF_GetBitmap1(fid, cp, mag_x, mag_y);
 430 }
 431 
 432 
 433 Private VF_OUTLINE
 434 mojikmap_get_outline(VF_FONT font, long code_point,
     /* [<][>][^][v][top][bottom][index][help] */
 435                   double mag_x, double mag_y)
 436 {
 437   FONT_MOJIKMAP  font_mojikmap;
 438   int            fid;
 439   long           cp;
 440 
 441   if ((font_mojikmap = (FONT_MOJIKMAP)font->private) == NULL){
 442     fprintf(stderr, "VFlib internal error in mojikmap class.\n");
 443     abort();
 444   }
 445   if ((fid = font_mapping(font, font_mojikmap, code_point, &cp)) < 0)
 446     return NULL;
 447   if (cp < 0)
 448     return NULL;
 449 
 450   return VF_GetOutline(fid, cp, mag_x, mag_y);
 451 }
 452 
 453 
 454 Private int
 455 mojikmap_get_metric2(VF_FONT font, long code_point, VF_METRIC2 metric, 
     /* [<][>][^][v][top][bottom][index][help] */
 456                   double mag_x, double mag_y)
 457 {
 458   FONT_MOJIKMAP  font_mojikmap;
 459   int            fid;
 460   long           cp;
 461 
 462   if ((font_mojikmap = (FONT_MOJIKMAP)font->private) == NULL){
 463     fprintf(stderr, "VFlib internal error in mojikmap class.\n");
 464     abort();
 465   }
 466   if ((fid = font_mapping(font, font_mojikmap, code_point, &cp)) < 0)
 467     return -1;
 468   if (cp < 0)
 469     return -1;
 470 
 471   VF_GetMetric2(fid, cp, metric, mag_x, mag_y);
 472 
 473   return 0;
 474 }
 475 
 476 Private int
 477 mojikmap_get_fontbbx2(VF_FONT font, double mag_x, double mag_y,
     /* [<][>][^][v][top][bottom][index][help] */
 478                    int*w_p, int *h_p, int *xoff_p, int *yoff_p)
 479 {
 480   FONT_MOJIKMAP  font_mojikmap;
 481   int         w, h, xoff, yoff;
 482   int         fid, i;
 483   
 484   if ((font_mojikmap = (FONT_MOJIKMAP)font->private) == NULL){
 485     fprintf(stderr, "VFlib internal error in mojikmap class.\n");
 486     abort();
 487   }
 488 
 489   *w_p = *h_p = *xoff_p = *yoff_p = 0;
 490   w = h = xoff = yoff = 0;
 491   for (i = 0; i < font_mojikmap->nsubfonts; i++){
 492     if ((fid = font_mojikmap->subfont_fids[i]) < 0)
 493       continue;
 494     if (VF_GetFontBoundingBox2(fid, mag_x, mag_y, &w, &h, &xoff, &yoff) < 0)
 495       continue;
 496     if (w > *w_p)
 497       *w_p = w;
 498     if (h > *h_p)
 499       *h_p = h;
 500     if (xoff < *xoff_p)
 501       *xoff_p = xoff;
 502     if (yoff > *yoff_p)
 503       *yoff_p = yoff;
 504   }
 505 
 506   return 0;
 507 }
 508 
 509 
 510 Private VF_BITMAP
 511 mojikmap_get_bitmap2(VF_FONT font, long code_point, 
     /* [<][>][^][v][top][bottom][index][help] */
 512                   double mag_x, double mag_y)
 513 {
 514   FONT_MOJIKMAP  font_mojikmap;
 515   int            fid;
 516   long           cp;
 517 
 518   if ((font_mojikmap = (FONT_MOJIKMAP)font->private) == NULL){
 519     fprintf(stderr, "VFlib internal error in mojikmap class.\n");
 520     abort();
 521   }
 522   if ((fid = font_mapping(font, font_mojikmap, code_point, &cp)) < 0)
 523     return NULL;
 524   if (cp < 0)
 525     return NULL;
 526 
 527   return VF_GetBitmap2(fid, cp, mag_x, mag_y);
 528 }
 529 
 530 
 531 Private char*
 532 mojikmap_get_font_prop(VF_FONT font, char *prop_name)
     /* [<][>][^][v][top][bottom][index][help] */
 533 {
 534   FONT_MOJIKMAP  font_mojikmap;
 535   SEXP           v;
 536   int            fid;
 537   long           cp;
 538 
 539   if ((font_mojikmap = (FONT_MOJIKMAP)font->private) == NULL){
 540     fprintf(stderr, "VFlib internal error in mojikmap class.\n");
 541     abort();
 542   }
 543 
 544   if ((v = vf_sexp_assoc(prop_name, font_mojikmap->props)) != NULL){
 545     return vf_strdup(vf_sexp_get_cstring(vf_sexp_cadr(v)));
 546   } else if ((v = vf_sexp_assoc(prop_name, default_properties)) != NULL){
 547     return vf_strdup(vf_sexp_get_cstring(vf_sexp_cadr(v)));
 548   }
 549 
 550   if ((fid = font_mapping(font, font_mojikmap, (long)1, &cp)) < 0)
 551     return NULL;
 552   if (cp < 0)
 553     return NULL;
 554 
 555   return VF_GetFontProp(fid, prop_name);
 556 }
 557 
 558 
 559 Private int
 560 mojikmap_query_font_type(VF_FONT font, long code_point)
     /* [<][>][^][v][top][bottom][index][help] */
 561 {
 562   FONT_MOJIKMAP  font_mojikmap;
 563   int            fid;
 564   long           cp;
 565 
 566   if ((font_mojikmap = (FONT_MOJIKMAP)font->private) == NULL){
 567     fprintf(stderr, "VFlib internal error in mojikmap class.\n");
 568     abort();
 569   }
 570   if ((fid = font_mapping(font, font_mojikmap, code_point, &cp)) < 0)
 571     return -1;
 572   if (cp < 0)
 573     return -1;
 574 
 575   return VF_QueryFontType(fid, cp);
 576 }
 577 
 578 
 579 Private int
 580 font_mapping(VF_FONT font, FONT_MOJIKMAP font_mojikmap, 
     /* [<][>][^][v][top][bottom][index][help] */
 581              long code_point, long *cp)
 582 {
 583   int   g, fid, c1, c2;
 584   long  c;
 585 
 586   if (code_point == 0){
 587     if (cp != NULL)
 588       *cp = -1;
 589     return -1;
 590   }
 591 
 592   g = -1;
 593   c = 0;
 594 
 595   switch (font_mojikmap->div_scheme){
 596   case DIVISION_SCHEME_TTF:
 597     g = code_point / (94*60);
 598     c = code_point % (94*60);
 599     if (c == 0){
 600       g += 100;
 601       c = (94*60);
 602     } else {
 603       g += 101;
 604     }
 605     c1 = ((c-1) / 94);
 606     c2 = ((c-1) % 94);
 607     if (c1 < 30){
 608       c1 += 16;
 609     } else {
 610       c1 += 18;
 611     }
 612     c = (c1+0x20) * 0x100 + (c2+0x21);
 613     g -= 101;
 614     if (font_mojikmap->ttf_subfont_enc == TTF_SUBFONT_ENC_JIS){
 615       ;
 616     } else if (font_mojikmap->ttf_subfont_enc == TTF_SUBFONT_ENC_UNICODE){
 617       if (font_mojikmap->ttf_subfont_ccv_id == CCV_NOT_TRIED){
 618         font_mojikmap->ttf_subfont_ccv_id 
 619           = vf_ccv_require("JISX0208", "ISO2022", "UNICODE", "UNICODE");
 620         if (debug_on('f')){
 621           printf("VFlib mojikmap:  CCV: id=%d\n",
 622                  font_mojikmap->ttf_subfont_ccv_id);
 623         }
 624         if (font_mojikmap->ttf_subfont_ccv_id < 0){
 625           font_mojikmap->ttf_subfont_ccv_id = CCV_NOT_EXIST;
 626           return -1; /* failed to invoke ccv */
 627         }
 628       }
 629       if (font_mojikmap->ttf_subfont_ccv_id >= 0){
 630         c = vf_ccv_conv(font_mojikmap->ttf_subfont_ccv_id, c);
 631       }
 632     } else { /* ??? */
 633       ;
 634     }
 635     break;
 636   case DIVISION_SCHEME_TYPE1:
 637     g = (code_point) / (94*60);
 638     c = (code_point) % (94*60);
 639     if (c == 0){
 640       g += 100;
 641       c = 5640;
 642     } else {
 643       g += 101;
 644     }
 645     if (c > 2820){
 646       c += 380;
 647     } else {
 648       c += 192;
 649     }
 650     g -= 101;
 651     g = g * TYPE1_NSUBS + (c / 256);
 652     c = (c % 256);
 653     break;
 654   default:
 655     break;
 656   }
 657 
 658   if ((g < 0) || (g >= font_mojikmap->nsubfonts))
 659     return -1;
 660 
 661   if (cp != NULL)
 662     *cp = c;
 663   fid = mojik_delayed_open(font, font_mojikmap, g);
 664 
 665   if (debug_on('m')){
 666     printf("VFlib mojikmap:  Code Point: %ld => FID: %d, Code: 0x%lx\n",
 667            code_point, fid, c);
 668   }
 669 
 670   return  fid;
 671 }
 672 
 673 
 674 
 675 Private int
 676 mojik_delayed_open(VF_FONT font, FONT_MOJIKMAP font_mojikmap, int g)
     /* [<][>][^][v][top][bottom][index][help] */
 677 {
 678   char  subfont[1024];
 679 
 680   if ((g < 0) || (g >= font_mojikmap->nsubfonts))
 681     return -1;
 682   if (font_mojikmap->subfont_fids[g] >= 0)
 683     return font_mojikmap->subfont_fids[g];
 684   if (font_mojikmap->subfont_fids[g] == SUBFONT_NOT_EXIST)
 685     return -1;
 686 
 687   switch (font_mojikmap->div_scheme){
 688 
 689   case DIVISION_SCHEME_TTF:
 690     sprintf(subfont, font_mojikmap->subfont_name, g+101);
 691     if (font->mode == 1){
 692       font_mojikmap->subfont_fids[g]
 693         = VF_OpenFont1(subfont, font->dpi_x, font->dpi_y, 
 694                        font->point_size, font->mag_x, font->mag_y);
 695     } else if (font->mode == 2){
 696       font_mojikmap->subfont_fids[g]
 697         = VF_OpenFont2(subfont, 
 698                        font->pixel_size, font->mag_x, font->mag_y);
 699     } else {
 700       fprintf(stderr, "VFlib: Internal error in mojikmap_delayed_open()\n");
 701       abort();
 702     }
 703     break;
 704 
 705   case DIVISION_SCHEME_TYPE1:
 706     sprintf(subfont, font_mojikmap->subfont_name, 
 707             (g / TYPE1_NSUBS) + 101, (g % TYPE1_NSUBS) + 6);
 708     if (font->mode == 1){
 709       font_mojikmap->subfont_fids[g]
 710         = VF_OpenFont1(subfont, font->dpi_x, font->dpi_y, 
 711                        font->point_size, font->mag_x, font->mag_y);
 712     } else if (font->mode == 2){
 713       font_mojikmap->subfont_fids[g]
 714         = VF_OpenFont2(subfont, 
 715                        font->pixel_size, font->mag_x, font->mag_y);
 716     } else {
 717       fprintf(stderr, "VFlib: Internal error in mojikmap_delayed_open()\n");
 718       abort();
 719     }
 720     break;
 721   }
 722 
 723   if (font_mojikmap->subfont_fids[g] < 0){
 724     font_mojikmap->subfont_fids[g] = SUBFONT_NOT_EXIST;
 725   }
 726   if (debug_on('f'))
 727     printf("VFlib mojikmap: subfont  name=%s fid=%d\n",
 728            subfont, font_mojikmap->subfont_fids[g]);
 729 
 730   return font_mojikmap->subfont_fids[g];
 731 }
 732 
 733 Private int
 734 debug_on(char type)
     /* [<][>][^][v][top][bottom][index][help] */
 735 {
 736   char  *p;
 737 
 738   if (default_debug_mode == NULL)
 739     return FALSE;
 740   if ((p = vf_sexp_get_cstring(default_debug_mode)) == NULL)
 741     return FALSE;
 742   
 743   while (*p != '\0'){
 744     if (*p == type)
 745       return TRUE;
 746     p++;
 747   }
 748 
 749   while (*p != '\0'){
 750     if (*p == '*')
 751       return TRUE;
 752     p++;
 753   }
 754 
 755   return FALSE;
 756 }
 757 
 758 
 759 /*EOF*/

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