dsound: Report buffer notifications in offset order.
[wine.git] / dlls / dwrite / freetype.c
blob86d85b34739b9aea931229d453d3302bd4d114c8
1 /*
2 * FreeType integration
4 * Copyright 2014 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #ifdef HAVE_FT2BUILD_H
25 #include <ft2build.h>
26 #include FT_FREETYPE_H
27 #endif /* HAVE_FT2BUILD_H */
29 #include "windef.h"
30 #include "wine/library.h"
31 #include "wine/debug.h"
33 #include "dwrite_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
37 #ifdef HAVE_FREETYPE
39 static void *ft_handle = NULL;
40 static FT_Library library = 0;
41 typedef struct
43 FT_Int major;
44 FT_Int minor;
45 FT_Int patch;
46 } FT_Version_t;
48 #define MAKE_FUNCPTR(f) static typeof(f) * p##f = NULL
49 MAKE_FUNCPTR(FT_Done_Face);
50 MAKE_FUNCPTR(FT_Init_FreeType);
51 MAKE_FUNCPTR(FT_Library_Version);
52 MAKE_FUNCPTR(FT_New_Memory_Face);
53 #undef MAKE_FUNCPTR
55 struct ft_fontface
57 FT_Face face;
60 BOOL init_freetype(void)
62 FT_Version_t FT_Version;
64 ft_handle = wine_dlopen(SONAME_LIBFREETYPE, RTLD_NOW, NULL, 0);
65 if (!ft_handle) {
66 WINE_MESSAGE("Wine cannot find the FreeType font library.\n");
67 return FALSE;
70 #define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(ft_handle, #f, NULL, 0)) == NULL){WARN("Can't find symbol %s\n", #f); goto sym_not_found;}
71 LOAD_FUNCPTR(FT_Done_Face)
72 LOAD_FUNCPTR(FT_Init_FreeType)
73 LOAD_FUNCPTR(FT_Library_Version)
74 LOAD_FUNCPTR(FT_New_Memory_Face)
75 #undef LOAD_FUNCPTR
77 if (pFT_Init_FreeType(&library) != 0) {
78 ERR("Can't init FreeType library\n");
79 wine_dlclose(ft_handle, NULL, 0);
80 ft_handle = NULL;
81 return FALSE;
83 pFT_Library_Version(library, &FT_Version.major, &FT_Version.minor, &FT_Version.patch);
85 TRACE("FreeType version is %d.%d.%d\n", FT_Version.major, FT_Version.minor, FT_Version.patch);
86 return TRUE;
88 sym_not_found:
89 WINE_MESSAGE("Wine cannot find certain functions that it needs from FreeType library.\n");
90 wine_dlclose(ft_handle, NULL, 0);
91 ft_handle = NULL;
92 return FALSE;
95 HRESULT alloc_ft_fontface(const void *data_ptr, UINT32 data_size, UINT32 index, struct ft_fontface **ftface)
97 FT_Face face;
98 FT_Error err;
100 *ftface = heap_alloc_zero(sizeof(struct ft_fontface));
101 if (!*ftface)
102 return E_OUTOFMEMORY;
104 err = pFT_New_Memory_Face(library, data_ptr, data_size, index, &face);
105 if (err) {
106 ERR("FT_New_Memory_Face rets %d\n", err);
107 return E_FAIL;
109 (*ftface)->face = face;
111 return S_OK;
114 void release_ft_fontface(struct ft_fontface *ftface)
116 if (!ftface) return;
117 pFT_Done_Face(ftface->face);
118 heap_free(ftface);
121 #else /* HAVE_FREETYPE */
123 BOOL init_freetype(void)
125 return FALSE;
128 HRESULT alloc_ft_fontface(const void *data_ptr, UINT32 data_size, UINT32 index, struct ft_fontface **face)
130 *face = NULL;
131 return S_FALSE;
134 void release_ft_fontface(struct ft_fontface *face)
138 #endif /* HAVE_FREETYPE */