1/*
2 * Copyright © 2015 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission.  The copyright holders make no representations
11 * about the suitability of this software for any purpose.  It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#ifndef _LIBXFONT2_H_
24#define _LIBXFONT2_H_
25
26#include	<stddef.h>
27#include	<stdarg.h>
28#include	<stdint.h>
29#include	<X11/Xfuncproto.h>
30#include	<X11/fonts/font.h>
31#include	<X11/fonts/fontproto.h>
32
33#define XFONT2_FPE_FUNCS_VERSION	1
34
35typedef int (*WakeupFpe) (FontPathElementPtr fpe);
36
37typedef struct _xfont2_fpe_funcs {
38	int		version;
39	NameCheckFunc	name_check;
40	InitFpeFunc	init_fpe;
41	FreeFpeFunc	free_fpe;
42	ResetFpeFunc	reset_fpe;
43	OpenFontFunc	open_font;
44	CloseFontFunc	close_font;
45	ListFontsFunc	list_fonts;
46	StartLfwiFunc	start_list_fonts_with_info;
47	NextLfwiFunc	list_next_font_with_info;
48	WakeupFpe	wakeup_fpe;
49	ClientDiedFunc	client_died;
50	LoadGlyphsFunc	load_glyphs;
51	StartLaFunc	start_list_fonts_and_aliases;
52	NextLaFunc	list_next_font_or_alias;
53	SetPathFunc	set_path_hook;
54} xfont2_fpe_funcs_rec, *xfont2_fpe_funcs_ptr;
55
56typedef void (*FontBlockHandlerProcPtr) (void *timeout);
57
58typedef void (*FontFdHandlerProcPtr) (int fd, void *data);
59
60#define XFONT2_CLIENT_FUNCS_VERSION	1
61
62typedef struct _xfont2_client_funcs {
63	int			version;
64	int			(*client_auth_generation)(ClientPtr client);
65	Bool			(*client_signal)(ClientPtr client);
66	void			(*delete_font_client_id)(Font id);
67	void			(*verrorf)(const char *f, va_list ap) _X_ATTRIBUTE_PRINTF(1,0);
68	FontPtr			(*find_old_font)(FSID id);
69	FontResolutionPtr	(*get_client_resolutions)(int *num);
70	int			(*get_default_point_size)(void);
71	Font			(*get_new_font_client_id)(void);
72	uint32_t		(*get_time_in_millis)(void);
73	int			(*init_fs_handlers)(FontPathElementPtr fpe,
74						    FontBlockHandlerProcPtr block_handler);
75	int			(*register_fpe_funcs)(const xfont2_fpe_funcs_rec *funcs);
76	void			(*remove_fs_handlers)(FontPathElementPtr fpe,
77						      FontBlockHandlerProcPtr block_handler,
78						      Bool all );
79	void			*(*get_server_client)(void);
80	int			(*set_font_authorizations)(char **authorizations,
81							   int *authlen, void *client);
82	int			(*store_font_client_font)(FontPtr pfont, Font id);
83	Atom			(*make_atom)(const char *string, unsigned len, int makeit);
84	int			(*valid_atom)(Atom atom);
85	const char		*(*name_for_atom)(Atom atom);
86	unsigned long		(*get_server_generation)(void);
87	int			(*add_fs_fd)(int fd, FontFdHandlerProcPtr handler, void *data);
88	void			(*remove_fs_fd)(int fd);
89	void			(*adjust_fs_wait_for_delay)(void *wt, unsigned long newdelay);
90} xfont2_client_funcs_rec, *xfont2_client_funcs_ptr;
91
92_X_EXPORT int
93xfont2_init(xfont2_client_funcs_rec const *client_funcs);
94
95_X_EXPORT void
96xfont2_query_glyph_extents(FontPtr pFont, CharInfoPtr *charinfo,
97			   unsigned long count, ExtentInfoRec *info);
98
99_X_EXPORT Bool
100xfont2_query_text_extents(FontPtr pFont, unsigned long count,
101			  unsigned char *chars, ExtentInfoRec *info);
102
103_X_EXPORT Bool
104xfont2_parse_glyph_caching_mode(char *str);
105
106_X_EXPORT void
107xfont2_init_glyph_caching(void);
108
109_X_EXPORT void
110xfont2_set_glyph_caching_mode(int newmode);
111
112_X_EXPORT FontNamesPtr
113xfont2_make_font_names_record(unsigned size);
114
115_X_EXPORT void
116xfont2_free_font_names(FontNamesPtr pFN);
117
118_X_EXPORT int
119xfont2_add_font_names_name(FontNamesPtr names,
120			   char *name,
121			   int length);
122
123typedef struct _xfont2_pattern_cache    *xfont2_pattern_cache_ptr;
124
125_X_EXPORT xfont2_pattern_cache_ptr
126xfont2_make_font_pattern_cache(void);
127
128_X_EXPORT void
129xfont2_free_font_pattern_cache(xfont2_pattern_cache_ptr cache);
130
131_X_EXPORT void
132xfont2_empty_font_pattern_cache(xfont2_pattern_cache_ptr cache);
133
134_X_EXPORT void
135xfont2_cache_font_pattern(xfont2_pattern_cache_ptr cache,
136			  const char * pattern,
137			  int patlen,
138			  FontPtr pFont);
139
140_X_EXPORT FontPtr
141xfont2_find_cached_font_pattern(xfont2_pattern_cache_ptr cache,
142				const char * pattern,
143				int patlen);
144
145_X_EXPORT void
146xfont2_remove_cached_font_pattern(xfont2_pattern_cache_ptr cache,
147				  FontPtr pFont);
148
149/* private.c */
150
151_X_EXPORT int
152xfont2_allocate_font_private_index (void);
153
154static inline void *
155xfont2_font_get_private(FontPtr pFont, int n)
156{
157	if (n > pFont->maxPrivate)
158		return NULL;
159	return pFont->devPrivates[n];
160}
161
162_X_EXPORT Bool
163xfont2_font_set_private(FontPtr pFont, int n, void *ptr);
164
165#endif /* _LIBXFONT2_H_ */
166