LOADFONT.CPP 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***************************************************************************
  19. ** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  20. ***************************************************************************
  21. * *
  22. * Project Name : Westwood Library *
  23. * *
  24. * File Name : LOADFONT.C *
  25. * *
  26. * Programmer : Joe L. Bostic *
  27. * *
  28. * Start Date : September 6, 1991 *
  29. * *
  30. * Last Update : June 27, 1994 [SKB] *
  31. * *
  32. *-------------------------------------------------------------------------*
  33. * Functions: *
  34. * Load_Font -- Loads a font from disk. *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #include "font.h"
  37. #include <file.h>
  38. #include <wwmem.h>
  39. #include <wwstd.h>
  40. #if(IBM)
  41. #include <fcntl.h>
  42. #include <io.h>
  43. #include <errno.h>
  44. int FontXSpacing = 0;
  45. int FontYSpacing = 0;
  46. void const *FontPtr = NULL;
  47. char FontWidth = 8;
  48. char FontHeight = 8;
  49. // only font.c and set_font.c use the following
  50. char *FontWidthBlockPtr = NULL;
  51. /***************************************************************************
  52. * LOAD_FONT -- Loads a font from disk. *
  53. * *
  54. * This loads a font from disk. This function must be called as a *
  55. * precursor to calling Set_Font(). You need only call this function *
  56. * once per desired font at the beginning of your code, but AFTER *
  57. * Prog_Init() is called. *
  58. * *
  59. * INPUT: name - Pointer to font name to use (eg. "topaz.font") *
  60. * *
  61. * fontsize - Size in points of the font loaded. *
  62. * *
  63. * OUTPUT: Pointer to font data or NULL if unable to load. *
  64. * *
  65. * WARNINGS: Some system memory is grabbed by this routine. *
  66. * *
  67. * HISTORY: *
  68. * 4/10/91 BS : 2.0 compatibily *
  69. * 6/09/91 JLB : IBM and Amiga compatability. *
  70. * 11/27/1991 JLB : Uses file I/O routines for disk access. *
  71. * 01/29/1992 DRD : Modified to use new font format. *
  72. * 02/01/1992 DRD : Added font file verification. *
  73. * 06/29/1994 SKB : modified for 32 bit library *
  74. *=========================================================================*/
  75. void * __cdecl Load_Font(char const *name)
  76. {
  77. char valid;
  78. int fh; // DOS file handle for font file.
  79. unsigned short size; // Size of the data in the file (-2);
  80. char *ptr = NULL; // Pointer to newly loaded font.
  81. fh=Open_File(name,READ);
  82. if ( fh>=0 ){
  83. if ( Read_File(fh, (char *) &size, 2) != 2) return(NULL);
  84. ptr = (char *) Alloc(size , MEM_NORMAL );
  85. *(short *)ptr = size;
  86. Read_File(fh, ptr + 2, size - 2);
  87. Close_File(fh);
  88. } else {
  89. return ((void*)errno);
  90. }
  91. #ifdef cuts
  92. if (Find_File(name)) {
  93. fh = Open_File(name, READ);
  94. if (Read_File(fh, (char *) &size, 2) != 2) return(NULL);
  95. ptr = (char *) Alloc(size, MEM_NORMAL);
  96. *(short *)ptr = size;
  97. Read_File(fh, ptr + 2, size - 2);
  98. Close_File(fh);
  99. } else {
  100. return (NULL);
  101. }
  102. #endif
  103. //
  104. // verify that the file loaded is a valid font file.
  105. //
  106. valid = FALSE;
  107. if (*(ptr + 2) == 0) { // no compression
  108. if (*(ptr + 3) == 5) { // currently only 5 data blocks are used.
  109. valid = TRUE;
  110. }
  111. }
  112. if ( !valid ) {
  113. return (NULL);
  114. }
  115. return(ptr);
  116. }
  117. #endif