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