Initial revision
This commit is contained in:
commit
24330d27f8
|
@ -0,0 +1,22 @@
|
|||
$XFree86: $
|
||||
|
||||
Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
|
||||
|
||||
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 Keith Packard not be used in
|
||||
advertising or publicity pertaining to distribution of the software without
|
||||
specific, written prior permission. Keith Packard makes no
|
||||
representations about the suitability of this software for any purpose. It
|
||||
is provided "as is" without express or implied warranty.
|
||||
|
||||
KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
EVENT SHALL KEITH PACKARD 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.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
The configuration files (fonts.conf, fonts.dtd) go in a new directory
|
||||
/etc/fonts, the install step doesn't current create this directory or copy
|
||||
the config files.
|
|
@ -0,0 +1,25 @@
|
|||
#define IHaveSubdirs
|
||||
#define PassCDebugFlags
|
||||
|
||||
LINTSUBDIRS=src fc-cache fc-list
|
||||
|
||||
SUBDIRS=fontconfig $(LINTSUBDIRS)
|
||||
|
||||
#ifndef FontconfigDir
|
||||
#define FontconfigDir /etc/fonts
|
||||
#endif
|
||||
|
||||
FONTCONFIGDIR=FontconfigDir
|
||||
|
||||
MakeSubdirs($(SUBDIRS))
|
||||
DependSubdirs($(SUBDIRS))
|
||||
MakeLintLibSubdirs($(LINTSUBDIRS))
|
||||
MakeLintSubdirs($(LINTSUBDIRS),install.ln,install.ln)
|
||||
|
||||
InstallNonExecFileNoClobber(fonts.conf,$(FONTCONFIGDIR))
|
||||
InstallNonExecFileNoClobber(fonts.dtd,$(FONTCONFIGDIR))
|
||||
|
||||
all:: fonts.conf
|
||||
|
||||
fonts.conf: fonts.conf.in
|
||||
sh ./setfontdirs
|
|
@ -0,0 +1,2 @@
|
|||
Fontconfig
|
||||
Font configuration and customization library
|
|
@ -0,0 +1,2 @@
|
|||
#undef HAVE_FREETYPE
|
||||
#undef FC_FALLBACK_FONTS
|
|
@ -0,0 +1,202 @@
|
|||
AC_INIT(fontconfig/fontconfig.h)
|
||||
|
||||
AC_PREREQ(2.13)
|
||||
|
||||
FC_MAJOR=1
|
||||
FC_MINOR=0
|
||||
FC_SUB=1
|
||||
FC_PRE=
|
||||
FC_IFACE_AGE=0
|
||||
FC_BIN_AGE=0
|
||||
|
||||
AC_SUBST(FC_MAJOR)
|
||||
AC_SUBST(FC_MINOR)
|
||||
AC_SUBST(FC_SUB)
|
||||
AC_SUBST(FC_IFACE_AGE)
|
||||
AC_SUBST(FC_BIN_AGE)
|
||||
|
||||
LT_RELEASE=$FC_MAJOR.$FC_MINOR
|
||||
LT_CURRENT=`expr $FC_SUB - $FC_IFACE_AGE`
|
||||
LT_REVISION=$FC_IFACE_AGE
|
||||
LT_AGE=`expr $FC_BIN_AGE - $FC_IFACE_AGE`
|
||||
AC_SUBST(LT_RELEASE)
|
||||
AC_SUBST(LT_CURRENT)
|
||||
AC_SUBST(LT_REVISION)
|
||||
AC_SUBST(LT_AGE)
|
||||
|
||||
AM_INIT_AUTOMAKE("fontconfig", $FC_MAJOR.$FC_MINOR.$FC_SUB$FC_PRE)
|
||||
|
||||
AC_CANONICAL_HOST
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
|
||||
AC_ARG_WITH(freetype_includes, [ --with-freetype-includes=DIR Use FreeType includes in DIR], freetype_includes=$withval, freetype_includes=yes)
|
||||
AC_ARG_WITH(freetype_lib, [ --with-freetype-lib=DIR Use FreeType library in DIR], freetype_lib=$withval, freetype_lib=yes)
|
||||
AC_ARG_WITH(freetype_config, [ --with-freeetype-config=PROG Use FreeType configuration program PROG], freetype_config=$withval, freetype_config=yes)
|
||||
AC_ARG_WITH(xml2_includes, [ --with-xml2-includes=DIR Use xml2 includes in DIR], xml2_includes=$withval, xml2_includes=yes)
|
||||
AC_ARG_WITH(xml2_lib, [ --with-xml2-lib=DIR Use xml2 library in DIR], xml2_lib=$withval, xml2_lib=yes)
|
||||
AC_ARG_WITH(xml2_config, [ --with-freeetype-config=PROG Use FreeType configuration program PROG], xml2_config=$withval, xml2_config=yes)
|
||||
AC_ARG_WITH(fallback_fonts, [ --with-fallback-fonts=DIR Use fonts from DIR when config is busted], fallback_fonts="$withval", fallback_fonts=yes)
|
||||
AC_ISC_POSIX
|
||||
AC_PROG_CC
|
||||
AC_STDC_HEADERS
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_INSTALL
|
||||
|
||||
AC_PROG_LN_S
|
||||
|
||||
dnl
|
||||
dnl Libtool
|
||||
dnl
|
||||
AM_DISABLE_STATIC
|
||||
AM_PROG_LIBTOOL
|
||||
AC_SUBST(LIBTOOL_DEPS)
|
||||
if libtool --features | grep "enable static" >/dev/null; then
|
||||
STATIC="-static"
|
||||
else
|
||||
STATIC=
|
||||
fi
|
||||
AC_SUBST(STATIC)
|
||||
|
||||
AC_SUBST(DEBUG_CFLAGS)
|
||||
AC_SUBST(GLOBAL_CFLAGS)
|
||||
|
||||
AC_CHECK_FUNCS(getopt_long getopt)
|
||||
|
||||
case "$freetype_config" in
|
||||
no)
|
||||
;;
|
||||
yes)
|
||||
AC_CHECK_PROG(ft_config, freetype-config, freetype-config, no)
|
||||
;;
|
||||
*)
|
||||
ft_config="$freetype_config"
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$freetype_includes" in
|
||||
no)
|
||||
freetype_includes=""
|
||||
;;
|
||||
yes)
|
||||
case "$ft_config" in
|
||||
no)
|
||||
freetype_includes=""
|
||||
;;
|
||||
*)
|
||||
freetype_includes="`$ft_config --cflags`"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
freetype_includes="-I$freetype_includes"
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$freetype_lib" in
|
||||
no)
|
||||
freetype_lib=""
|
||||
;;
|
||||
yes)
|
||||
case "$ft_config" in
|
||||
no)
|
||||
freetype_lib=""
|
||||
;;
|
||||
*)
|
||||
freetype_lib="`$ft_config --libs`"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
freetype_lib="-L$freetype_lib -lfreetype"
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$fallback_fonts" in
|
||||
yes)
|
||||
AC_DEFINE_UNQUOTED(FC_FALLBACK_FONTS, "/usr/X11R6/lib/X11/fonts/Type1")
|
||||
;;
|
||||
*)
|
||||
AC_DEFINE_UNQUOTED(FC_FALLBACK_FONTS, "$fallback_fonts")
|
||||
;;
|
||||
esac
|
||||
|
||||
saved_LIBS="$LIBS"
|
||||
LIBS="$LIBS $freetype_lib"
|
||||
saved_CPPFLAGS="$CPPFLAGS"
|
||||
CPPFLAGS="$CPPFLAGS $freetype_includes"
|
||||
AC_CHECK_HEADERS(ft2build.h)
|
||||
|
||||
case "$ac_cv_header_ft2build_h" in
|
||||
no)
|
||||
CPPFLAGS="$saved_CPPFLAGS"
|
||||
LIBS="$saved_LIBS"
|
||||
;;
|
||||
yes)
|
||||
AC_CHECK_FUNCS(FT_Init_FreeType)
|
||||
case "$ac_cv_func_FT_Init_FreeType" in
|
||||
no)
|
||||
CPPFLAGS="$saved_CPPFLAGS"
|
||||
LIBS="$saved_LIBS"
|
||||
;;
|
||||
yes)
|
||||
AC_DEFINE(HAVE_FREETYPE)
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$xml2_config" in
|
||||
no)
|
||||
;;
|
||||
yes)
|
||||
AC_CHECK_PROG(xml2_config_prog, xml2-config, xml2-config, no)
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$xml2_includes" in
|
||||
no)
|
||||
xml2_includes=""
|
||||
;;
|
||||
yes)
|
||||
case "$xml2_config_prog" in
|
||||
no)
|
||||
xml2_includes=""
|
||||
;;
|
||||
*)
|
||||
xml2_includes="`$xml2_config_prog --cflags`"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
xml2_includes="-I$xml2_includes"
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$xml2_lib" in
|
||||
no)
|
||||
xml2_lib=""
|
||||
;;
|
||||
yes)
|
||||
case "$xml2_config_prog" in
|
||||
no)
|
||||
xml2_lib=""
|
||||
;;
|
||||
*)
|
||||
xml2_lib="`$xml2_config_prog --libs`"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
xml2_lib="-L$xml2_lib -lxml2"
|
||||
;;
|
||||
esac
|
||||
|
||||
saved_LIBS="$LIBS"
|
||||
LIBS="$LIBS $xml2_lib"
|
||||
saved_CPPFLAGS="$CPPFLAGS"
|
||||
CPPFLAGS="$CPPFLAGS $xml2_includes"
|
||||
AC_CHECK_HEADERS(xmlversion.h)
|
||||
|
||||
AC_OUTPUT(Makefile src/Makefile fontconfig/Makefile fc-cache/Makefile fc-list/Makefile)
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
aclocal
|
||||
autoheader
|
||||
automake -a
|
||||
autoconf
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
\documentclass[10pt]{article}
|
||||
\usepackage{latexsym}
|
||||
\usepackage{epsfig}
|
||||
\usepackage{times}
|
||||
|
||||
\begin{document}
|
||||
\date{}
|
||||
\title{The Fontconfig Library:\\
|
||||
Architecture and Users Guide}
|
||||
\author{Keith Packard\\
|
||||
{\em XFree86 Core Team}\\
|
||||
keithp@keithp.com}
|
||||
\maketitle
|
||||
\thispagestyle{empty}
|
||||
|
||||
\abstract
|
||||
|
||||
The Fontconfig library provides for central administration and configuration
|
||||
of fonts in a POSIX system. All font consumers can share a common database
|
||||
of fonts and use common matching rules for font names. The set of available
|
||||
fonts can be configured for each user and a set of configurable matching
|
||||
rules allow for customizing the selection of fonts and configuring various
|
||||
parameters related to rasterizing of those fonts for display in a variety of
|
||||
media. The Fontconfig library is designed to co-exist peacefully with
|
||||
existing font configuration and rasterization mechanisms; while it uses the
|
||||
FreeType library to discover characteristics of available fonts, there
|
||||
is no requirement to use FreeType for rasterization.
|
||||
|
||||
\section {Introduction}
|
||||
|
||||
\section {Configuration Files}
|
||||
|
||||
\section {Application Interface}
|
||||
|
||||
\subsection {Datatypes}
|
||||
|
||||
\subsection {Font Set Interface}
|
||||
|
||||
\subsection {Font Patterns}
|
||||
|
||||
\subsection {Listing Available Fonts}
|
||||
|
||||
\subsection {Using Font Names}
|
||||
|
||||
\subsection {Manipulating Matrices}
|
||||
|
||||
\subsection {UTF-8 Helper Functions}
|
||||
|
||||
\section {Font Sub-System Interface}
|
||||
|
||||
\subsection {Extending Font Names}
|
||||
|
||||
\subsection {Executing Configuration Rules}
|
||||
|
||||
\end{document}
|
|
@ -0,0 +1,19 @@
|
|||
#include "../../libxml2/config.h"
|
||||
#if HAVE_ZLIB_H
|
||||
ZLIB=-lz
|
||||
#endif
|
||||
|
||||
INCLUDES=-I../../freetype2 -I/usr/include/libxml2 -I..
|
||||
FREETYPE2REQLIB = ../../freetype2/libfreetype.a
|
||||
XML2REQLIB=../../libxml2/.libs/libxml2.a $(ZLIB) -lm
|
||||
|
||||
LOCAL_LIBRARIES=-L../src -lfontconfig $(FREETYPE2REQLIB) $(XML2REQLIB)
|
||||
|
||||
SRCS=fc-cache.c
|
||||
OBJS=fc-cache.o
|
||||
|
||||
ComplexProgramTarget(fc-cache)
|
||||
LinkBuildBinary(ProgramTargetName(fc-cache))
|
||||
|
||||
install::
|
||||
FC_DEBUG=128 FONTCONFIG_PATH=.. ./fc-cache -v
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#else
|
||||
#define HAVE_GETOPT 1
|
||||
#endif
|
||||
|
||||
#if HAVE_GETOPT_LONG
|
||||
#define _GNU_SOURCE
|
||||
#include <getopt.h>
|
||||
const struct option longopts[] = {
|
||||
{"version", 0, 0, 'V'},
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, '?'},
|
||||
{NULL,0,0,0},
|
||||
};
|
||||
#else
|
||||
#if HAVE_GETOPT
|
||||
extern char *optarg;
|
||||
extern int optind, opterr, optopt;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void usage (char *program)
|
||||
{
|
||||
fprintf (stderr, "usage: %s [-vV?] [--verbose] [--version] [--help] [dirs]\n",
|
||||
program);
|
||||
fprintf (stderr, "Build font information caches in [dirs]\n"
|
||||
"(all directories in font configuration by default).\n");
|
||||
fprintf (stderr, "\n");
|
||||
fprintf (stderr, " -v, --verbose display status information while busy\n");
|
||||
fprintf (stderr, " -V, --version display font config version and exit\n");
|
||||
fprintf (stderr, " -?, --help display this help and exit\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int ret = 0;
|
||||
FcFontSet *set;
|
||||
char **dirs;
|
||||
int verbose = 0;
|
||||
int i;
|
||||
#if HAVE_GETOPT_LONG || HAVE_GETOPT
|
||||
int c;
|
||||
|
||||
#if HAVE_GETOPT_LONG
|
||||
while ((c = getopt_long (argc, argv, "Vv?", longopts, NULL)) != -1)
|
||||
#else
|
||||
while ((c = getopt (argc, argv, "Vv?")) != -1)
|
||||
#endif
|
||||
{
|
||||
switch (c) {
|
||||
case 'V':
|
||||
fprintf (stderr, "fontconfig version %d.%d.%d\n",
|
||||
FC_MAJOR, FC_MINOR, FC_REVISION);
|
||||
exit (0);
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
default:
|
||||
usage (argv[0]);
|
||||
}
|
||||
}
|
||||
i = optind;
|
||||
#else
|
||||
i = 1;
|
||||
#endif
|
||||
|
||||
if (!FcInitConfig ())
|
||||
{
|
||||
fprintf (stderr, "Can't init font config library\n");
|
||||
return 1;
|
||||
}
|
||||
if (argv[i])
|
||||
dirs = argv+i;
|
||||
else
|
||||
dirs = FcConfigGetDirs (0);
|
||||
/*
|
||||
* Now scan all of the directories into separate databases
|
||||
* and write out the results
|
||||
*/
|
||||
while (dirs && *dirs)
|
||||
{
|
||||
if (verbose)
|
||||
printf ("%s: Scanning directory \"%s\"\n", argv[0], *dirs);
|
||||
set = FcFontSetCreate ();
|
||||
if (!set)
|
||||
{
|
||||
fprintf (stderr, "Out of memory in \"%s\"\n", *dirs);
|
||||
ret++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!FcDirScan (set, 0, FcConfigGetBlanks (0), *dirs, FcTrue))
|
||||
{
|
||||
fprintf (stderr, "Can't scan directory \"%s\"\n", *dirs);
|
||||
ret++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose)
|
||||
printf ("%s: Saving %d font names for \"%s\"\n",
|
||||
argv[0], set->nfont, *dirs);
|
||||
if (!FcDirSave (set, *dirs))
|
||||
{
|
||||
fprintf (stderr, "Can't save cache in \"%s\"\n", *dirs);
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
FcFontSetDestroy (set);
|
||||
}
|
||||
++dirs;
|
||||
}
|
||||
if (verbose)
|
||||
printf ("%s: %s\n", argv[0], ret ? "failed" : "succeeded");
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
.\"
|
||||
.\" Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
|
||||
.\"
|
||||
.\" 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 Keith Packard not be used in
|
||||
.\" advertising or publicity pertaining to distribution of the software without
|
||||
.\" specific, written prior permission. Keith Packard makes no
|
||||
.\" representations about the suitability of this software for any purpose. It
|
||||
.\" is provided "as is" without express or implied warranty.
|
||||
.\"
|
||||
.\" KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
.\" INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
.\" EVENT SHALL KEITH PACKARD 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.
|
||||
.\"
|
||||
.\"
|
||||
.\" $XFree86: xc/programs/fc-cache/fc-cache.man,v 1.3 2001/02/09 03:47:56 tsi Exp $
|
||||
.\"
|
||||
.TH FC-CACHE 1 __vendorversion__
|
||||
.SH NAME
|
||||
fc-cache, fonts.cache \- create an index of FreeType font files in a directory
|
||||
.SH SYNOPSIS
|
||||
.B "fc-cache"
|
||||
.RI [ directory-name
|
||||
\|.\|.\|. ]
|
||||
.SH DESCRIPTION
|
||||
If directory arguments are not given,
|
||||
.I fc-cache
|
||||
uses each directory in the current font configuration. Each directory is
|
||||
scanned for font files readable by FreeType. A cache is created which
|
||||
contains properties of each font and the associated filename. This cache is
|
||||
used to speed application startup when using the fontconfig library.
|
||||
.SH FILES
|
||||
.TP 15
|
||||
.B fonts.cache
|
||||
Maps file names to font properties. Read by the fontconfig library at
|
||||
application startup to locate appropriate fonts.
|
||||
.SH "SEE ALSO"
|
||||
fontconfig(3)
|
|
@ -0,0 +1,17 @@
|
|||
#include "../../libxml2/config.h"
|
||||
#if HAVE_ZLIB_H
|
||||
ZLIB=-lz
|
||||
#endif
|
||||
|
||||
INCLUDES=-I../../freetype2 -I/usr/include/libxml2 -I..
|
||||
FREETYPE2REQLIB = ../../freetype2/libfreetype.a
|
||||
XML2REQLIB=../../libxml2/.libs/libxml2.a $(ZLIB) -lm
|
||||
|
||||
LOCAL_LIBRARIES=-L../src -lfontconfig $(FREETYPE2REQLIB) $(XML2REQLIB)
|
||||
DEPLIBS=../src/libfontconfig.a
|
||||
|
||||
SRCS=fc-list.c
|
||||
OBJS=fc-list.o
|
||||
|
||||
ComplexProgramTarget(fc-list)
|
||||
LinkBuildBinary(ProgramTargetName(fc-list))
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#else
|
||||
#define HAVE_GETOPT 1
|
||||
#endif
|
||||
|
||||
#if HAVE_GETOPT_LONG
|
||||
#define _GNU_SOURCE
|
||||
#include <getopt.h>
|
||||
const struct option longopts[] = {
|
||||
{"version", 0, 0, 'V'},
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, '?'},
|
||||
{NULL,0,0,0},
|
||||
};
|
||||
#else
|
||||
#if HAVE_GETOPT
|
||||
extern char *optarg;
|
||||
extern int optind, opterr, optopt;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void usage (char *program)
|
||||
{
|
||||
fprintf (stderr, "usage: %s [-vV?] [--verbose] [--version] [--help] [dirs]\n",
|
||||
program);
|
||||
fprintf (stderr, "Build font information caches in [dirs]\n"
|
||||
"(all directories in font configuration by default).\n");
|
||||
fprintf (stderr, "\n");
|
||||
fprintf (stderr, " -v, --verbose display status information while busy\n");
|
||||
fprintf (stderr, " -V, --version display font config version and exit\n");
|
||||
fprintf (stderr, " -?, --help display this help and exit\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int ret = 0;
|
||||
FcFontSet *set;
|
||||
int verbose = 0;
|
||||
int i;
|
||||
FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, FC_LANG, 0);
|
||||
FcFontSet *fs;
|
||||
FcPattern *pat;
|
||||
#if HAVE_GETOPT_LONG || HAVE_GETOPT
|
||||
int c;
|
||||
|
||||
#if HAVE_GETOPT_LONG
|
||||
while ((c = getopt_long (argc, argv, "Vv?", longopts, NULL)) != -1)
|
||||
#else
|
||||
while ((c = getopt (argc, argv, "Vv?")) != -1)
|
||||
#endif
|
||||
{
|
||||
switch (c) {
|
||||
case 'V':
|
||||
fprintf (stderr, "fontconfig version %d.%d.%d\n",
|
||||
FC_MAJOR, FC_MINOR, FC_REVISION);
|
||||
exit (0);
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
default:
|
||||
usage (argv[0]);
|
||||
}
|
||||
}
|
||||
i = optind;
|
||||
#else
|
||||
i = 1;
|
||||
#endif
|
||||
|
||||
if (!FcInit ())
|
||||
{
|
||||
fprintf (stderr, "Can't init font config library\n");
|
||||
return 1;
|
||||
}
|
||||
if (argv[i])
|
||||
pat = FcNameParse (argv[i]);
|
||||
else
|
||||
pat = FcPatternCreate ();
|
||||
|
||||
fs = FcFontList (0, pat, os);
|
||||
if (pat)
|
||||
FcPatternDestroy (pat);
|
||||
|
||||
if (fs)
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j = 0; j < fs->nfont; j++)
|
||||
{
|
||||
FcChar8 *font;
|
||||
|
||||
font = FcNameUnparse (fs->fonts[j]);
|
||||
printf ("%s\n", font);
|
||||
free (font);
|
||||
}
|
||||
FcFontSetDestroy (fs);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
.\"
|
||||
.\" Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
|
||||
.\"
|
||||
.\" 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 Keith Packard not be used in
|
||||
.\" advertising or publicity pertaining to distribution of the software without
|
||||
.\" specific, written prior permission. Keith Packard makes no
|
||||
.\" representations about the suitability of this software for any purpose. It
|
||||
.\" is provided "as is" without express or implied warranty.
|
||||
.\"
|
||||
.\" KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
.\" INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
.\" EVENT SHALL KEITH PACKARD 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.
|
||||
.\"
|
||||
.\"
|
||||
.\" $XFree86: xc/programs/fc-list/fc-list.man,v 1.3 2001/02/09 03:47:56 tsi Exp $
|
||||
.\"
|
||||
.TH FC-LIST 1 __vendorversion__
|
||||
.SH NAME
|
||||
fc-list \- list available fonts
|
||||
.SH SYNOPSIS
|
||||
.B "fc-list"
|
||||
.RI [ font-pattern ]
|
||||
.SH DESCRIPTION
|
||||
If font pattern is not given,
|
||||
.I fc-list
|
||||
lists all available faces and styles in the current font configuration.
|
||||
.SH "SEE ALSO"
|
||||
fontconfig(3)
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
dirs="/usr/share/fonts /usr/X11R6/lib/X11/fonts"
|
||||
for d in $dirs; do
|
||||
find $d \( -name '*.[Tt][Tt][Ff]' -o -name '*.[Pp][Ff][BbAa]' \) -print
|
||||
done | while read f; do
|
||||
dir=`dirname $f`
|
||||
echo $dir
|
||||
done | sort -u | sed 's/^/ <dir>/' | sed 's;$;</dir>;'
|
|
@ -0,0 +1,8 @@
|
|||
#define IncSubdir fontconfig
|
||||
|
||||
HEADERS=fcfreetype.h fcprivate.h fcxml.h fontconfig.h
|
||||
|
||||
BuildIncludes($(HEADERS),IncSubdir,..)
|
||||
#if BuildLibraries
|
||||
InstallMultipleFlags($(HEADERS),$(INCDIR)/IncSubdir,$(INSTINCFLAGS))
|
||||
#endif
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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 _FCFREETYPE_H_
|
||||
#define _FCFREETYPE_H_
|
||||
|
||||
FT_UInt
|
||||
FcFreeTypeCharIndex (FT_Face face, FcChar32 ucs4);
|
||||
|
||||
FcCharSet *
|
||||
FcFreeTypeCharSet (FT_Face face, FcBlanks *blanks);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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 _FCPRIVATE_H_
|
||||
#define _FCPRIVATE_H_
|
||||
|
||||
/*
|
||||
* I tried this with functions that took va_list* arguments
|
||||
* but portability concerns made me change these functions
|
||||
* into macros (sigh).
|
||||
*/
|
||||
|
||||
#define FcPatternVapBuild(result, orig, va) \
|
||||
{ \
|
||||
FcPattern *__p__ = (orig); \
|
||||
const char *__o__; \
|
||||
FcValue __v__; \
|
||||
\
|
||||
if (!__p__) \
|
||||
{ \
|
||||
__p__ = FcPatternCreate (); \
|
||||
if (!__p__) \
|
||||
goto _FcPatternVapBuild_bail0; \
|
||||
} \
|
||||
for (;;) \
|
||||
{ \
|
||||
__o__ = va_arg (va, const char *); \
|
||||
if (!__o__) \
|
||||
break; \
|
||||
__v__.type = va_arg (va, FcType); \
|
||||
switch (__v__.type) { \
|
||||
case FcTypeVoid: \
|
||||
goto _FcPatternVapBuild_bail1; \
|
||||
case FcTypeInteger: \
|
||||
__v__.u.i = va_arg (va, int); \
|
||||
break; \
|
||||
case FcTypeDouble: \
|
||||
__v__.u.d = va_arg (va, double); \
|
||||
break; \
|
||||
case FcTypeString: \
|
||||
__v__.u.s = va_arg (va, char *); \
|
||||
break; \
|
||||
case FcTypeBool: \
|
||||
__v__.u.b = va_arg (va, FcBool); \
|
||||
break; \
|
||||
case FcTypeMatrix: \
|
||||
__v__.u.m = va_arg (va, FcMatrix *); \
|
||||
break; \
|
||||
case FcTypeCharSet: \
|
||||
__v__.u.c = va_arg (va, FcCharSet *); \
|
||||
break; \
|
||||
} \
|
||||
if (!FcPatternAdd (__p__, __o__, __v__, FcTrue)) \
|
||||
goto _FcPatternVapBuild_bail1; \
|
||||
} \
|
||||
result = __p__; \
|
||||
goto _FcPatternVapBuild_return; \
|
||||
\
|
||||
_FcPatternVapBuild_bail1: \
|
||||
if (!orig) \
|
||||
FcPatternDestroy (__p__); \
|
||||
_FcPatternVapBuild_bail0: \
|
||||
result = 0; \
|
||||
\
|
||||
_FcPatternVapBuild_return: \
|
||||
; \
|
||||
}
|
||||
|
||||
|
||||
#define FcObjectSetVapBuild(__ret__, __first__, __va__) \
|
||||
{ \
|
||||
FcObjectSet *__os__; \
|
||||
const char *__ob__; \
|
||||
\
|
||||
__ret__ = 0; \
|
||||
__os__ = FcObjectSetCreate (); \
|
||||
if (!__os__) \
|
||||
goto _FcObjectSetVapBuild_bail0; \
|
||||
__ob__ = __first__; \
|
||||
while (__ob__) \
|
||||
{ \
|
||||
if (!FcObjectSetAdd (__os__, __ob__)) \
|
||||
goto _FcObjectSetVapBuild_bail1; \
|
||||
__ob__ = va_arg (__va__, const char *); \
|
||||
} \
|
||||
__ret__ = __os__; \
|
||||
\
|
||||
_FcObjectSetVapBuild_bail1: \
|
||||
if (!__ret__ && __os__) \
|
||||
FcObjectSetDestroy (__os__); \
|
||||
_FcObjectSetVapBuild_bail0: \
|
||||
; \
|
||||
}
|
||||
|
||||
#endif /* _FCPRIVATE_H_ */
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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 _FCXML_H_
|
||||
#define _FCXML_H_
|
||||
|
||||
#include <libxml/parser.h>
|
||||
|
||||
xmlDocPtr
|
||||
FcConfigLoad (const char *file);
|
||||
|
||||
FcBool
|
||||
FcConfigParse (FcConfig *config,
|
||||
xmlDocPtr doc);
|
||||
|
||||
#endif /* _FCXML_H_ */
|
|
@ -0,0 +1,551 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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 _FONTCONFIG_H_
|
||||
#define _FONTCONFIG_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
typedef unsigned char FcChar8;
|
||||
typedef unsigned short FcChar16;
|
||||
typedef unsigned int FcChar32;
|
||||
typedef int FcBool;
|
||||
|
||||
/*
|
||||
* Current Fontconfig version number
|
||||
*/
|
||||
#define FC_MAJOR 1
|
||||
#define FC_MINOR 0
|
||||
#define FC_REVISION 0
|
||||
|
||||
#define FC_VERSION ((FC_MAJOR * 10000) + (FC_MINOR * 100) + (FC_REVISION))
|
||||
|
||||
#define FcTrue 1
|
||||
#define FcFalse 0
|
||||
|
||||
#define FC_FAMILY "family" /* String */
|
||||
#define FC_STYLE "style" /* String */
|
||||
#define FC_SLANT "slant" /* Int */
|
||||
#define FC_WEIGHT "weight" /* Int */
|
||||
#define FC_SIZE "size" /* Double */
|
||||
#define FC_PIXEL_SIZE "pixelsize" /* Double */
|
||||
#define FC_SPACING "spacing" /* Int */
|
||||
#define FC_FOUNDRY "foundry" /* String */
|
||||
#define FC_ANTIALIAS "antialias" /* Bool (depends) */
|
||||
#define FC_HINTING "hinting" /* Bool (true) */
|
||||
#define FC_VERTICAL_LAYOUT "verticallayout" /* Bool (false) */
|
||||
#define FC_AUTOHINT "autohint" /* Bool (false) */
|
||||
#define FC_GLOBAL_ADVANCE "globaladvance" /* Bool (true) */
|
||||
#define FC_FILE "file" /* String */
|
||||
#define FC_INDEX "index" /* Int */
|
||||
#define FC_RASTERIZER "rasterizer" /* String */
|
||||
#define FC_OUTLINE "outline" /* Bool */
|
||||
#define FC_SCALABLE "scalable" /* Bool */
|
||||
#define FC_SCALE "scale" /* double */
|
||||
#define FC_DPI "dpi" /* double */
|
||||
#define FC_RGBA "rgba" /* Int */
|
||||
#define FC_MINSPACE "minspace" /* Bool use minimum line spacing */
|
||||
#define FC_SOURCE "source" /* String (X11, freetype) */
|
||||
#define FC_CHARSET "charset" /* CharSet */
|
||||
#define FC_LANG "lang" /* String OS/2 CodePageRange */
|
||||
|
||||
#define FC_DIR_CACHE_FILE "fonts.cache"
|
||||
#define FC_USER_CACHE_FILE ".fonts.cache"
|
||||
|
||||
/* Adjust outline rasterizer */
|
||||
#define FC_CHAR_WIDTH "charwidth" /* Int */
|
||||
#define FC_CHAR_HEIGHT "charheight"/* Int */
|
||||
#define FC_MATRIX "matrix" /* FcMatrix */
|
||||
|
||||
#define FC_WEIGHT_LIGHT 0
|
||||
#define FC_WEIGHT_MEDIUM 100
|
||||
#define FC_WEIGHT_DEMIBOLD 180
|
||||
#define FC_WEIGHT_BOLD 200
|
||||
#define FC_WEIGHT_BLACK 210
|
||||
|
||||
#define FC_SLANT_ROMAN 0
|
||||
#define FC_SLANT_ITALIC 100
|
||||
#define FC_SLANT_OBLIQUE 110
|
||||
|
||||
#define FC_PROPORTIONAL 0
|
||||
#define FC_MONO 100
|
||||
#define FC_CHARCELL 110
|
||||
|
||||
/* sub-pixel order */
|
||||
#define FC_RGBA_NONE 0
|
||||
#define FC_RGBA_RGB 1
|
||||
#define FC_RGBA_BGR 2
|
||||
#define FC_RGBA_VRGB 3
|
||||
#define FC_RGBA_VBGR 4
|
||||
|
||||
/* language groups from the OS/2 CodePageRange bits */
|
||||
#define FC_LANG_LATIN_1 "latin1" /* 0 */
|
||||
#define FC_LANG_LATIN_2_EASTERN_EUROPE "latin2easterneurope" /* 1 */
|
||||
#define FC_LANG_CYRILLIC "cyrillic" /* 2 */
|
||||
#define FC_LANG_GREEK "greek" /* 3 */
|
||||
#define FC_LANG_TURKISH "turkish" /* 4 */
|
||||
#define FC_LANG_HEBREW "hebrew" /* 5 */
|
||||
#define FC_LANG_ARABIC "arabic" /* 6 */
|
||||
#define FC_LANG_WINDOWS_BALTIC "windowsbaltic" /* 7 */
|
||||
#define FC_LANG_VIETNAMESE "vietnamese" /* 8 */
|
||||
/* 9-15 reserved for Alternate ANSI */
|
||||
#define FC_LANG_THAI "thai" /* 16 */
|
||||
#define FC_LANG_JAPANESE "japanese" /* 17 */
|
||||
#define FC_LANG_SIMPLIFIED_CHINESE "simplifiedchinese" /* 18 */
|
||||
#define FC_LANG_KOREAN_WANSUNG "koreanwansung" /* 19 */
|
||||
#define FC_LANG_TRADITIONAL_CHINESE "traditionalchinese" /* 20 */
|
||||
#define FC_LANG_KOREAN_JOHAB "koreanjohab" /* 21 */
|
||||
/* 22-28 reserved for Alternate ANSI & OEM */
|
||||
#define FC_LANG_MACINTOSH "macintosh" /* 29 */
|
||||
#define FC_LANG_OEM "oem" /* 30 */
|
||||
#define FC_LANG_SYMBOL "symbol" /* 31 */
|
||||
/* 32-47 reserved for OEM */
|
||||
#define FC_LANG_IBM_GREEK "ibmgreek" /* 48 */
|
||||
#define FC_LANG_MSDOS_RUSSIAN "msdosrussian" /* 49 */
|
||||
#define FC_LANG_MSDOS_NORDIC "msdosnordic" /* 50 */
|
||||
#define FC_LANG_ARABIC_864 "arabic864" /* 51 */
|
||||
#define FC_LANG_MSDOS_CANADIAN_FRENCH "msdoscanadianfrench" /* 52 */
|
||||
#define FC_LANG_HEBREW_862 "hebrew862" /* 53 */
|
||||
#define FC_LANG_MSDOS_ICELANDIC "msdosicelandic" /* 54 */
|
||||
#define FC_LANG_MSDOS_PORTUGUESE "msdosportuguese" /* 55 */
|
||||
#define FC_LANG_IBM_TURKISH "ibmturkish" /* 56 */
|
||||
#define FC_LANG_IBM_CYRILLIC "ibmcyrillic" /* 57 */
|
||||
#define FC_LANG_LATIN_2 "latin2" /* 58 */
|
||||
#define FC_LANG_MSDOS_BALTIC "msdosbaltic" /* 59 */
|
||||
#define FC_LANG_GREEK_437_G "greek437g" /* 60 */
|
||||
#define FC_LANG_ARABIC_ASMO_708 "arabicasmo708" /* 61 */
|
||||
#define FC_LANG_WE_LATIN_1 "welatin1" /* 62 */
|
||||
#define FC_LANG_US "us" /* 63 */
|
||||
|
||||
typedef enum _FcType {
|
||||
FcTypeVoid,
|
||||
FcTypeInteger,
|
||||
FcTypeDouble,
|
||||
FcTypeString,
|
||||
FcTypeBool,
|
||||
FcTypeMatrix,
|
||||
FcTypeCharSet
|
||||
} FcType;
|
||||
|
||||
typedef struct _FcMatrix {
|
||||
double xx, xy, yx, yy;
|
||||
} FcMatrix;
|
||||
|
||||
#define FcMatrixInit(m) ((m)->xx = (m)->yy = 1, \
|
||||
(m)->xy = (m)->yx = 0)
|
||||
|
||||
/*
|
||||
* A data structure to represent the available glyphs in a font.
|
||||
* This is represented as a sparse boolean btree.
|
||||
*/
|
||||
|
||||
typedef struct _FcCharSet FcCharSet;
|
||||
|
||||
typedef struct _FcObjectType {
|
||||
const char *object;
|
||||
FcType type;
|
||||
} FcObjectType;
|
||||
|
||||
typedef struct _FcConstant {
|
||||
const char *name;
|
||||
const char *object;
|
||||
int value;
|
||||
} FcConstant;
|
||||
|
||||
typedef enum _FcResult {
|
||||
FcResultMatch, FcResultNoMatch, FcResultTypeMismatch, FcResultNoId
|
||||
} FcResult;
|
||||
|
||||
typedef struct _FcValue {
|
||||
FcType type;
|
||||
union {
|
||||
const FcChar8 *s;
|
||||
int i;
|
||||
FcBool b;
|
||||
double d;
|
||||
const FcMatrix *m;
|
||||
const FcCharSet *c;
|
||||
} u;
|
||||
} FcValue;
|
||||
|
||||
typedef struct _FcPattern FcPattern;
|
||||
|
||||
typedef struct _FcFontSet {
|
||||
int nfont;
|
||||
int sfont;
|
||||
FcPattern **fonts;
|
||||
} FcFontSet;
|
||||
|
||||
typedef struct _FcObjectSet {
|
||||
int nobject;
|
||||
int sobject;
|
||||
const char **objects;
|
||||
} FcObjectSet;
|
||||
|
||||
typedef enum _FcMatchKind {
|
||||
FcMatchPattern, FcMatchFont
|
||||
} FcMatchKind;
|
||||
|
||||
typedef enum _FcSetName {
|
||||
FcSetSystem = 0,
|
||||
FcSetApplication = 1
|
||||
} FcSetName;
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus) /* for C++ V2.0 */
|
||||
#define _FCFUNCPROTOBEGIN extern "C" { /* do not leave open across includes */
|
||||
#define _FCFUNCPROTOEND }
|
||||
#else
|
||||
#define _FCFUNCPROTOBEGIN
|
||||
#define _FCFUNCPROTOEND
|
||||
#endif
|
||||
|
||||
typedef struct _FcConfig FcConfig;
|
||||
|
||||
typedef struct _FcFileCache FcFileCache;
|
||||
|
||||
typedef struct _FcBlanks FcBlanks;
|
||||
|
||||
_FCFUNCPROTOBEGIN
|
||||
|
||||
/* fcblanks.c */
|
||||
FcBlanks *
|
||||
FcBlanksCreate (void);
|
||||
|
||||
void
|
||||
FcBlanksDestroy (FcBlanks *b);
|
||||
|
||||
FcBool
|
||||
FcBlanksAdd (FcBlanks *b, FcChar32 ucs4);
|
||||
|
||||
FcBool
|
||||
FcBlanksIsMember (FcBlanks *b, FcChar32 ucs4);
|
||||
|
||||
/* fccfg.c */
|
||||
char *
|
||||
FcConfigFilename (const char *url);
|
||||
|
||||
FcConfig *
|
||||
FcConfigCreate (void);
|
||||
|
||||
void
|
||||
FcConfigDestroy (FcConfig *config);
|
||||
|
||||
FcBool
|
||||
FcConfigSetCurrent (FcConfig *config);
|
||||
|
||||
FcConfig *
|
||||
FcConfigGetCurrent (void);
|
||||
|
||||
FcBool
|
||||
FcConfigBuildFonts (FcConfig *config);
|
||||
|
||||
char **
|
||||
FcConfigGetDirs (FcConfig *config);
|
||||
|
||||
char **
|
||||
FcConfigGetConfigFiles (FcConfig *config);
|
||||
|
||||
char *
|
||||
FcConfigGetCache (FcConfig *config);
|
||||
|
||||
FcBlanks *
|
||||
FcConfigGetBlanks (FcConfig *config);
|
||||
|
||||
FcFontSet *
|
||||
FcConfigGetFonts (FcConfig *config,
|
||||
FcSetName set);
|
||||
|
||||
FcBool
|
||||
FcConfigAppFontAddFile (FcConfig *config,
|
||||
const char *file);
|
||||
|
||||
FcBool
|
||||
FcConfigAppFontAddDir (FcConfig *config,
|
||||
const char *dir);
|
||||
|
||||
void
|
||||
FcConfigAppFontClear (FcConfig *config);
|
||||
|
||||
FcBool
|
||||
FcConfigSubstitute (FcConfig *config,
|
||||
FcPattern *p,
|
||||
FcMatchKind kind);
|
||||
|
||||
/* fccharset.c */
|
||||
FcCharSet *
|
||||
FcCharSetCreate (void);
|
||||
|
||||
void
|
||||
FcCharSetDestroy (FcCharSet *fcs);
|
||||
|
||||
FcBool
|
||||
FcCharSetAddChar (FcCharSet *fcs, FcChar32 ucs4);
|
||||
|
||||
FcCharSet *
|
||||
FcCharSetCopy (FcCharSet *src);
|
||||
|
||||
FcBool
|
||||
FcCharSetEqual (const FcCharSet *a, const FcCharSet *b);
|
||||
|
||||
FcCharSet *
|
||||
FcCharSetIntersect (const FcCharSet *a, const FcCharSet *b);
|
||||
|
||||
FcCharSet *
|
||||
FcCharSetUnion (const FcCharSet *a, const FcCharSet *b);
|
||||
|
||||
FcCharSet *
|
||||
FcCharSetSubtract (const FcCharSet *a, const FcCharSet *b);
|
||||
|
||||
FcBool
|
||||
FcCharSetHasChar (const FcCharSet *fcs, FcChar32 ucs4);
|
||||
|
||||
FcChar32
|
||||
FcCharSetCount (const FcCharSet *a);
|
||||
|
||||
FcChar32
|
||||
FcCharSetIntersectCount (const FcCharSet *a, const FcCharSet *b);
|
||||
|
||||
FcChar32
|
||||
FcCharSetSubtractCount (const FcCharSet *a, const FcCharSet *b);
|
||||
|
||||
#ifndef FONTCONFIG_NO_FREETYPE
|
||||
#include <freetype/freetype.h>
|
||||
FT_UInt
|
||||
FcFreeTypeCharIndex (FT_Face face, FcChar32 ucs4);
|
||||
#endif
|
||||
|
||||
/* fcdbg.c */
|
||||
void
|
||||
FcPatternPrint (FcPattern *p);
|
||||
|
||||
/* fcdefault.c */
|
||||
void
|
||||
FcDefaultSubstitute (FcPattern *pattern);
|
||||
|
||||
/* fcdir.c */
|
||||
FcBool
|
||||
FcDirScan (FcFontSet *set,
|
||||
FcFileCache *cache,
|
||||
FcBlanks *blanks,
|
||||
const char *dir,
|
||||
FcBool force);
|
||||
|
||||
FcBool
|
||||
FcDirSave (FcFontSet *set, const char *dir);
|
||||
|
||||
/* fcfreetype.c */
|
||||
FcPattern *
|
||||
FcFreeTypeQuery (const char *file, int id, FcBlanks *blanks, int *count);
|
||||
|
||||
/* fcfs.c */
|
||||
|
||||
FcFontSet *
|
||||
FcFontSetCreate (void);
|
||||
|
||||
void
|
||||
FcFontSetDestroy (FcFontSet *s);
|
||||
|
||||
FcBool
|
||||
FcFontSetAdd (FcFontSet *s, FcPattern *font);
|
||||
|
||||
/* fcinit.c */
|
||||
FcBool
|
||||
FcInitFonts (void);
|
||||
|
||||
FcBool
|
||||
FcInitConfig (void);
|
||||
|
||||
FcBool
|
||||
FcInit (void);
|
||||
|
||||
/* fclist.c */
|
||||
FcObjectSet *
|
||||
FcObjectSetCreate (void);
|
||||
|
||||
FcBool
|
||||
FcObjectSetAdd (FcObjectSet *os, const char *object);
|
||||
|
||||
void
|
||||
FcObjectSetDestroy (FcObjectSet *os);
|
||||
|
||||
FcObjectSet *
|
||||
FcObjectSetVaBuild (const char *first, va_list va);
|
||||
|
||||
FcObjectSet *
|
||||
FcObjectSetBuild (const char *first, ...);
|
||||
|
||||
FcFontSet *
|
||||
FcFontList (FcConfig *config,
|
||||
FcPattern *p,
|
||||
FcObjectSet *os);
|
||||
|
||||
/* fcmatch.c */
|
||||
FcPattern *
|
||||
FcFontMatch (FcConfig *config,
|
||||
FcPattern *p,
|
||||
FcResult *result);
|
||||
|
||||
/* fcmatrix.c */
|
||||
FcMatrix *
|
||||
FcMatrixCopy (const FcMatrix *mat);
|
||||
|
||||
FcBool
|
||||
FcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2);
|
||||
|
||||
void
|
||||
FcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b);
|
||||
|
||||
void
|
||||
FcMatrixRotate (FcMatrix *m, double c, double s);
|
||||
|
||||
void
|
||||
FcMatrixScale (FcMatrix *m, double sx, double sy);
|
||||
|
||||
void
|
||||
FcMatrixShear (FcMatrix *m, double sh, double sv);
|
||||
|
||||
/* fcname.c */
|
||||
|
||||
FcBool
|
||||
FcNameRegisterObjectTypes (const FcObjectType *types, int ntype);
|
||||
|
||||
FcBool
|
||||
FcNameUnregisterObjectTypes (const FcObjectType *types, int ntype);
|
||||
|
||||
const FcObjectType *
|
||||
FcNameGetObjectType (const char *object);
|
||||
|
||||
FcBool
|
||||
FcNameRegisterConstants (const FcConstant *consts, int nconsts);
|
||||
|
||||
FcBool
|
||||
FcNameUnregisterConstants (const FcConstant *consts, int nconsts);
|
||||
|
||||
const FcConstant *
|
||||
FcNameGetConstant (char *string);
|
||||
|
||||
FcBool
|
||||
FcNameConstant (char *string, int *result);
|
||||
|
||||
FcPattern *
|
||||
FcNameParse (const char *name);
|
||||
|
||||
FcChar8 *
|
||||
FcNameUnparse (FcPattern *pat);
|
||||
|
||||
/* fcpat.c */
|
||||
FcPattern *
|
||||
FcPatternCreate (void);
|
||||
|
||||
FcPattern *
|
||||
FcPatternDuplicate (FcPattern *p);
|
||||
|
||||
void
|
||||
FcValueDestroy (FcValue v);
|
||||
|
||||
FcValue
|
||||
FcValueSave (FcValue v);
|
||||
|
||||
void
|
||||
FcPatternDestroy (FcPattern *p);
|
||||
|
||||
FcBool
|
||||
FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append);
|
||||
|
||||
FcResult
|
||||
FcPatternGet (FcPattern *p, const char *object, int id, FcValue *v);
|
||||
|
||||
FcBool
|
||||
FcPatternDel (FcPattern *p, const char *object);
|
||||
|
||||
FcBool
|
||||
FcPatternAddInteger (FcPattern *p, const char *object, int i);
|
||||
|
||||
FcBool
|
||||
FcPatternAddDouble (FcPattern *p, const char *object, double d);
|
||||
|
||||
FcBool
|
||||
FcPatternAddString (FcPattern *p, const char *object, const char *s);
|
||||
|
||||
FcBool
|
||||
FcPatternAddMatrix (FcPattern *p, const char *object, const FcMatrix *s);
|
||||
|
||||
FcBool
|
||||
FcPatternAddCharSet (FcPattern *p, const char *object, const FcCharSet *c);
|
||||
|
||||
FcBool
|
||||
FcPatternAddBool (FcPattern *p, const char *object, FcBool b);
|
||||
|
||||
FcResult
|
||||
FcPatternGetInteger (FcPattern *p, const char *object, int n, int *i);
|
||||
|
||||
FcResult
|
||||
FcPatternGetDouble (FcPattern *p, const char *object, int n, double *d);
|
||||
|
||||
FcResult
|
||||
FcPatternGetString (FcPattern *p, const char *object, int n, char **const s);
|
||||
|
||||
FcResult
|
||||
FcPatternGetMatrix (FcPattern *p, const char *object, int n, FcMatrix **s);
|
||||
|
||||
FcResult
|
||||
FcPatternGetCharSet (FcPattern *p, const char *object, int n, FcCharSet **c);
|
||||
|
||||
FcResult
|
||||
FcPatternGetBool (FcPattern *p, const char *object, int n, FcBool *b);
|
||||
|
||||
FcPattern *
|
||||
FcPatternVaBuild (FcPattern *orig, va_list va);
|
||||
|
||||
FcPattern *
|
||||
FcPatternBuild (FcPattern *orig, ...);
|
||||
|
||||
/* fcstr.c */
|
||||
|
||||
char *
|
||||
FcStrCopy (const char *s);
|
||||
|
||||
#define FcToLower(c) (('A' <= (c) && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
|
||||
|
||||
int
|
||||
FcStrCmpIgnoreCase (const char *s1, const char *s2);
|
||||
|
||||
int
|
||||
FcUtf8ToUcs4 (FcChar8 *src_orig,
|
||||
FcChar32 *dst,
|
||||
int len);
|
||||
|
||||
FcBool
|
||||
FcUtf8Len (FcChar8 *string,
|
||||
int len,
|
||||
int *nchar,
|
||||
int *wchar);
|
||||
|
||||
/* fcxml.c */
|
||||
FcBool
|
||||
FcConfigParseAndLoad (FcConfig *config, const char *file, FcBool complain);
|
||||
|
||||
_FCFUNCPROTOEND
|
||||
|
||||
#endif /* _FONTCONFIG_H_ */
|
|
@ -0,0 +1,191 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
|
||||
<!-- /etc/fonts.conf file to configure system font access -->
|
||||
<fontconfig>
|
||||
|
||||
<!-- FONTPATH_START -->
|
||||
|
||||
<!--
|
||||
Common X11R6 font directories
|
||||
-->
|
||||
|
||||
<dir>/usr/X11R6/lib/X11/fonts/truetype</dir>
|
||||
<dir>/usr/X11R6/lib/X11/fonts/Type1</dir>
|
||||
<dir>/usr/X11R6/lib/X11/fonts/TrueType</dir>
|
||||
|
||||
<!-- FONTPATH_END -->
|
||||
|
||||
<!--
|
||||
Accept deprecated 'mono' alias, replacing it with 'monospace'
|
||||
-->
|
||||
<match target="pattern">
|
||||
<test qual="any" name="family">
|
||||
<string>mono</string>
|
||||
</test>
|
||||
<edit name="family" mode="assign">
|
||||
<string>monospace</string>
|
||||
</edit>
|
||||
</match>
|
||||
|
||||
<!--
|
||||
Accept deprecated 'sans' alias, replacing it with 'sans-serif'
|
||||
-->
|
||||
<match target="pattern">
|
||||
<test qual="any" name="family">
|
||||
<string>sans</string>
|
||||
</test>
|
||||
<edit name="family" mode="assign">
|
||||
<string>sans-serif</string>
|
||||
</edit>
|
||||
</match>
|
||||
|
||||
<!--
|
||||
Mark common families with their generics so we'll get
|
||||
something reasonable
|
||||
-->
|
||||
|
||||
<!--
|
||||
Serif faces
|
||||
-->
|
||||
<alias>
|
||||
<family>Times</family>
|
||||
<default><family>serif</family></default>
|
||||
</alias>
|
||||
<alias>
|
||||
<family>Times New Roman</family>
|
||||
<default><family>serif</family></default>
|
||||
</alias>
|
||||
<!--
|
||||
Sans-serif faces
|
||||
-->
|
||||
<alias>
|
||||
<family>Helvetica</family>
|
||||
<default><family>sans-serif</family></default>
|
||||
</alias>
|
||||
<alias>
|
||||
<family>Arial</family>
|
||||
<default><family>sans-serif</family></default>
|
||||
</alias>
|
||||
<alias>
|
||||
<family>Verdana</family>
|
||||
<default><family>sans-serif</family></default>
|
||||
</alias>
|
||||
<!--
|
||||
Monospace faces
|
||||
-->
|
||||
<alias>
|
||||
<family>Courier</family>
|
||||
<default><family>monospace</family></default>
|
||||
</alias>
|
||||
<alias>
|
||||
<family>Courier New</family>
|
||||
<default><family>monospace</family></default>
|
||||
</alias>
|
||||
<alias>
|
||||
<family>Andale Mono</family>
|
||||
<default><family>monospace</family></default>
|
||||
</alias>
|
||||
<!--
|
||||
If the font still has no generic name, add sans-serif
|
||||
-->
|
||||
<match target="pattern">
|
||||
<test qual="all" name="family" compare="not_eq">
|
||||
<string>sans-serif</string>
|
||||
</test>
|
||||
<test qual="all" name="family" compare="not_eq">
|
||||
<string>serif</string>
|
||||
</test>
|
||||
<test qual="all" name="family" compare="not_eq">
|
||||
<string>monospace</string>
|
||||
</test>
|
||||
<edit name="family" mode="append_last">
|
||||
<string>sans-serif</string>
|
||||
</edit>
|
||||
</match>
|
||||
|
||||
<!--
|
||||
Load per-user customization file
|
||||
-->
|
||||
<include ignore_missing="yes">~/.fonts.conf</include>
|
||||
|
||||
<!--
|
||||
Alias well known font names to available TrueType fonts
|
||||
-->
|
||||
<alias>
|
||||
<family>Times</family>
|
||||
<prefer><family>Times New Roman</family></prefer>
|
||||
<default><family>serif</family></default>
|
||||
</alias>
|
||||
<alias>
|
||||
<family>Helvetica</family>
|
||||
<prefer><family>Verdana</family></prefer>
|
||||
<default><family>sans-serif</family></default>
|
||||
</alias>
|
||||
<alias>
|
||||
<family>Arial</family>
|
||||
<prefer><family>Verdana</family></prefer>
|
||||
<default><family>sans-serif</family></default>
|
||||
</alias>
|
||||
<alias>
|
||||
<family>Courier</family>
|
||||
<prefer><family>Courier New</family></prefer>
|
||||
<default><family>monospace</family></default>
|
||||
</alias>
|
||||
|
||||
<!--
|
||||
Provide required aliases for standard names
|
||||
-->
|
||||
<alias>
|
||||
<family>serif</family>
|
||||
<prefer>
|
||||
<family>Times New Roman</family>
|
||||
<family>Nimbus Roman No9 L</family>
|
||||
<family>Luxi Serif</family>
|
||||
<family>Times</family>
|
||||
</prefer>
|
||||
</alias>
|
||||
<alias>
|
||||
<family>sans-serif</family>
|
||||
<prefer>
|
||||
<family>Verdana</family>
|
||||
<family>Nimbus Sans L</family>
|
||||
<family>Luxi Sans</family>
|
||||
<family>Arial</family>
|
||||
<family>Helvetica</family>
|
||||
</prefer>
|
||||
</alias>
|
||||
<alias>
|
||||
<family>monospace</family>
|
||||
<prefer>
|
||||
<family>Andale Mono</family>
|
||||
<family>Courier New</family>
|
||||
<family>Nimbus Mono L</family>
|
||||
<family>Luxi Mono</family>
|
||||
</prefer>
|
||||
</alias>
|
||||
|
||||
<!--
|
||||
These are the default Unicode chars that are expected to be blank
|
||||
in fonts. All other blank chars are assumed to be broken and
|
||||
won't appear in the resulting charsets
|
||||
-->
|
||||
<config><blank>
|
||||
<int>0x20</int> <!-- space -->
|
||||
<int>0xa0</int> <!-- nsbp -->
|
||||
<int>0x2000</int> <!-- general punctuation spaces -->
|
||||
<int>0x2001</int>
|
||||
<int>0x2002</int>
|
||||
<int>0x2003</int>
|
||||
<int>0x2004</int>
|
||||
<int>0x2005</int>
|
||||
<int>0x2005</int>
|
||||
<int>0x2006</int>
|
||||
<int>0x2007</int>
|
||||
<int>0x2008</int>
|
||||
<int>0x2009</int>
|
||||
<int>0x200a</int>
|
||||
<int>0x200b</int>
|
||||
<int>0x3000</int> <!-- CJK space -->
|
||||
</blank></config>
|
||||
|
||||
</fontconfig>
|
|
@ -0,0 +1,165 @@
|
|||
<!-- This is the Document Type Definition for font configuration files -->
|
||||
<!ELEMENT fontconfig (dir |
|
||||
cache |
|
||||
include |
|
||||
config |
|
||||
match |
|
||||
alias)* >
|
||||
|
||||
<!--
|
||||
Add a directory that provides fonts
|
||||
-->
|
||||
<!ELEMENT dir (#PCDATA)>
|
||||
<!ATTLIST dir xml:space (default|preserve) 'preserve'>
|
||||
|
||||
<!--
|
||||
Define the per-user file that holds cache font information.
|
||||
|
||||
If the filename begins with '~', it is replaced with the users
|
||||
home directory path.
|
||||
-->
|
||||
<!ELEMENT cache (#PCDATA)>
|
||||
<!ATTLIST cache xml:space (default|preserve) 'preserve'>
|
||||
|
||||
<!--
|
||||
Reference another configuration file; note that this
|
||||
is another complete font configuration file and not
|
||||
just a file included by the XML parser.
|
||||
|
||||
Set 'ignore_missing' to 'yes' if errors are to be ignored.
|
||||
|
||||
If the filename begins with '~', it is replaced with the users
|
||||
home directory path.
|
||||
-->
|
||||
<!ELEMENT include (#PCDATA)>
|
||||
<!ATTLIST include
|
||||
ignore_missing (no|yes) "no"
|
||||
xml:space (default|preserve) "preserve">
|
||||
|
||||
<!--
|
||||
Global library configuration data
|
||||
-->
|
||||
<!ELEMENT config (blanks)*>
|
||||
|
||||
<!--
|
||||
Specify the set of Unicode encoding values which
|
||||
represent glyphs that are allowed to contain no
|
||||
data. With this list, fontconfig can examine
|
||||
fonts for broken glyphs and eliminate them from
|
||||
the set of valid Unicode chars. This idea
|
||||
was borrowed from Mozilla
|
||||
-->
|
||||
<!ELEMENT blanks (int)*>
|
||||
|
||||
<!--
|
||||
Aliases are just a special case for multiple match elements
|
||||
|
||||
They are syntactically equivalent to:
|
||||
|
||||
<match>
|
||||
<test name="family">
|
||||
<string value=[family]/>
|
||||
</test>
|
||||
<edit name="family" mode="prepend">
|
||||
<string value=[prefer]/>
|
||||
...
|
||||
</edit>
|
||||
<edit name="family" mode="append">
|
||||
<string value=[accept]/>
|
||||
...
|
||||
</edit>
|
||||
<edit name="family" mode="append_last">
|
||||
<string value=[default]/>
|
||||
...
|
||||
</edit>
|
||||
</match>
|
||||
-->
|
||||
<!ELEMENT alias (family, prefer?, accept?, default?)>
|
||||
<!ELEMENT prefer (family)*>
|
||||
<!ELEMENT accept (family)*>
|
||||
<!ELEMENT default (family)*>
|
||||
<!ELEMENT family (#PCDATA)>
|
||||
<!ATTLIST family xml:space (default|preserve) 'preserve'>
|
||||
|
||||
<!ENTITY % expr 'int|double|string|matrix|bool|charset
|
||||
|name|const
|
||||
|or|and|eq|not_eq|less|less_eq|more|more_eq
|
||||
|plus|minus|times|divide|not|if'>
|
||||
|
||||
<!--
|
||||
Match and edit patterns.
|
||||
|
||||
If 'target' is 'pattern', execute the match before selecting a font.
|
||||
if 'target' is 'font', execute the match on the result of a font
|
||||
selection.
|
||||
-->
|
||||
<!ELEMENT match (test*, edit*)>
|
||||
<!ATTLIST match
|
||||
target (pattern|font) "pattern">
|
||||
|
||||
<!--
|
||||
Match a field in a pattern
|
||||
|
||||
if 'qual' is 'any', then the match succeeds if any value in the field matches.
|
||||
if 'qual' is 'all', then the match succeeds only if all values match.
|
||||
-->
|
||||
<!ELEMENT test (%expr;)>
|
||||
<!ATTLIST test
|
||||
qual (any|all) "any"
|
||||
name CDATA #REQUIRED
|
||||
compare (eq|not_eq|less|less_eq|more|more_eq) "eq">
|
||||
|
||||
<!--
|
||||
Edit a field in a pattern
|
||||
|
||||
The enclosed values are used together to edit the list of values
|
||||
associated with 'name'.
|
||||
|
||||
If 'name' matches one of those used in a test element for this match element:
|
||||
if 'mode' is 'assign', replace the matched value.
|
||||
if 'mode' is 'assign_replace', replace all of the values
|
||||
if 'mode' is 'prepend', insert before the matched value
|
||||
if 'mode' is 'append', insert after the matched value
|
||||
if 'mode' is 'prepend_first', insert before all of the values
|
||||
if 'mode' is 'append_last', insert after all of the values
|
||||
If 'name' doesn't match any of those used in a test element:
|
||||
if 'mode' is 'assign' or 'assign_replace, replace all of the values
|
||||
if 'mode' is 'prepend' or 'prepend_first', insert before all of the values
|
||||
if 'mode' is 'append' or 'append_last', insert after all of the values
|
||||
-->
|
||||
<!ELEMENT edit (%expr;)*>
|
||||
<!ATTLIST edit
|
||||
name CDATA #REQUIRED
|
||||
mode (assign|assign_replace|prepend|append|prepend_first|append_last) "assign">
|
||||
|
||||
<!--
|
||||
Elements of expressions follow
|
||||
-->
|
||||
<!ELEMENT int (#PCDATA)>
|
||||
<!ATTLIST int xml:space (default|preserve) 'preserve'>
|
||||
<!ELEMENT double (#PCDATA)>
|
||||
<!ATTLIST double xml:space (default|preserve) 'preserve'>
|
||||
<!ELEMENT string (#PCDATA)>
|
||||
<!ATTLIST string xml:space (default|preserve) 'preserve'>
|
||||
<!ELEMENT matrix (double,double,double,double)>
|
||||
<!ELEMENT bool (true|false)>
|
||||
<!ELEMENT charset (#PCDATA)>
|
||||
<!ATTLIST charset xml:space (default|preserve) 'preserve'>
|
||||
<!ELEMENT name (#PCDATA)>
|
||||
<!ATTLIST name xml:space (default|preserve) 'preserve'>
|
||||
<!ELEMENT const (#PCDATA)>
|
||||
<!ATTLIST const xml:space (default|preserve) 'preserve'>
|
||||
<!ELEMENT or (%expr;)*>
|
||||
<!ELEMENT and (%expr;)*>
|
||||
<!ELEMENT eq ((%expr;), (%expr;))>
|
||||
<!ELEMENT not_eq ((%expr;), (%expr;))>
|
||||
<!ELEMENT less ((%expr;), (%expr;))>
|
||||
<!ELEMENT less_eq ((%expr;), (%expr;))>
|
||||
<!ELEMENT more ((%expr;), (%expr;))>
|
||||
<!ELEMENT more_eq ((%expr;), (%expr;))>
|
||||
<!ELEMENT plus (%expr;)*>
|
||||
<!ELEMENT minus (%expr;)*>
|
||||
<!ELEMENT times (%expr;)*>
|
||||
<!ELEMENT divide (%expr;)*>
|
||||
<!ELEMENT not (%expr;)>
|
||||
<!ELEMENT if ((%expr;), (%expr;), (%expr;))>
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/sh
|
||||
FONTDIRS=fontdirs$$
|
||||
trap "rm $FONTDIRS" 0
|
||||
sh ./findfonts > $FONTDIRS
|
||||
cp fonts.conf.in fonts.conf
|
||||
chmod +w fonts.conf
|
||||
ed fonts.conf << EOF
|
||||
/FONTPATH_END/a
|
||||
<!-- Font directories found on `date` -->
|
||||
.
|
||||
+r $FONTDIRS
|
||||
a
|
||||
|
||||
.
|
||||
/FONTPATH_START/,/FONTPATH_END/d
|
||||
w
|
||||
q
|
||||
EOF
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
#include "../../libxml2/config.h"
|
||||
#if HAVE_ZLIB_H
|
||||
ZLIB=-lz
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define SharedLibFontconfig YES
|
||||
#endif
|
||||
|
||||
#ifndef SharedLibFontconfig
|
||||
#define SharedLibFontconfig NO
|
||||
#endif
|
||||
|
||||
#ifndef NormalLibFontconfig
|
||||
#define NormalLibFontconfig (!SharedLibFontConfig | ForceNormalLib)
|
||||
#endif
|
||||
|
||||
#ifndef DebugLibFontconfig
|
||||
#define DebugLibFontconfig NO
|
||||
#endif
|
||||
|
||||
#ifndef ProfileLibFontconfig
|
||||
#define ProfileLibFontconfig NO
|
||||
#endif
|
||||
|
||||
#define LibHeaders NO
|
||||
|
||||
FONTCONFIGSRC=.
|
||||
|
||||
FALLBACK_FONTS=$(FONTDIR)/Type1
|
||||
|
||||
#if SharedLibFontconfig
|
||||
#ifndef SharedFontconfigRev
|
||||
#define SharedFontconfigRev 1.0
|
||||
#endif
|
||||
SharedLibReferences(FONTCONFIG,Fontconfig,$(FONTCONFIGSRC),SOXLIBREV,SharedFontconfigRev)
|
||||
#else
|
||||
ProjectUnsharedLibReferences(FONTCONFIG,Fontconfig,$(FONTCONFIGSRC),BuildLibDir)
|
||||
#endif
|
||||
|
||||
#define DoNormalLib NormalLibFontconfig
|
||||
#define DoSharedLib SharedLibFontconfig
|
||||
#define DoExtraLib SharedLibFontconfig
|
||||
#define DoDebugLib DebugLibFontconfig
|
||||
#define DoProfileLib ProfileLibFontconfig
|
||||
#define HasSharedData YES
|
||||
#define LibName fontconfig
|
||||
SOFONTCONFIGREV=1.0
|
||||
#define SoRev SOFONTCONFIGREV
|
||||
|
||||
#include <Threads.tmpl>
|
||||
|
||||
#if SharedLibFontconfig
|
||||
INCLUDES=-I/usr/local/include/freetype2 -I/usr/include/libxml2 -I..
|
||||
FREETYPE2REQLIB = -L/usr/local/lib -lfreetype
|
||||
XML2REQLIB=-lxml2
|
||||
#else
|
||||
INCLUDES=-I../../freetype2 -I../../libxml2/include -I..
|
||||
FREETYPE2REQLIB = ../../freetype2/libfreetype.a
|
||||
XML2REQLIB=../../libxml2/.libs/libxml2.a $(ZLIB) -lm
|
||||
#endif
|
||||
DEFINES=-DFC_FALLBACK_FONTS='"$(FALLBACK_FONTS)"'
|
||||
|
||||
REQUIREDLIBS=$(LDPRELIBS) $(FREETYPE2REQLIB) $(XML2REQLIB)
|
||||
|
||||
SRCS=fcblanks.c fccache.c fccfg.c fccharset.c fcdbg.c fcdefault.c fcdir.c \
|
||||
fcfreetype.c fcfs.c fcinit.c fclist.c fcmatch.c fcmatrix.c fcname.c \
|
||||
fcpat.c fcstr.c fcxml.c
|
||||
|
||||
OBJS=fcblanks.o fccache.o fccfg.o fccharset.o fcdbg.o fcdefault.o fcdir.o \
|
||||
fcfreetype.o fcfs.o fcinit.o fclist.o fcmatch.o fcmatrix.o fcname.o \
|
||||
fcpat.o fcstr.o fcxml.o
|
||||
|
||||
#define LibInstallBuild YES
|
||||
#undef LinkBuildLibrary
|
||||
#define LinkBuildLibrary(lib) MakeDir($(BUILDLIBDIR)) @@\
|
||||
RemoveFile($(BUILDLIBDIR)/lib) @@\
|
||||
cd $(BUILDLIBDIR) && $(LN) $(BUILDLIBTOP)/$(CURRENT_DIR)/lib .
|
||||
|
||||
|
||||
#include <Library.tmpl>
|
||||
|
||||
#if DoSharedLib && SharedDataSeparation
|
||||
SpecialCObjectRule(sharedlib,NullParameter,$(SHLIBDEF))
|
||||
#endif
|
||||
|
||||
MANSUFFIX = $(LIBMANSUFFIX)
|
||||
InstallManPage(fontconfig,$(LIBMANDIR))
|
||||
DependTarget()
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* $XFree86$
|
||||
*
|
||||
* Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include "fcint.h"
|
||||
|
||||
FcBlanks *
|
||||
FcBlanksCreate (void)
|
||||
{
|
||||
FcBlanks *b;
|
||||
|
||||
b = malloc (sizeof (FcBlanks));
|
||||
if (!b)
|
||||
return 0;
|
||||
b->nblank = 0;
|
||||
b->sblank = 0;
|
||||
b->blanks = 0;
|
||||
return b;
|
||||
}
|
||||
|
||||
void
|
||||
FcBlanksDestroy (FcBlanks *b)
|
||||
{
|
||||
if (b->blanks)
|
||||
free (b->blanks);
|
||||
free (b);
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcBlanksAdd (FcBlanks *b, FcChar32 ucs4)
|
||||
{
|
||||
FcChar32 *c;
|
||||
int sblank;
|
||||
|
||||
for (sblank = 0; sblank < b->nblank; sblank++)
|
||||
if (b->blanks[sblank] == ucs4)
|
||||
return FcTrue;
|
||||
|
||||
if (b->nblank == b->sblank)
|
||||
{
|
||||
sblank = b->sblank + 32;
|
||||
if (b->blanks)
|
||||
c = (FcChar32 *) realloc (b->blanks, sblank * sizeof (FcChar32));
|
||||
else
|
||||
c = (FcChar32 *) malloc (sblank * sizeof (FcChar32));
|
||||
if (!c)
|
||||
return FcFalse;
|
||||
b->sblank = sblank;
|
||||
b->blanks = c;
|
||||
}
|
||||
b->blanks[b->nblank++] = ucs4;
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcBlanksIsMember (FcBlanks *b, FcChar32 ucs4)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < b->nblank; i++)
|
||||
if (b->blanks[i] == ucs4)
|
||||
return FcTrue;
|
||||
return FcFalse;
|
||||
}
|
|
@ -0,0 +1,592 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include "fcint.h"
|
||||
|
||||
static unsigned int
|
||||
FcFileCacheHash (const char *string)
|
||||
{
|
||||
unsigned int h = 0;
|
||||
char c;
|
||||
|
||||
while ((c = *string++))
|
||||
h = (h << 1) ^ c;
|
||||
return h;
|
||||
}
|
||||
|
||||
char *
|
||||
FcFileCacheFind (FcFileCache *cache,
|
||||
const char *file,
|
||||
int id,
|
||||
int *count)
|
||||
{
|
||||
unsigned int hash;
|
||||
const char *match;
|
||||
FcFileCacheEnt *c, *name;
|
||||
int maxid;
|
||||
struct stat statb;
|
||||
|
||||
match = file;
|
||||
|
||||
hash = FcFileCacheHash (match);
|
||||
name = 0;
|
||||
maxid = -1;
|
||||
for (c = cache->ents[hash % FC_FILE_CACHE_HASH_SIZE]; c; c = c->next)
|
||||
{
|
||||
if (c->hash == hash && !strcmp (match, c->file))
|
||||
{
|
||||
if (c->id > maxid)
|
||||
maxid = c->id;
|
||||
if (c->id == id)
|
||||
{
|
||||
if (stat (file, &statb) < 0)
|
||||
{
|
||||
if (FcDebug () & FC_DBG_CACHE)
|
||||
printf (" file missing\n");
|
||||
return 0;
|
||||
}
|
||||
if (statb.st_mtime != c->time)
|
||||
{
|
||||
if (FcDebug () & FC_DBG_CACHE)
|
||||
printf (" timestamp mismatch (was %d is %d)\n",
|
||||
(int) c->time, (int) statb.st_mtime);
|
||||
return 0;
|
||||
}
|
||||
if (!c->referenced)
|
||||
{
|
||||
cache->referenced++;
|
||||
c->referenced = FcTrue;
|
||||
}
|
||||
name = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!name)
|
||||
return 0;
|
||||
*count = maxid + 1;
|
||||
return name->name;
|
||||
}
|
||||
|
||||
/*
|
||||
* Cache file syntax is quite simple:
|
||||
*
|
||||
* "file_name" id time "font_name" \n
|
||||
*/
|
||||
|
||||
static FcBool
|
||||
FcFileCacheReadString (FILE *f, char *dest, int len)
|
||||
{
|
||||
int c;
|
||||
FcBool escape;
|
||||
|
||||
while ((c = getc (f)) != EOF)
|
||||
if (c == '"')
|
||||
break;
|
||||
if (c == EOF)
|
||||
return FcFalse;
|
||||
if (len == 0)
|
||||
return FcFalse;
|
||||
|
||||
escape = FcFalse;
|
||||
while ((c = getc (f)) != EOF)
|
||||
{
|
||||
if (!escape)
|
||||
{
|
||||
switch (c) {
|
||||
case '"':
|
||||
*dest++ = '\0';
|
||||
return FcTrue;
|
||||
case '\\':
|
||||
escape = FcTrue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (--len <= 1)
|
||||
return FcFalse;
|
||||
*dest++ = c;
|
||||
escape = FcFalse;
|
||||
}
|
||||
return FcFalse;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcFileCacheReadUlong (FILE *f, unsigned long *dest)
|
||||
{
|
||||
unsigned long t;
|
||||
int c;
|
||||
|
||||
while ((c = getc (f)) != EOF)
|
||||
{
|
||||
if (!isspace (c))
|
||||
break;
|
||||
}
|
||||
if (c == EOF)
|
||||
return FcFalse;
|
||||
t = 0;
|
||||
for (;;)
|
||||
{
|
||||
if (c == EOF || isspace (c))
|
||||
break;
|
||||
if (!isdigit (c))
|
||||
return FcFalse;
|
||||
t = t * 10 + (c - '0');
|
||||
c = getc (f);
|
||||
}
|
||||
*dest = t;
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcFileCacheReadInt (FILE *f, int *dest)
|
||||
{
|
||||
unsigned long t;
|
||||
FcBool ret;
|
||||
|
||||
ret = FcFileCacheReadUlong (f, &t);
|
||||
if (ret)
|
||||
*dest = (int) t;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcFileCacheReadTime (FILE *f, time_t *dest)
|
||||
{
|
||||
unsigned long t;
|
||||
FcBool ret;
|
||||
|
||||
ret = FcFileCacheReadUlong (f, &t);
|
||||
if (ret)
|
||||
*dest = (time_t) t;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcFileCacheAdd (FcFileCache *cache,
|
||||
const char *file,
|
||||
int id,
|
||||
time_t time,
|
||||
const char *name,
|
||||
FcBool replace)
|
||||
{
|
||||
FcFileCacheEnt *c;
|
||||
FcFileCacheEnt **prev, *old;
|
||||
unsigned int hash;
|
||||
|
||||
if (FcDebug () & FC_DBG_CACHE)
|
||||
{
|
||||
printf ("%s face %s/%d as %s\n", replace ? "Replace" : "Add",
|
||||
file, id, name);
|
||||
}
|
||||
hash = FcFileCacheHash (file);
|
||||
for (prev = &cache->ents[hash % FC_FILE_CACHE_HASH_SIZE];
|
||||
(old = *prev);
|
||||
prev = &(*prev)->next)
|
||||
{
|
||||
if (old->hash == hash && old->id == id && !strcmp (old->file, file))
|
||||
break;
|
||||
}
|
||||
if (*prev)
|
||||
{
|
||||
if (!replace)
|
||||
return FcFalse;
|
||||
|
||||
old = *prev;
|
||||
if (old->referenced)
|
||||
cache->referenced--;
|
||||
*prev = old->next;
|
||||
free (old);
|
||||
cache->entries--;
|
||||
}
|
||||
|
||||
c = malloc (sizeof (FcFileCacheEnt) +
|
||||
strlen (file) + 1 +
|
||||
strlen (name) + 1);
|
||||
if (!c)
|
||||
return FcFalse;
|
||||
c->next = *prev;
|
||||
*prev = c;
|
||||
c->hash = hash;
|
||||
c->file = (char *) (c + 1);
|
||||
c->id = id;
|
||||
c->name = c->file + strlen (file) + 1;
|
||||
strcpy (c->file, file);
|
||||
c->time = time;
|
||||
c->referenced = replace;
|
||||
strcpy (c->name, name);
|
||||
cache->entries++;
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
FcFileCache *
|
||||
FcFileCacheCreate (void)
|
||||
{
|
||||
FcFileCache *cache;
|
||||
int h;
|
||||
|
||||
cache = malloc (sizeof (FcFileCache));
|
||||
if (!cache)
|
||||
return 0;
|
||||
for (h = 0; h < FC_FILE_CACHE_HASH_SIZE; h++)
|
||||
cache->ents[h] = 0;
|
||||
cache->entries = 0;
|
||||
cache->referenced = 0;
|
||||
cache->updated = FcFalse;
|
||||
return cache;
|
||||
}
|
||||
|
||||
void
|
||||
FcFileCacheDestroy (FcFileCache *cache)
|
||||
{
|
||||
FcFileCacheEnt *c, *next;
|
||||
int h;
|
||||
|
||||
for (h = 0; h < FC_FILE_CACHE_HASH_SIZE; h++)
|
||||
{
|
||||
for (c = cache->ents[h]; c; c = next)
|
||||
{
|
||||
next = c->next;
|
||||
free (c);
|
||||
}
|
||||
}
|
||||
free (cache);
|
||||
}
|
||||
|
||||
void
|
||||
FcFileCacheLoad (FcFileCache *cache,
|
||||
const char *cache_file)
|
||||
{
|
||||
FILE *f;
|
||||
char file[8192];
|
||||
int id;
|
||||
time_t time;
|
||||
char name[8192];
|
||||
|
||||
f = fopen (cache_file, "r");
|
||||
if (!f)
|
||||
return;
|
||||
|
||||
cache->updated = FcFalse;
|
||||
while (FcFileCacheReadString (f, file, sizeof (file)) &&
|
||||
FcFileCacheReadInt (f, &id) &&
|
||||
FcFileCacheReadTime (f, &time) &&
|
||||
FcFileCacheReadString (f, name, sizeof (name)))
|
||||
{
|
||||
(void) FcFileCacheAdd (cache, file, id, time, name, FcFalse);
|
||||
}
|
||||
fclose (f);
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcFileCacheUpdate (FcFileCache *cache,
|
||||
const char *file,
|
||||
int id,
|
||||
const char *name)
|
||||
{
|
||||
const char *match;
|
||||
struct stat statb;
|
||||
FcBool ret;
|
||||
|
||||
match = file;
|
||||
|
||||
if (stat (file, &statb) < 0)
|
||||
return FcFalse;
|
||||
ret = FcFileCacheAdd (cache, match, id,
|
||||
statb.st_mtime, name, FcTrue);
|
||||
if (ret)
|
||||
cache->updated = FcTrue;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcFileCacheWriteString (FILE *f, char *string)
|
||||
{
|
||||
char c;
|
||||
|
||||
if (putc ('"', f) == EOF)
|
||||
return FcFalse;
|
||||
while ((c = *string++))
|
||||
{
|
||||
switch (c) {
|
||||
case '"':
|
||||
case '\\':
|
||||
if (putc ('\\', f) == EOF)
|
||||
return FcFalse;
|
||||
/* fall through */
|
||||
default:
|
||||
if (putc (c, f) == EOF)
|
||||
return FcFalse;
|
||||
}
|
||||
}
|
||||
if (putc ('"', f) == EOF)
|
||||
return FcFalse;
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcFileCacheWriteUlong (FILE *f, unsigned long t)
|
||||
{
|
||||
int pow;
|
||||
unsigned long temp, digit;
|
||||
|
||||
temp = t;
|
||||
pow = 1;
|
||||
while (temp >= 10)
|
||||
{
|
||||
temp /= 10;
|
||||
pow *= 10;
|
||||
}
|
||||
temp = t;
|
||||
while (pow)
|
||||
{
|
||||
digit = temp / pow;
|
||||
if (putc ((char) digit + '0', f) == EOF)
|
||||
return FcFalse;
|
||||
temp = temp - pow * digit;
|
||||
pow = pow / 10;
|
||||
}
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcFileCacheWriteInt (FILE *f, int i)
|
||||
{
|
||||
return FcFileCacheWriteUlong (f, (unsigned long) i);
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcFileCacheWriteTime (FILE *f, time_t t)
|
||||
{
|
||||
return FcFileCacheWriteUlong (f, (unsigned long) t);
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcFileCacheSave (FcFileCache *cache,
|
||||
const char *cache_file)
|
||||
{
|
||||
char *lck;
|
||||
char *tmp;
|
||||
FILE *f;
|
||||
int h;
|
||||
FcFileCacheEnt *c;
|
||||
|
||||
if (!cache->updated && cache->referenced == cache->entries)
|
||||
return FcTrue;
|
||||
|
||||
lck = malloc (strlen (cache_file)*2 + 4);
|
||||
if (!lck)
|
||||
goto bail0;
|
||||
tmp = lck + strlen (cache_file) + 2;
|
||||
strcpy (lck, cache_file);
|
||||
strcat (lck, "L");
|
||||
strcpy (tmp, cache_file);
|
||||
strcat (tmp, "T");
|
||||
if (link (lck, cache_file) < 0 && errno != ENOENT)
|
||||
goto bail1;
|
||||
if (access (tmp, F_OK) == 0)
|
||||
goto bail2;
|
||||
f = fopen (tmp, "w");
|
||||
if (!f)
|
||||
goto bail2;
|
||||
|
||||
for (h = 0; h < FC_FILE_CACHE_HASH_SIZE; h++)
|
||||
{
|
||||
for (c = cache->ents[h]; c; c = c->next)
|
||||
{
|
||||
if (!c->referenced)
|
||||
continue;
|
||||
if (!FcFileCacheWriteString (f, c->file))
|
||||
goto bail4;
|
||||
if (putc (' ', f) == EOF)
|
||||
goto bail4;
|
||||
if (!FcFileCacheWriteInt (f, c->id))
|
||||
goto bail4;
|
||||
if (putc (' ', f) == EOF)
|
||||
goto bail4;
|
||||
if (!FcFileCacheWriteTime (f, c->time))
|
||||
goto bail4;
|
||||
if (putc (' ', f) == EOF)
|
||||
goto bail4;
|
||||
if (!FcFileCacheWriteString (f, c->name))
|
||||
goto bail4;
|
||||
if (putc ('\n', f) == EOF)
|
||||
goto bail4;
|
||||
}
|
||||
}
|
||||
|
||||
if (fclose (f) == EOF)
|
||||
goto bail3;
|
||||
|
||||
if (rename (tmp, cache_file) < 0)
|
||||
goto bail3;
|
||||
|
||||
unlink (lck);
|
||||
cache->updated = FcFalse;
|
||||
return FcTrue;
|
||||
|
||||
bail4:
|
||||
fclose (f);
|
||||
bail3:
|
||||
unlink (tmp);
|
||||
bail2:
|
||||
unlink (lck);
|
||||
bail1:
|
||||
free (lck);
|
||||
bail0:
|
||||
return FcFalse;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcFileCacheReadDir (FcFontSet *set, const char *cache_file)
|
||||
{
|
||||
FcPattern *font;
|
||||
FILE *f;
|
||||
char *path;
|
||||
char *base;
|
||||
char file[8192];
|
||||
int id;
|
||||
char name[8192];
|
||||
FcBool ret = FcFalse;
|
||||
|
||||
if (FcDebug () & FC_DBG_CACHE)
|
||||
{
|
||||
printf ("FcFileCacheReadDir cache_file \"%s\"\n", cache_file);
|
||||
}
|
||||
|
||||
f = fopen (cache_file, "r");
|
||||
if (!f)
|
||||
{
|
||||
if (FcDebug () & FC_DBG_CACHE)
|
||||
{
|
||||
printf (" no cache file\n");
|
||||
}
|
||||
goto bail0;
|
||||
}
|
||||
|
||||
base = strrchr (cache_file, '/');
|
||||
if (!base)
|
||||
goto bail1;
|
||||
base++;
|
||||
path = malloc (base - cache_file + 8192 + 1);
|
||||
if (!path)
|
||||
goto bail1;
|
||||
memcpy (path, cache_file, base - cache_file);
|
||||
base = path + (base - cache_file);
|
||||
|
||||
while (FcFileCacheReadString (f, file, sizeof (file)) &&
|
||||
FcFileCacheReadInt (f, &id) &&
|
||||
FcFileCacheReadString (f, name, sizeof (name)))
|
||||
{
|
||||
font = FcNameParse (name);
|
||||
if (font)
|
||||
{
|
||||
strcpy (base, file);
|
||||
if (FcDebug () & FC_DBG_CACHEV)
|
||||
{
|
||||
printf (" dir cache file \"%s\"\n", file);
|
||||
}
|
||||
FcPatternAddString (font, FC_FILE, path);
|
||||
if (!FcFontSetAdd (set, font))
|
||||
goto bail2;
|
||||
}
|
||||
}
|
||||
if (FcDebug () & FC_DBG_CACHE)
|
||||
{
|
||||
printf (" cache loaded\n");
|
||||
}
|
||||
|
||||
ret = FcTrue;
|
||||
bail2:
|
||||
free (path);
|
||||
bail1:
|
||||
fclose (f);
|
||||
bail0:
|
||||
return ret;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcFileCacheWriteDir (FcFontSet *set, const char *cache_file)
|
||||
{
|
||||
FcPattern *font;
|
||||
FILE *f;
|
||||
char *name;
|
||||
char *file, *base;
|
||||
int n;
|
||||
int id;
|
||||
FcBool ret;
|
||||
|
||||
if (FcDebug () & FC_DBG_CACHE)
|
||||
printf ("FcFileCacheWriteDir cache_file \"%s\"\n", cache_file);
|
||||
|
||||
f = fopen (cache_file, "w");
|
||||
if (!f)
|
||||
{
|
||||
if (FcDebug () & FC_DBG_CACHE)
|
||||
printf (" can't create \"%s\"\n", cache_file);
|
||||
goto bail0;
|
||||
}
|
||||
for (n = 0; n < set->nfont; n++)
|
||||
{
|
||||
font = set->fonts[n];
|
||||
if (FcPatternGetString (font, FC_FILE, 0, &file) != FcResultMatch)
|
||||
goto bail1;
|
||||
base = strrchr (file, '/');
|
||||
if (base)
|
||||
base = base + 1;
|
||||
else
|
||||
base = file;
|
||||
if (FcPatternGetInteger (font, FC_INDEX, 0, &id) != FcResultMatch)
|
||||
goto bail1;
|
||||
if (FcDebug () & FC_DBG_CACHEV)
|
||||
printf (" write file \"%s\"\n", base);
|
||||
if (!FcFileCacheWriteString (f, base))
|
||||
goto bail1;
|
||||
if (putc (' ', f) == EOF)
|
||||
goto bail1;
|
||||
if (!FcFileCacheWriteInt (f, id))
|
||||
goto bail1;
|
||||
if (putc (' ', f) == EOF)
|
||||
goto bail1;
|
||||
name = FcNameUnparse (font);
|
||||
if (!name)
|
||||
goto bail1;
|
||||
ret = FcFileCacheWriteString (f, name);
|
||||
free (name);
|
||||
if (!ret)
|
||||
goto bail1;
|
||||
if (putc ('\n', f) == EOF)
|
||||
goto bail1;
|
||||
}
|
||||
if (fclose (f) == EOF)
|
||||
goto bail0;
|
||||
|
||||
if (FcDebug () & FC_DBG_CACHE)
|
||||
printf (" cache written\n");
|
||||
return FcTrue;
|
||||
|
||||
bail1:
|
||||
fclose (f);
|
||||
bail0:
|
||||
unlink (cache_file);
|
||||
return FcFalse;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,272 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "fcint.h"
|
||||
|
||||
void
|
||||
FcValuePrint (FcValue v)
|
||||
{
|
||||
switch (v.type) {
|
||||
case FcTypeVoid:
|
||||
printf (" <void>");
|
||||
break;
|
||||
case FcTypeInteger:
|
||||
printf (" %d", v.u.i);
|
||||
break;
|
||||
case FcTypeDouble:
|
||||
printf (" %g", v.u.d);
|
||||
break;
|
||||
case FcTypeString:
|
||||
printf (" \"%s\"", v.u.s);
|
||||
break;
|
||||
case FcTypeBool:
|
||||
printf (" %s", v.u.b ? "FcTrue" : "FcFalse");
|
||||
break;
|
||||
case FcTypeMatrix:
|
||||
printf (" (%f %f; %f %f)", v.u.m->xx, v.u.m->xy, v.u.m->yx, v.u.m->yy);
|
||||
break;
|
||||
case FcTypeCharSet: /* XXX */
|
||||
printf (" set");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FcValueListPrint (FcValueList *l)
|
||||
{
|
||||
for (; l; l = l->next)
|
||||
FcValuePrint (l->value);
|
||||
}
|
||||
|
||||
void
|
||||
FcPatternPrint (FcPattern *p)
|
||||
{
|
||||
int i;
|
||||
FcPatternElt *e;
|
||||
|
||||
if (!p)
|
||||
{
|
||||
printf ("Null pattern\n");
|
||||
return;
|
||||
}
|
||||
printf ("Pattern %d of %d\n", p->num, p->size);
|
||||
for (i = 0; i < p->num; i++)
|
||||
{
|
||||
e = &p->elts[i];
|
||||
printf ("\t%s:", e->object);
|
||||
FcValueListPrint (e->values);
|
||||
printf ("\n");
|
||||
}
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
void
|
||||
FcOpPrint (FcOp op)
|
||||
{
|
||||
switch (op) {
|
||||
case FcOpInteger: printf ("Integer"); break;
|
||||
case FcOpDouble: printf ("Double"); break;
|
||||
case FcOpString: printf ("String"); break;
|
||||
case FcOpMatrix: printf ("Matrix"); break;
|
||||
case FcOpBool: printf ("Bool"); break;
|
||||
case FcOpCharSet: printf ("CharSet"); break;
|
||||
case FcOpField: printf ("Field"); break;
|
||||
case FcOpConst: printf ("Const"); break;
|
||||
case FcOpAssign: printf ("Assign"); break;
|
||||
case FcOpAssignReplace: printf ("AssignReplace"); break;
|
||||
case FcOpPrepend: printf ("Prepend"); break;
|
||||
case FcOpPrependFirst: printf ("PrependFirst"); break;
|
||||
case FcOpAppend: printf ("Append"); break;
|
||||
case FcOpAppendLast: printf ("AppendLast"); break;
|
||||
case FcOpQuest: printf ("Quest"); break;
|
||||
case FcOpOr: printf ("Or"); break;
|
||||
case FcOpAnd: printf ("And"); break;
|
||||
case FcOpEqual: printf ("Equal"); break;
|
||||
case FcOpContains: printf ("Contains"); break;
|
||||
case FcOpNotEqual: printf ("NotEqual"); break;
|
||||
case FcOpLess: printf ("Less"); break;
|
||||
case FcOpLessEqual: printf ("LessEqual"); break;
|
||||
case FcOpMore: printf ("More"); break;
|
||||
case FcOpMoreEqual: printf ("MoreEqual"); break;
|
||||
case FcOpPlus: printf ("Plus"); break;
|
||||
case FcOpMinus: printf ("Minus"); break;
|
||||
case FcOpTimes: printf ("Times"); break;
|
||||
case FcOpDivide: printf ("Divide"); break;
|
||||
case FcOpNot: printf ("Not"); break;
|
||||
case FcOpNil: printf ("Nil"); break;
|
||||
case FcOpComma: printf ("Comma"); break;
|
||||
case FcOpInvalid: printf ("Invalid"); break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FcExprPrint (FcExpr *expr)
|
||||
{
|
||||
switch (expr->op) {
|
||||
case FcOpInteger: printf ("%d", expr->u.ival); break;
|
||||
case FcOpDouble: printf ("%g", expr->u.dval); break;
|
||||
case FcOpString: printf ("\"%s\"", expr->u.sval); break;
|
||||
case FcOpMatrix: printf ("[%g %g %g %g]",
|
||||
expr->u.mval->xx,
|
||||
expr->u.mval->xy,
|
||||
expr->u.mval->yx,
|
||||
expr->u.mval->yy);
|
||||
case FcOpBool: printf ("%s", expr->u.bval ? "true" : "false"); break;
|
||||
case FcOpField: printf ("%s", expr->u.field); break;
|
||||
case FcOpQuest:
|
||||
FcExprPrint (expr->u.tree.left);
|
||||
printf (" quest ");
|
||||
FcExprPrint (expr->u.tree.right->u.tree.left);
|
||||
printf (" colon ");
|
||||
FcExprPrint (expr->u.tree.right->u.tree.right);
|
||||
break;
|
||||
case FcOpOr:
|
||||
case FcOpAnd:
|
||||
case FcOpEqual:
|
||||
case FcOpContains:
|
||||
case FcOpNotEqual:
|
||||
case FcOpLess:
|
||||
case FcOpLessEqual:
|
||||
case FcOpMore:
|
||||
case FcOpMoreEqual:
|
||||
case FcOpPlus:
|
||||
case FcOpMinus:
|
||||
case FcOpTimes:
|
||||
case FcOpDivide:
|
||||
FcExprPrint (expr->u.tree.left);
|
||||
printf (" ");
|
||||
switch (expr->op) {
|
||||
case FcOpOr: printf ("Or"); break;
|
||||
case FcOpAnd: printf ("And"); break;
|
||||
case FcOpEqual: printf ("Equal"); break;
|
||||
case FcOpContains: printf ("Contains"); break;
|
||||
case FcOpNotEqual: printf ("NotEqual"); break;
|
||||
case FcOpLess: printf ("Less"); break;
|
||||
case FcOpLessEqual: printf ("LessEqual"); break;
|
||||
case FcOpMore: printf ("More"); break;
|
||||
case FcOpMoreEqual: printf ("MoreEqual"); break;
|
||||
case FcOpPlus: printf ("Plus"); break;
|
||||
case FcOpMinus: printf ("Minus"); break;
|
||||
case FcOpTimes: printf ("Times"); break;
|
||||
case FcOpDivide: printf ("Divide"); break;
|
||||
default: break;
|
||||
}
|
||||
printf (" ");
|
||||
FcExprPrint (expr->u.tree.right);
|
||||
break;
|
||||
case FcOpNot:
|
||||
printf ("Not ");
|
||||
FcExprPrint (expr->u.tree.left);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FcTestPrint (FcTest *test)
|
||||
{
|
||||
switch (test->qual) {
|
||||
case FcQualAny:
|
||||
printf ("any ");
|
||||
break;
|
||||
case FcQualAll:
|
||||
printf ("all ");
|
||||
break;
|
||||
}
|
||||
printf ("%s ", test->field);
|
||||
FcOpPrint (test->op);
|
||||
printf (" ");
|
||||
FcExprPrint (test->expr);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
void
|
||||
FcEditPrint (FcEdit *edit)
|
||||
{
|
||||
printf ("Edit %s ", edit->field);
|
||||
FcOpPrint (edit->op);
|
||||
printf (" ");
|
||||
FcExprPrint (edit->expr);
|
||||
}
|
||||
|
||||
void
|
||||
FcSubstPrint (FcSubst *subst)
|
||||
{
|
||||
FcEdit *e;
|
||||
FcTest *t;
|
||||
|
||||
printf ("match\n");
|
||||
for (t = subst->test; t; t = t->next)
|
||||
{
|
||||
printf ("\t");
|
||||
FcTestPrint (t);
|
||||
}
|
||||
printf ("edit\n");
|
||||
for (e = subst->edit; e; e = e->next)
|
||||
{
|
||||
printf ("\t");
|
||||
FcEditPrint (e);
|
||||
printf (";\n");
|
||||
}
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
void
|
||||
FcFontSetPrint (FcFontSet *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf ("FontSet %d of %d\n", s->nfont, s->sfont);
|
||||
for (i = 0; i < s->nfont; i++)
|
||||
{
|
||||
printf ("Font %d ", i);
|
||||
FcPatternPrint (s->fonts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
FcDebug (void)
|
||||
{
|
||||
static int initialized;
|
||||
static int debug;
|
||||
|
||||
if (!initialized)
|
||||
{
|
||||
char *e;
|
||||
|
||||
initialized = 1;
|
||||
e = getenv ("FC_DEBUG");
|
||||
if (e)
|
||||
{
|
||||
printf ("FC_DEBUG=%s\n", e);
|
||||
debug = atoi (e);
|
||||
if (debug < 0)
|
||||
debug = 0;
|
||||
}
|
||||
}
|
||||
return debug;
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include "fcint.h"
|
||||
|
||||
static struct {
|
||||
char *field;
|
||||
FcBool value;
|
||||
} FcBoolDefaults[] = {
|
||||
{ FC_HINTING, FcTrue }, /* !FT_LOAD_NO_HINTING */
|
||||
{ FC_VERTICAL_LAYOUT, FcFalse }, /* FC_LOAD_VERTICAL_LAYOUT */
|
||||
{ FC_AUTOHINT, FcFalse }, /* FC_LOAD_FORCE_AUTOHINT */
|
||||
{ FC_GLOBAL_ADVANCE, FcTrue }, /* !FC_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH */
|
||||
};
|
||||
|
||||
#define NUM_FC_BOOL_DEFAULTS (sizeof FcBoolDefaults / sizeof FcBoolDefaults[0])
|
||||
|
||||
void
|
||||
FcDefaultSubstitute (FcPattern *pattern)
|
||||
{
|
||||
FcValue v;
|
||||
int i;
|
||||
|
||||
if (FcPatternGet (pattern, FC_STYLE, 0, &v) == FcResultNoMatch)
|
||||
{
|
||||
if (FcPatternGet (pattern, FC_WEIGHT, 0, &v) == FcResultNoMatch )
|
||||
{
|
||||
FcPatternAddInteger (pattern, FC_WEIGHT, FC_WEIGHT_MEDIUM);
|
||||
}
|
||||
if (FcPatternGet (pattern, FC_SLANT, 0, &v) == FcResultNoMatch)
|
||||
{
|
||||
FcPatternAddInteger (pattern, FC_SLANT, FC_SLANT_ROMAN);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_FC_BOOL_DEFAULTS; i++)
|
||||
if (FcPatternGet (pattern, FcBoolDefaults[i].field, 0, &v) == FcResultNoMatch)
|
||||
FcPatternAddBool (pattern, FcBoolDefaults[i].field, FcBoolDefaults[i].value);
|
||||
|
||||
if (FcPatternGet (pattern, FC_PIXEL_SIZE, 0, &v) == FcResultNoMatch)
|
||||
{
|
||||
double dpi, size, scale;
|
||||
|
||||
if (FcPatternGetDouble (pattern, FC_SIZE, 0, &size) != FcResultMatch)
|
||||
{
|
||||
size = 12.0;
|
||||
(void) FcPatternDel (pattern, FC_SIZE);
|
||||
FcPatternAddDouble (pattern, FC_SIZE, size);
|
||||
}
|
||||
if (FcPatternGetDouble (pattern, FC_SCALE, 0, &scale) != FcResultMatch)
|
||||
{
|
||||
scale = 1.0;
|
||||
(void) FcPatternDel (pattern, FC_SCALE);
|
||||
FcPatternAddDouble (pattern, FC_SCALE, scale);
|
||||
}
|
||||
size *= scale;
|
||||
if (FcPatternGetDouble (pattern, FC_DPI, 0, &dpi) != FcResultMatch)
|
||||
{
|
||||
dpi = 75.0;
|
||||
(void) FcPatternDel (pattern, FC_DPI);
|
||||
FcPatternAddDouble (pattern, FC_DPI, dpi);
|
||||
}
|
||||
size *= dpi / 72.0;
|
||||
FcPatternAddDouble (pattern, FC_PIXEL_SIZE, size);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "fcint.h"
|
||||
|
||||
#define FC_INVALID_FONT_FILE "."
|
||||
|
||||
FcBool
|
||||
FcFileScan (FcFontSet *set,
|
||||
FcFileCache *cache,
|
||||
FcBlanks *blanks,
|
||||
const char *file,
|
||||
FcBool force)
|
||||
{
|
||||
int id;
|
||||
char *name;
|
||||
FcPattern *font;
|
||||
FcBool ret = FcTrue;
|
||||
int count;
|
||||
|
||||
id = 0;
|
||||
do
|
||||
{
|
||||
if (!force && cache)
|
||||
name = FcFileCacheFind (cache, file, id, &count);
|
||||
else
|
||||
name = 0;
|
||||
if (name)
|
||||
{
|
||||
/* "." means the file doesn't contain a font */
|
||||
if (strcmp (name, FC_INVALID_FONT_FILE) != 0)
|
||||
{
|
||||
font = FcNameParse (name);
|
||||
if (font)
|
||||
FcPatternAddString (font, FC_FILE, file);
|
||||
}
|
||||
else
|
||||
font = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FcDebug () & FC_DBG_SCAN)
|
||||
{
|
||||
printf ("\tScanning file %s...", file);
|
||||
fflush (stdout);
|
||||
}
|
||||
font = FcFreeTypeQuery (file, id, blanks, &count);
|
||||
if (FcDebug () & FC_DBG_SCAN)
|
||||
printf ("done\n");
|
||||
if (!force && cache)
|
||||
{
|
||||
if (font)
|
||||
{
|
||||
FcChar8 *unparse;
|
||||
|
||||
unparse = FcNameUnparse (font);
|
||||
if (unparse)
|
||||
{
|
||||
(void) FcFileCacheUpdate (cache, file, id, unparse);
|
||||
free (unparse);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* negative cache files not containing fonts */
|
||||
FcFileCacheUpdate (cache, file, id, FC_INVALID_FONT_FILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (font)
|
||||
{
|
||||
if (!FcFontSetAdd (set, font))
|
||||
{
|
||||
FcPatternDestroy (font);
|
||||
font = 0;
|
||||
ret = FcFalse;
|
||||
}
|
||||
}
|
||||
id++;
|
||||
} while (font && ret && id < count);
|
||||
return ret;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcDirScan (FcFontSet *set,
|
||||
FcFileCache *cache,
|
||||
FcBlanks *blanks,
|
||||
const char *dir,
|
||||
FcBool force)
|
||||
{
|
||||
DIR *d;
|
||||
struct dirent *e;
|
||||
char *file;
|
||||
char *base;
|
||||
FcBool ret = FcTrue;
|
||||
|
||||
file = (char *) malloc (strlen (dir) + 1 + 256 + 1);
|
||||
if (!file)
|
||||
return FcFalse;
|
||||
|
||||
strcpy (file, dir);
|
||||
strcat (file, "/");
|
||||
base = file + strlen (file);
|
||||
if (!force)
|
||||
{
|
||||
strcpy (base, FC_DIR_CACHE_FILE);
|
||||
|
||||
if (FcFileCacheReadDir (set, file))
|
||||
{
|
||||
free (file);
|
||||
return FcTrue;
|
||||
}
|
||||
}
|
||||
|
||||
d = opendir (dir);
|
||||
if (!d)
|
||||
{
|
||||
free (file);
|
||||
return FcFalse;
|
||||
}
|
||||
while (ret && (e = readdir (d)))
|
||||
{
|
||||
if (e->d_name[0] != '.')
|
||||
{
|
||||
strcpy (base, e->d_name);
|
||||
FcFileScan (set, cache, blanks, file, force);
|
||||
}
|
||||
}
|
||||
free (file);
|
||||
closedir (d);
|
||||
return ret;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcDirSave (FcFontSet *set, const char *dir)
|
||||
{
|
||||
char *file;
|
||||
char *base;
|
||||
FcBool ret;
|
||||
|
||||
file = (char *) malloc (strlen (dir) + 1 + 256 + 1);
|
||||
if (!file)
|
||||
return FcFalse;
|
||||
|
||||
strcpy (file, dir);
|
||||
strcat (file, "/");
|
||||
base = file + strlen (file);
|
||||
strcpy (base, FC_DIR_CACHE_FILE);
|
||||
ret = FcFileCacheWriteDir (set, file);
|
||||
free (file);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "fcint.h"
|
||||
#include <freetype/freetype.h>
|
||||
#include <freetype/internal/ftobjs.h>
|
||||
#include <freetype/tttables.h>
|
||||
#include <fontconfig/fcfreetype.h>
|
||||
|
||||
static const struct {
|
||||
int bit;
|
||||
char *name;
|
||||
} FcCodePageRange[] = {
|
||||
{ 0, FC_LANG_LATIN_1 },
|
||||
{ 1, FC_LANG_LATIN_2_EASTERN_EUROPE },
|
||||
{ 2, FC_LANG_CYRILLIC },
|
||||
{ 3, FC_LANG_GREEK },
|
||||
{ 4, FC_LANG_TURKISH },
|
||||
{ 5, FC_LANG_HEBREW },
|
||||
{ 6, FC_LANG_ARABIC },
|
||||
{ 7, FC_LANG_WINDOWS_BALTIC },
|
||||
{ 8, FC_LANG_VIETNAMESE },
|
||||
/* 9-15 reserved for Alternate ANSI */
|
||||
{ 16, FC_LANG_THAI },
|
||||
{ 17, FC_LANG_JAPANESE },
|
||||
{ 18, FC_LANG_SIMPLIFIED_CHINESE },
|
||||
{ 19, FC_LANG_KOREAN_WANSUNG },
|
||||
{ 20, FC_LANG_TRADITIONAL_CHINESE },
|
||||
{ 21, FC_LANG_KOREAN_JOHAB },
|
||||
/* 22-28 reserved for Alternate ANSI & OEM */
|
||||
{ 29, FC_LANG_MACINTOSH },
|
||||
{ 30, FC_LANG_OEM },
|
||||
{ 31, FC_LANG_SYMBOL },
|
||||
/* 32-47 reserved for OEM */
|
||||
{ 48, FC_LANG_IBM_GREEK },
|
||||
{ 49, FC_LANG_MSDOS_RUSSIAN },
|
||||
{ 50, FC_LANG_MSDOS_NORDIC },
|
||||
{ 51, FC_LANG_ARABIC_864 },
|
||||
{ 52, FC_LANG_MSDOS_CANADIAN_FRENCH },
|
||||
{ 53, FC_LANG_HEBREW_862 },
|
||||
{ 54, FC_LANG_MSDOS_ICELANDIC },
|
||||
{ 55, FC_LANG_MSDOS_PORTUGUESE },
|
||||
{ 56, FC_LANG_IBM_TURKISH },
|
||||
{ 57, FC_LANG_IBM_CYRILLIC },
|
||||
{ 58, FC_LANG_LATIN_2 },
|
||||
{ 59, FC_LANG_MSDOS_BALTIC },
|
||||
{ 60, FC_LANG_GREEK_437_G },
|
||||
{ 61, FC_LANG_ARABIC_ASMO_708 },
|
||||
{ 62, FC_LANG_WE_LATIN_1 },
|
||||
{ 63, FC_LANG_US },
|
||||
};
|
||||
|
||||
#define NUM_CODE_PAGE_RANGE (sizeof FcCodePageRange / sizeof FcCodePageRange[0])
|
||||
|
||||
FcPattern *
|
||||
FcFreeTypeQuery (const char *file,
|
||||
int id,
|
||||
FcBlanks *blanks,
|
||||
int *count)
|
||||
{
|
||||
FT_Face face;
|
||||
FcPattern *pat;
|
||||
int slant;
|
||||
int weight;
|
||||
int i;
|
||||
FcCharSet *cs;
|
||||
FT_Library ftLibrary;
|
||||
const char *family;
|
||||
TT_OS2 *os2;
|
||||
|
||||
if (FT_Init_FreeType (&ftLibrary))
|
||||
return 0;
|
||||
|
||||
if (FT_New_Face (ftLibrary, file, id, &face))
|
||||
goto bail;
|
||||
|
||||
*count = face->num_faces;
|
||||
|
||||
pat = FcPatternCreate ();
|
||||
if (!pat)
|
||||
goto bail0;
|
||||
|
||||
if (!FcPatternAddBool (pat, FC_OUTLINE,
|
||||
(face->face_flags & FT_FACE_FLAG_SCALABLE) != 0))
|
||||
goto bail1;
|
||||
|
||||
if (!FcPatternAddBool (pat, FC_SCALABLE,
|
||||
(face->face_flags & FT_FACE_FLAG_SCALABLE) != 0))
|
||||
goto bail1;
|
||||
|
||||
|
||||
slant = FC_SLANT_ROMAN;
|
||||
if (face->style_flags & FT_STYLE_FLAG_ITALIC)
|
||||
slant = FC_SLANT_ITALIC;
|
||||
|
||||
if (!FcPatternAddInteger (pat, FC_SLANT, slant))
|
||||
goto bail1;
|
||||
|
||||
weight = FC_WEIGHT_MEDIUM;
|
||||
if (face->style_flags & FT_STYLE_FLAG_BOLD)
|
||||
weight = FC_WEIGHT_BOLD;
|
||||
|
||||
if (!FcPatternAddInteger (pat, FC_WEIGHT, weight))
|
||||
goto bail1;
|
||||
|
||||
family = face->family_name;
|
||||
if (!family)
|
||||
{
|
||||
family = strrchr (file, '/');
|
||||
if (family)
|
||||
family++;
|
||||
else
|
||||
family = file;
|
||||
}
|
||||
if (!FcPatternAddString (pat, FC_FAMILY, family))
|
||||
goto bail1;
|
||||
|
||||
if (face->style_name)
|
||||
{
|
||||
if (!FcPatternAddString (pat, FC_STYLE, face->style_name))
|
||||
goto bail1;
|
||||
}
|
||||
|
||||
if (!FcPatternAddString (pat, FC_FILE, file))
|
||||
goto bail1;
|
||||
|
||||
if (!FcPatternAddInteger (pat, FC_INDEX, id))
|
||||
goto bail1;
|
||||
|
||||
if (!FcPatternAddString (pat, FC_SOURCE, "FreeType"))
|
||||
goto bail1;
|
||||
|
||||
#if 0
|
||||
if ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0)
|
||||
if (!FcPatternAddInteger (pat, FC_SPACING, FC_MONO))
|
||||
goto bail1;
|
||||
#endif
|
||||
|
||||
cs = FcFreeTypeCharSet (face, blanks);
|
||||
if (!cs)
|
||||
goto bail1;
|
||||
|
||||
/*
|
||||
* Skip over PCF fonts that have no encoded characters; they're
|
||||
* usually just Unicode fonts transcoded to some legacy encoding
|
||||
*/
|
||||
if (FcCharSetCount (cs) == 0)
|
||||
{
|
||||
if (!strcmp(FT_MODULE_CLASS(&face->driver->root)->module_name, "pcf"))
|
||||
goto bail2;
|
||||
}
|
||||
|
||||
if (!FcPatternAddCharSet (pat, FC_CHARSET, cs))
|
||||
goto bail2;
|
||||
/*
|
||||
* Drop our reference to the charset
|
||||
*/
|
||||
FcCharSetDestroy (cs);
|
||||
|
||||
if (!(face->face_flags & FT_FACE_FLAG_SCALABLE))
|
||||
{
|
||||
for (i = 0; i < face->num_fixed_sizes; i++)
|
||||
if (!FcPatternAddDouble (pat, FC_PIXEL_SIZE,
|
||||
(double) face->available_sizes[i].height))
|
||||
goto bail1;
|
||||
if (!FcPatternAddBool (pat, FC_ANTIALIAS, FcFalse))
|
||||
goto bail1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the OS/2 table and poke about
|
||||
*/
|
||||
os2 = (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2);
|
||||
if (os2 && os2->version >= 0x0001 && os2->version != 0xffff)
|
||||
{
|
||||
for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
|
||||
{
|
||||
FT_ULong bits;
|
||||
int bit;
|
||||
if (FcCodePageRange[i].bit < 32)
|
||||
{
|
||||
bits = os2->ulCodePageRange1;
|
||||
bit = FcCodePageRange[i].bit;
|
||||
}
|
||||
else
|
||||
{
|
||||
bits = os2->ulCodePageRange2;
|
||||
bit = FcCodePageRange[i].bit - 32;
|
||||
}
|
||||
if (bits & (1 << bit))
|
||||
{
|
||||
if (!FcPatternAddString (pat, FC_LANG,
|
||||
FcCodePageRange[i].name))
|
||||
goto bail1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FT_Done_Face (face);
|
||||
FT_Done_FreeType (ftLibrary);
|
||||
return pat;
|
||||
|
||||
bail2:
|
||||
FcCharSetDestroy (cs);
|
||||
bail1:
|
||||
FcPatternDestroy (pat);
|
||||
bail0:
|
||||
FT_Done_Face (face);
|
||||
bail:
|
||||
FT_Done_FreeType (ftLibrary);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "fcint.h"
|
||||
|
||||
FcFontSet *
|
||||
FcFontSetCreate (void)
|
||||
{
|
||||
FcFontSet *s;
|
||||
|
||||
s = (FcFontSet *) malloc (sizeof (FcFontSet));
|
||||
if (!s)
|
||||
return 0;
|
||||
FcMemAlloc (FC_MEM_FONTSET, sizeof (FcFontSet));
|
||||
s->nfont = 0;
|
||||
s->sfont = 0;
|
||||
s->fonts = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
FcFontSetDestroy (FcFontSet *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < s->nfont; i++)
|
||||
FcPatternDestroy (s->fonts[i]);
|
||||
if (s->fonts)
|
||||
{
|
||||
FcMemFree (FC_MEM_FONTPTR, s->sfont * sizeof (FcPattern *));
|
||||
free (s->fonts);
|
||||
}
|
||||
FcMemFree (FC_MEM_FONTSET, sizeof (FcFontSet));
|
||||
free (s);
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcFontSetAdd (FcFontSet *s, FcPattern *font)
|
||||
{
|
||||
FcPattern **f;
|
||||
int sfont;
|
||||
|
||||
if (s->nfont == s->sfont)
|
||||
{
|
||||
sfont = s->sfont + 32;
|
||||
if (s->fonts)
|
||||
f = (FcPattern **) realloc (s->fonts, sfont * sizeof (FcPattern *));
|
||||
else
|
||||
f = (FcPattern **) malloc (sfont * sizeof (FcPattern *));
|
||||
if (!f)
|
||||
return FcFalse;
|
||||
if (s->sfont)
|
||||
FcMemFree (FC_MEM_FONTPTR, s->sfont * sizeof (FcPattern *));
|
||||
FcMemAlloc (FC_MEM_FONTPTR, sfont * sizeof (FcPattern *));
|
||||
s->sfont = sfont;
|
||||
s->fonts = f;
|
||||
}
|
||||
s->fonts[s->nfont++] = font;
|
||||
return FcTrue;
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "fcint.h"
|
||||
|
||||
FcBool
|
||||
FcInitFonts (void)
|
||||
{
|
||||
FcConfig *config;
|
||||
|
||||
config = FcConfigGetCurrent ();
|
||||
if (!config)
|
||||
return FcFalse;
|
||||
|
||||
if (FcConfigGetFonts (config, FcSetSystem))
|
||||
return FcTrue;
|
||||
|
||||
return FcConfigBuildFonts (config);
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcInitFallbackConfig (void)
|
||||
{
|
||||
FcConfig *config;
|
||||
|
||||
config = FcConfigCreate ();
|
||||
if (!config)
|
||||
goto bail0;
|
||||
if (!FcConfigAddDir (config, FC_FALLBACK_FONTS))
|
||||
goto bail1;
|
||||
FcConfigSetCurrent (config);
|
||||
return FcTrue;
|
||||
|
||||
bail1:
|
||||
FcConfigDestroy (config);
|
||||
bail0:
|
||||
return FcFalse;
|
||||
}
|
||||
|
||||
/*
|
||||
* Locate and parse the configuration file
|
||||
*/
|
||||
FcBool
|
||||
FcInitConfig (void)
|
||||
{
|
||||
FcConfig *config;
|
||||
|
||||
if (FcConfigGetCurrent ())
|
||||
return FcTrue;
|
||||
|
||||
config = FcConfigCreate ();
|
||||
if (!config)
|
||||
return FcFalse;
|
||||
|
||||
if (!FcConfigParseAndLoad (config, 0, FcTrue))
|
||||
{
|
||||
FcConfigDestroy (config);
|
||||
return FcInitFallbackConfig ();
|
||||
}
|
||||
|
||||
FcConfigSetCurrent (config);
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcInit (void)
|
||||
{
|
||||
return FcInitConfig () && FcInitFonts ();
|
||||
}
|
||||
|
||||
static struct {
|
||||
char *name;
|
||||
int alloc_count;
|
||||
int alloc_mem;
|
||||
int free_count;
|
||||
int free_mem;
|
||||
} FcInUse[FC_MEM_NUM] = {
|
||||
{ "charset", 0, 0 },
|
||||
{ "charnode", 0 ,0 },
|
||||
{ "fontset", 0, 0 },
|
||||
{ "fontptr", 0, 0 },
|
||||
{ "objectset", 0, 0 },
|
||||
{ "objectptr", 0, 0 },
|
||||
{ "matrix", 0, 0 },
|
||||
{ "pattern", 0, 0 },
|
||||
{ "patelt", 0, 0 },
|
||||
{ "vallist", 0, 0 },
|
||||
{ "substate", 0, 0 },
|
||||
{ "string", 0, 0 },
|
||||
{ "listbuck", 0, 0 },
|
||||
};
|
||||
|
||||
static int FcAllocCount, FcAllocMem;
|
||||
static int FcFreeCount, FcFreeMem;
|
||||
|
||||
static int FcMemNotice = 1*1024*1024;
|
||||
|
||||
static int FcAllocNotify, FcFreeNotify;
|
||||
|
||||
void
|
||||
FcMemReport (void)
|
||||
{
|
||||
int i;
|
||||
printf ("Fc Memory Usage:\n");
|
||||
printf ("\t Which Alloc Free Active\n");
|
||||
printf ("\t count bytes count bytes count bytes\n");
|
||||
for (i = 0; i < FC_MEM_NUM; i++)
|
||||
printf ("\t%8.8s%8d%8d%8d%8d%8d%8d\n",
|
||||
FcInUse[i].name,
|
||||
FcInUse[i].alloc_count, FcInUse[i].alloc_mem,
|
||||
FcInUse[i].free_count, FcInUse[i].free_mem,
|
||||
FcInUse[i].alloc_count - FcInUse[i].free_count,
|
||||
FcInUse[i].alloc_mem - FcInUse[i].free_mem);
|
||||
printf ("\t%8.8s%8d%8d%8d%8d%8d%8d\n",
|
||||
"Total",
|
||||
FcAllocCount, FcAllocMem,
|
||||
FcFreeCount, FcFreeMem,
|
||||
FcAllocCount - FcFreeCount,
|
||||
FcAllocMem - FcFreeMem);
|
||||
FcAllocNotify = 0;
|
||||
FcFreeNotify = 0;
|
||||
}
|
||||
|
||||
void
|
||||
FcMemAlloc (int kind, int size)
|
||||
{
|
||||
if (FcDebug() & FC_DBG_MEMORY)
|
||||
{
|
||||
FcInUse[kind].alloc_count++;
|
||||
FcInUse[kind].alloc_mem += size;
|
||||
FcAllocCount++;
|
||||
FcAllocMem += size;
|
||||
FcAllocNotify += size;
|
||||
if (FcAllocNotify > FcMemNotice)
|
||||
FcMemReport ();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FcMemFree (int kind, int size)
|
||||
{
|
||||
if (FcDebug() & FC_DBG_MEMORY)
|
||||
{
|
||||
FcInUse[kind].free_count++;
|
||||
FcInUse[kind].free_mem += size;
|
||||
FcFreeCount++;
|
||||
FcFreeMem += size;
|
||||
FcFreeNotify += size;
|
||||
if (FcFreeNotify > FcMemNotice)
|
||||
FcMemReport ();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,480 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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 _FCINT_H_
|
||||
#define _FCINT_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <libxml/parserInternals.h>
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#include <fontconfig/fcprivate.h>
|
||||
#include <fontconfig/fcxml.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
typedef struct _FcMatcher {
|
||||
char *object;
|
||||
double (*compare) (char *object, FcValue value1, FcValue value2);
|
||||
} FcMatcher;
|
||||
|
||||
typedef struct _FcSymbolic {
|
||||
const char *name;
|
||||
int value;
|
||||
} FcSymbolic;
|
||||
|
||||
#ifndef FC_CONFIG_PATH
|
||||
#define FC_CONFIG_PATH "fonts.conf"
|
||||
#endif
|
||||
|
||||
#define FC_DBG_MATCH 1
|
||||
#define FC_DBG_MATCHV 2
|
||||
#define FC_DBG_EDIT 4
|
||||
#define FC_DBG_FONTSET 8
|
||||
#define FC_DBG_CACHE 16
|
||||
#define FC_DBG_CACHEV 32
|
||||
#define FC_DBG_PARSE 64
|
||||
#define FC_DBG_SCAN 128
|
||||
#define FC_DBG_MEMORY 512
|
||||
|
||||
#define FC_MEM_CHARSET 0
|
||||
#define FC_MEM_CHARNODE 1
|
||||
#define FC_MEM_FONTSET 2
|
||||
#define FC_MEM_FONTPTR 3
|
||||
#define FC_MEM_OBJECTSET 4
|
||||
#define FC_MEM_OBJECTPTR 5
|
||||
#define FC_MEM_MATRIX 6
|
||||
#define FC_MEM_PATTERN 7
|
||||
#define FC_MEM_PATELT 8
|
||||
#define FC_MEM_VALLIST 9
|
||||
#define FC_MEM_SUBSTATE 10
|
||||
#define FC_MEM_STRING 11
|
||||
#define FC_MEM_LISTBUCK 12
|
||||
#define FC_MEM_NUM 13
|
||||
|
||||
typedef struct _FcValueList {
|
||||
struct _FcValueList *next;
|
||||
FcValue value;
|
||||
} FcValueList;
|
||||
|
||||
typedef struct _FcPatternElt {
|
||||
const char *object;
|
||||
FcValueList *values;
|
||||
} FcPatternElt;
|
||||
|
||||
struct _FcPattern {
|
||||
int num;
|
||||
int size;
|
||||
FcPatternElt *elts;
|
||||
};
|
||||
|
||||
typedef enum _FcOp {
|
||||
FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpBool, FcOpCharSet,
|
||||
FcOpNil,
|
||||
FcOpField, FcOpConst,
|
||||
FcOpAssign, FcOpAssignReplace,
|
||||
FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast,
|
||||
FcOpQuest,
|
||||
FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual, FcOpContains,
|
||||
FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual,
|
||||
FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide,
|
||||
FcOpNot, FcOpComma, FcOpInvalid
|
||||
} FcOp;
|
||||
|
||||
typedef struct _FcExpr {
|
||||
FcOp op;
|
||||
union {
|
||||
int ival;
|
||||
double dval;
|
||||
char *sval;
|
||||
FcMatrix *mval;
|
||||
FcBool bval;
|
||||
FcCharSet *cval;
|
||||
char *field;
|
||||
char *constant;
|
||||
struct {
|
||||
struct _FcExpr *left, *right;
|
||||
} tree;
|
||||
} u;
|
||||
} FcExpr;
|
||||
|
||||
typedef enum _FcQual {
|
||||
FcQualAny, FcQualAll
|
||||
} FcQual;
|
||||
|
||||
typedef struct _FcTest {
|
||||
struct _FcTest *next;
|
||||
FcQual qual;
|
||||
const char *field;
|
||||
FcOp op;
|
||||
FcExpr *expr;
|
||||
} FcTest;
|
||||
|
||||
typedef struct _FcEdit {
|
||||
struct _FcEdit *next;
|
||||
const char *field;
|
||||
FcOp op;
|
||||
FcExpr *expr;
|
||||
} FcEdit;
|
||||
|
||||
typedef struct _FcSubst {
|
||||
struct _FcSubst *next;
|
||||
FcTest *test;
|
||||
FcEdit *edit;
|
||||
} FcSubst;
|
||||
|
||||
typedef struct _FcCharLeaf FcCharLeaf;
|
||||
typedef struct _FcCharBranch FcCharBranch;
|
||||
typedef union _FcCharNode FcCharNode;
|
||||
|
||||
struct _FcCharLeaf {
|
||||
FcChar32 map[256/32];
|
||||
};
|
||||
|
||||
union _FcCharNode {
|
||||
FcCharBranch *branch;
|
||||
FcCharLeaf *leaf;
|
||||
};
|
||||
|
||||
struct _FcCharBranch {
|
||||
FcCharNode nodes[256];
|
||||
};
|
||||
|
||||
struct _FcCharSet {
|
||||
int levels;
|
||||
int ref; /* reference count */
|
||||
FcBool constant; /* shared constant */
|
||||
FcCharNode node;
|
||||
};
|
||||
|
||||
typedef struct _FcNameBuf {
|
||||
FcChar8 *buf;
|
||||
FcBool allocated;
|
||||
FcBool failed;
|
||||
int len;
|
||||
int size;
|
||||
} FcNameBuf;
|
||||
|
||||
typedef struct _FcFileCacheEnt {
|
||||
struct _FcFileCacheEnt *next;
|
||||
unsigned int hash;
|
||||
char *file;
|
||||
int id;
|
||||
time_t time;
|
||||
char *name;
|
||||
FcBool referenced;
|
||||
} FcFileCacheEnt;
|
||||
|
||||
#define FC_FILE_CACHE_HASH_SIZE 509
|
||||
|
||||
struct _FcFileCache {
|
||||
FcFileCacheEnt *ents[FC_FILE_CACHE_HASH_SIZE];
|
||||
FcBool updated;
|
||||
int entries;
|
||||
int referenced;
|
||||
};
|
||||
|
||||
struct _FcBlanks {
|
||||
int nblank;
|
||||
int sblank;
|
||||
FcChar32 *blanks;
|
||||
};
|
||||
|
||||
struct _FcConfig {
|
||||
/*
|
||||
* File names loaded from the configuration -- saved here as the
|
||||
* cache file must be consulted before the directories are scanned,
|
||||
* and those directives may occur in any order
|
||||
*/
|
||||
char **dirs; /* directories containing fonts */
|
||||
char *cache; /* name of per-user cache file */
|
||||
/*
|
||||
* Set of allowed blank chars -- used to
|
||||
* trim fonts of bogus glyphs
|
||||
*/
|
||||
FcBlanks *blanks;
|
||||
/*
|
||||
* Names of all of the configuration files used
|
||||
* to create this configuration
|
||||
*/
|
||||
char **configFiles; /* config files loaded */
|
||||
/*
|
||||
* Substitution instructions for patterns and fonts;
|
||||
* maxObjects is used to allocate appropriate intermediate storage
|
||||
* while performing a whole set of substitutions
|
||||
*/
|
||||
FcSubst *substPattern; /* substitutions for patterns */
|
||||
FcSubst *substFont; /* substitutions for fonts */
|
||||
int maxObjects; /* maximum number of tests in all substs */
|
||||
/*
|
||||
* The set of fonts loaded from the listed directories; the
|
||||
* order within the set does not determine the font selection,
|
||||
* except in the case of identical matches in which case earlier fonts
|
||||
* match preferrentially
|
||||
*/
|
||||
FcFontSet *fonts[FcSetApplication + 1];
|
||||
};
|
||||
|
||||
/* fcblanks.c */
|
||||
|
||||
/* fccache.c */
|
||||
|
||||
FcFileCache *
|
||||
FcFileCacheCreate (void);
|
||||
|
||||
char *
|
||||
FcFileCacheFind (FcFileCache *cache,
|
||||
const char *file,
|
||||
int id,
|
||||
int *count);
|
||||
|
||||
void
|
||||
FcFileCacheDestroy (FcFileCache *cache);
|
||||
|
||||
void
|
||||
FcFileCacheLoad (FcFileCache *cache,
|
||||
const char *cache_file);
|
||||
|
||||
FcBool
|
||||
FcFileCacheUpdate (FcFileCache *cache,
|
||||
const char *file,
|
||||
int id,
|
||||
const char *name);
|
||||
|
||||
FcBool
|
||||
FcFileCacheSave (FcFileCache *cache,
|
||||
const char *cache_file);
|
||||
|
||||
FcBool
|
||||
FcFileCacheReadDir (FcFontSet *set, const char *cache_file);
|
||||
|
||||
FcBool
|
||||
FcFileCacheWriteDir (FcFontSet *set, const char *cache_file);
|
||||
|
||||
/* fccfg.c */
|
||||
|
||||
FcBool
|
||||
FcConfigAddDir (FcConfig *config,
|
||||
const char *d);
|
||||
|
||||
FcBool
|
||||
FcConfigAddConfigFile (FcConfig *config,
|
||||
const char *f);
|
||||
|
||||
FcBool
|
||||
FcConfigSetCache (FcConfig *config,
|
||||
const char *c);
|
||||
|
||||
FcBool
|
||||
FcConfigAddBlank (FcConfig *config,
|
||||
FcChar32 blank);
|
||||
|
||||
FcBool
|
||||
FcConfigAddEdit (FcConfig *config,
|
||||
FcTest *test,
|
||||
FcEdit *edit,
|
||||
FcMatchKind kind);
|
||||
|
||||
void
|
||||
FcConfigSetFonts (FcConfig *config,
|
||||
FcFontSet *fonts,
|
||||
FcSetName set);
|
||||
|
||||
FcBool
|
||||
FcConfigCompareValue (const FcValue m,
|
||||
FcOp op,
|
||||
const FcValue v);
|
||||
|
||||
/* fccharset.c */
|
||||
FcBool
|
||||
FcNameUnparseCharSet (FcNameBuf *buf, const FcCharSet *c);
|
||||
|
||||
FcCharSet *
|
||||
FcNameParseCharSet (FcChar8 *string);
|
||||
|
||||
/* fcdbg.c */
|
||||
void
|
||||
FcValuePrint (FcValue v);
|
||||
|
||||
void
|
||||
FcValueListPrint (FcValueList *l);
|
||||
|
||||
void
|
||||
FcPatternPrint (FcPattern *p);
|
||||
|
||||
void
|
||||
FcOpPrint (FcOp op);
|
||||
|
||||
void
|
||||
FcTestPrint (FcTest *test);
|
||||
|
||||
void
|
||||
FcExprPrint (FcExpr *expr);
|
||||
|
||||
void
|
||||
FcEditPrint (FcEdit *edit);
|
||||
|
||||
void
|
||||
FcSubstPrint (FcSubst *subst);
|
||||
|
||||
void
|
||||
FcFontSetPrint (FcFontSet *s);
|
||||
|
||||
int
|
||||
FcDebug (void);
|
||||
|
||||
/* fcdir.c */
|
||||
FcBool
|
||||
FcFileScan (FcFontSet *set,
|
||||
FcFileCache *cache,
|
||||
FcBlanks *blanks,
|
||||
const char *file,
|
||||
FcBool force);
|
||||
|
||||
FcBool
|
||||
FcDirScan (FcFontSet *set,
|
||||
FcFileCache *cache,
|
||||
FcBlanks *blanks,
|
||||
const char *dir,
|
||||
FcBool force);
|
||||
|
||||
FcBool
|
||||
FcDirSave (FcFontSet *set, const char *dir);
|
||||
|
||||
/* fcfont.c */
|
||||
int
|
||||
FcFontDebug (void);
|
||||
|
||||
/* fcfs.c */
|
||||
/* fcgram.y */
|
||||
int
|
||||
FcConfigparse (void);
|
||||
|
||||
int
|
||||
FcConfigwrap (void);
|
||||
|
||||
void
|
||||
FcConfigerror (char *fmt, ...);
|
||||
|
||||
char *
|
||||
FcConfigSaveField (const char *field);
|
||||
|
||||
FcTest *
|
||||
FcTestCreate (FcQual qual, const char *field, FcOp compare, FcExpr *expr);
|
||||
|
||||
void
|
||||
FcTestDestroy (FcTest *test);
|
||||
|
||||
FcExpr *
|
||||
FcExprCreateInteger (int i);
|
||||
|
||||
FcExpr *
|
||||
FcExprCreateDouble (double d);
|
||||
|
||||
FcExpr *
|
||||
FcExprCreateString (const char *s);
|
||||
|
||||
FcExpr *
|
||||
FcExprCreateMatrix (const FcMatrix *m);
|
||||
|
||||
FcExpr *
|
||||
FcExprCreateBool (FcBool b);
|
||||
|
||||
FcExpr *
|
||||
FcExprCreateNil (void);
|
||||
|
||||
FcExpr *
|
||||
FcExprCreateField (const char *field);
|
||||
|
||||
FcExpr *
|
||||
FcExprCreateConst (const char *constant);
|
||||
|
||||
FcExpr *
|
||||
FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
|
||||
|
||||
void
|
||||
FcExprDestroy (FcExpr *e);
|
||||
|
||||
FcEdit *
|
||||
FcEditCreate (const char *field, FcOp op, FcExpr *expr);
|
||||
|
||||
void
|
||||
FcEditDestroy (FcEdit *e);
|
||||
|
||||
/* fcinit.c */
|
||||
|
||||
void
|
||||
FcMemReport (void);
|
||||
|
||||
void
|
||||
FcMemAlloc (int kind, int size);
|
||||
|
||||
void
|
||||
FcMemFree (int kind, int size);
|
||||
|
||||
/* fclist.c */
|
||||
|
||||
/* fcmatch.c */
|
||||
|
||||
/* fcname.c */
|
||||
FcBool
|
||||
FcNameConstant (char *string, int *result);
|
||||
|
||||
FcBool
|
||||
FcNameBool (char *v, FcBool *result);
|
||||
|
||||
FcBool
|
||||
FcNameBufChar (FcNameBuf *buf, FcChar8 c);
|
||||
|
||||
FcBool
|
||||
FcNameBufString (FcNameBuf *buf, const FcChar8 *s);
|
||||
|
||||
/* fcpat.c */
|
||||
void
|
||||
FcValueListDestroy (FcValueList *l);
|
||||
|
||||
FcPatternElt *
|
||||
FcPatternFind (FcPattern *p, const char *object, FcBool insert);
|
||||
|
||||
/* fcrender.c */
|
||||
|
||||
/* fcmatrix.c */
|
||||
void
|
||||
FcMatrixFree (FcMatrix *mat);
|
||||
|
||||
/* fcstr.c */
|
||||
char *
|
||||
FcStrPlus (const char *s1, const char *s2);
|
||||
|
||||
void
|
||||
FcStrFree (char *s);
|
||||
|
||||
#endif /* _FC_INT_H_ */
|
|
@ -0,0 +1,442 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "fcint.h"
|
||||
|
||||
FcObjectSet *
|
||||
FcObjectSetCreate (void)
|
||||
{
|
||||
FcObjectSet *os;
|
||||
|
||||
os = (FcObjectSet *) malloc (sizeof (FcObjectSet));
|
||||
if (!os)
|
||||
return 0;
|
||||
FcMemAlloc (FC_MEM_OBJECTSET, sizeof (FcObjectSet));
|
||||
os->nobject = 0;
|
||||
os->sobject = 0;
|
||||
os->objects = 0;
|
||||
return os;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcObjectSetAdd (FcObjectSet *os, const char *object)
|
||||
{
|
||||
int s;
|
||||
const char **objects;
|
||||
|
||||
if (os->nobject == os->sobject)
|
||||
{
|
||||
s = os->sobject + 4;
|
||||
if (os->objects)
|
||||
objects = (const char **) realloc ((void *) os->objects,
|
||||
s * sizeof (const char *));
|
||||
else
|
||||
objects = (const char **) malloc (s * sizeof (const char *));
|
||||
if (!objects)
|
||||
return FcFalse;
|
||||
if (os->sobject)
|
||||
FcMemFree (FC_MEM_OBJECTPTR, os->sobject * sizeof (const char *));
|
||||
FcMemAlloc (FC_MEM_OBJECTPTR, s * sizeof (const char *));
|
||||
os->objects = objects;
|
||||
os->sobject = s;
|
||||
}
|
||||
os->objects[os->nobject++] = object;
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
void
|
||||
FcObjectSetDestroy (FcObjectSet *os)
|
||||
{
|
||||
if (os->objects)
|
||||
{
|
||||
FcMemFree (FC_MEM_OBJECTPTR, os->sobject * sizeof (const char *));
|
||||
free ((void *) os->objects);
|
||||
}
|
||||
FcMemFree (FC_MEM_OBJECTSET, sizeof (FcObjectSet));
|
||||
free (os);
|
||||
}
|
||||
|
||||
FcObjectSet *
|
||||
FcObjectSetVaBuild (const char *first, va_list va)
|
||||
{
|
||||
FcObjectSet *ret;
|
||||
|
||||
FcObjectSetVapBuild (ret, first, va);
|
||||
return ret;
|
||||
}
|
||||
|
||||
FcObjectSet *
|
||||
FcObjectSetBuild (const char *first, ...)
|
||||
{
|
||||
va_list va;
|
||||
FcObjectSet *os;
|
||||
|
||||
va_start (va, first);
|
||||
FcObjectSetVapBuild (os, first, va);
|
||||
va_end (va);
|
||||
return os;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcListValueListMatchAny (FcValueList *v1orig,
|
||||
FcValueList *v2orig)
|
||||
{
|
||||
FcValueList *v1, *v2;
|
||||
|
||||
for (v1 = v1orig; v1; v1 = v1->next)
|
||||
for (v2 = v2orig; v2; v2 = v2->next)
|
||||
if (FcConfigCompareValue (v2->value, FcOpContains, v1->value))
|
||||
return FcTrue;
|
||||
return FcFalse;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcListValueListEqual (FcValueList *v1orig,
|
||||
FcValueList *v2orig)
|
||||
{
|
||||
FcValueList *v1, *v2;
|
||||
|
||||
for (v1 = v1orig; v1; v1 = v1->next)
|
||||
{
|
||||
for (v2 = v2orig; v2; v2 = v2->next)
|
||||
if (FcConfigCompareValue (v1->value, FcOpEqual, v2->value))
|
||||
break;
|
||||
if (!v2)
|
||||
return FcFalse;
|
||||
}
|
||||
for (v2 = v2orig; v2; v2 = v2->next)
|
||||
{
|
||||
for (v1 = v1orig; v1; v1 = v1->next)
|
||||
if (FcConfigCompareValue (v1->value, FcOpEqual, v2->value))
|
||||
break;
|
||||
if (!v1)
|
||||
return FcFalse;
|
||||
}
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
/*
|
||||
* FcTrue iff all objects in "p" match "font"
|
||||
*/
|
||||
|
||||
static FcBool
|
||||
FcListPatternMatchAny (FcPattern *p,
|
||||
FcPattern *font)
|
||||
{
|
||||
int i;
|
||||
FcPatternElt *e;
|
||||
|
||||
for (i = 0; i < p->num; i++)
|
||||
{
|
||||
e = FcPatternFind (font, p->elts[i].object, FcFalse);
|
||||
if (!e)
|
||||
return FcFalse;
|
||||
if (!FcListValueListMatchAny (p->elts[i].values, e->values))
|
||||
return FcFalse;
|
||||
}
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcListPatternEqual (FcPattern *p1,
|
||||
FcPattern *p2,
|
||||
FcObjectSet *os)
|
||||
{
|
||||
int i;
|
||||
FcPatternElt *e1, *e2;
|
||||
|
||||
for (i = 0; i < os->nobject; i++)
|
||||
{
|
||||
e1 = FcPatternFind (p1, os->objects[i], FcFalse);
|
||||
e2 = FcPatternFind (p2, os->objects[i], FcFalse);
|
||||
if (!e1 && !e2)
|
||||
return FcTrue;
|
||||
if (!e1 || !e2)
|
||||
return FcFalse;
|
||||
if (!FcListValueListEqual (e1->values, e2->values))
|
||||
return FcFalse;
|
||||
}
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
static FcChar32
|
||||
FcListStringHash (const FcChar8 *s)
|
||||
{
|
||||
FcChar32 h = 0;
|
||||
FcChar8 c;
|
||||
|
||||
while ((c = *s++))
|
||||
{
|
||||
c = FcToLower (c);
|
||||
h = ((h << 3) ^ (h >> 3)) ^ c;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
static FcChar32
|
||||
FcListMatrixHash (const FcMatrix *m)
|
||||
{
|
||||
int xx = (int) (m->xx * 100),
|
||||
xy = (int) (m->xy * 100),
|
||||
yx = (int) (m->yx * 100),
|
||||
yy = (int) (m->yy * 100);
|
||||
|
||||
return ((FcChar32) xx) ^ ((FcChar32) xy) ^ ((FcChar32) yx) ^ ((FcChar32) yy);
|
||||
}
|
||||
|
||||
static FcChar32
|
||||
FcListValueHash (FcValue v)
|
||||
{
|
||||
switch (v.type) {
|
||||
case FcTypeVoid:
|
||||
return 0;
|
||||
case FcTypeInteger:
|
||||
return (FcChar32) v.u.i;
|
||||
case FcTypeDouble:
|
||||
return (FcChar32) (int) v.u.d;
|
||||
case FcTypeString:
|
||||
return FcListStringHash (v.u.s);
|
||||
case FcTypeBool:
|
||||
return (FcChar32) v.u.b;
|
||||
case FcTypeMatrix:
|
||||
return FcListMatrixHash (v.u.m);
|
||||
case FcTypeCharSet:
|
||||
return FcCharSetCount (v.u.c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FcChar32
|
||||
FcListValueListHash (FcValueList *list)
|
||||
{
|
||||
FcChar32 h = 0;
|
||||
|
||||
while (list)
|
||||
{
|
||||
h = h ^ FcListValueHash (list->value);
|
||||
list = list->next;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
static FcChar32
|
||||
FcListPatternHash (FcPattern *font,
|
||||
FcObjectSet *os)
|
||||
{
|
||||
int n;
|
||||
FcPatternElt *e;
|
||||
FcChar32 h = 0;
|
||||
|
||||
for (n = 0; n < os->nobject; n++)
|
||||
{
|
||||
e = FcPatternFind (font, os->objects[n], FcFalse);
|
||||
if (e)
|
||||
h = h ^ FcListValueListHash (e->values);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
typedef struct _FcListBucket {
|
||||
struct _FcListBucket *next;
|
||||
FcChar32 hash;
|
||||
FcPattern *pattern;
|
||||
} FcListBucket;
|
||||
|
||||
#define FC_LIST_HASH_SIZE 4099
|
||||
|
||||
typedef struct _FcListHashTable {
|
||||
int entries;
|
||||
FcListBucket *buckets[FC_LIST_HASH_SIZE];
|
||||
} FcListHashTable;
|
||||
|
||||
static void
|
||||
FcListHashTableInit (FcListHashTable *table)
|
||||
{
|
||||
table->entries = 0;
|
||||
memset (table->buckets, '\0', sizeof (table->buckets));
|
||||
}
|
||||
|
||||
static void
|
||||
FcListHashTableCleanup (FcListHashTable *table)
|
||||
{
|
||||
int i;
|
||||
FcListBucket *bucket, *next;
|
||||
|
||||
for (i = 0; i < FC_LIST_HASH_SIZE; i++)
|
||||
{
|
||||
for (bucket = table->buckets[i]; bucket; bucket = next)
|
||||
{
|
||||
next = bucket->next;
|
||||
FcPatternDestroy (bucket->pattern);
|
||||
FcMemFree (FC_MEM_LISTBUCK, sizeof (FcListBucket));
|
||||
free (bucket);
|
||||
}
|
||||
table->buckets[i] = 0;
|
||||
}
|
||||
table->entries = 0;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcListAppend (FcListHashTable *table,
|
||||
FcPattern *font,
|
||||
FcObjectSet *os)
|
||||
{
|
||||
int o;
|
||||
FcPatternElt *e;
|
||||
FcValueList *v;
|
||||
FcChar32 hash;
|
||||
FcListBucket **prev, *bucket;
|
||||
|
||||
hash = FcListPatternHash (font, os);
|
||||
for (prev = &table->buckets[hash % FC_LIST_HASH_SIZE];
|
||||
(bucket = *prev); prev = &(bucket->next))
|
||||
{
|
||||
if (bucket->hash == hash &&
|
||||
FcListPatternEqual (bucket->pattern, font, os))
|
||||
return FcTrue;
|
||||
}
|
||||
bucket = (FcListBucket *) malloc (sizeof (FcListBucket));
|
||||
if (!bucket)
|
||||
goto bail0;
|
||||
FcMemAlloc (FC_MEM_LISTBUCK, sizeof (FcListBucket));
|
||||
bucket->next = 0;
|
||||
bucket->hash = hash;
|
||||
bucket->pattern = FcPatternCreate ();
|
||||
if (!bucket->pattern)
|
||||
goto bail1;
|
||||
|
||||
for (o = 0; o < os->nobject; o++)
|
||||
{
|
||||
e = FcPatternFind (font, os->objects[o], FcFalse);
|
||||
if (e)
|
||||
{
|
||||
for (v = e->values; v; v = v->next)
|
||||
{
|
||||
if (!FcPatternAdd (bucket->pattern,
|
||||
os->objects[o],
|
||||
v->value, FcTrue))
|
||||
goto bail2;
|
||||
}
|
||||
}
|
||||
}
|
||||
*prev = bucket;
|
||||
++table->entries;
|
||||
|
||||
return FcTrue;
|
||||
|
||||
bail2:
|
||||
FcPatternDestroy (bucket->pattern);
|
||||
bail1:
|
||||
FcMemFree (FC_MEM_LISTBUCK, sizeof (FcListBucket));
|
||||
free (bucket);
|
||||
bail0:
|
||||
return FcFalse;
|
||||
}
|
||||
|
||||
FcFontSet *
|
||||
FcFontList (FcConfig *config,
|
||||
FcPattern *p,
|
||||
FcObjectSet *os)
|
||||
{
|
||||
FcFontSet *ret;
|
||||
FcFontSet *s;
|
||||
int f;
|
||||
FcSetName set;
|
||||
FcListHashTable table;
|
||||
int i;
|
||||
FcListBucket *bucket;
|
||||
|
||||
if (!config)
|
||||
{
|
||||
config = FcConfigGetCurrent ();
|
||||
if (!config)
|
||||
goto bail0;
|
||||
}
|
||||
FcListHashTableInit (&table);
|
||||
/*
|
||||
* Walk all available fonts adding those that
|
||||
* match to the hash table
|
||||
*/
|
||||
for (set = FcSetSystem; set <= FcSetApplication; set++)
|
||||
{
|
||||
s = config->fonts[set];
|
||||
if (!s)
|
||||
continue;
|
||||
for (f = 0; f < s->nfont; f++)
|
||||
if (FcListPatternMatchAny (p, s->fonts[f]))
|
||||
if (!FcListAppend (&table, s->fonts[f], os))
|
||||
goto bail1;
|
||||
}
|
||||
#if 0
|
||||
{
|
||||
int max = 0;
|
||||
int full = 0;
|
||||
int ents = 0;
|
||||
int len;
|
||||
for (i = 0; i < FC_LIST_HASH_SIZE; i++)
|
||||
{
|
||||
if ((bucket = table.buckets[i]))
|
||||
{
|
||||
len = 0;
|
||||
for (; bucket; bucket = bucket->next)
|
||||
{
|
||||
ents++;
|
||||
len++;
|
||||
}
|
||||
if (len > max)
|
||||
max = len;
|
||||
full++;
|
||||
}
|
||||
}
|
||||
printf ("used: %d max: %d avg: %g\n", full, max,
|
||||
(double) ents / FC_LIST_HASH_SIZE);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Walk the hash table and build
|
||||
* a font set
|
||||
*/
|
||||
ret = FcFontSetCreate ();
|
||||
if (!ret)
|
||||
goto bail0;
|
||||
for (i = 0; i < FC_LIST_HASH_SIZE; i++)
|
||||
while ((bucket = table.buckets[i]))
|
||||
{
|
||||
if (!FcFontSetAdd (ret, bucket->pattern))
|
||||
goto bail2;
|
||||
table.buckets[i] = bucket->next;
|
||||
FcMemFree (FC_MEM_LISTBUCK, sizeof (FcListBucket));
|
||||
free (bucket);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
bail2:
|
||||
FcFontSetDestroy (ret);
|
||||
bail1:
|
||||
FcListHashTableCleanup (&table);
|
||||
bail0:
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,347 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "fcint.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static double
|
||||
FcCompareInteger (char *object, FcValue value1, FcValue value2)
|
||||
{
|
||||
int v;
|
||||
|
||||
if (value2.type != FcTypeInteger || value1.type != FcTypeInteger)
|
||||
return -1.0;
|
||||
v = value2.u.i - value1.u.i;
|
||||
if (v < 0)
|
||||
v = -v;
|
||||
return (double) v;
|
||||
}
|
||||
|
||||
static double
|
||||
FcCompareString (char *object, FcValue value1, FcValue value2)
|
||||
{
|
||||
if (value2.type != FcTypeString || value1.type != FcTypeString)
|
||||
return -1.0;
|
||||
return (double) FcStrCmpIgnoreCase (value1.u.s, value2.u.s) != 0;
|
||||
}
|
||||
|
||||
static double
|
||||
FcCompareBool (char *object, FcValue value1, FcValue value2)
|
||||
{
|
||||
if (value2.type != FcTypeBool || value1.type != FcTypeBool)
|
||||
return -1.0;
|
||||
return (double) value2.u.b != value1.u.b;
|
||||
}
|
||||
|
||||
static double
|
||||
FcCompareCharSet (char *object, FcValue value1, FcValue value2)
|
||||
{
|
||||
if (value2.type != FcTypeCharSet || value1.type != FcTypeCharSet)
|
||||
return -1.0;
|
||||
return (double) FcCharSetSubtractCount (value1.u.c, value2.u.c);
|
||||
}
|
||||
|
||||
static double
|
||||
FcCompareSize (char *object, FcValue value1, FcValue value2)
|
||||
{
|
||||
double v1, v2, v;
|
||||
|
||||
switch (value1.type) {
|
||||
case FcTypeInteger:
|
||||
v1 = value1.u.i;
|
||||
break;
|
||||
case FcTypeDouble:
|
||||
v1 = value1.u.d;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
switch (value2.type) {
|
||||
case FcTypeInteger:
|
||||
v2 = value2.u.i;
|
||||
break;
|
||||
case FcTypeDouble:
|
||||
v2 = value2.u.d;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
if (v2 == 0)
|
||||
return 0;
|
||||
v = v2 - v1;
|
||||
if (v < 0)
|
||||
v = -v;
|
||||
return v;
|
||||
}
|
||||
|
||||
/*
|
||||
* Order is significant, it defines the precedence of
|
||||
* each value, earlier values are more significant than
|
||||
* later values
|
||||
*/
|
||||
static FcMatcher _FcMatchers [] = {
|
||||
{ FC_FOUNDRY, FcCompareString, },
|
||||
{ FC_CHARSET, FcCompareCharSet },
|
||||
{ FC_ANTIALIAS, FcCompareBool, },
|
||||
{ FC_LANG, FcCompareString },
|
||||
{ FC_FAMILY, FcCompareString, },
|
||||
{ FC_SPACING, FcCompareInteger, },
|
||||
{ FC_PIXEL_SIZE, FcCompareSize, },
|
||||
{ FC_STYLE, FcCompareString, },
|
||||
{ FC_SLANT, FcCompareInteger, },
|
||||
{ FC_WEIGHT, FcCompareInteger, },
|
||||
{ FC_RASTERIZER, FcCompareString, },
|
||||
{ FC_OUTLINE, FcCompareBool, },
|
||||
};
|
||||
|
||||
#define NUM_MATCHER (sizeof _FcMatchers / sizeof _FcMatchers[0])
|
||||
|
||||
static FcBool
|
||||
FcCompareValueList (const char *object,
|
||||
FcValueList *v1orig, /* pattern */
|
||||
FcValueList *v2orig, /* target */
|
||||
FcValue *bestValue,
|
||||
double *value,
|
||||
FcResult *result)
|
||||
{
|
||||
FcValueList *v1, *v2;
|
||||
double v, best;
|
||||
int j;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NUM_MATCHER; i++)
|
||||
{
|
||||
if (!FcStrCmpIgnoreCase (_FcMatchers[i].object, object))
|
||||
break;
|
||||
}
|
||||
if (i == NUM_MATCHER)
|
||||
{
|
||||
if (bestValue)
|
||||
*bestValue = v2orig->value;
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
best = 1e99;
|
||||
j = 0;
|
||||
for (v1 = v1orig; v1; v1 = v1->next)
|
||||
{
|
||||
for (v2 = v2orig; v2; v2 = v2->next)
|
||||
{
|
||||
v = (*_FcMatchers[i].compare) (_FcMatchers[i].object,
|
||||
v1->value,
|
||||
v2->value);
|
||||
if (v < 0)
|
||||
{
|
||||
*result = FcResultTypeMismatch;
|
||||
return FcFalse;
|
||||
}
|
||||
if (FcDebug () & FC_DBG_MATCHV)
|
||||
printf (" v %g j %d ", v, j);
|
||||
v = v * 100 + j;
|
||||
if (v < best)
|
||||
{
|
||||
if (bestValue)
|
||||
*bestValue = v2->value;
|
||||
best = v;
|
||||
}
|
||||
}
|
||||
j++;
|
||||
}
|
||||
if (FcDebug () & FC_DBG_MATCHV)
|
||||
{
|
||||
printf (" %s: %g ", object, best);
|
||||
FcValueListPrint (v1orig);
|
||||
printf (", ");
|
||||
FcValueListPrint (v2orig);
|
||||
printf ("\n");
|
||||
}
|
||||
value[i] += best;
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a value indicating the distance between the two lists of
|
||||
* values
|
||||
*/
|
||||
|
||||
static FcBool
|
||||
FcCompare (FcPattern *pat,
|
||||
FcPattern *fnt,
|
||||
double *value,
|
||||
FcResult *result)
|
||||
{
|
||||
int i, i1, i2;
|
||||
|
||||
for (i = 0; i < NUM_MATCHER; i++)
|
||||
value[i] = 0.0;
|
||||
|
||||
for (i1 = 0; i1 < pat->num; i1++)
|
||||
{
|
||||
for (i2 = 0; i2 < fnt->num; i2++)
|
||||
{
|
||||
if (!FcStrCmpIgnoreCase (pat->elts[i1].object,
|
||||
fnt->elts[i2].object))
|
||||
{
|
||||
if (!FcCompareValueList (pat->elts[i1].object,
|
||||
pat->elts[i1].values,
|
||||
fnt->elts[i2].values,
|
||||
0,
|
||||
value,
|
||||
result))
|
||||
return FcFalse;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
/*
|
||||
* Overspecified patterns are slightly penalized in
|
||||
* case some other font includes the requested field
|
||||
*/
|
||||
if (i2 == fnt->num)
|
||||
{
|
||||
for (i2 = 0; i2 < NUM_MATCHER; i2++)
|
||||
{
|
||||
if (!FcStrCmpIgnoreCase (_FcMatchers[i2].object,
|
||||
pat->elts[i1].object))
|
||||
{
|
||||
value[i2] = 1.0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
FcPattern *
|
||||
FcFontMatch (FcConfig *config,
|
||||
FcPattern *p,
|
||||
FcResult *result)
|
||||
{
|
||||
double score[NUM_MATCHER], bestscore[NUM_MATCHER];
|
||||
int f;
|
||||
FcFontSet *s;
|
||||
FcPattern *best;
|
||||
FcPattern *new;
|
||||
FcPatternElt *fe, *pe;
|
||||
FcValue v;
|
||||
int i;
|
||||
FcSetName set;
|
||||
|
||||
for (i = 0; i < NUM_MATCHER; i++)
|
||||
bestscore[i] = 0;
|
||||
best = 0;
|
||||
if (FcDebug () & FC_DBG_MATCH)
|
||||
{
|
||||
printf ("Match ");
|
||||
FcPatternPrint (p);
|
||||
}
|
||||
if (!config)
|
||||
{
|
||||
config = FcConfigGetCurrent ();
|
||||
if (!config)
|
||||
return 0;
|
||||
}
|
||||
for (set = FcSetSystem; set <= FcSetApplication; set++)
|
||||
{
|
||||
s = config->fonts[set];
|
||||
if (!s)
|
||||
continue;
|
||||
for (f = 0; f < s->nfont; f++)
|
||||
{
|
||||
if (FcDebug () & FC_DBG_MATCHV)
|
||||
{
|
||||
printf ("Font %d ", f);
|
||||
FcPatternPrint (s->fonts[f]);
|
||||
}
|
||||
if (!FcCompare (p, s->fonts[f], score, result))
|
||||
return 0;
|
||||
if (FcDebug () & FC_DBG_MATCHV)
|
||||
{
|
||||
printf ("Score");
|
||||
for (i = 0; i < NUM_MATCHER; i++)
|
||||
{
|
||||
printf (" %g", score[i]);
|
||||
}
|
||||
printf ("\n");
|
||||
}
|
||||
for (i = 0; i < NUM_MATCHER; i++)
|
||||
{
|
||||
if (best && bestscore[i] < score[i])
|
||||
break;
|
||||
if (!best || score[i] < bestscore[i])
|
||||
{
|
||||
for (i = 0; i < NUM_MATCHER; i++)
|
||||
bestscore[i] = score[i];
|
||||
best = s->fonts[f];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (FcDebug () & FC_DBG_MATCH)
|
||||
{
|
||||
printf ("Best score");
|
||||
for (i = 0; i < NUM_MATCHER; i++)
|
||||
printf (" %g", bestscore[i]);
|
||||
FcPatternPrint (best);
|
||||
}
|
||||
if (!best)
|
||||
{
|
||||
*result = FcResultNoMatch;
|
||||
return 0;
|
||||
}
|
||||
new = FcPatternCreate ();
|
||||
if (!new)
|
||||
return 0;
|
||||
for (i = 0; i < best->num; i++)
|
||||
{
|
||||
fe = &best->elts[i];
|
||||
pe = FcPatternFind (p, fe->object, FcFalse);
|
||||
if (pe)
|
||||
{
|
||||
if (!FcCompareValueList (pe->object, pe->values,
|
||||
fe->values, &v, score, result))
|
||||
{
|
||||
FcPatternDestroy (new);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
v = fe->values->value;
|
||||
FcPatternAdd (new, fe->object, v, FcTrue);
|
||||
}
|
||||
for (i = 0; i < p->num; i++)
|
||||
{
|
||||
pe = &p->elts[i];
|
||||
fe = FcPatternFind (best, pe->object, FcFalse);
|
||||
if (!fe)
|
||||
FcPatternAdd (new, pe->object, pe->values->value, FcTrue);
|
||||
}
|
||||
FcConfigSubstitute (config, new, FcMatchFont);
|
||||
return new;
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2000 Tuomas J. Lukka
|
||||
*
|
||||
* 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 Tuomas Lukka not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Tuomas Lukka makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* TUOMAS LUKKA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL TUOMAS LUKKA 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.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include "fcint.h"
|
||||
|
||||
FcMatrix *
|
||||
FcMatrixCopy (const FcMatrix *mat)
|
||||
{
|
||||
FcMatrix *r;
|
||||
if(!mat)
|
||||
return 0;
|
||||
r = (FcMatrix *) malloc (sizeof (*r) );
|
||||
if (!r)
|
||||
return 0;
|
||||
FcMemAlloc (FC_MEM_MATRIX, sizeof (FcMatrix));
|
||||
*r = *mat;
|
||||
return r;
|
||||
}
|
||||
|
||||
void
|
||||
FcMatrixFree (FcMatrix *mat)
|
||||
{
|
||||
FcMemFree (FC_MEM_MATRIX, sizeof (FcMatrix));
|
||||
free (mat);
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2)
|
||||
{
|
||||
if(mat1 == mat2) return FcTrue;
|
||||
if(mat1 == 0 || mat2 == 0) return FcFalse;
|
||||
return mat1->xx == mat2->xx &&
|
||||
mat1->xy == mat2->xy &&
|
||||
mat1->yx == mat2->yx &&
|
||||
mat1->yy == mat2->yy;
|
||||
}
|
||||
|
||||
void
|
||||
FcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b)
|
||||
{
|
||||
FcMatrix r;
|
||||
|
||||
r.xx = a->xx * b->xx + a->xy * b->yx;
|
||||
r.xy = a->xx * b->xy + a->xy * b->yy;
|
||||
r.yx = a->yx * b->xx + a->yy * b->yx;
|
||||
r.yy = a->yx * b->xy + a->yy * b->yy;
|
||||
*result = r;
|
||||
}
|
||||
|
||||
void
|
||||
FcMatrixRotate (FcMatrix *m, double c, double s)
|
||||
{
|
||||
FcMatrix r;
|
||||
|
||||
/*
|
||||
* X Coordinate system is upside down, swap to make
|
||||
* rotations counterclockwise
|
||||
*/
|
||||
r.xx = c;
|
||||
r.xy = -s;
|
||||
r.yx = s;
|
||||
r.yy = c;
|
||||
FcMatrixMultiply (m, &r, m);
|
||||
}
|
||||
|
||||
void
|
||||
FcMatrixScale (FcMatrix *m, double sx, double sy)
|
||||
{
|
||||
FcMatrix r;
|
||||
|
||||
r.xx = sx;
|
||||
r.xy = 0;
|
||||
r.yx = 0;
|
||||
r.yy = sy;
|
||||
FcMatrixMultiply (m, &r, m);
|
||||
}
|
||||
|
||||
void
|
||||
FcMatrixShear (FcMatrix *m, double sh, double sv)
|
||||
{
|
||||
FcMatrix r;
|
||||
|
||||
r.xx = 1;
|
||||
r.xy = sh;
|
||||
r.yx = sv;
|
||||
r.yy = 1;
|
||||
FcMatrixMultiply (m, &r, m);
|
||||
}
|
|
@ -0,0 +1,621 @@
|
|||
/*
|
||||
* $XFree86: xc/lib/Fc/xftname.c,v 1.10 2001/03/30 18:50:18 keithp Exp $
|
||||
*
|
||||
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "fcint.h"
|
||||
|
||||
static const FcObjectType _FcBaseObjectTypes[] = {
|
||||
{ FC_FAMILY, FcTypeString, },
|
||||
{ FC_STYLE, FcTypeString, },
|
||||
{ FC_SLANT, FcTypeInteger, },
|
||||
{ FC_WEIGHT, FcTypeInteger, },
|
||||
{ FC_SIZE, FcTypeDouble, },
|
||||
{ FC_PIXEL_SIZE, FcTypeDouble, },
|
||||
{ FC_SPACING, FcTypeInteger, },
|
||||
{ FC_FOUNDRY, FcTypeString, },
|
||||
/* { FC_CORE, FcTypeBool, }, */
|
||||
{ FC_ANTIALIAS, FcTypeBool, },
|
||||
/* { FC_XLFD, FcTypeString, }, */
|
||||
{ FC_FILE, FcTypeString, },
|
||||
{ FC_INDEX, FcTypeInteger, },
|
||||
{ FC_RASTERIZER, FcTypeString, },
|
||||
{ FC_OUTLINE, FcTypeBool, },
|
||||
{ FC_SCALABLE, FcTypeBool, },
|
||||
{ FC_RGBA, FcTypeInteger, },
|
||||
{ FC_SCALE, FcTypeDouble, },
|
||||
/* { FC_RENDER, FcTypeBool, },*/
|
||||
{ FC_MINSPACE, FcTypeBool, },
|
||||
{ FC_CHAR_WIDTH, FcTypeInteger },
|
||||
{ FC_CHAR_HEIGHT, FcTypeInteger },
|
||||
{ FC_MATRIX, FcTypeMatrix },
|
||||
{ FC_CHARSET, FcTypeCharSet },
|
||||
{ FC_LANG, FcTypeString },
|
||||
};
|
||||
|
||||
#define NUM_OBJECT_TYPES (sizeof _FcBaseObjectTypes / sizeof _FcBaseObjectTypes[0])
|
||||
|
||||
typedef struct _FcObjectTypeList FcObjectTypeList;
|
||||
|
||||
struct _FcObjectTypeList {
|
||||
const FcObjectTypeList *next;
|
||||
const FcObjectType *types;
|
||||
int ntypes;
|
||||
};
|
||||
|
||||
static const FcObjectTypeList _FcBaseObjectTypesList = {
|
||||
0,
|
||||
_FcBaseObjectTypes,
|
||||
NUM_OBJECT_TYPES
|
||||
};
|
||||
|
||||
static const FcObjectTypeList *_FcObjectTypes = &_FcBaseObjectTypesList;
|
||||
|
||||
FcBool
|
||||
FcNameRegisterObjectTypes (const FcObjectType *types, int ntypes)
|
||||
{
|
||||
FcObjectTypeList *l;
|
||||
|
||||
l = (FcObjectTypeList *) malloc (sizeof (FcObjectTypeList));
|
||||
if (!l)
|
||||
return FcFalse;
|
||||
l->types = types;
|
||||
l->ntypes = ntypes;
|
||||
l->next = _FcObjectTypes;
|
||||
_FcObjectTypes = l;
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcNameUnregisterObjectTypes (const FcObjectType *types, int ntypes)
|
||||
{
|
||||
const FcObjectTypeList *l, **prev;
|
||||
|
||||
for (prev = &_FcObjectTypes;
|
||||
(l = *prev);
|
||||
prev = (const FcObjectTypeList **) &(l->next))
|
||||
{
|
||||
if (l->types == types && l->ntypes == ntypes)
|
||||
{
|
||||
*prev = l->next;
|
||||
free ((void *) l);
|
||||
return FcTrue;
|
||||
}
|
||||
}
|
||||
return FcFalse;
|
||||
}
|
||||
|
||||
const FcObjectType *
|
||||
FcNameGetObjectType (const char *object)
|
||||
{
|
||||
int i;
|
||||
const FcObjectTypeList *l;
|
||||
const FcObjectType *t;
|
||||
|
||||
for (l = _FcObjectTypes; l; l = l->next)
|
||||
{
|
||||
for (i = 0; i < l->ntypes; i++)
|
||||
{
|
||||
t = &l->types[i];
|
||||
if (!FcStrCmpIgnoreCase (object, t->object))
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const FcConstant _FcBaseConstants[] = {
|
||||
{ "light", "weight", FC_WEIGHT_LIGHT, },
|
||||
{ "medium", "weight", FC_WEIGHT_MEDIUM, },
|
||||
{ "demibold", "weight", FC_WEIGHT_DEMIBOLD, },
|
||||
{ "bold", "weight", FC_WEIGHT_BOLD, },
|
||||
{ "black", "weight", FC_WEIGHT_BLACK, },
|
||||
|
||||
{ "roman", "slant", FC_SLANT_ROMAN, },
|
||||
{ "italic", "slant", FC_SLANT_ITALIC, },
|
||||
{ "oblique", "slant", FC_SLANT_OBLIQUE, },
|
||||
|
||||
{ "proportional", "spacing", FC_PROPORTIONAL, },
|
||||
{ "mono", "spacing", FC_MONO, },
|
||||
{ "charcell", "spacing", FC_CHARCELL, },
|
||||
|
||||
{ "rgb", "rgba", FC_RGBA_RGB, },
|
||||
{ "bgr", "rgba", FC_RGBA_BGR, },
|
||||
{ "vrgb", "rgba", FC_RGBA_VRGB },
|
||||
{ "vbgr", "rgba", FC_RGBA_VBGR },
|
||||
};
|
||||
|
||||
#define NUM_FC_CONSTANTS (sizeof _FcBaseConstants/sizeof _FcBaseConstants[0])
|
||||
|
||||
typedef struct _FcConstantList FcConstantList;
|
||||
|
||||
struct _FcConstantList {
|
||||
const FcConstantList *next;
|
||||
const FcConstant *consts;
|
||||
int nconsts;
|
||||
};
|
||||
|
||||
static const FcConstantList _FcBaseConstantList = {
|
||||
0,
|
||||
_FcBaseConstants,
|
||||
NUM_FC_CONSTANTS
|
||||
};
|
||||
|
||||
static const FcConstantList *_FcConstants = &_FcBaseConstantList;
|
||||
|
||||
FcBool
|
||||
FcNameRegisterConstants (const FcConstant *consts, int nconsts)
|
||||
{
|
||||
FcConstantList *l;
|
||||
|
||||
l = (FcConstantList *) malloc (sizeof (FcConstantList));
|
||||
if (!l)
|
||||
return FcFalse;
|
||||
l->consts = consts;
|
||||
l->nconsts = nconsts;
|
||||
l->next = _FcConstants;
|
||||
_FcConstants = l;
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcNameUnregisterConstants (const FcConstant *consts, int nconsts)
|
||||
{
|
||||
const FcConstantList *l, **prev;
|
||||
|
||||
for (prev = &_FcConstants;
|
||||
(l = *prev);
|
||||
prev = (const FcConstantList **) &(l->next))
|
||||
{
|
||||
if (l->consts == consts && l->nconsts == nconsts)
|
||||
{
|
||||
*prev = l->next;
|
||||
free ((void *) l);
|
||||
return FcTrue;
|
||||
}
|
||||
}
|
||||
return FcFalse;
|
||||
}
|
||||
|
||||
const FcConstant *
|
||||
FcNameGetConstant (char *string)
|
||||
{
|
||||
const FcConstantList *l;
|
||||
int i;
|
||||
|
||||
for (l = _FcConstants; l; l = l->next)
|
||||
{
|
||||
for (i = 0; i < l->nconsts; i++)
|
||||
if (!FcStrCmpIgnoreCase (string, l->consts[i].name))
|
||||
return &l->consts[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcNameConstant (char *string, int *result)
|
||||
{
|
||||
const FcConstant *c;
|
||||
|
||||
if ((c = FcNameGetConstant(string)))
|
||||
{
|
||||
*result = c->value;
|
||||
return FcTrue;
|
||||
}
|
||||
return FcFalse;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcNameBool (char *v, FcBool *result)
|
||||
{
|
||||
char c0, c1;
|
||||
|
||||
c0 = *v;
|
||||
if (isupper (c0))
|
||||
c0 = tolower (c0);
|
||||
if (c0 == 't' || c0 == 'y' || c0 == '1')
|
||||
{
|
||||
*result = FcTrue;
|
||||
return FcTrue;
|
||||
}
|
||||
if (c0 == 'f' || c0 == 'n' || c0 == '0')
|
||||
{
|
||||
*result = FcFalse;
|
||||
return FcTrue;
|
||||
}
|
||||
if (c0 == 'o')
|
||||
{
|
||||
c1 = v[1];
|
||||
if (isupper (c1))
|
||||
c1 = tolower (c1);
|
||||
if (c1 == 'n')
|
||||
{
|
||||
*result = FcTrue;
|
||||
return FcTrue;
|
||||
}
|
||||
if (c1 == 'f')
|
||||
{
|
||||
*result = FcFalse;
|
||||
return FcTrue;
|
||||
}
|
||||
}
|
||||
return FcFalse;
|
||||
}
|
||||
|
||||
static FcValue
|
||||
FcNameConvert (FcType type, char *string, FcMatrix *m)
|
||||
{
|
||||
FcValue v;
|
||||
|
||||
v.type = type;
|
||||
switch (v.type) {
|
||||
case FcTypeInteger:
|
||||
if (!FcNameConstant (string, &v.u.i))
|
||||
v.u.i = atoi (string);
|
||||
break;
|
||||
case FcTypeString:
|
||||
v.u.s = string;
|
||||
break;
|
||||
case FcTypeBool:
|
||||
if (!FcNameBool (string, &v.u.b))
|
||||
v.u.b = FcFalse;
|
||||
break;
|
||||
case FcTypeDouble:
|
||||
v.u.d = strtod (string, 0);
|
||||
break;
|
||||
case FcTypeMatrix:
|
||||
v.u.m = m;
|
||||
sscanf (string, "%lg %lg %lg %lg", &m->xx, &m->xy, &m->yx, &m->yy);
|
||||
break;
|
||||
case FcTypeCharSet:
|
||||
v.u.c = FcNameParseCharSet (string);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static const char *
|
||||
FcNameFindNext (const char *cur, const char *delim, char *save, char *last)
|
||||
{
|
||||
char c;
|
||||
|
||||
while ((c = *cur))
|
||||
{
|
||||
if (c == '\\')
|
||||
{
|
||||
++cur;
|
||||
if (!(c = *cur))
|
||||
break;
|
||||
}
|
||||
else if (strchr (delim, c))
|
||||
break;
|
||||
++cur;
|
||||
*save++ = c;
|
||||
}
|
||||
*save = 0;
|
||||
*last = *cur;
|
||||
if (*cur)
|
||||
cur++;
|
||||
return cur;
|
||||
}
|
||||
|
||||
FcPattern *
|
||||
FcNameParse (const char *name)
|
||||
{
|
||||
char *save;
|
||||
FcPattern *pat;
|
||||
double d;
|
||||
char *e;
|
||||
char delim;
|
||||
FcValue v;
|
||||
FcMatrix m;
|
||||
const FcObjectType *t;
|
||||
const FcConstant *c;
|
||||
|
||||
save = malloc (strlen (name) + 1);
|
||||
if (!save)
|
||||
goto bail0;
|
||||
pat = FcPatternCreate ();
|
||||
if (!pat)
|
||||
goto bail1;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
name = FcNameFindNext (name, "-,:", save, &delim);
|
||||
if (save[0])
|
||||
{
|
||||
if (!FcPatternAddString (pat, FC_FAMILY, save))
|
||||
goto bail2;
|
||||
}
|
||||
if (delim != ',')
|
||||
break;
|
||||
}
|
||||
if (delim == '-')
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
name = FcNameFindNext (name, "-,:", save, &delim);
|
||||
d = strtod (save, &e);
|
||||
if (e != save)
|
||||
{
|
||||
if (!FcPatternAddDouble (pat, FC_SIZE, d))
|
||||
goto bail2;
|
||||
}
|
||||
if (delim != ',')
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (delim == ':')
|
||||
{
|
||||
name = FcNameFindNext (name, "=_:", save, &delim);
|
||||
if (save[0])
|
||||
{
|
||||
if (delim == '=' || delim == '_')
|
||||
{
|
||||
t = FcNameGetObjectType (save);
|
||||
for (;;)
|
||||
{
|
||||
name = FcNameFindNext (name, ":,", save, &delim);
|
||||
if (save[0] && t)
|
||||
{
|
||||
v = FcNameConvert (t->type, save, &m);
|
||||
if (!FcPatternAdd (pat, t->object, v, FcTrue))
|
||||
{
|
||||
if (v.type == FcTypeCharSet)
|
||||
FcCharSetDestroy ((FcCharSet *) v.u.c);
|
||||
goto bail2;
|
||||
}
|
||||
if (v.type == FcTypeCharSet)
|
||||
FcCharSetDestroy ((FcCharSet *) v.u.c);
|
||||
}
|
||||
if (delim != ',')
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((c = FcNameGetConstant (save)))
|
||||
{
|
||||
if (!FcPatternAddInteger (pat, c->object, c->value))
|
||||
goto bail2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free (save);
|
||||
return pat;
|
||||
|
||||
bail2:
|
||||
FcPatternDestroy (pat);
|
||||
bail1:
|
||||
free (save);
|
||||
bail0:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
FcNameBufInit (FcNameBuf *buf, FcChar8 *init, int size)
|
||||
{
|
||||
buf->buf = init;
|
||||
buf->allocated = FcFalse;
|
||||
buf->failed = FcFalse;
|
||||
buf->len = 0;
|
||||
buf->size = size;
|
||||
}
|
||||
|
||||
static void
|
||||
FcNameBufDestroy (FcNameBuf *buf)
|
||||
{
|
||||
if (buf->allocated)
|
||||
free (buf->buf);
|
||||
}
|
||||
|
||||
static FcChar8 *
|
||||
FcNameBufDone (FcNameBuf *buf)
|
||||
{
|
||||
FcChar8 *ret;
|
||||
|
||||
ret = malloc (buf->len + 1);
|
||||
if (ret)
|
||||
{
|
||||
memcpy (ret, buf->buf, buf->len);
|
||||
ret[buf->len] = '\0';
|
||||
}
|
||||
FcNameBufDestroy (buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcNameBufChar (FcNameBuf *buf, FcChar8 c)
|
||||
{
|
||||
if (buf->len == buf->size)
|
||||
{
|
||||
FcChar8 *new;
|
||||
int size;
|
||||
|
||||
if (buf->allocated)
|
||||
{
|
||||
size = buf->size * 2;
|
||||
new = realloc (buf->buf, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
size = buf->size + 1024;
|
||||
new = malloc (size);
|
||||
if (new)
|
||||
{
|
||||
buf->allocated = FcTrue;
|
||||
memcpy (new, buf->buf, buf->len);
|
||||
}
|
||||
}
|
||||
if (!new)
|
||||
{
|
||||
buf->failed = FcTrue;
|
||||
return FcFalse;
|
||||
}
|
||||
buf->size = size;
|
||||
buf->buf = new;
|
||||
}
|
||||
buf->buf[buf->len++] = c;
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcNameBufString (FcNameBuf *buf, const FcChar8 *s)
|
||||
{
|
||||
FcChar8 c;
|
||||
while ((c = *s++))
|
||||
if (!FcNameBufChar (buf, c))
|
||||
return FcFalse;
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcNameUnparseString (FcNameBuf *buf,
|
||||
const FcChar8 *string,
|
||||
const FcChar8 *escape)
|
||||
{
|
||||
FcChar8 c;
|
||||
while ((c = *string++))
|
||||
{
|
||||
if (escape && strchr ((char *) escape, (char) c))
|
||||
{
|
||||
if (!FcNameBufChar (buf, escape[0]))
|
||||
return FcFalse;
|
||||
}
|
||||
if (!FcNameBufChar (buf, c))
|
||||
return FcFalse;
|
||||
}
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcNameUnparseValue (FcNameBuf *buf,
|
||||
FcValue v,
|
||||
FcChar8 *escape)
|
||||
{
|
||||
FcChar8 temp[1024];
|
||||
|
||||
switch (v.type) {
|
||||
case FcTypeVoid:
|
||||
return FcTrue;
|
||||
case FcTypeInteger:
|
||||
sprintf ((char *) temp, "%d", v.u.i);
|
||||
return FcNameUnparseString (buf, temp, 0);
|
||||
case FcTypeDouble:
|
||||
sprintf ((char *) temp, "%g", v.u.d);
|
||||
return FcNameUnparseString (buf, temp, 0);
|
||||
case FcTypeString:
|
||||
return FcNameUnparseString (buf, v.u.s, escape);
|
||||
case FcTypeBool:
|
||||
return FcNameUnparseString (buf, v.u.b ? "True" : "False", 0);
|
||||
case FcTypeMatrix:
|
||||
sprintf ((char *) temp, "%g %g %g %g",
|
||||
v.u.m->xx, v.u.m->xy, v.u.m->yx, v.u.m->yy);
|
||||
return FcNameUnparseString (buf, temp, 0);
|
||||
case FcTypeCharSet:
|
||||
return FcNameUnparseCharSet (buf, v.u.c);
|
||||
}
|
||||
return FcFalse;
|
||||
}
|
||||
|
||||
static FcBool
|
||||
FcNameUnparseValueList (FcNameBuf *buf,
|
||||
FcValueList *v,
|
||||
char *escape)
|
||||
{
|
||||
while (v)
|
||||
{
|
||||
if (!FcNameUnparseValue (buf, v->value, escape))
|
||||
return FcFalse;
|
||||
if ((v = v->next))
|
||||
if (!FcNameUnparseString (buf, ",", 0))
|
||||
return FcFalse;
|
||||
}
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
#define FC_ESCAPE_FIXED "\\-:,"
|
||||
#define FC_ESCAPE_VARIABLE "\\=_:,"
|
||||
|
||||
FcChar8 *
|
||||
FcNameUnparse (FcPattern *pat)
|
||||
{
|
||||
FcNameBuf buf;
|
||||
FcChar8 buf_static[8192];
|
||||
int i;
|
||||
FcPatternElt *e;
|
||||
const FcObjectTypeList *l;
|
||||
const FcObjectType *o;
|
||||
|
||||
FcNameBufInit (&buf, buf_static, sizeof (buf_static));
|
||||
e = FcPatternFind (pat, FC_FAMILY, FcFalse);
|
||||
if (e)
|
||||
{
|
||||
if (!FcNameUnparseValueList (&buf, e->values, FC_ESCAPE_FIXED))
|
||||
goto bail0;
|
||||
}
|
||||
e = FcPatternFind (pat, FC_SIZE, FcFalse);
|
||||
if (e)
|
||||
{
|
||||
if (!FcNameUnparseString (&buf, "-", 0))
|
||||
goto bail0;
|
||||
if (!FcNameUnparseValueList (&buf, e->values, FC_ESCAPE_FIXED))
|
||||
goto bail0;
|
||||
}
|
||||
for (l = _FcObjectTypes; l; l = l->next)
|
||||
{
|
||||
for (i = 0; i < l->ntypes; i++)
|
||||
{
|
||||
o = &l->types[i];
|
||||
if (!strcmp (o->object, FC_FAMILY) ||
|
||||
!strcmp (o->object, FC_SIZE) ||
|
||||
!strcmp (o->object, FC_FILE))
|
||||
continue;
|
||||
|
||||
e = FcPatternFind (pat, o->object, FcFalse);
|
||||
if (e)
|
||||
{
|
||||
if (!FcNameUnparseString (&buf, ":", 0))
|
||||
goto bail0;
|
||||
if (!FcNameUnparseString (&buf, o->object, FC_ESCAPE_VARIABLE))
|
||||
goto bail0;
|
||||
if (!FcNameUnparseString (&buf, "=", 0))
|
||||
goto bail0;
|
||||
if (!FcNameUnparseValueList (&buf, e->values,
|
||||
FC_ESCAPE_VARIABLE))
|
||||
goto bail0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FcNameBufDone (&buf);
|
||||
bail0:
|
||||
FcNameBufDestroy (&buf);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,491 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "fcint.h"
|
||||
|
||||
FcPattern *
|
||||
FcPatternCreate (void)
|
||||
{
|
||||
FcPattern *p;
|
||||
|
||||
p = (FcPattern *) malloc (sizeof (FcPattern));
|
||||
if (!p)
|
||||
return 0;
|
||||
FcMemAlloc (FC_MEM_PATTERN, sizeof (FcPattern));
|
||||
p->num = 0;
|
||||
p->size = 0;
|
||||
p->elts = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
FcValueDestroy (FcValue v)
|
||||
{
|
||||
switch (v.type) {
|
||||
case FcTypeString:
|
||||
FcStrFree ((FcChar8 *) v.u.s);
|
||||
break;
|
||||
case FcTypeMatrix:
|
||||
FcMatrixFree ((FcMatrix *) v.u.m);
|
||||
break;
|
||||
case FcTypeCharSet:
|
||||
FcCharSetDestroy ((FcCharSet *) v.u.c);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FcValue
|
||||
FcValueSave (FcValue v)
|
||||
{
|
||||
switch (v.type) {
|
||||
case FcTypeString:
|
||||
v.u.s = FcStrCopy (v.u.s);
|
||||
if (!v.u.s)
|
||||
v.type = FcTypeVoid;
|
||||
break;
|
||||
case FcTypeMatrix:
|
||||
v.u.m = FcMatrixCopy (v.u.m);
|
||||
if (!v.u.m)
|
||||
v.type = FcTypeVoid;
|
||||
break;
|
||||
case FcTypeCharSet:
|
||||
v.u.c = FcCharSetCopy ((FcCharSet *) v.u.c);
|
||||
if (!v.u.c)
|
||||
v.type = FcTypeVoid;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
void
|
||||
FcValueListDestroy (FcValueList *l)
|
||||
{
|
||||
FcValueList *next;
|
||||
for (; l; l = next)
|
||||
{
|
||||
switch (l->value.type) {
|
||||
case FcTypeString:
|
||||
FcStrFree ((FcChar8 *) l->value.u.s);
|
||||
break;
|
||||
case FcTypeMatrix:
|
||||
FcMatrixFree ((FcMatrix *) l->value.u.m);
|
||||
break;
|
||||
case FcTypeCharSet:
|
||||
FcCharSetDestroy ((FcCharSet *) l->value.u.c);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
next = l->next;
|
||||
FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
|
||||
free (l);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FcPatternDestroy (FcPattern *p)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < p->num; i++)
|
||||
FcValueListDestroy (p->elts[i].values);
|
||||
|
||||
p->num = 0;
|
||||
if (p->elts)
|
||||
{
|
||||
FcMemFree (FC_MEM_PATELT, p->size * sizeof (FcPatternElt));
|
||||
free (p->elts);
|
||||
p->elts = 0;
|
||||
}
|
||||
p->size = 0;
|
||||
FcMemFree (FC_MEM_PATTERN, sizeof (FcPattern));
|
||||
free (p);
|
||||
}
|
||||
|
||||
FcPatternElt *
|
||||
FcPatternFind (FcPattern *p, const char *object, FcBool insert)
|
||||
{
|
||||
int i;
|
||||
int s;
|
||||
FcPatternElt *e;
|
||||
|
||||
/* match existing */
|
||||
for (i = 0; i < p->num; i++)
|
||||
{
|
||||
if (!FcStrCmpIgnoreCase (object, p->elts[i].object))
|
||||
return &p->elts[i];
|
||||
}
|
||||
|
||||
if (!insert)
|
||||
return FcFalse;
|
||||
|
||||
/* grow array */
|
||||
if (i == p->size)
|
||||
{
|
||||
s = p->size + 16;
|
||||
if (p->elts)
|
||||
e = (FcPatternElt *) realloc (p->elts, s * sizeof (FcPatternElt));
|
||||
else
|
||||
e = (FcPatternElt *) malloc (s * sizeof (FcPatternElt));
|
||||
if (!e)
|
||||
return FcFalse;
|
||||
p->elts = e;
|
||||
if (p->size)
|
||||
FcMemFree (FC_MEM_PATELT, p->size * sizeof (FcPatternElt));
|
||||
FcMemAlloc (FC_MEM_PATELT, s * sizeof (FcPatternElt));
|
||||
while (p->size < s)
|
||||
{
|
||||
p->elts[p->size].object = 0;
|
||||
p->elts[p->size].values = 0;
|
||||
p->size++;
|
||||
}
|
||||
}
|
||||
|
||||
/* bump count */
|
||||
p->num++;
|
||||
|
||||
p->elts[i].object = object;
|
||||
|
||||
return &p->elts[i];
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append)
|
||||
{
|
||||
FcPatternElt *e;
|
||||
FcValueList *new, **prev;
|
||||
|
||||
new = (FcValueList *) malloc (sizeof (FcValueList));
|
||||
if (!new)
|
||||
goto bail0;
|
||||
|
||||
FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList));
|
||||
/* dup string */
|
||||
value = FcValueSave (value);
|
||||
if (value.type == FcTypeVoid)
|
||||
goto bail1;
|
||||
|
||||
new->value = value;
|
||||
new->next = 0;
|
||||
|
||||
e = FcPatternFind (p, object, FcTrue);
|
||||
if (!e)
|
||||
goto bail2;
|
||||
|
||||
if (append)
|
||||
{
|
||||
for (prev = &e->values; *prev; prev = &(*prev)->next);
|
||||
*prev = new;
|
||||
}
|
||||
else
|
||||
{
|
||||
new->next = e->values;
|
||||
e->values = new;
|
||||
}
|
||||
|
||||
return FcTrue;
|
||||
|
||||
bail2:
|
||||
switch (value.type) {
|
||||
case FcTypeString:
|
||||
FcStrFree ((FcChar8 *) value.u.s);
|
||||
break;
|
||||
case FcTypeMatrix:
|
||||
FcMatrixFree ((FcMatrix *) value.u.m);
|
||||
break;
|
||||
case FcTypeCharSet:
|
||||
FcCharSetDestroy ((FcCharSet *) value.u.c);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
bail1:
|
||||
FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
|
||||
free (new);
|
||||
bail0:
|
||||
return FcFalse;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcPatternDel (FcPattern *p, const char *object)
|
||||
{
|
||||
FcPatternElt *e;
|
||||
int i;
|
||||
|
||||
e = FcPatternFind (p, object, FcFalse);
|
||||
if (!e)
|
||||
return FcFalse;
|
||||
|
||||
i = e - p->elts;
|
||||
|
||||
/* destroy value */
|
||||
FcValueListDestroy (e->values);
|
||||
|
||||
/* shuffle existing ones down */
|
||||
memmove (e, e+1, (p->elts + p->num - (e + 1)) * sizeof (FcPatternElt));
|
||||
p->num--;
|
||||
p->elts[p->num].object = 0;
|
||||
p->elts[p->num].values = 0;
|
||||
return FcTrue;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcPatternAddInteger (FcPattern *p, const char *object, int i)
|
||||
{
|
||||
FcValue v;
|
||||
|
||||
v.type = FcTypeInteger;
|
||||
v.u.i = i;
|
||||
return FcPatternAdd (p, object, v, FcTrue);
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcPatternAddDouble (FcPattern *p, const char *object, double d)
|
||||
{
|
||||
FcValue v;
|
||||
|
||||
v.type = FcTypeDouble;
|
||||
v.u.d = d;
|
||||
return FcPatternAdd (p, object, v, FcTrue);
|
||||
}
|
||||
|
||||
|
||||
FcBool
|
||||
FcPatternAddString (FcPattern *p, const char *object, const char *s)
|
||||
{
|
||||
FcValue v;
|
||||
|
||||
v.type = FcTypeString;
|
||||
v.u.s = (char *) s;
|
||||
return FcPatternAdd (p, object, v, FcTrue);
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcPatternAddMatrix (FcPattern *p, const char *object, const FcMatrix *s)
|
||||
{
|
||||
FcValue v;
|
||||
|
||||
v.type = FcTypeMatrix;
|
||||
v.u.m = (FcMatrix *) s;
|
||||
return FcPatternAdd (p, object, v, FcTrue);
|
||||
}
|
||||
|
||||
|
||||
FcBool
|
||||
FcPatternAddBool (FcPattern *p, const char *object, FcBool b)
|
||||
{
|
||||
FcValue v;
|
||||
|
||||
v.type = FcTypeBool;
|
||||
v.u.b = b;
|
||||
return FcPatternAdd (p, object, v, FcTrue);
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcPatternAddCharSet (FcPattern *p, const char *object, const FcCharSet *c)
|
||||
{
|
||||
FcValue v;
|
||||
|
||||
v.type = FcTypeCharSet;
|
||||
v.u.c = (FcCharSet *) c;
|
||||
return FcPatternAdd (p, object, v, FcTrue);
|
||||
}
|
||||
|
||||
FcResult
|
||||
FcPatternGet (FcPattern *p, const char *object, int id, FcValue *v)
|
||||
{
|
||||
FcPatternElt *e;
|
||||
FcValueList *l;
|
||||
|
||||
e = FcPatternFind (p, object, FcFalse);
|
||||
if (!e)
|
||||
return FcResultNoMatch;
|
||||
for (l = e->values; l; l = l->next)
|
||||
{
|
||||
if (!id)
|
||||
{
|
||||
*v = l->value;
|
||||
return FcResultMatch;
|
||||
}
|
||||
id--;
|
||||
}
|
||||
return FcResultNoId;
|
||||
}
|
||||
|
||||
FcResult
|
||||
FcPatternGetInteger (FcPattern *p, const char *object, int id, int *i)
|
||||
{
|
||||
FcValue v;
|
||||
FcResult r;
|
||||
|
||||
r = FcPatternGet (p, object, id, &v);
|
||||
if (r != FcResultMatch)
|
||||
return r;
|
||||
switch (v.type) {
|
||||
case FcTypeDouble:
|
||||
*i = (int) v.u.d;
|
||||
break;
|
||||
case FcTypeInteger:
|
||||
*i = v.u.i;
|
||||
break;
|
||||
default:
|
||||
return FcResultTypeMismatch;
|
||||
}
|
||||
return FcResultMatch;
|
||||
}
|
||||
|
||||
FcResult
|
||||
FcPatternGetDouble (FcPattern *p, const char *object, int id, double *d)
|
||||
{
|
||||
FcValue v;
|
||||
FcResult r;
|
||||
|
||||
r = FcPatternGet (p, object, id, &v);
|
||||
if (r != FcResultMatch)
|
||||
return r;
|
||||
switch (v.type) {
|
||||
case FcTypeDouble:
|
||||
*d = v.u.d;
|
||||
break;
|
||||
case FcTypeInteger:
|
||||
*d = (double) v.u.i;
|
||||
break;
|
||||
default:
|
||||
return FcResultTypeMismatch;
|
||||
}
|
||||
return FcResultMatch;
|
||||
}
|
||||
|
||||
FcResult
|
||||
FcPatternGetString (FcPattern *p, const char *object, int id, char ** s)
|
||||
{
|
||||
FcValue v;
|
||||
FcResult r;
|
||||
|
||||
r = FcPatternGet (p, object, id, &v);
|
||||
if (r != FcResultMatch)
|
||||
return r;
|
||||
if (v.type != FcTypeString)
|
||||
return FcResultTypeMismatch;
|
||||
*s = (char *) v.u.s;
|
||||
return FcResultMatch;
|
||||
}
|
||||
|
||||
FcResult
|
||||
FcPatternGetMatrix (FcPattern *p, const char *object, int id, FcMatrix **m)
|
||||
{
|
||||
FcValue v;
|
||||
FcResult r;
|
||||
|
||||
r = FcPatternGet (p, object, id, &v);
|
||||
if (r != FcResultMatch)
|
||||
return r;
|
||||
if (v.type != FcTypeMatrix)
|
||||
return FcResultTypeMismatch;
|
||||
*m = (FcMatrix *) v.u.m;
|
||||
return FcResultMatch;
|
||||
}
|
||||
|
||||
|
||||
FcResult
|
||||
FcPatternGetBool (FcPattern *p, const char *object, int id, FcBool *b)
|
||||
{
|
||||
FcValue v;
|
||||
FcResult r;
|
||||
|
||||
r = FcPatternGet (p, object, id, &v);
|
||||
if (r != FcResultMatch)
|
||||
return r;
|
||||
if (v.type != FcTypeBool)
|
||||
return FcResultTypeMismatch;
|
||||
*b = v.u.b;
|
||||
return FcResultMatch;
|
||||
}
|
||||
|
||||
FcResult
|
||||
FcPatternGetCharSet (FcPattern *p, const char *object, int id, FcCharSet **c)
|
||||
{
|
||||
FcValue v;
|
||||
FcResult r;
|
||||
|
||||
r = FcPatternGet (p, object, id, &v);
|
||||
if (r != FcResultMatch)
|
||||
return r;
|
||||
if (v.type != FcTypeCharSet)
|
||||
return FcResultTypeMismatch;
|
||||
*c = (FcCharSet *) v.u.c;
|
||||
return FcResultMatch;
|
||||
}
|
||||
|
||||
FcPattern *
|
||||
FcPatternDuplicate (FcPattern *orig)
|
||||
{
|
||||
FcPattern *new;
|
||||
int i;
|
||||
FcValueList *l;
|
||||
|
||||
new = FcPatternCreate ();
|
||||
if (!new)
|
||||
goto bail0;
|
||||
|
||||
for (i = 0; i < orig->num; i++)
|
||||
{
|
||||
for (l = orig->elts[i].values; l; l = l->next)
|
||||
if (!FcPatternAdd (new, orig->elts[i].object, l->value, FcTrue))
|
||||
goto bail1;
|
||||
}
|
||||
|
||||
return new;
|
||||
|
||||
bail1:
|
||||
FcPatternDestroy (new);
|
||||
bail0:
|
||||
return 0;
|
||||
}
|
||||
|
||||
FcPattern *
|
||||
FcPatternVaBuild (FcPattern *orig, va_list va)
|
||||
{
|
||||
FcPattern *ret;
|
||||
|
||||
FcPatternVapBuild (ret, orig, va);
|
||||
return ret;
|
||||
}
|
||||
|
||||
FcPattern *
|
||||
FcPatternBuild (FcPattern *orig, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
va_start (va, orig);
|
||||
FcPatternVapBuild (orig, orig, va);
|
||||
va_end (va);
|
||||
return orig;
|
||||
}
|
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
* $XFree86: $
|
||||
*
|
||||
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||
*
|
||||
* 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 Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include "fcint.h"
|
||||
|
||||
char *
|
||||
FcStrCopy (const char *s)
|
||||
{
|
||||
char *r;
|
||||
|
||||
if (!s)
|
||||
return 0;
|
||||
r = (char *) malloc (strlen (s) + 1);
|
||||
if (!r)
|
||||
return 0;
|
||||
FcMemAlloc (FC_MEM_STRING, strlen (s) + 1);
|
||||
strcpy (r, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
char *
|
||||
FcStrPlus (const char *s1, const char *s2)
|
||||
{
|
||||
int l = strlen (s1) + strlen (s2) + 1;
|
||||
char *s = malloc (l);
|
||||
|
||||
if (!s)
|
||||
return 0;
|
||||
FcMemAlloc (FC_MEM_STRING, l);
|
||||
strcpy (s, s1);
|
||||
strcat (s, s2);
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
FcStrFree (char *s)
|
||||
{
|
||||
FcMemFree (FC_MEM_STRING, strlen (s) + 1);
|
||||
free (s);
|
||||
}
|
||||
|
||||
int
|
||||
FcStrCmpIgnoreCase (const char *s1, const char *s2)
|
||||
{
|
||||
char c1, c2;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
c1 = *s1++;
|
||||
c2 = *s2++;
|
||||
if (!c1 || !c2)
|
||||
break;
|
||||
c1 = FcToLower (c1);
|
||||
c2 = FcToLower (c2);
|
||||
if (c1 != c2)
|
||||
break;
|
||||
}
|
||||
return (int) c2 - (int) c1;
|
||||
}
|
||||
|
||||
int
|
||||
FcUtf8ToUcs4 (FcChar8 *src_orig,
|
||||
FcChar32 *dst,
|
||||
int len)
|
||||
{
|
||||
FcChar8 *src = src_orig;
|
||||
FcChar8 s;
|
||||
int extra;
|
||||
FcChar32 result;
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
s = *src++;
|
||||
len--;
|
||||
|
||||
if (!(s & 0x80))
|
||||
{
|
||||
result = s;
|
||||
extra = 0;
|
||||
}
|
||||
else if (!(s & 0x40))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (!(s & 0x20))
|
||||
{
|
||||
result = s & 0x1f;
|
||||
extra = 1;
|
||||
}
|
||||
else if (!(s & 0x10))
|
||||
{
|
||||
result = s & 0xf;
|
||||
extra = 2;
|
||||
}
|
||||
else if (!(s & 0x08))
|
||||
{
|
||||
result = s & 0x07;
|
||||
extra = 3;
|
||||
}
|
||||
else if (!(s & 0x04))
|
||||
{
|
||||
result = s & 0x03;
|
||||
extra = 4;
|
||||
}
|
||||
else if ( ! (s & 0x02))
|
||||
{
|
||||
result = s & 0x01;
|
||||
extra = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (extra > len)
|
||||
return -1;
|
||||
|
||||
while (extra--)
|
||||
{
|
||||
result <<= 6;
|
||||
s = *src++;
|
||||
|
||||
if ((s & 0xc0) != 0x80)
|
||||
return -1;
|
||||
|
||||
result |= s & 0x3f;
|
||||
}
|
||||
*dst = result;
|
||||
return src - src_orig;
|
||||
}
|
||||
|
||||
FcBool
|
||||
FcUtf8Len (FcChar8 *string,
|
||||
int len,
|
||||
int *nchar,
|
||||
int *wchar)
|
||||
{
|
||||
int n;
|
||||
int clen;
|
||||
FcChar32 c;
|
||||
FcChar32 max;
|
||||
|
||||
n = 0;
|
||||
max = 0;
|
||||
while (len)
|
||||
{
|
||||
clen = FcUtf8ToUcs4 (string, &c, len);
|
||||
if (clen <= 0) /* malformed UTF8 string */
|
||||
return FcFalse;
|
||||
if (c > max)
|
||||
max = c;
|
||||
string += clen;
|
||||
len -= clen;
|
||||
n++;
|
||||
}
|
||||
*nchar = n;
|
||||
if (max >= 0x10000)
|
||||
*wchar = 4;
|
||||
else if (max > 0x100)
|
||||
*wchar = 2;
|
||||
else
|
||||
*wchar = 1;
|
||||
return FcTrue;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue