1 /*
2 
3 Boost Software License - Version 1.0 - August 17th, 2003
4 
5 Permission is hereby granted, free of charge, to any person or organization
6 obtaining a copy of the software and accompanying documentation covered by
7 this license (the "Software") to use, reproduce, display, distribute,
8 execute, and transmit the Software, and to prepare derivative works of the
9 Software, and to permit third-parties to whom the Software is furnished to
10 do so, all subject to the following:
11 
12 The copyright notices in the Software and this entire statement, including
13 the above license grant, this restriction and the following disclaimer,
14 must be included in all copies of the Software, in whole or in part, and
15 all derivative works of the Software, unless such copies or derivative
16 works are solely in the form of machine-executable object code generated by
17 a source language processor.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 
27 */
28 module derelict.sdl.ttf;
29 
30 private
31 {
32     import derelict.util.loader;
33     import derelict.util.exception;
34     import derelict.util.compat;
35     import derelict.sdl.sdl;
36 
37 }
38 
39 enum : Uint8
40 {
41     SDL_TTF_MAJOR_VERSION = 2,
42     SDL_TTF_MINOR_VERSION = 0,
43     SDL_TTF_PATCHLEVEL    = 10,
44 }
45 alias SDL_TTF_MAJOR_VERSION TTF_MAJOR_VERSION;
46 alias SDL_TTF_MINOR_VERSION TTF_MINOR_VERSION;
47 alias SDL_TTF_PATCHLEVEL TTF_PATCHLEVEL;
48 
49 enum
50 {
51     UNICODE_BOM_NATIVE = 0xFEFF,
52     UNICODE_BOM_SWAPPED = 0xFFFE,
53     TTF_STYLE_NORMAL = 0x00,
54     TTF_STYLE_BOLD = 0x01,
55     TTF_STYLE_ITALIC = 0x02,
56     TTF_STYLE_UNDERLINE = 0x04,
57     TTF_STYLE_STRIKETHROUGH = 0x08,
58 }
59 
60 enum
61 {
62     TTF_HINTING_NORMAL = 0,
63     TTF_HINTING_LIGHT = 1,
64     TTF_HINTING_MONO = 2,
65     TTF_HINTING_NONE = 3,
66 }
67 
68 alias SDL_SetError TTF_SetError;
69 alias SDL_GetError TTF_GetError;
70 
71 struct _TTF_Font {}
72 alias _TTF_Font TTF_Font;
73 
74 void SDL_TTF_VERSION(SDL_version* X)
75 {
76     X.major = SDL_TTF_MAJOR_VERSION;
77     X.minor = SDL_TTF_MINOR_VERSION;
78     X.patch = SDL_TTF_PATCHLEVEL;
79 }
80 
81 void TTF_VERSION(SDL_version* X) { SDL_TTF_VERSION(X); }
82 
83 
84 extern (C)
85 {
86     alias CSDLVERPTR function() da_TTF_Linked_Version;
87     alias void function(int) da_TTF_ByteSwappedUNICODE;
88     alias int function() da_TTF_Init;
89     alias TTF_Font * function (in char*, int) da_TTF_OpenFont;
90     alias TTF_Font * function (in char*, int, long ) da_TTF_OpenFontIndex;
91     alias TTF_Font * function (SDL_RWops*, int, int) da_TTF_OpenFontRW;
92     alias TTF_Font * function (SDL_RWops*, int, int, long) da_TTF_OpenFontIndexRW;
93     alias int function (in TTF_Font*) da_TTF_GetFontStyle;
94     alias void function (in TTF_Font*, int style) da_TTF_SetFontStyle;
95     alias int function(in TTF_Font*) da_TTF_GetFontOutline;
96     alias void function(TTF_Font*, int) da_TTF_SetFontOutline;
97     alias int function(in TTF_Font*) da_TTF_GetFontHinting;
98     alias void function(TTF_Font*, int) da_TTF_SetFontHinting;
99     alias int function(in TTF_Font*) da_TTF_FontHeight;
100     alias int function(in TTF_Font*) da_TTF_FontAscent;
101     alias int function(in TTF_Font*) da_TTF_FontDescent;
102     alias int function(in TTF_Font*) da_TTF_FontLineSkip;
103     alias int function(in TTF_Font*) da_TTF_GetFontKerning;
104     alias void function(TTF_Font*, int) da_TTF_SetFontKerning;
105     alias int function(in TTF_Font*) da_TTF_FontFaces;
106     alias int function(in TTF_Font*) da_TTF_FontFaceIsFixedWidth;
107     alias char* function(in TTF_Font*) da_TTF_FontFaceFamilyName;
108     alias char* function(in TTF_Font*) da_TTF_FontFaceStyleName;
109     alias int function(in TTF_Font*, Uint16) da_TTF_GlyphIsProvided;
110     alias int function (TTF_Font*, Uint16, int*, int*, int*, int*, int*) da_TTF_GlyphMetrics;
111     alias int function (TTF_Font*, in char*, int*, int*) da_TTF_SizeText;
112     alias int function (TTF_Font*, in char*, int*, int*) da_TTF_SizeUTF8;
113     alias int function (TTF_Font*, Uint16*, int*, int*) da_TTF_SizeUNICODE;
114     alias SDL_Surface* function (TTF_Font*, in char*, SDL_Color) da_TTF_RenderText_Solid;
115     alias SDL_Surface* function (TTF_Font*, in char*, SDL_Color) da_TTF_RenderUTF8_Solid;
116     alias SDL_Surface* function (TTF_Font*, in Uint16*, SDL_Color) da_TTF_RenderUNICODE_Solid;
117     alias SDL_Surface* function (TTF_Font*, Uint16, SDL_Color) da_TTF_RenderGlyph_Solid;
118     alias SDL_Surface* function (TTF_Font*, in char*, SDL_Color, SDL_Color) da_TTF_RenderText_Shaded;
119     alias SDL_Surface* function (TTF_Font*, in char*, SDL_Color, SDL_Color) da_TTF_RenderUTF8_Shaded;
120     alias SDL_Surface* function (TTF_Font*, in Uint16*, SDL_Color, SDL_Color) da_TTF_RenderUNICODE_Shaded;
121     alias SDL_Surface* function (TTF_Font*, Uint16, SDL_Color, SDL_Color) da_TTF_RenderGlyph_Shaded;
122     alias SDL_Surface* function (TTF_Font*, in char*, SDL_Color) da_TTF_RenderText_Blended;
123     alias SDL_Surface* function (TTF_Font*, in char*, SDL_Color) da_TTF_RenderUTF8_Blended;
124     alias SDL_Surface* function (TTF_Font*, in Uint16*, SDL_Color) da_TTF_RenderUNICODE_Blended;
125     alias SDL_Surface* function (TTF_Font*, Uint16, SDL_Color) da_TTF_RenderGlyph_Blended;
126     alias void function (TTF_Font*) da_TTF_CloseFont;
127     alias void function () da_TTF_Quit;
128     alias int function () da_TTF_WasInit;
129 }
130 
131 mixin(gsharedString!() ~
132 "
133 da_TTF_Linked_Version TTF_Linked_Version;
134 da_TTF_ByteSwappedUNICODE TTF_ByteSwappedUNICODE;
135 da_TTF_Init TTF_Init;
136 da_TTF_OpenFont TTF_OpenFont;
137 da_TTF_OpenFontIndex TTF_OpenFontIndex;
138 da_TTF_OpenFontRW TTF_OpenFontRW;
139 da_TTF_OpenFontIndexRW TTF_OpenFontIndexRW;
140 da_TTF_GetFontStyle TTF_GetFontStyle;
141 da_TTF_SetFontStyle TTF_SetFontStyle;
142 da_TTF_GetFontOutline TTF_GetFontOutline;
143 da_TTF_SetFontOutline TTF_SetFontOutline;
144 da_TTF_GetFontHinting TTF_GetFontHinting;
145 da_TTF_SetFontHinting TTF_SetFontHinting;
146 da_TTF_FontHeight TTF_FontHeight;
147 da_TTF_FontAscent TTF_FontAscent;
148 da_TTF_FontDescent TTF_FontDescent;
149 da_TTF_FontLineSkip TTF_FontLineSkip;
150 da_TTF_GetFontKerning TTF_GetFontKerning;
151 da_TTF_SetFontKerning TTF_SetFontKerning;
152 da_TTF_FontFaces TTF_FontFaces;
153 da_TTF_FontFaceIsFixedWidth TTF_FontFaceIsFixedWidth;
154 da_TTF_FontFaceFamilyName TTF_FontFaceFamilyName;
155 da_TTF_FontFaceStyleName TTF_FontFaceStyleName;
156 da_TTF_GlyphIsProvided TTF_GlyphIsProvided;
157 da_TTF_GlyphMetrics TTF_GlyphMetrics;
158 da_TTF_SizeText TTF_SizeText;
159 da_TTF_SizeUTF8 TTF_SizeUTF8;
160 da_TTF_SizeUNICODE TTF_SizeUNICODE;
161 da_TTF_RenderText_Solid TTF_RenderText_Solid;
162 da_TTF_RenderUTF8_Solid TTF_RenderUTF8_Solid;
163 da_TTF_RenderUNICODE_Solid TTF_RenderUNICODE_Solid;
164 da_TTF_RenderGlyph_Solid TTF_RenderGlyph_Solid;
165 da_TTF_RenderText_Shaded TTF_RenderText_Shaded;
166 da_TTF_RenderUTF8_Shaded TTF_RenderUTF8_Shaded;
167 da_TTF_RenderUNICODE_Shaded TTF_RenderUNICODE_Shaded;
168 da_TTF_RenderGlyph_Shaded TTF_RenderGlyph_Shaded;
169 da_TTF_RenderText_Blended TTF_RenderText_Blended;
170 da_TTF_RenderUTF8_Blended TTF_RenderUTF8_Blended;
171 da_TTF_RenderUNICODE_Blended TTF_RenderUNICODE_Blended;
172 da_TTF_RenderGlyph_Blended TTF_RenderGlyph_Blended;
173 da_TTF_CloseFont TTF_CloseFont;
174 da_TTF_Quit TTF_Quit;
175 da_TTF_WasInit TTF_WasInit;
176 ");
177 
178 alias TTF_RenderText_Shaded TTF_RenderText;
179 alias TTF_RenderUTF8_Shaded TTF_RenderUTF8;
180 alias TTF_RenderUNICODE_Shaded TTF_RenderUNICODE;
181 
182 class DerelictSDLttfLoader : SharedLibLoader
183 {
184 public:
185     this()
186     {
187         super(
188             "SDL_ttf.dll",
189             "libSDL_ttf.so, libSDL_ttf-2.0.so, libSDL_ttf-2.0.so.0",
190             "./Frameworks/SDL_ttf.framework/SDL_ttf, /Library/Frameworks/SDL_ttf.framework/SDL_ttf, /System/Library/Frameworks/SDL_ttf.framework/SDL_ttf"
191         );
192     }
193 
194 protected:
195     override void loadSymbols()
196     {
197         if(!DerelictSDL.isLoaded)
198         {
199             throw new SharedLibLoadException("DerelictSDL must be loaded before attempting to load DerelictSDLttf!");
200         }
201 
202         bindFunc(cast(void**)&TTF_Linked_Version, "TTF_Linked_Version");
203         bindFunc(cast(void**)&TTF_ByteSwappedUNICODE, "TTF_ByteSwappedUNICODE");
204         bindFunc(cast(void**)&TTF_Init, "TTF_Init");
205         bindFunc(cast(void**)&TTF_OpenFont, "TTF_OpenFont");
206         bindFunc(cast(void**)&TTF_OpenFontIndex, "TTF_OpenFontIndex");
207         bindFunc(cast(void**)&TTF_OpenFontRW, "TTF_OpenFontRW");
208         bindFunc(cast(void**)&TTF_OpenFontIndexRW, "TTF_OpenFontIndexRW");
209         bindFunc(cast(void**)&TTF_GetFontStyle, "TTF_GetFontStyle");
210         bindFunc(cast(void**)&TTF_SetFontStyle, "TTF_SetFontStyle");
211         bindFunc(cast(void**)&TTF_GetFontOutline, "TTF_GetFontOutline");
212         bindFunc(cast(void**)&TTF_SetFontOutline, "TTF_SetFontOutline");
213         bindFunc(cast(void**)&TTF_GetFontHinting, "TTF_GetFontHinting");
214         bindFunc(cast(void**)&TTF_SetFontHinting, "TTF_SetFontHinting");
215         bindFunc(cast(void**)&TTF_FontHeight, "TTF_FontHeight");
216         bindFunc(cast(void**)&TTF_FontAscent, "TTF_FontAscent");
217         bindFunc(cast(void**)&TTF_FontDescent, "TTF_FontDescent");
218         bindFunc(cast(void**)&TTF_FontLineSkip, "TTF_FontLineSkip");
219         bindFunc(cast(void**)&TTF_GetFontKerning, "TTF_GetFontKerning");
220         bindFunc(cast(void**)&TTF_SetFontKerning, "TTF_SetFontKerning");
221         bindFunc(cast(void**)&TTF_FontFaces, "TTF_FontFaces");
222         bindFunc(cast(void**)&TTF_FontFaceIsFixedWidth, "TTF_FontFaceIsFixedWidth");
223         bindFunc(cast(void**)&TTF_FontFaceFamilyName, "TTF_FontFaceFamilyName");
224         bindFunc(cast(void**)&TTF_FontFaceStyleName, "TTF_FontFaceStyleName");
225         bindFunc(cast(void**)&TTF_GlyphIsProvided, "TTF_GlyphIsProvided");
226         bindFunc(cast(void**)&TTF_GlyphMetrics, "TTF_GlyphMetrics");
227         bindFunc(cast(void**)&TTF_SizeText, "TTF_SizeText");
228         bindFunc(cast(void**)&TTF_SizeUTF8, "TTF_SizeUTF8");
229         bindFunc(cast(void**)&TTF_SizeUNICODE, "TTF_SizeUNICODE");
230         bindFunc(cast(void**)&TTF_RenderText_Solid, "TTF_RenderText_Solid");
231         bindFunc(cast(void**)&TTF_RenderUTF8_Solid, "TTF_RenderUTF8_Solid");
232         bindFunc(cast(void**)&TTF_RenderUNICODE_Solid, "TTF_RenderUNICODE_Solid");
233         bindFunc(cast(void**)&TTF_RenderGlyph_Solid, "TTF_RenderGlyph_Solid");
234         bindFunc(cast(void**)&TTF_RenderText_Shaded, "TTF_RenderText_Shaded");
235         bindFunc(cast(void**)&TTF_RenderUTF8_Shaded, "TTF_RenderUTF8_Shaded");
236         bindFunc(cast(void**)&TTF_RenderUNICODE_Shaded, "TTF_RenderUNICODE_Shaded");
237         bindFunc(cast(void**)&TTF_RenderGlyph_Shaded, "TTF_RenderGlyph_Shaded");
238         bindFunc(cast(void**)&TTF_RenderText_Blended, "TTF_RenderText_Blended");
239         bindFunc(cast(void**)&TTF_RenderUTF8_Blended, "TTF_RenderUTF8_Blended");
240         bindFunc(cast(void**)&TTF_RenderUNICODE_Blended, "TTF_RenderUNICODE_Blended");
241         bindFunc(cast(void**)&TTF_RenderGlyph_Blended, "TTF_RenderGlyph_Blended");
242         bindFunc(cast(void**)&TTF_CloseFont, "TTF_CloseFont");
243         bindFunc(cast(void**)&TTF_Quit, "TTF_Quit");
244         bindFunc(cast(void**)&TTF_WasInit, "TTF_WasInit");
245     }
246 }
247 
248 DerelictSDLttfLoader DerelictSDLttf;
249 
250 static this()
251 {
252     DerelictSDLttf = new DerelictSDLttfLoader();
253 }
254 
255 static ~this()
256 {
257     if(SharedLibLoader.isAutoUnloadEnabled())
258         DerelictSDLttf.unload();
259 }