CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

FONT.CPP (6933B)


      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 : LIBRARY                                  *
     21  *                                                                         *
     22  *                    File Name : FONT.C                                   *
     23  *                                                                         *
     24  *                   Programmer : David Dettmer                            *
     25  *                                                                         *
     26  *                  Last Update : July 20, 1994   [SKB]                    *
     27  *                                                                         *
     28  *-------------------------------------------------------------------------*
     29  * Functions:                                                              *
     30  *   Char_Pixel_Width -- Return pixel width of a character.						*
     31  *   String_Pixel_Width -- Return pixel width of a string of characters.   *
     32  *   Get_Next_Text_Print_XY -- Calculates X and Y given ret value from Text_P*
     33  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     34 
     35 #include "font.h"
     36 #include <malloc.h>
     37 #include <dos.h>
     38 #include <fcntl.h>
     39 #include <io.h>
     40 #include <sys\stat.h>
     41 #include <string.h>
     42 #include <wwstd.h>
     43 
     44 
     45 /***************************************************************************
     46  * CHAR_PIXEL_WIDTH -- Return pixel width of a character.						*
     47  *                                                                         *
     48  *    Retreives the pixel width of a character from the font width block.	*
     49  *                                                                         *
     50  * INPUT:      Character.																	*
     51  *                                                                         *
     52  * OUTPUT:     Pixel width of a string of characters.                      *
     53  *                                                                         *
     54  * WARNINGS:   Set_Font must have been called first.                       *
     55  *                                                                         *
     56  * HISTORY:                                                                *
     57  *   01/31/1992 DRD : Created.                                             *
     58  *   06/30/1994 SKB : Converted to 32 bit library.                         *
     59  *=========================================================================*/
     60 int __cdecl Char_Pixel_Width(char chr)
     61 {
     62 	int	width;
     63 
     64 	width = (unsigned char)*(FontWidthBlockPtr + (unsigned char)chr) + FontXSpacing;
     65 
     66 	return(width);
     67 }
     68 
     69 
     70 /***************************************************************************
     71  * STRING_PIXEL_WIDTH -- Return pixel width of a string of characters.     *
     72  *                                                                         *
     73  *    Calculates the pixel width of a string of characters.  This uses     *
     74  *		the font width block for the widths.											*
     75  *                                                                         *
     76  * INPUT:      Pointer to string of characters.                            *
     77  *                                                                         *
     78  * OUTPUT:     Pixel width of a string of characters.                      *
     79  *                                                                         *
     80  * WARNINGS:   Set_Font must have been called first.                       *
     81  *                                                                         *
     82  * HISTORY:                                                                *
     83  *   01/30/1992 DRD : Created.                                             *
     84  *   01/31/1992 DRD : Use Char_Pixel_Width.                                *
     85  *   06/30/1994 SKB : Converted to 32 bit library.                         *
     86  *=========================================================================*/
     87 unsigned int __cdecl String_Pixel_Width(char const *string)
     88 {
     89 	WORD	width;				// Working accumulator of string width.
     90 	WORD	largest = 0;		// Largest recorded width of the string.
     91 
     92 	if (!string) return(0);
     93 
     94 	width = 0;
     95 	while (*string) {
     96 		if (*string == '\r') {
     97 			string++;
     98 			largest = MAX(largest, width);
     99 			width = 0;
    100 		} else {
    101 			width += Char_Pixel_Width(*string++);	// add each char's width
    102 		}
    103 	}
    104 	largest = MAX(largest, width);
    105 	return(largest);
    106 }
    107 
    108 
    109 
    110 /***************************************************************************
    111  * GET_NEXT_TEXT_PRINT_XY -- Calculates X and Y given ret value from Text_P*
    112  *                                                                         *
    113  *                                                                         *
    114  * INPUT:   VVPC& vp - viewport that was printed to.                       *
    115  *          unsigned long offset - offset that Text_Print returned.                *
    116  *          INT *x - x return value.                                       *
    117  *          INT *y - y return value.                                       *
    118  *                                                                         *
    119  * OUTPUT:  x and y are set.                                               *
    120  *                                                                         *
    121  * WARNINGS:                                                               *
    122  *                                                                         *
    123  * HISTORY:                                                                *
    124  *   07/20/1994 SKB : Created.                                             *
    125  *=========================================================================*/
    126 VOID __cdecl Get_Next_Text_Print_XY(GraphicViewPortClass& gp, unsigned long offset, INT *x, INT *y)
    127 {
    128 	INT	buffwidth;
    129 
    130 	if (offset) {
    131 		buffwidth = gp.Get_Width() + gp.Get_XAdd();
    132 		offset -= gp.Get_Offset();
    133 		*x = offset % buffwidth;
    134 		*y = offset / buffwidth;
    135 	} else {
    136 		*x = *y = 0;
    137 	}
    138 }