/tags/beta-0_99_1/harbour/source/rtl/gtalleg/ssf.c

# · C · 210 lines · 133 code · 21 blank · 56 comment · 13 complexity · 739d06cf1db47d522c6f7bcdcbec16e4 MD5 · raw file

  1. /*
  2. * $Id: ssf.c 6619 2006-03-01 13:49:07Z druzus $
  3. */
  4. /*
  5. *
  6. * This file was conceived while I was developing an allegro based gt
  7. * (gtAlleg) for xHarbour, so it is brought under the same license terms.
  8. *
  9. */
  10. /*
  11. * xHarbour Project source code:
  12. * Simple Scalable Font library, main C module.
  13. *
  14. * Copyright 2004 Mauricio Abre <maurifull@datafull.com>
  15. * www - http: (yet to be constructed...)
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2, or (at your option)
  20. * any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this software; see the file COPYING. If not, write to
  29. * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  30. * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
  31. *
  32. * As a special exception, the Harbour Project gives permission for
  33. * additional uses of the text contained in its release of Harbour.
  34. *
  35. * The exception is that, if you link the Harbour libraries with other
  36. * files to produce an executable, this does not by itself cause the
  37. * resulting executable to be covered by the GNU General Public License.
  38. * Your use of that executable is in no way restricted on account of
  39. * linking the Harbour library code into it.
  40. *
  41. * This exception does not however invalidate any other reasons why
  42. * the executable file might be covered by the GNU General Public License.
  43. *
  44. * This exception applies only to the code released by the Harbour
  45. * Project under the name Harbour. If you copy code from other
  46. * Harbour Project or Free Software Foundation releases into a copy of
  47. * Harbour, as the General Public License permits, the exception does
  48. * not apply to the code that you add in this way. To avoid misleading
  49. * anyone as to the status of such modified files, you must delete
  50. * this exception notice from them.
  51. *
  52. * If you write modifications of your own for Harbour, it is your choice
  53. * whether to permit this exception to apply to your modifications.
  54. * If you do not wish that, delete this exception notice.
  55. *
  56. */
  57. #include <stdio.h>
  58. #include <stdlib.h>
  59. #include "hbapi.h"
  60. #include "ssf.h"
  61. #include "fixedth.sfc"
  62. ssfFont *ssfDefaultFont = &ssfFixedThinFont;
  63. #define fSize sfont->fsize
  64. #define fLeft points[0]
  65. #define fTop points[1]
  66. #define fRight points[2]
  67. #define fBottom points[3]
  68. #define fLeft2 points[4]
  69. #define fTop2 points[5]
  70. #define fRight2 points[6]
  71. #define fBottom2 points[7]
  72. void ssfSetFontSize(ssfFont *sfont, USHORT fsize)
  73. {
  74. fSize = fsize;
  75. }
  76. USHORT ssfDrawChar(AL_BITMAP *dst, ssfFont *sfont, char c, int x, int y, int color)
  77. {
  78. BYTE p;
  79. int i, j, thick;
  80. ssfGlyph charGlyph;
  81. ssfFrame charFrame;
  82. int points[8];
  83. float fScale;
  84. p = (BYTE) c;
  85. charGlyph = *sfont->chars[p];
  86. fScale = (float) ((float) sfont->fsize / (float) 65535);
  87. for (i = 0; i < charGlyph.num; i++)
  88. {
  89. charFrame = charGlyph.frames[i];
  90. if (charFrame.ftype == SSF_SPLINE2)
  91. {
  92. fLeft2 = x + (int) (fScale * charFrame.left);
  93. fTop2 = y + (int) (fScale * charFrame.top);
  94. fRight2 = x + (int) (fScale * charFrame.right);
  95. fBottom2 = y + (int) (fScale * charFrame.bottom);
  96. }
  97. else
  98. {
  99. fLeft = x + (int) (fScale * charFrame.left);
  100. fTop = y + (int) (fScale * charFrame.top);
  101. fRight = x + (int) (fScale * charFrame.right);
  102. fBottom = y + (int) (fScale * charFrame.bottom);
  103. }
  104. switch (charFrame.ftype)
  105. {
  106. case SSF_SPLINE2:
  107. thick = (int) (fScale * charFrame.thick);
  108. if (thick == 0)
  109. thick++;
  110. for (j = 0; j < thick; j++)
  111. {
  112. al_draw_spline(dst, points, color);
  113. switch (charFrame.thickdir)
  114. {
  115. case THICK_LEFT:
  116. fLeft--;
  117. fRight--;
  118. fLeft2--;
  119. fRight2--;
  120. break;
  121. case THICK_UP:
  122. fTop--;
  123. fBottom--;
  124. fTop2--;
  125. fBottom2--;
  126. break;
  127. case THICK_RIGHT:
  128. fLeft++;
  129. fRight++;
  130. fLeft2++;
  131. fRight2++;
  132. break;
  133. case THICK_DOWN:
  134. fTop++;
  135. fBottom++;
  136. fTop2++;
  137. fBottom2++;
  138. break;
  139. }
  140. }
  141. break;
  142. case SSF_LINE:
  143. thick = (int) (fScale * charFrame.thick);
  144. if (thick == 0)
  145. thick++;
  146. for (j = 0; j < thick; j++)
  147. {
  148. al_draw_line(dst, fLeft, fTop, fRight, fBottom, color);
  149. switch (charFrame.thickdir) {
  150. case THICK_LEFT:
  151. fLeft--;
  152. fRight--;
  153. break;
  154. case THICK_UP:
  155. fTop--;
  156. fBottom--;
  157. break;
  158. case THICK_RIGHT:
  159. fLeft++;
  160. fRight++;
  161. break;
  162. case THICK_DOWN:
  163. fTop++;
  164. fBottom++;
  165. break;
  166. }
  167. }
  168. break;
  169. case SSF_BOX:
  170. al_draw_rect_fill(dst, fLeft, fTop, fRight, fBottom, color);
  171. break;
  172. case SSF_TRIANGLE:
  173. thick = x + (int) (fScale * charFrame.thick);
  174. al_draw_triangle(dst, fLeft, fTop, fRight, fBottom, thick, y + (int) (fScale * charFrame.thickdir), color);
  175. break;
  176. }
  177. }
  178. return (sfont->fsize / 2);
  179. }
  180. int ssfDrawText(AL_BITMAP *dst, ssfFont *sfont, char *s, int x, int y, int color)
  181. {
  182. int i = 0;
  183. while ( s[i] )
  184. {
  185. x += ssfDrawChar(dst, sfont, s[i], x, y, color);
  186. i++;
  187. }
  188. return x;
  189. }