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: 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 void getMetric() ;
120 static Bool getAccel() ;
121 static Bool getProperties() ;
122 static void putPtn() ;
123 static void ByteSwap() ;
124 static void 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 snprintf( tmbuf, sizeof(tmbuf), "%s", 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" );
397 USAGE("dtgpftobdf: can't read file\n" );
407 #define getINT8( p ) ( *p++ ) ;
416 c |= (CARD32)(*p++) << 8;
417 c |= (CARD32)(*p++) << 16;
418 c |= (CARD32)(*p) << 24;
425 getINT32( p, format )
431 if ( PCF_BYTE_ORDER(format) == MSBFirst ) {
432 c = (CARD32)(*p++) << 24;
433 c |= (CARD32)(*p++) << 16;
434 c |= (CARD32)(*p++) << 8;
438 c |= (CARD32)(*p++) << 8;
439 c |= (CARD32)(*p++) << 16;
440 c |= (CARD32)(*p) << 24;
447 getINT16( p, format )
453 if ( PCF_BYTE_ORDER(format) == MSBFirst ) {
454 c = (CARD32)(*p++) << 8;
458 c |= (CARD32)(*p) << 8;
465 seekToType( tables, ntables, type, formatp, sizep, offsetp)
475 for ( i = 0; i < ntables; i++ ) {
476 if ( getLSB32( (unsigned char *)&tables[i].type) == type) {
477 *formatp = getLSB32( (unsigned char *)&tables[i].format);
478 *sizep = getLSB32( (unsigned char *)&tables[i].size);
479 *offsetp = getLSB32( (unsigned char *)&tables[i].offset);
488 getMetric( buf, format, metric )
493 metric->leftSideBearing = getINT16( (unsigned char *)buf, format);
495 metric->rightSideBearing = getINT16( (unsigned char *)buf, format);
497 metric->characterWidth = getINT16( (unsigned char *)buf, format);
499 metric->ascent = getINT16( (unsigned char *)buf, format);
501 metric->descent = getINT16( (unsigned char *)buf, format);
503 metric->attributes = getINT16( (unsigned char *)buf, format);
508 getAccel( pFontInfo, maxink, buf_top, tables, ntables, type )
509 FontInfoPtr pFontInfo;
521 if ( !seekToType( tables, ntables, type, &format, &size, &offset)) {
525 buffer = buf_top + offset;
526 format = getLSB32( (unsigned char *)buffer);
528 if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT )
529 && !PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS )
533 pFontInfo->noOverlap = *buffer++;
534 pFontInfo->constantMetrics = *buffer++;
535 pFontInfo->terminalFont = *buffer++;
536 pFontInfo->constantWidth = *buffer++;
537 pFontInfo->inkInside = *buffer++;
538 pFontInfo->inkMetrics = *buffer++;
539 pFontInfo->drawDirection = *buffer++;
540 /* natural alignment */
544 pFontInfo->fontAscent = getINT32( (unsigned char *)buffer, format);
547 pFontInfo->fontDescent = getINT32((unsigned char *)buffer, format);
552 getMetric(buffer, format, &pFontInfo->minbounds.metrics);
555 getMetric(buffer, format, &pFontInfo->maxbounds.metrics);
558 if ( PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) ) {
560 getMetric( buffer, format, maxink);
562 *maxink = pFontInfo->maxbounds.metrics;
569 getProperties( pcf, buf_top, tables, ntables)
581 if ( !seekToType( tables, ntables, (CARD32)PCF_PROPERTIES, &format, &size, &offset ) ) {
585 buffer = buf_top + offset;
586 format = getLSB32( (unsigned char *)buffer );
588 if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
591 pcf->nprops = getINT32((unsigned char *)buffer, format);
594 if ( !( pcf->props = ( FontPropPtr )malloc( pcf->nprops * sizeof( FontPropRec ) ) ) ) {
598 if ( !( pcf->isStringProp = ( char * )malloc(pcf->nprops * sizeof( char ) ) ) ) {
602 for ( i = 0; i < pcf->nprops; i++ ) {
603 pcf->props[i].name = getINT32((unsigned char *)buffer, format);
605 pcf->isStringProp[i] = *buffer++;
606 pcf->props[i].value = getINT32((unsigned char *)buffer, format);
609 if ( pcf->nprops & 3 ) {
610 i = 4 - (pcf->nprops & 3);
614 pcf->str_length = getINT32((unsigned char *)buffer, format);
617 pcf->string = (char *)buffer;
623 openPcfFont( fontname )
636 pcf_tmp = ( PcfTmp * )calloc( 1, sizeof( PcfTmp ) );
638 USAGE("dtgpftobdf : calloc() error.\n" ) ;
642 if ( stat( fontname, &st ) ) {
646 if ( ( pcf_tmp->pcf_buffer = readfontfile( fontname)) == (char *)-1 ) {
650 pcf_tmp->pcf_bufsz = st.st_size;
652 if ( (format = getLSB32( (unsigned char *)pcf_tmp->pcf_buffer )) != PCF_FILE_VERSION ) {
653 USAGE1("dtgpftobdf : pcf file version(0x%x) error.\n", format ) ;
657 pcf_tmp->ntables = getLSB32( (unsigned char *)(pcf_tmp->pcf_buffer + 4) );
658 pcf_tmp->tables = (PCFTablePtr)(pcf_tmp->pcf_buffer + 8 );
661 &pcf_tmp->info, &maxink, pcf_tmp->pcf_buffer,
662 pcf_tmp->tables, pcf_tmp->ntables, (CARD32)PCF_BDF_ACCELERATORS
666 &pcf_tmp->info, &maxink, pcf_tmp->pcf_buffer,
667 pcf_tmp->tables, pcf_tmp->ntables, (CARD32)PCF_ACCELERATORS
670 USAGE("dtgpftobdf : Cannot get accelerators.\n" ) ;
676 pcf_tmp, pcf_tmp->pcf_buffer,
677 pcf_tmp->tables, pcf_tmp->ntables
680 USAGE("dtgpftobdf : getProperties error.\n" ) ;
684 pcf_tmp->tables, pcf_tmp->ntables,
685 (CARD32)PCF_BITMAPS, &format, &size, &offset
688 USAGE("dtgpftobdf : PCF_BITMAPS error.\n" ) ;
692 buffp = pcf_tmp->pcf_buffer + offset;
694 format = getLSB32( (unsigned char *)buffp);
697 if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
698 USAGE("dtgpftobdf : error.!PCF_FORMAT_MATCH(PCF_BITMAPS)\n" ) ;
702 pcf_tmp->nbitmaps = getINT32( (unsigned char *)buffp, format);
704 pcf_tmp->offsets = (CARD32 *)buffp;
705 buffp += sizeof( *pcf_tmp->offsets) * pcf_tmp->nbitmaps;
708 bitmapSizes = (CARD32 *)buffp;
710 = getINT32( (unsigned char *)&bitmapSizes[PCF_GLYPH_PAD_INDEX(format)], format);
711 pcf_tmp->bmp_fmt = format;
712 buffp += sizeof( *bitmapSizes) * GLYPHPADOPTIONS;
713 pcf_tmp->bitmaps = buffp;
714 buffp += pcf_tmp->sizebitmaps;
717 pcf_tmp->tables, pcf_tmp->ntables,
718 (CARD32)PCF_BDF_ENCODINGS, &format, &size, &offset
721 USAGE("dtgpftobdf : error.(PCF_BDF_ENCODINGS)\n" ) ;
725 buffp = pcf_tmp->pcf_buffer + offset;
726 format = getLSB32( (unsigned char *)buffp);
728 if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
729 USAGE("dtgpftobdf : error.!PCF_FORMAT_MATCH(PCF_BDF_ENCODINGS)\n" ) ;
733 pcf_tmp->info.firstCol = getINT16( (unsigned char *)buffp, format);
735 pcf_tmp->info.lastCol = getINT16( (unsigned char *)buffp, format);
737 pcf_tmp->info.firstRow = getINT16( (unsigned char *)buffp, format);
739 pcf_tmp->info.lastRow = getINT16( (unsigned char *)buffp, format);
741 pcf_tmp->info.chDefault = getINT16( (unsigned char *)buffp, format);
744 pcf_tmp->info.allExist = FALSE;
745 pcf_tmp->enc_fmt = format;
746 pcf_tmp->encodingOffsets = (CARD16 *)buffp;
749 * get scale width infomations
752 pcf_tmp->tables, pcf_tmp->ntables,
753 (CARD32)PCF_SWIDTHS, &format, &size, &offset
759 buffp = pcf_tmp->pcf_buffer + offset;
760 format = getLSB32( (unsigned char*)buffp);
762 if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
765 pcf_tmp->swd_fmt = (CARD32)format ;
766 pcf_tmp->swd_num = getINT32( (unsigned char*)buffp, format ) ;
769 pcf_tmp->swidth = (CARD32 *)buffp ;
775 pcf_tmp->tables, pcf_tmp->ntables,
776 (CARD32)PCF_GLYPH_NAMES, &format, &size, &offset
782 buffp = pcf_tmp->pcf_buffer + offset;
783 format = getLSB32( (unsigned char*)buffp);
785 if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
788 pcf_tmp->glyphs = getINT32( (unsigned char*)buffp, format ) ;
790 pcf_tmp->glyph_offset = (int *)buffp ;
791 buffp += 4 * (pcf_tmp->glyphs + 1) ;
792 pcf_tmp->glyph_name = (char *)buffp ;
793 pcf_tmp->glyph_fmt = (CARD32)format ;
799 pcf_tmp->tables, pcf_tmp->ntables,
800 (CARD32)PCF_METRICS, &format, &size, &offset
806 buffp = pcf_tmp->pcf_buffer + offset;
807 format = getLSB32( (unsigned char*)buffp);
809 if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
810 pcf_tmp->compress = 0 ;
811 pcf_tmp->mtr_num = getINT32( (unsigned char*)buffp, format ) ;
813 }else if ( PCF_FORMAT_MATCH( format, PCF_COMPRESSED_METRICS ) ) {
814 pcf_tmp->compress = 1 ;
815 pcf_tmp->mtr_num = (int)getINT16( (unsigned char*)buffp, format ) ;
820 pcf_tmp->metrics = (xCharInfo *)buffp ;
821 pcf_tmp->mtr_fmt = (CARD32)format ;
834 Anafprop(fip,fpropPtr,fpropvnPtr,fontname,ps,res,fplistPtr,fplistNum)
836 FontPropRec *fpropPtr;
839 FontPropRec **fplistPtr;
842 unsigned int *fplistNum;
844 FontPropRec *wkp ,*wklp;
848 *fplistNum = fip->nProps - 1;
849 *fplistPtr = (FontPropRec *)malloc(*fplistNum * sizeof(FontPropRec));
852 for (i = 0; i < fip->nProps; i++) {
853 fpnp = fpropvnPtr + wkp->name;
855 if ((fpnL == 4) && (strncmp(fpnp,"FONT",4) == 0)) {
856 *fontname = fpropvnPtr + wkp->value;
861 if (strncmp(fpnp,"POINT_SIZE",10) == 0) {
862 ps->value = wkp->value;
864 if (strncmp(fpnp,"RESOLUTION",10) == 0) {
865 res->value = wkp->value;
868 wklp->name = (CARD32) (intptr_t) fpropvnPtr + wkp->name;
869 if (wkp->indirect == TRUE) {
870 wklp->value = (INT32) (intptr_t) fpropvnPtr + wkp->value;
872 wklp->value = wkp->value;
874 wklp->indirect = wkp->indirect;
883 setProp( pcf, proptmp )
890 for ( i = 0; i < pcf->nprops; i++ ) {
891 fpnp = pcf->string + pcf->props[i].name;
893 if ( ( fpnL == 4 ) && ( strncmp( fpnp,"FONT", 4 ) == 0 ) ) {
894 proptmp->font_name = pcf->string + pcf->props[i].value;
898 if ( strncmp( fpnp,"POINT_SIZE", 10 ) == 0 ) {
899 proptmp->psize.value = pcf->props[i].value;
900 } else if ( strncmp( fpnp, "RESOLUTION", 10 ) == 0 ) {
901 proptmp->resolution.value = pcf->props[i].value;
910 * output to SIZE (SIZE point resolutionX resolutionY)
915 FontPropRec *ps, *res;
919 char buf1[16], buf2[16];
921 f = ps->value / 10.0;
922 if ( ( ps->value % 10 ) != 0 ) {
923 sprintf( buf1, "%.1f", f );
925 sprintf( buf1, "%.0f", f );
927 k = ( ( res->value * 72.27 ) / 100.0 ) + 1;
928 sprintf( buf2, "%d %d", k, k );
929 fprintf( stdout, "SIZE %s %s\n", buf1, buf2 );
934 /* output to SIZE of pcf font */
942 char buf1[16],buf2[16];
944 f = proptmp->psize.value / 10.0;
945 if ( ( proptmp->psize.value % 10 ) != 0 ) {
946 snprintf( buf1, sizeof(buf1), "%.1f",f );
948 snprintf( buf1, sizeof(buf1), "%.0f",f);
950 k = ( ( proptmp->resolution.value * 72.27 ) / 100.0 ) + 1;
951 snprintf( buf2, sizeof(buf2), "%d %d", k, k );
952 fprintf( stdout,"SIZE %s %s\n", buf1, buf2 );
959 pPROPS( fip,fplistPtr,fplistNum )
961 FontPropRec *fplistPtr;
962 unsigned int fplistNum;
968 k = snprintf( bufp, sizeof(buf), "STARTPROPERTIES %d\n", fplistNum+3 );
970 k = snprintf( bufp, sizeof(buf) - (bufp - buf), "FONT_ASCENT %d\n", fip->fontAscent );
972 k = snprintf( bufp, sizeof(buf) - (bufp - buf), "FONT_DESCENT %d\n", fip->fontDescent );
974 k = snprintf( bufp, sizeof(buf) - (bufp - buf), "DEFAULT_CHAR %d\n", fip->chDefault );
977 for ( i = 0; i < fplistNum; i++ ) {
978 if ( wkp->indirect == TRUE ) {
979 k = snprintf( bufp, sizeof(buf) - (bufp - buf), "%s \"%s\"\n", (char *) (intptr_t) wkp->name, (char *) (intptr_t) wkp->value );
982 k = snprintf( bufp, sizeof(buf) - (bufp - buf), "%s %d\n", (char *) (intptr_t) wkp->name, wkp->value );
987 k = snprintf( bufp, sizeof(buf) - (bufp - buf), "ENDPROPERTIES\n" );
990 fprintf( stdout, "%s", buf );
996 /* output to font property information of pcf fontpcf */
1005 k = sprintf( bufp, "STARTPROPERTIES %d\n", pcf->nprops+3 );
1007 k = sprintf( bufp, "FONT_ASCENT %d\n",
1008 (pcf->info.fontAscent >= pcf->info.maxbounds.metrics.ascent)
1009 ? pcf->info.fontAscent : pcf->info.maxbounds.metrics.ascent
1012 k = sprintf( bufp, "FONT_DESCENT %d\n",
1013 (pcf->info.fontDescent >= pcf->info.maxbounds.metrics.descent)
1014 ? pcf->info.fontDescent : pcf->info.maxbounds.metrics.descent
1017 k = sprintf( bufp, "DEFAULT_CHAR %d\n", pcf->info.chDefault );
1020 for ( i = 0; i < pcf->nprops; i++ ) {
1021 if ( pcf->isStringProp[i] ) {
1022 k = sprintf(bufp,"%s \"%s\"\n",
1023 pcf->string + wkp->name, pcf->string + wkp->value
1027 k = sprintf(bufp,"%s %d\n",
1028 pcf->string + wkp->name, wkp->value
1034 k = sprintf( bufp, "ENDPROPERTIES\n" );
1037 fprintf( stdout,"%s",buf );
1045 * output to character information and patern
1049 pCHARS(fip,cip,glyphPtr,charNum,glyphPad)
1053 unsigned int charNum;
1054 unsigned int glyphPad;
1059 unsigned int frow, lrow, row, fcol, lcol, col;
1060 unsigned int bbw, bbh;
1064 fprintf( stdout, "CHARS %d\n", charNum );
1066 frow = fip->firstRow;
1067 lrow = fip->lastRow;
1068 fcol = fip->firstCol;
1069 lcol = fip->lastCol;
1074 for ( i = 0; i < 256; i++ ) {
1078 for ( row = frow; row <= lrow; row++ ) {
1079 for ( col = fcol; col <= lcol; col++ ) {
1080 if ( wkp->exists == FALSE ) {
1084 fprintf( stdout, "STARTCHAR %.2x%.2x\n", row,col );
1085 fprintf( stdout, "ENCODING %d\n", (row << 8) + col );
1086 fprintf( stdout, "SWIDTH 256 0\nDWIDTH %d %d\n",
1087 wkp->metrics.characterWidth,0 );
1088 bbw = wkp->metrics.rightSideBearing
1089 - wkp->metrics.leftSideBearing;
1090 bbh = wkp->metrics.ascent + wkp->metrics.descent;
1091 fprintf( stdout, "BBX %d %d %d %d\nBITMAP\n", bbw, bbh,
1092 wkp->metrics.leftSideBearing,
1093 - ( wkp->metrics.descent ));
1094 bml = (bbw + 7) / 8;
1095 for ( i = 0; i < bbh; i++ ) {
1097 for ( j = 0; j < bml; j++ ) {
1098 sprintf( bufp, "%s", (char *) cvtp[(unsigned char)glyph[j]] );
1101 fprintf( stdout, "%.*s\n", bml*2, buf );
1104 fprintf( stdout,"ENDCHAR\n" );
1113 * output to character information and patern
1117 pfixCHARS(fip,cip,glyphPtr,charNum,glyphPad)
1121 unsigned int charNum;
1122 unsigned int glyphPad;
1125 register int i, j, k;
1126 unsigned int frow,lrow,fcol,lcol;
1127 register int row, col;
1128 unsigned int bbw, bbh, bbox, bboy;
1129 unsigned int xd, yd;
1131 register char *glyph;
1132 char fixbuf[240], *fixbufp;
1135 fprintf( stdout,"CHARS %d\n",charNum );
1137 for ( i = 0; i < 256; i++ ) {
1141 frow = fip->firstRow;
1142 lrow = fip->lastRow;
1143 fcol = fip->firstCol;
1144 lcol = fip->lastCol;
1145 xd = cip->metrics.characterWidth;
1147 bbw = cip->metrics.rightSideBearing - cip->metrics.leftSideBearing;
1148 bbh = cip->metrics.ascent + cip->metrics.descent;
1149 bbox = cip->metrics.leftSideBearing;
1150 bboy = -(cip->metrics.descent);
1153 fixdl = sprintf( fixbufp, "SWIDTH 256 0\nDWIDTH %d %d\n", xd, yd );
1155 k = sprintf(fixbufp,"BBX %d %d %d %d\nBITMAP\n",
1156 bbw, bbh, bbox, bboy
1160 bml = (bbw + 7) / 8;
1163 for ( row = frow; row <= lrow; row++ ) {
1164 for ( col = fcol; col <= lcol; col++ ) {
1165 if ( wkp->exists == FALSE ) {
1170 memcpy(bufp,"STARTCHAR ",10);
1172 memcpy(bufp,cvtp[row],2);
1174 memcpy(bufp,cvtp[col],3);
1176 memcpy(bufp,"ENCODING ",9);
1178 k = sprintf(bufp,"%d\n",(row << 8) + col);
1180 memcpy(bufp,fixbuf,fixdl);
1182 for (i = 0; i < bbh; i++) {
1183 for (j = 0; j < bml; j++) {
1184 memcpy(bufp, cvtp[(unsigned char)glyph[j]],3);
1190 memcpy( bufp, "ENDCHAR\n", 8 );
1193 fprintf( stdout, "%s", buf );
1202 putPtn( bits, width, height)
1203 unsigned char *bits; /* 1 byte boundary , no byte swap data */
1209 bytewidth = ( width + 7) / 8;
1211 for ( i = height; i-- > 0;) {
1212 for ( j = bytewidth; j-- > 0; bits++) {
1213 fprintf(stdout, "%.2x", *bits);
1215 fprintf(stdout, "\n");
1240 *(p + 1) = *(p + 2);
1246 static unsigned char _reverse_byte[0x100] = {
1247 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
1248 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
1249 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
1250 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
1251 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
1252 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
1253 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
1254 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
1255 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
1256 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
1257 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
1258 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
1259 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
1260 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
1261 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
1262 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
1263 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
1264 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
1265 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
1266 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
1267 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
1268 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
1269 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
1270 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
1271 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
1272 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
1273 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
1274 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
1275 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
1276 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
1277 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
1278 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
1282 BitOrderInvert(buf, nbytes)
1283 register unsigned char *buf;
1284 register int nbytes;
1286 register unsigned char *rev = _reverse_byte;
1288 for (; --nbytes >= 0; buf++)
1293 invertBits( src, format, width, height, dest)
1299 int bit, byte, glyph, scan;
1300 int src_bytewidth, dest_bytewidth;
1304 bit = PCF_BIT_ORDER( format);
1305 byte = PCF_BYTE_ORDER( format);
1306 glyph = PCF_GLYPH_PAD( format);
1307 scan = PCF_SCAN_UNIT( format);
1309 src_bytewidth = (( width + ( 8 * glyph ) - 1)/( 8 * glyph)) * glyph;
1310 dest_bytewidth = ( width + 7) /8;
1312 for ( i = 0; i < height; i++, src += src_bytewidth,
1313 dest += dest_bytewidth) {
1314 for ( j = 0; j < src_bytewidth; j += scan) {
1315 memcpy( work, src + j, scan);
1316 if ( bit == LSBFirst)
1317 BitOrderInvert( (unsigned char *)work, scan);
1318 if ( byte == LSBFirst)
1319 ByteSwap( work, scan);
1320 if (( j + scan) >= dest_bytewidth) {
1321 memcpy( dest + j, work, dest_bytewidth - j);
1324 memcpy( dest + j, work, scan);
1331 pCHARS_pcf (pcf, fix)
1335 char *bmp_ptn = NULL;
1336 char *bitmap = NULL;
1337 int ptn_width = 0, ptn_height = 0;
1338 int bmp_width = 0, bmp_height = 0;
1345 int bmp_adj = 0, ptn_adj = 0;
1348 INT16 bl, br, ba, bd, bdw ;
1349 unsigned char cl, cr, ca, cd, cdw ;
1350 unsigned char *comp ;
1351 int bbw, bbh, bbx, bby, dwidth ;
1353 fprintf(stdout,"CHARS %d\n",pcf->nbitmaps);
1355 row_width = pcf->info.lastCol - pcf->info.firstCol + 1;
1356 nencoding = row_width * (pcf->info.lastRow - pcf->info.firstRow + 1);
1359 bmp_width = pcf->info.maxbounds.metrics.leftSideBearing
1360 + pcf->info.maxbounds.metrics.rightSideBearing ;
1361 bmp_height = pcf->info.fontAscent + pcf->info.fontDescent ;
1362 ptn_width = bmp_width ;
1363 ptn_height = pcf->info.maxbounds.metrics.ascent +
1364 pcf->info.maxbounds.metrics.descent;
1366 if (!(bmp_ptn = make_toptn( ptn_width, ptn_height)))
1369 if ( ( adj_hi = pcf->info.fontAscent - pcf->info.maxbounds.metrics.ascent ) > 0) {
1370 width_bytes = 8 * PCF_GLYPH_PAD( pcf->bmp_fmt);
1371 width_bytes = (( width_bytes + bmp_width - 1)/width_bytes) * PCF_GLYPH_PAD( pcf->bmp_fmt);
1372 bmp_adj = width_bytes * adj_hi;
1374 if (( cpy_height = bmp_height - adj_hi) > ptn_height)
1375 cpy_height = ptn_height ;
1376 } else if ( adj_hi < 0) {
1378 width_bytes = ( ptn_width + 7) / 8;
1380 ptn_adj = width_bytes * adj_hi;
1381 if (( cpy_height = ptn_height - adj_hi) > bmp_height)
1382 cpy_height = bmp_height ;
1386 cpy_height = ptn_height ;
1391 for ( encoding = 0; encoding < nencoding; encoding++) {
1392 if(fix == TRUE) memset( bmp_ptn, '\0', (ptn_width + 7)/8 * ptn_height);
1393 encodingOffset = getINT16( (unsigned char *)(pcf->encodingOffsets + encoding), pcf->enc_fmt);
1394 if (encodingOffset == 0xFFFF) continue;
1396 row = pcf->info.firstRow + encoding / row_width;
1397 col = pcf->info.firstCol + encoding % row_width;
1399 fprintf(stdout,"STARTCHAR %s\n",pcf->glyph_name +
1400 getINT32( (unsigned char*)&pcf->glyph_offset[encodingOffset],
1402 fprintf(stdout,"ENCODING %d\n",(row << 8) + col);
1404 fprintf( stdout,"SWIDTH %d 0\n", getINT32( (unsigned char*)(pcf->swidth + encodingOffset), pcf->swd_fmt) );
1406 if( pcf->compress ){
1407 comp = (unsigned char*)pcf->metrics +
1408 encodingOffset * SIZEOF_COMPRESSED_METRIC ;
1409 cl = getINT8( comp ) ;
1410 cr = getINT8( comp ) ;
1411 cdw = getINT8( comp ) ;
1412 ca = getINT8( comp ) ;
1413 cd = getINT8( comp ) ;
1415 dwidth = (int)(cdw - 0x80) ;
1416 bbw = (int)((cr - 0x80) - (cl - 0x80)) ;
1417 bbh = (int)((ca - 0x80) + (cd - 0x80)) ;
1418 bbx = (int)(cl - 0x80) ;
1419 bby = (int)( -(cd - 0x80) ) ;
1421 bl = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].leftSideBearing, pcf->mtr_fmt ) ;
1422 br = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].rightSideBearing, pcf->mtr_fmt ) ;
1423 bdw = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].characterWidth, pcf->mtr_fmt ) ;
1424 ba = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].ascent, pcf->mtr_fmt ) ;
1425 bd = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].descent, pcf->mtr_fmt ) ;
1432 fprintf( stdout,"DWIDTH %d 0\n", dwidth ) ;
1433 fprintf( stdout,"BBX %d %d %d %d\nBITMAP\n", bbw, bbh, bbx, bby ) ;
1435 if( fix == FALSE ) {
1436 bmp_width = pcf->info.maxbounds.metrics.leftSideBearing
1437 + pcf->info.maxbounds.metrics.rightSideBearing ;
1438 bmp_height = pcf->info.fontAscent + pcf->info.fontDescent ;
1442 if (!(bmp_ptn = make_toptn( ptn_width, ptn_height)))
1445 if ( ( adj_hi = pcf->info.fontAscent - pcf->info.maxbounds.metrics.ascent ) > 0) {
1446 width_bytes = 8 * PCF_GLYPH_PAD( pcf->bmp_fmt);
1447 width_bytes = (( width_bytes + bmp_width - 1)/width_bytes) * PCF_GLYPH_PAD( pcf->bmp_fmt);
1448 bmp_adj = width_bytes * adj_hi;
1450 if (( cpy_height = bmp_height - adj_hi) > ptn_height)
1451 cpy_height = ptn_height ;
1452 } else if ( adj_hi < 0) {
1454 width_bytes = ( ptn_width + 7) / 8;
1456 ptn_adj = width_bytes * adj_hi;
1457 if (( cpy_height = ptn_height - adj_hi) > bmp_height)
1458 cpy_height = bmp_height ;
1462 cpy_height = ptn_height ;
1464 memset( bmp_ptn, '\0', (ptn_width + 7)/8 * ptn_height);
1467 bitmap = pcf->bitmaps + getINT32( (unsigned char *)(pcf->offsets + encodingOffset),
1469 /* Only do this if non-NULL... */
1472 invertBits( bitmap + bmp_adj, pcf->bmp_fmt,
1473 ptn_width, cpy_height, bmp_ptn + ptn_adj);
1474 putPtn( (unsigned char *)bmp_ptn, ptn_width, ptn_height );
1478 fprintf(stderr, "%s: bmp_ptn is NULL", __FUNCTION__);
1481 fprintf(stdout,"ENDCHAR\n");
1482 if( fix == FALSE ) free(bmp_ptn);
1484 if( fix == TRUE ) free(bmp_ptn);
1489 make_toptn( width, height)
1494 byte_width = (width + 7)/8;
1496 return (char *)malloc( byte_width * height);
1503 getarg(argc,argv,fname,bitorder,byteorder,scanunit,glyphPad,outLevel,fix)
1517 char *usage="dtgpftobdf [-H] [-V] [-help] font_file_name";
1519 *glyphPad = DEFAULTGLPAD;
1520 *bitorder = DEFAULTBITORDER;
1521 *scanunit = DEFAULTSCANUNIT;
1522 *byteorder = DEFAULTBYTEORDER;
1527 for (i = 1; i < argc; i++ ) {
1533 *glyphPad = atoi(arg+1) ;
1534 if (*glyphPad != 1 &&
1538 USAGE("dtgpftobdf : illegal padding number (1/2/4/8)\n");
1546 USAGE1("usage: %s\n",usage);
1552 USAGE1("dtgpftobdf : illegal option -- %s\n",arg);
1553 USAGE1("usage: %s\n",usage);
1558 if (already == FALSE) {
1562 USAGE1("dtgpftobdf : extra parameter --- %s\n",arg);
1563 USAGE1("usage: %s\n", usage );
1568 if (already == FALSE) {
1569 USAGE("dtgpftobdf : require file name\n");
1570 USAGE1("usage: %s\n",usage);