2
0

sdl_ttf.pas 23 KB

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