font.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*=============================================================================
  2. Name : font.h
  3. Purpose : Definitions for drawing text strings
  4. Created 7/11/1997 by lmoloney
  5. Copyright Relic Entertainment, Inc. All rights reserved.
  6. =============================================================================*/
  7. #ifndef ___FONT_H
  8. #define ___FONT_H
  9. #include "types.h"
  10. #include "color.h"
  11. #include "prim2d.h"
  12. /*=============================================================================
  13. Switches
  14. =============================================================================*/
  15. #ifndef HW_Release
  16. #define FONT_ERROR_CHECKING 1 //general error checking
  17. #define FONT_VERBOSE_LEVEL 1 //print extra info
  18. #define FONT_HACK_LOAD 0 //just pretend to load a font file
  19. #define FONT_TEST 1 //test the task module
  20. #define FONT_SAVE_TEXTURE 1 //save texture handle while printing fonts
  21. #define FONT_ALL_CAPS 0 //print everything using caps
  22. #define FONT_IGNORE_NON_ALPHA 1 //ignore non-alphabetical characters
  23. #define FONT_COLOR_HACK 0 //work around a shortcoming in 3dFXGL
  24. #define FONT_MANUAL_CLIP 1 //do a check to see if font is off-screen
  25. #else //HW_Debug
  26. #define FONT_ERROR_CHECKING 0 //general error checking
  27. #define FONT_VERBOSE_LEVEL 0 //print extra info
  28. #define FONT_HACK_LOAD 0 //just pretend to load a font file
  29. #define FONT_TEST 0 //test the task module
  30. #define FONT_SAVE_TEXTURE 1 //save texture handle while printing fonts
  31. #define FONT_ALL_CAPS 0 //print everything using caps
  32. #define FONT_IGNORE_NON_ALPHA 1 //ignore non-alphabetical characters
  33. #define FONT_COLOR_HACK 0 //work around a shortcoming in 3dFXGL
  34. #define FONT_MANUAL_CLIP 1 //do a check to see if font is off-screen
  35. #endif //HW_Debug
  36. /*=============================================================================
  37. Definitions:
  38. =============================================================================*/
  39. #define FONT_NumberCharacters 256 //max. number of characters in a font
  40. #define FONT_Version 0x100 //current font file version
  41. #define FONT_Identification "Orannge" //another mispelled fruit
  42. #define FONT_IdentLength 8 //length of mispelled fruit
  43. #define FONT_InvalidFontHandle 0xffffffff //this is not a fonthandle
  44. //font flags
  45. #define FF_Color 0x0001 //color font
  46. #define FF_Alpha 0x0002 //alpha-blending enabled
  47. //font brightening coefficients
  48. #define FONT_RedBrightFactor 350
  49. #define FONT_GreenBrightFactor 350
  50. #define FONT_BlueBrightFactor 350
  51. //shadows
  52. typedef enum {
  53. // cardinal directions of font shadows -- combine these at will
  54. FS_NONE = 0,
  55. FS_N = 1,
  56. FS_S = 2,
  57. FS_E = 4,
  58. FS_W = 8,
  59. FS_NE = 16,
  60. FS_NW = 32,
  61. FS_SE = 64,
  62. FS_SW = 128
  63. }
  64. FontShadowType;
  65. /*=============================================================================
  66. Type definitions:
  67. =============================================================================*/
  68. //structure of a character header
  69. typedef struct
  70. {
  71. ubyte *bitmap; //pointer to bitmap for character (was offset x/y)
  72. sword width, height; //size of character
  73. sword offsetX, offsetY; //offset in screen space to draw
  74. }
  75. charheader;
  76. typedef struct
  77. {
  78. sword u, v; //location of top-left corner of font
  79. sword width, height; //size of image
  80. sword offsetX, offsetY; //offset in screen space to draw
  81. }
  82. charfileheader;
  83. //structure of a font
  84. typedef struct
  85. {
  86. sdword nCharacters; //number of characters in font
  87. sdword spacing; //inter-character spacing
  88. sdword fullHeight; //total height of font, from top of tallest char to bottom of lowest hanging characters
  89. sdword baseLine; //y-value of baseline
  90. char *name; //optional name pointer
  91. sdword imageWidth; //dimensions of font image
  92. sdword imageHeight;
  93. sdword nColors; //colors in image palette
  94. color *palette; //pointer to palette
  95. ubyte *image; //pointer to image
  96. void* glFont;
  97. ubyte reserved[12]; //reserved for expansion of future attributes
  98. charheader *character[256]; //full character map
  99. }
  100. fontheader;
  101. //structure for a file header
  102. typedef struct
  103. {
  104. char identification[FONT_IdentLength]; //file type string
  105. uword version; //current version
  106. uword flags; //flags for font
  107. fontheader header;
  108. }
  109. fontfileheader;
  110. #define FONT_GL_MAXPAGES 4
  111. //structure for a GL font page
  112. typedef struct
  113. {
  114. sdword width, height; //dimensions
  115. real32 oneOverWidth, oneOverHeight; //1 / [dimensions]
  116. udword glhandle; //GL texture object
  117. udword pad;
  118. } glfontpage;
  119. //structure for a single GL font character
  120. typedef struct
  121. {
  122. glfontpage* page; //page this character resides on
  123. sword u, v; //location on page
  124. } glfontcharacter;
  125. //structure for a GL font (fonts as texture pages)
  126. typedef struct
  127. {
  128. sdword numPages; //number of font pages for this font
  129. glfontpage page[FONT_GL_MAXPAGES]; //page list
  130. glfontcharacter character[256]; //character list
  131. } glfontheader;
  132. //handle on fonts
  133. typedef udword fonthandle;
  134. /*=============================================================================
  135. Macros
  136. =============================================================================*/
  137. #define fontHeaderSize(nChars) (sizeof(fontheader))
  138. /*=============================================================================
  139. Functions:
  140. =============================================================================*/
  141. //load in a font
  142. fontheader *fontLoad(char *fileName);
  143. void fontDiscard(fonthandle font);
  144. void fontDiscardGL(fontheader* font);
  145. //select a font
  146. fonthandle fontMakeCurrent(fonthandle font);
  147. fonthandle fontCurrentGet(void);
  148. void fontShadowSet(FontShadowType s, color color);
  149. FontShadowType fontShadowGet(void);
  150. //printing fonts
  151. sdword fontPrintCentre(sdword y, color c, char *string);
  152. sdword fontPrintCentreCentreRectangle(rectangle *rect, color c, char *string);
  153. sdword fontPrint(sdword x, sdword y, color c, char *string);
  154. sdword fontPrintN(sdword x, sdword y, color c, char *string, sdword maxCharacters);
  155. sdword fontPrintf(sdword x, sdword y, color c, char *format, ...);
  156. sdword fontWidth(char *string);
  157. sdword fontWidthN(char *string, sdword maxCharacters);
  158. sdword fontWidthf(char *format, ...);
  159. sdword fontHeight(char *string);
  160. sdword fontHeightf(char *format, ...);
  161. void glfontRecreate(fontheader* header);
  162. #endif //___FONT_H