DIB Engine: fixes clipping, text and more
[wine/hacks.git] / dlls / winedib.drv / freetype.c
blobf1cd7b4cc2dfc964b8c6f2d3a2b0bd9969e72169
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 MAKE_FUNCPTR(FT_Bitmap_New)
50 MAKE_FUNCPTR(FT_Bitmap_Done)
51 MAKE_FUNCPTR(FT_Bitmap_Convert)
52 #undef MAKE_FUNCPTR
54 /* freetype initialization flag */
55 static BOOL FreeType_Initialized = FALSE;
57 /* freetype dll handle */
58 static void *ft_handle = NULL;
60 /* freetype library handle */
61 FT_Library DIBDRV_ftLibrary = NULL;
63 /* initialize freetype library */
64 BOOL _DIBDRV_FreeType_Init(void)
66 FT_Int error;
68 ft_handle = wine_dlopen(SONAME_LIBFREETYPE, RTLD_NOW, NULL, 0);
69 if(!ft_handle)
71 WINE_MESSAGE(
72 "Wine cannot find the FreeType font library. To enable Wine to\n"
73 "use TrueType fonts please install a version of FreeType greater than\n"
74 "or equal to 2.0.5.\n"
75 "http://www.freetype.org\n");
76 return FALSE;
79 #define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(ft_handle, #f, NULL, 0)) == NULL) goto sym_not_found;
80 LOAD_FUNCPTR(FT_Done_Face)
81 LOAD_FUNCPTR(FT_Done_FreeType)
82 LOAD_FUNCPTR(FT_Get_Char_Index)
83 LOAD_FUNCPTR(FT_Get_Glyph_Name)
84 LOAD_FUNCPTR(FT_Get_Sfnt_Name)
85 LOAD_FUNCPTR(FT_Get_Sfnt_Name_Count)
86 LOAD_FUNCPTR(FT_Get_Sfnt_Table)
87 LOAD_FUNCPTR(FT_Init_FreeType)
88 LOAD_FUNCPTR(FT_Load_Glyph)
89 LOAD_FUNCPTR(FT_Load_Char)
90 LOAD_FUNCPTR(FT_Get_Glyph)
91 LOAD_FUNCPTR(FT_Glyph_Copy)
92 LOAD_FUNCPTR(FT_Glyph_To_Bitmap)
93 LOAD_FUNCPTR(FT_Done_Glyph)
94 LOAD_FUNCPTR(FT_New_Face)
95 LOAD_FUNCPTR(FT_Set_Charmap)
96 LOAD_FUNCPTR(FT_Set_Char_Size)
97 LOAD_FUNCPTR(FT_Set_Pixel_Sizes)
98 LOAD_FUNCPTR(FT_Get_First_Char)
99 LOAD_FUNCPTR(FT_Render_Glyph)
100 LOAD_FUNCPTR(FT_Glyph_Transform)
101 LOAD_FUNCPTR(FT_Bitmap_New)
102 LOAD_FUNCPTR(FT_Bitmap_Done)
103 LOAD_FUNCPTR(FT_Bitmap_Convert)
104 #undef LOAD_FUNCPTR
106 error = pFT_Init_FreeType(&DIBDRV_ftLibrary);
107 if (error != FT_Err_Ok)
109 ERR("%s returned %i\n", "FT_Init_FreeType", error);
110 wine_dlclose(ft_handle, NULL, 0);
111 return FALSE;
114 /* marks library as initialized */
115 FreeType_Initialized = TRUE;
117 return TRUE;
119 sym_not_found:
120 WINE_MESSAGE(
121 "Wine cannot find certain functions that it needs inside the FreeType\n"
122 "font library. To enable Wine to use TrueType fonts please upgrade\n"
123 "FreeType to at least version 2.0.5.\n"
124 "http://www.freetype.org\n");
125 wine_dlclose(ft_handle, NULL, 0);
126 ft_handle = NULL;
127 return FALSE;
130 /* terminates freetype library */
131 void _DIBDRV_FreeType_Terminate(void)
133 if(!FreeType_Initialized)
134 return;
136 /* terminates and unload freetype library */
137 pFT_Done_FreeType(DIBDRV_ftLibrary);
138 wine_dlclose(ft_handle, NULL, 0);
139 ft_handle = NULL;
140 FreeType_Initialized = FALSE;