Commit 135fb032 authored by Keith Packard's avatar Keith Packard

Eliminate calls back to X server or font server functions by name (v4)

This eliminates the weak symbol adventures and makes all of the calls
back to the X server or Font server go through a table of functions
instead, clarifying the required API.

As this is a rather major change to the API for the library, it now
installs itself as libXfont2 instead of libXfont, and the package
config file is now xfont2.pc.

All of the installed headers remain the same as the original library;
there's now a new include file, libxfont2.h, which defines the X
server and Font server interfaces.

This moves util/atom.c to stubs/atom.c and reformats that file, hence
the diff being larger than it would otherwise be.

v2: Rename to libXfont2 instead of libXfont_2 as suggested by Emil Velikov
    Fix whitespace in stubs/atom.c, which was moved from util/

v3: Remove select masks from API. Expose single 'font_init' function
    for all library initialization.

v4: Change name of distributed tarballs to libXfont2 as well
Signed-off-by: Keith Packard's avatarKeith Packard <keithp@keithp.com>
parent eb67d10a
......@@ -23,6 +23,9 @@ SUBDIRS=doc src
libXfontincludedir = $(includedir)/X11/fonts
libXfontinclude_HEADERS = \
include/X11/fonts/libxfont2.h
noinst_HEADERS = \
include/X11/fonts/bdfint.h \
include/X11/fonts/bitmap.h \
include/X11/fonts/bufio.h \
......@@ -35,13 +38,15 @@ libXfontinclude_HEADERS = \
include/X11/fonts/fontutil.h \
include/X11/fonts/fontxlfd.h \
include/X11/fonts/pcf.h \
include/libxfontint.h \
src/FreeType/ft.h \
src/FreeType/ftfuncs.h
nodist_libXfontinclude_HEADERS = \
include/X11/fonts/fontconf.h
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = xfont.pc
pkgconfig_DATA = xfont2.pc
MAINTAINERCLEANFILES = ChangeLog INSTALL
......
......@@ -21,8 +21,8 @@
# Initialize Autoconf
AC_PREREQ([2.60])
AC_INIT([libXfont], [1.5.1],
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [libXfont])
AC_INIT([libXfont2], [2.0.0],
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [libXfont2])
AC_CONFIG_SRCDIR([Makefile.am])
AC_CONFIG_HEADERS([config.h include/X11/fonts/fontconf.h])
AC_CONFIG_MACRO_DIR([m4])
......@@ -253,5 +253,5 @@ AC_CONFIG_FILES([Makefile
src/fc/Makefile
src/util/Makefile
src/stubs/Makefile
xfont.pc])
xfont2.pc])
AC_OUTPUT
......@@ -66,7 +66,7 @@ extern BufFilePtr BufFilePushBZIP2 ( BufFilePtr );
#endif
extern int BufFileClose ( BufFilePtr, int );
extern int BufFileRead ( BufFilePtr, char*, int );
extern int BufFileWrite ( BufFilePtr, char*, int );
extern int BufFileWrite ( BufFilePtr, const char*, int );
#define BufFileGet(f) ((f)->left-- ? *(f)->bufp++ : ((f)->eof = (*(f)->input) (f)))
#define BufFilePut(c,f) (--(f)->left ? *(f)->bufp++ = ((unsigned char)(c)) : (*(f)->output) ((unsigned char)(c),f))
......
......@@ -54,7 +54,7 @@ in this Software without prior written authorization from The Open Group.
extern Atom MakeAtom ( const char *string, unsigned len, int makeit );
extern int ValidAtom ( Atom atom );
extern char *NameForAtom (Atom atom);
extern const char *NameForAtom (Atom atom);
#define lowbit(x) ((x) & (~(x) + 1))
......
......@@ -3,6 +3,7 @@
#include <X11/fonts/FSproto.h>
#if 0
extern int FontCouldBeTerminal(FontInfoPtr);
extern int CheckFSFormat(fsBitmapFormat, fsBitmapFormatMask, int *, int *,
int *, int *, int *);
......@@ -20,5 +21,6 @@ extern void InitGlyphCaching ( void );
extern void SetGlyphCachingMode ( int newmode );
extern int add_range ( fsRange *newrange, int *nranges, fsRange **range,
Bool charset_subset );
#endif
#endif /* _FONTUTIL_H_ */
/*
* Copyright © 2015 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#ifndef _LIBXFONT2_H_
#define _LIBXFONT2_H_
#include <stdarg.h>
#include <stdint.h>
#include <X11/Xfuncproto.h>
#include <X11/fonts/font.h>
#define XFONT2_FPE_FUNCS_VERSION 1
typedef int (*WakeupFpe) (FontPathElementPtr fpe);
typedef struct _xfont2_fpe_funcs {
int version;
NameCheckFunc name_check;
InitFpeFunc init_fpe;
FreeFpeFunc free_fpe;
ResetFpeFunc reset_fpe;
OpenFontFunc open_font;
CloseFontFunc close_font;
ListFontsFunc list_fonts;
StartLfwiFunc start_list_fonts_with_info;
NextLfwiFunc list_next_font_with_info;
WakeupFpe wakeup_fpe;
ClientDiedFunc client_died;
LoadGlyphsFunc load_glyphs;
StartLaFunc start_list_fonts_and_aliases;
NextLaFunc list_next_font_or_alias;
SetPathFunc set_path_hook;
} xfont2_fpe_funcs_rec, *xfont2_fpe_funcs_ptr;
typedef void (*FontBlockHandlerProcPtr) (void *timeout);
typedef void (*FontFdHandlerProcPtr) (int fd, void *data);
#define XFONT2_CLIENT_FUNCS_VERSION 1
typedef struct _xfont2_client_funcs {
int version;
int (*client_auth_generation)(ClientPtr client);
Bool (*client_signal)(ClientPtr client);
void (*delete_font_client_id)(Font id);
void (*verrorf)(const char *f, va_list ap) _X_ATTRIBUTE_PRINTF(1,0);
FontPtr (*find_old_font)(FSID id);
FontResolutionPtr (*get_client_resolutions)(int *num);
int (*get_default_point_size)(void);
Font (*get_new_font_client_id)(void);
uint32_t (*get_time_in_millis)(void);
int (*init_fs_handlers)(FontPathElementPtr fpe,
FontBlockHandlerProcPtr block_handler);
int (*register_fpe_funcs)(const xfont2_fpe_funcs_rec *funcs);
void (*remove_fs_handlers)(FontPathElementPtr fpe,
FontBlockHandlerProcPtr block_handler,
Bool all );
void *(*get_server_client)(void);
int (*set_font_authorizations)(char **authorizations,
int *authlen, void *client);
int (*store_font_client_font)(FontPtr pfont, Font id);
Atom (*make_atom)(const char *string, unsigned len, int makeit);
int (*valid_atom)(Atom atom);
const char *(*name_for_atom)(Atom atom);
unsigned long (*get_server_generation)(void);
int (*add_fs_fd)(int fd, FontFdHandlerProcPtr handler, void *data);
void (*remove_fs_fd)(int fd);
void (*adjust_fs_wait_for_delay)(void *wt, unsigned long newdelay);
} xfont2_client_funcs_rec, *xfont2_client_funcs_ptr;
_X_EXPORT int
xfont2_init(xfont2_client_funcs_rec const *client_funcs);
_X_EXPORT void
xfont2_query_glyph_extents(FontPtr pFont, CharInfoPtr *charinfo,
unsigned long count, ExtentInfoRec *info);
_X_EXPORT Bool
xfont2_query_text_extents(FontPtr pFont, unsigned long count,
unsigned char *chars, ExtentInfoRec *info);
_X_EXPORT Bool
xfont2_parse_glyph_caching_mode(char *str);
_X_EXPORT void
xfont2_init_glyph_caching(void);
_X_EXPORT void
xfont2_set_glyph_caching_mode(int newmode);
_X_EXPORT FontNamesPtr
xfont2_make_font_names_record(unsigned size);
_X_EXPORT void
xfont2_free_font_names(FontNamesPtr pFN);
_X_EXPORT int
xfont2_add_font_names_name(FontNamesPtr names,
char *name,
int length);
typedef struct _xfont2_pattern_cache *xfont2_pattern_cache_ptr;
_X_EXPORT xfont2_pattern_cache_ptr
xfont2_make_font_pattern_cache(void);
_X_EXPORT void
xfont2_free_font_pattern_cache(xfont2_pattern_cache_ptr cache);
_X_EXPORT void
xfont2_empty_font_pattern_cache(xfont2_pattern_cache_ptr cache);
_X_EXPORT void
xfont2_cache_font_pattern(xfont2_pattern_cache_ptr cache,
const char * pattern,
int patlen,
FontPtr pFont);
_X_EXPORT FontPtr
xfont2_find_cached_font_pattern(xfont2_pattern_cache_ptr cache,
const char * pattern,
int patlen);
_X_EXPORT void
xfont2_remove_cached_font_pattern(xfont2_pattern_cache_ptr cache,
FontPtr pFont);
/* private.c */
_X_EXPORT int
xfont2_allocate_font_private_index (void);
static inline void *
xfont2_font_get_private(FontPtr pFont, int n)
{
if (n > pFont->maxPrivate)
return NULL;
return pFont->devPrivates[n];
}
_X_EXPORT Bool
xfont2_font_set_private(FontPtr pFont, int n, void *ptr);
#endif /* _LIBXFONT2_H_ */
/*
* Copyright © 2015 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#ifndef _LIBXFONTINT_H_
#define _LIBXFONTINT_H_
#include <X11/fonts/FSproto.h>
#define client_auth_generation __libxfont__client_auth_generation
#define ClientSignal __libxfont__ClientSignal
#define DeleteFontClientID __libxfont__DeleteFontClientID
#define ErrorF __libxfont__ErrorF
#define find_old_font __libxfont__find_old_font
#define GetClientResolutions __libxfont__GetClientResolutions
#define GetDefaultPointSize __libxfont__GetDefaultPointSize
#define GetNewFontClientID __libxfont__GetNewFontClientID
#define GetTimeInMillis __libxfont__GetTimeInMillis
#define init_fs_handlers __libxfont__init_fs_handlers
#define remove_fs_handlers __libxfont__remove_fs_handlers
#define __GetServerClient __libxfont____GetServerClient
#define set_font_authorizations __libxfont__set_font_authorizations
#define StoreFontClientFont __libxfont__StoreFontClientFont
#define MakeAtom __libxfont__MakeAtom
#define ValidAtom __libxfont__ValidAtom
#define NameForAtom __libxfont__NameForAtom
#define add_fs_fd __libxfont_add_fs_fd
#define remove_fs_fd __libxfont_remove_fs_fd
#define adjust_fs_wait_for_delay __libxfont_adjust_fs_wait_for_delay
#include <X11/fonts/FS.h>
#include <X11/fonts/FSproto.h>
#include <X11/X.h>
#include <X11/Xos.h>
#include <X11/fonts/fontmisc.h>
#include <X11/fonts/fontstruct.h>
#include <X11/fonts/fontutil.h>
#include <X11/fonts/fontproto.h>
#include <errno.h>
#include <limits.h>
#include <stdint.h>
#include <X11/fonts/libxfont2.h>
#ifndef LIBXFONT_SKIP_ERRORF
void
ErrorF(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2);
#endif
FontPtr
find_old_font(FSID id);
unsigned long
GetTimeInMillis (void);
int
register_fpe_funcs(const xfont2_fpe_funcs_rec *funcs);
void *
__GetServerClient(void);
int
set_font_authorizations(char **authorizations, int *authlen, ClientPtr client);
unsigned long
__GetServerGeneration (void);
int add_fs_fd(int fd, FontFdHandlerProcPtr handler, void *data);
void remove_fs_fd(int fd);
void adjust_fs_wait_for_delay(void *wt, unsigned long newdelay);
int
init_fs_handlers2(FontPathElementPtr fpe,
FontBlockHandlerProcPtr block_handler);
void
remove_fs_handlers2(FontPathElementPtr fpe,
FontBlockHandlerProcPtr blockHandler,
Bool all);
Atom
__libxfont_internal__MakeAtom(const char *string, unsigned len, int makeit);
int
__libxfont_internal__ValidAtom(Atom atom);
const char *
__libxfont_internal__NameForAtom(Atom atom);
int
CheckFSFormat(fsBitmapFormat format,
fsBitmapFormatMask fmask,
int *bit_order,
int *byte_order,
int *scan,
int *glyph,
int *image);
int
FontCouldBeTerminal(FontInfoPtr);
void
FontComputeInfoAccelerators(FontInfoPtr);
int
add_range (fsRange *newrange, int *nranges, fsRange **range,
Bool charset_subset);
#endif /* _LIBXFONTINT_H_ */
......@@ -82,6 +82,4 @@ unsigned FTRemap(FT_Face face, FTMappingPtr, unsigned code);
int FTtoXReturnCode(int);
int FTGetEnglishName(FT_Face, int, char *, int);
extern void ErrorF(const char*, ...);
#endif /* _FT_H_ */
......@@ -23,6 +23,7 @@ THE SOFTWARE.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <string.h>
#include <X11/fonts/fntfilst.h>
......
......@@ -29,6 +29,7 @@ THE SOFTWARE.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <X11/fonts/fontmisc.h>
#include <string.h>
......
......@@ -24,6 +24,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <X11/fonts/fontmisc.h>
#include <ctype.h>
#include <string.h>
......
......@@ -41,6 +41,7 @@ static char const * const releaseID =
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <X11/fonts/fontmisc.h>
#include <string.h>
#include <ctype.h>
......
......@@ -19,7 +19,7 @@
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
lib_LTLIBRARIES = libXfont.la
lib_LTLIBRARIES = libXfont2.la
AM_CFLAGS = $(OS_CFLAGS) $(CWARNFLAGS)
......@@ -58,11 +58,11 @@ SUBDIRS=\
$(FONTFILE_DIR) $(FREETYPE_DIR) $(BITMAP_DIR) \
$(BUILTINS_DIR) $(FC_DIR) $(UTIL_DIR) $(STUBS_DIR)
libXfont_la_LIBADD = \
libXfont2_la_LIBADD = \
$(FONTFILE_LIB) $(FREETYPE_LIB) $(BITMAP_LIB) \
$(BUILTINS_LIB) $(FC_LIB) $(UTIL_LIB) $(STUBS_LIB) \
$(FREETYPE_LIBS) $(Z_LIBS) $(MATH_LIBS) $(XFONT_LIBS)
libXfont_la_SOURCES = dummy.c
libXfont2_la_SOURCES = dummy.c
libXfont_la_LDFLAGS = -version-number 1:4:1 -no-undefined
libXfont2_la_LDFLAGS = -version-number 2:0:0 -no-undefined
......@@ -52,6 +52,7 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <ctype.h>
#include <X11/fonts/fntfilst.h>
......
......@@ -52,6 +52,7 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <ctype.h>
#include <stdio.h>
......
......@@ -31,6 +31,7 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <X11/fonts/fntfilst.h>
#include <X11/fonts/bitmap.h>
......
......@@ -31,6 +31,7 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <X11/fonts/fntfilst.h>
#include <X11/fonts/bitmap.h>
......
......@@ -29,6 +29,7 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <X11/fonts/fntfilst.h>
#include <X11/fonts/bitmap.h>
......
......@@ -33,6 +33,7 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <X11/fonts/fntfilst.h>
#include <X11/fonts/bitmap.h>
......@@ -43,9 +44,6 @@ from The Open Group.
#define MAX(a,b) (((a)>(b)) ? a : b)
#endif
/* Should get this from elsewhere */
extern unsigned long __GetServerGeneration(void);
static void bitmapUnloadScalable (FontPtr pFont);
static void ScaleBitmap ( FontPtr pFont, CharInfoPtr opci,
CharInfoPtr pci, double *inv_xform,
......
......@@ -33,6 +33,7 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <X11/fonts/fntfilst.h>
#include <X11/fonts/bitmap.h>
......
......@@ -33,6 +33,7 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <X11/fonts/fntfilst.h>
#include <X11/fonts/bitmap.h>
......
......@@ -33,6 +33,7 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <X11/fonts/fntfilst.h>
#include <X11/fonts/bitmap.h>
......@@ -43,7 +44,7 @@ from The Open Group.
static CARD32 current_position;
static int
pcfWrite(FontFilePtr file, char *b, int c)
pcfWrite(FontFilePtr file, const char *b, int c)
{
current_position += c;
return FontFileWrite(file, b, c);
......@@ -189,7 +190,7 @@ pcfPutAccel(FontFilePtr file, CARD32 format, FontInfoPtr pFontInfo)
#define CanCompressMetrics(min,max) (CanCompressMetric(min) && CanCompressMetric(max))
static char *
static const char *
pcfNameForAtom(Atom a)
{
return NameForAtom(a);
......@@ -218,7 +219,7 @@ pcfWriteFont(FontPtr pFont, FontFilePtr file)
int header_size;
FontPropPtr offsetProps;
int prop_pad = 0;
char *atom_name;
const char *atom_name;
int glyph;
CARD32 offset;
......
......@@ -52,6 +52,7 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <ctype.h>
#include <X11/fonts/fntfilst.h>
......
......@@ -24,6 +24,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include "builtin.h"
static BuiltinDirPtr
......
......@@ -24,6 +24,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <string.h>
#include "builtin.h"
......
......@@ -24,6 +24,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include "builtin.h"
static const char file_cursor[] = {
......
......@@ -24,6 +24,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "libxfontint.h"
#include <X11/fonts/fntfilst.h>
#include "builtin.h"
......@@ -65,24 +66,29 @@ BuiltinFreeFPE (FontPathElementPtr fpe)
return Successful;
}
static const xfont2_fpe_funcs_rec builtin_fpe_funcs = {
.version = XFONT2_FPE_FUNCS_VERSION,
.name_check = BuiltinNameCheck,
.init_fpe = BuiltinInitFPE,
.free_fpe = BuiltinFreeFPE,
.reset_fpe = BuiltinResetFPE,
.open_font = FontFileOpenFont,
.close_font = FontFileCloseFont,
.list_fonts = FontFileListFonts,
.start_list_fonts_with_info = FontFileStartListFontsWithInfo,
.list_next_font_with_info = FontFileListNextFontWithInfo,
.wakeup_fpe = 0,
.client_died = 0,
.load_glyphs = 0,
.start_list_fonts_and_aliases = 0,
.list_next_font_or_alias = 0,
.set_path_hook = 0
};
void
BuiltinRegisterFpeFunctions(void)
{
BuiltinRegisterFontFileFunctions ();
font_file_type = RegisterFPEFunctions(BuiltinNameCheck,
BuiltinInitFPE,
BuiltinFreeFPE,
BuiltinResetFPE,
FontFileOpenFont,
FontFileCloseFont,
FontFileListFonts,
FontFileStartListFontsWithInfo,
FontFileListNextFontWithInfo,
(WakeupFpeFunc) 0,
(ClientDiedFunc) 0,
(LoadGlyphsFunc) 0,