Font.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #ifndef __FONT_H__
  21. #define __FONT_H__
  22. struct scaledGlyphInfo_t {
  23. float top, left;
  24. float width, height;
  25. float xSkip;
  26. float s1, t1, s2, t2;
  27. const class idMaterial * material;
  28. };
  29. class idFont {
  30. public:
  31. idFont( const char * n );
  32. ~idFont();
  33. void Touch();
  34. const char * GetName() const { return name; }
  35. float GetLineHeight( float scale ) const;
  36. float GetAscender( float scale ) const;
  37. float GetMaxCharWidth( float scale ) const;
  38. float GetGlyphWidth( float scale, uint32 idx ) const;
  39. void GetScaledGlyph( float scale, uint32 idx, scaledGlyphInfo_t & glyphInfo ) const;
  40. private:
  41. static idFont * RemapFont( const char * baseName );
  42. int GetGlyphIndex( uint32 idx ) const;
  43. bool LoadFont();
  44. struct glyphInfo_t {
  45. byte width; // width of glyph in pixels
  46. byte height; // height of glyph in pixels
  47. char top; // distance in pixels from the base line to the top of the glyph
  48. char left; // distance in pixels from the pen to the left edge of the glyph
  49. byte xSkip; // x adjustment after rendering this glyph
  50. uint16 s; // x offset in image where glyph starts (in pixels)
  51. uint16 t; // y offset in image where glyph starts (in pixels)
  52. };
  53. struct fontInfo_t {
  54. struct oldInfo_t {
  55. float maxWidth;
  56. float maxHeight;
  57. } oldInfo[3];
  58. short ascender;
  59. short descender;
  60. short numGlyphs;
  61. glyphInfo_t * glyphData;
  62. // This is a sorted array of all characters in the font
  63. // This maps directly to glyphData, so if charIndex[0] is 42 then glyphData[0] is character 42
  64. uint32 * charIndex;
  65. // As an optimization, provide a direct mapping for the ascii character set
  66. char ascii[128];
  67. const idMaterial * material;
  68. };
  69. // base name of the font (minus "fonts/" and ".dat")
  70. idStr name;
  71. // Fonts can be aliases to other fonts
  72. idFont * alias;
  73. // If the font is NOT an alias, this is where the font data is located
  74. fontInfo_t * fontInfo;
  75. };
  76. #endif