1 2 // Copyright 2018 - 2022 Michael D. Parker 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 module bindbc.sdl.ttf; 8 9 import bindbc.sdl.config; 10 static if(bindSDLTTF): 11 12 import core.stdc.config; 13 import bindbc.sdl.bind.sdlerror : SDL_GetError, SDL_SetError; 14 import bindbc.sdl.bind.sdlpixels : SDL_Color; 15 import bindbc.sdl.bind.sdlrwops : SDL_RWops; 16 import bindbc.sdl.bind.sdlsurface : SDL_Surface; 17 import bindbc.sdl.bind.sdlversion : SDL_version; 18 import bindbc.sdl.bind.sdlstdinc : SDL_bool; 19 20 alias TTF_SetError = SDL_SetError; 21 alias TTF_GetError = SDL_GetError; 22 23 enum SDLTTFSupport { 24 noLibrary, 25 badLibrary, 26 sdlTTF2012 = 2012, 27 sdlTTF2013 = 2013, 28 sdlTTF2014 = 2014, 29 sdlTTF2015 = 2015, 30 sdlTTF2018 = 2018, 31 } 32 33 enum ubyte SDL_TTF_MAJOR_VERSION = 2; 34 enum ubyte SDL_TTF_MINOR_VERSION = 0; 35 36 version(SDL_TTF_2018) { 37 enum sdlTTFSupport = SDLTTFSupport.sdlTTF2018; 38 enum ubyte SDL_TTF_PATCHLEVEL = 18; 39 } 40 else version(SDL_TTF_2015) { 41 enum sdlTTFSupport = SDLTTFSupport.sdlTTF2015; 42 enum ubyte SDL_TTF_PATCHLEVEL = 15; 43 } 44 else version(SDL_TTF_2014) { 45 enum sdlTTFSupport = SDLTTFSupport.sdlTTF2014; 46 enum ubyte SDL_TTF_PATCHLEVEL = 14; 47 } 48 else version(SDL_TTF_2013) { 49 enum sdlTTFSupport = SDLTTFSupport.sdlTTF2013; 50 enum ubyte SDL_TTF_PATCHLEVEL = 13; 51 } 52 else { 53 enum sdlTTFSupport = SDLTTFSupport.sdlTTF2012; 54 enum ubyte SDL_TTF_PATCHLEVEL = 12; 55 } 56 57 alias TTF_MAJOR_VERSION = SDL_TTF_MAJOR_VERSION; 58 alias TTF_MINOR_VERSION = SDL_TTF_MINOR_VERSION; 59 alias TTF_PATCHLEVEL = SDL_TTF_PATCHLEVEL; 60 61 @nogc nothrow 62 void SDL_TTF_VERSION(SDL_version* X) { 63 X.major = SDL_TTF_MAJOR_VERSION; 64 X.minor = SDL_TTF_MINOR_VERSION; 65 X.patch = SDL_TTF_PATCHLEVEL; 66 } 67 alias TTF_VERSION = SDL_TTF_VERSION; 68 69 enum { 70 UNICODE_BOM_NATIVE = 0xFEFF, 71 UNICODE_BOM_SWAPPED = 0xFFFE, 72 TTF_STYLE_NORMAL = 0x00, 73 TTF_STYLE_BOLD = 0x01, 74 TTF_STYLE_ITALIC = 0x02, 75 TTF_STYLE_UNDERLINE = 0x04, 76 TTF_STYLE_STRIKETHROUGH = 0x08, 77 } 78 79 enum TTF_HINTING_NORMAL = 0; 80 enum TTF_HINTING_LIGHT = 1; 81 enum TTF_HINTING_MONO = 2; 82 enum TTF_HINTING_NONE = 3; 83 static if(sdlTTFSupport >= SDLTTFSupport.sdlTTF2018){ 84 enum TTF_HINTING_LIGHT_SUBPIXEL = 4; 85 } 86 87 88 struct TTF_Font; 89 90 static if(staticBinding) { 91 extern(C) @nogc nothrow { 92 SDL_version* TTF_Linked_Version(); 93 void TTF_ByteSwappedUNICODE(int swapped); 94 int TTF_Init(); 95 TTF_Font* TTF_OpenFont(const(char)* file, int ptsize); 96 TTF_Font* TTF_OpenFontIndex(const(char)* file, int ptsize, c_long index); 97 TTF_Font* TTF_OpenFontRW(SDL_RWops* src, int freesrc, int ptsize); 98 TTF_Font* TTF_OpenFontIndexRW(SDL_RWops* src, int freesrc, int ptsize, c_long index); 99 int TTF_GetFontStyle(const(TTF_Font)* font); 100 void TTF_SetFontStyle(const(TTF_Font)* font ,int style); 101 int TTF_GetFontOutline(const(TTF_Font)* font); 102 void TTF_SetFontOutline(TTF_Font* font, int outline); 103 int TTF_GetFontHinting(const(TTF_Font)* font); 104 void TTF_SetFontHinting(TTF_Font* font, int hinting); 105 int TTF_FontHeight(const(TTF_Font)* font); 106 int TTF_FontAscent(const(TTF_Font)* font); 107 int TTF_FontDescent(const(TTF_Font)* font); 108 int TTF_FontLineSkip(const(TTF_Font)* font); 109 int TTF_GetFontKerning(const(TTF_Font)* font); 110 void TTF_SetFontKerning(TTF_Font* font, int allowed); 111 int TTF_FontFaces(const(TTF_Font)* font); 112 int TTF_FontFaceIsFixedWidth(const(TTF_Font)* font); 113 char* TTF_FontFaceFamilyName(const(TTF_Font)* font); 114 char* TTF_FontFaceStyleName(const(TTF_Font)* font); 115 int TTF_GlyphIsProvided(const(TTF_Font)* font, ushort ch); 116 int TTF_GlyphMetrics(TTF_Font* font, ushort ch, int* minx, int* maxx, int* miny, int* maxy, int* advance); 117 int TTF_SizeText(TTF_Font* font, const(char)* text, int* w, int* h); 118 int TTF_SizeUTF8(TTF_Font* font, const(char)* text, int* w, int* h); 119 int TTF_SizeUNICODE(TTF_Font* font, const(ushort)* text, int* w, int* h); 120 SDL_Surface* TTF_RenderText_Solid(TTF_Font* font, const(char)* text, SDL_Color fg); 121 SDL_Surface* TTF_RenderUTF8_Solid(TTF_Font* font, const(char)* text, SDL_Color fg); 122 SDL_Surface* TTF_RenderUNICODE_Solid(TTF_Font* font, const(ushort)* text, SDL_Color fg); 123 SDL_Surface* TTF_RenderGlyph_Solid(TTF_Font* font, ushort ch, SDL_Color fg); 124 SDL_Surface* TTF_RenderText_Shaded(TTF_Font* font, const(char)* text, SDL_Color fg, SDL_Color bg); 125 SDL_Surface* TTF_RenderUTF8_Shaded(TTF_Font* font, const(char)* text, SDL_Color fg, SDL_Color bg); 126 SDL_Surface* TTF_RenderUNICODE_Shaded(TTF_Font* font, const(ushort)* text, SDL_Color fg, SDL_Color bg); 127 SDL_Surface TTF_RenderGlyph_Shaded(TTF_Font* font, ushort ch, SDL_Color fg,SDL_Color bg); 128 SDL_Surface* TTF_RenderText_Blended(TTF_Font* font, const(char)* text, SDL_Color fg); 129 SDL_Surface* TTF_RenderUTF8_Blended(TTF_Font* font, const(char)* text, SDL_Color fg); 130 SDL_Surface* TTF_RenderUNICODE_Blended(TTF_Font* font, const(ushort)* text, SDL_Color fg); 131 SDL_Surface* TTF_RenderText_Blended_Wrapped(TTF_Font* font, const(char)* text, SDL_Color fg, uint wrapLength); 132 SDL_Surface* TTF_RenderUTF8_Blended_Wrapped(TTF_Font* font, const(char)* text,SDL_Color fg, uint wrapLength); 133 SDL_Surface* TTF_RenderUNICODE_Blended_Wrapped(TTF_Font* font, const(ushort)* text, SDL_Color fg, uint wrapLength); 134 SDL_Surface* TTF_RenderGlyph_Blended(TTF_Font* font, ushort ch, SDL_Color fg); 135 void TTF_CloseFont(TTF_Font* font); 136 void TTF_Quit(); 137 int TTF_WasInit(); 138 int TTF_GetFontKerningSize(TTF_Font* font, int prev_index, int index); 139 140 static if(sdlTTFSupport >= SDLTTFSupport.sdlTTF2014) { 141 int TTF_GetFontKerningSizeGlyph(TTF_Font* font, ushort previous_ch, ushort ch); 142 } 143 144 static if(sdlTTFSupport >= SDLTTFSupport.sdlTTF2018) { 145 void TTF_GetFreeTypeVersion(int* major, int* minor, int* patch); 146 void TTF_GetHarfBuzzVersion(int* major, int* minor, int* patch); 147 int TTF_SetFontSDF(TTF_Font* font, SDL_bool on_off); 148 SDL_bool TTF_GetFontSDF(const(TTF_Font)* font); 149 TTF_Font* TTF_OpenFontDPI(const(char)* file, int ptsize, uint hdpi, uint vdpi); 150 TTF_Font* TTF_OpenFontIndexDPI(const(char)*file, int ptsize, long index, uint hdpi, uint vdpi); 151 TTF_Font* TTF_OpenFontDPIRW(SDL_RWops* src, int freesrc, int ptsize, uint hdpi, uint vdpi); 152 TTF_Font* TTF_OpenFontIndexDPIRW(SDL_RWops* src, int freesrc, int ptsize, long index, uint hdpi, uint vdpi); 153 int TTF_SetFontSizeDPI(TTF_Font* font, int ptsize, uint hdpi, uint vdpi); 154 int TTF_GlyphIsProvided32(TTF_Font* font, uint ch); 155 int TTF_GlyphMetrics32(TTF_Font* font, uint ch, int* minx, int* maxx, int* miny, int* maxy, int* advance); 156 SDL_Surface* TTF_RenderGlyph32_Solid(TTF_Font* font, uint ch, SDL_Color fg); 157 SDL_Surface* TTF_RenderGlyph32_Shaded(TTF_Font* font, uint ch, SDL_Color fg, SDL_Color bg); 158 SDL_Surface* TTF_RenderGlyph32_Blended(TTF_Font* font, uint ch, SDL_Color fg); 159 int TTF_GetFontKerningSizeGlyphs32(TTF_Font* font, uint previous_ch, uint ch); 160 int TTF_SetDirection(int direction); 161 int TTF_SetScript(int script); 162 int TTF_MeasureText(TTF_Font* font, const(char)* text, int measure_width, int* extent, int* count); 163 int TTF_MeasureUTF8(TTF_Font* font, const(char)* text, int measure_width, int* extent, int* count); 164 int TTF_MeasureUNICODE(TTF_Font* font, const(ushort)* text, int measure_width, int *extent, int *count); 165 int TTF_SetFontSize(TTF_Font* font, int ptsize); 166 SDL_Surface* TTF_RenderText_Solid_Wrapped(TTF_Font* font, const(char)* text, SDL_Color fg, uint wrapLength); 167 SDL_Surface* TTF_RenderUTF8_Solid_Wrapped(TTF_Font* font, const(char)* text, SDL_Color fg, uint wrapLength); 168 SDL_Surface* TTF_RenderUNICODE_Solid_Wrapped(TTF_Font* font, const(ushort)* text, SDL_Color fg, uint wrapLength); 169 SDL_Surface* TTF_RenderText_Shaded_Wrapped(TTF_Font* font, const(char)* text, SDL_Color fg, SDL_Color bg, uint wrapLength); 170 SDL_Surface* TTF_RenderUTF8_Shaded_Wrapped(TTF_Font* font, const(char)* text, SDL_Color fg, SDL_Color bg, uint wrapLength); 171 SDL_Surface* TTF_RenderUNICODE_Shaded_Wrapped(TTF_Font* font, const(ushort)* text, SDL_Color fg, SDL_Color bg, uint wrapLength); 172 } 173 } 174 } 175 else { 176 import bindbc.loader; 177 extern(C) @nogc nothrow { 178 alias pTTF_Linked_Version = SDL_version* function(); 179 alias pTTF_ByteSwappedUNICODE = void function(int swapped); 180 alias pTTF_Init = int function(); 181 alias pTTF_OpenFont = TTF_Font * function(const(char)* file, int ptsize); 182 alias pTTF_OpenFontIndex = TTF_Font * function(const(char)* file, int ptsize, c_long index); 183 alias pTTF_OpenFontRW = TTF_Font * function(SDL_RWops* src, int freesrc, int ptsize); 184 alias pTTF_OpenFontIndexRW = TTF_Font * function(SDL_RWops* src, int freesrc, int ptsize, c_long index); 185 alias pTTF_GetFontStyle = int function(const(TTF_Font)* font); 186 alias pTTF_SetFontStyle = void function(const(TTF_Font)* font ,int style); 187 alias pTTF_GetFontOutline = int function(const(TTF_Font)* font); 188 alias pTTF_SetFontOutline = void function(TTF_Font* font, int outline); 189 alias pTTF_GetFontHinting = int function(const(TTF_Font)* font); 190 alias pTTF_SetFontHinting = void function(TTF_Font* font, int hinting); 191 alias pTTF_FontHeight = int function(const(TTF_Font)* font); 192 alias pTTF_FontAscent = int function(const(TTF_Font)* font); 193 alias pTTF_FontDescent = int function(const(TTF_Font)* font); 194 alias pTTF_FontLineSkip = int function(const(TTF_Font)* font); 195 alias pTTF_GetFontKerning = int function(const(TTF_Font)* font); 196 alias pTTF_SetFontKerning = void function(TTF_Font* font, int allowed); 197 alias pTTF_FontFaces = int function(const(TTF_Font)* font); 198 alias pTTF_FontFaceIsFixedWidth = int function(const(TTF_Font)* font); 199 alias pTTF_FontFaceFamilyName = char* function(const(TTF_Font)* font); 200 alias pTTF_FontFaceStyleName = char* function(const(TTF_Font)* font); 201 alias pTTF_GlyphIsProvided = int function(const(TTF_Font)* font, ushort ch); 202 alias pTTF_GlyphMetrics = int function(TTF_Font* font, ushort ch, int* minx, int* maxx, int* miny, int* maxy, int* advance); 203 alias pTTF_SizeText = int function(TTF_Font* font, const(char)* text, int* w, int* h); 204 alias pTTF_SizeUTF8 = int function(TTF_Font* font, const(char)* text, int* w, int* h); 205 alias pTTF_SizeUNICODE = int function(TTF_Font* font, const(ushort)* text, int* w, int* h); 206 alias pTTF_RenderText_Solid = SDL_Surface* function(TTF_Font* font, const(char)* text, SDL_Color fg); 207 alias pTTF_RenderUTF8_Solid = SDL_Surface* function(TTF_Font* font, const(char)* text, SDL_Color fg); 208 alias pTTF_RenderUNICODE_Solid = SDL_Surface* function(TTF_Font* font, const(ushort)* text,SDL_Color fg); 209 alias pTTF_RenderGlyph_Solid = SDL_Surface* function(TTF_Font* font, ushort ch, SDL_Color fg); 210 alias pTTF_RenderText_Shaded = SDL_Surface* function(TTF_Font* font, const(char)* text, SDL_Color fg, SDL_Color bg); 211 alias pTTF_RenderUTF8_Shaded = SDL_Surface* function(TTF_Font* font, const(char)* text, SDL_Color fg, SDL_Color bg); 212 alias pTTF_RenderUNICODE_Shaded = SDL_Surface* function(TTF_Font* font, const(ushort)* text, SDL_Color fg, SDL_Color bg); 213 alias pTTF_RenderGlyph_Shaded = SDL_Surface* function(TTF_Font* font, ushort ch, SDL_Color fg,SDL_Color bg); 214 alias pTTF_RenderText_Blended = SDL_Surface* function(TTF_Font* font, const(char)* text, SDL_Color fg); 215 alias pTTF_RenderUTF8_Blended = SDL_Surface* function(TTF_Font* font, const(char)* text, SDL_Color fg); 216 alias pTTF_RenderUNICODE_Blended = SDL_Surface* function(TTF_Font* font, const(ushort)* text, SDL_Color fg); 217 alias pTTF_RenderText_Blended_Wrapped = SDL_Surface* function(TTF_Font* font, const(char)* text, SDL_Color fg, uint wrapLength); 218 alias pTTF_RenderUTF8_Blended_Wrapped = SDL_Surface* function(TTF_Font* font, const(char)* text,SDL_Color fg, uint wrapLength); 219 alias pTTF_RenderUNICODE_Blended_Wrapped = SDL_Surface* function(TTF_Font* font, const(ushort)* text, SDL_Color fg, uint wrapLength); 220 alias pTTF_RenderGlyph_Blended = SDL_Surface* function(TTF_Font* font, ushort ch, SDL_Color fg); 221 alias pTTF_CloseFont = void function(TTF_Font* font); 222 alias pTTF_Quit = void function(); 223 alias pTTF_WasInit = int function(); 224 alias pTTF_GetFontKerningSize = int function(TTF_Font* font, int prev_index, int index); 225 } 226 227 __gshared { 228 pTTF_Linked_Version TTF_Linked_Version; 229 pTTF_ByteSwappedUNICODE TTF_ByteSwappedUNICODE; 230 pTTF_Init TTF_Init; 231 pTTF_OpenFont TTF_OpenFont; 232 pTTF_OpenFontIndex TTF_OpenFontIndex; 233 pTTF_OpenFontRW TTF_OpenFontRW; 234 pTTF_OpenFontIndexRW TTF_OpenFontIndexRW; 235 pTTF_GetFontStyle TTF_GetFontStyle; 236 pTTF_SetFontStyle TTF_SetFontStyle; 237 pTTF_GetFontOutline TTF_GetFontOutline; 238 pTTF_SetFontOutline TTF_SetFontOutline; 239 pTTF_GetFontHinting TTF_GetFontHinting; 240 pTTF_SetFontHinting TTF_SetFontHinting; 241 pTTF_FontHeight TTF_FontHeight; 242 pTTF_FontAscent TTF_FontAscent; 243 pTTF_FontDescent TTF_FontDescent; 244 pTTF_FontLineSkip TTF_FontLineSkip; 245 pTTF_GetFontKerning TTF_GetFontKerning; 246 pTTF_SetFontKerning TTF_SetFontKerning; 247 pTTF_FontFaces TTF_FontFaces; 248 pTTF_FontFaceIsFixedWidth TTF_FontFaceIsFixedWidth; 249 pTTF_FontFaceFamilyName TTF_FontFaceFamilyName; 250 pTTF_FontFaceStyleName TTF_FontFaceStyleName; 251 pTTF_GlyphIsProvided TTF_GlyphIsProvided; 252 pTTF_GlyphMetrics TTF_GlyphMetrics; 253 pTTF_SizeText TTF_SizeText; 254 pTTF_SizeUTF8 TTF_SizeUTF8; 255 pTTF_SizeUNICODE TTF_SizeUNICODE; 256 pTTF_RenderText_Solid TTF_RenderText_Solid; 257 pTTF_RenderUTF8_Solid TTF_RenderUTF8_Solid; 258 pTTF_RenderUNICODE_Solid TTF_RenderUNICODE_Solid; 259 pTTF_RenderGlyph_Solid TTF_RenderGlyph_Solid; 260 pTTF_RenderText_Shaded TTF_RenderText_Shaded; 261 pTTF_RenderUTF8_Shaded TTF_RenderUTF8_Shaded; 262 pTTF_RenderUNICODE_Shaded TTF_RenderUNICODE_Shaded; 263 pTTF_RenderGlyph_Shaded TTF_RenderGlyph_Shaded; 264 pTTF_RenderText_Blended TTF_RenderText_Blended; 265 pTTF_RenderUTF8_Blended TTF_RenderUTF8_Blended; 266 pTTF_RenderUNICODE_Blended TTF_RenderUNICODE_Blended; 267 pTTF_RenderText_Blended_Wrapped TTF_RenderText_Blended_Wrapped; 268 pTTF_RenderUTF8_Blended_Wrapped TTF_RenderUTF8_Blended_Wrapped; 269 pTTF_RenderUNICODE_Blended_Wrapped TTF_RenderUNICODE_Blended_Wrapped; 270 pTTF_RenderGlyph_Blended TTF_RenderGlyph_Blended; 271 pTTF_CloseFont TTF_CloseFont; 272 pTTF_Quit TTF_Quit; 273 pTTF_WasInit TTF_WasInit; 274 pTTF_GetFontKerningSize TTF_GetFontKerningSize; 275 } 276 277 static if(sdlTTFSupport >= SDLTTFSupport.sdlTTF2014) { 278 extern(C) @nogc nothrow { 279 alias pTTF_GetFontKerningSizeGlyphs = int function(TTF_Font* font, ushort previous_ch, ushort ch); 280 } 281 282 __gshared { 283 pTTF_GetFontKerningSizeGlyphs TTF_GetFontKerningSizeGlyphs; 284 } 285 } 286 287 static if(sdlTTFSupport >= SDLTTFSupport.sdlTTF2018) { 288 extern(C) @nogc nothrow { 289 alias pTTF_GetFreeTypeVersion = void function(int* major, int* minor, int* patch); 290 alias pTTF_GetHarfBuzzVersion = void function(int* major, int* minor, int* patch); 291 alias pTTF_SetFontSDF = int function(TTF_Font* font, SDL_bool on_off); 292 alias pTTF_GetFontSDF = SDL_bool function(const(TTF_Font)* font); 293 alias pTTF_OpenFontDPI = TTF_Font* function(const(char)* file, int ptsize, uint hdpi, uint vdpi); 294 alias pTTF_OpenFontIndexDPI = TTF_Font* function(const(char)*file, int ptsize, long index, uint hdpi, uint vdpi); 295 alias pTTF_OpenFontDPIRW = TTF_Font* function(SDL_RWops* src, int freesrc, int ptsize, uint hdpi, uint vdpi); 296 alias pTTF_OpenFontIndexDPIRW = TTF_Font* function(SDL_RWops* src, int freesrc, int ptsize, long index, uint hdpi, uint vdpi); 297 alias pTTF_SetFontSizeDPI = int function(TTF_Font* font, int ptsize, uint hdpi, uint vdpi); 298 alias pTTF_GlyphIsProvided32 = int function(TTF_Font* font, uint ch); 299 alias pTTF_GlyphMetrics32 = int function(TTF_Font* font, uint ch, int* minx, int* maxx, int* miny, int* maxy, int* advance); 300 alias pTTF_RenderGlyph32_Solid = SDL_Surface* function(TTF_Font* font, uint ch, SDL_Color fg); 301 alias pTTF_RenderGlyph32_Shaded = SDL_Surface* function(TTF_Font* font, uint ch, SDL_Color fg, SDL_Color bg); 302 alias pTTF_RenderGlyph32_Blended = SDL_Surface* function(TTF_Font* font, uint ch, SDL_Color fg); 303 alias pTTF_GetFontKerningSizeGlyphs32 = int function(TTF_Font* font, uint previous_ch, uint ch); 304 alias pTTF_SetDirection = int function(int direction); 305 alias pTTF_SetScript = int function(int script); 306 alias pTTF_MeasureText = int function(TTF_Font* font, const(char)* text, int measure_width, int* extent, int* count); 307 alias pTTF_MeasureUTF8 = int function(TTF_Font* font, const(char)* text, int measure_width, int* extent, int* count); 308 alias pTTF_MeasureUNICODE = int function(TTF_Font* font, const(ushort)* text, int measure_width, int *extent, int *count); 309 alias pTTF_SetFontSize = int function(TTF_Font* font, int ptsize); 310 alias pTTF_RenderText_Solid_Wrapped = SDL_Surface* function(TTF_Font* font, const(char)* text, SDL_Color fg, uint wrapLength); 311 alias pTTF_RenderUTF8_Solid_Wrapped = SDL_Surface* function(TTF_Font* font, const(char)* text, SDL_Color fg, uint wrapLength); 312 alias pTTF_RenderUNICODE_Solid_Wrapped = SDL_Surface* function(TTF_Font* font, const(ushort)* text, SDL_Color fg, uint wrapLength); 313 alias pTTF_RenderText_Shaded_Wrapped = SDL_Surface* function(TTF_Font* font, const(char)* text, SDL_Color fg, SDL_Color bg, uint wrapLength); 314 alias pTTF_RenderUTF8_Shaded_Wrapped = SDL_Surface* function(TTF_Font* font, const(char)* text, SDL_Color fg, SDL_Color bg, uint wrapLength); 315 alias pTTF_RenderUNICODE_Shaded_Wrapped = SDL_Surface* function(TTF_Font* font, const(ushort)* text, SDL_Color fg, SDL_Color bg, uint wrapLength); 316 } 317 318 __gshared { 319 pTTF_GetFreeTypeVersion TTF_GetFreeTypeVersion; 320 pTTF_GetHarfBuzzVersion TTF_GetHarfBuzzVersion; 321 pTTF_SetFontSDF TTF_SetFontSDF; 322 pTTF_GetFontSDF TTF_GetFontSDF; 323 pTTF_OpenFontDPI TTF_OpenFontDPI; 324 pTTF_OpenFontIndexDPI TTF_OpenFontIndexDPI; 325 pTTF_OpenFontDPIRW TTF_OpenFontDPIRW; 326 pTTF_OpenFontIndexDPIRW TTF_OpenFontIndexDPIRW; 327 pTTF_SetFontSizeDPI TTF_SetFontSizeDPI; 328 pTTF_GlyphIsProvided32 TTF_GlyphIsProvided32; 329 pTTF_GlyphMetrics32 TTF_GlyphMetrics32; 330 pTTF_RenderGlyph32_Solid TTF_RenderGlyph32_Solid; 331 pTTF_RenderGlyph32_Shaded TTF_RenderGlyph32_Shaded; 332 pTTF_RenderGlyph32_Blended TTF_RenderGlyph32_Blended; 333 pTTF_GetFontKerningSizeGlyphs32 TTF_GetFontKerningSizeGlyphs32; 334 pTTF_SetDirection TTF_SetDirection; 335 pTTF_SetScript TTF_SetScript; 336 pTTF_MeasureText TTF_MeasureText; 337 pTTF_MeasureUTF8 TTF_MeasureUTF8; 338 pTTF_MeasureUNICODE TTF_MeasureUNICODE; 339 pTTF_SetFontSize TTF_SetFontSize; 340 pTTF_RenderText_Solid_Wrapped TTF_RenderText_Solid_Wrapped; 341 pTTF_RenderUTF8_Solid_Wrapped TTF_RenderUTF8_Solid_Wrapped; 342 pTTF_RenderUNICODE_Solid_Wrapped TTF_RenderUNICODE_Solid_Wrapped; 343 pTTF_RenderText_Shaded_Wrapped TTF_RenderText_Shaded_Wrapped; 344 pTTF_RenderUTF8_Shaded_Wrapped TTF_RenderUTF8_Shaded_Wrapped; 345 pTTF_RenderUNICODE_Shaded_Wrapped TTF_RenderUNICODE_Shaded_Wrapped; 346 } 347 } 348 349 private { 350 SharedLib lib; 351 SDLTTFSupport loadedVersion; 352 } 353 354 @nogc nothrow: 355 void unloadSDLTTF() 356 { 357 if(lib != invalidHandle) { 358 lib.unload(); 359 } 360 } 361 362 SDLTTFSupport loadedSDLTTFVersion() { return loadedVersion; } 363 364 bool isSDLTTFLoaded() 365 { 366 return lib != invalidHandle; 367 } 368 369 SDLTTFSupport loadSDLTTF() 370 { 371 version(Windows) { 372 const(char)[][1] libNames = ["SDL2_ttf.dll"]; 373 } 374 else version(OSX) { 375 const(char)[][6] libNames = [ 376 "libSDL2_ttf.dylib", 377 "/usr/local/lib/libSDL2_ttf.dylib", 378 "../Frameworks/SDL2_ttf.framework/SDL2_ttf", 379 "/Library/Frameworks/SDL2_ttf.framework/SDL2_ttf", 380 "/System/Library/Frameworks/SDL2_ttf.framework/SDL2_ttf", 381 "/opt/local/lib/libSDL2_ttf.dylib" 382 ]; 383 } 384 else version(Posix) { 385 const(char)[][6] libNames = [ 386 "libSDL2_ttf.so", 387 "/usr/local/lib/libSDL2_ttf.so", 388 "libSDL2-2.0_ttf.so", 389 "/usr/local/lib/libSDL2-2.0_ttf.so", 390 "libSDL2-2.0_ttf.so.0", 391 "/usr/local/lib/libSDL2-2.0_ttf.so.0" 392 ]; 393 } 394 else static assert(0, "bindbc-sdl is not yet supported on this platform."); 395 396 SDLTTFSupport ret; 397 foreach(name; libNames) { 398 ret = loadSDLTTF(name.ptr); 399 if(ret != SDLTTFSupport.noLibrary) break; 400 } 401 return ret; 402 } 403 404 SDLTTFSupport loadSDLTTF(const(char)* libName) 405 { 406 lib = load(libName); 407 if(lib == invalidHandle) { 408 return SDLTTFSupport.noLibrary; 409 } 410 411 auto errCount = errorCount(); 412 loadedVersion = SDLTTFSupport.badLibrary; 413 414 lib.bindSymbol(cast(void**)&TTF_Linked_Version,"TTF_Linked_Version"); 415 lib.bindSymbol(cast(void**)&TTF_ByteSwappedUNICODE,"TTF_ByteSwappedUNICODE"); 416 lib.bindSymbol(cast(void**)&TTF_Init,"TTF_Init"); 417 lib.bindSymbol(cast(void**)&TTF_OpenFont,"TTF_OpenFont"); 418 lib.bindSymbol(cast(void**)&TTF_OpenFontIndex,"TTF_OpenFontIndex"); 419 lib.bindSymbol(cast(void**)&TTF_OpenFontRW,"TTF_OpenFontRW"); 420 lib.bindSymbol(cast(void**)&TTF_OpenFontIndexRW,"TTF_OpenFontIndexRW"); 421 lib.bindSymbol(cast(void**)&TTF_GetFontStyle,"TTF_GetFontStyle"); 422 lib.bindSymbol(cast(void**)&TTF_SetFontStyle,"TTF_SetFontStyle"); 423 lib.bindSymbol(cast(void**)&TTF_GetFontOutline,"TTF_GetFontOutline"); 424 lib.bindSymbol(cast(void**)&TTF_SetFontOutline,"TTF_SetFontOutline"); 425 lib.bindSymbol(cast(void**)&TTF_GetFontHinting,"TTF_GetFontHinting"); 426 lib.bindSymbol(cast(void**)&TTF_SetFontHinting,"TTF_SetFontHinting"); 427 lib.bindSymbol(cast(void**)&TTF_FontHeight,"TTF_FontHeight"); 428 lib.bindSymbol(cast(void**)&TTF_FontAscent,"TTF_FontAscent"); 429 lib.bindSymbol(cast(void**)&TTF_FontDescent,"TTF_FontDescent"); 430 lib.bindSymbol(cast(void**)&TTF_FontLineSkip,"TTF_FontLineSkip"); 431 lib.bindSymbol(cast(void**)&TTF_GetFontKerning,"TTF_GetFontKerning"); 432 lib.bindSymbol(cast(void**)&TTF_SetFontKerning,"TTF_SetFontKerning"); 433 lib.bindSymbol(cast(void**)&TTF_FontFaces,"TTF_FontFaces"); 434 lib.bindSymbol(cast(void**)&TTF_FontFaceIsFixedWidth,"TTF_FontFaceIsFixedWidth"); 435 lib.bindSymbol(cast(void**)&TTF_FontFaceFamilyName,"TTF_FontFaceFamilyName"); 436 lib.bindSymbol(cast(void**)&TTF_FontFaceStyleName,"TTF_FontFaceStyleName"); 437 lib.bindSymbol(cast(void**)&TTF_GlyphIsProvided,"TTF_GlyphIsProvided"); 438 lib.bindSymbol(cast(void**)&TTF_GlyphMetrics,"TTF_GlyphMetrics"); 439 lib.bindSymbol(cast(void**)&TTF_SizeText,"TTF_SizeText"); 440 lib.bindSymbol(cast(void**)&TTF_SizeUTF8,"TTF_SizeUTF8"); 441 lib.bindSymbol(cast(void**)&TTF_SizeUNICODE,"TTF_SizeUNICODE"); 442 lib.bindSymbol(cast(void**)&TTF_RenderText_Solid,"TTF_RenderText_Solid"); 443 lib.bindSymbol(cast(void**)&TTF_RenderUTF8_Solid,"TTF_RenderUTF8_Solid"); 444 lib.bindSymbol(cast(void**)&TTF_RenderUNICODE_Solid,"TTF_RenderUNICODE_Solid"); 445 lib.bindSymbol(cast(void**)&TTF_RenderGlyph_Solid,"TTF_RenderGlyph_Solid"); 446 lib.bindSymbol(cast(void**)&TTF_RenderText_Shaded,"TTF_RenderText_Shaded"); 447 lib.bindSymbol(cast(void**)&TTF_RenderUTF8_Shaded,"TTF_RenderUTF8_Shaded"); 448 lib.bindSymbol(cast(void**)&TTF_RenderUNICODE_Shaded,"TTF_RenderUNICODE_Shaded"); 449 lib.bindSymbol(cast(void**)&TTF_RenderGlyph_Shaded,"TTF_RenderGlyph_Shaded"); 450 lib.bindSymbol(cast(void**)&TTF_RenderText_Blended,"TTF_RenderText_Blended"); 451 lib.bindSymbol(cast(void**)&TTF_RenderUTF8_Blended,"TTF_RenderUTF8_Blended"); 452 lib.bindSymbol(cast(void**)&TTF_RenderUNICODE_Blended,"TTF_RenderUNICODE_Blended"); 453 lib.bindSymbol(cast(void**)&TTF_RenderText_Blended_Wrapped,"TTF_RenderText_Blended_Wrapped"); 454 lib.bindSymbol(cast(void**)&TTF_RenderUTF8_Blended_Wrapped,"TTF_RenderUTF8_Blended_Wrapped"); 455 lib.bindSymbol(cast(void**)&TTF_RenderUNICODE_Blended_Wrapped,"TTF_RenderUNICODE_Blended_Wrapped"); 456 lib.bindSymbol(cast(void**)&TTF_RenderGlyph_Blended,"TTF_RenderGlyph_Blended"); 457 lib.bindSymbol(cast(void**)&TTF_CloseFont,"TTF_CloseFont"); 458 lib.bindSymbol(cast(void**)&TTF_Quit,"TTF_Quit"); 459 lib.bindSymbol(cast(void**)&TTF_WasInit,"TTF_WasInit"); 460 lib.bindSymbol(cast(void**)&TTF_GetFontKerningSize,"TTF_GetFontKerningSize"); 461 462 if(errorCount() != errCount) return SDLTTFSupport.badLibrary; 463 else loadedVersion = SDLTTFSupport.sdlTTF2012; 464 465 static if(sdlTTFSupport >= SDLTTFSupport.sdlTTF2014) { 466 lib.bindSymbol(cast(void**)&TTF_GetFontKerningSizeGlyphs,"TTF_GetFontKerningSizeGlyphs"); 467 468 if(errorCount() != errCount) return SDLTTFSupport.badLibrary; 469 else loadedVersion = SDLTTFSupport.sdlTTF2014; 470 } 471 472 static if(sdlTTFSupport >= SDLTTFSupport.sdlTTF2018) { 473 lib.bindSymbol(cast(void**)&TTF_GetFreeTypeVersion,"TTF_GetFreeTypeVersion"); 474 lib.bindSymbol(cast(void**)&TTF_GetHarfBuzzVersion,"TTF_GetHarfBuzzVersion"); 475 lib.bindSymbol(cast(void**)&TTF_SetFontSDF,"TTF_SetFontSDF"); 476 lib.bindSymbol(cast(void**)&TTF_GetFontSDF,"TTF_GetFontSDF"); 477 lib.bindSymbol(cast(void**)&TTF_OpenFontDPI,"TTF_OpenFontDPI"); 478 lib.bindSymbol(cast(void**)&TTF_OpenFontIndexDPI,"TTF_OpenFontIndexDPI"); 479 lib.bindSymbol(cast(void**)&TTF_OpenFontDPIRW,"TTF_OpenFontDPIRW"); 480 lib.bindSymbol(cast(void**)&TTF_OpenFontIndexDPIRW,"TTF_OpenFontIndexDPIRW"); 481 lib.bindSymbol(cast(void**)&TTF_SetFontSizeDPI,"TTF_SetFontSizeDPI"); 482 lib.bindSymbol(cast(void**)&TTF_GlyphIsProvided32,"TTF_GlyphIsProvided32"); 483 lib.bindSymbol(cast(void**)&TTF_GlyphMetrics32,"TTF_GlyphMetrics32"); 484 lib.bindSymbol(cast(void**)&TTF_RenderGlyph32_Solid,"TTF_RenderGlyph32_Solid"); 485 lib.bindSymbol(cast(void**)&TTF_RenderGlyph32_Shaded,"TTF_RenderGlyph32_Shaded"); 486 lib.bindSymbol(cast(void**)&TTF_RenderGlyph32_Blended,"TTF_RenderGlyph32_Blended"); 487 lib.bindSymbol(cast(void**)&TTF_GetFontKerningSizeGlyphs32,"TTF_GetFontKerningSizeGlyphs32"); 488 lib.bindSymbol(cast(void**)&TTF_SetDirection,"TTF_SetDirection"); 489 lib.bindSymbol(cast(void**)&TTF_SetScript,"TTF_SetScript"); 490 lib.bindSymbol(cast(void**)&TTF_MeasureText,"TTF_MeasureText"); 491 lib.bindSymbol(cast(void**)&TTF_MeasureUTF8,"TTF_MeasureUTF8"); 492 lib.bindSymbol(cast(void**)&TTF_MeasureUNICODE,"TTF_MeasureUNICODE"); 493 lib.bindSymbol(cast(void**)&TTF_SetFontSize,"TTF_SetFontSize"); 494 lib.bindSymbol(cast(void**)&TTF_RenderText_Solid_Wrapped,"TTF_RenderText_Solid_Wrapped"); 495 lib.bindSymbol(cast(void**)&TTF_RenderUTF8_Solid_Wrapped,"TTF_RenderUTF8_Solid_Wrapped"); 496 lib.bindSymbol(cast(void**)&TTF_RenderUNICODE_Solid_Wrapped,"TTF_RenderUNICODE_Solid_Wrapped"); 497 lib.bindSymbol(cast(void**)&TTF_RenderText_Shaded_Wrapped,"TTF_RenderText_Shaded_Wrapped"); 498 lib.bindSymbol(cast(void**)&TTF_RenderUTF8_Shaded_Wrapped,"TTF_RenderUTF8_Shaded_Wrapped"); 499 lib.bindSymbol(cast(void**)&TTF_RenderUNICODE_Shaded_Wrapped,"TTF_RenderUNICODE_Shaded_Wrapped"); 500 501 if(errorCount() != errCount) return SDLTTFSupport.badLibrary; 502 else loadedVersion = SDLTTFSupport.sdlTTF2018; 503 } 504 505 return loadedVersion; 506 } 507 }