MakeFONT.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // MakeFONT - Font table File Creator
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <assert.h>
  17. #include <Engine/Engine.h>
  18. void SubMain( int argc, char *argv[])
  19. {
  20. printf("\nMakeFONT - Font Tables Maker (2.51)\n");
  21. printf( " (C)1999 CROTEAM Ltd\n\n");
  22. // 5 to 7 parameters are allowed as input
  23. if( (argc<5) || (argc>6))
  24. {
  25. printf( "USAGE: MakeFont <texture_file> <char_width> <char_height> ");
  26. printf( "<char_order_file> [-A]\n");
  27. printf( "\n");
  28. printf( "texture_file: FULL PATH to texture file that represents font\n");
  29. printf( "char_width: maximum width (in pixels) of single character\n");
  30. printf( "char_height: maximum height (in pixels) of single character\n");
  31. printf( "char_order_file: full path to ASCII file that shows\n");
  32. printf( " graphical order of character in font texture\n");
  33. printf( "-A: do not include alpha channel when determining character width \n");
  34. printf( "\n");
  35. printf( "NOTES: - out file will have the name as texture file, but \".fnt\" extension\n");
  36. printf( " - texture file must begin with character that will be a replacement for\n");
  37. printf( " each character that hasn't got definition in this texture file\n");
  38. exit( EXIT_FAILURE);
  39. }
  40. // initialize engine
  41. SE_InitEngine("");
  42. // first input parameter is texture name
  43. CTFileName fnTextureFileName = CTString(argv[1]);
  44. // parameters 2 and 3 give us character dimensions
  45. ULONG ulCharWidth = strtoul( argv[2], NULL, 10);
  46. ULONG ulCharHeight= strtoul( argv[3], NULL, 10);
  47. // parameter 4 specifies text file for character arrangements
  48. CTFileName fnOrderFile = CTString(argv[4]);
  49. // alpha channel ignore check
  50. BOOL bUseAlpha = TRUE;
  51. if( argc==6 && (argv[5][1]=='a' || argv[5][1]=='A')) bUseAlpha = FALSE;
  52. // font generation starts
  53. printf( "- Generating font table.\n");
  54. // try to create font
  55. CFontData fdFontData;
  56. try
  57. {
  58. // remove application path from font texture file
  59. fnTextureFileName.RemoveApplicationPath_t();
  60. // create font
  61. fdFontData.Make_t( fnTextureFileName, ulCharWidth, ulCharHeight, fnOrderFile, bUseAlpha);
  62. }
  63. // catch and report errors
  64. catch(char *strError)
  65. {
  66. printf( "! Cannot create font.\n %s\n", strError);
  67. exit(EXIT_FAILURE);
  68. }
  69. // save processed data
  70. printf( "- Saving font table file.\n");
  71. // create font name
  72. CTFileName strFontFileName;
  73. strFontFileName = fnTextureFileName.FileDir()+fnTextureFileName.FileName() + ".fnt";
  74. // try to
  75. try
  76. {
  77. fdFontData.Save_t( strFontFileName);
  78. }
  79. catch(char *strError)
  80. {
  81. printf("! Cannot save font.\n %s\n", strError);
  82. exit(EXIT_FAILURE);
  83. }
  84. printf( "- '%s' created successfuly.\n", strFontFileName);
  85. exit( EXIT_SUCCESS);
  86. }
  87. // ---------------- Main
  88. int main( int argc, char *argv[])
  89. {
  90. CTSTREAM_BEGIN
  91. {
  92. SubMain(argc, argv);
  93. }
  94. CTSTREAM_END;
  95. getch();
  96. return 0;
  97. }