pcf2bmf.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <locale.h>
  4. #include <string.h>
  5. #include <wchar.h>
  6. #include <getopt.h>
  7. #include "pcf.h"
  8. pcffont_t pcfFont;
  9. char sOutFilename[256];
  10. int nFontCount;
  11. static void help(void)
  12. {
  13. printf("Usage: pcf2bmf [options] ...\n"
  14. " -h --help\t\t\tPrint this help message\n"
  15. " -f --file\t\t\tpcf name to process \n"
  16. " -o --output\t\t\toutput filename\n"
  17. " -c --count\t\t\tgenerate font count\n"
  18. );
  19. }
  20. static struct option opts[] = {
  21. { "help", 0, 0, 'h' },
  22. { "file", 1, 0, 'f' },
  23. { "output", 1, 0, 'o' },
  24. { "count", 1, 0, 'c' },
  25. { NULL, 0, NULL, 0 }
  26. };
  27. int main(int argc, char *argv[])
  28. {
  29. ucs4_t c;
  30. char sFilename[256];
  31. setlocale( LC_ALL, "" );
  32. if(argc < 3)
  33. {
  34. help();
  35. exit(2);
  36. }
  37. int oc;
  38. nFontCount = 65535;
  39. while((oc=getopt_long(argc,argv,"hf:o:c:", opts, NULL))!=-1)
  40. {
  41. switch (oc) {
  42. case 'h':
  43. help();
  44. exit(0);
  45. break;
  46. case 'f':
  47. strncpy(sFilename, optarg, sizeof(sFilename) - 1);
  48. sFilename[sizeof(sFilename) - 1] = '\0';
  49. break;
  50. case 'o':
  51. strncpy(sOutFilename, optarg, sizeof(sOutFilename) - 1);
  52. sOutFilename[sizeof(sOutFilename) - 1] = '\0';
  53. break;
  54. case 'c':
  55. nFontCount = atoi(optarg);
  56. break;
  57. default:
  58. help();
  59. exit(2);
  60. }
  61. }
  62. pcfFont.file = sFilename;
  63. if (load_pcf(&pcfFont) >= 0)
  64. {
  65. fprintf(stdout, "%d %d %d\n", pcfFont.Fmetrics.ascent, pcfFont.Fmetrics.descent,
  66. pcfFont.Fmetrics.linespace);
  67. return 0;
  68. }
  69. else
  70. {
  71. fprintf(stdout,"Fail to load font file. Press ENTER to exit.\n");
  72. c = getwchar();
  73. return -1;
  74. }
  75. }