sdl_ttf.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. unit sdl_ttf;
  2. {
  3. $Id: sdl_ttf.pas,v 1.18 2007/06/01 11:16:33 savage Exp $
  4. }
  5. {******************************************************************************}
  6. { }
  7. { JEDI-SDL : Pascal units for SDL - Simple DirectMedia Layer }
  8. { Conversion of the Simple DirectMedia Layer Headers }
  9. { }
  10. { Portions created by Sam Lantinga <[email protected]> are }
  11. { Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga }
  12. { 5635-34 Springhouse Dr. }
  13. { Pleasanton, CA 94588 (USA) }
  14. { }
  15. { All Rights Reserved. }
  16. { }
  17. { The original files are : SDL_ttf.h }
  18. { }
  19. { The initial developer of this Pascal code was : }
  20. { Dominqiue Louis <[email protected]> }
  21. { }
  22. { Portions created by Dominqiue Louis are }
  23. { Copyright (C) 2000 - 2001 Dominqiue Louis. }
  24. { }
  25. { }
  26. { Contributor(s) }
  27. { -------------- }
  28. { Tom Jones <[email protected]> His Project inspired this conversion }
  29. { }
  30. { Obtained through: }
  31. { Joint Endeavour of Delphi Innovators ( Project JEDI ) }
  32. { }
  33. { You may retrieve the latest version of this file at the Project }
  34. { JEDI home page, located at http://delphi-jedi.org }
  35. { }
  36. { The contents of this file are used with permission, subject to }
  37. { the Mozilla Public License Version 1.1 (the "License"); you may }
  38. { not use this file except in compliance with the License. You may }
  39. { obtain a copy of the License at }
  40. { http://www.mozilla.org/MPL/MPL-1.1.html }
  41. { }
  42. { Software distributed under the License is distributed on an }
  43. { "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
  44. { implied. See the License for the specific language governing }
  45. { rights and limitations under the License. }
  46. { }
  47. { Description }
  48. { ----------- }
  49. { }
  50. { }
  51. { }
  52. { }
  53. { }
  54. { }
  55. { }
  56. { Requires }
  57. { -------- }
  58. { The SDL Runtime libraris on Win32 : SDL.dll on Linux : libSDL.so }
  59. { They are available from... }
  60. { http://www.libsdl.org . }
  61. { }
  62. { Programming Notes }
  63. { ----------------- }
  64. { }
  65. { }
  66. { }
  67. { }
  68. { Revision History }
  69. { ---------------- }
  70. { December 08 2002 - DL : Fixed definition of TTF_RenderUnicode_Solid }
  71. { }
  72. { April 03 2003 - DL : Added jedi-sdl.inc include file to support more }
  73. { Pascal compilers. Initial support is now included }
  74. { for GnuPascal, VirtualPascal, TMT and obviously }
  75. { continue support for Delphi Kylix and FreePascal. }
  76. { }
  77. { April 24 2003 - DL : under instruction from Alexey Barkovoy, I have added}
  78. { better TMT Pascal support and under instruction }
  79. { from Prof. Abimbola Olowofoyeku (The African Chief),}
  80. { I have added better Gnu Pascal support }
  81. { }
  82. { April 30 2003 - DL : under instruction from David Mears AKA }
  83. { Jason Siletto, I have added FPC Linux support. }
  84. { This was compiled with fpc 1.1, so remember to set }
  85. { include file path. ie. -Fi/usr/share/fpcsrc/rtl/* }
  86. { }
  87. {
  88. $Log: sdl_ttf.pas,v $
  89. Revision 1.18 2007/06/01 11:16:33 savage
  90. Added IFDEF UNIX for Workaround.
  91. Revision 1.17 2007/06/01 08:38:21 savage
  92. Added TTF_RenderText_Solid workaround as suggested by Michalis Kamburelis
  93. Revision 1.16 2007/05/29 21:32:14 savage
  94. Changes as suggested by Almindor for 64bit compatibility.
  95. Revision 1.15 2007/05/20 20:32:45 savage
  96. Initial Changes to Handle 64 Bits
  97. Revision 1.14 2006/12/02 00:19:01 savage
  98. Updated to latest version
  99. Revision 1.13 2005/04/10 11:48:33 savage
  100. Changes as suggested by Michalis, thanks.
  101. Revision 1.12 2005/01/05 01:47:14 savage
  102. Changed LibName to reflect what MacOS X should have. ie libSDL*-1.2.0.dylib respectively.
  103. Revision 1.11 2005/01/04 23:14:57 savage
  104. Changed LibName to reflect what most Linux distros will have. ie libSDL*-1.2.so.0 respectively.
  105. Revision 1.10 2005/01/02 19:07:32 savage
  106. Slight bug fix to use LongInt instead of Long ( Thanks Michalis Kamburelis )
  107. Revision 1.9 2005/01/01 02:15:20 savage
  108. Updated to v2.0.7
  109. Revision 1.8 2004/10/07 21:02:32 savage
  110. Fix for FPC
  111. Revision 1.7 2004/09/30 22:39:50 savage
  112. Added a true type font class which contains a wrap text function.
  113. Changed the sdl_ttf.pas header to reflect the future of jedi-sdl.
  114. Revision 1.6 2004/08/14 22:54:30 savage
  115. Updated so that Library name defines are correctly defined for MacOS X.
  116. Revision 1.5 2004/05/10 14:10:04 savage
  117. Initial MacOS X support. Fixed defines for MACOS ( Classic ) and DARWIN ( MacOS X ).
  118. Revision 1.4 2004/04/13 09:32:08 savage
  119. Changed Shared object names back to just the .so extension to avoid conflicts on various Linux/Unix distros. Therefore developers will need to create Symbolic links to the actual Share Objects if necessary.
  120. Revision 1.3 2004/04/01 20:53:24 savage
  121. Changed Linux Shared Object names so they reflect the Symbolic Links that are created when installing the RPMs from the SDL site.
  122. Revision 1.2 2004/03/30 20:23:28 savage
  123. Tidied up use of UNIX compiler directive.
  124. Revision 1.1 2004/02/16 22:16:40 savage
  125. v1.0 changes
  126. }
  127. {******************************************************************************}
  128. {$I jedi-sdl.inc}
  129. {
  130. Define this to workaround a known bug in some freetype versions.
  131. The error manifests as TTF_RenderGlyph_Solid returning nil (error)
  132. and error message (in SDL_Error) is
  133. "Failed loading DPMSDisable: /usr/lib/libX11.so.6: undefined symbol: DPMSDisable"
  134. See [http://lists.libsdl.org/pipermail/sdl-libsdl.org/2007-March/060459.html]
  135. }
  136. {$IFDEF UNIX}
  137. {$DEFINE Workaround_TTF_RenderText_Solid}
  138. {$ENDIF}
  139. interface
  140. uses
  141. {$IFDEF __GPC__}
  142. gpc,
  143. {$ENDIF}
  144. {$IFDEF WINDOWS}
  145. {$IFNDEF __GPC__}
  146. Windows,
  147. {$ENDIF}
  148. {$ENDIF}
  149. sdl;
  150. const
  151. {$IFDEF WINDOWS}
  152. SDLttfLibName = 'SDL_ttf.dll';
  153. {$ENDIF}
  154. {$IFDEF UNIX}
  155. {$IFDEF DARWIN}
  156. SDLttfLibName = 'libSDL_ttf-2.0.0.dylib';
  157. {$ELSE}
  158. {$IFDEF FPC}
  159. SDLttfLibName = 'libSDL_ttf.so';
  160. {$ELSE}
  161. SDLttfLibName = 'libSDL_ttf-2.0.so.0';
  162. {$ENDIF}
  163. {$ENDIF}
  164. {$ENDIF}
  165. {$IFDEF MACOS}
  166. SDLttfLibName = 'SDL_ttf';
  167. {$ENDIF}
  168. {* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL *}
  169. SDL_TTF_MAJOR_VERSION = 2;
  170. {$EXTERNALSYM SDL_TTF_MAJOR_VERSION}
  171. SDL_TTF_MINOR_VERSION = 0;
  172. {$EXTERNALSYM SDL_TTF_MINOR_VERSION}
  173. SDL_TTF_PATCHLEVEL = 8;
  174. {$EXTERNALSYM SDL_TTF_PATCHLEVEL}
  175. // Backwards compatibility
  176. TTF_MAJOR_VERSION = SDL_TTF_MAJOR_VERSION;
  177. TTF_MINOR_VERSION = SDL_TTF_MINOR_VERSION;
  178. TTF_PATCHLEVEL = SDL_TTF_PATCHLEVEL;
  179. {*
  180. Set and retrieve the font style
  181. This font style is implemented by modifying the font glyphs, and
  182. doesn't reflect any inherent properties of the truetype font file.
  183. *}
  184. TTF_STYLE_NORMAL = $00;
  185. TTF_STYLE_BOLD = $01;
  186. TTF_STYLE_ITALIC = $02;
  187. TTF_STYLE_UNDERLINE = $04;
  188. // ZERO WIDTH NO-BREAKSPACE (Unicode byte order mark)
  189. UNICODE_BOM_NATIVE = $FEFF;
  190. UNICODE_BOM_SWAPPED = $FFFE;
  191. type
  192. PTTF_Font = ^TTTF_font;
  193. TTTF_Font = record
  194. end;
  195. { This macro can be used to fill a version structure with the compile-time
  196. version of the SDL_ttf library. }
  197. procedure SDL_TTF_VERSION( var X : TSDL_version );
  198. {$EXTERNALSYM SDL_TTF_VERSION}
  199. { This function gets the version of the dynamically linked SDL_ttf library.
  200. It should NOT be used to fill a version structure, instead you should use the
  201. SDL_TTF_VERSION() macro. }
  202. function TTF_Linked_Version : PSDL_version;
  203. cdecl; external {$IFDEF __GPC__}name 'TTF_Linked_Version'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  204. {$EXTERNALSYM TTF_Linked_Version}
  205. { This function tells the library whether UNICODE text is generally
  206. byteswapped. A UNICODE BOM character in a string will override
  207. this setting for the remainder of that string.
  208. }
  209. procedure TTF_ByteSwappedUNICODE( swapped : integer );
  210. cdecl; external {$IFDEF __GPC__}name 'TTF_ByteSwappedUNICODE'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  211. {$EXTERNALSYM TTF_ByteSwappedUNICODE}
  212. //returns 0 on succes, -1 if error occurs
  213. function TTF_Init : integer;
  214. cdecl; external {$IFDEF __GPC__}name 'TTF_Init'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  215. {$EXTERNALSYM TTF_Init}
  216. {
  217. Open a font file and create a font of the specified point size.
  218. Some .fon fonts will have several sizes embedded in the file, so the
  219. point size becomes the index of choosing which size. If the value
  220. is too high, the last indexed size will be the default.
  221. }
  222. function TTF_OpenFont( const filename : Pchar; ptsize : integer ) : PTTF_Font;
  223. cdecl; external {$IFDEF __GPC__}name 'TTF_OpenFont'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  224. {$EXTERNALSYM TTF_OpenFont}
  225. function TTF_OpenFontIndex( const filename : Pchar; ptsize : integer; index : Longint ): PTTF_Font;
  226. cdecl; external {$IFDEF __GPC__}name 'TTF_OpenFontIndex'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  227. {$EXTERNALSYM TTF_OpenFontIndex}
  228. function TTF_OpenFontRW( src : PSDL_RWops; freesrc : integer; ptsize : integer ): PTTF_Font;
  229. cdecl; external {$IFDEF __GPC__}name 'TTF_OpenFontRW'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  230. {$EXTERNALSYM TTF_OpenFontRW}
  231. function TTF_OpenFontIndexRW( src : PSDL_RWops; freesrc : integer; ptsize : integer; index : Longint ): PTTF_Font;
  232. cdecl; external {$IFDEF __GPC__}name 'TTF_OpenFontIndexRW'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  233. {$EXTERNALSYM TTF_OpenFontIndexRW}
  234. function TTF_GetFontStyle( font : PTTF_Font) : integer;
  235. cdecl; external {$IFDEF __GPC__}name 'TTF_GetFontStyle'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  236. {$EXTERNALSYM TTF_GetFontStyle}
  237. procedure TTF_SetFontStyle( font : PTTF_Font; style : integer );
  238. cdecl; external {$IFDEF __GPC__}name 'TTF_SetFontStyle'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  239. {$EXTERNALSYM TTF_SetFontStyle}
  240. { Get the total height of the font - usually equal to point size }
  241. function TTF_FontHeight( font : PTTF_Font ) : Integer;
  242. cdecl; external {$IFDEF __GPC__}name 'TTF_FontHeight'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  243. {$EXTERNALSYM TTF_FontHeight}
  244. { Get the offset from the baseline to the top of the font
  245. This is a positive value, relative to the baseline.
  246. }
  247. function TTF_FontAscent( font : PTTF_Font ) : Integer;
  248. cdecl; external {$IFDEF __GPC__}name 'TTF_FontAscent'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  249. {$EXTERNALSYM TTF_FontAscent}
  250. { Get the offset from the baseline to the bottom of the font
  251. This is a negative value, relative to the baseline.
  252. }
  253. function TTF_FontDescent( font : PTTF_Font ) : Integer;
  254. cdecl; external {$IFDEF __GPC__}name 'TTF_FontDescent'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  255. {$EXTERNALSYM TTF_FontDescent}
  256. { Get the recommended spacing between lines of text for this font }
  257. function TTF_FontLineSkip( font : PTTF_Font ): Integer;
  258. cdecl; external {$IFDEF __GPC__}name 'TTF_FontLineSkip'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  259. {$EXTERNALSYM TTF_FontLineSkip}
  260. { Get the number of faces of the font }
  261. function TTF_FontFaces( font : PTTF_Font ) : Longint;
  262. cdecl; external {$IFDEF __GPC__}name 'TTF_FontFaces'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  263. {$EXTERNALSYM TTF_FontFaces}
  264. { Get the font face attributes, if any }
  265. function TTF_FontFaceIsFixedWidth( font : PTTF_Font ): Integer;
  266. cdecl; external {$IFDEF __GPC__}name 'TTF_FontFaceIsFixedWidth'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  267. {$EXTERNALSYM TTF_FontFaceIsFixedWidth}
  268. function TTF_FontFaceFamilyName( font : PTTF_Font ): PChar;
  269. cdecl; external {$IFDEF __GPC__}name 'TTF_FontFaceFamilyName'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  270. {$EXTERNALSYM TTF_FontFaceFamilyName}
  271. function TTF_FontFaceStyleName( font : PTTF_Font ): PChar;
  272. cdecl; external {$IFDEF __GPC__}name 'TTF_FontFaceStyleName'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  273. {$EXTERNALSYM TTF_FontFaceStyleName}
  274. { Get the metrics (dimensions) of a glyph }
  275. function TTF_GlyphMetrics( font : PTTF_Font; ch : Uint16;
  276. var minx : integer; var maxx : integer;
  277. var miny : integer; var maxy : integer;
  278. var advance : integer ): Integer;
  279. cdecl; external {$IFDEF __GPC__}name 'TTF_GlyphMetrics'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  280. {$EXTERNALSYM TTF_GlyphMetrics}
  281. { Get the dimensions of a rendered string of text }
  282. function TTF_SizeText( font : PTTF_Font; const text : PChar; var w : integer; var y : integer ): Integer;
  283. cdecl; external {$IFDEF __GPC__}name 'TTF_SizeText'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  284. {$EXTERNALSYM TTF_SizeText}
  285. function TTF_SizeUTF8( font : PTTF_Font; const text : PChar; var w : integer; var y : integer): Integer;
  286. cdecl; external {$IFDEF __GPC__}name 'TTF_SizeUTF8'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  287. {$EXTERNALSYM TTF_SizeUTF8}
  288. function TTF_SizeUNICODE( font : PTTF_Font; const text : PUint16; var w : integer; var y : integer): Integer;
  289. cdecl; external {$IFDEF __GPC__}name 'TTF_SizeUNICODE'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  290. {$EXTERNALSYM TTF_SizeUNICODE}
  291. { Create an 8-bit palettized surface and render the given text at
  292. fast quality with the given font and color. The 0 pixel is the
  293. colorkey, giving a transparent background, and the 1 pixel is set
  294. to the text color.
  295. This function returns the new surface, or NULL if there was an error.
  296. }
  297. function TTF_RenderText_Solid( font : PTTF_Font;
  298. const text : PChar; fg : TSDL_Color ): PSDL_Surface;
  299. {$IFNDEF Workaround_TTF_RenderText_Solid}
  300. cdecl; external {$IFDEF __GPC__}name 'TTF_RenderText_Solid'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  301. {$EXTERNALSYM TTF_RenderText_Solid}
  302. {$ENDIF}
  303. function TTF_RenderUTF8_Solid( font : PTTF_Font;
  304. const text : PChar; fg : TSDL_Color ): PSDL_Surface;
  305. cdecl; external {$IFDEF __GPC__}name 'TTF_RenderUTF8_Solid'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  306. {$EXTERNALSYM TTF_RenderUTF8_Solid}
  307. function TTF_RenderUNICODE_Solid( font : PTTF_Font;
  308. const text :PUint16; fg : TSDL_Color ): PSDL_Surface;
  309. cdecl; external {$IFDEF __GPC__}name 'TTF_RenderUNICODE_Solid'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  310. {$EXTERNALSYM TTF_RenderUNICODE_Solid}
  311. {
  312. Create an 8-bit palettized surface and render the given glyph at
  313. fast quality with the given font and color. The 0 pixel is the
  314. colorkey, giving a transparent background, and the 1 pixel is set
  315. to the text color. The glyph is rendered without any padding or
  316. centering in the X direction, and aligned normally in the Y direction.
  317. This function returns the new surface, or NULL if there was an error.
  318. }
  319. function TTF_RenderGlyph_Solid( font : PTTF_Font;
  320. ch : Uint16; fg : TSDL_Color ): PSDL_Surface;
  321. cdecl; external {$IFDEF __GPC__}name 'TTF_RenderGlyph_Solid'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  322. {$EXTERNALSYM TTF_RenderGlyph_Solid}
  323. { Create an 8-bit palettized surface and render the given text at
  324. high quality with the given font and colors. The 0 pixel is background,
  325. while other pixels have varying degrees of the foreground color.
  326. This function returns the new surface, or NULL if there was an error.
  327. }
  328. function TTF_RenderText_Shaded( font : PTTF_Font;
  329. const text : PChar; fg : TSDL_Color; bg : TSDL_Color ): PSDL_Surface;
  330. cdecl; external {$IFDEF __GPC__}name 'TTF_RenderText_Shaded'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  331. {$EXTERNALSYM TTF_RenderText_Shaded}
  332. function TTF_RenderUTF8_Shaded( font : PTTF_Font;
  333. const text : PChar; fg : TSDL_Color; bg : TSDL_Color ): PSDL_Surface;
  334. cdecl; external {$IFDEF __GPC__}name 'TTF_RenderUTF8_Shaded'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  335. {$EXTERNALSYM TTF_RenderUTF8_Shaded}
  336. function TTF_RenderUNICODE_Shaded( font : PTTF_Font;
  337. const text : PUint16; fg : TSDL_Color; bg : TSDL_Color ): PSDL_Surface;
  338. cdecl; external {$IFDEF __GPC__}name 'TTF_RenderUNICODE_Shaded'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  339. {$EXTERNALSYM TTF_RenderUNICODE_Shaded}
  340. { Create an 8-bit palettized surface and render the given glyph at
  341. high quality with the given font and colors. The 0 pixel is background,
  342. while other pixels have varying degrees of the foreground color.
  343. The glyph is rendered without any padding or centering in the X
  344. direction, and aligned normally in the Y direction.
  345. This function returns the new surface, or NULL if there was an error.
  346. }
  347. function TTF_RenderGlyph_Shaded( font : PTTF_Font; ch : Uint16; fg : TSDL_Color;
  348. bg : TSDL_Color ): PSDL_Surface;
  349. cdecl; external {$IFDEF __GPC__}name 'TTF_RenderGlyph_Shaded'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  350. {$EXTERNALSYM TTF_RenderGlyph_Shaded}
  351. { Create a 32-bit ARGB surface and render the given text at high quality,
  352. using alpha blending to dither the font with the given color.
  353. This function returns the new surface, or NULL if there was an error.
  354. }
  355. function TTF_RenderText_Blended( font : PTTF_Font;
  356. const text : PChar; fg : TSDL_Color ): PSDL_Surface;
  357. cdecl; external {$IFDEF __GPC__}name 'TTF_RenderText_Blended'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  358. {$EXTERNALSYM TTF_RenderText_Blended}
  359. function TTF_RenderUTF8_Blended( font : PTTF_Font;
  360. const text : PChar; fg : TSDL_Color ): PSDL_Surface;
  361. cdecl; external {$IFDEF __GPC__}name 'TTF_RenderUTF8_Blended'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  362. {$EXTERNALSYM TTF_RenderUTF8_Blended}
  363. function TTF_RenderUNICODE_Blended( font : PTTF_Font;
  364. const text: PUint16; fg : TSDL_Color ): PSDL_Surface;
  365. cdecl; external {$IFDEF __GPC__}name 'TTF_RenderUNICODE_Blended'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  366. {$EXTERNALSYM TTF_RenderUNICODE_Blended}
  367. { Create a 32-bit ARGB surface and render the given glyph at high quality,
  368. using alpha blending to dither the font with the given color.
  369. The glyph is rendered without any padding or centering in the X
  370. direction, and aligned normally in the Y direction.
  371. This function returns the new surface, or NULL if there was an error.
  372. }
  373. function TTF_RenderGlyph_Blended( font : PTTF_Font; ch : Uint16; fg : TSDL_Color ): PSDL_Surface;
  374. cdecl; external {$IFDEF __GPC__}name 'TTF_RenderGlyph_Blended'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  375. {$EXTERNALSYM TTF_RenderGlyph_Blended}
  376. { For compatibility with previous versions, here are the old functions }
  377. {#define TTF_RenderText(font, text, fg, bg)
  378. TTF_RenderText_Shaded(font, text, fg, bg)
  379. #define TTF_RenderUTF8(font, text, fg, bg)
  380. TTF_RenderUTF8_Shaded(font, text, fg, bg)
  381. #define TTF_RenderUNICODE(font, text, fg, bg)
  382. TTF_RenderUNICODE_Shaded(font, text, fg, bg)}
  383. { Close an opened font file }
  384. procedure TTF_CloseFont( font : PTTF_Font );
  385. cdecl; external {$IFDEF __GPC__}name 'TTF_CloseFont'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  386. {$EXTERNALSYM TTF_CloseFont}
  387. //De-initialize TTF engine
  388. procedure TTF_Quit;
  389. cdecl; external {$IFDEF __GPC__}name 'TTF_Quit'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  390. {$EXTERNALSYM TTF_Quit}
  391. // Check if the TTF engine is initialized
  392. function TTF_WasInit : integer;
  393. cdecl; external {$IFDEF __GPC__}name 'TTF_WasInit'{$ELSE} SDLttfLibName{$ENDIF __GPC__};
  394. {$EXTERNALSYM TTF_WasInit}
  395. // We'll use SDL for reporting errors
  396. procedure TTF_SetError( fmt : PChar );
  397. function TTF_GetError : PChar;
  398. implementation
  399. {$IFDEF __GPC__}
  400. {$L 'sdl_ttf'} { link sdl_ttf.dll.a or libsdl_ttf.so or libsdl_ttf.a }
  401. {$ENDIF}
  402. procedure SDL_TTF_VERSION( var X : TSDL_version );
  403. begin
  404. X.major := SDL_TTF_MAJOR_VERSION;
  405. X.minor := SDL_TTF_MINOR_VERSION;
  406. X.patch := SDL_TTF_PATCHLEVEL;
  407. end;
  408. procedure TTF_SetError( fmt : PChar );
  409. begin
  410. SDL_SetError( fmt );
  411. end;
  412. function TTF_GetError : PChar;
  413. begin
  414. result := SDL_GetError;
  415. end;
  416. {$IFDEF Workaround_TTF_RenderText_Solid}
  417. function TTF_RenderText_Solid( font : PTTF_Font;
  418. const text : PChar; fg : TSDL_Color ): PSDL_Surface;
  419. const
  420. Black: TSDL_Color = (r: 0; g: 0; b: 0; unused: 0);
  421. begin
  422. Result := TTF_RenderText_Shaded(font, text, fg, Black);
  423. end;
  424. {$ENDIF Workaround_TTF_RenderText_Solid}
  425. end.