Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
2.4 KiB

  1. //===== Copyright c 1996-2008, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Valve font compiler
  4. //
  5. //===========================================================================//
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include "utlbuffer.h"
  9. #include "valvefont.h"
  10. int Usage()
  11. {
  12. printf( "Usage: vfont inputfont.ttf [outputfont.vfont]\n" );
  13. return -1;
  14. }
  15. int main( int argc, char ** argv )
  16. {
  17. printf( "Valve Software - vfont.exe (" __DATE__ ")\n" );
  18. int iArg = 1;
  19. if ( iArg >= argc )
  20. return Usage();
  21. //
  22. // Check if we are in decompiler mode
  23. //
  24. #if VFONT_DECOMPILER
  25. bool bDecompiler = false;
  26. bDecompiler = !stricmp( argv[ iArg ], "-d" );
  27. if ( bDecompiler )
  28. ++ iArg;
  29. #endif
  30. if ( iArg >= argc )
  31. return Usage();
  32. //
  33. // Input file
  34. //
  35. char const *szInput = argv[ iArg ];
  36. ++ iArg;
  37. //
  38. // Output file
  39. //
  40. char szOutput[ 512 ] = {0};
  41. if ( iArg >= argc )
  42. {
  43. int numBytes = strlen( szInput );
  44. strcpy( szOutput, szInput );
  45. char *pDot = strrchr( szOutput, '.' );
  46. char *pSlash1 = strrchr( szOutput, '/' );
  47. char *pSlash2 = strrchr( szOutput, '\\' );
  48. if ( !pDot )
  49. {
  50. pDot = szOutput + numBytes;
  51. }
  52. else if ( pDot < pSlash1 || pDot < pSlash2 )
  53. {
  54. pDot = szOutput + numBytes;
  55. }
  56. sprintf( pDot, ".vfont" );
  57. }
  58. else
  59. {
  60. strcpy( szOutput, argv[ iArg ] );
  61. }
  62. //
  63. // Read the input
  64. //
  65. FILE *fin = fopen( szInput, "rb" );
  66. if ( !fin )
  67. {
  68. printf( "Error: cannot open input file '%s'!\n", szInput );
  69. return -2;
  70. }
  71. fseek( fin, 0, SEEK_END );
  72. long lSize = ftell( fin );
  73. fseek( fin, 0, SEEK_SET );
  74. CUtlBuffer buf;
  75. buf.EnsureCapacity( lSize );
  76. fread( buf.Base(), 1, lSize, fin );
  77. buf.SeekPut( CUtlBuffer::SEEK_HEAD, lSize );
  78. fclose( fin );
  79. //
  80. // Compile
  81. //
  82. #if VFONT_DECOMPILER
  83. if ( bDecompiler )
  84. {
  85. bool bResult = ValveFont::DecodeFont( buf );
  86. if ( !bResult )
  87. {
  88. printf( "Error: cannot decompile input file '%s'!\n", szInput );
  89. return 1;
  90. }
  91. }
  92. else
  93. ValveFont::EncodeFont( buf );
  94. #else
  95. ValveFont::EncodeFont( buf );
  96. #endif
  97. //
  98. // Write the output
  99. //
  100. FILE *fout = fopen( szOutput, "wb" );
  101. if ( !fout )
  102. {
  103. printf( "Error: cannot open output file '%s'!\n", szOutput );
  104. return -3;
  105. }
  106. fwrite( buf.Base(), 1, buf.TellPut(), fout );
  107. fclose( fout );
  108. printf( "vfont successfully %scompiled '%s' as '%s'.\n",
  109. #if VFONT_DECOMPILER
  110. bDecompiler ? "de" : "",
  111. #else
  112. "",
  113. #endif
  114. szInput, szOutput );
  115. return 0;
  116. }