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: cpgpf.c /main/6 1996/11/08 02:03:36 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
36 #include <sys/types.h>
40 #include <sys/resource.h>
54 #include <X11/Xproto.h>
55 #include "fontstruct.h"
58 #include "snfstruct.h"
68 #define RESIZE_BY_RATE( a, r ) ((int)( (float)(a) * (r)))
69 #define DEF_RESOLUTION ((78 / 72.27) * 100)
71 static void put_error_and_exit();
72 static void put_help();
73 static void sigint_out() ;
74 static void getDefaultCh() ;
75 static void MkFontProp() ;
77 static int CpyGpfInit() ;
78 static int writeGpf() ;
79 static int check_width() ;
80 static int check_height() ;
81 static int check_width_height() ;
82 static int getGpfFileName() ;
83 static int readGpf() ;
84 static int readBdfHeaderAndPut() ;
85 static int check_code() ;
86 static int readBdfToMemory() ;
87 static int cpg_atoi() ;
88 static int is_in_udcregion() ;
90 extern int fal_code_to_glyph() ;
92 static struct ptobhead WriteGpf;
94 static char *targ_file = NULL; /* UDC_file_name */
95 static char *com = NULL; /* command_name */
96 static char create_font[BUFSIZE] ;
97 static int new_target = 0 ;
98 static unsigned int firstCol, lastCol, firstRow, lastRow ;
100 static char *spacing ;
101 static char *char_set ;
102 static char *xlfdname ;
108 if (WriteGpf.out_file) {
109 Unlink_Tmpfile( WriteGpf.out_file, com );
119 int code_area , help, no_infile, no_style, type ;
120 int rtn, i, exit_code ;
124 struct btophead InputGpf; /* input file */
125 struct btophead OutputGpf; /* output file */
127 char isnf_file[BUFSIZE] ;
128 char osnf_file[BUFSIZE] ;
129 char readbuf[BUFSIZE];
130 char *istyle, *ostyle ;
131 char *ixlfdname, *oxlfdname ;
135 char *start_code, *end_code ;
136 int startcode, endcode ;
139 char *codeset = DEFAULT_CODESET;
142 * initiation of parameters
145 *create_font = '\0' ;
146 if( (locale = (char *)getenv( "LANG" )) == NULL ){
150 memset( &InputGpf, 0, sizeof(struct btophead) ) ;
151 memset( &OutputGpf, 0, sizeof(struct btophead) ) ;
152 memset( &WriteGpf, 0, sizeof(struct ptobhead) ) ;
154 COMM_SETDEFAULTSTYLE( istyle ) ;
155 COMM_SETDEFAULTSTYLE( ostyle ) ;
157 InputGpf.in_file = OutputGpf.in_file = WriteGpf.out_file = NULL;
158 ixlfdname = oxlfdname = '\0' ;
159 spacing = char_set = xlfdname = NULL ;
163 firstCol = firstRow = 0xff ;
164 lastCol = lastRow = 0 ;
166 start_code = end_code = '\0' ;
167 startcode = MIN_CODE ;
170 /* get full path of font compilers */
171 if (!( bdftopcf = get_cmd_path( getenv( "PATH" ), BDFTOPCF_CMD ))) {
174 if (!( oakgtobdf = get_cmd_path( getenv( "PATH" ), SNFTOBDF_CMD ))) {
175 oakgtobdf = SNFTOBDF;
177 if (!( bdftosnf = get_cmd_path( getenv( "PATH" ), BDFTOSNF_CMD ))) {
180 /*****************************************************************
182 *****************************************************************/
184 help = no_infile = no_style = type = 0;
186 for ( i = 1; i < argc; i++ ) {
187 if ( *argv[i] != '-' ) {
188 if( !InputGpf.in_file ){
189 InputGpf.in_file = argv[i] ;
190 }else if( !OutputGpf.in_file ){
191 OutputGpf.in_file = argv[i] ;
196 }else if ( !strcmp( argv[i], "-ig" ) ) {
197 if ( ( i < argc-1) && (*argv[i+1] != '-' ) ) {
198 InputGpf.in_file = argv[++i];
202 } else if ( !strcmp( argv[i], "-og" ) ) {
203 if ( (i < argc-1) && (*argv[i+1] != '-') ){
204 OutputGpf.in_file = argv[++i];
208 } else if ( !strcmp( argv[i], "-system" ) ) {
210 } else if ( !strcmp( argv[i], "-help" ) ) {
212 } else if ( !strcmp(argv[i], "-width") ) {
213 if ((i < argc-1) && (*argv[i+1] != '-')) {
214 OutputGpf.p_width = check_width( com, argv[++i]);
215 if (OutputGpf.p_width == 0) {
219 USAGE1("%s : The character width is not specified.\n", com);
222 } else if ( !strcmp(argv[i], "-height") ) {
223 if ((i < argc-1) && (*argv[i+1] != '-')) {
224 OutputGpf.p_height = check_height( argv[0], argv[++i]);
225 if (OutputGpf.p_height == 0) {
229 USAGE1("%s : The character height is not specified.\n", com);
232 } else if ( !strcmp(argv[i], "-start") ) {
233 if ((i < argc-1) && (*argv[i+1] != '-')) {
234 start_code = argv[++i] ;
236 USAGE1("%s : The extract start code is not specified.\n", com);
239 } else if ( !strcmp(argv[i], "-end" ) ) {
240 if ( ( i < argc-1 ) && ( *argv[i+1] != '-' ) ) {
241 end_code = argv[++i] ;
243 USAGE1("%s : The extract end code is not specified.\n", com);
246 } else if ( !strcmp( argv[i], "-istyle" ) ) {
247 if ( ( i < argc-1 ) && ( *argv[i+1] != '-' ) ){
252 } else if ( !strcmp( argv[i], "-ostyle" ) ) {
253 if ( ( i < argc-1 ) && ( *argv[i+1] != '-' ) ){
258 } else if ( !strcmp( argv[i], "-codeset" ) ) {
259 if ( ( i < argc - 1 ) && ( *argv[i+1] != '-' )){
261 COMM_SET_CODESET( codeset, code_area ) ;
263 } else if ( !strcmp( argv[i], "-ixlfd" ) ) {
265 ixlfdname = argv[++i];
267 } else if ( !strcmp( argv[i], "-oxlfd" ) ) {
269 oxlfdname = argv[++i];
271 } else if ( COMM_SBOPT_STRCMP( argv, i ) ) {
272 COMM_SBOPT_SETSBOPT( code_area ) ;
273 } else if ( COMM_TYPE_STRCMP( argv, i ) ) {
274 COMM_TYPE_SETTYPE( argc, argv, i, type ) ;
286 COMM_SBOPT_CHECKSBOPT( com, code_area ) ;
289 if ( no_infile == 1 )
290 USAGE1("%s : The font file name for input cannot be omitted.\n", com );
292 USAGE1("%s : The font file name for output cannot be omitted.\n", com );
296 if ( (code_no = cpg_atoi( codeset)) == -1 ) {
297 USAGE1("%s : The code set number is illegal.\n", com );
303 USAGE1("%s : The style for input cannot be omitted.\n", com );
305 USAGE1("%s : The style for output cannot be omitted.\n", com );
306 USAGE1("%s : The style is not specified.\n", com ) ;
310 /*****************************************************************
312 *****************************************************************/
314 if ( getGpfFileName( com, &InputGpf, code_area, code_no, ixlfdname, isnf_file, istyle ) ) {
319 if ( getGpfFileName( com, &OutputGpf, code_area, code_no, oxlfdname, osnf_file, ostyle ) ) {
324 * refuse proportional fonts
326 if( ( !stat( OutputGpf.in_file, &statbuf ) )){
327 if ( GetUdcFontName( OutputGpf.in_file, NULL, &xlfdname ) ) {
328 USAGE2("%s : This font cannot get XLFD(%s). Terminates abnormally.\n", com, OutputGpf.in_file );
331 GETSPACINGSTR( spacing, xlfdname ) ;
332 if ( !strcmp( "p", spacing ) || !strcmp( "P", spacing ) ) {
333 USAGE2("%s : cannot edit proportional fonts.(SPACING \"%s\")\n", com, spacing );
338 if( !(code_area & SYSTM) ){
339 USAGE2("%s : \"%s\" does not exists.\n", com, OutputGpf.in_file );
343 if( xlfdname ) free( xlfdname ) ;
344 if ( GetUdcFontName( InputGpf.in_file, NULL, &xlfdname ) ) {
345 USAGE2("%s : This font cannot get XLFD(%s). Terminates abnormally.\n", com, InputGpf.in_file );
348 GETSPACINGSTR( spacing, xlfdname ) ;
349 if ( !strcmp( "p", spacing ) || !strcmp( "P", spacing ) ) {
350 USAGE2("%s : cannot edit proportional fonts.(SPACING \"%s\")\n", com, spacing );
353 GETCHARSETSTR( char_set, xlfdname ) ;
355 /*****************************************************************
356 * get UDC code region
357 *****************************************************************/
358 if ( !(code_area & SYSTM) ) {
359 if ( GetUdcRegion( com, code_no, InputGpf.in_file, &num_gr, &gr ) ) {
360 USAGE1("%s : This font cannot get UDC code region. Terminates abnormally.\n", com);
365 if( (gr = (FalGlyphRegion *)malloc( sizeof(FalGlyphRegion) * num_gr )) == NULL ) {
366 USAGE1("%s : malloc error. Terminates abnormally.\n", com);
369 gr[0].start = MIN_CODE ;
370 gr[0].end = MAX_CODE ;
374 * check specified code region
376 if( start_code && end_code ) {
377 if( (startcode = check_code(com, start_code, START_CODE, char_set, num_gr, gr )) < 0 ) {
380 if( (endcode = check_code(com, end_code, END_CODE, char_set, num_gr, gr )) < 0 ) {
384 if ( startcode > endcode ) {
385 USAGE1("%s : The specification of extract start/end code is improper.\n", com);
389 if( is_in_udcregion( startcode, endcode, num_gr, gr ) ){
390 USAGE3("%s : The specified code \"%s-%s\" is outside of the UDC code region.\n", com, start_code, end_code );
391 USAGE("The UDC code region of specified font is showed below.\n" );
392 for( i=0; i<num_gr; i++ )
393 USAGE2("\t0x%x-0x%x\n", gr[i].start, gr[i].end );
398 /*****************************************************************
399 * check status of font file
400 *****************************************************************/
401 /* get InputGpf.in_file */
402 if ((targ_file = GetRealFileName( OutputGpf.in_file )) == NULL){
403 if( errno == ENOENT && (code_area & SYSTM) ){
404 /* create new file */
405 if ( ( chk_fd = open( OutputGpf.in_file, O_RDWR | O_CREAT, 0644 ) ) < 0 ) {
406 USAGE2("%s : The font file of substance \"%s\" cannot be create.\n", com , OutputGpf.in_file );
409 targ_file = OutputGpf.in_file ;
413 USAGE2("%s : It is not possible to refer to the substance of the font file. \"%s\"\n", com, OutputGpf.in_file);
417 WriteGpf.snf_file = targ_file;
419 if ( ( chk_fd = open( targ_file, O_RDWR ) ) < 0 ) {
420 USAGE2("%s : The font file of substance \"%s\" cannot be opened.\n", com , targ_file );
423 if ( isLock( chk_fd ) == 1 ) {
424 USAGE2("%s : \"%s\" is opened by other application. \n", WriteGpf.snf_file, com );
430 /*****************************************************************
431 * set code category to inner structure
432 *****************************************************************/
434 WriteGpf.start_code = MIN_CODE;
435 WriteGpf.end_code = MAX_CODE;
436 WriteGpf.code_category = ALL_CODE;
438 COMM_SBFNT_SETUDCAREA( argv[0], OutputGpf, char_set, code_area, num_gr, gr ) ;
445 * (InputGpf.in_file) --> GPFTOBDF ==H
447 * (OutputGpf.in_file) --> GPFTOBDF ==H
451 * (WriteGpf.out_file) <-- BDFTOGPF ==H
455 signal( SIGHUP , (void(*)())sigint_out );
456 signal( SIGINT , (void(*)())sigint_out );
457 signal( SIGQUIT, (void(*)())sigint_out );
458 signal( SIGTERM, (void(*)())sigint_out );
460 if ( rtn = CpyGpfInit( &InputGpf, &OutputGpf, &WriteGpf, type ) ) {
461 if ( WriteGpf.out_file ) {
462 Unlink_Tmpfile( WriteGpf.out_file, com );
464 put_error_and_exit( &InputGpf, &WriteGpf, rtn, com );
467 /* read copy origin */
468 if ( (rtn = readGpf( &InputGpf, readbuf, startcode, endcode, num_gr, gr )) ){
469 if ( WriteGpf.out_file ) {
470 Unlink_Tmpfile( WriteGpf.out_file, com );
472 put_error_and_exit( &InputGpf, &WriteGpf, rtn, com );
474 fclose( InputGpf.input );
476 /* read copy target */
477 if( (rtn = readBdfHeaderAndPut(&OutputGpf, &WriteGpf, readbuf)) ) {
478 if ( WriteGpf.out_file ) {
479 Unlink_Tmpfile( WriteGpf.out_file, com );
481 put_error_and_exit( &InputGpf, &WriteGpf, rtn, com );
483 fclose( OutputGpf.input );
487 * write SNF output file
489 if ( ( rtn = writeGpf( &InputGpf, &OutputGpf, &WriteGpf ) ) ) {
490 if ( WriteGpf.out_file ) {
491 Unlink_Tmpfile( WriteGpf.out_file, com );
493 put_error_and_exit( &InputGpf, &WriteGpf, rtn, com );
497 if ( pclose( WriteGpf.output ) ) {
498 Unlink_Tmpfile( WriteGpf.out_file, com );
499 put_error_and_exit( &InputGpf, &WriteGpf, PCLOSE_ERROR, com );
502 fclose( WriteGpf.output );
504 #if !defined( SVR4 ) && !defined( SYSV )
505 if ( !WIFEXITED(exit_stat) ) {
507 if ( ! ( WIFEXITED(exit_stat) && !WEXITSTATUS(exit_stat) ) ) {
509 USAGE3("%s: The error occurred by %s (%08x).\n", com, oakgtobdf, exit_stat);
510 Unlink_Tmpfile( WriteGpf.out_file, com );
511 put_error_and_exit( &InputGpf, &WriteGpf, FATAL_ERROR, com );
514 signal( SIGHUP , SIG_IGN );
515 signal( SIGINT , SIG_IGN );
516 signal( SIGQUIT, SIG_IGN );
517 signal( SIGTERM, SIG_IGN );
520 if ( ( stat( WriteGpf.out_file, &statbuf ) ) || ( statbuf.st_size == 0 )
522 Unlink_Tmpfile( WriteGpf.out_file, com );
523 put_error_and_exit( &InputGpf, &WriteGpf, BDF_WRITE, com );
525 if ( stat( WriteGpf.snf_file, &statbuf ) ) {
526 Unlink_Tmpfile( WriteGpf.out_file, com );
529 exit_code = Make_NewFefFile( WriteGpf.snf_file, WriteGpf.out_file,
530 FONT_FILE_PARM, (uid_t)statbuf.st_uid, (gid_t)statbuf.st_gid, com ) ;
533 if( *create_font != '\0' && new_target )
534 fprintf( stdout, "%s : New font <%s> is created.\n", com, create_font );
541 getGpfFileName( com, gpfinf, code_area, code_no, xlfdname, snf_file, style )
543 struct btophead *gpfinf ;
552 if ( gpfinf->in_file == NULL && xlfdname == NULL ) {
553 if ( code_area & SYSTM ) {
554 USAGE1("%s : The GPF output file name cannot be omitted.\n", com );
555 } else { /* string of charcter size */
556 USAGE1("%s : The character size specification cannot be omitted.\n", com );
562 if ( !(code_area & SYSTM) ) {
564 if ( GetUdcFileName( com, code_no, xlfdname, snf_file ) ) {
565 USAGE2("%s : Failed to get font file.( XLFD: %s ) Terminates abnormally.\n", com, xlfdname );
568 gpfinf->in_file = snf_file ;
571 switch ( GetFileName( com, gpfinf->in_file, style, code_no, snf_file ) ) {
573 gpfinf->in_file = snf_file;
578 USAGE1("%s : The font file name cannot be obtained. Terminates abnormally.\n", com);
589 CpyGpfInit(i_gpf, o_gpf, w_gpf, type )
590 struct btophead *i_gpf;
591 struct btophead *o_gpf;
592 struct ptobhead *w_gpf;
596 int ifd[2], ofd[2], snf_fd, permission;
599 char command[BUFSIZE], *ep ;
606 if ( ChkPcfFontFile( w_gpf->snf_file ) ) {
608 if( (snf_fd = open( w_gpf->snf_file, O_RDONLY ) ) >= 0 ) {
609 COMM_SNF_FILEVERSION( snf_fd, finf, buf, permission ) ;
610 if ( permission < 0 ) {
618 COMM_SNF_NEWTARGET( permission ) ;
621 /* open pipe for copy origin gpf */
622 if (pipe(ifd) != 0) {
629 if ( dup( ifd[1] ) < 0 ) {
634 execl( oakgtobdf, oakgtobdf, i_gpf->in_file, 0 );
642 if ( ( i_gpf->input = fdopen( ifd[0], "r" ) ) == NULL ) {
646 /* open pipe for copy target gpf */
647 if (pipe(ofd) != 0) {
654 if ( dup( ofd[1] ) < 0 ) {
660 execl( oakgtobdf, oakgtobdf, o_gpf->in_file, "-H", 0 );
662 execl( oakgtobdf, oakgtobdf, i_gpf->in_file, "-H", 0 );
671 if ( ( o_gpf->input = fdopen( ofd[0], "r" ) ) == NULL ) {
675 /* open pipe for target gpf */
676 if ( !( w_gpf->out_file = GetTmpPath( targ_file ) ) ) {
681 if( ChkPcfFontFile( w_gpf->snf_file ) == 0 ) {
682 sprintf(command, "%s > %s", bdftopcf, w_gpf->out_file) ;
684 COMM_SNF_POPEN( permission, w_gpf->snf_file, w_gpf->out_file, ep, buf, command ) ;
686 if ((w_gpf->output = popen(command, "w")) == NULL) {
689 #else /* ROOT_ONLY */
690 if ( pipe( pfd ) != 0 ) {
695 if ( ( out_fd = open( w_gpf->out_file, O_WRONLY | O_CREAT, 0664 ) ) < 0 ) {
699 if ( dup(pfd[0]) < 0 ) {
705 if( dup( out_fd ) < 0 ) {
711 if ( ChkPcfFontFile( w_gpf->snf_file ) == 0 ) {
712 execl( bdftopcf, bdftopcf, 0 );
713 return PCFFONTC_ERROR;
716 if( type ) permission = type ;
717 COMM_SNF_EXECLBDFTOSNF( permission, buf, w_gpf->snf_file ) ;
718 return SNFFONTC_ERROR;
726 if ( ( w_gpf->output = fdopen( pfd[1], "w" ) ) == NULL ) {
729 #endif /* ROOT_ONLY */
736 readGpf(i_gpf, buf, startcode, endcode, num_gr, gr)
737 struct btophead *i_gpf;
745 if ( ( rtn = ReadBdfHeader( i_gpf, buf ) ) ) {
749 nchar = i_gpf->num_chars ;
751 if ( ( i_gpf->code = (int *)malloc( sizeof(int) * nchar ) ) == NULL ) {
755 if ( ( i_gpf->ptn = (char **)malloc( sizeof(char *) * nchar ) ) == NULL ) {
759 return readBdfToMemory( i_gpf, buf, startcode, endcode, num_gr, gr ) ;
765 readBdfHeaderAndPut(o_gpf, w_gpf, buf)
766 struct btophead *o_gpf;
767 struct ptobhead *w_gpf;
772 int getstat, zoom, property ;
774 getstat = zoom = property = 0 ;
776 if( o_gpf->p_width || o_gpf->p_height ){
779 if ( (fp = fopen( w_gpf->out_file, "w" )) == NULL ) {
780 return BDF_OPEN_HEAD ;
784 if ( fgets( buf, BUFSIZE, o_gpf->input ) == NULL ) {
790 if ( !strncmp( p, SIZE, strlen( SIZE ) ) ) {
791 if ( ( sscanf( p, "SIZE %f%d",
792 &(o_gpf->bdf_point), &(o_gpf->bdf_xdpi))) != 2 ) {
796 fprintf( fp, "%s", buf );
799 } else if ( !strncmp( p, FONTBOUNDINGBOX, strlen( FONTBOUNDINGBOX ) ) ) {
800 if ( ( sscanf( p, "FONTBOUNDINGBOX %d%d%d%d",
801 &(o_gpf->bdf_width), &(o_gpf->bdf_height),
802 &(o_gpf->bdf_x), &(o_gpf->bdf_y) )) != 4) {
806 /* -width / -height */
808 /* -width / -height */
809 if( o_gpf->p_width ) o_gpf->bdf_width = o_gpf->p_width ;
810 if( o_gpf->p_height ) o_gpf->bdf_height = o_gpf->p_height ;
811 fprintf( fp, "FONTBOUNDINGBOX %d %d %d %d\n",
812 o_gpf->bdf_width, o_gpf->bdf_height,
813 o_gpf->bdf_x, o_gpf->bdf_y );
815 fprintf( fp, "%s", buf );
819 } else if ( !strncmp( p, "ENDPROPERTIES", strlen( "ENDPROPERTIES" ) ) ) {
820 fprintf( fp, "%s", buf );
827 if ( !strncmp( p, "STARTPROPERTIES", strlen( "STARTPROPERTIES" ) ) ) {
829 fprintf( fp, "%s", buf );
830 } else if ( !strncmp( p, "FONT ", strlen( "FONT " ) ) ) {
833 if( (sscanf( buf, "FONT \"%s\"", font )) != 1 ){
837 MkFontProp( o_gpf->bdf_height, font, create_font ) ;
838 fprintf( fp, "FONT \"%s\"\n", create_font ) ;
840 if( (sscanf( buf, "FONT %s", font )) != 1 ){
844 MkFontProp( o_gpf->p_height, font, create_font ) ;
845 fprintf( fp, "FONT %s\n", create_font ) ;
847 } else if ( !strncmp( p, "PIXEL_SIZE ", strlen( "PIXEL_SIZE " ) ) ) {
848 fprintf( fp, "PIXEL_SIZE %d\n", o_gpf->bdf_height ) ;
849 } else if ( !strncmp( p, "AVERAGE_WIDTH ", strlen( "AVERAGE_WIDTH " ) ) ) {
850 fprintf( fp, "AVERAGE_WIDTH %d\n", o_gpf->bdf_height*10 ) ;
851 } else if ( !strncmp( p, "POINT_SIZE ", strlen( "POINT_SIZE " ) ) ) {
852 fprintf( fp, "POINT_SIZE %d\n", o_gpf->bdf_height*10 );
853 } else if ( !strncmp( p, "RESOLUTION ", strlen( "RESOLUTION " ) ) ) {
855 if( (sscanf( buf, "RESOLUTION %d\n", &resol )) != 1 ){
859 fprintf( fp, "RESOLUTION %d\n", (int)((resol<0)?DEF_RESOLUTION:resol) );
860 } else if ( !strncmp( p, "X_HEIGHT ", strlen( "X_HEIGHT " ) ) ) {
861 fprintf( fp, "X_HEIGHT %d\n", o_gpf->bdf_height );
862 } else if ( !strncmp( p, "QUAD_WIDTH ", strlen( "QUAD_WIDTH " ) ) ) {
863 fprintf( fp, "QUAD_WIDTH %d\n", o_gpf->bdf_width );
864 } else if ( !strncmp( p, "FONT_ASCENT ", strlen( "FONT_ASCENT " ) ) ) {
865 fprintf( fp, "FONT_ASCENT %d\n", (o_gpf->bdf_height + o_gpf->bdf_y) );
866 } else if ( !strncmp( p, "FONT_DESCENT ", strlen( "FONT_DESCENT " ) ) ) {
867 fprintf( fp, "FONT_DESCENT %d\n", -(o_gpf->bdf_y) );
868 } else if ( !strncmp( p, "DEFAULT_CHAR ", strlen( "DEFAULT_CHAR " ) ) ) {
869 fprintf( fp, "DEFAULT_CHAR %d\n", ((firstRow << 8) + firstCol) );
871 fprintf( fp, "%s", buf );
874 fprintf( fp, "%s", buf );
880 if ( getstat != 0x07 ) {
889 writeGpf( i_gpf, o_gpf, w_gpf )
890 struct btophead *i_gpf;
891 struct btophead *o_gpf;
892 struct ptobhead *w_gpf;
895 char rdbuf[BUFSIZE] ;
897 /* put BDF header from temporary file */
898 if ( (fp = fopen( w_gpf->out_file, "r" )) == NULL ) {
899 return BDF_OPEN_HEAD ;
901 while( fgets( rdbuf, BUFSIZE, fp ) != (char *)NULL ){
902 fprintf( w_gpf->output, "%s", rdbuf ) ;
908 return BDF_READ_HEAD ;
911 /* set specified width or height */
912 w_gpf->bdf_width = o_gpf->bdf_width ;
913 w_gpf->bdf_height = o_gpf->bdf_height ;
914 w_gpf->bdf_x = o_gpf->bdf_x;
915 w_gpf->bdf_y = o_gpf->bdf_y;
916 w_gpf->bdf_point = o_gpf->bdf_point;
917 w_gpf->bdf_xdpi = o_gpf->bdf_xdpi;
919 w_gpf->p_width = i_gpf->bdf_width;
920 w_gpf->p_height = i_gpf->bdf_height;
922 if( w_gpf->bdf_width != w_gpf->p_width ||
923 w_gpf->bdf_height != w_gpf->p_height ) {
929 w_gpf->num_chars = i_gpf->num_chars;
930 w_gpf->code = i_gpf->code;
931 w_gpf->ptn = i_gpf->ptn;
933 return WritePtnToBdf( w_gpf );
939 check_width( prog_name, len_str )
943 return( check_width_height( prog_name, len_str, 0) );
948 check_height( prog_name, len_str )
952 return( check_width_height( prog_name, len_str, 1) );
956 check_width_height( prog_name, len_str, mode )
959 int mode; /* width ... 0 , height ... 1 */
964 ret = (int)strtol( len_str, &tmp, 10 ); /* <-- ret = atoi( len_str ) */
965 if ((tmp == len_str) || (ret < MIN_FONT_WIDTH) || (ret > MAX_FONT_WIDTH)) {
968 USAGE2("%s : The specification of the character width is improper.\"%s\"¡¥\n",
972 USAGE2("%s : The specification of the character height is improper.\"%s\"¡¥\n",
986 check_code( prog_name, code_str, mode, charset, num_gr, gr )
989 int mode; /* start_code ... 0, end_code ... 1 */
1001 code = (int)strtol(code_str, &tmp, 16);
1002 if ( tmp == code_str ) {
1006 if( COMM_SBFNT_ISSBFNT( charset ) ) {
1008 CONVGLYPHINDEX( code_num ) ;
1010 if( fal_code_to_glyph( locale, code, &gi, &num_gi) ) {
1011 USAGE2("%s : Failed to convert code point into glyph index.\"%s\" \n", prog_name, code_str ) ;
1015 code_num = gi[0].glyph_index ;
1018 for( i=0; i<num_gi; i++ ) {
1019 if( !strcmp( gi[i].charset_str, char_set ) ) {
1020 code_num = gi[i].glyph_index ;
1023 } else err_flg = 1 ;
1028 for( i=0; i<num_gr; i++ ) {
1029 if( (code_num >= gr[i].start) && (code_num <= gr[i].end) )
1037 USAGE2("%s : The specification of the extract start code is improper.\"%s\"¡¥\n",
1038 prog_name, code_str);
1041 USAGE2("%s : The specification of the extract end code is improper.\"%s\"¡¥\n",
1042 prog_name, code_str);
1045 USAGE2("%s : The specification of the extract code is improper.\"%s\"¡¥\n",
1046 prog_name, code_str);
1057 readBdfToMemory(head, buf, startcode, endcode, num_gr, gr)
1058 struct btophead *head;
1063 FalGlyphRegion *gr ;
1065 int code, mwidth, num_char, bsize, rtn;
1069 mwidth = (head->bdf_width + 7) / 8;
1070 bsize = mwidth * head->bdf_height;
1072 if ((rtn = GetBdfCode(head, buf, &code)) < 0) {
1073 return(rtn); /* contain BDF_INVAL */
1074 } else if (rtn == FILE_END) {
1075 head->num_chars = num_char;
1078 if ( !IsInRegion( code, num_gr, gr ) &&
1079 ( startcode > code || endcode < code )
1083 getDefaultCh( (unsigned int)code ) ;
1085 head->code[num_char] = code;
1086 if ( ( ptn = head->ptn[num_char++] = (char *)malloc( bsize ) ) == NULL ) {
1087 return(MALLOC_ERROR);
1089 if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) {
1098 getDefaultCh( code )
1103 if( (cbuf & 0xff) < firstCol ) firstCol = cbuf & 0xff ;
1104 if( (cbuf >> 8) < firstRow ) firstRow = cbuf >> 8 ;
1105 if( (cbuf & 0xff) > lastCol ) lastCol = cbuf & 0xff ;
1106 if( (cbuf >> 8) > lastRow ) lastRow = cbuf >> 8 ;
1117 ep = (char *)strchr( numstr, '\0' ) ;
1118 val = (int)strtol( numstr, &cbuf, 10 ) ;
1119 if ( cbuf == numstr || cbuf != ep ) {
1126 is_in_udcregion( start, end, num_gr, gr )
1127 int start, end, num_gr ;
1128 FalGlyphRegion *gr ;
1131 if( start < gr[0].start && end < gr[0].start ){
1134 for( i=0; i<num_gr-1; i++ ){
1135 if( (start > gr[i].end && start < gr[i+1].start )
1136 && (end > gr[i].end && end < gr[i+1].start )
1140 if( start > gr[num_gr-1].end && end > gr[num_gr-1].end ){
1148 MkFontProp(font_height, font, output)
1153 char fbuf[BUFSIZE], split[BUFSIZE] ;
1154 char *ep, *pix_sz, *point_sz, *rsl_x, *av_width, *char_set ;
1156 snprintf( fbuf, sizeof(fbuf), "%s", font ) ;
1157 snprintf( split, sizeof(split), "%s", font ) ;
1159 ep += strlen( fbuf ) ;
1161 if( *ep == '"' ) *ep = '\0' ;
1162 POINTXLFDELM( pix_sz, fbuf, XLFD_ELM_PIXEL_SIZE ) ;
1163 POINTXLFDELM( point_sz, split, XLFD_ELM_POINT_SIZE ) ;
1164 POINTXLFDELM( rsl_x, split, XLFD_ELM_RESOLUTION_X ) ;
1165 POINTXLFDELM( av_width, split, XLFD_ELM_AVERAGE_WIDTH ) ;
1166 POINTXLFDELM( char_set, fbuf, XLFD_ELM_CHARSET_REGISTRY ) ;
1170 sprintf(output, "%s-%d-%s-%d%s", fbuf,
1171 font_height, /* pixel size */
1173 font_height*10, /* average width */
1180 put_error_and_exit(ptob_in, ptob_out, er_no, prog_name)
1181 struct btophead *ptob_in;
1182 struct ptobhead *ptob_out;
1186 ErrMsgTable_AndExit( er_no, ptob_in->in_file, ptob_out->out_file,
1187 NULL, NULL, NULL, prog_name );
1194 put_help( prog_name )
1197 USAGE1("Usage: %s -ixlfd oxlfd -oxlfd oxlfd\n", prog_name);
1198 USAGE("\t[in_character_size][out_character_size]\n");
1199 USAGE("\t[-start start_code][-end end_code]\n");
1200 USAGE("\t[-istyle ostyle][-ostyle ostyle]");
1202 USAGE1("%s can copy glyphs of gpf file in the following code area.\n", prog_name);
1203 USAGE("codeset \t\tcode area\n");
1204 USAGE("----------------------------------------\n");
1206 USAGE("If the -start and -end option is omitted, the start/end code of each extractive area is specified.\n");
1207 USAGE("The xlfd name and character size may be obtained using dtlsgpf command.\n");