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 librararies 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: gpftobdf.c /main/5 1996/11/08 02:04:24 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
33 #include <sys/types.h>
42 #include <X11/Xproto.h>
46 #include "fontstruct.h"
47 #include "snfstruct.h"
58 #define GLYPHPADOPTIONS 4
59 #define SIZEOF_COMPRESSED_METRIC 5
64 typedef struct pcf_tmp {
74 CARD32 bmp_fmt; /* bitOrder ,byteOrder, glyph, scan */
79 CARD16 *encodingOffsets;
102 typedef struct prop_tmp {
105 FontPropRec resolution;
110 static char *readfontfile();
111 static void Anafprop();
113 static void pPROPS();
114 static void pCHARS();
115 static void pfixCHARS();
118 static Bool seekToType() ;
119 static int getMetric() ;
120 static Bool getAccel() ;
121 static Bool getProperties() ;
122 static int putPtn() ;
123 static int ByteSwap() ;
124 static int invertBits() ;
126 static int getINT16() ;
127 static int getINT32() ;
128 static CARD32 getLSB32();
129 static char *make_toptn();
130 static void pSIZE_pcf();
131 static PcfTmp *openPcfFont();
132 static void setProp();
133 static void pPROPS_pcf();
134 static void pCHARS_pcf();
135 static void BitOrderInvert();
136 static char *bufp,buf[2048];
138 extern int ChkPcfFontFile();
149 FontInfoRec *fip; /* font information */
150 CharInfoRec *cip, *wkcip; /* character information */
151 unsigned int glyphstotal; /* glyph */
152 unsigned int charInfoNum ; /* character information's number */
153 unsigned int charNum; /* define character number */
154 char *glyphPtr; /* glyph */
155 FontPropRec *fpropPtr,*fplistPtr; /* font property list */
156 FontPropRec psprop; /* point size property */
157 FontPropRec resprop; /* resolution property */
160 unsigned int fplistNum; /* font property number */
161 char *fontname; /* fontname */
166 char fname[1024]; /* snf filename */
167 int bitorder; /* bitorder */
168 int byteorder; /* byteorder */
169 int scanunit; /* scanunit */
170 int glyphPad ; /* glyph */
171 int outLevel; /* output information level */
180 extern char *GetRealFileName();
183 if (getarg(argc,argv,fname,&bitorder,&byteorder,&scanunit,&glyphPad,
184 &outLevel,&fix) != 0) {
191 if ( ( tmpfname = GetRealFileName( fname ) ) == NULL ) {
192 USAGE("dtgpftobdf: cannot refer to substance file.\n" );
195 if ( strcmp( tmpfname, fname ) != 0 ){
196 strcpy( fname, tmpfname );
199 if ( ChkPcfFontFile( fname ) == 0 ){
202 if ( !( pcf = openPcfFont( fname ) ) ) {
203 USAGE("dtgpftobdf: cannot open font\n" );
209 if ( ( fp = readfontfile( fname ) ) == (char *)-1 ) {
217 COMM_SNF_GETHEADER( fip, fp ) ;
218 /* font file check */
219 if ((fip->version1 != fip->version2) ||
220 (fip->version1 != FONT_FILE_VERSION)) {
221 USAGE("dtgpftobdf: illegal font version\n");
225 cip = (CharInfoRec *)((char *)fip + sizeof(FontInfoRec));
227 charInfoNum = (fip->lastCol - fip->firstCol + 1)
228 *(fip->lastRow - fip->firstRow + 1);
229 glyphPtr = ((char *)cip) + ( charInfoNum * sizeof(CharInfoRec) );
231 charNum = charInfoNum ;
234 glyphstotal = fip->maxbounds.byteOffset;
236 glyphPad = (((fip->maxbounds.metrics.rightSideBearing
237 - fip->maxbounds.metrics.leftSideBearing)+31)/32)*4;
240 for ( i = 0; i < charInfoNum; i++ ) {
241 if ( wkcip->exists == FALSE ) {
248 for ( i = 0; i < charInfoNum; i++ ) {
249 if (wkcip->exists == FALSE) {
254 glyphstotal += (wkcip->metrics.ascent
255 + wkcip->metrics.descent) * glyphPad;
260 fpropPtr = (FontPropRec *)(glyphPtr + glyphstotal);
261 fpropvnPtr = ((char *)fpropPtr) + (fip->nProps) * sizeof(FontPropRec);
267 setProp( pcf, &proptmp );
269 fontname = (char *)0;
271 fip, fpropPtr, fpropvnPtr,
272 &fontname, &psprop, &resprop,
273 &fplistPtr, &fplistNum
278 *¡¡output to BDF information
281 memcpy(bufp,"STARTFONT 2.1\n",14);
283 memcpy(bufp,"COMMENT\n",8);
285 memcpy(bufp,"COMMENT This BDF was created by dtgpftobdf.\n",45 );
287 memcpy(bufp,"COMMENT\n",8);
290 tm = localtime(&clock);
292 strcpy( tmbuf, asctime(tm) ) ;
294 k = sprintf(bufp,"COMMENT Created date : %s\n",tmbuf );
296 memcpy(bufp,"COMMENT\n",8);
300 k = sprintf(bufp,"FONT %s\n",proptmp.font_name);
303 fprintf( stdout,"%s",buf );
304 pSIZE_pcf( &proptmp );
305 fprintf( stdout,"FONTBOUNDINGBOX %d %d %d %d\n",
306 pcf->info.maxbounds.metrics.rightSideBearing
307 - pcf->info.maxbounds.metrics.leftSideBearing,
308 pcf->info.maxbounds.metrics.ascent
309 + pcf->info.maxbounds.metrics.descent,
310 pcf->info.maxbounds.metrics.leftSideBearing,
311 - ( pcf->info.maxbounds.metrics.descent )
314 if ( outLevel == FALSE ) {
315 pCHARS_pcf( pcf, fix );
318 k = sprintf( bufp,"FONT %s\n",fontname );
321 fprintf( stdout,"%s",buf );
322 pSIZE( &psprop, &resprop );
323 fprintf( stdout,"FONTBOUNDINGBOX %d %d %d %d\n",
324 cip->metrics.rightSideBearing
325 - cip->metrics.leftSideBearing,
326 cip->metrics.ascent + cip->metrics.descent,
327 cip->metrics.leftSideBearing,
328 -(cip->metrics.descent)
330 pPROPS( fip,fplistPtr,fplistNum );
331 if ( outLevel == FALSE ) {
333 pfixCHARS( fip,cip,glyphPtr,charNum, glyphPad );
335 pCHARS(fip,cip,glyphPtr,charNum,glyphPad);
341 fprintf( stdout,"ENDFONT\n" );
349 static char *readfontfile( fname )
356 fd = open( fname,O_RDONLY );
358 USAGE("dtgpftobdf: can't open file.\n" );
362 if ( fstat( fd,&stat ) == 0 ) {
363 fp = (char *)mmap( 0, stat.st_size, PROT_READ, MAP_SHARED, fd, 0 );
364 if ( fp == (char *)-1 ) {
365 if ( ( fp = ( char * )malloc( stat.st_size ) ) == NULL ) {
366 USAGE("dtgpftobdf: malloc error.\n" );
370 /* if ( read( fd, fp, stat.st_size ) < 0 ) {*/
371 if ( read( fd, fp, stat.st_size ) != stat.st_size ) {
372 USAGE("dtgpftobdf: can't read file.\n" );
378 USAGE("dtgpftobdf: can't read file\n" );
384 if ( fstat(fd,&stat) == 0 ) {
385 if ( ( fp = (char *)malloc(stat.st_size) ) == NULL ) {
386 USAGE("dtgpftobdf: malloc error.\n" );
390 if ( read( fd, fp, stat.st_size ) < 0 ) {
391 USAGE("dtgpftobdf: can't read file.\n" );
396 USAGE("dtgpftobdf: can't read file\n" );
406 #define getINT8( p ) ( *p++ ) ;
415 c |= (CARD32)(*p++) << 8;
416 c |= (CARD32)(*p++) << 16;
417 c |= (CARD32)(*p) << 24;
424 getINT32( p, format )
430 if ( PCF_BYTE_ORDER(format) == MSBFirst ) {
431 c = (CARD32)(*p++) << 24;
432 c |= (CARD32)(*p++) << 16;
433 c |= (CARD32)(*p++) << 8;
437 c |= (CARD32)(*p++) << 8;
438 c |= (CARD32)(*p++) << 16;
439 c |= (CARD32)(*p) << 24;
446 getINT16( p, format )
452 if ( PCF_BYTE_ORDER(format) == MSBFirst ) {
453 c = (CARD32)(*p++) << 8;
457 c |= (CARD32)(*p) << 8;
464 seekToType( tables, ntables, type, formatp, sizep, offsetp)
474 for ( i = 0; i < ntables; i++ ) {
475 if ( getLSB32( (unsigned char *)&tables[i].type) == type) {
476 *formatp = getLSB32( (unsigned char *)&tables[i].format);
477 *sizep = getLSB32( (unsigned char *)&tables[i].size);
478 *offsetp = getLSB32( (unsigned char *)&tables[i].offset);
487 getMetric( buf, format, metric )
492 metric->leftSideBearing = getINT16( (unsigned char *)buf, format);
494 metric->rightSideBearing = getINT16( (unsigned char *)buf, format);
496 metric->characterWidth = getINT16( (unsigned char *)buf, format);
498 metric->ascent = getINT16( (unsigned char *)buf, format);
500 metric->descent = getINT16( (unsigned char *)buf, format);
502 metric->attributes = getINT16( (unsigned char *)buf, format);
507 getAccel( pFontInfo, maxink, buf_top, tables, ntables, type )
508 FontInfoPtr pFontInfo;
520 if ( !seekToType( tables, ntables, type, &format, &size, &offset)) {
524 buffer = buf_top + offset;
525 format = getLSB32( (unsigned char *)buffer);
527 if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT )
528 && !PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS )
532 pFontInfo->noOverlap = *buffer++;
533 pFontInfo->constantMetrics = *buffer++;
534 pFontInfo->terminalFont = *buffer++;
535 pFontInfo->constantWidth = *buffer++;
536 pFontInfo->inkInside = *buffer++;
537 pFontInfo->inkMetrics = *buffer++;
538 pFontInfo->drawDirection = *buffer++;
539 /* natural alignment */
543 pFontInfo->fontAscent = getINT32( (unsigned char *)buffer, format);
546 pFontInfo->fontDescent = getINT32((unsigned char *)buffer, format);
551 getMetric(buffer, format, &pFontInfo->minbounds.metrics);
554 getMetric(buffer, format, &pFontInfo->maxbounds.metrics);
557 if ( PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) ) {
559 getMetric( buffer, format, maxink);
561 *maxink = pFontInfo->maxbounds.metrics;
568 getProperties( pcf, buf_top, tables, ntables)
580 if ( !seekToType( tables, ntables, (CARD32)PCF_PROPERTIES, &format, &size, &offset ) ) {
584 buffer = buf_top + offset;
585 format = getLSB32( (unsigned char *)buffer );
587 if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
590 pcf->nprops = getINT32((unsigned char *)buffer, format);
593 if ( !( pcf->props = ( FontPropPtr )malloc( pcf->nprops * sizeof( FontPropRec ) ) ) ) {
597 if ( !( pcf->isStringProp = ( char * )malloc(pcf->nprops * sizeof( char ) ) ) ) {
601 for ( i = 0; i < pcf->nprops; i++ ) {
602 pcf->props[i].name = getINT32((unsigned char *)buffer, format);
604 pcf->isStringProp[i] = *buffer++;
605 pcf->props[i].value = getINT32((unsigned char *)buffer, format);
608 if ( pcf->nprops & 3 ) {
609 i = 4 - (pcf->nprops & 3);
613 pcf->str_length = getINT32((unsigned char *)buffer, format);
616 pcf->string = (char *)buffer;
622 openPcfFont( fontname )
635 pcf_tmp = ( PcfTmp * )calloc( 1, sizeof( PcfTmp ) );
637 USAGE("dtgpftobdf : calloc() error.\n" ) ;
641 if ( stat( fontname, &st ) ) {
645 if ( ( pcf_tmp->pcf_buffer = readfontfile( fontname)) == (char *)-1 ) {
649 pcf_tmp->pcf_bufsz = st.st_size;
651 if ( (format = getLSB32( (unsigned char *)pcf_tmp->pcf_buffer )) != PCF_FILE_VERSION ) {
652 USAGE1("dtgpftobdf : pcf file version(0x%x) error.\n", format ) ;
656 pcf_tmp->ntables = getLSB32( (unsigned char *)(pcf_tmp->pcf_buffer + 4) );
657 pcf_tmp->tables = (PCFTablePtr)(pcf_tmp->pcf_buffer + 8 );
660 &pcf_tmp->info, &maxink, pcf_tmp->pcf_buffer,
661 pcf_tmp->tables, pcf_tmp->ntables, (CARD32)PCF_BDF_ACCELERATORS
665 &pcf_tmp->info, &maxink, pcf_tmp->pcf_buffer,
666 pcf_tmp->tables, pcf_tmp->ntables, (CARD32)PCF_ACCELERATORS
669 USAGE("dtgpftobdf : Cannot get accelerators.\n" ) ;
675 pcf_tmp, pcf_tmp->pcf_buffer,
676 pcf_tmp->tables, pcf_tmp->ntables
679 USAGE("dtgpftobdf : getProperties error.\n" ) ;
683 pcf_tmp->tables, pcf_tmp->ntables,
684 (CARD32)PCF_BITMAPS, &format, &size, &offset
687 USAGE("dtgpftobdf : PCF_BITMAPS error.\n" ) ;
691 buffp = pcf_tmp->pcf_buffer + offset;
693 format = getLSB32( (unsigned char *)buffp);
696 if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
697 USAGE("dtgpftobdf : error.!PCF_FORMAT_MATCH(PCF_BITMAPS)\n" ) ;
701 pcf_tmp->nbitmaps = getINT32( (unsigned char *)buffp, format);
703 pcf_tmp->offsets = (CARD32 *)buffp;
704 buffp += sizeof( *pcf_tmp->offsets) * pcf_tmp->nbitmaps;
707 bitmapSizes = (CARD32 *)buffp;
709 = getINT32( (unsigned char *)&bitmapSizes[PCF_GLYPH_PAD_INDEX(format)], format);
710 pcf_tmp->bmp_fmt = format;
711 buffp += sizeof( *bitmapSizes) * GLYPHPADOPTIONS;
712 pcf_tmp->bitmaps = buffp;
713 buffp += pcf_tmp->sizebitmaps;
716 pcf_tmp->tables, pcf_tmp->ntables,
717 (CARD32)PCF_BDF_ENCODINGS, &format, &size, &offset
720 USAGE("dtgpftobdf : error.(PCF_BDF_ENCODINGS)\n" ) ;
724 buffp = pcf_tmp->pcf_buffer + offset;
725 format = getLSB32( (unsigned char *)buffp);
727 if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
728 USAGE("dtgpftobdf : error.!PCF_FORMAT_MATCH(PCF_BDF_ENCODINGS)\n" ) ;
732 pcf_tmp->info.firstCol = getINT16( (unsigned char *)buffp, format);
734 pcf_tmp->info.lastCol = getINT16( (unsigned char *)buffp, format);
736 pcf_tmp->info.firstRow = getINT16( (unsigned char *)buffp, format);
738 pcf_tmp->info.lastRow = getINT16( (unsigned char *)buffp, format);
740 pcf_tmp->info.chDefault = getINT16( (unsigned char *)buffp, format);
743 pcf_tmp->info.allExist = FALSE;
744 pcf_tmp->enc_fmt = format;
745 pcf_tmp->encodingOffsets = (CARD16 *)buffp;
748 * get scale width infomations
751 pcf_tmp->tables, pcf_tmp->ntables,
752 (CARD32)PCF_SWIDTHS, &format, &size, &offset
758 buffp = pcf_tmp->pcf_buffer + offset;
759 format = getLSB32( (unsigned char*)buffp);
761 if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
764 pcf_tmp->swd_fmt = (CARD32)format ;
765 pcf_tmp->swd_num = getINT32( (unsigned char*)buffp, format ) ;
768 pcf_tmp->swidth = (CARD32 *)buffp ;
774 pcf_tmp->tables, pcf_tmp->ntables,
775 (CARD32)PCF_GLYPH_NAMES, &format, &size, &offset
781 buffp = pcf_tmp->pcf_buffer + offset;
782 format = getLSB32( (unsigned char*)buffp);
784 if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
787 pcf_tmp->glyphs = getINT32( (unsigned char*)buffp, format ) ;
789 pcf_tmp->glyph_offset = (int *)buffp ;
790 buffp += 4 * (pcf_tmp->glyphs + 1) ;
791 pcf_tmp->glyph_name = (char *)buffp ;
792 pcf_tmp->glyph_fmt = (CARD32)format ;
798 pcf_tmp->tables, pcf_tmp->ntables,
799 (CARD32)PCF_METRICS, &format, &size, &offset
805 buffp = pcf_tmp->pcf_buffer + offset;
806 format = getLSB32( (unsigned char*)buffp);
808 if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
809 pcf_tmp->compress = 0 ;
810 pcf_tmp->mtr_num = getINT32( (unsigned char*)buffp, format ) ;
812 }else if ( PCF_FORMAT_MATCH( format, PCF_COMPRESSED_METRICS ) ) {
813 pcf_tmp->compress = 1 ;
814 pcf_tmp->mtr_num = (int)getINT16( (unsigned char*)buffp, format ) ;
819 pcf_tmp->metrics = (xCharInfo *)buffp ;
820 pcf_tmp->mtr_fmt = (CARD32)format ;
833 Anafprop(fip,fpropPtr,fpropvnPtr,fontname,ps,res,fplistPtr,fplistNum)
835 FontPropRec *fpropPtr;
838 FontPropRec **fplistPtr;
841 unsigned int *fplistNum;
843 FontPropRec *wkp ,*wklp;
847 *fplistNum = fip->nProps - 1;
848 *fplistPtr = (FontPropRec *)malloc(*fplistNum * sizeof(FontPropRec));
851 for (i = 0; i < fip->nProps; i++) {
852 fpnp = fpropvnPtr + wkp->name;
854 if ((fpnL == 4) && (strncmp(fpnp,"FONT",4) == 0)) {
855 *fontname = fpropvnPtr + wkp->value;
860 if (strncmp(fpnp,"POINT_SIZE",10) == 0) {
861 ps->value = wkp->value;
863 if (strncmp(fpnp,"RESOLUTION",10) == 0) {
864 res->value = wkp->value;
867 wklp->name = (CARD32)fpropvnPtr + wkp->name;
868 if (wkp->indirect == TRUE) {
869 wklp->value = (INT32)fpropvnPtr + wkp->value;
871 wklp->value = wkp->value;
873 wklp->indirect = wkp->indirect;
882 setProp( pcf, proptmp )
889 for ( i = 0; i < pcf->nprops; i++ ) {
890 fpnp = pcf->string + pcf->props[i].name;
892 if ( ( fpnL == 4 ) && ( strncmp( fpnp,"FONT", 4 ) == 0 ) ) {
893 proptmp->font_name = pcf->string + pcf->props[i].value;
897 if ( strncmp( fpnp,"POINT_SIZE", 10 ) == 0 ) {
898 proptmp->psize.value = pcf->props[i].value;
899 } else if ( strncmp( fpnp, "RESOLUTION", 10 ) == 0 ) {
900 proptmp->resolution.value = pcf->props[i].value;
909 * output to SIZE (SIZE point resolutionX resolutionY)
914 FontPropRec *ps, *res;
918 char buf1[16], buf2[16];
920 f = ps->value / 10.0;
921 if ( ( ps->value % 10 ) != 0 ) {
922 sprintf( buf1, "%.1f", f );
924 sprintf( buf1, "%.0f", f );
926 k = ( ( res->value * 72.27 ) / 100.0 ) + 1;
927 sprintf( buf2, "%d %d", k, k );
928 fprintf( stdout, "SIZE %s %s\n", buf1, buf2 );
933 /* output to SIZE of pcf font */
941 char buf1[16],buf2[16];
943 f = proptmp->psize.value / 10.0;
944 if ( ( proptmp->psize.value % 10 ) != 0 ) {
945 sprintf( buf1,"%.1f",f );
947 sprintf(buf1,"%.0f",f);
949 k = ( ( proptmp->resolution.value * 72.27 ) / 100.0 ) + 1;
950 sprintf( buf2, "%d %d", k, k );
951 fprintf( stdout,"SIZE %s %s\n", buf1, buf2 );
958 pPROPS( fip,fplistPtr,fplistNum )
960 FontPropRec *fplistPtr;
961 unsigned int fplistNum;
967 k = sprintf( bufp,"STARTPROPERTIES %d\n", fplistNum+3 );
969 k = sprintf( bufp, "FONT_ASCENT %d\n", fip->fontAscent );
971 k = sprintf( bufp, "FONT_DESCENT %d\n", fip->fontDescent );
973 k = sprintf( bufp, "DEFAULT_CHAR %d\n", fip->chDefault );
976 for ( i = 0; i < fplistNum; i++ ) {
977 if ( wkp->indirect == TRUE ) {
978 k = sprintf( bufp, "%s \"%s\"\n", wkp->name, wkp->value );
981 k = sprintf( bufp, "%s %d\n", wkp->name, wkp->value );
986 k = sprintf( bufp, "ENDPROPERTIES\n" );
989 fprintf( stdout, "%s", buf );
995 /* output to font property information of pcf fontpcf */
1004 k = sprintf( bufp, "STARTPROPERTIES %d\n", pcf->nprops+3 );
1006 k = sprintf( bufp, "FONT_ASCENT %d\n",
1007 (pcf->info.fontAscent >= pcf->info.maxbounds.metrics.ascent)
1008 ? pcf->info.fontAscent : pcf->info.maxbounds.metrics.ascent
1011 k = sprintf( bufp, "FONT_DESCENT %d\n",
1012 (pcf->info.fontDescent >= pcf->info.maxbounds.metrics.descent)
1013 ? pcf->info.fontDescent : pcf->info.maxbounds.metrics.descent
1016 k = sprintf( bufp, "DEFAULT_CHAR %d\n", pcf->info.chDefault );
1019 for ( i = 0; i < pcf->nprops; i++ ) {
1020 if ( pcf->isStringProp[i] ) {
1021 k = sprintf(bufp,"%s \"%s\"\n",
1022 pcf->string + wkp->name, pcf->string + wkp->value
1026 k = sprintf(bufp,"%s %d\n",
1027 pcf->string + wkp->name, wkp->value
1033 k = sprintf( bufp, "ENDPROPERTIES\n" );
1036 fprintf( stdout,"%s",buf );
1044 * output to character information and patern
1048 pCHARS(fip,cip,glyphPtr,charNum,glyphPad)
1052 unsigned int charNum;
1053 unsigned int glyphPad;
1058 unsigned int frow, lrow, row, fcol, lcol, col;
1059 unsigned int bbw, bbh;
1063 fprintf( stdout, "CHARS %d\n", charNum );
1065 frow = fip->firstRow;
1066 lrow = fip->lastRow;
1067 fcol = fip->firstCol;
1068 lcol = fip->lastCol;
1073 for ( i = 0; i < 256; i++ ) {
1077 for ( row = frow; row <= lrow; row++ ) {
1078 for ( col = fcol; col <= lcol; col++ ) {
1079 if ( wkp->exists == FALSE ) {
1083 fprintf( stdout, "STARTCHAR %.2x%.2x\n", row,col );
1084 fprintf( stdout, "ENCODING %d\n", (row << 8) + col );
1085 fprintf( stdout, "SWIDTH 256 0\nDWIDTH %d %d\n",
1086 wkp->metrics.characterWidth,0 );
1087 bbw = wkp->metrics.rightSideBearing
1088 - wkp->metrics.leftSideBearing;
1089 bbh = wkp->metrics.ascent + wkp->metrics.descent;
1090 fprintf( stdout, "BBX %d %d %d %d\nBITMAP\n", bbw, bbh,
1091 wkp->metrics.leftSideBearing,
1092 - ( wkp->metrics.descent ));
1093 bml = (bbw + 7) / 8;
1094 for ( i = 0; i < bbh; i++ ) {
1096 for ( j = 0; j < bml; j++ ) {
1097 sprintf( bufp, "%s", cvtp[(unsigned char)glyph[j]] );
1100 fprintf( stdout, "%.*s\n", bml*2, buf );
1103 fprintf( stdout,"ENDCHAR\n" );
1112 * output to character information and patern
1116 pfixCHARS(fip,cip,glyphPtr,charNum,glyphPad)
1120 unsigned int charNum;
1121 unsigned int glyphPad;
1124 register int i, j, k;
1125 unsigned int frow,lrow,fcol,lcol;
1126 register int row, col;
1127 unsigned int bbw, bbh, bbox, bboy;
1128 unsigned int xd, yd;
1130 register char *glyph;
1131 char fixbuf[240], *fixbufp;
1134 fprintf( stdout,"CHARS %d\n",charNum );
1136 for ( i = 0; i < 256; i++ ) {
1140 frow = fip->firstRow;
1141 lrow = fip->lastRow;
1142 fcol = fip->firstCol;
1143 lcol = fip->lastCol;
1144 xd = cip->metrics.characterWidth;
1146 bbw = cip->metrics.rightSideBearing - cip->metrics.leftSideBearing;
1147 bbh = cip->metrics.ascent + cip->metrics.descent;
1148 bbox = cip->metrics.leftSideBearing;
1149 bboy = -(cip->metrics.descent);
1152 fixdl = sprintf( fixbufp, "SWIDTH 256 0\nDWIDTH %d %d\n", xd, yd );
1154 k = sprintf(fixbufp,"BBX %d %d %d %d\nBITMAP\n",
1155 bbw, bbh, bbox, bboy
1159 bml = (bbw + 7) / 8;
1162 for ( row = frow; row <= lrow; row++ ) {
1163 for ( col = fcol; col <= lcol; col++ ) {
1164 if ( wkp->exists == FALSE ) {
1169 memcpy(bufp,"STARTCHAR ",10);
1171 memcpy(bufp,cvtp[row],2);
1173 memcpy(bufp,cvtp[col],3);
1175 memcpy(bufp,"ENCODING ",9);
1177 k = sprintf(bufp,"%d\n",(row << 8) + col);
1179 memcpy(bufp,fixbuf,fixdl);
1181 for (i = 0; i < bbh; i++) {
1182 for (j = 0; j < bml; j++) {
1183 memcpy(bufp, cvtp[(unsigned char)glyph[j]],3);
1189 memcpy( bufp, "ENDCHAR\n", 8 );
1192 fprintf( stdout, "%s", buf );
1201 putPtn( bits, width, height)
1202 unsigned char *bits; /* 1 byte boundary , no byte swap data */
1208 bytewidth = ( width + 7) / 8;
1210 for ( i = height; i-- > 0;) {
1211 for ( j = bytewidth; j-- > 0; bits++) {
1212 fprintf(stdout, "%.2x", *bits);
1214 fprintf(stdout, "\n");
1239 *(p + 1) = *(p + 2);
1245 static unsigned char _reverse_byte[0x100] = {
1246 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
1247 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
1248 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
1249 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
1250 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
1251 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
1252 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
1253 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
1254 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
1255 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
1256 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
1257 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
1258 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
1259 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
1260 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
1261 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
1262 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
1263 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
1264 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
1265 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
1266 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
1267 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
1268 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
1269 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
1270 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
1271 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
1272 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
1273 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
1274 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
1275 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
1276 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
1277 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
1281 BitOrderInvert(buf, nbytes)
1282 register unsigned char *buf;
1283 register int nbytes;
1285 register unsigned char *rev = _reverse_byte;
1287 for (; --nbytes >= 0; buf++)
1292 invertBits( src, format, width, height, dest)
1298 int bit, byte, glyph, scan;
1299 int src_bytewidth, dest_bytewidth;
1303 bit = PCF_BIT_ORDER( format);
1304 byte = PCF_BYTE_ORDER( format);
1305 glyph = PCF_GLYPH_PAD( format);
1306 scan = PCF_SCAN_UNIT( format);
1308 src_bytewidth = (( width + ( 8 * glyph ) - 1)/( 8 * glyph)) * glyph;
1309 dest_bytewidth = ( width + 7) /8;
1311 for ( i = 0; i < height; i++, src += src_bytewidth,
1312 dest += dest_bytewidth) {
1313 for ( j = 0; j < src_bytewidth; j += scan) {
1314 memcpy( work, src + j, scan);
1315 if ( bit == LSBFirst)
1316 BitOrderInvert( (unsigned char *)work, scan);
1317 if ( byte == LSBFirst)
1318 ByteSwap( work, scan);
1319 if (( j + scan) >= dest_bytewidth) {
1320 memcpy( dest + j, work, dest_bytewidth - j);
1323 memcpy( dest + j, work, scan);
1330 pCHARS_pcf (pcf, fix)
1336 int ptn_width, ptn_height;
1337 int bmp_width, bmp_height;
1344 int bmp_adj, ptn_adj;
1347 INT16 bl, br, ba, bd, bdw ;
1348 unsigned char cl, cr, ca, cd, cdw ;
1349 unsigned char *comp ;
1350 int bbw, bbh, bbx, bby, dwidth ;
1352 fprintf(stdout,"CHARS %d\n",pcf->nbitmaps);
1354 row_width = pcf->info.lastCol - pcf->info.firstCol + 1;
1355 nencoding = row_width * (pcf->info.lastRow - pcf->info.firstRow + 1);
1358 bmp_width = pcf->info.maxbounds.metrics.leftSideBearing
1359 + pcf->info.maxbounds.metrics.rightSideBearing ;
1360 bmp_height = pcf->info.fontAscent + pcf->info.fontDescent ;
1361 ptn_width = bmp_width ;
1362 ptn_height = pcf->info.maxbounds.metrics.ascent +
1363 pcf->info.maxbounds.metrics.descent;
1365 if (!(bmp_ptn = make_toptn( ptn_width, ptn_height)))
1368 if ( ( adj_hi = pcf->info.fontAscent - pcf->info.maxbounds.metrics.ascent ) > 0) {
1369 width_bytes = 8 * PCF_GLYPH_PAD( pcf->bmp_fmt);
1370 width_bytes = (( width_bytes + bmp_width - 1)/width_bytes) * PCF_GLYPH_PAD( pcf->bmp_fmt);
1371 bmp_adj = width_bytes * adj_hi;
1373 if (( cpy_height = bmp_height - adj_hi) > ptn_height)
1374 cpy_height = ptn_height ;
1375 } else if ( adj_hi < 0) {
1377 width_bytes = ( ptn_width + 7) / 8;
1379 ptn_adj = width_bytes * adj_hi;
1380 if (( cpy_height = ptn_height - adj_hi) > bmp_height)
1381 cpy_height = bmp_height ;
1385 cpy_height = ptn_height ;
1390 for ( encoding = 0; encoding < nencoding; encoding++) {
1391 if(fix == TRUE) memset( bmp_ptn, '\0', (ptn_width + 7)/8 * ptn_height);
1392 encodingOffset = getINT16( (unsigned char *)(pcf->encodingOffsets + encoding), pcf->enc_fmt);
1393 if (encodingOffset == 0xFFFF) continue;
1395 row = pcf->info.firstRow + encoding / row_width;
1396 col = pcf->info.firstCol + encoding % row_width;
1398 fprintf(stdout,"STARTCHAR %s\n",pcf->glyph_name +
1399 getINT32( (unsigned char*)&pcf->glyph_offset[encodingOffset],
1401 fprintf(stdout,"ENCODING %d\n",(row << 8) + col);
1403 fprintf( stdout,"SWIDTH %d 0\n", getINT32( (unsigned char*)(pcf->swidth + encodingOffset), pcf->swd_fmt) );
1405 if( pcf->compress ){
1406 comp = (unsigned char*)pcf->metrics +
1407 encodingOffset * SIZEOF_COMPRESSED_METRIC ;
1408 cl = getINT8( comp ) ;
1409 cr = getINT8( comp ) ;
1410 cdw = getINT8( comp ) ;
1411 ca = getINT8( comp ) ;
1412 cd = getINT8( comp ) ;
1414 dwidth = (int)(cdw - 0x80) ;
1415 bbw = (int)((cr - 0x80) - (cl - 0x80)) ;
1416 bbh = (int)((ca - 0x80) + (cd - 0x80)) ;
1417 bbx = (int)(cl - 0x80) ;
1418 bby = (int)( -(cd - 0x80) ) ;
1420 bl = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].leftSideBearing, pcf->mtr_fmt ) ;
1421 br = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].rightSideBearing, pcf->mtr_fmt ) ;
1422 bdw = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].characterWidth, pcf->mtr_fmt ) ;
1423 ba = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].ascent, pcf->mtr_fmt ) ;
1424 bd = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].descent, pcf->mtr_fmt ) ;
1431 fprintf( stdout,"DWIDTH %d 0\n", dwidth ) ;
1432 fprintf( stdout,"BBX %d %d %d %d\nBITMAP\n", bbw, bbh, bbx, bby ) ;
1434 if( fix == FALSE ) {
1435 bmp_width = pcf->info.maxbounds.metrics.leftSideBearing
1436 + pcf->info.maxbounds.metrics.rightSideBearing ;
1437 bmp_height = pcf->info.fontAscent + pcf->info.fontDescent ;
1441 if (!(bmp_ptn = make_toptn( ptn_width, ptn_height)))
1444 if ( ( adj_hi = pcf->info.fontAscent - pcf->info.maxbounds.metrics.ascent ) > 0) {
1445 width_bytes = 8 * PCF_GLYPH_PAD( pcf->bmp_fmt);
1446 width_bytes = (( width_bytes + bmp_width - 1)/width_bytes) * PCF_GLYPH_PAD( pcf->bmp_fmt);
1447 bmp_adj = width_bytes * adj_hi;
1449 if (( cpy_height = bmp_height - adj_hi) > ptn_height)
1450 cpy_height = ptn_height ;
1451 } else if ( adj_hi < 0) {
1453 width_bytes = ( ptn_width + 7) / 8;
1455 ptn_adj = width_bytes * adj_hi;
1456 if (( cpy_height = ptn_height - adj_hi) > bmp_height)
1457 cpy_height = bmp_height ;
1461 cpy_height = ptn_height ;
1463 memset( bmp_ptn, '\0', (ptn_width + 7)/8 * ptn_height);
1466 bitmap = pcf->bitmaps + getINT32( (unsigned char *)(pcf->offsets + encodingOffset),
1468 invertBits( bitmap + bmp_adj, pcf->bmp_fmt, ptn_width, cpy_height, bmp_ptn + ptn_adj);
1469 putPtn( (unsigned char *)bmp_ptn, ptn_width, ptn_height );
1470 fprintf(stdout,"ENDCHAR\n");
1471 if( fix == FALSE ) free(bmp_ptn);
1473 if( fix == TRUE ) free(bmp_ptn);
1478 make_toptn( width, height)
1483 byte_width = (width + 7)/8;
1485 return (char *)malloc( byte_width * height);
1492 getarg(argc,argv,fname,bitorder,byteorder,scanunit,glyphPad,outLevel,fix)
1506 char *usage="dtgpftobdf [-H] [-V] [-help] font_file_name";
1508 *glyphPad = DEFAULTGLPAD;
1509 *bitorder = DEFAULTBITORDER;
1510 *scanunit = DEFAULTSCANUNIT;
1511 *byteorder = DEFAULTBYTEORDER;
1516 for (i = 1; i < argc; i++ ) {
1522 *glyphPad = atoi(arg+1) ;
1523 if (*glyphPad != 1 &&
1527 USAGE("dtgpftobdf : illegal padding number (1/2/4/8)\n");
1535 USAGE1("usage: %s\n",usage);
1541 USAGE1("dtgpftobdf : illegal option -- %s\n",arg);
1542 USAGE1("usage: %s\n",usage);
1547 if (already == FALSE) {
1551 USAGE1("dtgpftobdf : extra parameter --- %s\n",arg);
1552 USAGE1("usage: %s\n", usage );
1557 if (already == FALSE) {
1558 USAGE("dtgpftobdf : require file name\n");
1559 USAGE1("usage: %s\n",usage);