DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

Font.h (3482B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
     25 
     26 ===========================================================================
     27 */
     28 #ifndef __FONT_H__
     29 #define __FONT_H__
     30 
     31 struct scaledGlyphInfo_t {
     32 	float	top, left;
     33 	float	width, height;
     34 	float	xSkip;
     35 	float	s1, t1, s2, t2;
     36 	const class idMaterial * material;
     37 };
     38 
     39 class idFont {
     40 public:
     41 	idFont( const char * n );
     42 	~idFont();
     43 
     44 	void Touch();
     45 
     46 	const char * GetName() const { return name; }
     47 
     48 	float GetLineHeight( float scale ) const;
     49 	float GetAscender( float scale ) const;
     50 	float GetMaxCharWidth( float scale ) const;
     51 
     52 	float GetGlyphWidth( float scale, uint32 idx ) const;
     53 	void GetScaledGlyph( float scale, uint32 idx, scaledGlyphInfo_t & glyphInfo ) const;
     54 
     55 private:
     56 	static idFont * RemapFont( const char * baseName );
     57 
     58 	int	GetGlyphIndex( uint32 idx ) const;
     59 
     60 	bool LoadFont();
     61 
     62 	struct glyphInfo_t {
     63 		byte	width;	// width of glyph in pixels
     64 		byte	height;	// height of glyph in pixels
     65 		char	top;	// distance in pixels from the base line to the top of the glyph
     66 		char	left;	// distance in pixels from the pen to the left edge of the glyph
     67 		byte	xSkip;	// x adjustment after rendering this glyph
     68 		uint16	s;		// x offset in image where glyph starts (in pixels)
     69 		uint16	t;		// y offset in image where glyph starts (in pixels)
     70 	};
     71 	struct fontInfo_t {
     72 		struct oldInfo_t {
     73 			float maxWidth;
     74 			float maxHeight;
     75 		} oldInfo[3];
     76 
     77 		short		ascender;
     78 		short		descender;
     79 
     80 		short		numGlyphs;
     81 		glyphInfo_t * glyphData;
     82 
     83 		// This is a sorted array of all characters in the font
     84 		// This maps directly to glyphData, so if charIndex[0] is 42 then glyphData[0] is character 42
     85 		uint32 *	charIndex;
     86 
     87 		// As an optimization, provide a direct mapping for the ascii character set
     88 		char		ascii[128];
     89 
     90 		const idMaterial *	material;
     91 	};
     92 
     93 	// base name of the font (minus "fonts/" and ".dat")
     94 	idStr			name;
     95 
     96 	// Fonts can be aliases to other fonts
     97 	idFont * alias;
     98 
     99 	// If the font is NOT an alias, this is where the font data is located
    100 	fontInfo_t * fontInfo;
    101 };
    102 
    103 #endif