DEADSOFTWARE

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