2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: falfont.c /main/8 1996/07/04 02:35:37 cde-fuj $ */
25 * (c) Copyright 1995 FUJITSU LIMITED
26 * This is source code modified by FUJITSU LIMITED under the Joint
27 * Development Agreement for the CDEnext PST.
28 * This is unpublished proprietary source code of FUJITSU LIMITED
41 #include <sys/types.h>
51 #define MKFONTLIST (1<<1)
52 #define SRCHFNAME (1<<2)
53 #define FONTOFID (1<<3)
55 typedef struct _FontIDInfo {
62 typedef struct _MngFontID {
67 /*** structures for UDC fontpath ***/
68 static FalFontPath orgn = { 0, NULL }; /* for libfal */
69 static FalFontPath copy = { 0, NULL }; /* report to the user */
70 static FalFontPath wpath = { 0, NULL }; /* for libfal */
72 /***** Variables for notice kind of error *****/
76 unsigned long fal_utyerrno ;
77 char fal_err_file[ FAL_LINE_MAX+1 ] ;
79 char fal_err_file_buf[ sizeof(fal_err_file) ] ;
81 #define fal_seterrcode( uty, der, errno, func ) { \
82 fal_utyerror = (uty); \
83 fal_utyderror = (der) ; \
84 fal_utyerrno = (errno) ; \
85 fal_utyerrno |= ((func)<<8) ; \
89 static int execDefined ;
90 static int execUndefined ;
91 static int IsDefaultPath = FALSE ;
92 static MngFontID mngfid = { 0, NULL } ;
93 static int tmp_codeset = 0 ;
94 static char *fal_locale = NULL ;
95 static char *charset_str_buf = NULL ;
96 static int *codeset_list_sav = NULL ;
97 static int codeset_list_num = 0 ;
99 /* declaration of inner functions */
100 char *fal_get_base_name();
102 static FILE *open_fonts_list() ;
103 static int falGetGlyph() ;
104 static int falGetCharIndex() ;
105 static int falZoom() ;
106 static int exline() ;
107 static char falGetMask() ;
108 static int chk_key_str() ;
109 static int fal_make_fontlist() ;
110 static int fal_sort_fontlist() ;
111 static int set_default_path() ;
112 static int cpy_default_path() ;
113 static int comp_default_path() ;
114 static int fal_clear_font_path() ;
115 static int set_font_pathlist() ;
117 static int fal_split_data() ;
118 static int fal_clear_data() ;
119 static int CR_to_NULL() ;
120 static int fal_cmp_data() ;
121 static int new_target() ;
126 void set_errfile_str() ;
128 static int fal_init() ;
129 static int fal_add_fidinf() ;
130 static int fal_read_fidinf() ;
131 static int fal_del_fidinf() ;
132 static int fal_conv_code_to_glyph() ;
133 static int fal_conv_glyph_to_code() ;
134 static int falReadFontInfoLists() ;
135 static int fal_get_def_fontdata() ;
136 static int falgetfontlist() ;
137 static int fal_get_undef_fontdata() ;
138 static void clear_charset_info() ;
139 static int make_default_path() ;
140 static int file_lock() ;
141 static int file_unlock() ;
142 static int is_lock() ;
144 extern int falReadFontProp() ;
145 extern int falReadGpfProp() ;
146 extern int falInitReadPcfProp() ;
147 extern int fal_get_codeset() ;
148 extern int falInitReadPcf() ;
149 extern void falGetPcfGSize() ;
150 extern int falPcfGlyph() ;
151 extern int fal_code_to_glyph() ;
152 extern int fal_glyph_to_code() ;
159 memset( fal_err_file, '\0', sizeof(fal_err_file) ) ;
160 memset( fal_err_file_buf, '\0', sizeof(fal_err_file_buf) ) ;
164 if( (lcl = (char *)getenv( "LANG" )) == NULL ){
167 if( (fal_locale = (char *)strdup( lcl )) == NULL ){
168 fal_utyerror = _FAL_MALOC_ER;
170 fal_utyerrno = FAL_ERR_MALLOC ;
178 set_errfile_str( obuf, ibuf )
184 if( (strlen(ibuf)+1) > sizeof(fal_err_file) ){
186 sp += ((strlen(ibuf)+1) - sizeof(fal_err_file)) ;
189 strcpy( obuf, ibuf ) ;
194 * open a fontfile by "RDONLY"
197 FalOpenFont( file, protect_key_data, codeset )
199 int protect_key_data;
202 FalFontID __FalOpenFont();
204 return __FalOpenFont( file, protect_key_data, codeset, 0 );
208 * open a fontfile by "RDWR"
212 * 1: ON --- open mode "RDWR"
213 * 0: OFF -- for "FalOpenFont()"
216 __FalOpenFont( file, protect_key_data, codeset, lockflag )
218 int protect_key_data;
228 if ( !(openfontfile = (char *)malloc( strlen( file ) + 1 )) ) {
229 fal_seterrcode( _FAL_MALOC_ER, 0,
230 FAL_ERR_MALLOC , FAL_FUNCNUM_OPNFNT ) ;
231 return (FalFontID)FAL_ERROR;
233 strcpy( openfontfile, file );
235 /* read a condition of a fontfile */
236 if ( stat( openfontfile, &st ) < 0 ) {
237 set_errfile_str( fal_err_file, openfontfile ) ;
238 free( openfontfile );
239 fal_utyerror = _FAL_STAT_ER;
240 fal_utyderror = errno;
241 fal_utyerrno = FAL_ERR_STAT ;
242 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
243 return (FalFontID)FAL_ERROR;
246 CHK_PROTECT_KEY( protect_key_data, openfontfile, fal_utyerror, fal_utyderror ) ;
248 if ( st.st_size < sizeof( FontInfoRec ) ) {
249 set_errfile_str( fal_err_file, openfontfile ) ;
250 free( openfontfile );
251 fal_utyerror = _FAL_FONT_ER;
253 fal_utyerrno = FAL_ERR_FONT ;
254 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
255 return (FalFontID)FAL_ERROR;
258 /* open a fontfile */
259 if ( lockflag == 1 ) {
261 if ( (fd = open( openfontfile, O_RDWR )) < 0 ) {
262 set_errfile_str( fal_err_file, openfontfile ) ;
263 free( openfontfile );
264 fal_utyerror = _FAL_OPEN_ER;
265 fal_utyderror = errno;
266 fal_utyerrno = FAL_ERR_FNT_OPN ;
267 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
268 return (FalFontID)FAL_ERROR;
270 ret = is_lock( fd ) ;
272 set_errfile_str( fal_err_file, openfontfile ) ;
273 free( openfontfile );
274 fal_utyerror = _FAL_OPEN_ER;
275 fal_utyderror = errno;
276 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
278 return (FalFontID)FAL_ERROR;
281 if ( (fd = open( openfontfile, O_RDONLY)) < 0 ) {
282 set_errfile_str( fal_err_file, openfontfile ) ;
283 free( openfontfile );
284 fal_utyerror = _FAL_OPEN_ER;
285 fal_utyderror = errno;
286 fal_utyerrno = FAL_ERR_FNT_OPN ;
287 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
288 return (FalFontID)FAL_ERROR;
292 /* read a fontfile */
293 if ( !(finf = ( Oak_FontInf * )malloc(sizeof( Oak_FontInf ) )) ) {
294 free( openfontfile );
295 fal_utyerror = _FAL_MALOC_ER;
297 fal_utyerrno = FAL_ERR_MALLOC ;
298 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
300 return (FalFontID)FAL_ERROR;
306 buf = (char *)mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
307 if ( buf != (char *)-1 ) {
308 /* if "mmap" is normal end */
309 if ( lockflag == 0 ) {
313 finf->fsize = st.st_size;
316 /* if "mmap" is abnormal end , try "read()" */
317 finf->ismmap = FALSE;
318 if ( !(buf = (char *)malloc(st.st_size)) ) {
319 free( openfontfile );
320 fal_utyerror = _FAL_MALOC_ER;
322 fal_utyerrno = FAL_ERR_MALLOC ;
323 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
326 return (FalFontID)FAL_ERROR;
328 if ( read(fd, buf, st.st_size) != st.st_size ) {
329 set_errfile_str( fal_err_file, openfontfile ) ;
330 free( openfontfile );
331 fal_utyerror = _FAL_READ_ER;
332 fal_utyderror = errno;
333 fal_utyerrno = FAL_ERR_FNT_RD ;
334 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
338 return (FalFontID)FAL_ERROR;
344 if ( !(finf->fname = (char *)strdup( openfontfile )) ) {
345 fal_seterrcode( _FAL_MALOC_ER, 0,
346 FAL_ERR_MALLOC , FAL_FUNCNUM_OPNFNT ) ;
347 free( openfontfile );
351 return (FalFontID)FAL_ERROR;
354 /* case of a pcf font */
355 if ( strcmp( FILE_SUFFIX( openfontfile ), PCFSUFFIX ) == 0 ) {
356 if ( falInitReadPcf( &finf->pcfinf, buf ) ) {
357 fal_utyerror = _FAL_PKEY_ER;
359 fal_utyerrno = FAL_ERR_FONT ;
360 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
365 finf->pFinf = &finf->pcfinf.info;
367 FAL_GET_SNF_HEADER( buf, protect_key_data, fal_utyerror, fal_utyderror, fd, finf, openfontfile ) ;
373 = (CharInfoPtr)( (char *)finf->pFinf
374 + sizeof( FontInfoRec ) );
376 = (unsigned char *)((char *)finf->pCinf
377 + (sizeof(CharInfoRec) * GETNUMCHARS(finf->pFinf)));
379 = finf->pFinf->maxbounds.metrics.rightSideBearing
380 - finf->pFinf->maxbounds.metrics.leftSideBearing;
382 = finf->pFinf->maxbounds.metrics.ascent
383 + finf->pFinf->maxbounds.metrics.descent;
384 } else if ( finf->isPcf ) {
386 finf->pGlyphs = NULL;
387 falGetPcfGSize( &finf->pcfinf, &finf->width, &finf->height);
389 fal_utyerror = _FAL_FONT_ER;
391 fal_utyerrno = FAL_ERR_FONT ;
392 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
396 finf->start = (finf->pFinf->firstRow << 8) | finf->pFinf->firstCol;
397 finf->end = (finf->pFinf->lastRow << 8) | finf->pFinf->lastCol;
401 finf->sptnBuf = (char *)0;
403 finf->dptnBuf = (char *)0;
405 finf->dbuf = (char *)0;
407 finf->sptnBufL = ((finf->width + 7) / 8) * (finf->height);
408 finf->sptnBuf = (char *)malloc(finf->sptnBufL);
409 if ( finf->sptnBuf == NULL ) {
410 fal_utyerror = _FAL_MALOC_ER;
412 fal_utyerrno = FAL_ERR_MALLOC ;
413 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
417 /* Save font information */
418 if( fal_add_fidinf( (FalFontID)finf, codeset,
419 ((tmp_codeset)?tmp_codeset:codeset),
420 lockflag ) == FAL_ERROR )
422 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
426 /* Lock the font file */
427 if ( lockflag == 1 ) {
428 if ( file_lock( finf->fd ) == FAL_ERROR ) {
429 set_errfile_str( fal_err_file, openfontfile ) ;
430 fal_utyerror = _FAL_OPEN_ER;
431 fal_utyderror = errno;
432 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
436 free( openfontfile );
438 return( ( FalFontID ) finf );
443 if ( finf->ismmap == TRUE ) {
444 munmap( buf, finf->fsize );
453 set_errfile_str( fal_err_file, openfontfile ) ;
454 free( openfontfile );
459 return (FalFontID)FAL_ERROR;
464 #if NeedFunctionPrototypes
472 int __FalCloseFont();
473 FontIDInfo fontid_inf ;
475 if( fal_read_fidinf( fid, &fontid_inf ) == FAL_ERROR ) {
476 fal_utyerrno |= (FAL_FUNCNUM_CLSFNT<<8) ;
480 return __FalCloseFont( fid, fontid_inf.islock );
489 * 1: ON --- open a font by "RDWR" mode
490 * 0: OFF -- for "FalOpenFont()"
492 __FalCloseFont( fid, lockflag )
498 finf = ( Oak_FontInf * )fid;
500 if ( finf == NULL ) {
501 fal_utyerror = _FAL_PARM_ER;
503 fal_utyerrno = FAL_ERR_PARM ;
504 fal_utyerrno |= (FAL_FUNCNUM_CLSFNT<<8) ;
508 set_errfile_str( fal_err_file_buf, finf->fname ) ;
510 if ( finf->buf != NULL ) {
512 if ( finf->ismmap == TRUE ) {
513 munmap( finf->buf, finf->fsize );
514 if ( lockflag == 1 ) {
526 free( finf->sptnBuf );
527 free( finf->dptnBuf );
532 if ( lockflag == 1 ) {
533 if ( file_unlock( finf->fd ) == FAL_ERROR ) {
534 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
535 fal_utyerrno |= (FAL_FUNCNUM_CLSFNT<<8) ;
540 if ( fal_del_fidinf( fid ) == FAL_ERROR ) {
541 fal_utyerrno |= (FAL_FUNCNUM_CLSFNT<<8) ;
548 #if NeedFunctionPrototypes
551 FalFontinfo *fontinfo )
553 FalQueryFont( fid, fontinfo )
555 FalFontinfo *fontinfo;
559 unsigned int inner_start, inner_end ;
560 FontIDInfo fontid_inf ;
562 if( fal_read_fidinf( fid, &fontid_inf ) == FAL_ERROR ){
563 fal_utyerrno |= (FAL_FUNCNUM_QRY<<8) ;
566 finf = ( Oak_FontInf * )fid;
567 if ( finf == NULL || fontinfo == NULL ) {
568 fal_utyerror = _FAL_PARM_ER;
570 fal_utyderror = _FAL_Q_P_FINF_DER;
572 fal_utyderror = _FAL_Q_P_FONT_DER;
574 fal_utyerrno = FAL_ERR_PARM ;
575 fal_utyerrno |= (FAL_FUNCNUM_QRY<<8) ;
579 fontinfo->width = (int)finf->width;
580 fontinfo->height = (int)finf->height;
582 if( (fal_conv_glyph_to_code( finf, fontid_inf.dspcode,
583 fontid_inf.cd_set, finf->start, &inner_start ) == FAL_ERROR ) ||
584 (fal_conv_glyph_to_code( finf, fontid_inf.dspcode,
585 fontid_inf.cd_set, finf->end, &inner_end ) == FAL_ERROR ))
587 fal_utyerrno |= (FAL_FUNCNUM_QRY<<8) ;
591 fontinfo->top = inner_start ;
592 fontinfo->bottom = inner_end ;
597 #if NeedFunctionPrototypes
606 FalReadFont( fid, code, width, height )
617 unsigned int inner_code; /* an inside code of a file */
619 finf = ( Oak_FontInf * )fid;
621 if ( finf == NULL ) {
622 fal_utyerror = _FAL_PARM_ER;
623 fal_utyderror = _FAL_R_P_FINF_DER;
624 fal_utyerrno = FAL_ERR_PARM ;
625 fal_utyerrno |= (FAL_FUNCNUM_RDFNT<<8) ;
626 return (char *)FAL_ERROR;
629 fal_utyerror = _FAL_PARM_ER;
630 fal_utyderror = _FAL_R_P_W_DER;
631 fal_utyerrno = FAL_ERR_PARM ;
632 fal_utyerrno |= (FAL_FUNCNUM_RDFNT<<8) ;
633 return (char *)FAL_ERROR;
636 fal_utyerror = _FAL_PARM_ER;
637 fal_utyderror = _FAL_R_P_H_DER;
638 fal_utyerrno = FAL_ERR_PARM ;
639 fal_utyerrno |= (FAL_FUNCNUM_RDFNT<<8) ;
640 return (char *)FAL_ERROR;
647 height = finf->height;
649 if ( (width != finf->width) || (height != finf->height) ) {
655 memset(finf->sptnBuf, 0, finf->sptnBufL);
657 if( fal_conv_code_to_glyph( fid, code, &inner_code ) == FAL_ERROR ) {
659 fal_utyerrno |= (FAL_FUNCNUM_RDFNT<<8) ;
664 /* case of a pcf font */
665 falPcfGlyph( finf->sptnBuf, finf, inner_code );
667 /* case of a snf font */
668 falGetGlyph( finf->sptnBuf, finf, inner_code );
670 if ( zoom_on == TRUE ) {
671 ptnBsize = ((width + 7)/8)*height;
672 if ( ptnBsize > finf->dptnBufL ) {
673 if ( finf->dptnBuf == NULL ) {
674 toglyph = (char *)malloc( ptnBsize );
676 toglyph = (char *)realloc( finf->dptnBuf, ptnBsize );
678 if ( toglyph == NULL ) {
679 fal_utyerror = _FAL_MALOC_ER;
681 fal_utyerrno = FAL_ERR_MALLOC ;
682 fal_utyerrno |= (FAL_FUNCNUM_RDFNT<<8) ;
683 return (char *)FAL_ERROR;
685 finf->dptnBufL = ptnBsize;
686 finf->dptnBuf = toglyph;
688 ptnBsize = (width + 7) / 8;
689 if ( ptnBsize > finf->dbufL ) {
690 if ( finf->dbuf == NULL ) {
691 toglyph = (char *)malloc( ptnBsize );
693 toglyph = (char *)realloc( finf->dbuf, ptnBsize );
695 if ( toglyph == NULL ) {
696 fal_utyerror = _FAL_MALOC_ER;
698 fal_utyerrno = FAL_ERR_MALLOC ;
699 fal_utyerrno |= (FAL_FUNCNUM_RDFNT<<8) ;
700 return (char *)FAL_ERROR;
702 finf->dbufL = ptnBsize;
703 finf->dbuf = toglyph;
706 finf->dptnBuf, finf->sptnBuf,
707 finf->width, finf->height, width, height, finf->dbuf
709 return( finf->dptnBuf );
711 return finf->sptnBuf;
716 falGetGlyph( glyph, finf, code )
721 int in_dwidth, out_dwidth, ix, i, j;
722 char *glyph_p, *inp, p_mask, falGetMask();
723 CharInfoPtr CharInfP;
724 int codeRow, codeCol;
725 unsigned int inner_code; /* an inside code of a file */
728 codeCol = inner_code & 0xff; /* a lower byte of an inside code */
729 codeRow = (inner_code >> 8) & 0xff; /* a upper byte of a code */
733 ((code < finf->start) || (code > finf->end)) ||
734 ((codeCol < finf->pFinf->firstCol) ||
735 (codeCol > finf->pFinf->lastCol)) ||
736 ((codeRow < finf->pFinf->firstRow) ||
737 (codeRow > finf->pFinf->lastRow))
743 /* Get a character index */
744 ix = falGetCharIndex( finf, inner_code );
745 CharInfP = finf->pCinf;
747 if ( !CharInfP[ix].exists ) {
755 = (finf->width + SNF_BOUND - 1)
756 / SNF_BOUND * (SNF_BOUND / 8);
757 out_dwidth = (finf->width + 7) / 8;
759 p_mask = falGetMask( finf->width );
761 glyph_p = (char *)finf->pGlyphs + CharInfP[ix].byteOffset;
762 for ( i = 0; i < finf->height; i++ ) {
763 inp = glyph_p + ( in_dwidth * i );
764 for ( j = 0; j < out_dwidth-1; j++ ) {
767 *glyph++ = *inp++ & p_mask;
773 falGetCharIndex( finf, code )
775 int code; /* an inside code of a file */
777 int nColperRow, nRow, nCol;
779 nColperRow = finf->pFinf->lastCol - finf->pFinf->firstCol + 1;
780 nRow = ((code >> 8) & 0xff) - finf->pFinf->firstRow;
781 nCol = (code & 0xff) - finf->pFinf->firstCol;
783 return ( nRow * nColperRow + nCol );
787 falZoom( dmem, smem, sw, sh, dw, dh, dbuf )
801 swidth = (sw + 7) / 8;
802 dwidth = (dw + 7) / 8;
807 for ( i=0; i < sh; i++ ) {
810 exline( sp, dbuf, sw, dw );
813 memcpy( dp, dbuf, dwidth );
815 for ( ; lcnt >= sh; lcnt -= sh ) {
816 memcpy( dp, dbuf, dwidth );
827 exline( sp, dbuf, sw, dw )
833 int i, bit, sval, dval, dcnt, bcnt;
838 for ( i = 0; i < sw; i++ ) {
842 bit = ( (sval & 0x80) ? 1 : 0 );
844 for ( bcnt += dw; bcnt >= sw; bcnt -= sw ) {
845 dval = ( dval << 1 ) | bit;
847 *dbuf++ = (char)dval;
860 static unsigned char _Fal_Mask_Tab[8] = {
861 0xff, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe
869 return _Fal_Mask_Tab[ix];
873 /* a difinition of a style */
874 static FalFontDB fal_db_style[] = {
875 { FAL_FONT_MINCHO, FAL_FONT_STR_MINCHO },
876 { FAL_FONT_GOTHIC, FAL_FONT_STR_GOTHIC },
877 { FAL_FONT_MARU_GOTHIC, FAL_FONT_STR_MARU_GOTHIC },
878 { FAL_FONT_TEXTBOOK, FAL_FONT_STR_TEXTBOOK },
879 { FAL_FONT_BRASH_GYOU, FAL_FONT_STR_BRASH_GYOU },
880 { FAL_FONT_BRASH_KAI, FAL_FONT_STR_BRASH_KAI },
881 { FAL_FONT_HANDWRITING, FAL_FONT_STR_HANDWRITING },
882 { FAL_FONT_UNKNOWN, ""}
885 /* a difinition of a shape */
886 static FalFontDB fal_db_shape[] = {
887 { FAL_FONT_ZENKAKU, FAL_FONT_STR_ZENKAKU },
888 { FAL_FONT_HANKAKU, FAL_FONT_STR_HANKAKU },
889 { FAL_FONT_QUARTER, FAL_FONT_STR_QUARTER },
890 { FAL_FONT_UNKNOWN, ""}
895 /*********************************************************/
896 /* make a font information list and carry to user */
897 /*********************************************************/
899 #if NeedFunctionPrototypes
902 FalFontData *key_data,
904 FalFontDataList **list_ret )
907 FalGetFontList( key_data, mask, list_ret )
908 FalFontData *key_data; /* a structure of a searching information */
909 int mask; /* a mask */
910 FalFontDataList **list_ret; /* maked a address of a structure */
914 FalFontDataList *fls; /* a pointer of a structure of "FalFontDataList()" */
916 /* clear an error's data */
922 SET_EXECDEFAULT( mask, execDefined, execUndefined ) ;
924 /* interface check */
925 if ( list_ret == NULL ) {
926 fal_utyerror = _FAL_PARM_ER;
927 fal_utyderror = _FAL_L_P_LST_DER;
928 fal_utyerrno = FAL_ERR_PARM ;
929 fal_utyerrno |= (FAL_FUNCNUM_GFLST<<8) ;
933 /* character check */
934 if ( chk_key_str( key_data, mask ) == FAL_ERROR ) {
935 fal_utyerrno |= (FAL_FUNCNUM_GFLST<<8) ;
940 if ( orgn.path == NULL ) {
941 if ( set_default_path() == FAL_ERROR ) {
942 fal_utyerrno |= (FAL_FUNCNUM_GFLST<<8) ;
947 /* make an structure of "FalFontDataList()" */
948 if ((fls = (FalFontDataList *)malloc( sizeof( FalFontDataList ))) == NULL){
949 fal_utyerror = _FAL_MALOC_ER;
950 fal_utyerrno = FAL_ERR_MALLOC ;
951 fal_utyerrno |= (FAL_FUNCNUM_GFLST<<8) ;
955 /* inital set for search */
959 /* make font infomation list */
960 if ( fal_make_fontlist( fls, key_data, mask ) == FAL_ERROR) {
961 switch( fal_utyerror ) {
963 case _FAL_DATA_OPEN_ER :
966 FalFreeFontList( fls );
967 fal_utyerrno &= 0xff;
968 fal_utyerrno |= (FAL_FUNCNUM_GFLST<<8) ;
971 /* sort element of font infomation list */
972 if( fal_sort_fontlist( fls ) == FAL_ERROR ) {
973 FalFreeFontList( fls );
974 fal_utyerrno &= 0xff;
975 fal_utyerrno |= (FAL_FUNCNUM_GFLST<<8) ;
985 /***********************************************************************/
986 /* search a character "key" of a structure */
987 /***********************************************************************/
990 chk_key_str( key, mask )
991 FalFontData *key; /* a structure of saerching information */
992 int mask; /* a mask */
1000 /* check a character of setting a mask */
1002 if ((mask & FAL_FONT_MASK_XLFDNAME) && (key->xlfdname == NULL)) {
1006 if ((mask & FAL_FONT_MASK_STYLE_NAME) && (key->style.name == NULL)) {
1010 if ((mask & FAL_FONT_MASK_SHAPE_NAME) && (key->shape.name == NULL)) {
1013 CHK_KEY_STR_OPTION( mask, key, flg ) ;
1016 fal_utyerror = _FAL_PARM_ER;
1017 fal_utyderror = _FAL_L_P_KEY_DER;
1018 fal_utyerrno = FAL_ERR_PARM ;
1025 /***************************************************************/
1026 /* read a font information and add a list or make a list */
1027 /***************************************************************/
1031 fal_make_fontlist( fls, key, mask )
1032 FalFontDataList *fls; /* a pointer of a structure of a font information list */
1033 FalFontData *key; /* a structure of searching information */
1034 int mask; /* a mask for a saerch */
1036 return falReadFontInfoLists(MKFONTLIST,
1043 /**************************************************/
1044 /* free a structure of "FalFontDataList()" */
1045 /**************************************************/
1047 #if NeedFunctionPrototypes
1050 FalFontDataList *list )
1053 FalFreeFontList( list )
1054 FalFontDataList *list;
1059 /* parametter check */
1060 if ( list == NULL ) {
1061 fal_utyerror = _FAL_PARM_ER;
1062 fal_utyerrno = FAL_ERR_PARM ;
1063 fal_utyerrno |= (FAL_FUNCNUM_FRFLST<<8) ;
1066 /* free a structure's array of "FalFontData()" */
1067 if ( list->list != NULL ) {
1068 for ( i = 0; i < list->num; i++ ) {
1069 /* free a structure's character of "FalFontData()" */
1070 free( list->list[i].xlfdname );
1071 free( list->list[i].style.name );
1072 free( list->list[i].shape.name );
1073 FAL_FREE_FONTLIST_OPTION( list ) ;
1075 /* free a structure's array of "FalFontData()" */
1081 /* free a structure of " FalFontDataList()" */
1087 /***********************************************************************/
1088 /* split string for "FalFontData()" */
1089 /***********************************************************************/
1092 fal_split_data( buf, elm_num, elm)
1100 /* check a comment */
1101 if ((*buf == '#') || (*buf == '\0')) {
1102 return _FAL_TRY_NEXT;
1104 /* check a pathname */
1105 if ( *buf == '/' ) {
1106 return _FAL_TRY_NEXT;
1109 for ( cnt = 0, strtop_flg = 1 ; *buf != '\0'; buf++ ){
1115 if ( *buf == ':' ) {
1120 if ( cnt != elm_num ) {
1121 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
1122 fal_utyerror = _FAL_FLST_ER;
1123 fal_utyerrno = FAL_ERR_FDATA_DSC ;
1129 /***********************************************************************/
1130 /* clear a structure of "FalFontData()" */
1131 /***********************************************************************/
1137 /* search a character */
1138 free(tmp->xlfdname);
1139 free(tmp->style.name);
1140 free(tmp->shape.name);
1141 FAL_CLEAR_DATA_OPTION( tmp ) ;
1142 memset(tmp, 0, sizeof(*tmp));
1147 fal_check_already_exist( data, lst )
1149 FalFontDataList *lst;
1154 mask = FAL_FONT_MASK_XLFDNAME | FAL_FONT_MASK_STYLE_NAME
1155 | FAL_FONT_MASK_SIZE_H | FAL_FONT_MASK_CODE_SET ;
1157 for ( i=0 ; i < lst->num ; i++ ){
1158 switch ( fal_cmp_data( &(lst->list[i]), data, mask ) ) {
1171 fal_sort_fontlist( lst )
1172 FalFontDataList *lst;
1175 FalFontDataList srt;
1179 if( lst->num == 0 ){
1185 if (( srt.list = malloc(sizeof(FalFontData) * srt.num)) == NULL) {
1186 fal_utyerrno = FAL_ERR_MALLOC ;
1189 memmove (srt.list, lst->list, sizeof(FalFontData) * srt.num);
1191 for ( i=0 ; i < srt.num -1 ; i++ ) {
1193 memmove( &target, &(srt.list[i]), sizeof(FalFontData));
1196 for ( j=i+1 ; j < srt.num ; j++ ) {
1197 if ( new_target( &target, &(srt.list[j]) ) ) {
1198 memmove( &target, &(srt.list[j]), sizeof(FalFontData));
1202 if (target_entry != i) {
1203 memmove( &target, &(srt.list[target_entry]),
1206 memmove( &(srt.list[i+1]), &(srt.list[i]),
1207 sizeof(FalFontData)*(target_entry -i)
1209 memmove( &(srt.list[i]), &target,
1215 lst->list = srt.list;
1221 /***************************************/
1222 /* change a character for a number */
1223 /***************************************/
1234 str_end = strchr( str, '\0' );
1236 tmp = (int)strtol(str, &ptr, 10);
1239 if ((ptr == str) || (ptr != str_end)) {
1240 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
1241 fal_utyerror = _FAL_FLST_ER;
1242 fal_utyerrno = FAL_ERR_FDATA_DSC ;
1249 /*******************************/
1251 /*******************************/
1258 if (!strcmp(str, "CS0")) {
1260 } else if (!strcmp(str, "CS1")) {
1262 } else if (!strcmp(str, "CS2")) {
1264 } else if (!strcmp(str, "CS3")) {
1267 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
1268 fal_utyerror = _FAL_FLST_ER;
1269 fal_utyerrno = FAL_ERR_FDATA_DSC ;
1276 /******************************************/
1277 /* get a equipment of an output permission*/
1278 /******************************************/
1282 fal_set_prm(str, prm)
1287 for ( ; *str != '\0' ; str++) {
1289 tmp |= FAL_FONT_PRINTER;
1290 } else if( *str == 'D' ) {
1291 tmp |= FAL_FONT_DISPLAY;
1293 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
1294 fal_utyerror = _FAL_FLST_ER;
1295 fal_utyerrno = FAL_ERR_FDATA_DSC ;
1303 static int fal_read_db( str, db )
1309 for(i=0 ; db[i].def != FAL_FONT_UNKNOWN ; i++) {
1310 if (!strcmp(str, db[i].name)) {
1314 return FAL_FONT_UNKNOWN ;
1318 /***************************************/
1319 /* make a structure of "FalFontPath()" */
1320 /***************************************/
1323 FalGetFontPath( dlist_ret )
1324 FalFontPath **dlist_ret;
1327 /* clear an error data */
1332 /* get current locale */
1333 if( fal_init() ) return FAL_ERROR ;
1335 /* parametter check */
1336 if ( dlist_ret == NULL ) {
1337 fal_utyerror = _FAL_PARM_ER;
1338 fal_utyerrno = FAL_ERR_PARM ;
1341 if ( orgn.path == NULL ) {
1342 if ( set_default_path() == FAL_ERROR ) {
1345 if ( cpy_default_path( © ) == FAL_ERROR ){
1348 } else if ( copy.path == NULL ) {
1349 if ( cpy_default_path(©) == FAL_ERROR ){
1354 if ( comp_default_path( © ) == FAL_ERROR ) {
1355 fal_clear_font_path( © );
1356 if ( cpy_default_path(©) == FAL_ERROR ){
1368 return set_font_pathlist(&orgn, 0) ;
1372 cpy_default_path( p )
1378 if ((orgn.num == 0) || (orgn.path == NULL)) {
1385 (tmp.path = (char **)malloc(sizeof(char *) * (orgn.num) ))
1388 fal_utyerror = _FAL_MALOC_ER;
1389 fal_utyerrno = FAL_ERR_MALLOC ;
1393 for ( i = 0 ; i< orgn.num ; i++ ) {
1395 /* malloc & copy in strdup */
1396 if ((tmp_str = (char *)strdup((orgn.path)[i])) == NULL) {
1397 fal_clear_font_path( &tmp );
1398 fal_utyerror = _FAL_MALOC_ER;
1399 fal_utyerrno = FAL_ERR_MALLOC ;
1402 tmp.path[i] = tmp_str;
1411 comp_default_path(p)
1416 if ( p->num != orgn.num ) {
1417 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
1418 fal_utyerrno = FAL_ERR_FPATH ;
1421 for ( i = 0; i < p->num; i++ ) {
1422 if( strcmp( p->path[i], orgn.path[i] ) ) {
1423 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
1424 fal_utyerrno = FAL_ERR_FPATH ;
1433 fal_clear_font_path( ls )
1438 if (ls->path != NULL) {
1439 /* free a fontpath character */
1440 for (i=0 ; i < ls->num ; i++) {
1441 if ((ls->path[i] != NULL) && (ls->path[i] == orgn.path[i])) {
1445 /* free a character pointer array */
1456 #define FAL_FONT_ELM_FILENAME 0
1457 #define FAL_FONT_ELM_SIZE_W 1
1458 #define FAL_FONT_ELM_SIZE_H 2
1459 #define FAL_FONT_ELM_LETTER_W 3
1460 #define FAL_FONT_ELM_LETTER_H 4
1461 #define FAL_FONT_ELM_LETTER_X 5
1462 #define FAL_FONT_ELM_LETTER_Y 6
1463 #define FAL_FONT_ELM_STYLE_NAME 7
1464 #define FAL_FONT_ELM_SHAPE_NAME 8
1466 #define FAL_FONT_ELM_CODE_SET 10
1467 #define FAL_FONT_ELM_PERMISSION 11
1468 #define FAL_FONT_ELM_XLFDNAME 12
1471 set_struct( tmp_data, elm )
1472 FalFontData *tmp_data;
1477 /* data information */
1479 /* a width of a character size */
1481 elm[FAL_FONT_ELM_SIZE_W], &(tmp_data->size.w )
1486 /* a height of a character size */
1488 elm[FAL_FONT_ELM_SIZE_H], &(tmp_data->size.h )
1493 /* a width of a letter size */
1495 elm[FAL_FONT_ELM_LETTER_W], &(tmp_data->letter.w )
1500 /* a height of a letter size */
1502 elm[FAL_FONT_ELM_LETTER_H], &(tmp_data->letter.h )
1507 /* position x of a letter size */
1509 elm[FAL_FONT_ELM_LETTER_X], &(tmp_data->letter.x )
1514 /* position y of a letter size */
1516 elm[FAL_FONT_ELM_LETTER_Y], &(tmp_data->letter.y )
1523 elm[FAL_FONT_ELM_CODE_SET], &(tmp_data->cd_set )
1528 /* a equipment of an output permission */
1530 elm[FAL_FONT_ELM_PERMISSION], &(tmp_data->prm )
1536 /* character information */
1539 if ( ( dup_p = (char *)strdup( elm[FAL_FONT_ELM_XLFDNAME] ) ) == NULL ) {
1540 fal_utyerrno = FAL_ERR_MALLOC ;
1543 tmp_data->xlfdname = dup_p;
1545 /* character style (character) */
1546 if ( ( dup_p = (char *)strdup( elm[FAL_FONT_ELM_STYLE_NAME] ) ) == NULL) {
1547 free( tmp_data->xlfdname );
1548 fal_utyerror = _FAL_MALOC_ER;
1549 fal_utyerrno = FAL_ERR_MALLOC ;
1552 tmp_data->style.name = dup_p;
1554 /* character style (numerical) */
1556 = fal_read_db( tmp_data->style.name, (FalFontDB *)&fal_db_style );
1558 /* character shape (character) */
1559 if ( ( dup_p = (char *)strdup( elm[FAL_FONT_ELM_SHAPE_NAME] ) ) == NULL ) {
1560 free( tmp_data->style.name );
1561 free( tmp_data->xlfdname );
1562 fal_utyerror = _FAL_MALOC_ER;
1563 fal_utyerrno = FAL_ERR_MALLOC ;
1566 tmp_data->shape.name = dup_p;
1568 /* character shape (numerical) */
1570 = fal_read_db( tmp_data->shape.name, (FalFontDB *)&fal_db_shape );
1572 SET_STRUCT_OPTION( dup_p, elm, tmp_data, fal_utyerror, fal_db_group ) ;
1576 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
1577 fal_utyerrno = FAL_ERR_FDATA_DSC ;
1581 /* get a full path name */
1582 int searchFontFileName( data, fullPathName )
1587 rtn = falReadFontInfoLists(SRCHFNAME,
1591 if( fal_utyerrno != 0 ){
1592 fal_utyerrno |= (FAL_FUNCNUM_SRCHFNM<<8) ;
1598 int fal_eq_data( data, tmp_data )
1600 FalFontData tmp_data;
1605 if ( strcmp( data.xlfdname, tmp_data.xlfdname ) != 0 ) {
1609 /* a width of a character size */
1610 if ( ( flg == 0 ) && ( data.size.h != tmp_data.size.h ) ) {
1614 /* a height of a character size */
1615 if ( ( flg == 0 ) && ( data.size.w != tmp_data.size.w ) ) {
1618 /* a height of a letter size */
1619 if ( ( flg == 0 ) && ( data.letter.h != tmp_data.letter.h ) ) {
1623 /* a width of a letter size */
1624 if ( ( flg == 0 ) && ( data.letter.w != tmp_data.letter.w ) ) {
1628 /* position x of a letter size */
1629 if ( ( flg == 0 ) && ( data.letter.x != tmp_data.letter.x ) ) {
1633 /* position y of a letter size */
1634 if ( ( flg == 0 ) && ( data.letter.y != tmp_data.letter.y ) ) {
1638 /* a definition data of a character style */
1639 if ( ( flg == 0 ) && ( data.style.def != tmp_data.style.def ) ) {
1643 /* character style */
1644 if ( (data.style.name != NULL) && (tmp_data.style.name != NULL) ) {
1645 if ( ( flg == 0 ) && ( strcmp( data.style.name, tmp_data.style.name ) != 0 ) ) {
1650 /* a definition data of a character shape */
1651 if ( ( flg == 0 ) && ( data.shape.def != tmp_data.shape.def ) ) {
1655 /* character shape */
1656 if ( (data.shape.name != NULL) && (tmp_data.shape.name != NULL) ) {
1657 if ( ( flg == 0 ) && ( strcmp( data.shape.name, tmp_data.shape.name ) != 0 ) ) {
1662 FAL_EQ_DATA_OPTION( flg, data, tmp_data ) ;
1665 if ( ( flg == 0 ) && ( data.cd_set != tmp_data.cd_set ) ) {
1669 /* an equipment of an output permission */
1670 if ( ( flg == 0 ) && ( data.prm != tmp_data.prm ) ) {
1676 } else if ( flg != 0 ) {
1677 return _FAL_TRY_NEXT;
1679 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
1680 fal_utyerrno = FAL_ERR_FDATA_DSC ;
1690 for( ; *buf != '\0'; buf++ ) {
1699 char *fal_get_base_name( str )
1704 str_slash = strrchr( str, '/');
1705 if ( str_slash == NULL ) {
1708 return( ++str_slash );
1713 fal_cmp_data( op1, key, mask )
1722 if ( key == NULL ) {
1727 ( mask & FAL_FONT_MASK_XLFDNAME )
1728 && strcmp( op1->xlfdname, key->xlfdname )
1730 return _FAL_TRY_NEXT;
1733 ( mask & FAL_FONT_MASK_SIZE_W )
1734 && (op1->size.w != key->size.w )
1736 return _FAL_TRY_NEXT;
1739 ( mask & FAL_FONT_MASK_SIZE_H )
1740 && (op1->size.h != key->size.h )
1742 return _FAL_TRY_NEXT;
1745 ( mask & FAL_FONT_MASK_LETTER_W )
1746 && ( op1->letter.w != key->letter.w )
1748 return _FAL_TRY_NEXT;
1751 ( mask & FAL_FONT_MASK_LETTER_H )
1752 && ( op1->letter.h != key->letter.h )
1754 return _FAL_TRY_NEXT;
1757 ( mask & FAL_FONT_MASK_LETTER_X )
1758 && ( op1->letter.x != key->letter.x )
1760 return _FAL_TRY_NEXT;
1763 ( mask & FAL_FONT_MASK_LETTER_Y )
1764 && ( op1->letter.y != key->letter.y )
1766 return _FAL_TRY_NEXT;
1769 ( mask & FAL_FONT_MASK_STYLE_DEF )
1770 && ( op1->style.def != key->style.def )
1772 return _FAL_TRY_NEXT;
1774 if( (op1->style.name != NULL) && (key->style.name != NULL) ) {
1776 ( mask & FAL_FONT_MASK_STYLE_NAME )
1777 && strcmp( op1->style.name, key->style.name )
1779 return _FAL_TRY_NEXT;
1783 ( mask & FAL_FONT_MASK_SHAPE_DEF )
1784 && ( op1->shape.def != key->shape.def )
1786 return _FAL_TRY_NEXT;
1788 if( (op1->shape.name != NULL) && (key->shape.name != NULL) ) {
1790 ( mask & FAL_FONT_MASK_SHAPE_NAME )
1791 && strcmp( op1->shape.name, key->shape.name )
1793 return _FAL_TRY_NEXT;
1796 FAL_CMP_DATA_OPTION( mask, op1, key ) ;
1798 ( mask & FAL_FONT_MASK_CODE_SET )
1799 && ( op1->cd_set != key->cd_set )
1801 return _FAL_TRY_NEXT;
1803 if ( mask & FAL_FONT_MASK_PERMISSION ) {
1805 cmp_prm = key->prm & (FAL_FONT_DISPLAY | FAL_FONT_PRINTER);
1806 if ( ( op1->prm & cmp_prm ) != cmp_prm ) {
1807 return _FAL_TRY_NEXT;
1815 /* return data ¡§ sort ... 1 */
1819 new_target( target, choose )
1820 FalFontData *target;
1821 FalFontData *choose;
1828 diff.style.def = choose->style.def - target->style.def;
1829 if( (choose->style.name != NULL) && (target->style.name != NULL) ) {
1830 str_chk.style = strcmp( choose->style.name, target->style.name ) ;
1833 NEW_TARGET_SET( diff, choose, target, str_chk ) ;
1835 diff.shape.def = choose->shape.def - target->shape.def;
1836 if( (choose->shape.name != NULL) && (target->shape.name != NULL) ) {
1837 str_chk.shape = strcmp( choose->shape.name, target->shape.name ) ;
1840 diff.cd_set = choose->cd_set - target->cd_set;
1841 diff.size.h = choose->size.h - target->size.h;
1842 diff.size.w = choose->size.w - target->size.w;
1843 diff.letter.h = choose->letter.h - target->letter.h;
1844 diff.letter.w = choose->letter.w - target->letter.w;
1847 if ( target->style.def == FAL_FONT_UNKNOWN ) {
1848 if ( choose->style.def > 0 ) {
1851 /* style is FAL_FONT_UNKNOWN both "target" and "choose" */
1852 if ( str_chk.style < 0 ) {
1855 if ( str_chk.style > 0) {
1858 } else if ( choose->style.def == FAL_FONT_UNKNOWN ) {
1861 /* target->style.def and choose->style.def is not FAL_FONT_UNKNOWN */
1862 if (diff.style.def < 0) {
1865 if ( diff.style.def > 0) {
1869 NEW_TARGET_CHK( diff, choose, target, str_chk ) ;
1871 /* character shape */
1872 if ( target->shape.def == FAL_FONT_UNKNOWN ) {
1873 if ( choose->shape.def > 0 ) {
1876 if ( str_chk.shape < 0 ) {
1879 if ( str_chk.shape > 0 ) {
1882 } else if (choose->shape.def == FAL_FONT_UNKNOWN ) {
1885 if ( diff.shape.def < 0 ) {
1888 if ( diff.shape.def > 0 ) {
1893 if ( diff.cd_set < 0 ) {
1896 if (diff.cd_set > 0) {
1900 /* character size height */
1901 if ( diff.size.h < 0 ) {
1904 if ( diff.size.h > 0 ) {
1908 /* letter size height */
1909 if ( diff.letter.h < 0 ) {
1912 if ( diff.letter.h > 0 ) {
1916 /* character size wide */
1917 if ( diff.size.w < 0 ) {
1920 if ( diff.size.w > 0 ) {
1924 /* letter size wide */
1925 if ( diff.letter.w < 0 ) {
1928 if ( diff.letter.w > 0 ) {
1935 #if NeedFunctionPrototypes
1936 int FalFontOfFontID(
1938 FalFontData *fontdata )
1940 int FalFontOfFontID( fid, fontdata )
1942 FalFontData *fontdata;
1946 rtn = falReadFontInfoLists(FONTOFID,
1950 if( fal_utyerrno != 0 ){
1951 fal_utyerrno |= (FAL_FUNCNUM_FID<<8) ;
1956 #if NeedFunctionPrototypes
1959 FalFontData *open_font_data,
1961 FalFontDataList **missing_font_list_return )
1964 FalOpenSysFont( open_font_data, font_data_mask, missing_font_list_return )
1965 FalFontData *open_font_data;
1967 FalFontDataList **missing_font_list_return;
1970 int retFL; /* return a data of FontList */
1971 FalFontID retOF; /* return a data of OpenFont */
1972 char fname[FAL_LINE_MAX];
1974 /* follow "font_data_mask" and call "FalGetFontList()" */
1975 retFL = FalGetFontList(
1976 open_font_data, font_data_mask, missing_font_list_return
1978 /* case of an abnormal end */
1980 *missing_font_list_return = NULL;
1984 if ( (*missing_font_list_return)->num > 1 ) {
1986 } else if ( (*missing_font_list_return)->num == 1 ) {
1987 /* investigator an font file name */
1988 int slct_cdset, prm, islock, dspcode ;
1991 (*missing_font_list_return)->list[0], fname
1994 FalFreeFontList( *missing_font_list_return );
1995 fal_utyerrno &= 0xff ;
1996 fal_utyerrno |= (FAL_FUNCNUM_SRCHFNM<<8) ;
1997 *missing_font_list_return = NULL;
2000 /* open a font by "__FalOpenFont()" */
2001 slct_cdset = (*missing_font_list_return)->list[0].cd_set ;
2002 dspcode = ( font_data_mask & FAL_FONT_MASK_GLYPH_INDEX )?
2003 FAL_FONT_GLYPH_INDEX : slct_cdset ;
2004 prm = ((*missing_font_list_return)->list[0].prm ) ?
2005 (*missing_font_list_return)->list[0].prm :
2006 FAL_FONT_DISPLAY | FAL_FONT_PRINTER ;
2007 islock = (( font_data_mask & FAL_FONT_MASK_UPDATE )? 1 : 0 );
2008 retOF = __FalOpenFont( fname, prm, dspcode, islock );
2010 if ( retOF == (FalFontID)FAL_ERROR ) {
2012 FalFreeFontList( *missing_font_list_return );
2013 fal_utyerrno &= 0xff ;
2014 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
2015 *missing_font_list_return = NULL;
2018 /* normal end ( return retOF ) */
2019 *missing_font_list_return = NULL;
2020 FalFreeFontList( *missing_font_list_return );
2021 if( fal_add_fidinf( retOF,
2022 dspcode, slct_cdset, islock ) == FAL_ERROR ){
2023 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
2028 } else if ( (*missing_font_list_return)->num == 0 ) {
2030 * set NULL in "missing_font_list_return"
2032 FalFreeFontList( *missing_font_list_return );
2033 *missing_font_list_return = NULL;
2037 *missing_font_list_return = NULL;
2038 fal_utyerrno = FAL_ERR_FATAL ;
2039 fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ;
2045 /********************************************************
2046 * function to access fonts.list
2047 ********************************************************/
2049 FILE *open_fonts_list()
2053 char *locale = NULL ;
2054 char *fal_search_path = NULL ;
2055 char flist_d[FAL_LINE_MAX] ;
2056 char flist_c[FAL_LINE_MAX] ;
2057 char flist_l[FAL_LINE_MAX] ;
2059 GETLISTFILEPATH( locale, fal_search_path, flist_d, flist_c, flist_l, FONTS_LIST_FILE ) ;
2061 if ( ( fp = fopen( flist_l, "r" ) ) == NULL ) {
2062 if( (fp = fopen( flist_c, "r" )) == NULL ) {
2063 if( (fp = fopen( flist_d, "r" )) == NULL ) {
2064 set_errfile_str( fal_err_file, flist_d ) ;
2065 set_errfile_str( fal_err_file_buf, flist_d ) ;
2066 fal_utyerror = _FAL_DATA_OPEN_ER;
2067 fal_utyderror = errno;
2068 fal_utyerrno = FAL_ERR_FDATA_OPN ;
2070 /* Save full path of fonts.list. */
2071 set_errfile_str( fal_err_file_buf, flist_d ) ;
2072 if( IsDefaultPath == TRUE ) IsDefaultPath = FALSE ;
2075 /* Save full path of fonts.list. */
2076 set_errfile_str( fal_err_file_buf, flist_c ) ;
2077 if( IsDefaultPath == TRUE ) IsDefaultPath = FALSE ;
2080 /* Save full path of fonts.list. */
2081 set_errfile_str( fal_err_file_buf, flist_l ) ;
2082 if( IsDefaultPath == TRUE ) IsDefaultPath = FALSE ;
2091 * functions to read "fonts.dir" files
2094 /***************************************************************/
2095 /* read a font information and add a list or make a list */
2096 /***************************************************************/
2100 set_font_pathlist(pathlist, nodef)
2101 FalFontPath *pathlist ;
2105 char buf[FAL_LINE_MAX];
2106 char *font_path = NULL ;
2111 /* open a font directory information file */
2112 if ((fp = open_fonts_list()) == NULL) {
2113 /* Make default path list */
2114 if( errno == ENOENT || errno == EACCES || errno == EISDIR ){
2115 if ( make_default_path(pathlist) ) {
2122 memset( buf, '\0', sizeof(buf) ) ;
2124 while ( fgets( buf, FAL_LINE_MAX, fp ) != (char *)NULL ){
2125 struct stat statbuf ;
2130 if( buf[0] == '#' ){ /* comments */
2132 }else if( buf[0] == '/' ){ /* font path */
2134 /* add font_path to pathlist */
2136 num = pathlist->num;
2137 if (pathlist->path == NULL) {
2138 tmp_list = (char **)malloc(sizeof(char *)*(num +1));
2140 tmp_list = (char **)realloc(pathlist->path, sizeof(char *)*(num+1));
2142 if (tmp_list == NULL) {
2145 fal_clear_font_path( pathlist );
2146 fal_utyerror = _FAL_MALOC_ER;
2147 fal_utyerrno = FAL_ERR_MALLOC ;
2150 pathlist->path = tmp_list;
2151 pathlist->path[num] = font_path;
2156 if ((font_path = (char *)strdup(buf)) == NULL) {
2158 fal_clear_font_path( pathlist );
2159 fal_utyerror = _FAL_MALOC_ER;
2160 fal_utyerrno = FAL_ERR_MALLOC ;
2163 ep = font_path + strlen( font_path ) - 1 ;
2164 *ep = '/'; /* ':' -> '/' */
2165 if( *(ep-1) == '/' ) *ep = '\0';
2167 if( stat( font_path, &statbuf ) ) {
2172 if( !(statbuf.st_mode & S_IFDIR) ) {
2178 }else{ /* font file */
2189 /* add font_path to pathlist */
2191 num = pathlist->num;
2192 if (pathlist->path == NULL) {
2193 tmp_list = (char **)malloc(sizeof(char *)*(num +1));
2195 tmp_list = (char **)realloc(pathlist->path, sizeof(char *)*(num+1));
2197 if (tmp_list == NULL) {
2200 fal_clear_font_path( pathlist );
2201 fal_utyerror = _FAL_MALOC_ER;
2202 fal_utyerrno = FAL_ERR_MALLOC ;
2205 pathlist->path = tmp_list;
2206 pathlist->path[num] = font_path;
2210 if ( feof(fp) != 0 ){
2215 fal_clear_font_path( pathlist );
2216 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
2217 fal_utyerror = _FAL_READ_PATH_ER;
2218 fal_utyerrno = FAL_ERR_FPATH ;
2225 make_default_path(pathlist)
2226 FalFontPath *pathlist ;
2228 struct stat statbuf ;
2229 char pbuf[FAL_LINE_MAX], *dir, *p ;
2230 char *path, **plist ;
2234 memset( pbuf, '\0', sizeof(pbuf) ) ;
2237 if( (dir = getenv( "DTUDCFONTPATH" )) != NULL ) {
2238 len = strlen( dir ) ;
2243 strcpy( p, DTUDCFONTPATH ) ;
2247 while ( (ep = strchr( sp, ':' )) != (char *)NULL ){
2251 if ((path = (char *)malloc(sizeof(char) * (strlen(sp)+2))) == NULL) {
2252 fal_clear_font_path( pathlist );
2253 fal_utyerror = _FAL_MALOC_ER;
2254 fal_utyerrno = FAL_ERR_MALLOC ;
2257 strcpy( path, sp ) ;
2258 len = strlen( sp ) ;
2261 if( path[len-2] == '/' ) path[len-1] = '\0';
2263 if( stat(path, &statbuf) ) {
2268 if( !(statbuf.st_mode & S_IFDIR) ) {
2274 /* add path to pathlist */
2275 num = pathlist->num;
2276 if (pathlist->path == NULL) {
2277 plist = (char **)malloc(sizeof(char *)*(num +1));
2279 plist = (char **)realloc(pathlist->path, sizeof(char *)*(num+1));
2281 if (plist == NULL) {
2282 fal_clear_font_path( pathlist );
2283 fal_utyerror = _FAL_MALOC_ER;
2284 fal_utyerrno = FAL_ERR_MALLOC ;
2288 pathlist->path = plist;
2289 pathlist->path[num] = path;
2293 if( execDefined == TRUE ) execDefined = FALSE ;
2294 if( IsDefaultPath == FALSE ) IsDefaultPath = TRUE ;
2305 falReadFontInfoLists(func, lstkey, mask, fls, fnkey, fullpath, fid, fdata)
2307 /* parameters for FalGetFontList */
2308 FalFontData *lstkey;
2310 FalFontDataList *fls;
2311 /* parameters for searchFontFileName */
2314 /* parameters for FalFontOfFontID */
2319 char pname[ FAL_LINE_MAX ] ;
2322 FalFontData tmp_data;
2323 FontIDInfo fontid_inf;
2324 char *elm[FAL_DATA_ELM * 3];
2325 char buf[FAL_LINE_MAX * 3];
2327 struct stat statbuf ;
2328 char *keyfname, *fontFileName, *fonts_list_file ;
2331 int codeset_num, *codeset_list ;
2333 keyfname = fontFileName = fonts_list_file = NULL ;
2335 codeset_list = NULL ;
2336 if( func & FONTOFID ){
2337 finf = (Oak_FontInf *)fid ;
2338 keyfname = finf->fname ;
2341 /* get current locale */
2342 if( fal_init() ) return FAL_ERROR ;
2344 /* get font path list */
2345 if( wpath.path==NULL ) {
2346 if( set_font_pathlist( &wpath, 1 ) ) {
2351 * If execDefined is true, this function read detail informations
2352 * of the fonts descripted in fonts.list.
2354 if( execDefined == TRUE && IsDefaultPath == FALSE ) {
2355 /* open an information file */
2356 if ((fp = open_fonts_list()) == NULL) {
2359 memset( pname, 0, sizeof( pname ) );
2361 while ( fgets( buf, FAL_LINE_MAX, fp ) != ( char * ) NULL ) {
2365 memset( elm, 0, sizeof( elm ) );
2366 memset( &tmp_data, 0, sizeof( tmp_data ) );
2370 * get font information of a font
2372 switch( fal_get_def_fontdata(func, pname, buf, elm, &tmp_data, keyfname ) ) {
2374 if( buf[0] == '/' ) {
2375 buf[strlen( buf ) -1] = '/' ;
2376 strcpy( pname, buf ) ;
2387 case MKFONTLIST : /* FalGetFontList */
2388 switch( falgetfontlist(&tmp_data, lstkey, mask, fls, 1) ){
2389 case _FAL_TRY_NEXT :
2398 case SRCHFNAME : /* searchFontFileName */
2399 eq = fal_eq_data( fnkey, tmp_data ) ;
2402 sprintf( fullpath, "%s%s", pname, elm[ FAL_FONT_ELM_FILENAME ] );
2403 fal_clear_data( &tmp_data ) ;
2406 case _FAL_TRY_NEXT :
2407 fal_clear_data( &tmp_data ) ;
2409 default : /* FAL_ERROR */
2413 case FONTOFID : /* FalFontOfFontID */
2414 memmove( fdata, &tmp_data, sizeof(FalFontData) ) ;
2418 fal_utyerrno = FAL_ERR_PARM ;
2422 } /* end of while loop */
2424 if ( feof( fp ) != 0 ) {
2427 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
2428 fal_utyerror = _FAL_DATA_READ_ER;
2429 fal_utyerrno = FAL_ERR_FDATA_RD ;
2434 if( (func & SRCHFNAME) && (execUndefined == FALSE) ){
2435 fal_utyerrno = FAL_ERR_NOFONT ;
2442 * If execUnefined is true, this function read list of font path,
2443 * and get the name of font file from fonts.dir.
2445 if( execUndefined == TRUE ) {
2450 for( i=0; i<wpath.num; i++ ) {
2451 FalFontData *p_bak ;
2453 fonts_list_file = (char *)malloc( sizeof(char) * ( strlen(wpath.path[i]) + strlen(FONTSDIR) + 1 ) ) ;
2454 if( fonts_list_file == (char *)NULL ) {
2455 fal_utyerror = _FAL_MALOC_ER;
2456 fal_utyerrno = FAL_ERR_MALLOC ;
2459 sprintf( fonts_list_file, "%s%s", wpath.path[i], FONTSDIR ) ;
2461 if( stat( fonts_list_file, &statbuf ) ) {
2462 FreeString( fonts_list_file ) ;
2465 if( !(statbuf.st_mode & S_IFREG) ) {
2466 FreeString( fonts_list_file ) ;
2470 /* open "fonts.dir" */
2471 if ((fp = fopen( fonts_list_file, "r" )) == NULL) {
2472 if( errno == EACCES ) {
2473 FreeString( fonts_list_file ) ;
2476 set_errfile_str( fal_err_file, fonts_list_file ) ;
2477 FreeString( fonts_list_file ) ;
2478 fal_utyerror = _FAL_OPEN_ER;
2479 fal_utyderror = errno ;
2480 fal_utyerrno = FAL_ERR_FNTDIR_OPN ;
2484 /* Save full path of fonts.dir */
2485 set_errfile_str( fal_err_file_buf, fonts_list_file ) ;
2486 FreeString( fonts_list_file ) ;
2488 /* Get number of fonts in current path */
2489 if( fgets( buf, FAL_LINE_MAX, fp ) == (char *)NULL ) {
2490 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
2491 fal_utyerror = _FAL_DATA_READ_ER;
2492 fal_utyerrno = FAL_ERR_FNTDIR_RD ;
2496 fontnum = atoi( buf );
2498 /* Get list of font informations */
2499 if( func & MKFONTLIST){
2500 if ( fls->list == NULL ) {
2501 p_bak = (FalFontData *)malloc(sizeof(FalFontData) * (fls->num + fontnum));
2503 p_bak = (FalFontData *)realloc(fls->list, sizeof(FalFontData)*(fls->num + fontnum));
2505 if ( p_bak == NULL ) {
2506 fal_utyerror = _FAL_MALOC_ER;
2507 fal_utyerrno = FAL_ERR_MALLOC ;
2513 memset( buf, 0, sizeof(buf));
2515 while( fgets( buf, FAL_LINE_MAX, fp ) != (char *)NULL ) {
2519 /* set FalFontData */
2520 CR_to_NULL(buf); /* '\n' -> '\0' */
2521 memset( &tmp_data, 0, sizeof(FalFontData));
2523 /* parse string of font file */
2524 if( (ep = strchr( buf, ' ' )) == (char *)NULL ) continue ;
2526 /* refuse font file (not gpf) */
2528 ( strcmp( FILE_SUFFIX(buf), PCFSUFFIX ) != 0 ) &&
2529 ( strcmp( FILE_SUFFIX(buf), SNFSUFFIX ) != 0 ) &&
2530 ( ISOPTFONT(buf) != 0 )
2535 /* get string of font file */
2536 if( (func & SRCHFNAME) || (func & FONTOFID) ){
2537 fontFileName = (char *)malloc( sizeof(char) * ( strlen(wpath.path[i]) + strlen(buf) + 1 ) ) ;
2538 if( fontFileName == (char *)NULL ) {
2539 fal_utyerror = _FAL_MALOC_ER;
2540 fal_utyerrno = FAL_ERR_MALLOC ;
2543 sprintf( fontFileName, "%s%s", wpath.path[i], buf ) ;
2546 /* read font file and get properties */
2548 switch( fal_get_undef_fontdata(func, fontFileName, xlfd, &tmp_data, keyfname, &codeset_num, &codeset_list) )
2550 case _FAL_TRY_NEXT :
2551 if( (func & SRCHFNAME) || (func & FONTOFID) ) FreeString( fontFileName ) ;
2552 fal_clear_data( &tmp_data );
2553 memset( buf, 0, sizeof(buf));
2556 if( (func & FONTOFID) ) FreeString( fontFileName ) ;
2560 if( (func & SRCHFNAME) || (func & FONTOFID) ) FreeString( fontFileName ) ;
2564 if( !(func & FONTOFID) && (codeset_num == 0) ){
2565 if( (func & SRCHFNAME) ) FreeString( fontFileName ) ;
2566 fal_clear_data( &tmp_data );
2567 memset( buf, 0, sizeof(buf));
2572 case MKFONTLIST : /* FalGetFontList */
2573 tmp_num = fls->num ;
2574 case SRCHFNAME : /* searchFontFileName */
2576 for( j=0; j<codeset_num; j++ ) {
2577 tmp_data.cd_set = FALGETFALCODESET( codeset_list[j] ) ;
2579 if( func & MKFONTLIST ){ /* FalGetFontList */
2580 /* Ignore fonts already exists. */
2581 if ( fal_check_already_exist(&tmp_data, fls) >= 0 ) {
2585 switch( falgetfontlist(&tmp_data, lstkey, mask, fls, 1) ){
2586 case _FAL_TRY_NEXT :
2595 if( func & SRCHFNAME ){ /* searchFontFileName */
2596 eq = fal_eq_data( fnkey, tmp_data ) ;
2599 strcpy( fullpath, fontFileName );
2600 fal_clear_data( &tmp_data ) ;
2601 FreeString( fontFileName ) ;
2602 tmp_codeset = tmp_data.cd_set ;
2604 /* clear code set informations */
2605 clear_charset_info() ;
2607 case _FAL_TRY_NEXT :
2609 default : /* FAL_ERROR */
2610 FreeString( fontFileName ) ;
2615 if( func & MKFONTLIST ){ /* FalGetFontList */
2616 if( fls->num == tmp_num ) fal_clear_data( &tmp_data ) ;
2618 if( func & SRCHFNAME ){ /* searchFontFileName */
2619 fal_clear_data( &tmp_data ) ;
2620 FreeString( fontFileName ) ; /* _FAL_TRY_NEXT */
2624 case FONTOFID : /* FalFontOfFontID */
2625 memmove( fdata, &tmp_data, sizeof(FalFontData) ) ;
2626 if( fal_read_fidinf( fid, &fontid_inf ) != FAL_ERROR )
2627 fdata->cd_set = fontid_inf.cd_set ;
2639 memset(buf, 0, sizeof(buf));
2642 if ( feof(fp) != 0 ) {
2645 set_errfile_str( fal_err_file, fal_err_file_buf ) ;
2646 fal_utyerror = _FAL_DATA_READ_ER;
2647 fal_utyerrno = FAL_ERR_FNTDIR_RD ;
2654 /* clear code set informations */
2655 clear_charset_info() ;
2657 if( (func & SRCHFNAME) || (func & FONTOFID) ){
2658 fal_utyerrno = FAL_ERR_NOFONT ;
2662 } /* execUndefined */
2668 clear_charset_info() ;
2669 fal_clear_data( &tmp_data ) ;
2676 /* clear code set informations */
2678 clear_charset_info()
2680 if( charset_str_buf ) free( charset_str_buf ) ;
2681 charset_str_buf = NULL ;
2682 if( codeset_list_sav ) free( codeset_list_sav ) ;
2683 codeset_list_sav = NULL ;
2684 codeset_list_num = 0 ;
2689 fal_get_def_fontdata(func, pname, buf, elm, tmp_data, key_fname)
2691 char *pname ; /* font path */
2692 char *buf ; /* buffer for fgets() */
2694 FalFontData *tmp_data ;
2698 char tmp_fname[FAL_LINE_MAX] ;
2700 if( (rtn = fal_split_data( buf, FAL_DATA_ELM, elm )) ) {
2704 if( func & FONTOFID ){
2705 sprintf( tmp_fname, "%s%s", pname, elm[ FAL_FONT_ELM_FILENAME ] );
2706 if( strcmp( tmp_fname, key_fname ) ) return _FAL_TRY_NEXT ;
2709 /* set informations to structrue */
2710 if ( set_struct( tmp_data, elm ) == FAL_ERROR ) {
2719 falgetfontlist(tmp_data, key, mask, fls, fontnum)
2720 FalFontData *tmp_data ;
2723 FalFontDataList *fls ;
2726 FalFontData *p_bak ;
2729 return _FAL_TRY_NEXT ;
2732 /* compare with key data */
2733 if ( fal_cmp_data(tmp_data, key, mask) == _FAL_TRY_NEXT ) {
2734 return _FAL_TRY_NEXT ;
2737 if ( fls->list == NULL ) {
2738 p_bak = malloc(sizeof(FalFontData) * (fls->num + fontnum));
2740 p_bak = realloc(fls->list, sizeof(FalFontData)*(fls->num + fontnum));
2742 if ( p_bak == NULL ) {
2743 fal_utyerror = _FAL_MALOC_ER;
2744 fal_utyerrno = FAL_ERR_MALLOC ;
2748 memmove(&(fls->list[fls->num]), tmp_data, sizeof(FalFontData));
2749 fls->num++; /* update number of fonts */
2757 fal_get_undef_fontdata(func, full_path, xlfd, tmp_data, key_fname, codeset_num, codeset_list)
2761 FalFontData *tmp_data ;
2764 int **codeset_list ;
2768 char xlfdname[ FAL_LINE_MAX ], *family, *pixsize ;
2771 /* FalFontOfFontID() */
2772 if( func & FONTOFID ){
2773 if( strcmp( full_path, key_fname ) ) return _FAL_TRY_NEXT ;
2777 * parse XLFD and get font informations
2779 cbuf = ep = family = pixsize = NULL ;
2781 strcpy( xlfdname, xlfd ) ;
2783 GETXLFDELMSTR( pixsize, xlfd, XLFD_ELM_PIXEL_SIZE ) ;
2784 ep = (char *)strchr( pixsize, '\0' ) ;
2785 pix = (int)strtol( pixsize, &cbuf, 10 ) ;
2786 if( cbuf == pixsize || cbuf != ep ){
2787 return _FAL_TRY_NEXT ;
2790 GETXLFDELMSTR( family, xlfd, XLFD_ELM_FAMILY_NAME ) ;
2793 if( (tmp_data->style.name = (char *)strdup( family )) == NULL ) {
2794 fal_utyerror = _FAL_MALOC_ER ;
2795 fal_utyerrno = FAL_ERR_MALLOC ;
2798 if( (tmp_data->xlfdname = (char *)strdup( xlfdname )) == NULL ) {
2799 fal_utyerror = _FAL_MALOC_ER ;
2800 fal_utyerrno = FAL_ERR_MALLOC ;
2803 tmp_data->size.h = pix ;
2804 tmp_data->size.w = -1 ;
2806 /* FalGetFontList() and searchFontFilename() */
2807 if( (func & MKFONTLIST) || (func & SRCHFNAME) ){
2808 GETCHARSETSTR( char_set, tmp_data->xlfdname ) ;
2809 /* code set infomations exist */
2810 if( charset_str_buf && !strcmp( charset_str_buf, char_set ) ) {
2811 *codeset_num = codeset_list_num ;
2812 *codeset_list = codeset_list_sav ;
2814 /* clear code set infomations */
2815 clear_charset_info() ;
2816 /* get code set infomations */
2817 if( (rtn = fal_get_codeset( fal_locale, char_set, codeset_list, codeset_num )) ){
2820 /* save code set infomations */
2821 if( (charset_str_buf = (char *)strdup( char_set )) == NULL ) {
2822 fal_utyerror = _FAL_MALOC_ER ;
2823 fal_utyerrno = FAL_ERR_MALLOC ;
2826 codeset_list_num = *codeset_num ;
2827 codeset_list_sav = *codeset_list ;
2836 * get file name of fonts
2839 #if NeedFunctionPrototypes
2841 FalFontIDToFileName(
2846 FalFontIDToFileName( fid, file_name )
2854 fal_utyerror = _FAL_PARM_ER ;
2855 fal_utyderror = _FAL_R_P_FINF_DER ;
2856 fal_utyerrno = FAL_ERR_PARM ;
2857 fal_utyerrno |= (FAL_FUNCNUM_IDTOFNM<<8) ;
2860 if( file_name == NULL ) {
2861 fal_utyerror = _FAL_PARM_ER ;
2862 fal_utyderror = _FAL_R_P_W_DER ;
2863 fal_utyerrno = FAL_ERR_PARM ;
2864 fal_utyerrno |= (FAL_FUNCNUM_IDTOFNM<<8) ;
2867 finf = (Oak_FontInf *)fid ;
2868 if( (fname = (char *)strdup( finf->fname )) == NULL ) {
2869 fal_utyerror = _FAL_MALOC_ER ;
2870 fal_utyerrno = FAL_ERR_MALLOC ;
2871 fal_utyerrno |= (FAL_FUNCNUM_IDTOFNM<<8) ;
2874 *file_name = fname ;
2879 #if NeedFunctionPrototypes
2889 if( list == NULL ) {
2890 fal_utyerror = _FAL_PARM_ER ;
2891 fal_utyerrno = FAL_ERR_PARM ;
2892 fal_utyerrno |= (FAL_FUNCNUM_FREE<<8) ;
2902 FalFreeGI( ginf, num )
2907 if( ginf == NULL ) {
2908 fal_utyerror = _FAL_PARM_ER ;
2909 fal_utyerrno = FAL_ERR_PARM ;
2912 for( i=0; i<num; i++ ) {
2913 if( ginf[i].charset_str != NULL )
2914 free( ginf[i].charset_str ) ;
2922 * This functions manage the relation of FontID
2923 * between code set number.
2927 fal_add_fidinf( fid, dspcode, cd_set, islock )
2934 FontIDInfo **flist ;
2936 fal_utyerror = _FAL_PARM_ER ;
2937 fal_utyerrno = FAL_ERR_PARM ;
2941 for( i=0; i<mngfid.num; i++ ) {
2942 if( fid == mngfid.finf[i]->fid ) {
2944 mngfid.finf[i]->dspcode = dspcode ;
2945 mngfid.finf[i]->cd_set = cd_set ;
2946 mngfid.finf[i]->islock = islock ;
2952 if( mngfid.finf == NULL ) {
2954 if( (flist = (FontIDInfo **)malloc( sizeof(FontIDInfo *) )) == NULL ) {
2955 fal_utyerror = _FAL_MALOC_ER ;
2956 fal_utyerrno = FAL_ERR_MALLOC ;
2961 if( (flist = (FontIDInfo **)realloc(
2962 mngfid.finf, sizeof(FontIDInfo *) * (cnt + 1) )) == NULL )
2964 fal_utyerror = _FAL_MALOC_ER ;
2965 fal_utyerrno = FAL_ERR_MALLOC ;
2969 if( (flist[cnt] = (FontIDInfo *)malloc( sizeof(FontIDInfo) )) == NULL ) {
2970 fal_utyerror = _FAL_MALOC_ER ;
2971 fal_utyerrno = FAL_ERR_MALLOC ;
2975 flist[cnt]->fid = fid ;
2976 flist[cnt]->cd_set = cd_set ;
2977 flist[cnt]->dspcode = dspcode ;
2978 flist[cnt]->islock = islock ;
2980 mngfid.num = cnt + 1 ;
2981 mngfid.finf = flist ;
2988 fal_read_fidinf( fid, fontid_inf )
2990 FontIDInfo *fontid_inf;
2994 fal_utyerror = _FAL_PARM_ER ;
2995 fal_utyerrno = FAL_ERR_PARM ;
2998 for( i=0; i<mngfid.num; i++ ) {
2999 if( mngfid.finf[i]->fid == fid ) {
3000 fontid_inf->fid = fid ;
3001 fontid_inf->cd_set = mngfid.finf[i]->cd_set ;
3002 fontid_inf->dspcode = mngfid.finf[i]->dspcode ;
3003 fontid_inf->islock = mngfid.finf[i]->islock ;
3007 fal_utyerror = _FAL_PARM_ER ;
3008 fal_utyerrno = FAL_ERR_FID_RD ;
3014 fal_del_fidinf( fid )
3017 int i, cnt, target ;
3018 FontIDInfo **flist ;
3020 for( i=0; i<mngfid.num; i++ ) {
3021 if( mngfid.finf[i]->fid == fid ) {
3026 cnt = mngfid.num - 1 ;
3027 free( mngfid.finf[target] ) ;
3028 for( i=target; i<mngfid.num; i++ ) {
3029 mngfid.finf[i] = mngfid.finf[i+1] ;
3032 if( (flist = (FontIDInfo **)realloc(
3033 mngfid.finf, sizeof(FontIDInfo *) * cnt )) == NULL )
3035 fal_utyerror = _FAL_MALOC_ER ;
3036 fal_utyerrno = FAL_ERR_MALLOC ;
3040 mngfid.finf = flist ;
3042 free( mngfid.finf ) ;
3044 mngfid.finf = NULL ;
3050 * convert codepoint into glyph index
3054 fal_conv_code_to_glyph( fid, code, glidx )
3057 unsigned int *glidx ;
3060 FalFontData tmp_data ;
3062 FontIDInfo fontid_inf ;
3065 int inner_code = 0 ;
3067 static FalFontID cmpfid = 0 ;
3068 static char charset_name[FAL_LINE_MAX] ;
3070 finf = (Oak_FontInf *)fid ;
3072 * get code set number
3074 if( fal_read_fidinf( fid, &fontid_inf ) == FAL_ERROR ) {
3078 if( fontid_inf.dspcode != FAL_FONT_GLYPH_INDEX ){
3080 * get string of "CHARSET_REGISTRY"
3082 memset( &tmp_data, 0, sizeof(FalFontData) ) ;
3084 if( cmpfid != fid ){
3085 if( falReadGpfProp( FAL_READ_FONTINFO, finf, FAL_FONT_PRM, &tmp_data ) ) {
3086 fal_clear_data( &tmp_data ) ;
3089 GETCHARSETSTR( char_set, tmp_data.xlfdname ) ;
3090 snprintf( charset_name, sizeof(charset_name), "%s", char_set ) ;
3094 * convert codepoint into glyph index
3096 if( COMM_SBFNT_ISSBFNT( charset_name ) ) {
3098 FAL_OPT_CONVCPTOGI( fontid_inf.dspcode, inner_code ) ;
3100 if( fal_code_to_glyph( fal_locale, code, &gi, &gnum ) ) {
3101 fal_clear_data( &tmp_data ) ;
3105 inner_code = gi[0].glyph_index ;
3107 for( i=0; i<gnum; i++ ) {
3108 if( !strcmp( gi[i].charset_str, char_set ) ) {
3109 inner_code = gi[i].glyph_index ;
3114 FalFreeGI( gi, gnum ) ;
3116 fal_clear_data( &tmp_data ) ;
3118 inner_code = code; /* glyph index */
3120 *glidx = inner_code ;
3127 * convert codepoint into glyph index
3131 fal_conv_glyph_to_code( finf, dspcode, cd_set, glidx, code )
3135 unsigned int glidx ;
3136 unsigned int *code ;
3138 FalFontData tmp_data ;
3143 * get code set number
3145 if( dspcode != FAL_FONT_GLYPH_INDEX ){
3147 * get string of "CHARSET_REGISTRY"
3149 memset( &tmp_data, 0, sizeof(tmp_data) ) ;
3150 if( falReadGpfProp( FAL_READ_FONTINFO, finf, FAL_FONT_PRM, &tmp_data ) ) {
3151 fal_clear_data( &tmp_data ) ;
3154 GETCHARSETSTR( char_set, tmp_data.xlfdname ) ;
3157 * convert glyph index into codepoint
3159 if( COMM_SBFNT_ISSBFNT( char_set ) ) {
3160 inner_code = glidx ;
3161 FAL_OPT_CONVGITOCP( dspcode, inner_code ) ;
3163 if( fal_glyph_to_code( fal_locale, char_set, cd_set, glidx, &inner_code ) ) {
3164 fal_clear_data( &tmp_data ) ;
3168 fal_clear_data( &tmp_data ) ;
3170 inner_code = glidx ; /* glyph index */
3172 *code = inner_code ;
3180 int fd; /* a file descripter */
3184 flpar.l_type = F_RDLCK;
3189 if ( fcntl( fd, F_SETLK, &flpar ) == -1 ) {
3190 fal_utyerrno = FAL_ERR_FILELCK ;
3199 int fd; /* a file descripter */
3203 flpar.l_type = F_UNLCK;
3208 if ( fcntl( fd, F_SETLK, &flpar ) == -1 ){
3209 fal_utyerrno = FAL_ERR_FILEUNLCK ;
3217 int fd; /* file descripter */
3221 flpar.l_type = F_WRLCK;
3226 if ( fcntl( fd, F_GETLK, &flpar ) == -1 ) {
3227 fal_utyerrno = FAL_ERR_FILEGETLCK ;
3231 if ( flpar.l_type == F_UNLCK ){
3234 fal_utyerrno = FAL_ERR_LCKD ;
3239 /********************< end of falfont.c >*********************************/