LOADFONT.CPP 5.3 KB

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