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    = 11,
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     alias int function(TTF_Font*,int,int) da_TTF_GetFontKerningSize;
130 }
131 
132 mixin(gsharedString!() ~
133 "
134 da_TTF_Linked_Version TTF_Linked_Version;
135 da_TTF_ByteSwappedUNICODE TTF_ByteSwappedUNICODE;
136 da_TTF_Init TTF_Init;
137 da_TTF_OpenFont TTF_OpenFont;
138 da_TTF_OpenFontIndex TTF_OpenFontIndex;
139 da_TTF_OpenFontRW TTF_OpenFontRW;
140 da_TTF_OpenFontIndexRW TTF_OpenFontIndexRW;
141 da_TTF_GetFontStyle TTF_GetFontStyle;
142 da_TTF_SetFontStyle TTF_SetFontStyle;
143 da_TTF_GetFontOutline TTF_GetFontOutline;
144 da_TTF_SetFontOutline TTF_SetFontOutline;
145 da_TTF_GetFontHinting TTF_GetFontHinting;
146 da_TTF_SetFontHinting TTF_SetFontHinting;
147 da_TTF_FontHeight TTF_FontHeight;
148 da_TTF_FontAscent TTF_FontAscent;
149 da_TTF_FontDescent TTF_FontDescent;
150 da_TTF_FontLineSkip TTF_FontLineSkip;
151 da_TTF_GetFontKerning TTF_GetFontKerning;
152 da_TTF_SetFontKerning TTF_SetFontKerning;
153 da_TTF_FontFaces TTF_FontFaces;
154 da_TTF_FontFaceIsFixedWidth TTF_FontFaceIsFixedWidth;
155 da_TTF_FontFaceFamilyName TTF_FontFaceFamilyName;
156 da_TTF_FontFaceStyleName TTF_FontFaceStyleName;
157 da_TTF_GlyphIsProvided TTF_GlyphIsProvided;
158 da_TTF_GlyphMetrics TTF_GlyphMetrics;
159 da_TTF_SizeText TTF_SizeText;
160 da_TTF_SizeUTF8 TTF_SizeUTF8;
161 da_TTF_SizeUNICODE TTF_SizeUNICODE;
162 da_TTF_RenderText_Solid TTF_RenderText_Solid;
163 da_TTF_RenderUTF8_Solid TTF_RenderUTF8_Solid;
164 da_TTF_RenderUNICODE_Solid TTF_RenderUNICODE_Solid;
165 da_TTF_RenderGlyph_Solid TTF_RenderGlyph_Solid;
166 da_TTF_RenderText_Shaded TTF_RenderText_Shaded;
167 da_TTF_RenderUTF8_Shaded TTF_RenderUTF8_Shaded;
168 da_TTF_RenderUNICODE_Shaded TTF_RenderUNICODE_Shaded;
169 da_TTF_RenderGlyph_Shaded TTF_RenderGlyph_Shaded;
170 da_TTF_RenderText_Blended TTF_RenderText_Blended;
171 da_TTF_RenderUTF8_Blended TTF_RenderUTF8_Blended;
172 da_TTF_RenderUNICODE_Blended TTF_RenderUNICODE_Blended;
173 da_TTF_RenderGlyph_Blended TTF_RenderGlyph_Blended;
174 da_TTF_CloseFont TTF_CloseFont;
175 da_TTF_Quit TTF_Quit;
176 da_TTF_WasInit TTF_WasInit;
177 da_TTF_GetFontKerningSize TTF_GetFontKerningSize;
178 ");
179 
180 alias TTF_RenderText_Shaded TTF_RenderText;
181 alias TTF_RenderUTF8_Shaded TTF_RenderUTF8;
182 alias TTF_RenderUNICODE_Shaded TTF_RenderUNICODE;
183 
184 class DerelictSDLttfLoader : SharedLibLoader
185 {
186 public:
187     this()
188     {
189         super(
190             "SDL_ttf.dll",
191             "libSDL_ttf.so, libSDL_ttf-2.0.so, libSDL_ttf-2.0.so.0",
192             "./Frameworks/SDL_ttf.framework/SDL_ttf, /Library/Frameworks/SDL_ttf.framework/SDL_ttf, /System/Library/Frameworks/SDL_ttf.framework/SDL_ttf"
193         );
194     }
195 
196 protected:
197     override void loadSymbols()
198     {
199         if(!DerelictSDL.isLoaded)
200         {
201             throw new SharedLibLoadException("DerelictSDL must be loaded before attempting to load DerelictSDLttf!");
202         }
203 
204         bindFunc(cast(void**)&TTF_Linked_Version, "TTF_Linked_Version");
205         bindFunc(cast(void**)&TTF_ByteSwappedUNICODE, "TTF_ByteSwappedUNICODE");
206         bindFunc(cast(void**)&TTF_Init, "TTF_Init");
207         bindFunc(cast(void**)&TTF_OpenFont, "TTF_OpenFont");
208         bindFunc(cast(void**)&TTF_OpenFontIndex, "TTF_OpenFontIndex");
209         bindFunc(cast(void**)&TTF_OpenFontRW, "TTF_OpenFontRW");
210         bindFunc(cast(void**)&TTF_OpenFontIndexRW, "TTF_OpenFontIndexRW");
211         bindFunc(cast(void**)&TTF_GetFontStyle, "TTF_GetFontStyle");
212         bindFunc(cast(void**)&TTF_SetFontStyle, "TTF_SetFontStyle");
213         bindFunc(cast(void**)&TTF_GetFontOutline, "TTF_GetFontOutline");
214         bindFunc(cast(void**)&TTF_SetFontOutline, "TTF_SetFontOutline");
215         bindFunc(cast(void**)&TTF_GetFontHinting, "TTF_GetFontHinting");
216         bindFunc(cast(void**)&TTF_SetFontHinting, "TTF_SetFontHinting");
217         bindFunc(cast(void**)&TTF_FontHeight, "TTF_FontHeight");
218         bindFunc(cast(void**)&TTF_FontAscent, "TTF_FontAscent");
219         bindFunc(cast(void**)&TTF_FontDescent, "TTF_FontDescent");
220         bindFunc(cast(void**)&TTF_FontLineSkip, "TTF_FontLineSkip");
221         bindFunc(cast(void**)&TTF_GetFontKerning, "TTF_GetFontKerning");
222         bindFunc(cast(void**)&TTF_SetFontKerning, "TTF_SetFontKerning");
223         bindFunc(cast(void**)&TTF_FontFaces, "TTF_FontFaces");
224         bindFunc(cast(void**)&TTF_FontFaceIsFixedWidth, "TTF_FontFaceIsFixedWidth");
225         bindFunc(cast(void**)&TTF_FontFaceFamilyName, "TTF_FontFaceFamilyName");
226         bindFunc(cast(void**)&TTF_FontFaceStyleName, "TTF_FontFaceStyleName");
227         bindFunc(cast(void**)&TTF_GlyphIsProvided, "TTF_GlyphIsProvided");
228         bindFunc(cast(void**)&TTF_GlyphMetrics, "TTF_GlyphMetrics");
229         bindFunc(cast(void**)&TTF_SizeText, "TTF_SizeText");
230         bindFunc(cast(void**)&TTF_SizeUTF8, "TTF_SizeUTF8");
231         bindFunc(cast(void**)&TTF_SizeUNICODE, "TTF_SizeUNICODE");
232         bindFunc(cast(void**)&TTF_RenderText_Solid, "TTF_RenderText_Solid");
233         bindFunc(cast(void**)&TTF_RenderUTF8_Solid, "TTF_RenderUTF8_Solid");
234         bindFunc(cast(void**)&TTF_RenderUNICODE_Solid, "TTF_RenderUNICODE_Solid");
235         bindFunc(cast(void**)&TTF_RenderGlyph_Solid, "TTF_RenderGlyph_Solid");
236         bindFunc(cast(void**)&TTF_RenderText_Shaded, "TTF_RenderText_Shaded");
237         bindFunc(cast(void**)&TTF_RenderUTF8_Shaded, "TTF_RenderUTF8_Shaded");
238         bindFunc(cast(void**)&TTF_RenderUNICODE_Shaded, "TTF_RenderUNICODE_Shaded");
239         bindFunc(cast(void**)&TTF_RenderGlyph_Shaded, "TTF_RenderGlyph_Shaded");
240         bindFunc(cast(void**)&TTF_RenderText_Blended, "TTF_RenderText_Blended");
241         bindFunc(cast(void**)&TTF_RenderUTF8_Blended, "TTF_RenderUTF8_Blended");
242         bindFunc(cast(void**)&TTF_RenderUNICODE_Blended, "TTF_RenderUNICODE_Blended");
243         bindFunc(cast(void**)&TTF_RenderGlyph_Blended, "TTF_RenderGlyph_Blended");
244         bindFunc(cast(void**)&TTF_CloseFont, "TTF_CloseFont");
245         bindFunc(cast(void**)&TTF_Quit, "TTF_Quit");
246         bindFunc(cast(void**)&TTF_WasInit, "TTF_WasInit");
247         bindFunc(cast(void**)&TTF_GetFontKerningSize, "TTF_GetFontKerningSize");
248     }
249 }
250 
251 DerelictSDLttfLoader DerelictSDLttf;
252 
253 static this()
254 {
255     DerelictSDLttf = new DerelictSDLttfLoader();
256 }
257 
258 static ~this()
259 {
260     if(SharedLibLoader.isAutoUnloadEnabled())
261         DerelictSDLttf.unload();
262 }