~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/tools/fnt2bdf.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /************************************************
  2  *
  3  * Extract fonts from .fnt or Windows DLL files
  4  * and convert them to the .bdf format.
  5  *
  6  * Copyright 1994-1996 Kevin Carothers and Alex Korobka
  7  *
  8  * This library is free software; you can redistribute it and/or
  9  * modify it under the terms of the GNU Lesser General Public
 10  * License as published by the Free Software Foundation; either
 11  * version 2.1 of the License, or (at your option) any later version.
 12  *
 13  * This library is distributed in the hope that it will be useful,
 14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16  * Lesser General Public License for more details.
 17  *
 18  * You should have received a copy of the GNU Lesser General Public
 19  * License along with this library; if not, write to the Free Software
 20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 21  */
 22 
 23 #include "config.h"
 24 #include "wine/port.h"
 25 
 26 #ifdef HAVE_SYS_PARAM_H
 27 # include <sys/param.h>
 28 #endif
 29 #include <sys/types.h>
 30 #include <sys/stat.h>
 31 #include <stdio.h>
 32 #include <stdlib.h>
 33 #include <string.h>
 34 #ifdef HAVE_UNISTD_H
 35 # include <unistd.h>
 36 #endif
 37 #include <fcntl.h>
 38 #ifdef HAVE_IO_H
 39 # include <io.h>
 40 #endif
 41 
 42 #include "fnt2bdf.h"
 43 
 44 #define FILE_ERROR      0
 45 #define FILE_DLL        1
 46 #define FILE_FNT        2
 47 
 48 /* global options */
 49 
 50 static int dump_bdf( fnt_fontS* cpe_font_struct, unsigned char* file_buffer);
 51 static int dump_bdf_hdr(FILE* fs, fnt_fontS* cpe_font_struct, unsigned char* file_buffer);
 52 
 53 static char* g_lpstrFileName = NULL;
 54 static char* g_lpstrCharSet = NULL;
 55 static char* g_lpstrInputFile = NULL;
 56 static int   g_outputPoints = 0;
 57 
 58 /* info */
 59 
 60 static void usage(void)
 61 {
 62     printf("Usage: fnt2bdf [-t] [-c charset] [-o basename] [input file]\n");
 63     printf("  -c charset\tcharset name for OEM_CHARSET fonts\n");
 64     printf("  -f basename\tbasic output filename\n");
 65     printf("  -t \t\toutput files by point size instead of pixel height\n");
 66     printf("  input file\tMSWindows .fon, .fnt, .dll, or .exe file.\n");
 67     printf("\nExample:\n  fnt2bdf -c winsys vgasys.fnt\n\n");
 68     exit(-1);
 69 }
 70 
 71 /* convert little-endian value to the local format */
 72 
 73 static int return_data_value(enum data_types dtype, void * pChr)
 74 {
 75 int   ret_val = 0;
 76 
 77     switch(dtype) {
 78         case (dfChar):
 79             ret_val = (int) *(unsigned char *)pChr;
 80             break;
 81 
 82         case(dfShort):
 83             ret_val = *(unsigned char *)pChr;
 84             ret_val += (*((unsigned char *)pChr + 1) << 8);
 85             break;
 86 
 87         case(dfLong): {
 88             int  i;
 89 
 90             for(i=3; i >= 0; i--)  {
 91                 ret_val += *((unsigned char *)pChr + i) << (8*i);
 92                 }
 93             break;
 94             }
 95                 case(dfString):
 96                         break;
 97         }
 98     return ret_val;
 99 }
100 
101 static int make_bdf_filename(char* name, fnt_fontS* cpe_font_struct, unsigned char* file_buffer)
102 {
103 long    l_nameoffset = return_data_value(dfLong, &cpe_font_struct->hdr.fi.dfFace);
104 char*   lpChar;
105 
106   if( !g_lpstrFileName )
107   {
108     if( !l_nameoffset ||
109          l_nameoffset > return_data_value(dfLong, &cpe_font_struct->hdr.dfSize) + 1 )
110          return ERROR_DATA;
111     lpChar =  (char*)(file_buffer + l_nameoffset);
112   }
113     else lpChar = g_lpstrFileName;
114 
115   strcpy( name, lpChar );
116 
117   while( (lpChar = strchr( name, ' ')) )
118          *lpChar = '-';
119 
120   /* construct a filename from the font typeface, slant, weight, and size */
121 
122   if( cpe_font_struct->hdr.fi.dfItalic ) strcat(name, "_i" );
123   else strcat(name, "_r" );
124 
125   lpChar = name + strlen( name );
126   sprintf(lpChar, "%d-%d.bdf", return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfWeight),
127           (g_outputPoints) ? return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfPoints)
128                            : return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfPixHeight) );
129   return 0;
130 }
131 
132 /* parse FONT resource and write .bdf file */
133 
134 static int parse_fnt_data(unsigned char* file_buffer, int length)
135 {
136   fnt_fontS     cpe_font_struct;
137   int           ic=0, t;
138 
139   memcpy((char *) &cpe_font_struct.hdr, file_buffer, sizeof(fnt_hdrS));
140 
141   /* check font header */
142 
143   t = return_data_value(dfShort, &cpe_font_struct.hdr.dfVersion);
144   if( t != 0x300 && t != 0x200) return ERROR_VERSION;
145 
146   t = return_data_value(dfShort, &cpe_font_struct.hdr.fi.dfType);
147   if (t & 1)
148   {
149     fprintf(stderr, "Vector fonts not supported\n");
150     return ERROR_DATA;
151   }
152 
153   t = return_data_value(dfLong, &cpe_font_struct.hdr.dfSize);
154   if( t > length ) return ERROR_SIZE;
155   else
156   {
157     /* set up the charWidth/charOffset  structure pairs (dfCharTable)... */
158 
159     int l_fchar = return_data_value(dfChar, &cpe_font_struct.hdr.fi.dfFirstChar),
160         l_lchar = return_data_value(dfChar, &cpe_font_struct.hdr.fi.dfLastChar);
161     int l_len   = l_lchar - l_fchar + 1;
162     int l_ptr = sizeof(fnt_hdrS);
163 
164     /* some fields were introduced for Windows 3.x fonts */
165     if( return_data_value(dfShort, &cpe_font_struct.hdr.dfVersion) == 0x200 )
166         l_ptr -= 30;
167 
168     /* malloc size = (# chars) * sizeof(WinCharS) */
169 
170     if((cpe_font_struct.dfCharTable = (WinCharS *) calloc(sizeof(WinCharS), l_len)) == NULL)
171         return ERROR_MEMORY;
172 
173     /* NOW, convert them all to UNIX (lton) notation... */
174 
175     for(ic=0; ic < l_len; ic++) {
176         cpe_font_struct.dfCharTable[ic].charWidth = return_data_value(dfShort, &file_buffer[l_ptr]);
177         l_ptr += 2;     /* bump by sizeof(short) */
178 
179 
180         if( return_data_value(dfShort, &cpe_font_struct.hdr.dfVersion) == 0x200) {
181             cpe_font_struct.dfCharTable[ic].charOffset =
182                         return_data_value(dfShort, &file_buffer[l_ptr]);
183             l_ptr += 2; /* bump by sizeof(short) */
184             }
185         else {  /*  Windows Version 3.0 type font */
186             cpe_font_struct.dfCharTable[ic].charOffset =
187                         return_data_value(dfLong, &file_buffer[l_ptr]);
188             l_ptr += 4; /* bump by sizeof(long) */
189             }
190         }
191     t = dump_bdf(&cpe_font_struct, file_buffer);
192     free( cpe_font_struct.dfCharTable );
193   }
194   return t;
195 }
196 
197 static int dump_bdf( fnt_fontS* cpe_font_struct, unsigned char* file_buffer)
198 {
199   FILE*   fp;
200   int     ic;
201   int     l_fchar = return_data_value(dfChar, &cpe_font_struct->hdr.fi.dfFirstChar),
202           l_lchar = return_data_value(dfChar, &cpe_font_struct->hdr.fi.dfLastChar);
203 
204   int     l_len = l_lchar-l_fchar + 1,
205           l_hgt = return_data_value(dfChar, &cpe_font_struct->hdr.fi.dfPixHeight);
206   int     l_ascent = return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfAscent);
207   char    l_filename[256];
208 
209     if( (ic = make_bdf_filename(l_filename, cpe_font_struct, file_buffer)) )
210         return ic;
211 
212     if((fp = fopen(l_filename, "w")) == NULL)
213     {
214       fprintf(stderr, "Couldn't open \"%s\" for output.\n", l_filename);
215       return ERROR_FILE;
216     }
217 
218     ic = dump_bdf_hdr(fp, cpe_font_struct, file_buffer);
219     if (ic) return (ic);
220 
221     /* NOW, convert all chars to UNIX (lton) notation... */
222 
223     for(ic=0; ic < l_len; ic++) {
224         int rowidx, l_span,             /* how many char-cols wide is char? */
225             l_idx = cpe_font_struct->dfCharTable[ic].charOffset;
226 
227         l_span = (int) (cpe_font_struct->dfCharTable[ic].charWidth-1)/8;
228 
229         fprintf(fp, "STARTCHAR %d  \n", ic);
230         fprintf(fp, "ENCODING %d\n",   l_fchar);
231         fprintf(fp, "SWIDTH    %d    %d \n",
232                 cpe_font_struct->dfCharTable[ic].charWidth*1000,
233                 0);
234 
235         fprintf(fp, "DWIDTH    %d    %d \n",
236                 cpe_font_struct->dfCharTable[ic].charWidth, 0);
237 
238         fprintf(fp, "BBX  %d  %d  %d   %d\n",
239                 cpe_font_struct->dfCharTable[ic].charWidth, l_hgt, 0,
240                 l_ascent - l_hgt);
241 
242         fprintf(fp, "BITMAP\n");
243         for(rowidx=0; rowidx < l_hgt; rowidx++) {
244             switch(l_span) {
245                 case(0):        /* 1-7 pixels wide font */
246                     {
247                     fprintf(fp, "%02X\n", (int) file_buffer[l_idx+rowidx]);
248                     break;
249                     }
250 
251                 case(1):        /* 8-15 pixels wide font */
252                     {
253                     fprintf(fp, "%02X%02X",
254                         (int) file_buffer[l_idx+rowidx], file_buffer[l_idx+l_hgt+rowidx]);
255                     fprintf(fp, "\n");
256                     break;
257                     }
258 
259                 case(2):        /* 16-23 pixels wide font */
260                     {
261                     fprintf(fp, "%02X%02X%02X",
262                         file_buffer[l_idx+rowidx],
263                         file_buffer[l_idx+l_hgt+rowidx],
264                         file_buffer[l_idx+(2*l_hgt)+rowidx]);
265                     fprintf(fp, "\n");
266                     break;
267                     }
268 
269                 case(3):        /* 24-31 pixels wide font */
270                     {
271                     fprintf(fp, "%02X%02X%02X%02X",
272                         file_buffer[l_idx+rowidx],
273                         file_buffer[l_idx+l_hgt+rowidx],
274                         file_buffer[l_idx+(2*l_hgt)+rowidx],
275                         file_buffer[l_idx+(3*l_hgt)+rowidx]);
276                     fprintf(fp, "\n");
277                     break;
278                     }
279                 case(4):        /* 32-39 */
280                     {
281                     fprintf(fp, "%02X%02X%02X%02X%02X",
282                         file_buffer[l_idx+rowidx],
283                         file_buffer[l_idx+l_hgt+rowidx],
284                         file_buffer[l_idx+(2*l_hgt)+rowidx],
285                         file_buffer[l_idx+(3*l_hgt)+rowidx],
286                         file_buffer[l_idx+(4*l_hgt)+rowidx]);
287                     fprintf(fp, "\n");
288                     break;
289                     }
290                 default:
291                     fclose(fp);
292                     unlink(l_filename);
293                     return ERROR_DATA;
294                 }
295             }
296         fprintf(fp, "ENDCHAR\n");
297 
298         l_fchar++;      /* Go to next one */
299         }
300 fprintf(fp, "ENDFONT\n");
301 fclose(fp);
302 return 0;
303 }
304 
305 
306 static int dump_bdf_hdr(FILE* fs, fnt_fontS* cpe_font_struct, unsigned char* file_buffer)
307 {
308 int     l_fchar = return_data_value(dfChar, &cpe_font_struct->hdr.fi.dfFirstChar),
309         l_lchar = return_data_value(dfChar, &cpe_font_struct->hdr.fi.dfLastChar);
310 int     l_len = l_lchar - l_fchar + 1;
311 long    l_nameoffset = return_data_value(dfLong, &cpe_font_struct->hdr.fi.dfFace);
312 int     l_cellheight = return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfPixHeight);
313 int     l_ascent = return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfAscent);
314 
315     fprintf(fs, "STARTFONT   2.1\n");
316 
317     /* Compose font name */
318 
319     if( l_nameoffset &&
320         l_nameoffset < return_data_value(dfLong, &cpe_font_struct->hdr.dfSize) )
321     {
322       int     dpi, point_size;
323       char*   lpFace = (char*)(file_buffer + l_nameoffset), *lpChar;
324       short   tmWeight = return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfWeight);
325 
326       while((lpChar = strchr(lpFace, '-')) )
327             *lpChar = ' ';
328 
329       fprintf(fs, "FONT -windows-%s-", lpFace );
330 
331       if( tmWeight == 0 )                       /* weight */
332           fputs("medium-", fs);
333       else if( tmWeight <= FW_LIGHT )
334           fputs("light-", fs);
335       else if( tmWeight <= FW_MEDIUM )
336           fputs("medium-", fs);
337       else if( tmWeight <= FW_DEMIBOLD )
338           fputs("demibold-", fs);
339       else if( tmWeight <= FW_BOLD )
340           fputs("bold-", fs);
341       else fputs("black-", fs);
342 
343       if( cpe_font_struct->hdr.fi.dfItalic )    /* slant */
344           fputs("i-", fs);
345       else fputs("r-", fs);
346 
347       /* style */
348 
349       if( (cpe_font_struct->hdr.fi.dfPitchAndFamily & 0xF0) == FF_SWISS )
350           fputs("normal-sans-", fs);
351       else fputs("normal--", fs);       /* still can be -sans */
352 
353       /* y extents */
354 
355       point_size = 10 * return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfPoints );
356       dpi = (l_cellheight * 720) / point_size;
357 
358       fprintf(fs, "%d-%d-%d-%d-",l_cellheight, point_size,
359             return_data_value (dfShort, &cpe_font_struct->hdr.fi.dfHorizRes),
360             return_data_value (dfShort, &cpe_font_struct->hdr.fi.dfVertRes));
361 
362       /* spacing */
363 
364       if( return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfPixWidth) ) fputs("c-", fs);
365       else fputs("p-", fs);
366 
367       /* average width */
368 
369       fprintf( fs, "%d-", 10 * return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfAvgWidth) );
370 
371       /* charset */
372 
373      if( g_lpstrCharSet ) fprintf(fs, "%s\n", g_lpstrCharSet);
374      else
375       switch( cpe_font_struct->hdr.fi.dfCharSet )
376       {
377         /* Microsoft just had to invent its own charsets! */
378 
379         case ANSI_CHARSET:      fputs("microsoft-cp1252\n", fs); break;
380         case GREEK_CHARSET:     fputs("microsoft-cp1253\n", fs); break;
381         case TURKISH_CHARSET:   fputs("microsoft-cp1254\n", fs); break;
382         case HEBREW_CHARSET:    fputs("microsoft-cp1255\n", fs); break;
383         case ARABIC_CHARSET:    fputs("microsoft-cp1256\n", fs); break;
384         case BALTIC_CHARSET:    fputs("microsoft-cp1257\n", fs); break;
385         case RUSSIAN_CHARSET:   fputs("microsoft-cp1251\n", fs); break;
386         case EE_CHARSET:        fputs("microsoft-cp1250\n", fs); break;
387         case SYMBOL_CHARSET:    fputs("microsoft-symbol\n", fs); break;
388         case SHIFTJIS_CHARSET:  fputs("jisx0208.1983-0\n", fs); break;
389         case DEFAULT_CHARSET:   fputs("iso8859-1\n", fs); break;
390 
391         default:
392         case OEM_CHARSET:
393                     fputs("Undefined charset, use -c option.\n", stderr);
394                     return ERROR_DATA;
395       }
396     }
397     else return ERROR_DATA;
398 
399     fprintf(fs, "SIZE  %d  %d   %d\n",
400         return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfPoints ),
401         return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfHorizRes),
402         return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfVertRes));   /* dfVertRes[2] */
403 
404     fprintf(fs, "FONTBOUNDINGBOX %d  %d  %d  %d\n",
405         return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfMaxWidth),
406         return_data_value(dfChar, &cpe_font_struct->hdr.fi.dfPixHeight),
407         0, l_ascent - l_cellheight );
408 
409     fprintf(fs, "STARTPROPERTIES  4\n");
410 
411     fprintf(fs, "FONT_ASCENT %d\n", l_ascent );                       /*  dfAscent[2] */
412     fprintf(fs, "FONT_DESCENT %d\n", l_cellheight - l_ascent );
413     fprintf(fs, "CAP_HEIGHT %d\n", l_ascent -
414                                    return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfInternalLeading));
415     fprintf(fs, "DEFAULT_CHAR %d\n", return_data_value(dfShort, &cpe_font_struct->hdr.fi.dfDefaultChar));
416 
417     fprintf(fs, "ENDPROPERTIES\n");
418 
419     fprintf(fs, "CHARS  %d\n",  l_len);
420     return 0;
421 }
422 
423 
424 
425 static void parse_options(int argc, char **argv)
426 {
427   int i;
428 
429   switch( argc )
430   {
431     case 2:
432          g_lpstrInputFile = argv[1];
433          break;
434 
435     case 3:
436     case 4:
437     case 5:
438     case 6:
439     case 7:
440     case 8:
441          for( i = 1; i < argc - 1; i++ )
442          {
443            if( argv[i][0] != '-' ||
444                strlen(argv[i]) != 2 ) break;
445 
446            if( argv[i][1] == 'c' )
447                g_lpstrCharSet = argv[i+1];
448            else
449            if( argv[i][1] == 'f' )
450                g_lpstrFileName = argv[i+1];
451            else
452            if( argv[i][1] == 't' )
453            {
454               g_outputPoints = 1;
455               continue;
456            }
457            else
458            usage();
459 
460            i++;
461          }
462          if( i == argc - 1 )
463          {
464            g_lpstrInputFile = argv[i];
465            break;
466          }
467     default: usage();
468   }
469 
470 }
471 
472 /* read file data and return file type */
473 
474 static int get_resource_table(int fd, unsigned char** lpdata, int fsize)
475 {
476   IMAGE_DOS_HEADER mz_header;
477   IMAGE_OS2_HEADER ne_header;
478   long s, offset, size;
479   int retval;
480 
481   lseek( fd, 0, SEEK_SET );
482 
483   if( read(fd, &mz_header, sizeof(mz_header)) != sizeof(mz_header) )
484       return FILE_ERROR;
485 
486   s = return_data_value(dfShort, &mz_header.e_magic);
487 
488   if( s == IMAGE_DOS_SIGNATURE)         /* looks like .dll file so far... */
489   {
490     s = return_data_value(dfShort, &mz_header.e_lfanew);
491     lseek( fd, s, SEEK_SET );
492 
493     if( read(fd, &ne_header, sizeof(ne_header)) != sizeof(ne_header) )
494         return FILE_ERROR;
495 
496     s = return_data_value(dfShort, &ne_header.ne_magic);
497 
498     if( s == IMAGE_NT_SIGNATURE)
499     {
500        fprintf( stderr, "Do not know how to handle 32-bit Windows DLLs.\n");
501        return FILE_ERROR;
502     }
503     else if ( s != IMAGE_OS2_SIGNATURE) return FILE_ERROR;
504 
505     s = return_data_value(dfShort, &ne_header.ne_rsrctab);
506     size = return_data_value(dfShort, &ne_header.ne_restab);
507 
508     if( size > fsize ) return FILE_ERROR;
509 
510     size -= s;
511     offset = s + return_data_value(dfShort, &mz_header.e_lfanew);
512 
513     if( size <= sizeof(NE_TYPEINFO) ) return FILE_ERROR;
514     retval = FILE_DLL;
515   }
516   else if( s == 0x300 || s == 0x200 )           /* maybe .fnt ? */
517   {
518     size = return_data_value(dfLong, &((fnt_hdrS *)&mz_header)->dfSize);
519 
520     if( size != fsize ) return FILE_ERROR;
521     offset  = 0;
522     retval = FILE_FNT;
523   }
524   else return FILE_ERROR;
525 
526   *lpdata = (unsigned char*)malloc(size);
527 
528   if( *lpdata )
529   {
530     lseek( fd, offset, SEEK_SET );
531     if( read(fd, *lpdata, size) != size )
532            { free( *lpdata ); *lpdata = NULL; }
533   }
534   return retval;
535 }
536 
537 
538 /* entry point */
539 
540 int main(int argc, char **argv)
541 {
542   unsigned char* lpdata = NULL;
543   int            fd;
544 
545   parse_options( argc, argv);
546 
547   if( (fd = open( g_lpstrInputFile, O_RDONLY | O_BINARY)) )
548   {
549     int    i;
550     struct stat file_stat;
551 
552     fstat( fd, &file_stat);
553     i = get_resource_table( fd, &lpdata, file_stat.st_size );
554 
555     switch(i)
556     {
557         case FILE_DLL:
558              if( lpdata )
559              {
560                int          j, count = 0;
561                NE_TYPEINFO* pTInfo = (NE_TYPEINFO*)(lpdata + 2);
562                NE_NAMEINFO* pFontStorage = NULL;
563 
564                while( (i = return_data_value(dfShort, &pTInfo->type_id)) )
565                {
566                   j = return_data_value(dfShort, &pTInfo->count);
567                   if( i == NE_RSCTYPE_FONT )
568                   {
569                     count = j;
570                     pFontStorage = (NE_NAMEINFO*)(pTInfo + 1);
571                     break; /* found one */
572                   }
573 
574                   pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1) + j*sizeof(NE_NAMEINFO));
575                }
576                if( pFontStorage && count )
577                {
578                  unsigned short         size_shift = return_data_value(dfShort, lpdata);
579                  unsigned char*         lpfont = NULL;
580                  unsigned               offset;
581                  int                    length;
582 
583                  for( j = 0; j < count; j++, pFontStorage++ )
584                  {
585                     length = return_data_value(dfShort, &pFontStorage->length) << size_shift;
586                     offset = return_data_value(dfShort, &pFontStorage->offset) << size_shift;
587 
588                     if( !(lpfont = (unsigned char*) realloc( lpfont, length )) )
589                     {
590                         fprintf(stderr, "Memory allocation error.\n" );
591                         exit(1);
592                     }
593 
594                     lseek( fd, offset, SEEK_SET );
595                     if( read(fd, lpfont, length) != length )
596                     {
597                         fprintf(stderr, "Unable to read Windows DLL.\n" );
598                         exit(1);
599                     }
600 
601                     if( (i = parse_fnt_data( lpfont, length )) )
602                     {
603                         fprintf(stderr, "Unable to parse font data: Error %d\n", i );
604                         exit(1);
605                     }
606                  }
607                  free(lpfont); free(lpdata);
608                  exit(0);
609                }
610                else
611                {
612                  fprintf(stderr, "No fonts found.\n" );
613                  exit(1);
614                }
615                free( lpdata );
616              }
617              else
618              {
619                fprintf(stderr, "Unable to read Windows DLL.\n" );
620                exit(1);
621              }
622              break;
623 
624         case FILE_FNT:
625              if( lpdata )
626              {
627                if( (i = parse_fnt_data( lpdata, file_stat.st_size )) )
628                {
629                    fprintf(stderr, "Unable to parse font data: Error %d\n", i );
630                    exit(1);
631                }
632                free( lpdata );
633              }
634              else
635              {
636                fprintf(stderr, "Unable to read .FNT file.\n" );
637                exit(1);
638              }
639              break;
640 
641         case FILE_ERROR:
642              fprintf(stderr, "Corrupt or invalid file.\n" );
643              exit(1);
644     }
645     close(fd);
646     exit(0);
647   }
648   else
649   {
650     fprintf(stderr, "Unable to open '%s'.\n", g_lpstrInputFile );
651     exit(1);
652   }
653 }
654 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.