Support compiling without fontconfig

Adds a new, fake, fontconfig font backend.  Fontconfig can be disabled
using --disable-fc, in which case the toy text API wont find fonts and
the internal font will always be used.

Also defines the feature macro CAIRO_HAS_FC_FONT.  The two fontconfig-specific
functions in cairo-ft.h depend on that macro now.
This commit is contained in:
Behdad Esfahbod 2009-03-17 00:53:30 -04:00
parent 0e7bcb5e37
commit 3ec94f9b59
16 changed files with 125 additions and 45 deletions

View file

@ -169,6 +169,16 @@ enabled_cairo_boilerplate_private += $(cairo_boilerplate_ft_private)
enabled_cairo_boilerplate_sources += $(cairo_boilerplate_ft_sources)
endif
supported_cairo_boilerplate_headers += $(cairo_boilerplate_fc_headers)
all_cairo_boilerplate_headers += $(cairo_boilerplate_fc_headers)
all_cairo_boilerplate_private += $(cairo_boilerplate_fc_private)
all_cairo_boilerplate_sources += $(cairo_boilerplate_fc_sources)
ifeq ($(CAIRO_HAS_FC_FONT),1)
enabled_cairo_boilerplate_headers += $(cairo_boilerplate_fc_headers)
enabled_cairo_boilerplate_private += $(cairo_boilerplate_fc_private)
enabled_cairo_boilerplate_sources += $(cairo_boilerplate_fc_sources)
endif
supported_cairo_boilerplate_headers += $(cairo_boilerplate_ps_headers)
all_cairo_boilerplate_headers += $(cairo_boilerplate_ps_headers)
all_cairo_boilerplate_private += $(cairo_boilerplate_ps_private)

View file

@ -15,6 +15,7 @@ CAIRO_HAS_GLITZ_SURFACE=0
CAIRO_HAS_DIRECTFB_SURFACE=0
CAIRO_HAS_SCRIPT_SURFACE=0
CAIRO_HAS_FT_FONT=0
CAIRO_HAS_FC_FONT=0
CAIRO_HAS_PS_SURFACE=1
CAIRO_HAS_PDF_SURFACE=1
CAIRO_HAS_SVG_SURFACE=1

View file

@ -50,6 +50,9 @@ endif
ifeq ($(CAIRO_HAS_FT_FONT),1)
@echo "#define CAIRO_HAS_FT_FONT 1" >> src/cairo-features.h
endif
ifeq ($(CAIRO_HAS_FC_FONT),1)
@echo "#define CAIRO_HAS_FC_FONT 1" >> src/cairo-features.h
endif
ifeq ($(CAIRO_HAS_PS_SURFACE),1)
@echo "#define CAIRO_HAS_PS_SURFACE 1" >> src/cairo-features.h
endif

View file

@ -379,6 +379,7 @@ AC_DEFUN([CAIRO_REPORT],
echo "The following font backends:"
echo " User: yes (always builtin)"
echo " FreeType: $use_ft"
echo " Fontconfig: $use_fc"
echo " Win32: $use_win32_font"
echo " Quartz: $use_quartz_font"
echo ""

View file

@ -259,13 +259,6 @@ FREETYPE_MIN_RELEASE=2.1.9
FREETYPE_MIN_VERSION=9.7.3
CAIRO_ENABLE_FONT_BACKEND(ft, FreeType, auto, [
ft_REQUIRES="fontconfig"
PKG_CHECK_MODULES(FONTCONFIG, $ft_REQUIRES,,
[AC_MSG_RESULT(no); use_ft="no (requires $ft_REQUIRES)"])
if test "x$use_ft" = "xyes"; then
CAIRO_CHECK_FUNCS_WITH_FLAGS(FcFini, [$FONTCONFIG_CFLAGS], [$FONTCONFIG_LIBS])
PKG_CHECK_MODULES(FREETYPE, freetype2 >= $FREETYPE_MIN_VERSION,
[freetype_pkgconfig=yes],
@ -293,9 +286,20 @@ CAIRO_ENABLE_FONT_BACKEND(ft, FreeType, auto, [
use_ft="no ($FREETYPE_VERSION found; version $FREETYPE_MIN_VERSION from release $FREETYPE_MIN_RELEASE required)"])
fi
fi
ft_CFLAGS="$FREETYPE_CFLAGS"
ft_LIBS="$FREETYPE_LIBS"
])
CAIRO_ENABLE_FONT_BACKEND(fc, Fontconfig, auto, [
use_fc=$use_ft
if test "x$use_fc" = "xyes"; then
fc_REQUIRES="fontconfig"
PKG_CHECK_MODULES(FONTCONFIG, $fc_REQUIRES,,
[AC_MSG_RESULT(no); use_fc="no (requires $fc_REQUIRES)"])
fi
ft_CFLAGS="$FREETYPE_CFLAGS $FONTCONFIG_CFLAGS"
ft_LIBS="$FREETYPE_LIBS $FONTCONFIG_LIBS"
fc_CFLAGS="$FONTCONFIG_CFLAGS"
fc_LIBS="$FONTCONFIG_LIBS"
])
if test "x$use_ft" = "xyes"; then
@ -317,6 +321,10 @@ if test "x$use_ft" = "xyes"; then
CFLAGS="$_save_cflags"
fi
if test "x$use_fc" = "xyes"; then
CAIRO_CHECK_FUNCS_WITH_FLAGS(FcFini, [$FONTCONFIG_CFLAGS], [$FONTCONFIG_LIBS])
fi
dnl ===========================================================================
AC_ARG_ENABLE(pthread,

View file

@ -2,6 +2,7 @@
<FILE>cairo-ft</FILE>
<TITLE>ft-font</TITLE>
CAIRO_HAS_FT_FONT
CAIRO_HAS_FC_FONT
cairo_ft_font_face_create_for_ft_face
cairo_ft_font_face_create_for_pattern
cairo_ft_font_options_substitute

View file

@ -28,6 +28,15 @@ This macro can be used to conditionally compile backend-specific code.
<!-- ##### MACRO CAIRO_HAS_FC_FONT ##### -->
<para>
Defined if the Fontconfig-specific functions of the FreeType font backend
are available.
This macro can be used to conditionally compile backend-specific code.
</para>
<!-- ##### FUNCTION cairo_ft_font_face_create_for_ft_face ##### -->
<para>

View file

@ -70,7 +70,7 @@ code is required before or after each individual cairo function call.
@CAIRO_STATUS_INVALID_CLUSTERS:
@CAIRO_STATUS_INVALID_SLANT:
@CAIRO_STATUS_INVALID_WEIGHT:
@CAIRO_STATUS_INVALID_SIZE:
@CAIRO_STATUS_INVALID_SIZE:
<!-- ##### FUNCTION cairo_status_to_string ##### -->
<para>

View file

@ -231,6 +231,20 @@ ifeq ($(CAIRO_HAS_FT_FONT),1)
enabled_cairo_pkgconf += cairo-ft.pc
endif
supported_cairo_headers += $(cairo_fc_headers)
all_cairo_headers += $(cairo_fc_headers)
all_cairo_private += $(cairo_fc_private)
all_cairo_sources += $(cairo_fc_sources)
ifeq ($(CAIRO_HAS_FC_FONT),1)
enabled_cairo_headers += $(cairo_fc_headers)
enabled_cairo_private += $(cairo_fc_private)
enabled_cairo_sources += $(cairo_fc_sources)
endif
all_cairo_pkgconf += cairo-fc.pc
ifeq ($(CAIRO_HAS_FC_FONT),1)
enabled_cairo_pkgconf += cairo-fc.pc
endif
supported_cairo_headers += $(cairo_ps_headers)
all_cairo_headers += $(cairo_ps_headers)
all_cairo_private += $(cairo_ps_private)

View file

@ -45,8 +45,10 @@
#include <float.h>
#if CAIRO_HAS_FC_FONT
#include <fontconfig/fontconfig.h>
#include <fontconfig/fcfreetype.h>
#endif
#include <ft2build.h>
#include FT_FREETYPE_H
@ -117,10 +119,6 @@ _cairo_ft_unscaled_font_keys_equal (const void *key_a,
static void
_cairo_ft_unscaled_font_fini (cairo_ft_unscaled_font_t *unscaled);
static cairo_status_t
_cairo_ft_font_options_substitute (const cairo_font_options_t *options,
FcPattern *pattern);
typedef enum _cairo_ft_extra_flags {
CAIRO_FT_OPTIONS_HINT_METRICS = (1 << 0),
CAIRO_FT_OPTIONS_EMBOLDEN = (1 << 1)
@ -139,11 +137,18 @@ struct _cairo_ft_font_face {
cairo_ft_options_t ft_options;
cairo_ft_font_face_t *next;
#if CAIRO_HAS_FC_FONT
FcPattern *pattern; /* if pattern is set, the above fields will be NULL */
#endif
};
static const cairo_unscaled_font_backend_t cairo_ft_unscaled_font_backend;
#if CAIRO_HAS_FC_FONT
static cairo_status_t
_cairo_ft_font_options_substitute (const cairo_font_options_t *options,
FcPattern *pattern);
static cairo_status_t
_cairo_ft_resolve_pattern (FcPattern *pattern,
const cairo_matrix_t *font_matrix,
@ -152,6 +157,7 @@ _cairo_ft_resolve_pattern (FcPattern *pattern,
cairo_ft_unscaled_font_t **unscaled,
cairo_ft_options_t *ft_options);
#endif
/*
* We maintain a hash table to map file/id => #cairo_ft_unscaled_font_t.
@ -465,6 +471,7 @@ UNWIND:
}
#if CAIRO_HAS_FC_FONT
static cairo_ft_unscaled_font_t *
_cairo_ft_unscaled_font_create_for_pattern (FcPattern *pattern)
{
@ -486,6 +493,7 @@ _cairo_ft_unscaled_font_create_for_pattern (FcPattern *pattern)
DONE:
return _cairo_ft_unscaled_font_create_internal (font_face != NULL, filename, id, font_face);
}
#endif
static cairo_ft_unscaled_font_t *
_cairo_ft_unscaled_font_create_from_face (FT_Face face)
@ -1291,6 +1299,7 @@ typedef struct _cairo_ft_scaled_font {
static const cairo_scaled_font_backend_t _cairo_ft_scaled_font_backend;
#if CAIRO_HAS_FC_FONT
/* The load flags passed to FT_Load_Glyph control aspects like hinting and
* antialiasing. Here we compute them from the fields of a FcPattern.
*/
@ -1426,6 +1435,7 @@ _get_pattern_ft_options (FcPattern *pattern, cairo_ft_options_t *ret)
*ret = ft_options;
}
#endif
static void
_cairo_ft_options_merge (cairo_ft_options_t *options,
@ -2044,9 +2054,11 @@ _cairo_ft_ucs4_to_index (void *abstract_font,
if (!face)
return 0;
/* If making this compile without fontconfig, use:
* index = FT_Get_Char_Index (face, ucs4); */
#if CAIRO_HAS_FC_FONT
index = FcFreeTypeCharIndex (face, ucs4);
#else
index = FT_Get_Char_Index (face, ucs4);
#endif
_cairo_ft_unscaled_font_unlock_face (unscaled);
return index;
@ -2125,6 +2137,7 @@ static const cairo_scaled_font_backend_t _cairo_ft_scaled_font_backend = {
/* #cairo_ft_font_face_t */
#if CAIRO_HAS_FC_FONT
static cairo_status_t
_cairo_ft_font_face_create_for_pattern (FcPattern *pattern,
cairo_font_face_t **out);
@ -2191,6 +2204,7 @@ _cairo_ft_font_face_create_for_toy (cairo_toy_font_face_t *toy_face,
return status;
}
#endif
static void
_cairo_ft_font_face_destroy (void *abstract_face)
@ -2249,8 +2263,10 @@ _cairo_ft_font_face_destroy (void *abstract_face)
font_face->unscaled = NULL;
}
#if CAIRO_HAS_FC_FONT
if (font_face->pattern)
FcPatternDestroy (font_face->pattern);
#endif
}
static cairo_status_t
@ -2274,6 +2290,7 @@ _cairo_ft_font_face_scaled_font_create (void *abstract_face,
* flags and ignore the options.
*/
#if CAIRO_HAS_FC_FONT
/* If we have an unresolved pattern, resolve it and create
* unscaled font. Otherwise, use the ones stored in font_face.
*/
@ -2295,7 +2312,9 @@ _cairo_ft_font_face_scaled_font_create (void *abstract_face,
return CAIRO_STATUS_SUCCESS;
}
} else {
} else
#endif
{
unscaled = font_face->unscaled;
ft_options = font_face->ft_options;
}
@ -2309,11 +2328,16 @@ _cairo_ft_font_face_scaled_font_create (void *abstract_face,
const cairo_font_face_backend_t _cairo_ft_font_face_backend = {
CAIRO_FONT_TYPE_FT,
#if CAIRO_HAS_FC_FONT
_cairo_ft_font_face_create_for_toy,
#else
NULL,
#endif
_cairo_ft_font_face_destroy,
_cairo_ft_font_face_scaled_font_create
};
#if CAIRO_HAS_FC_FONT
static cairo_status_t
_cairo_ft_font_face_create_for_pattern (FcPattern *pattern,
cairo_font_face_t **out)
@ -2338,6 +2362,7 @@ _cairo_ft_font_face_create_for_pattern (FcPattern *pattern,
*out = &font_face->base;
return CAIRO_STATUS_SUCCESS;
}
#endif
static cairo_font_face_t *
_cairo_ft_font_face_create (cairo_ft_unscaled_font_t *unscaled,
@ -2378,7 +2403,9 @@ _cairo_ft_font_face_create (cairo_ft_unscaled_font_t *unscaled,
font_face->next = unscaled->faces;
unscaled->faces = font_face;
#if CAIRO_HAS_FC_FONT
font_face->pattern = NULL;
#endif
_cairo_font_face_init (&font_face->base, &_cairo_ft_font_face_backend);
@ -2387,6 +2414,7 @@ _cairo_ft_font_face_create (cairo_ft_unscaled_font_t *unscaled,
/* implement the platform-specific interface */
#if CAIRO_HAS_FC_FONT
static cairo_status_t
_cairo_ft_font_options_substitute (const cairo_font_options_t *options,
FcPattern *pattern)
@ -2633,6 +2661,7 @@ cairo_ft_font_face_create_for_pattern (FcPattern *pattern)
return font_face;
}
#endif
/**
* cairo_ft_font_face_create_for_ft_face:

View file

@ -43,19 +43,15 @@
/* Fontconfig/Freetype platform-specific font interface */
#include <fontconfig/fontconfig.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#if CAIRO_HAS_FC_FONT
#include <fontconfig/fontconfig.h>
#endif
CAIRO_BEGIN_DECLS
cairo_public cairo_font_face_t *
cairo_ft_font_face_create_for_pattern (FcPattern *pattern);
cairo_public void
cairo_ft_font_options_substitute (const cairo_font_options_t *options,
FcPattern *pattern);
cairo_public cairo_font_face_t *
cairo_ft_font_face_create_for_ft_face (FT_Face face,
int load_flags);
@ -66,6 +62,17 @@ cairo_ft_scaled_font_lock_face (cairo_scaled_font_t *scaled_font);
cairo_public void
cairo_ft_scaled_font_unlock_face (cairo_scaled_font_t *scaled_font);
#if CAIRO_HAS_FC_FONT
cairo_public cairo_font_face_t *
cairo_ft_font_face_create_for_pattern (FcPattern *pattern);
cairo_public void
cairo_ft_font_options_substitute (const cairo_font_options_t *options,
FcPattern *pattern);
#endif
CAIRO_END_DECLS
#else /* CAIRO_HAS_FT_FONT */

View file

@ -39,7 +39,9 @@
#include "cairo-os2-private.h"
#if CAIRO_HAS_FC_FONT
#include <fontconfig/fontconfig.h>
#endif
#include <float.h>
#ifdef BUILD_CAIRO_DLL
@ -101,7 +103,7 @@ cairo_os2_init (void)
DisableFPUException ();
#if CAIRO_HAS_FT_FONT
#if CAIRO_HAS_FC_FONT
/* Initialize FontConfig */
FcInit ();
#endif
@ -132,7 +134,7 @@ cairo_os2_fini (void)
cairo_debug_reset_static_data ();
#if CAIRO_HAS_FT_FONT
#if CAIRO_HAS_FC_FONT
# if HAVE_FCFINI
/* Uninitialize FontConfig */
FcFini ();

View file

@ -1240,7 +1240,7 @@ _cprt_move_to (void *closure,
return CAIRO_INT_STATUS_UNSUPPORTED;
}
/**
/*
* Check whether the given path is representable as a region.
* That is, if the path contains only axis aligned lines between
* integer coordinates in device space.

View file

@ -2719,8 +2719,8 @@ slim_hidden_def (cairo_scaled_font_get_font_matrix);
*
* Stores the CTM with which @scaled_font was created into @ctm.
* Note that the translation offsets (x0, y0) of the CTM are ignored
* by cairo_scaled_font_create(). So, the matrix this function
* returns always has 0,0 as x0,y0.
* by cairo_scaled_font_create(). So, the matrix this
* function returns always has 0,0 as x0,y0.
*
* Since: 1.2
**/

View file

@ -38,8 +38,6 @@
#include "cairo-xlib-private.h"
#include "cairo-xlib-xrender-private.h"
#include <fontconfig/fontconfig.h>
#include <X11/Xlibint.h> /* For XESetCloseDisplay */
typedef int (*cairo_xlib_error_func_t) (Display *display,

View file

@ -112,7 +112,7 @@ get_integer_default (Display *dpy,
v = XGetDefault (dpy, "Xft", option);
if (v) {
#if CAIRO_HAS_FT_FONT
#if CAIRO_HAS_FC_FONT
if (FcNameConstant ((FcChar8 *) v, value))
return TRUE;
#endif
@ -125,7 +125,15 @@ get_integer_default (Display *dpy,
return FALSE;
}
/* Old versions of fontconfig didn't have these options */
#ifndef FC_RGBA_UNKNOWN
#define FC_RGBA_UNKNOWN 0
#define FC_RGBA_RGB 1
#define FC_RGBA_BGR 2
#define FC_RGBA_VRGB 3
#define FC_RGBA_VBGR 4
#define FC_RGBA_NONE 5
#endif
#ifndef FC_HINT_NONE
#define FC_HINT_NONE 0
#define FC_HINT_SLIGHT 1
@ -133,17 +141,6 @@ get_integer_default (Display *dpy,
#define FC_HINT_FULL 3
#endif
/* Fontconfig version older than 2.6 didn't have these options */
#ifndef FC_LCD_FILTER
#define FC_LCD_FILTER "lcdfilter"
#endif
/* Some Ubuntu versions defined FC_LCD_FILTER without defining the following */
#ifndef FC_LCD_NONE
#define FC_LCD_NONE 0
#define FC_LCD_DEFAULT 1
#define FC_LCD_LIGHT 2
#define FC_LCD_LEGACY 3
#endif
static void
_cairo_xlib_init_screen_font_options (Display *dpy,