DIB Engine: implement most engine functions
[wine/hacks.git] / dlls / winedib.drv / freetype.c
blob111a18b6980ff5f23a68bef0481ab2b88166e247
1 /*
2 * Truetype font functions
4 * Copyright 2008 Massimo Del Fedele
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include "dibdrv.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
27 #define MAKE_FUNCPTR(f) typeof(f) * p##f = NULL;
28 MAKE_FUNCPTR(FT_Done_Face)
29 MAKE_FUNCPTR(FT_Done_FreeType)
30 MAKE_FUNCPTR(FT_Get_Char_Index)
31 MAKE_FUNCPTR(FT_Get_Glyph_Name)
32 MAKE_FUNCPTR(FT_Get_Sfnt_Name)
33 MAKE_FUNCPTR(FT_Get_Sfnt_Name_Count)
34 MAKE_FUNCPTR(FT_Get_Sfnt_Table)
35 MAKE_FUNCPTR(FT_Init_FreeType)
36 MAKE_FUNCPTR(FT_Load_Glyph)
37 MAKE_FUNCPTR(FT_Load_Char)
38 MAKE_FUNCPTR(FT_Get_Glyph)
39 MAKE_FUNCPTR(FT_Glyph_Copy)
40 MAKE_FUNCPTR(FT_Glyph_To_Bitmap)
41 MAKE_FUNCPTR(FT_Done_Glyph)
42 MAKE_FUNCPTR(FT_New_Face)
43 MAKE_FUNCPTR(FT_Set_Charmap)
44 MAKE_FUNCPTR(FT_Set_Char_Size)
45 MAKE_FUNCPTR(FT_Set_Pixel_Sizes)
46 MAKE_FUNCPTR(FT_Get_First_Char)
47 MAKE_FUNCPTR(FT_Render_Glyph)
48 MAKE_FUNCPTR(FT_Glyph_Transform)
49 #undef MAKE_FUNCPTR
51 /* freetype initialization flag */
52 static BOOL FreeType_Initialized = FALSE;
54 /* freetype dll handle */
55 static void *ft_handle = NULL;
57 /* freetype library handle */
58 FT_Library DIBDRV_ftLibrary = NULL;
60 /* initialize freetype library */
61 BOOL _DIBDRV_FreeType_Init(void)
63 FT_Int error;
65 ft_handle = wine_dlopen(SONAME_LIBFREETYPE, RTLD_NOW, NULL, 0);
66 if(!ft_handle)
68 WINE_MESSAGE(
69 "Wine cannot find the FreeType font library. To enable Wine to\n"
70 "use TrueType fonts please install a version of FreeType greater than\n"
71 "or equal to 2.0.5.\n"
72 "http://www.freetype.org\n");
73 return FALSE;
76 #define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(ft_handle, #f, NULL, 0)) == NULL) goto sym_not_found;
77 LOAD_FUNCPTR(FT_Done_Face)
78 LOAD_FUNCPTR(FT_Done_FreeType)
79 LOAD_FUNCPTR(FT_Get_Char_Index)
80 LOAD_FUNCPTR(FT_Get_Glyph_Name)
81 LOAD_FUNCPTR(FT_Get_Sfnt_Name)
82 LOAD_FUNCPTR(FT_Get_Sfnt_Name_Count)
83 LOAD_FUNCPTR(FT_Get_Sfnt_Table)
84 LOAD_FUNCPTR(FT_Init_FreeType)
85 LOAD_FUNCPTR(FT_Load_Glyph)
86 LOAD_FUNCPTR(FT_Load_Char)
87 LOAD_FUNCPTR(FT_Get_Glyph)
88 LOAD_FUNCPTR(FT_Glyph_Copy)
89 LOAD_FUNCPTR(FT_Glyph_To_Bitmap)
90 LOAD_FUNCPTR(FT_Done_Glyph)
91 LOAD_FUNCPTR(FT_New_Face)
92 LOAD_FUNCPTR(FT_Set_Charmap)
93 LOAD_FUNCPTR(FT_Set_Char_Size)
94 LOAD_FUNCPTR(FT_Set_Pixel_Sizes)
95 LOAD_FUNCPTR(FT_Get_First_Char)
96 LOAD_FUNCPTR(FT_Render_Glyph)
97 LOAD_FUNCPTR(FT_Glyph_Transform)
98 #undef LOAD_FUNCPTR
100 error = pFT_Init_FreeType(&DIBDRV_ftLibrary);
101 if (error != FT_Err_Ok)
103 ERR("%s returned %i\n", "FT_Init_FreeType", error);
104 wine_dlclose(ft_handle, NULL, 0);
105 return FALSE;
108 /* marks library as initialized */
109 FreeType_Initialized = TRUE;
111 return TRUE;
113 sym_not_found:
114 WINE_MESSAGE(
115 "Wine cannot find certain functions that it needs inside the FreeType\n"
116 "font library. To enable Wine to use TrueType fonts please upgrade\n"
117 "FreeType to at least version 2.0.5.\n"
118 "http://www.freetype.org\n");
119 wine_dlclose(ft_handle, NULL, 0);
120 ft_handle = NULL;
121 return FALSE;
124 /* terminates freetype library */
125 void _DIBDRV_FreeType_Terminate(void)
127 if(!FreeType_Initialized)
128 return;
130 /* terminates and unload freetype library */
131 pFT_Done_FreeType(DIBDRV_ftLibrary);
132 wine_dlclose(ft_handle, NULL, 0);
133 ft_handle = NULL;
134 FreeType_Initialized = FALSE;