DEADSOFTWARE

put "{$MODE ...}" directive in each source file; removed trailing spaces, and convert...
[d2df-sdl.git] / src / lib / sdl2 / SDL2_ttf.pas
1 {$MODE DELPHI}
2 unit sdl2_ttf;
4 {*
5 SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts
6 Copyright (C) 2001-2013 Sam Lantinga <slouken@libsdl.org>
8 This software is provided 'as-is', without any express or implied
9 warranty. In no event will the authors be held liable for any damages
10 arising from the use of this software.
12 Permission is granted to anyone to use this software for any purpose,
13 including commercial applications, and to alter it and redistribute it
14 freely, subject to the following restrictions:
16 1. The origin of this software must not be misrepresented; you must not
17 claim that you wrote the original software. If you use this software
18 in a product, an acknowledgement in the product documentation would be
19 appreciated but is not required.
20 2. Altered source versions must be plainly marked as such, and must not be
21 misrepresented as being the original software.
22 3. This notice may not be removed or altered from any source distribution.
23 *}
25 {* This library is a wrapper around the excellent FreeType 2.0 library,
26 available at:
27 http://www.freetype.org/
28 *}
30 {* ChangeLog: (Header Translation)
31 ----------
33 v.1.72-stable; 29.09.2013: fixed bug with procedures without parameters
34 (they must have brackets)
35 v.1.70-stable; 11.09.2013: Initial Commit
37 *}
39 interface
41 {$I jedi.inc}
43 uses
44 SDL2;
46 const
47 {$IFDEF WINDOWS}
48 TTF_LibName = 'SDL2_ttf.dll';
49 {$ENDIF}
51 {$IFDEF UNIX}
52 {$IFDEF DARWIN}
53 TTF_LibName = 'libSDL2_tff.dylib';
54 {$ELSE}
55 {$IFDEF FPC}
56 TTF_LibName = 'libSDL2_ttf.so';
57 {$ELSE}
58 TTF_LibName = 'libSDL2_ttf.so.0';
59 {$ENDIF}
60 {$ENDIF}
61 {$ENDIF}
63 {$IFDEF MACOS}
64 TTF_LibName = 'SDL2_ttf';
65 {$IFDEF FPC}
66 {$linklib libSDL2_ttf}
67 {$ENDIF}
68 {$ENDIF}
70 {* Set up for C function definitions, even when using C++ *}
72 {* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL *}
73 const
74 SDL_TTF_MAJOR_VERSION = 2;
75 SDL_TTF_MINOR_VERSION = 0;
76 SDL_TTF_PATCHLEVEL = 12;
78 Procedure SDL_TTF_VERSION(Out X:TSDL_Version);
80 {* Backwards compatibility *}
81 const
82 TTF_MAJOR_VERSION = SDL_TTF_MAJOR_VERSION;
83 TTF_MINOR_VERSION = SDL_TTF_MINOR_VERSION;
84 TTF_PATCHLEVEL = SDL_TTF_PATCHLEVEL;
85 //TTF_VERSION(X) = SDL_TTF_VERSION(X);
87 {* This function gets the version of the dynamically linked SDL_ttf library.
88 it should NOT be used to fill a version structure, instead you should
89 use the SDL_TTF_VERSION() macro.
90 *}
91 function TTF_Linked_Version: TSDL_Version cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_Linked_Version' {$ENDIF} {$ENDIF};
93 {* ZERO WIDTH NO-BREAKSPACE (Unicode byte order mark) *}
94 const
95 UNICODE_BOM_NATIVE = $FEFF;
96 UNICODE_BOM_SWAPPED = $FFFE;
98 {* This function tells the library whether UNICODE text is generally
99 byteswapped. A UNICODE BOM character in a string will override
100 this setting for the remainder of that string.
101 *}
102 procedure TTF_ByteSwappedUNICODE(swapped: Integer) cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_ByteSwappedUNICODE' {$ENDIF} {$ENDIF};
104 {* The internal structure containing font information *}
105 type
106 PTTF_Font = ^TTTF_Font;
107 TTTF_Font = record end; //todo?
109 {* Initialize the TTF engine - returns 0 if successful, -1 on error *}
110 function TTF_Init(): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_Init' {$ENDIF} {$ENDIF};
112 {* Open a font file and create a font of the specified point size.
113 * Some .fon fonts will have several sizes embedded in the file, so the
114 * point size becomes the index of choosing which size. If the value
115 * is too high, the last indexed size will be the default. *}
116 function TTF_OpenFont(_file: PAnsiChar; ptsize: Integer): PTTF_Font cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_OpenFont' {$ENDIF} {$ENDIF};
117 function TTF_OpenFontIndex(_file: PAnsiChar; ptsize: Integer; index: LongInt): PTTF_Font cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_OpenFontIndex' {$ENDIF} {$ENDIF};
118 function TTF_OpenFontRW(src: PSDL_RWops; freesrc: Integer; ptsize: LongInt): PTTF_Font cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_OpenFontRW' {$ENDIF} {$ENDIF};
119 function TTF_OpenFontIndexRW(src: PSDL_RWops; freesrc: Integer; ptsize: Integer; index: LongInt): PTTF_Font cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_OpenFontIndexRW' {$ENDIF} {$ENDIF};
121 {* Set and retrieve the font style *}
122 const
123 TTF_STYLE_NORMAL = $00;
124 TTF_STYLE_BOLD = $01;
125 TTF_STYLE_ITALIC = $02;
126 TTF_STYLE_UNDERLINE = $04;
127 TTF_STYLE_STRIKETHROUGH = $08;
129 function TTF_GetFontStyle(font: PTTF_Font): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_GetFontStyle' {$ENDIF} {$ENDIF};
130 procedure TTF_SetFontStyle(font: PTTF_Font; style: Integer) cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_SetFontStyle' {$ENDIF} {$ENDIF};
131 function TTF_GetFontOutline(font: PTTF_Font): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_GetFontOutline' {$ENDIF} {$ENDIF};
132 procedure TTF_SetFontOutline(font: PTTF_Font; outline: Integer) cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_SetFontOutline' {$ENDIF} {$ENDIF};
134 {* Set and retrieve FreeType hinter settings *}
135 const
136 TTF_HINTING_NORMAL = 0;
137 TTF_HINTING_LIGHT = 1;
138 TTF_HINTING_MONO = 2;
139 TTF_HINTING_NONE = 3;
141 function TTF_GetFontHinting(font: PTTF_Font): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_GetFontHinting' {$ENDIF} {$ENDIF};
142 procedure TTF_SetFontHinting(font: PTTF_Font; hinting: Integer) cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_SetFontHinting' {$ENDIF} {$ENDIF};
144 {* Get the total height of the font - usually equal to point size *}
145 function TTF_FontHeight(font: PTTF_Font): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_FontHeight' {$ENDIF} {$ENDIF};
147 {* Get the offset from the baseline to the top of the font
148 This is a positive value, relative to the baseline.
149 *}
150 function TTF_FontAscent(font: PTTF_Font): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_FontAscent' {$ENDIF} {$ENDIF};
152 {* Get the offset from the baseline to the bottom of the font
153 This is a negative value, relative to the baseline.
154 *}
155 function TTF_FontDescent(font: PTTF_Font): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_FontDescent' {$ENDIF} {$ENDIF};
157 {* Get the recommended spacing between lines of text for this font *}
158 function TTF_FontLineSkip(font: PTTF_Font): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_FontLineSkip' {$ENDIF} {$ENDIF};
160 {* Get/Set whether or not kerning is allowed for this font *}
161 function TTF_GetFontKerning(font: PTTF_Font): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_GetFontKerning' {$ENDIF} {$ENDIF};
162 procedure TTF_SetFontKerning(font: PTTF_Font; allowed: Integer) cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_SetFontKerning' {$ENDIF} {$ENDIF};
164 {* Get the number of faces of the font *}
165 function TTF_FontFaces(font: PTTF_Font): LongInt cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_FontFaces' {$ENDIF} {$ENDIF};
167 {* Get the font face attributes, if any *}
168 function TTF_FontFaceIsFixedWidth(font: PTTF_Font): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_FontFaceIsFixedWidth' {$ENDIF} {$ENDIF};
169 function TTF_FontFaceFamilyName(font: PTTF_Font): PAnsiChar cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_FontFaceFamilyName' {$ENDIF} {$ENDIF};
170 function TTF_FontFaceStyleName(font: PTTF_Font): PAnsiChar cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_FontFaceStyleName' {$ENDIF} {$ENDIF};
172 {* Check wether a glyph is provided by the font or not *}
173 function TTF_GlyphIsProvided(font: PTTF_Font; ch: UInt16): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_GlyphIsProvided' {$ENDIF} {$ENDIF};
175 {* Get the metrics (dimensions) of a glyph
176 To understand what these metrics mean, here is a useful link:
177 http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
178 *}
179 function TTF_GlyphMetrics(font: PTTF_Font; ch: UInt16;
180 minx, maxx: PInt;
181 miny, maxy: PInt; advance: PInt): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_GlyphMetrics' {$ENDIF} {$ENDIF};
183 {* Get the dimensions of a rendered string of text *}
184 function TTF_SizeText(font: PTTF_Font; text: PAnsiChar; w, h: PInt): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_SizeText' {$ENDIF} {$ENDIF};
185 function TTF_SizeUTF8(font: PTTF_Font; text: PAnsiChar; w, h: PInt): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_SizeUTF8' {$ENDIF} {$ENDIF};
186 function TTF_SizeUNICODE(font: PTTF_Font; text: PUInt16; w, h: PInt): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_SizeUNICODE' {$ENDIF} {$ENDIF};
188 {* Create an 8-bit palettized surface and render the given text at
189 fast quality with the given font and color. The 0 pixel is the
190 colorkey, giving a transparent background, and the 1 pixel is set
191 to the text color.
192 This function returns the new surface, or NULL if there was an error.
193 *}
194 function TTF_RenderText_Solid(font: PTTF_Font; text: PAnsiChar; fg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderText_Solid' {$ENDIF} {$ENDIF};
195 function TTF_RenderUTF8_Solid(font: PTTF_Font; text: PAnsiChar; fg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderUTF8_Solid' {$ENDIF} {$ENDIF};
196 function TTF_RenderUNICODE_Solid(font: PTTF_Font; text: PUInt16; fg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderUNICODE_Solid' {$ENDIF} {$ENDIF};
198 {* Create an 8-bit palettized surface and render the given glyph at
199 fast quality with the given font and color. The 0 pixel is the
200 colorkey, giving a transparent background, and the 1 pixel is set
201 to the text color. The glyph is rendered without any padding or
202 centering in the X direction, and aligned normally in the Y direction.
203 This function returns the new surface, or NULL if there was an error.
204 *}
205 function TTF_RenderGlyph_Solid(font: PTTF_Font; ch: UInt16; fg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderGlyph_Solid' {$ENDIF} {$ENDIF};
207 {* Create an 8-bit palettized surface and render the given text at
208 high quality with the given font and colors. The 0 pixel is background,
209 while other pixels have varying degrees of the foreground color.
210 This function returns the new surface, or NULL if there was an error.
211 *}
212 function TTF_RenderText_Shaded(font: PTTF_Font; text: PAnsiChar; fg, bg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderText_Shaded' {$ENDIF} {$ENDIF};
213 function TTF_RenderUTF8_Shaded(font: PTTF_Font; text: PAnsiChar; fg, bg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderUTF8_Shaded' {$ENDIF} {$ENDIF};
214 function TTF_RenderUNICODE_Shaded(font: PTTF_Font; text: PUInt16; fg, bg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderUNICODE_Shaded' {$ENDIF} {$ENDIF};
216 {* Create an 8-bit palettized surface and render the given glyph at
217 high quality with the given font and colors. The 0 pixel is background,
218 while other pixels have varying degrees of the foreground color.
219 The glyph is rendered without any padding or centering in the X
220 direction, and aligned normally in the Y direction.
221 This function returns the new surface, or NULL if there was an error.
222 *}
223 function TTF_RenderGlyph_Shaded(font: PTTF_Font; ch: UInt16; fg, bg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderGlyph_Shaded' {$ENDIF} {$ENDIF};
225 {* Create a 32-bit ARGB surface and render the given text at high quality,
226 using alpha blending to dither the font with the given color.
227 This function returns the new surface, or NULL if there was an error.
228 *}
229 function TTF_RenderText_Blended(font: PTTF_Font; text: PAnsiChar; fg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderText_Blended' {$ENDIF} {$ENDIF};
230 function TTF_RenderUTF8_Blended(font: PTTF_Font; text: PAnsiChar; fg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderUTF8_Blended' {$ENDIF} {$ENDIF};
231 function TTF_RenderUNICODE_Blended(font: PTTF_Font; text: UInt16; fg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderUNICODE_Blended' {$ENDIF} {$ENDIF};
233 {* Create a 32-bit ARGB surface and render the given text at high quality,
234 using alpha blending to dither the font with the given color.
235 Text is wrapped to multiple lines on line endings and on word boundaries
236 if it extends beyond wrapLength in pixels.
237 This function returns the new surface, or NULL if there was an error.
238 *}
239 function TTF_RenderText_Blended_Wrapped(font: PTTF_Font; text: PAnsiChar; fg: TSDL_Color; wrapLength: UInt32): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderText_Blended_Wrapped' {$ENDIF} {$ENDIF};
240 function TTF_RenderUTF8_Blended_Wrapped(font: PTTF_Font; text: PAnsiChar; fg: TSDL_Color; wrapLength: UInt32): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderUTF8_Blended_Wrapped' {$ENDIF} {$ENDIF};
241 function TTF_RenderUNICODE_Blended_Wrapped(font: PTTF_Font; text: PUInt16; fg: TSDL_Color; wrapLength: UInt32): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderUNICODE_Blended_Wrapped' {$ENDIF} {$ENDIF};
243 {* Create a 32-bit ARGB surface and render the given glyph at high quality,
244 using alpha blending to dither the font with the given color.
245 The glyph is rendered without any padding or centering in the X
246 direction, and aligned normally in the Y direction.
247 This function returns the new surface, or NULL if there was an error.
248 *}
249 function TTF_RenderGlyph_Blended(font: PTTF_Font; ch: UInt16; fg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderGlyph_Blended' {$ENDIF} {$ENDIF};
251 {* For compatibility with previous versions, here are the old functions *}
252 function TTF_RenderText(font: PTTF_Font; text: PAnsiChar; fg, bg: TSDL_Color): PSDL_Surface;
253 function TTF_RenderUTF8(font: PTTF_Font; text: PAnsiChar; fg, bg: TSDL_Color): PSDL_Surface;
254 function TTF_RenderUNICODE(font: PTTF_Font; text: PUInt16; fg, bg: TSDL_Color): PSDL_Surface;
256 {* Close an opened font file *}
257 procedure TTF_CloseFont(font: PTTF_Font) cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_CloseFont' {$ENDIF} {$ENDIF};
259 {* De-initialize the TTF engine *}
260 procedure TTF_Quit() cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_Quit' {$ENDIF} {$ENDIF};
262 {* Check if the TTF engine is initialized *}
263 function TTF_WasInit: Boolean cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_WasInit' {$ENDIF} {$ENDIF};
265 {* Get the kerning size of two glyphs *}
266 function TTF_GetFontKerningSize(font: PTTF_Font; prev_index, index: Integer): Integer cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_GetFontKerningSize' {$ENDIF} {$ENDIF};
268 {* We'll use SDL for reporting errors *}
269 function TTF_SetError(const fmt: PAnsiChar): SInt32; cdecl;
270 function TTF_GetError: PAnsiChar; cdecl;
272 implementation
274 Procedure SDL_TTF_VERSION(Out X:TSDL_Version);
275 begin
276 x.major := SDL_TTF_MAJOR_VERSION;
277 x.minor := SDL_TTF_MINOR_VERSION;
278 x.patch := SDL_TTF_PATCHLEVEL;
279 end;
281 function TTF_SetError(const fmt: PAnsiChar): SInt32; cdecl;
282 begin
283 Result := SDL_SetError(fmt);
284 end;
286 function TTF_GetError: PAnsiChar; cdecl;
287 begin
288 Result := SDL_GetError();
289 end;
291 function TTF_RenderText(font: PTTF_Font; text: PAnsiChar; fg, bg: TSDL_Color): PSDL_Surface;
292 begin
293 Result := TTF_RenderText_Shaded(font, text, fg, bg);
294 end;
296 function TTF_RenderUTF8(font: PTTF_Font; text: PAnsiChar; fg, bg: TSDL_Color): PSDL_Surface;
297 begin
298 Result := TTF_RenderUTF8_Shaded(font, text, fg, bg);
299 end;
301 function TTF_RenderUNICODE(font: PTTF_Font; text: PUInt16; fg, bg: TSDL_Color): PSDL_Surface;
302 begin
303 Result := TTF_RenderUNICODE_Shaded(font, text, fg, bg);
304 end;
306 end.