Skip to content

Commit 6eb186f

Browse files
Add SDL_textengine.inc
1 parent 60adf8b commit 6eb186f

File tree

2 files changed

+230
-54
lines changed

2 files changed

+230
-54
lines changed

units/SDL3_ttf.pas

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,72 +23,72 @@
2323

2424
interface
2525

26-
{$IFDEF WINDOWS}
27-
uses
28-
SDL3,
29-
{$IFDEF FPC}
30-
ctypes,
31-
{$ENDIF}
32-
Windows;
33-
{$ENDIF}
26+
{$IFDEF WINDOWS}
27+
uses
28+
SDL3,
29+
{$IFDEF FPC}
30+
ctypes,
31+
{$ENDIF}
32+
Windows;
33+
{$ENDIF}
3434

35-
{$IF DEFINED(UNIX) AND NOT DEFINED(ANDROID)}
36-
uses
37-
SDL3,
38-
{$IFDEF FPC}
39-
ctypes,
40-
UnixType,
41-
{$ENDIF}
42-
{$IFDEF DARWIN}
43-
CocoaAll;
44-
{$ELSE}
45-
X,
46-
XLib;
47-
{$ENDIF}
48-
{$ENDIF}
35+
{$IF DEFINED(UNIX) AND NOT DEFINED(ANDROID)}
36+
uses
37+
SDL3,
38+
{$IFDEF FPC}
39+
ctypes,
40+
UnixType,
41+
{$ENDIF}
42+
{$IFDEF DARWIN}
43+
CocoaAll;
44+
{$ELSE}
45+
X,
46+
XLib;
47+
{$ENDIF}
48+
{$ENDIF}
4949

50-
{$IF DEFINED(UNIX) AND DEFINED(ANDROID) AND DEFINED(FPC)}
51-
uses
52-
SDL3,
53-
ctypes,
54-
UnixType;
55-
{$ENDIF}
50+
{$IF DEFINED(UNIX) AND DEFINED(ANDROID) AND DEFINED(FPC)}
51+
uses
52+
SDL3,
53+
ctypes,
54+
UnixType;
55+
{$ENDIF}
5656

5757
const
5858

59-
{$IFDEF WINDOWS}
60-
IMG_LibName = 'SDL3_ttf.dll';
61-
{$ENDIF}
59+
{$IFDEF WINDOWS}
60+
IMG_LibName = 'SDL3_ttf.dll';
61+
{$ENDIF}
6262

63-
{$IFDEF UNIX}
64-
{$IFDEF DARWIN}
65-
IMG_LibName = 'libSDL3_ttf.dylib';
66-
{$IFDEF FPC}
67-
{$LINKLIB libSDL3}
68-
{$ENDIF}
63+
{$IFDEF UNIX}
64+
{$IFDEF DARWIN}
65+
IMG_LibName = 'libSDL3_ttf.dylib';
66+
{$IFDEF FPC}
67+
{$LINKLIB libSDL3}
68+
{$ENDIF}
69+
{$ELSE}
70+
{$IFDEF FPC}
71+
IMG_LibName = 'libSDL3_ttf.so';
6972
{$ELSE}
70-
{$IFDEF FPC}
71-
IMG_LibName = 'libSDL3_ttf.so';
72-
{$ELSE}
73-
IMG_LibName = 'libSDL3_ttf.so.0';
74-
{$ENDIF}
73+
IMG_LibName = 'libSDL3_ttf.so.0';
7574
{$ENDIF}
7675
{$ENDIF}
76+
{$ENDIF}
7777

78-
{$IFDEF MACOS}
79-
IMG_LibName = 'SDL3_ttf';
80-
{$IFDEF FPC}
81-
{$linklib libSDL3}
82-
{$ENDIF}
78+
{$IFDEF MACOS}
79+
IMG_LibName = 'SDL3_ttf';
80+
{$IFDEF FPC}
81+
{$linklib libSDL3}
8382
{$ENDIF}
83+
{$ENDIF}
8484

85-
{*
86-
* Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO
87-
}
88-
const
89-
SDL_TTF_MAJOR_VERSION = 3;
90-
SDL_TTF_MINOR_VERSION = 1;
91-
SDL_TTF_MICRO_VERSION = 0;
85+
{*
86+
* Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO
87+
}
88+
const
89+
SDL_TTF_MAJOR_VERSION = 3;
90+
SDL_TTF_MINOR_VERSION = 1;
91+
SDL_TTF_MICRO_VERSION = 0;
9292

9393
{*
9494
* This is the version number macro for the current SDL_ttf version.
@@ -2912,6 +2912,8 @@ procedure TTF_Quit; cdecl;
29122912
function TTF_WasInit: cint; cdecl;
29132913
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_WasInit' {$ENDIF} {$ENDIF};
29142914

2915+
{$I SDL_textengine.inc} // 3.1.0-prev
2916+
29152917
implementation
29162918

29172919
function SDL_TTF_VERSION: Integer;

units/SDL_textengine.inc

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
{
2+
This file is part of:
3+
4+
SDL3 for Pascal
5+
(https://github.com/PascalGameDevelopment/SDL3-for-Pascal)
6+
SPDX-License-Identifier: Zlib
7+
}
8+
9+
{$DEFINE SDL_TTF_TEXTENGINE}
10+
11+
{*
12+
* \file SDL_textengine.h
13+
*
14+
* Definitions for implementations of the TTF_TextEngine interface.
15+
}
16+
17+
{*
18+
* A font atlas draw command.
19+
*
20+
* \since This enum is available since SDL_ttf 3.0.0.
21+
}
22+
type
23+
PPTTF_DrawCommand = ^PTTF_DrawCommand;
24+
PTTF_DrawCommand = ^TTTF_DrawCommand;
25+
TTTF_DrawCommand = type Integer;
26+
const
27+
TTF_DRAW_COMMAND_NOOP = TTTF_DrawCommand(0);
28+
TTF_DRAW_COMMAND_FILL = TTTF_DrawCommand(1);
29+
TTF_DRAW_COMMAND_COPY = TTTF_DrawCommand(2);
30+
31+
{*
32+
* A filled rectangle draw operation.
33+
*
34+
* \since This struct is available since SDL_ttf 3.0.0.
35+
*
36+
* \sa TTF_DrawOperation
37+
}
38+
type
39+
PPTTF_FillOperation = ^PTTF_FillOperation;
40+
PTTF_FillOperation = ^TTTF_FillOperation;
41+
TTTF_FillOperation = record
42+
cmd: TTTF_DrawCommand; {*< TTF_DRAW_COMMAND_FILL }
43+
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. }
44+
end;
45+
46+
{*
47+
* A texture copy draw operation.
48+
*
49+
* \since This struct is available since SDL_ttf 3.0.0.
50+
*
51+
* \sa TTF_DrawOperation
52+
}
53+
type
54+
PPTTF_CopyOperation = ^PTTF_CopyOperation;
55+
PTTF_CopyOperation = ^TTTF_CopyOperation;
56+
TTTF_CopyOperation = record
57+
cmd: TTTF_DrawCommand; {*< TTF_DRAW_COMMAND_COPY }
58+
text_offset: cint; {*< The offset in the text corresponding to this glyph.
59+
There may be multiple glyphs with the same text offset
60+
and the next text offset might be several Unicode codepoints
61+
later. In this case the glyphs and codepoints are grouped
62+
together and the group bounding box is the union of the dst
63+
rectangles for the corresponding glyphs. }
64+
glyph_font: PTTF_Font; {*< The font containing the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() }
65+
glyph_index: cuint32; {*< The glyph index of the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() }
66+
src: TSDL_Rect; {*< The area within the glyph to be drawn }
67+
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. }
68+
reserved: Pointer;
69+
end;
70+
71+
{*
72+
* A text engine draw operation.
73+
*
74+
* \since This struct is available since SDL_ttf 3.0.0.
75+
}
76+
type
77+
PPTTF_DrawOperation = ^PTTF_DrawOperation;
78+
PTTF_DrawOperation = ^TTTF_DrawOperation;
79+
TTTF_DrawOperation = record
80+
case Integer of
81+
0: (cmd: TTTF_DrawCommand);
82+
1: (fill: TTTF_FillOperation);
83+
2: (copy: TTTF_CopyOperation);
84+
end;
85+
86+
{ Private data in TTF_Text, to assist in text measurement and layout }
87+
type
88+
PPTTF_TextLayout = ^PTTF_TextLayout;
89+
PTTF_TextLayout = type Pointer;
90+
91+
{ Private data in TTF_Text, available to implementations
92+
93+
#note : SDL3-for-Pascal:
94+
95+
In C TTF_TextData is defined in two different namespaces as
96+
typedef struct (SDL3_ttf.h) and as struct (SDL_textengine.h).
97+
This is not possible in Pascal; causes "duplicate identifier"
98+
error. Therefore the struct's name has an underscore added
99+
here. }
100+
type
101+
PPTTF_TextData_ = ^PTTF_TextData_;
102+
PTTF_TextData_ = ^TTTF_TextData_;
103+
TTTF_TextData_ = record
104+
font: PTTF_Font; {*< The font used by this text, read-only. }
105+
color: TSDL_FColor; {*< The color of the text, read-only. }
106+
107+
needs_layout_update: cbool; {*< True if the layout needs to be updated }
108+
layout: PTTF_TextLayout; {*< Cached layout information, read-only. }
109+
x: cint; {*< The x offset of the upper left corner of this text, in pixels, read-only. }
110+
y: cint; {*< The y offset of the upper left corner of this text, in pixels, read-only. }
111+
w: cint; {*< The width of this text, in pixels, read-only. }
112+
h: cint; {*< The height of this text, in pixels, read-only. }
113+
num_ops: cint; {*< The number of drawing operations to render this text, read-only. }
114+
ops: PTTF_DrawOperation; {*< The drawing operations used to render this text, read-only. }
115+
num_clusters: cint; {*< The number of substrings representing clusters of glyphs in the string, read-only }
116+
clusters: PTTF_SubString; {*< Substrings representing clusters of glyphs in the string, read-only }
117+
118+
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 }
119+
120+
needs_engine_update: cbool; {*< True if the engine text needs to be updated }
121+
engine: PTTF_TextEngine; {*< The engine used to render this text, read-only. }
122+
engine_text: Pointer; {*< The implementation-specific representation of this text }
123+
end;
124+
125+
{*
126+
* A text engine interface.
127+
*
128+
* This structure should be initialized using SDL_INIT_INTERFACE()
129+
*
130+
* \since This struct is available since SDL_ttf 3.0.0.
131+
*
132+
* \sa SDL_INIT_INTERFACE
133+
134+
#note : SDL3-for-Pascal:
135+
136+
In C TTF_TextEngine is defined in two different namespaces as
137+
typedef struct (SDL3_ttf.h) and as struct (SDL_textengine.h).
138+
This is not possible in Pascal; causes "duplicate identifier"
139+
error. Therefore the struct's name has an underscore added
140+
here. }
141+
type
142+
PPTTF_TextEngine_ = ^PTTF_TextEngine_;
143+
PTTF_TextEngine_ = ^TTTF_TextEngine_;
144+
TTTF_TextEngine_ = record
145+
version: cuint32; {*< The version of this interface }
146+
userdata: Pointer; {*< User data Pointer passed to callbacks }
147+
148+
{ Create a text representation from draw instructions.
149+
*
150+
* All fields of `text` except `internal->engine_text` will already be filled out.
151+
*
152+
* This function should set the `internal->engine_text` field to a non-nil value.
153+
*
154+
* \param userdata the userdata Pointer in this interface.
155+
* \param text the text object being created.
156+
}
157+
CreateText: function(userdata: Pointer; text: PTTF_Text): cbool; cdecl;
158+
159+
{*
160+
* Destroy a text representation.
161+
}
162+
DestroyText: procedure(userdata: Pointer; text: PTTF_Text); cdecl;
163+
end;
164+
165+
{ Check the size of TTF_TextEngine
166+
*
167+
* If this assert fails, either the compiler is padding to an unexpected size,
168+
* or the interface has been updated and this should be updated to match and
169+
* the code using this interface should be updated to handle the old version.
170+
}
171+
{ #todo : SDL3-for-Pascal: Implement }
172+
// SDL_COMPILE_TIME_ASSERT(TTF_TextEngine_SIZE, ...
173+
174+

0 commit comments

Comments
 (0)