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	<stdarg.h>
27 #include	<stdint.h>
28 #include	<X11/Xfuncproto.h>
29 #include	<X11/fonts/font.h>
30 
31 #define XFONT2_FPE_FUNCS_VERSION	1
32 
33 typedef int (*WakeupFpe) (FontPathElementPtr fpe);
34 
35 typedef struct _xfont2_fpe_funcs {
36 	int		version;
37 	NameCheckFunc	name_check;
38 	InitFpeFunc	init_fpe;
39 	FreeFpeFunc	free_fpe;
40 	ResetFpeFunc	reset_fpe;
41 	OpenFontFunc	open_font;
42 	CloseFontFunc	close_font;
43 	ListFontsFunc	list_fonts;
44 	StartLfwiFunc	start_list_fonts_with_info;
45 	NextLfwiFunc	list_next_font_with_info;
46 	WakeupFpe	wakeup_fpe;
47 	ClientDiedFunc	client_died;
48 	LoadGlyphsFunc	load_glyphs;
49 	StartLaFunc	start_list_fonts_and_aliases;
50 	NextLaFunc	list_next_font_or_alias;
51 	SetPathFunc	set_path_hook;
52 } xfont2_fpe_funcs_rec, *xfont2_fpe_funcs_ptr;
53 
54 typedef void (*FontBlockHandlerProcPtr) (void *timeout);
55 
56 typedef void (*FontFdHandlerProcPtr) (int fd, void *data);
57 
58 #define XFONT2_CLIENT_FUNCS_VERSION	1
59 
60 typedef struct _xfont2_client_funcs {
61 	int			version;
62 	int			(*client_auth_generation)(ClientPtr client);
63 	Bool			(*client_signal)(ClientPtr client);
64 	void			(*delete_font_client_id)(Font id);
65 	void			(*verrorf)(const char *f, va_list ap) _X_ATTRIBUTE_PRINTF(1,0);
66 	FontPtr			(*find_old_font)(FSID id);
67 	FontResolutionPtr	(*get_client_resolutions)(int *num);
68 	int			(*get_default_point_size)(void);
69 	Font			(*get_new_font_client_id)(void);
70 	uint32_t		(*get_time_in_millis)(void);
71 	int			(*init_fs_handlers)(FontPathElementPtr fpe,
72 						    FontBlockHandlerProcPtr block_handler);
73 	int			(*register_fpe_funcs)(const xfont2_fpe_funcs_rec *funcs);
74 	void			(*remove_fs_handlers)(FontPathElementPtr fpe,
75 						      FontBlockHandlerProcPtr block_handler,
76 						      Bool all );
77 	void			*(*get_server_client)(void);
78 	int			(*set_font_authorizations)(char **authorizations,
79 							   int *authlen, void *client);
80 	int			(*store_font_client_font)(FontPtr pfont, Font id);
81 	Atom			(*make_atom)(const char *string, unsigned len, int makeit);
82 	int			(*valid_atom)(Atom atom);
83 	const char		*(*name_for_atom)(Atom atom);
84 	unsigned long		(*get_server_generation)(void);
85 	int			(*add_fs_fd)(int fd, FontFdHandlerProcPtr handler, void *data);
86 	void			(*remove_fs_fd)(int fd);
87 	void			(*adjust_fs_wait_for_delay)(void *wt, unsigned long newdelay);
88 } xfont2_client_funcs_rec, *xfont2_client_funcs_ptr;
89 
90 _X_EXPORT int
91 xfont2_init(xfont2_client_funcs_rec const *client_funcs);
92 
93 _X_EXPORT void
94 xfont2_query_glyph_extents(FontPtr pFont, CharInfoPtr *charinfo,
95 			   unsigned long count, ExtentInfoRec *info);
96 
97 _X_EXPORT Bool
98 xfont2_query_text_extents(FontPtr pFont, unsigned long count,
99 			  unsigned char *chars, ExtentInfoRec *info);
100 
101 _X_EXPORT Bool
102 xfont2_parse_glyph_caching_mode(char *str);
103 
104 _X_EXPORT void
105 xfont2_init_glyph_caching(void);
106 
107 _X_EXPORT void
108 xfont2_set_glyph_caching_mode(int newmode);
109 
110 _X_EXPORT FontNamesPtr
111 xfont2_make_font_names_record(unsigned size);
112 
113 _X_EXPORT void
114 xfont2_free_font_names(FontNamesPtr pFN);
115 
116 _X_EXPORT int
117 xfont2_add_font_names_name(FontNamesPtr names,
118 			   char *name,
119 			   int length);
120 
121 typedef struct _xfont2_pattern_cache    *xfont2_pattern_cache_ptr;
122 
123 _X_EXPORT xfont2_pattern_cache_ptr
124 xfont2_make_font_pattern_cache(void);
125 
126 _X_EXPORT void
127 xfont2_free_font_pattern_cache(xfont2_pattern_cache_ptr cache);
128 
129 _X_EXPORT void
130 xfont2_empty_font_pattern_cache(xfont2_pattern_cache_ptr cache);
131 
132 _X_EXPORT void
133 xfont2_cache_font_pattern(xfont2_pattern_cache_ptr cache,
134 			  const char * pattern,
135 			  int patlen,
136 			  FontPtr pFont);
137 
138 _X_EXPORT FontPtr
139 xfont2_find_cached_font_pattern(xfont2_pattern_cache_ptr cache,
140 				const char * pattern,
141 				int patlen);
142 
143 _X_EXPORT void
144 xfont2_remove_cached_font_pattern(xfont2_pattern_cache_ptr cache,
145 				  FontPtr pFont);
146 
147 /* private.c */
148 
149 _X_EXPORT int
150 xfont2_allocate_font_private_index (void);
151 
152 static inline void *
xfont2_font_get_private(FontPtr pFont,int n)153 xfont2_font_get_private(FontPtr pFont, int n)
154 {
155 	if (n > pFont->maxPrivate)
156 		return NULL;
157 	return pFont->devPrivates[n];
158 }
159 
160 _X_EXPORT Bool
161 xfont2_font_set_private(FontPtr pFont, int n, void *ptr);
162 
163 #endif /* _LIBXFONT2_H_ */
164