FONT.CPP 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program 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. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***************************************************************************
  19. ** 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 **
  20. ***************************************************************************
  21. * *
  22. * Project Name : LIBRARY *
  23. * *
  24. * File Name : FONT.C *
  25. * *
  26. * Programmer : David Dettmer *
  27. * *
  28. * Last Update : July 20, 1994 [SKB] *
  29. * *
  30. *-------------------------------------------------------------------------*
  31. * Functions: *
  32. * Char_Pixel_Width -- Return pixel width of a character. *
  33. * String_Pixel_Width -- Return pixel width of a string of characters. *
  34. * Get_Next_Text_Print_XY -- Calculates X and Y given ret value from Text_P*
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #include "font.h"
  37. #include <malloc.h>
  38. #include <dos.h>
  39. #include <fcntl.h>
  40. #include <io.h>
  41. #include <sys\stat.h>
  42. #include <string.h>
  43. #include <wwstd.h>
  44. /***************************************************************************
  45. * CHAR_PIXEL_WIDTH -- Return pixel width of a character. *
  46. * *
  47. * Retreives the pixel width of a character from the font width block. *
  48. * *
  49. * INPUT: Character. *
  50. * *
  51. * OUTPUT: Pixel width of a string of characters. *
  52. * *
  53. * WARNINGS: Set_Font must have been called first. *
  54. * *
  55. * HISTORY: *
  56. * 01/31/1992 DRD : Created. *
  57. * 06/30/1994 SKB : Converted to 32 bit library. *
  58. *=========================================================================*/
  59. int __cdecl Char_Pixel_Width(char chr)
  60. {
  61. int width;
  62. width = (unsigned char)*(FontWidthBlockPtr + (unsigned char)chr) + FontXSpacing;
  63. return(width);
  64. }
  65. /***************************************************************************
  66. * STRING_PIXEL_WIDTH -- Return pixel width of a string of characters. *
  67. * *
  68. * Calculates the pixel width of a string of characters. This uses *
  69. * the font width block for the widths. *
  70. * *
  71. * INPUT: Pointer to string of characters. *
  72. * *
  73. * OUTPUT: Pixel width of a string of characters. *
  74. * *
  75. * WARNINGS: Set_Font must have been called first. *
  76. * *
  77. * HISTORY: *
  78. * 01/30/1992 DRD : Created. *
  79. * 01/31/1992 DRD : Use Char_Pixel_Width. *
  80. * 06/30/1994 SKB : Converted to 32 bit library. *
  81. *=========================================================================*/
  82. unsigned int __cdecl String_Pixel_Width(char const *string)
  83. {
  84. WORD width; // Working accumulator of string width.
  85. WORD largest = 0; // Largest recorded width of the string.
  86. if (!string) return(0);
  87. width = 0;
  88. while (*string) {
  89. if (*string == '\r') {
  90. string++;
  91. largest = MAX(largest, width);
  92. width = 0;
  93. } else {
  94. width += Char_Pixel_Width(*string++); // add each char's width
  95. }
  96. }
  97. largest = MAX(largest, width);
  98. return(largest);
  99. }
  100. /***************************************************************************
  101. * GET_NEXT_TEXT_PRINT_XY -- Calculates X and Y given ret value from Text_P*
  102. * *
  103. * *
  104. * INPUT: VVPC& vp - viewport that was printed to. *
  105. * unsigned long offset - offset that Text_Print returned. *
  106. * INT *x - x return value. *
  107. * INT *y - y return value. *
  108. * *
  109. * OUTPUT: x and y are set. *
  110. * *
  111. * WARNINGS: *
  112. * *
  113. * HISTORY: *
  114. * 07/20/1994 SKB : Created. *
  115. *=========================================================================*/
  116. VOID __cdecl Get_Next_Text_Print_XY(GraphicViewPortClass& gp, unsigned long offset, INT *x, INT *y)
  117. {
  118. INT buffwidth;
  119. if (offset) {
  120. buffwidth = gp.Get_Width() + gp.Get_XAdd();
  121. offset -= gp.Get_Offset();
  122. *x = offset % buffwidth;
  123. *y = offset / buffwidth;
  124. } else {
  125. *x = *y = 0;
  126. }
  127. }