Font.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #ifndef SE_INCL_FONT_H
  13. #define SE_INCL_FONT_H
  14. #ifdef PRAGMA_ONCE
  15. #pragma once
  16. #endif
  17. #include <Engine/Base/FileName.h>
  18. #include <Engine/Base/Serial.h>
  19. // some default fonts
  20. ENGINE_API extern CFontData *_pfdDisplayFont;
  21. ENGINE_API extern CFontData *_pfdConsoleFont;
  22. /*
  23. * font letter description
  24. */
  25. class ENGINE_API CFontCharData {
  26. public:
  27. PIX fcd_pixXOffset, fcd_pixYOffset; // offset of letter inside tex file (in pixels)
  28. PIX fcd_pixStart, fcd_pixEnd; // position and size adjustment for current letter
  29. // constructor
  30. CFontCharData(void);
  31. // simple stream functions
  32. void Read_t( CTStream *inFile);
  33. void Write_t( CTStream *outFile);
  34. };
  35. /*
  36. * font description
  37. */
  38. class ENGINE_API CFontData : public CSerial {
  39. // implementation
  40. public:
  41. PIX fd_pixCharSpacing, fd_pixLineSpacing; // intra character and intra line spacing
  42. PIX fd_pixCharWidth, fd_pixCharHeight; // maximum character width and height
  43. BOOL fd_bFixedWidth; // treated as of fixed width
  44. CTFileName fd_fnTexture;
  45. class CFontCharData fd_fcdFontCharData[256];
  46. class CTextureData *fd_ptdTextureData;
  47. // interface
  48. public:
  49. CFontData();
  50. ~CFontData();
  51. inline PIX GetWidth(void) const { return fd_pixCharWidth; };
  52. inline PIX GetHeight(void) const { return fd_pixCharHeight; };
  53. inline PIX GetCharSpacing(void) const { return fd_pixCharSpacing; };
  54. inline PIX GetLineSpacing(void) const { return fd_pixLineSpacing; };
  55. inline BOOL IsFixedWidth(void) const { return fd_bFixedWidth; };
  56. inline void SetCharSpacing( PIX pixSpacing) { fd_pixCharSpacing = pixSpacing; };
  57. inline void SetLineSpacing( PIX pixSpacing) { fd_pixLineSpacing = pixSpacing; };
  58. inline void SetFixedWidth(void) { fd_bFixedWidth = TRUE; };
  59. inline void SetVariableWidth(void) { fd_bFixedWidth = FALSE; };
  60. inline void SetSpaceWidth( FLOAT fWidthRatio) { // relative to char cell width (1/2 is default)
  61. fd_fcdFontCharData[' '].fcd_pixEnd = (PIX)(fd_pixCharWidth*fWidthRatio); }
  62. void Read_t( CTStream *inFile); // throw char *
  63. void Write_t( CTStream *outFile); // throw char *
  64. void Make_t( const CTFileName &fnTexture, PIX pixCharWidth, PIX pixCharHeight,
  65. CTFileName &fnOrderFile, BOOL bUseAlpha);
  66. void Clear();
  67. };
  68. #endif /* include-once check. */