Skip to content

Commit 5fd4006

Browse files
Merge pull request #19 from Free-Pascal-meets-SDL-Website/add-sdl3-ttf
Add SDL3_ttf unit
2 parents a70aac2 + 829a0f7 commit 5fd4006

File tree

2 files changed

+3136
-0
lines changed

2 files changed

+3136
-0
lines changed

units/SDL3_textengine.pas

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
unit SDL3_textengine;
2+
3+
{
4+
This file is part of:
5+
6+
SDL3 for Pascal
7+
(https://github.com/PascalGameDevelopment/SDL3-for-Pascal)
8+
SPDX-License-Identifier: Zlib
9+
}
10+
11+
{$DEFINE SDL_TTF_TEXTENGINE}
12+
13+
{$I sdl.inc}
14+
15+
interface
16+
17+
{$IFDEF WINDOWS}
18+
uses
19+
SDL3,
20+
SDL3_ttf,
21+
{$IFDEF FPC}
22+
ctypes,
23+
{$ENDIF}
24+
Windows;
25+
{$ENDIF}
26+
27+
{$IF DEFINED(UNIX) AND NOT DEFINED(ANDROID)}
28+
uses
29+
SDL3,
30+
SDL3_ttf,
31+
{$IFDEF FPC}
32+
ctypes,
33+
UnixType,
34+
{$ENDIF}
35+
{$IFDEF DARWIN}
36+
CocoaAll;
37+
{$ELSE}
38+
X,
39+
XLib;
40+
{$ENDIF}
41+
{$ENDIF}
42+
43+
{$IF DEFINED(UNIX) AND DEFINED(ANDROID) AND DEFINED(FPC)}
44+
uses
45+
SDL3,
46+
SDL3_ttf,
47+
ctypes,
48+
UnixType;
49+
{$ENDIF}
50+
51+
{*
52+
* \file SDL_textengine.h
53+
*
54+
* Definitions for implementations of the TTF_TextEngine interface.
55+
}
56+
57+
{ #note : SDL3-for-Pascal: Based on file SDL_textengine.h version 3.1.0 (preview). }
58+
59+
{*
60+
* A font atlas draw command.
61+
*
62+
* \since This enum is available since SDL_ttf 3.0.0.
63+
}
64+
type
65+
PPTTF_DrawCommand = ^PTTF_DrawCommand;
66+
PTTF_DrawCommand = ^TTTF_DrawCommand;
67+
TTTF_DrawCommand = type Integer;
68+
const
69+
TTF_DRAW_COMMAND_NOOP = TTTF_DrawCommand(0);
70+
TTF_DRAW_COMMAND_FILL = TTTF_DrawCommand(1);
71+
TTF_DRAW_COMMAND_COPY = TTTF_DrawCommand(2);
72+
73+
{*
74+
* A filled rectangle draw operation.
75+
*
76+
* \since This struct is available since SDL_ttf 3.0.0.
77+
*
78+
* \sa TTF_DrawOperation
79+
}
80+
type
81+
PPTTF_FillOperation = ^PTTF_FillOperation;
82+
PTTF_FillOperation = ^TTTF_FillOperation;
83+
TTTF_FillOperation = record
84+
cmd: TTTF_DrawCommand; {*< TTF_DRAW_COMMAND_FILL }
85+
rect: TSDL_Rect; {*< The rectangle to fill, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. }
86+
end;
87+
88+
{*
89+
* A texture copy draw operation.
90+
*
91+
* \since This struct is available since SDL_ttf 3.0.0.
92+
*
93+
* \sa TTF_DrawOperation
94+
}
95+
type
96+
PPTTF_CopyOperation = ^PTTF_CopyOperation;
97+
PTTF_CopyOperation = ^TTTF_CopyOperation;
98+
TTTF_CopyOperation = record
99+
cmd: TTTF_DrawCommand; {*< TTF_DRAW_COMMAND_COPY }
100+
text_offset: cint; {*< The offset in the text corresponding to this glyph.
101+
There may be multiple glyphs with the same text offset
102+
and the next text offset might be several Unicode codepoints
103+
later. In this case the glyphs and codepoints are grouped
104+
together and the group bounding box is the union of the dst
105+
rectangles for the corresponding glyphs. }
106+
glyph_font: PTTF_Font; {*< The font containing the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() }
107+
glyph_index: cuint32; {*< The glyph index of the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() }
108+
src: TSDL_Rect; {*< The area within the glyph to be drawn }
109+
dst: TSDL_Rect; {*< The drawing coordinates of the glyph, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. }
110+
reserved: Pointer;
111+
end;
112+
113+
{*
114+
* A text engine draw operation.
115+
*
116+
* \since This struct is available since SDL_ttf 3.0.0.
117+
}
118+
type
119+
PPTTF_DrawOperation = ^PTTF_DrawOperation;
120+
PTTF_DrawOperation = ^TTTF_DrawOperation;
121+
TTTF_DrawOperation = record
122+
case Integer of
123+
0: (cmd: TTTF_DrawCommand);
124+
1: (fill: TTTF_FillOperation);
125+
2: (copy: TTTF_CopyOperation);
126+
end;
127+
128+
{ Private data in TTF_Text, to assist in text measurement and layout }
129+
type
130+
PPTTF_TextLayout = ^PTTF_TextLayout;
131+
PTTF_TextLayout = type Pointer;
132+
133+
{ Private data in TTF_Text, available to implementations }
134+
type
135+
PPTTF_TextData = ^PTTF_TextData;
136+
PTTF_TextData = ^TTTF_TextData;
137+
TTTF_TextData = record
138+
font: PTTF_Font; {*< The font used by this text, read-only. }
139+
color: TSDL_FColor; {*< The color of the text, read-only. }
140+
141+
needs_layout_update: cbool; {*< True if the layout needs to be updated }
142+
layout: PTTF_TextLayout; {*< Cached layout information, read-only. }
143+
x: cint; {*< The x offset of the upper left corner of this text, in pixels, read-only. }
144+
y: cint; {*< The y offset of the upper left corner of this text, in pixels, read-only. }
145+
w: cint; {*< The width of this text, in pixels, read-only. }
146+
h: cint; {*< The height of this text, in pixels, read-only. }
147+
num_ops: cint; {*< The number of drawing operations to render this text, read-only. }
148+
ops: PTTF_DrawOperation; {*< The drawing operations used to render this text, read-only. }
149+
num_clusters: cint; {*< The number of substrings representing clusters of glyphs in the string, read-only }
150+
clusters: PTTF_SubString; {*< Substrings representing clusters of glyphs in the string, read-only }
151+
152+
props: TSDL_PropertiesID; {*< Custom properties associated with this text, read-only. This field is created as-needed using TTF_GetTextProperties() and the properties may be then set and read normally }
153+
154+
needs_engine_update: cbool; {*< True if the engine text needs to be updated }
155+
engine: PTTF_TextEngine; {*< The engine used to render this text, read-only. }
156+
engine_text: Pointer; {*< The implementation-specific representation of this text }
157+
end;
158+
159+
{*
160+
* A text engine interface.
161+
*
162+
* This structure should be initialized using SDL_INIT_INTERFACE()
163+
*
164+
* \since This struct is available since SDL_ttf 3.0.0.
165+
*
166+
* \sa SDL_INIT_INTERFACE
167+
}
168+
type
169+
PPTTF_TextEngine = ^PTTF_TextEngine;
170+
PTTF_TextEngine = ^TTTF_TextEngine;
171+
TTTF_TextEngine = record
172+
version: cuint32; {*< The version of this interface }
173+
userdata: Pointer; {*< User data Pointer passed to callbacks }
174+
175+
{ Create a text representation from draw instructions.
176+
*
177+
* All fields of `text` except `internal->engine_text` will already be filled out.
178+
*
179+
* This function should set the `internal->engine_text` field to a non-nil value.
180+
*
181+
* \param userdata the userdata Pointer in this interface.
182+
* \param text the text object being created.
183+
}
184+
CreateText: function(userdata: Pointer; text: PTTF_Text): cbool; cdecl;
185+
186+
{*
187+
* Destroy a text representation.
188+
}
189+
DestroyText: procedure(userdata: Pointer; text: PTTF_Text); cdecl;
190+
end;
191+
192+
{ Check the size of TTF_TextEngine
193+
*
194+
* If this assert fails, either the compiler is padding to an unexpected size,
195+
* or the interface has been updated and this should be updated to match and
196+
* the code using this interface should be updated to handle the old version.
197+
}
198+
{ #todo : SDL3-for-Pascal: Implement }
199+
// SDL_COMPILE_TIME_ASSERT(TTF_TextEngine_SIZE, ...
200+
201+
implementation
202+
203+
end.
204+

0 commit comments

Comments
 (0)