diff options
author | marha <marha@users.sourceforge.net> | 2011-09-12 11:27:51 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-09-12 11:27:51 +0200 |
commit | dafebc5bb70303f0b5baf0b087cf4d9a64b5c7f0 (patch) | |
tree | bdf833cc6a4fc9035411779e10dd9e8478201885 /libXfont/src/fontfile | |
parent | 0b40f5f4b54453a77f4b09c431f8efc6875da61f (diff) | |
download | vcxsrv-dafebc5bb70303f0b5baf0b087cf4d9a64b5c7f0.tar.gz vcxsrv-dafebc5bb70303f0b5baf0b087cf4d9a64b5c7f0.tar.bz2 vcxsrv-dafebc5bb70303f0b5baf0b087cf4d9a64b5c7f0.zip |
Synchronised line endinge with release branch
Diffstat (limited to 'libXfont/src/fontfile')
-rw-r--r-- | libXfont/src/fontfile/bitsource.c | 342 | ||||
-rw-r--r-- | libXfont/src/fontfile/bufio.c | 406 | ||||
-rw-r--r-- | libXfont/src/fontfile/decompress.c | 820 | ||||
-rw-r--r-- | libXfont/src/fontfile/defaults.c | 148 | ||||
-rw-r--r-- | libXfont/src/fontfile/dirfile.c | 984 | ||||
-rw-r--r-- | libXfont/src/fontfile/fileio.c | 182 | ||||
-rw-r--r-- | libXfont/src/fontfile/filewr.c | 124 | ||||
-rw-r--r-- | libXfont/src/fontfile/fontdir.c | 1650 | ||||
-rw-r--r-- | libXfont/src/fontfile/fontencc.c | 152 | ||||
-rw-r--r-- | libXfont/src/fontfile/fontfile.c | 2338 | ||||
-rw-r--r-- | libXfont/src/fontfile/fontscale.c | 882 | ||||
-rw-r--r-- | libXfont/src/fontfile/gunzip.c | 450 | ||||
-rw-r--r-- | libXfont/src/fontfile/renderers.c | 230 |
13 files changed, 4354 insertions, 4354 deletions
diff --git a/libXfont/src/fontfile/bitsource.c b/libXfont/src/fontfile/bitsource.c index f6ceb2aba..1b79c2bcb 100644 --- a/libXfont/src/fontfile/bitsource.c +++ b/libXfont/src/fontfile/bitsource.c @@ -1,171 +1,171 @@ -/*
-
-Copyright 1991, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-/*
- * Author: Keith Packard, MIT X Consortium
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/fonts/fntfilst.h>
-
-BitmapSourcesRec FontFileBitmapSources;
-
-Bool
-FontFileRegisterBitmapSource (FontPathElementPtr fpe)
-{
- FontPathElementPtr *new;
- int i;
- int newsize;
-
- for (i = 0; i < FontFileBitmapSources.count; i++)
- if (FontFileBitmapSources.fpe[i] == fpe)
- return TRUE;
- if (FontFileBitmapSources.count == FontFileBitmapSources.size)
- {
- newsize = FontFileBitmapSources.size + 4;
- new = realloc (FontFileBitmapSources.fpe, newsize * sizeof *new);
- if (!new)
- return FALSE;
- FontFileBitmapSources.size = newsize;
- FontFileBitmapSources.fpe = new;
- }
- FontFileBitmapSources.fpe[FontFileBitmapSources.count++] = fpe;
- return TRUE;
-}
-
-void
-FontFileUnregisterBitmapSource (FontPathElementPtr fpe)
-{
- int i;
-
- for (i = 0; i < FontFileBitmapSources.count; i++)
- if (FontFileBitmapSources.fpe[i] == fpe)
- {
- FontFileBitmapSources.count--;
- if (FontFileBitmapSources.count == 0)
- {
- FontFileBitmapSources.size = 0;
- free (FontFileBitmapSources.fpe);
- FontFileBitmapSources.fpe = 0;
- }
- else
- {
- for (; i < FontFileBitmapSources.count; i++)
- FontFileBitmapSources.fpe[i] = FontFileBitmapSources.fpe[i+1];
- }
- break;
- }
-}
-
-/*
- * Our set_path_hook: unregister all bitmap sources.
- * This is necessary because already open fonts will keep their FPEs
- * allocated, but they may not be on the new font path.
- * The bitmap sources in the new path will be registered by the init_func.
- */
-void
-FontFileEmptyBitmapSource(void)
-{
- if (FontFileBitmapSources.count == 0)
- return;
-
- FontFileBitmapSources.count = 0;
- FontFileBitmapSources.size = 0;
- free (FontFileBitmapSources.fpe);
- FontFileBitmapSources.fpe = 0;
-}
-
-int
-FontFileMatchBitmapSource (FontPathElementPtr fpe,
- FontPtr *pFont,
- int flags,
- FontEntryPtr entry,
- FontNamePtr zeroPat,
- FontScalablePtr vals,
- fsBitmapFormat format,
- fsBitmapFormatMask fmask,
- Bool noSpecificSize)
-{
- int source;
- FontEntryPtr zero;
- FontBitmapEntryPtr bitmap;
- int ret;
- FontDirectoryPtr dir;
- FontScaledPtr scaled;
-
- /*
- * Look through all the registered bitmap sources for
- * the same zero name as ours; entries along that one
- * can be scaled as desired.
- */
- ret = BadFontName;
- for (source = 0; source < FontFileBitmapSources.count; source++)
- {
- if (FontFileBitmapSources.fpe[source] == fpe)
- continue;
- dir = (FontDirectoryPtr) FontFileBitmapSources.fpe[source]->private;
- zero = FontFileFindNameInDir (&dir->scalable, zeroPat);
- if (!zero)
- continue;
- scaled = FontFileFindScaledInstance (zero, vals, noSpecificSize);
- if (scaled)
- {
- if (scaled->pFont)
- {
- *pFont = scaled->pFont;
- (*pFont)->fpe = FontFileBitmapSources.fpe[source];
- ret = Successful;
- }
- else if (scaled->bitmap)
- {
- entry = scaled->bitmap;
- bitmap = &entry->u.bitmap;
- if (bitmap->pFont)
- {
- *pFont = bitmap->pFont;
- (*pFont)->fpe = FontFileBitmapSources.fpe[source];
- ret = Successful;
- }
- else
- {
- ret = FontFileOpenBitmap (
- FontFileBitmapSources.fpe[source],
- pFont, flags, entry, format, fmask);
- if (ret == Successful && *pFont)
- (*pFont)->fpe = FontFileBitmapSources.fpe[source];
- }
- }
- else /* "cannot" happen */
- {
- ret = BadFontName;
- }
- break;
- }
- }
- return ret;
-}
+/* + +Copyright 1991, 1998 The Open Group + +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. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ + +/* + * Author: Keith Packard, MIT X Consortium + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/fonts/fntfilst.h> + +BitmapSourcesRec FontFileBitmapSources; + +Bool +FontFileRegisterBitmapSource (FontPathElementPtr fpe) +{ + FontPathElementPtr *new; + int i; + int newsize; + + for (i = 0; i < FontFileBitmapSources.count; i++) + if (FontFileBitmapSources.fpe[i] == fpe) + return TRUE; + if (FontFileBitmapSources.count == FontFileBitmapSources.size) + { + newsize = FontFileBitmapSources.size + 4; + new = realloc (FontFileBitmapSources.fpe, newsize * sizeof *new); + if (!new) + return FALSE; + FontFileBitmapSources.size = newsize; + FontFileBitmapSources.fpe = new; + } + FontFileBitmapSources.fpe[FontFileBitmapSources.count++] = fpe; + return TRUE; +} + +void +FontFileUnregisterBitmapSource (FontPathElementPtr fpe) +{ + int i; + + for (i = 0; i < FontFileBitmapSources.count; i++) + if (FontFileBitmapSources.fpe[i] == fpe) + { + FontFileBitmapSources.count--; + if (FontFileBitmapSources.count == 0) + { + FontFileBitmapSources.size = 0; + free (FontFileBitmapSources.fpe); + FontFileBitmapSources.fpe = 0; + } + else + { + for (; i < FontFileBitmapSources.count; i++) + FontFileBitmapSources.fpe[i] = FontFileBitmapSources.fpe[i+1]; + } + break; + } +} + +/* + * Our set_path_hook: unregister all bitmap sources. + * This is necessary because already open fonts will keep their FPEs + * allocated, but they may not be on the new font path. + * The bitmap sources in the new path will be registered by the init_func. + */ +void +FontFileEmptyBitmapSource(void) +{ + if (FontFileBitmapSources.count == 0) + return; + + FontFileBitmapSources.count = 0; + FontFileBitmapSources.size = 0; + free (FontFileBitmapSources.fpe); + FontFileBitmapSources.fpe = 0; +} + +int +FontFileMatchBitmapSource (FontPathElementPtr fpe, + FontPtr *pFont, + int flags, + FontEntryPtr entry, + FontNamePtr zeroPat, + FontScalablePtr vals, + fsBitmapFormat format, + fsBitmapFormatMask fmask, + Bool noSpecificSize) +{ + int source; + FontEntryPtr zero; + FontBitmapEntryPtr bitmap; + int ret; + FontDirectoryPtr dir; + FontScaledPtr scaled; + + /* + * Look through all the registered bitmap sources for + * the same zero name as ours; entries along that one + * can be scaled as desired. + */ + ret = BadFontName; + for (source = 0; source < FontFileBitmapSources.count; source++) + { + if (FontFileBitmapSources.fpe[source] == fpe) + continue; + dir = (FontDirectoryPtr) FontFileBitmapSources.fpe[source]->private; + zero = FontFileFindNameInDir (&dir->scalable, zeroPat); + if (!zero) + continue; + scaled = FontFileFindScaledInstance (zero, vals, noSpecificSize); + if (scaled) + { + if (scaled->pFont) + { + *pFont = scaled->pFont; + (*pFont)->fpe = FontFileBitmapSources.fpe[source]; + ret = Successful; + } + else if (scaled->bitmap) + { + entry = scaled->bitmap; + bitmap = &entry->u.bitmap; + if (bitmap->pFont) + { + *pFont = bitmap->pFont; + (*pFont)->fpe = FontFileBitmapSources.fpe[source]; + ret = Successful; + } + else + { + ret = FontFileOpenBitmap ( + FontFileBitmapSources.fpe[source], + pFont, flags, entry, format, fmask); + if (ret == Successful && *pFont) + (*pFont)->fpe = FontFileBitmapSources.fpe[source]; + } + } + else /* "cannot" happen */ + { + ret = BadFontName; + } + break; + } + } + return ret; +} diff --git a/libXfont/src/fontfile/bufio.c b/libXfont/src/fontfile/bufio.c index 8b880e150..34b7f3665 100644 --- a/libXfont/src/fontfile/bufio.c +++ b/libXfont/src/fontfile/bufio.c @@ -1,203 +1,203 @@ -/*
-
-Copyright 1991, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-/*
- * Author: Keith Packard, MIT X Consortium
- */
-
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xos.h>
-#include <X11/fonts/fontmisc.h>
-#include <X11/fonts/bufio.h>
-#include <errno.h>
-
-BufFilePtr
-BufFileCreate (char *private,
- int (*input)(BufFilePtr),
- int (*output)(int, BufFilePtr),
- int (*skip)(BufFilePtr, int),
- int (*close)(BufFilePtr, int))
-{
- BufFilePtr f;
-
- f = malloc (sizeof *f);
- if (!f)
- return 0;
- f->private = private;
- f->bufp = f->buffer;
- f->left = 0;
- f->input = input;
- f->output = output;
- f->skip = skip;
- f->eof = 0;
- f->close = close;
- return f;
-}
-
-#define FileDes(f) ((int)(long) (f)->private)
-
-static int
-BufFileRawFill (BufFilePtr f)
-{
- int left;
-
- left = read (FileDes(f), (char *)f->buffer, BUFFILESIZE);
- if (left <= 0) {
- f->left = 0;
- return BUFFILEEOF;
- }
- f->left = left - 1;
- f->bufp = f->buffer + 1;
- return f->buffer[0];
-}
-
-static int
-BufFileRawSkip (BufFilePtr f, int count)
-{
- int curoff;
- int fileoff;
- int todo;
-
- curoff = f->bufp - f->buffer;
- fileoff = curoff + f->left;
- if (curoff + count <= fileoff) {
- f->bufp += count;
- f->left -= count;
- } else {
- todo = count - (fileoff - curoff);
- if (lseek (FileDes(f), todo, 1) == -1) {
- if (errno != ESPIPE)
- return BUFFILEEOF;
- while (todo) {
- curoff = BUFFILESIZE;
- if (curoff > todo)
- curoff = todo;
- fileoff = read (FileDes(f), (char *)f->buffer, curoff);
- if (fileoff <= 0)
- return BUFFILEEOF;
- todo -= fileoff;
- }
- }
- f->left = 0;
- }
- return count;
-}
-
-static int
-BufFileRawClose (BufFilePtr f, int doClose)
-{
- if (doClose)
- close (FileDes (f));
- return 1;
-}
-
-BufFilePtr
-BufFileOpenRead (int fd)
-{
-#if defined (WIN32)
- /* hv: I'd bet WIN32 has the same effect here */
- setmode(fd,O_BINARY);
-#endif
- return BufFileCreate ((char *)(long) fd, BufFileRawFill, 0, BufFileRawSkip, BufFileRawClose);
-}
-
-static int
-BufFileRawFlush (int c, BufFilePtr f)
-{
- int cnt;
-
- if (c != BUFFILEEOF)
- *f->bufp++ = c;
- cnt = f->bufp - f->buffer;
- f->bufp = f->buffer;
- f->left = BUFFILESIZE;
- if (write (FileDes(f), (char *)f->buffer, cnt) != cnt)
- return BUFFILEEOF;
- return c;
-}
-
-static int
-BufFileFlush (BufFilePtr f, int doClose)
-{
- if (f->bufp != f->buffer)
- return (*f->output) (BUFFILEEOF, f);
- return 0;
-}
-
-BufFilePtr
-BufFileOpenWrite (int fd)
-{
- BufFilePtr f;
-
-#if defined(WIN32)
- /* hv: I'd bet WIN32 has the same effect here */
- setmode(fd,O_BINARY);
-#endif
- f = BufFileCreate ((char *)(long) fd, 0, BufFileRawFlush, 0, BufFileFlush);
- f->bufp = f->buffer;
- f->left = BUFFILESIZE;
- return f;
-}
-
-int
-BufFileRead (BufFilePtr f, char *b, int n)
-{
- int c, cnt;
- cnt = n;
- while (cnt--) {
- c = BufFileGet (f);
- if (c == BUFFILEEOF)
- break;
- *b++ = c;
- }
- return n - cnt - 1;
-}
-
-int
-BufFileWrite (BufFilePtr f, char *b, int n)
-{
- int cnt;
- cnt = n;
- while (cnt--) {
- if (BufFilePut (*b++, f) == BUFFILEEOF)
- return BUFFILEEOF;
- }
- return n;
-}
-
-int
-BufFileClose (BufFilePtr f, int doClose)
-{
- int ret;
- ret = (*f->close) (f, doClose);
- free (f);
- return ret;
-}
+/* + +Copyright 1991, 1998 The Open Group + +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. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ + +/* + * Author: Keith Packard, MIT X Consortium + */ + + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/Xos.h> +#include <X11/fonts/fontmisc.h> +#include <X11/fonts/bufio.h> +#include <errno.h> + +BufFilePtr +BufFileCreate (char *private, + int (*input)(BufFilePtr), + int (*output)(int, BufFilePtr), + int (*skip)(BufFilePtr, int), + int (*close)(BufFilePtr, int)) +{ + BufFilePtr f; + + f = malloc (sizeof *f); + if (!f) + return 0; + f->private = private; + f->bufp = f->buffer; + f->left = 0; + f->input = input; + f->output = output; + f->skip = skip; + f->eof = 0; + f->close = close; + return f; +} + +#define FileDes(f) ((int)(long) (f)->private) + +static int +BufFileRawFill (BufFilePtr f) +{ + int left; + + left = read (FileDes(f), (char *)f->buffer, BUFFILESIZE); + if (left <= 0) { + f->left = 0; + return BUFFILEEOF; + } + f->left = left - 1; + f->bufp = f->buffer + 1; + return f->buffer[0]; +} + +static int +BufFileRawSkip (BufFilePtr f, int count) +{ + int curoff; + int fileoff; + int todo; + + curoff = f->bufp - f->buffer; + fileoff = curoff + f->left; + if (curoff + count <= fileoff) { + f->bufp += count; + f->left -= count; + } else { + todo = count - (fileoff - curoff); + if (lseek (FileDes(f), todo, 1) == -1) { + if (errno != ESPIPE) + return BUFFILEEOF; + while (todo) { + curoff = BUFFILESIZE; + if (curoff > todo) + curoff = todo; + fileoff = read (FileDes(f), (char *)f->buffer, curoff); + if (fileoff <= 0) + return BUFFILEEOF; + todo -= fileoff; + } + } + f->left = 0; + } + return count; +} + +static int +BufFileRawClose (BufFilePtr f, int doClose) +{ + if (doClose) + close (FileDes (f)); + return 1; +} + +BufFilePtr +BufFileOpenRead (int fd) +{ +#if defined (WIN32) + /* hv: I'd bet WIN32 has the same effect here */ + setmode(fd,O_BINARY); +#endif + return BufFileCreate ((char *)(long) fd, BufFileRawFill, 0, BufFileRawSkip, BufFileRawClose); +} + +static int +BufFileRawFlush (int c, BufFilePtr f) +{ + int cnt; + + if (c != BUFFILEEOF) + *f->bufp++ = c; + cnt = f->bufp - f->buffer; + f->bufp = f->buffer; + f->left = BUFFILESIZE; + if (write (FileDes(f), (char *)f->buffer, cnt) != cnt) + return BUFFILEEOF; + return c; +} + +static int +BufFileFlush (BufFilePtr f, int doClose) +{ + if (f->bufp != f->buffer) + return (*f->output) (BUFFILEEOF, f); + return 0; +} + +BufFilePtr +BufFileOpenWrite (int fd) +{ + BufFilePtr f; + +#if defined(WIN32) + /* hv: I'd bet WIN32 has the same effect here */ + setmode(fd,O_BINARY); +#endif + f = BufFileCreate ((char *)(long) fd, 0, BufFileRawFlush, 0, BufFileFlush); + f->bufp = f->buffer; + f->left = BUFFILESIZE; + return f; +} + +int +BufFileRead (BufFilePtr f, char *b, int n) +{ + int c, cnt; + cnt = n; + while (cnt--) { + c = BufFileGet (f); + if (c == BUFFILEEOF) + break; + *b++ = c; + } + return n - cnt - 1; +} + +int +BufFileWrite (BufFilePtr f, char *b, int n) +{ + int cnt; + cnt = n; + while (cnt--) { + if (BufFilePut (*b++, f) == BUFFILEEOF) + return BUFFILEEOF; + } + return n; +} + +int +BufFileClose (BufFilePtr f, int doClose) +{ + int ret; + ret = (*f->close) (f, doClose); + free (f); + return ret; +} diff --git a/libXfont/src/fontfile/decompress.c b/libXfont/src/fontfile/decompress.c index 1d8fdc50e..c8171dd4a 100644 --- a/libXfont/src/fontfile/decompress.c +++ b/libXfont/src/fontfile/decompress.c @@ -1,410 +1,410 @@ -/*
- * Copyright 1985, 1986 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * James A. Woods, derived from original work by Spencer Thomas
- * and Joseph Orost.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley. The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-/*
-
-Copyright 1993, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-/*
- * decompress - cat a compressed file
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/fonts/fontmisc.h>
-#include <X11/fonts/bufio.h>
-
-#define BITS 16
-
-/*
- * a code_int must be able to hold 2**BITS values of type int, and also -1
- */
-#if BITS > 15
-typedef long int code_int;
-#else
-typedef int code_int;
-#endif
-
-typedef long int count_int;
-
-#ifdef NO_UCHAR
- typedef char char_type;
-#else
- typedef unsigned char char_type;
-#endif /* UCHAR */
-
-static char_type magic_header[] = { "\037\235" }; /* 1F 9D */
-
-/* Defines for third byte of header */
-#define BIT_MASK 0x1f
-#define BLOCK_MASK 0x80
-/* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is
- a fourth header byte (for expansion).
-*/
-
-#define INIT_BITS 9 /* initial number of bits/code */
-
-#ifdef COMPATIBLE /* But wrong! */
-# define MAXCODE(n_bits) (1 << (n_bits) - 1)
-#else
-# define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
-#endif /* COMPATIBLE */
-
-/*
- * the next two codes should not be changed lightly, as they must not
- * lie within the contiguous general code space.
- */
-#define FIRST 257 /* first free entry */
-#define CLEAR 256 /* table clear output code */
-
-#define STACK_SIZE 8192
-
-typedef struct _compressedFILE {
- BufFilePtr file;
-
- char_type *stackp;
- code_int oldcode;
- char_type finchar;
-
- int block_compress;
- int maxbits;
- code_int maxcode, maxmaxcode;
-
- code_int free_ent;
- int clear_flg;
- int n_bits;
-
- /* bit buffer */
- int offset, size;
- char_type buf[BITS];
-
- char_type de_stack[STACK_SIZE];
- char_type *tab_suffix;
- unsigned short *tab_prefix;
-} CompressedFile;
-
-
-static int hsize_table[] = {
- 5003, /* 12 bits - 80% occupancy */
- 9001, /* 13 bits - 91% occupancy */
- 18013, /* 14 bits - 91% occupancy */
- 35023, /* 15 bits - 94% occupancy */
- 69001 /* 16 bits - 95% occupancy */
-};
-
-static int BufCompressedClose ( BufFilePtr f, int doClose );
-static int BufCompressedFill ( BufFilePtr f );
-static code_int getcode ( CompressedFile *file );
-static int BufCompressedSkip ( BufFilePtr f, int bytes );
-
-BufFilePtr
-BufFilePushCompressed (BufFilePtr f)
-{
- int code;
- int maxbits;
- int hsize;
- CompressedFile *file;
- int extra;
-
- if ((BufFileGet(f) != (magic_header[0] & 0xFF)) ||
- (BufFileGet(f) != (magic_header[1] & 0xFF)))
- {
- return 0;
- }
- code = BufFileGet (f);
- if (code == BUFFILEEOF) return 0;
-
- maxbits = code & BIT_MASK;
- if (maxbits > BITS || maxbits < 12)
- return 0;
- hsize = hsize_table[maxbits - 12];
- extra = (1 << maxbits) * sizeof (char_type) +
- hsize * sizeof (unsigned short);
- file = malloc (sizeof (CompressedFile) + extra);
- if (!file)
- return 0;
- file->file = f;
- file->maxbits = maxbits;
- file->block_compress = code & BLOCK_MASK;
- file->maxmaxcode = 1 << file->maxbits;
- file->tab_suffix = (char_type *) &file[1];
- file->tab_prefix = (unsigned short *) (file->tab_suffix + file->maxmaxcode);
- /*
- * As above, initialize the first 256 entries in the table.
- */
- file->maxcode = MAXCODE(file->n_bits = INIT_BITS);
- for ( code = 255; code >= 0; code-- ) {
- file->tab_prefix[code] = 0;
- file->tab_suffix[code] = (char_type) code;
- }
- file->free_ent = ((file->block_compress) ? FIRST : 256 );
- file->clear_flg = 0;
- file->offset = 0;
- file->size = 0;
- file->stackp = file->de_stack;
- bzero(file->buf, BITS);
- file->finchar = file->oldcode = getcode (file);
- if (file->oldcode != -1)
- *file->stackp++ = file->finchar;
- return BufFileCreate ((char *) file,
- BufCompressedFill,
- 0,
- BufCompressedSkip,
- BufCompressedClose);
-}
-
-static int
-BufCompressedClose (BufFilePtr f, int doClose)
-{
- CompressedFile *file;
- BufFilePtr raw;
-
- file = (CompressedFile *) f->private;
- raw = file->file;
- free (file);
- BufFileClose (raw, doClose);
- return 1;
-}
-
-static int
-BufCompressedFill (BufFilePtr f)
-{
- CompressedFile *file;
- register char_type *stackp, *de_stack;
- register char_type finchar;
- register code_int code, oldcode, incode;
- BufChar *buf, *bufend;
-
- file = (CompressedFile *) f->private;
-
- buf = f->buffer;
- bufend = buf + BUFFILESIZE;
- stackp = file->stackp;
- de_stack = file->de_stack;
- finchar = file->finchar;
- oldcode = file->oldcode;
- while (buf < bufend) {
- while (stackp > de_stack && buf < bufend)
- *buf++ = *--stackp;
-
- if (buf == bufend)
- break;
-
- if (oldcode == -1)
- break;
-
- code = getcode (file);
- if (code == -1)
- break;
-
- if ( (code == CLEAR) && file->block_compress ) {
- for ( code = 255; code >= 0; code-- )
- file->tab_prefix[code] = 0;
- file->clear_flg = 1;
- file->free_ent = FIRST - 1;
- if ( (code = getcode (file)) == -1 ) /* O, untimely death! */
- break;
- }
- incode = code;
- /*
- * Special case for KwKwK string.
- */
- if ( code >= file->free_ent ) {
- *stackp++ = finchar;
- code = oldcode;
- }
-
- /*
- * Generate output characters in reverse order
- */
- while ( code >= 256 )
- {
- if (stackp - de_stack >= STACK_SIZE - 1)
- return BUFFILEEOF;
- *stackp++ = file->tab_suffix[code];
- code = file->tab_prefix[code];
- }
- finchar = file->tab_suffix[code];
- *stackp++ = finchar;
-
- /*
- * Generate the new entry.
- */
- if ( (code=file->free_ent) < file->maxmaxcode ) {
- file->tab_prefix[code] = (unsigned short)oldcode;
- file->tab_suffix[code] = finchar;
- file->free_ent = code+1;
- }
- /*
- * Remember previous code.
- */
- oldcode = incode;
- }
- file->oldcode = oldcode;
- file->stackp = stackp;
- file->finchar = finchar;
- if (buf == f->buffer) {
- f->left = 0;
- return BUFFILEEOF;
- }
- f->bufp = f->buffer + 1;
- f->left = (buf - f->buffer) - 1;
- return f->buffer[0];
-}
-
-/*****************************************************************
- * TAG( getcode )
- *
- * Read one code from the standard input. If BUFFILEEOF, return -1.
- * Inputs:
- * stdin
- * Outputs:
- * code or -1 is returned.
- */
-
-static char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
-
-static code_int
-getcode(CompressedFile *file)
-{
- register code_int code;
- register int r_off, bits;
- register char_type *bp = file->buf;
- register BufFilePtr raw;
-
- if ( file->clear_flg > 0 || file->offset >= file->size ||
- file->free_ent > file->maxcode )
- {
- /*
- * If the next entry will be too big for the current code
- * size, then we must increase the size. This implies reading
- * a new buffer full, too.
- */
- if ( file->free_ent > file->maxcode ) {
- file->n_bits++;
- if ( file->n_bits == file->maxbits )
- file->maxcode = file->maxmaxcode; /* won't get any bigger now */
- else
- file->maxcode = MAXCODE(file->n_bits);
- }
- if ( file->clear_flg > 0) {
- file->maxcode = MAXCODE (file->n_bits = INIT_BITS);
- file->clear_flg = 0;
- }
- bits = file->n_bits;
- raw = file->file;
- while (bits > 0 && (code = BufFileGet (raw)) != BUFFILEEOF)
- {
- *bp++ = code;
- --bits;
- }
- bp = file->buf;
- if (bits == file->n_bits)
- return -1; /* end of file */
- file->size = file->n_bits - bits;
- file->offset = 0;
- /* Round size down to integral number of codes */
- file->size = (file->size << 3) - (file->n_bits - 1);
- }
- r_off = file->offset;
- bits = file->n_bits;
- /*
- * Get to the first byte.
- */
- bp += (r_off >> 3);
- r_off &= 7;
- /* Get first part (low order bits) */
-#ifdef NO_UCHAR
- code = ((*bp++ >> r_off) & rmask[8 - r_off]) & 0xff;
-#else
- code = (*bp++ >> r_off);
-#endif /* NO_UCHAR */
- bits -= (8 - r_off);
- r_off = 8 - r_off; /* now, offset into code word */
- /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
- if ( bits >= 8 ) {
-#ifdef NO_UCHAR
- code |= (*bp++ & 0xff) << r_off;
-#else
- code |= *bp++ << r_off;
-#endif /* NO_UCHAR */
- r_off += 8;
- bits -= 8;
- }
- /* high order bits. */
- code |= (*bp & rmask[bits]) << r_off;
- file->offset += file->n_bits;
-
- return code;
-}
-
-static int
-BufCompressedSkip (BufFilePtr f, int bytes)
-{
- int c;
- while (bytes--)
- {
- c = BufFileGet(f);
- if (c == BUFFILEEOF)
- return BUFFILEEOF;
- }
- return 0;
-}
-
-#ifdef TEST
-int
-main (int argc, char *argv[])
-{
- BufFilePtr inputraw, input, output;
- int c;
-
- inputraw = BufFileOpenRead (0);
- input = BufFilePushCompressed (inputraw);
- output = BufFileOpenWrite (1);
- while ((c = BufFileGet (input)) != BUFFILEEOF)
- BufFilePut (c, output);
- BufFileClose (input, FALSE);
- BufFileClose (output, FALSE);
- return 0;
-}
-#endif
+/* + * Copyright 1985, 1986 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * James A. Woods, derived from original work by Spencer Thomas + * and Joseph Orost. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +/* + +Copyright 1993, 1998 The Open Group + +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. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ +/* + * decompress - cat a compressed file + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/fonts/fontmisc.h> +#include <X11/fonts/bufio.h> + +#define BITS 16 + +/* + * a code_int must be able to hold 2**BITS values of type int, and also -1 + */ +#if BITS > 15 +typedef long int code_int; +#else +typedef int code_int; +#endif + +typedef long int count_int; + +#ifdef NO_UCHAR + typedef char char_type; +#else + typedef unsigned char char_type; +#endif /* UCHAR */ + +static char_type magic_header[] = { "\037\235" }; /* 1F 9D */ + +/* Defines for third byte of header */ +#define BIT_MASK 0x1f +#define BLOCK_MASK 0x80 +/* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is + a fourth header byte (for expansion). +*/ + +#define INIT_BITS 9 /* initial number of bits/code */ + +#ifdef COMPATIBLE /* But wrong! */ +# define MAXCODE(n_bits) (1 << (n_bits) - 1) +#else +# define MAXCODE(n_bits) ((1 << (n_bits)) - 1) +#endif /* COMPATIBLE */ + +/* + * the next two codes should not be changed lightly, as they must not + * lie within the contiguous general code space. + */ +#define FIRST 257 /* first free entry */ +#define CLEAR 256 /* table clear output code */ + +#define STACK_SIZE 8192 + +typedef struct _compressedFILE { + BufFilePtr file; + + char_type *stackp; + code_int oldcode; + char_type finchar; + + int block_compress; + int maxbits; + code_int maxcode, maxmaxcode; + + code_int free_ent; + int clear_flg; + int n_bits; + + /* bit buffer */ + int offset, size; + char_type buf[BITS]; + + char_type de_stack[STACK_SIZE]; + char_type *tab_suffix; + unsigned short *tab_prefix; +} CompressedFile; + + +static int hsize_table[] = { + 5003, /* 12 bits - 80% occupancy */ + 9001, /* 13 bits - 91% occupancy */ + 18013, /* 14 bits - 91% occupancy */ + 35023, /* 15 bits - 94% occupancy */ + 69001 /* 16 bits - 95% occupancy */ +}; + +static int BufCompressedClose ( BufFilePtr f, int doClose ); +static int BufCompressedFill ( BufFilePtr f ); +static code_int getcode ( CompressedFile *file ); +static int BufCompressedSkip ( BufFilePtr f, int bytes ); + +BufFilePtr +BufFilePushCompressed (BufFilePtr f) +{ + int code; + int maxbits; + int hsize; + CompressedFile *file; + int extra; + + if ((BufFileGet(f) != (magic_header[0] & 0xFF)) || + (BufFileGet(f) != (magic_header[1] & 0xFF))) + { + return 0; + } + code = BufFileGet (f); + if (code == BUFFILEEOF) return 0; + + maxbits = code & BIT_MASK; + if (maxbits > BITS || maxbits < 12) + return 0; + hsize = hsize_table[maxbits - 12]; + extra = (1 << maxbits) * sizeof (char_type) + + hsize * sizeof (unsigned short); + file = malloc (sizeof (CompressedFile) + extra); + if (!file) + return 0; + file->file = f; + file->maxbits = maxbits; + file->block_compress = code & BLOCK_MASK; + file->maxmaxcode = 1 << file->maxbits; + file->tab_suffix = (char_type *) &file[1]; + file->tab_prefix = (unsigned short *) (file->tab_suffix + file->maxmaxcode); + /* + * As above, initialize the first 256 entries in the table. + */ + file->maxcode = MAXCODE(file->n_bits = INIT_BITS); + for ( code = 255; code >= 0; code-- ) { + file->tab_prefix[code] = 0; + file->tab_suffix[code] = (char_type) code; + } + file->free_ent = ((file->block_compress) ? FIRST : 256 ); + file->clear_flg = 0; + file->offset = 0; + file->size = 0; + file->stackp = file->de_stack; + bzero(file->buf, BITS); + file->finchar = file->oldcode = getcode (file); + if (file->oldcode != -1) + *file->stackp++ = file->finchar; + return BufFileCreate ((char *) file, + BufCompressedFill, + 0, + BufCompressedSkip, + BufCompressedClose); +} + +static int +BufCompressedClose (BufFilePtr f, int doClose) +{ + CompressedFile *file; + BufFilePtr raw; + + file = (CompressedFile *) f->private; + raw = file->file; + free (file); + BufFileClose (raw, doClose); + return 1; +} + +static int +BufCompressedFill (BufFilePtr f) +{ + CompressedFile *file; + register char_type *stackp, *de_stack; + register char_type finchar; + register code_int code, oldcode, incode; + BufChar *buf, *bufend; + + file = (CompressedFile *) f->private; + + buf = f->buffer; + bufend = buf + BUFFILESIZE; + stackp = file->stackp; + de_stack = file->de_stack; + finchar = file->finchar; + oldcode = file->oldcode; + while (buf < bufend) { + while (stackp > de_stack && buf < bufend) + *buf++ = *--stackp; + + if (buf == bufend) + break; + + if (oldcode == -1) + break; + + code = getcode (file); + if (code == -1) + break; + + if ( (code == CLEAR) && file->block_compress ) { + for ( code = 255; code >= 0; code-- ) + file->tab_prefix[code] = 0; + file->clear_flg = 1; + file->free_ent = FIRST - 1; + if ( (code = getcode (file)) == -1 ) /* O, untimely death! */ + break; + } + incode = code; + /* + * Special case for KwKwK string. + */ + if ( code >= file->free_ent ) { + *stackp++ = finchar; + code = oldcode; + } + + /* + * Generate output characters in reverse order + */ + while ( code >= 256 ) + { + if (stackp - de_stack >= STACK_SIZE - 1) + return BUFFILEEOF; + *stackp++ = file->tab_suffix[code]; + code = file->tab_prefix[code]; + } + finchar = file->tab_suffix[code]; + *stackp++ = finchar; + + /* + * Generate the new entry. + */ + if ( (code=file->free_ent) < file->maxmaxcode ) { + file->tab_prefix[code] = (unsigned short)oldcode; + file->tab_suffix[code] = finchar; + file->free_ent = code+1; + } + /* + * Remember previous code. + */ + oldcode = incode; + } + file->oldcode = oldcode; + file->stackp = stackp; + file->finchar = finchar; + if (buf == f->buffer) { + f->left = 0; + return BUFFILEEOF; + } + f->bufp = f->buffer + 1; + f->left = (buf - f->buffer) - 1; + return f->buffer[0]; +} + +/***************************************************************** + * TAG( getcode ) + * + * Read one code from the standard input. If BUFFILEEOF, return -1. + * Inputs: + * stdin + * Outputs: + * code or -1 is returned. + */ + +static char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; + +static code_int +getcode(CompressedFile *file) +{ + register code_int code; + register int r_off, bits; + register char_type *bp = file->buf; + register BufFilePtr raw; + + if ( file->clear_flg > 0 || file->offset >= file->size || + file->free_ent > file->maxcode ) + { + /* + * If the next entry will be too big for the current code + * size, then we must increase the size. This implies reading + * a new buffer full, too. + */ + if ( file->free_ent > file->maxcode ) { + file->n_bits++; + if ( file->n_bits == file->maxbits ) + file->maxcode = file->maxmaxcode; /* won't get any bigger now */ + else + file->maxcode = MAXCODE(file->n_bits); + } + if ( file->clear_flg > 0) { + file->maxcode = MAXCODE (file->n_bits = INIT_BITS); + file->clear_flg = 0; + } + bits = file->n_bits; + raw = file->file; + while (bits > 0 && (code = BufFileGet (raw)) != BUFFILEEOF) + { + *bp++ = code; + --bits; + } + bp = file->buf; + if (bits == file->n_bits) + return -1; /* end of file */ + file->size = file->n_bits - bits; + file->offset = 0; + /* Round size down to integral number of codes */ + file->size = (file->size << 3) - (file->n_bits - 1); + } + r_off = file->offset; + bits = file->n_bits; + /* + * Get to the first byte. + */ + bp += (r_off >> 3); + r_off &= 7; + /* Get first part (low order bits) */ +#ifdef NO_UCHAR + code = ((*bp++ >> r_off) & rmask[8 - r_off]) & 0xff; +#else + code = (*bp++ >> r_off); +#endif /* NO_UCHAR */ + bits -= (8 - r_off); + r_off = 8 - r_off; /* now, offset into code word */ + /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */ + if ( bits >= 8 ) { +#ifdef NO_UCHAR + code |= (*bp++ & 0xff) << r_off; +#else + code |= *bp++ << r_off; +#endif /* NO_UCHAR */ + r_off += 8; + bits -= 8; + } + /* high order bits. */ + code |= (*bp & rmask[bits]) << r_off; + file->offset += file->n_bits; + + return code; +} + +static int +BufCompressedSkip (BufFilePtr f, int bytes) +{ + int c; + while (bytes--) + { + c = BufFileGet(f); + if (c == BUFFILEEOF) + return BUFFILEEOF; + } + return 0; +} + +#ifdef TEST +int +main (int argc, char *argv[]) +{ + BufFilePtr inputraw, input, output; + int c; + + inputraw = BufFileOpenRead (0); + input = BufFilePushCompressed (inputraw); + output = BufFileOpenWrite (1); + while ((c = BufFileGet (input)) != BUFFILEEOF) + BufFilePut (c, output); + BufFileClose (input, FALSE); + BufFileClose (output, FALSE); + return 0; +} +#endif diff --git a/libXfont/src/fontfile/defaults.c b/libXfont/src/fontfile/defaults.c index b42024df3..1ad7d7ce5 100644 --- a/libXfont/src/fontfile/defaults.c +++ b/libXfont/src/fontfile/defaults.c @@ -1,74 +1,74 @@ -/*
-
-Copyright 1990, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-/*
- * Author: Keith Packard, MIT X Consortium
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/X.h>
-#include <X11/Xproto.h>
-
-#ifndef DEFAULT_BIT_ORDER
-#ifdef BITMAP_BIT_ORDER
-#define DEFAULT_BIT_ORDER BITMAP_BIT_ORDER
-#else
-#define DEFAULT_BIT_ORDER MSBFirst
-#endif
-#endif
-
-#ifndef DEFAULT_BYTE_ORDER
-#ifdef IMAGE_BYTE_ORDER
-#define DEFAULT_BYTE_ORDER IMAGE_BYTE_ORDER
-#else
-#define DEFAULT_BYTE_ORDER MSBFirst
-#endif
-#endif
-
-#ifndef DEFAULT_GLYPH_PAD
-#ifdef GLYPHPADBYTES
-#define DEFAULT_GLYPH_PAD GLYPHPADBYTES
-#else
-#define DEFAULT_GLYPH_PAD 4
-#endif
-#endif
-
-#ifndef DEFAULT_SCAN_UNIT
-#define DEFAULT_SCAN_UNIT 1
-#endif
-
-#include <X11/fonts/fntfilst.h>
-
-void
-FontDefaultFormat (int *bit, int *byte, int *glyph, int *scan)
-{
- *bit = DEFAULT_BIT_ORDER;
- *byte = DEFAULT_BYTE_ORDER;
- *glyph = DEFAULT_GLYPH_PAD;
- *scan = DEFAULT_SCAN_UNIT;
-}
+/* + +Copyright 1990, 1998 The Open Group + +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. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ + +/* + * Author: Keith Packard, MIT X Consortium + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/X.h> +#include <X11/Xproto.h> + +#ifndef DEFAULT_BIT_ORDER +#ifdef BITMAP_BIT_ORDER +#define DEFAULT_BIT_ORDER BITMAP_BIT_ORDER +#else +#define DEFAULT_BIT_ORDER MSBFirst +#endif +#endif + +#ifndef DEFAULT_BYTE_ORDER +#ifdef IMAGE_BYTE_ORDER +#define DEFAULT_BYTE_ORDER IMAGE_BYTE_ORDER +#else +#define DEFAULT_BYTE_ORDER MSBFirst +#endif +#endif + +#ifndef DEFAULT_GLYPH_PAD +#ifdef GLYPHPADBYTES +#define DEFAULT_GLYPH_PAD GLYPHPADBYTES +#else +#define DEFAULT_GLYPH_PAD 4 +#endif +#endif + +#ifndef DEFAULT_SCAN_UNIT +#define DEFAULT_SCAN_UNIT 1 +#endif + +#include <X11/fonts/fntfilst.h> + +void +FontDefaultFormat (int *bit, int *byte, int *glyph, int *scan) +{ + *bit = DEFAULT_BIT_ORDER; + *byte = DEFAULT_BYTE_ORDER; + *glyph = DEFAULT_GLYPH_PAD; + *scan = DEFAULT_SCAN_UNIT; +} diff --git a/libXfont/src/fontfile/dirfile.c b/libXfont/src/fontfile/dirfile.c index 50eb2faf5..c8aff6f4f 100644 --- a/libXfont/src/fontfile/dirfile.c +++ b/libXfont/src/fontfile/dirfile.c @@ -1,492 +1,492 @@ -/*
-
-Copyright 1991, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-/*
- * Author: Keith Packard, MIT X Consortium
- */
-
-/*
- * dirfile.c
- *
- * Read fonts.dir and fonts.alias files
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/fonts/fntfilst.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-
-static Bool AddFileNameAliases ( FontDirectoryPtr dir );
-static int ReadFontAlias ( char *directory, Bool isFile,
- FontDirectoryPtr *pdir );
-static int lexAlias ( FILE *file, char **lexToken );
-static int lexc ( FILE *file );
-
-int
-FontFileReadDirectory (char *directory, FontDirectoryPtr *pdir)
-{
- char file_name[MAXFONTFILENAMELEN];
- char font_name[MAXFONTNAMELEN];
- char dir_file[MAXFONTFILENAMELEN];
- char dir_path[MAXFONTFILENAMELEN];
- char *ptr;
- FILE *file;
- int count,
- num_fonts,
- status;
- struct stat statb;
- static char format[24] = "";
-#if defined(WIN32)
- int i;
-#endif
-
- FontDirectoryPtr dir = NullFontDirectory;
-
- if (strlen(directory) + 1 + sizeof(FontDirFile) > sizeof(dir_file))
- return BadFontPath;
-
- /* Check for font directory attributes */
-#if !defined(WIN32)
- if ((ptr = strchr(directory, ':'))) {
-#else
- /* OS/2 and WIN32 path might start with a drive letter, don't clip this */
- if ((ptr = strchr(directory+2, ':'))) {
-#endif
- strncpy(dir_path, directory, ptr - directory);
- dir_path[ptr - directory] = '\0';
- } else {
- strcpy(dir_path, directory);
- }
- strcpy(dir_file, dir_path);
- if (dir_file[strlen(dir_file) - 1] != '/')
- strcat(dir_file, "/");
- strcat(dir_file, FontDirFile);
- file = fopen(dir_file, "rt");
- if (file) {
-#ifndef WIN32
- if (fstat (fileno(file), &statb) == -1)
-#else
- if (stat (dir_file, &statb) == -1)
-#endif
- {
- fclose(file);
- return BadFontPath;
- }
- count = fscanf(file, "%d\n", &num_fonts);
- if ((count == EOF) || (count != 1)) {
- fclose(file);
- return BadFontPath;
- }
- dir = FontFileMakeDir(directory, num_fonts);
- if (dir == NULL) {
- fclose(file);
- return BadFontPath;
- }
- dir->dir_mtime = statb.st_mtime;
- if (format[0] == '\0')
- sprintf(format, "%%%ds %%%d[^\n]\n",
- MAXFONTFILENAMELEN-1, MAXFONTNAMELEN-1);
-
- while ((count = fscanf(file, format, file_name, font_name)) != EOF) {
-#if defined(WIN32)
- /* strip any existing trailing CR */
- for (i=0; i<strlen(font_name); i++) {
- if (font_name[i]=='\r') font_name[i] = '\0';
- }
-#endif
- if (count != 2) {
- FontFileFreeDir (dir);
- fclose(file);
- return BadFontPath;
- }
-
- /*
- * We blindly try to load all the font files specified.
- * In theory, we might want to warn that some of the fonts
- * couldn't be loaded.
- */
- FontFileAddFontFile (dir, font_name, file_name);
- }
- fclose(file);
-
- } else if (errno != ENOENT) {
- return BadFontPath;
- }
- status = ReadFontAlias(dir_path, FALSE, &dir);
- if (status != Successful) {
- if (dir)
- FontFileFreeDir (dir);
- return status;
- }
- if (!dir)
- return BadFontPath;
-
- FontFileSortDir(dir);
-
- *pdir = dir;
- return Successful;
-}
-
-Bool
-FontFileDirectoryChanged(FontDirectoryPtr dir)
-{
- char dir_file[MAXFONTFILENAMELEN];
- struct stat statb;
-
- if (strlen(dir->directory) + sizeof(FontDirFile) > sizeof(dir_file))
- return FALSE;
-
- strcpy (dir_file, dir->directory);
- strcat (dir_file, FontDirFile);
- if (stat (dir_file, &statb) == -1)
- {
- if (errno != ENOENT || dir->dir_mtime != 0)
- return TRUE;
- return FALSE; /* doesn't exist and never did: no change */
- }
- if (dir->dir_mtime != statb.st_mtime)
- return TRUE;
-
- if ((strlen(dir->directory) + sizeof(FontAliasFile)) > sizeof(dir_file))
- return FALSE;
- strcpy (dir_file, dir->directory);
- strcat (dir_file, FontAliasFile);
- if (stat (dir_file, &statb) == -1)
- {
- if (errno != ENOENT || dir->alias_mtime != 0)
- return TRUE;
- return FALSE; /* doesn't exist and never did: no change */
- }
- if (dir->alias_mtime != statb.st_mtime)
- return TRUE;
- return FALSE;
-}
-
-/*
- * Make each of the file names an automatic alias for each of the files.
- */
-
-static Bool
-AddFileNameAliases(FontDirectoryPtr dir)
-{
- int i;
- char copy[MAXFONTFILENAMELEN];
- char *fileName;
- FontTablePtr table;
- FontRendererPtr renderer;
- int len;
- FontNameRec name;
-
- table = &dir->nonScalable;
- for (i = 0; i < table->used; i++) {
- if (table->entries[i].type != FONT_ENTRY_BITMAP)
- continue;
- fileName = table->entries[i].u.bitmap.fileName;
- renderer = FontFileMatchRenderer (fileName);
- if (!renderer)
- continue;
-
- len = strlen (fileName) - renderer->fileSuffixLen;
- if (len >= sizeof(copy))
- continue;
- CopyISOLatin1Lowered (copy, fileName, len);
- copy[len] = '\0';
- name.name = copy;
- name.length = len;
- name.ndashes = FontFileCountDashes (copy, len);
-
- if (!FontFileFindNameInDir(table, &name)) {
- if (!FontFileAddFontAlias (dir, copy, table->entries[i].name.name))
- return FALSE;
- }
- }
- return TRUE;
-}
-
-/*
- * parse the font.alias file. Format is:
- *
- * alias font-name
- *
- * To imbed white-space in an alias name, enclose it like "font name"
- * in double quotes. \ escapes and character, so
- * "font name \"With Double Quotes\" \\ and \\ back-slashes"
- * works just fine.
- *
- * A line beginning with a ! denotes a newline-terminated comment.
- */
-
-/*
- * token types
- */
-
-#define NAME 0
-#define NEWLINE 1
-#define DONE 2
-#define EALLOC 3
-
-static int
-ReadFontAlias(char *directory, Bool isFile, FontDirectoryPtr *pdir)
-{
- char alias[MAXFONTNAMELEN];
- char font_name[MAXFONTNAMELEN];
- char alias_file[MAXFONTFILENAMELEN];
- FILE *file;
- FontDirectoryPtr dir;
- int token;
- char *lexToken;
- int status = Successful;
- struct stat statb;
-
- if (strlen(directory) >= sizeof(alias_file))
- return BadFontPath;
- dir = *pdir;
- strcpy(alias_file, directory);
- if (!isFile) {
- if (strlen(directory) + 1 + sizeof(FontAliasFile) > sizeof(alias_file))
- return BadFontPath;
- if (directory[strlen(directory) - 1] != '/')
- strcat(alias_file, "/");
- strcat(alias_file, FontAliasFile);
- }
- file = fopen(alias_file, "rt");
- if (!file)
- return ((errno == ENOENT) ? Successful : BadFontPath);
- if (!dir)
- *pdir = dir = FontFileMakeDir(directory, 10);
- if (!dir)
- {
- fclose (file);
- return AllocError;
- }
-#ifndef WIN32
- if (fstat (fileno (file), &statb) == -1)
-#else
- if (stat (alias_file, &statb) == -1)
-#endif
- {
- fclose (file);
- return BadFontPath;
- }
- dir->alias_mtime = statb.st_mtime;
- while (status == Successful) {
- token = lexAlias(file, &lexToken);
- switch (token) {
- case NEWLINE:
- break;
- case DONE:
- fclose(file);
- return Successful;
- case EALLOC:
- status = AllocError;
- break;
- case NAME:
- if (strlen(lexToken) >= sizeof(alias)) {
- status = BadFontPath;
- break;
- }
- strcpy(alias, lexToken);
- token = lexAlias(file, &lexToken);
- switch (token) {
- case NEWLINE:
- if (strcmp(alias, "FILE_NAMES_ALIASES"))
- status = BadFontPath;
- else if (!AddFileNameAliases(dir))
- status = AllocError;
- break;
- case DONE:
- status = BadFontPath;
- break;
- case EALLOC:
- status = AllocError;
- break;
- case NAME:
- if (strlen(lexToken) >= sizeof(font_name)) {
- status = BadFontPath;
- break;
- }
- CopyISOLatin1Lowered(alias, alias, strlen(alias));
- CopyISOLatin1Lowered(font_name, lexToken, strlen(lexToken));
- if (!FontFileAddFontAlias (dir, alias, font_name))
- status = AllocError;
- break;
- }
- }
- }
- fclose(file);
- return status;
-}
-
-#define QUOTE 0
-#define WHITE 1
-#define NORMAL 2
-#define END 3
-#define NL 4
-#define BANG 5
-
-static int charClass;
-
-static int
-lexAlias(FILE *file, char **lexToken)
-{
- int c;
- char *t;
- enum state {
- Begin, Normal, Quoted, Comment
- } state;
- int count;
-
- static char *tokenBuf = (char *) NULL;
- static int tokenSize = 0;
-
- t = tokenBuf;
- count = 0;
- state = Begin;
- for (;;) {
- if (count == tokenSize) {
- int nsize;
- char *nbuf;
-
- nsize = tokenSize ? (tokenSize << 1) : 64;
- nbuf = realloc(tokenBuf, nsize);
- if (!nbuf)
- return EALLOC;
- tokenBuf = nbuf;
- tokenSize = nsize;
- t = tokenBuf + count;
- }
- c = lexc(file);
- switch (charClass) {
- case QUOTE:
- switch (state) {
- case Begin:
- case Normal:
- state = Quoted;
- break;
- case Quoted:
- state = Normal;
- break;
- case Comment:
- break;
- }
- break;
- case WHITE:
- switch (state) {
- case Begin:
- case Comment:
- continue;
- case Normal:
- *t = '\0';
- *lexToken = tokenBuf;
- return NAME;
- case Quoted:
- break;
- }
- /* fall through */
- case NORMAL:
- switch (state) {
- case Begin:
- state = Normal;
- break;
- case Comment:
- continue;
- default:
- break;
- }
- *t++ = c;
- ++count;
- break;
- case END:
- case NL:
- switch (state) {
- case Begin:
- case Comment:
- *lexToken = (char *) NULL;
- return charClass == END ? DONE : NEWLINE;
- default:
- *t = '\0';
- *lexToken = tokenBuf;
- ungetc(c, file);
- return NAME;
- }
- break;
- case BANG:
- switch (state) {
- case Begin:
- state = Comment;
- break;
- case Comment:
- break;
- default:
- *t++ = c;
- ++count;
- }
- break;
- }
- }
-}
-
-static int
-lexc(FILE *file)
-{
- int c;
-
- c = getc(file);
- switch (c) {
- case EOF:
- charClass = END;
- break;
- case '\\':
- c = getc(file);
- if (c == EOF)
- charClass = END;
- else
- charClass = NORMAL;
- break;
- case '"':
- charClass = QUOTE;
- break;
- case ' ':
- case '\t':
- charClass = WHITE;
- break;
- case '\r':
- case '\n':
- charClass = NL;
- break;
- case '!':
- charClass = BANG;
- break;
- default:
- charClass = NORMAL;
- break;
- }
- return c;
-}
+/* + +Copyright 1991, 1998 The Open Group + +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. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ + +/* + * Author: Keith Packard, MIT X Consortium + */ + +/* + * dirfile.c + * + * Read fonts.dir and fonts.alias files + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/fonts/fntfilst.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> + +static Bool AddFileNameAliases ( FontDirectoryPtr dir ); +static int ReadFontAlias ( char *directory, Bool isFile, + FontDirectoryPtr *pdir ); +static int lexAlias ( FILE *file, char **lexToken ); +static int lexc ( FILE *file ); + +int +FontFileReadDirectory (char *directory, FontDirectoryPtr *pdir) +{ + char file_name[MAXFONTFILENAMELEN]; + char font_name[MAXFONTNAMELEN]; + char dir_file[MAXFONTFILENAMELEN]; + char dir_path[MAXFONTFILENAMELEN]; + char *ptr; + FILE *file; + int count, + num_fonts, + status; + struct stat statb; + static char format[24] = ""; +#if defined(WIN32) + int i; +#endif + + FontDirectoryPtr dir = NullFontDirectory; + + if (strlen(directory) + 1 + sizeof(FontDirFile) > sizeof(dir_file)) + return BadFontPath; + + /* Check for font directory attributes */ +#if !defined(WIN32) + if ((ptr = strchr(directory, ':'))) { +#else + /* OS/2 and WIN32 path might start with a drive letter, don't clip this */ + if ((ptr = strchr(directory+2, ':'))) { +#endif + strncpy(dir_path, directory, ptr - directory); + dir_path[ptr - directory] = '\0'; + } else { + strcpy(dir_path, directory); + } + strcpy(dir_file, dir_path); + if (dir_file[strlen(dir_file) - 1] != '/') + strcat(dir_file, "/"); + strcat(dir_file, FontDirFile); + file = fopen(dir_file, "rt"); + if (file) { +#ifndef WIN32 + if (fstat (fileno(file), &statb) == -1) +#else + if (stat (dir_file, &statb) == -1) +#endif + { + fclose(file); + return BadFontPath; + } + count = fscanf(file, "%d\n", &num_fonts); + if ((count == EOF) || (count != 1)) { + fclose(file); + return BadFontPath; + } + dir = FontFileMakeDir(directory, num_fonts); + if (dir == NULL) { + fclose(file); + return BadFontPath; + } + dir->dir_mtime = statb.st_mtime; + if (format[0] == '\0') + sprintf(format, "%%%ds %%%d[^\n]\n", + MAXFONTFILENAMELEN-1, MAXFONTNAMELEN-1); + + while ((count = fscanf(file, format, file_name, font_name)) != EOF) { +#if defined(WIN32) + /* strip any existing trailing CR */ + for (i=0; i<strlen(font_name); i++) { + if (font_name[i]=='\r') font_name[i] = '\0'; + } +#endif + if (count != 2) { + FontFileFreeDir (dir); + fclose(file); + return BadFontPath; + } + + /* + * We blindly try to load all the font files specified. + * In theory, we might want to warn that some of the fonts + * couldn't be loaded. + */ + FontFileAddFontFile (dir, font_name, file_name); + } + fclose(file); + + } else if (errno != ENOENT) { + return BadFontPath; + } + status = ReadFontAlias(dir_path, FALSE, &dir); + if (status != Successful) { + if (dir) + FontFileFreeDir (dir); + return status; + } + if (!dir) + return BadFontPath; + + FontFileSortDir(dir); + + *pdir = dir; + return Successful; +} + +Bool +FontFileDirectoryChanged(FontDirectoryPtr dir) +{ + char dir_file[MAXFONTFILENAMELEN]; + struct stat statb; + + if (strlen(dir->directory) + sizeof(FontDirFile) > sizeof(dir_file)) + return FALSE; + + strcpy (dir_file, dir->directory); + strcat (dir_file, FontDirFile); + if (stat (dir_file, &statb) == -1) + { + if (errno != ENOENT || dir->dir_mtime != 0) + return TRUE; + return FALSE; /* doesn't exist and never did: no change */ + } + if (dir->dir_mtime != statb.st_mtime) + return TRUE; + + if ((strlen(dir->directory) + sizeof(FontAliasFile)) > sizeof(dir_file)) + return FALSE; + strcpy (dir_file, dir->directory); + strcat (dir_file, FontAliasFile); + if (stat (dir_file, &statb) == -1) + { + if (errno != ENOENT || dir->alias_mtime != 0) + return TRUE; + return FALSE; /* doesn't exist and never did: no change */ + } + if (dir->alias_mtime != statb.st_mtime) + return TRUE; + return FALSE; +} + +/* + * Make each of the file names an automatic alias for each of the files. + */ + +static Bool +AddFileNameAliases(FontDirectoryPtr dir) +{ + int i; + char copy[MAXFONTFILENAMELEN]; + char *fileName; + FontTablePtr table; + FontRendererPtr renderer; + int len; + FontNameRec name; + + table = &dir->nonScalable; + for (i = 0; i < table->used; i++) { + if (table->entries[i].type != FONT_ENTRY_BITMAP) + continue; + fileName = table->entries[i].u.bitmap.fileName; + renderer = FontFileMatchRenderer (fileName); + if (!renderer) + continue; + + len = strlen (fileName) - renderer->fileSuffixLen; + if (len >= sizeof(copy)) + continue; + CopyISOLatin1Lowered (copy, fileName, len); + copy[len] = '\0'; + name.name = copy; + name.length = len; + name.ndashes = FontFileCountDashes (copy, len); + + if (!FontFileFindNameInDir(table, &name)) { + if (!FontFileAddFontAlias (dir, copy, table->entries[i].name.name)) + return FALSE; + } + } + return TRUE; +} + +/* + * parse the font.alias file. Format is: + * + * alias font-name + * + * To imbed white-space in an alias name, enclose it like "font name" + * in double quotes. \ escapes and character, so + * "font name \"With Double Quotes\" \\ and \\ back-slashes" + * works just fine. + * + * A line beginning with a ! denotes a newline-terminated comment. + */ + +/* + * token types + */ + +#define NAME 0 +#define NEWLINE 1 +#define DONE 2 +#define EALLOC 3 + +static int +ReadFontAlias(char *directory, Bool isFile, FontDirectoryPtr *pdir) +{ + char alias[MAXFONTNAMELEN]; + char font_name[MAXFONTNAMELEN]; + char alias_file[MAXFONTFILENAMELEN]; + FILE *file; + FontDirectoryPtr dir; + int token; + char *lexToken; + int status = Successful; + struct stat statb; + + if (strlen(directory) >= sizeof(alias_file)) + return BadFontPath; + dir = *pdir; + strcpy(alias_file, directory); + if (!isFile) { + if (strlen(directory) + 1 + sizeof(FontAliasFile) > sizeof(alias_file)) + return BadFontPath; + if (directory[strlen(directory) - 1] != '/') + strcat(alias_file, "/"); + strcat(alias_file, FontAliasFile); + } + file = fopen(alias_file, "rt"); + if (!file) + return ((errno == ENOENT) ? Successful : BadFontPath); + if (!dir) + *pdir = dir = FontFileMakeDir(directory, 10); + if (!dir) + { + fclose (file); + return AllocError; + } +#ifndef WIN32 + if (fstat (fileno (file), &statb) == -1) +#else + if (stat (alias_file, &statb) == -1) +#endif + { + fclose (file); + return BadFontPath; + } + dir->alias_mtime = statb.st_mtime; + while (status == Successful) { + token = lexAlias(file, &lexToken); + switch (token) { + case NEWLINE: + break; + case DONE: + fclose(file); + return Successful; + case EALLOC: + status = AllocError; + break; + case NAME: + if (strlen(lexToken) >= sizeof(alias)) { + status = BadFontPath; + break; + } + strcpy(alias, lexToken); + token = lexAlias(file, &lexToken); + switch (token) { + case NEWLINE: + if (strcmp(alias, "FILE_NAMES_ALIASES")) + status = BadFontPath; + else if (!AddFileNameAliases(dir)) + status = AllocError; + break; + case DONE: + status = BadFontPath; + break; + case EALLOC: + status = AllocError; + break; + case NAME: + if (strlen(lexToken) >= sizeof(font_name)) { + status = BadFontPath; + break; + } + CopyISOLatin1Lowered(alias, alias, strlen(alias)); + CopyISOLatin1Lowered(font_name, lexToken, strlen(lexToken)); + if (!FontFileAddFontAlias (dir, alias, font_name)) + status = AllocError; + break; + } + } + } + fclose(file); + return status; +} + +#define QUOTE 0 +#define WHITE 1 +#define NORMAL 2 +#define END 3 +#define NL 4 +#define BANG 5 + +static int charClass; + +static int +lexAlias(FILE *file, char **lexToken) +{ + int c; + char *t; + enum state { + Begin, Normal, Quoted, Comment + } state; + int count; + + static char *tokenBuf = (char *) NULL; + static int tokenSize = 0; + + t = tokenBuf; + count = 0; + state = Begin; + for (;;) { + if (count == tokenSize) { + int nsize; + char *nbuf; + + nsize = tokenSize ? (tokenSize << 1) : 64; + nbuf = realloc(tokenBuf, nsize); + if (!nbuf) + return EALLOC; + tokenBuf = nbuf; + tokenSize = nsize; + t = tokenBuf + count; + } + c = lexc(file); + switch (charClass) { + case QUOTE: + switch (state) { + case Begin: + case Normal: + state = Quoted; + break; + case Quoted: + state = Normal; + break; + case Comment: + break; + } + break; + case WHITE: + switch (state) { + case Begin: + case Comment: + continue; + case Normal: + *t = '\0'; + *lexToken = tokenBuf; + return NAME; + case Quoted: + break; + } + /* fall through */ + case NORMAL: + switch (state) { + case Begin: + state = Normal; + break; + case Comment: + continue; + default: + break; + } + *t++ = c; + ++count; + break; + case END: + case NL: + switch (state) { + case Begin: + case Comment: + *lexToken = (char *) NULL; + return charClass == END ? DONE : NEWLINE; + default: + *t = '\0'; + *lexToken = tokenBuf; + ungetc(c, file); + return NAME; + } + break; + case BANG: + switch (state) { + case Begin: + state = Comment; + break; + case Comment: + break; + default: + *t++ = c; + ++count; + } + break; + } + } +} + +static int +lexc(FILE *file) +{ + int c; + + c = getc(file); + switch (c) { + case EOF: + charClass = END; + break; + case '\\': + c = getc(file); + if (c == EOF) + charClass = END; + else + charClass = NORMAL; + break; + case '"': + charClass = QUOTE; + break; + case ' ': + case '\t': + charClass = WHITE; + break; + case '\r': + case '\n': + charClass = NL; + break; + case '!': + charClass = BANG; + break; + default: + charClass = NORMAL; + break; + } + return c; +} diff --git a/libXfont/src/fontfile/fileio.c b/libXfont/src/fontfile/fileio.c index 136087ca5..80af51193 100644 --- a/libXfont/src/fontfile/fileio.c +++ b/libXfont/src/fontfile/fileio.c @@ -1,91 +1,91 @@ -/*
-
-Copyright 1991, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-/*
- * Author: Keith Packard, MIT X Consortium
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/fonts/fntfilio.h>
-#include <X11/Xos.h>
-#ifndef O_BINARY
-#define O_BINARY O_RDONLY
-#endif
-
-FontFilePtr
-FontFileOpen (const char *name)
-{
- int fd;
- int len;
- BufFilePtr raw, cooked;
-
- fd = open (name, O_BINARY);
- if (fd < 0)
- return 0;
- raw = BufFileOpenRead (fd);
- if (!raw)
- {
- close (fd);
- return 0;
- }
- len = strlen (name);
- if (len > 2 && !strcmp (name + len - 2, ".Z")) {
- cooked = BufFilePushCompressed (raw);
- if (!cooked) {
- BufFileClose (raw, TRUE);
- return 0;
- }
- raw = cooked;
-#ifdef X_GZIP_FONT_COMPRESSION
- } else if (len > 3 && !strcmp (name + len - 3, ".gz")) {
- cooked = BufFilePushZIP (raw);
- if (!cooked) {
- BufFileClose (raw, TRUE);
- return 0;
- }
- raw = cooked;
-#endif
-#ifdef X_BZIP2_FONT_COMPRESSION
- } else if (len > 4 && !strcmp (name + len - 4, ".bz2")) {
- cooked = BufFilePushBZIP2 (raw);
- if (!cooked) {
- BufFileClose (raw, TRUE);
- return 0;
- }
- raw = cooked;
-#endif
- }
- return (FontFilePtr) raw;
-}
-
-int
-FontFileClose (FontFilePtr f)
-{
- return BufFileClose ((BufFilePtr) f, TRUE);
-}
-
+/* + +Copyright 1991, 1998 The Open Group + +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. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ + +/* + * Author: Keith Packard, MIT X Consortium + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/fonts/fntfilio.h> +#include <X11/Xos.h> +#ifndef O_BINARY +#define O_BINARY O_RDONLY +#endif + +FontFilePtr +FontFileOpen (const char *name) +{ + int fd; + int len; + BufFilePtr raw, cooked; + + fd = open (name, O_BINARY); + if (fd < 0) + return 0; + raw = BufFileOpenRead (fd); + if (!raw) + { + close (fd); + return 0; + } + len = strlen (name); + if (len > 2 && !strcmp (name + len - 2, ".Z")) { + cooked = BufFilePushCompressed (raw); + if (!cooked) { + BufFileClose (raw, TRUE); + return 0; + } + raw = cooked; +#ifdef X_GZIP_FONT_COMPRESSION + } else if (len > 3 && !strcmp (name + len - 3, ".gz")) { + cooked = BufFilePushZIP (raw); + if (!cooked) { + BufFileClose (raw, TRUE); + return 0; + } + raw = cooked; +#endif +#ifdef X_BZIP2_FONT_COMPRESSION + } else if (len > 4 && !strcmp (name + len - 4, ".bz2")) { + cooked = BufFilePushBZIP2 (raw); + if (!cooked) { + BufFileClose (raw, TRUE); + return 0; + } + raw = cooked; +#endif + } + return (FontFilePtr) raw; +} + +int +FontFileClose (FontFilePtr f) +{ + return BufFileClose ((BufFilePtr) f, TRUE); +} + diff --git a/libXfont/src/fontfile/filewr.c b/libXfont/src/fontfile/filewr.c index ad99e744b..bcc7b1eda 100644 --- a/libXfont/src/fontfile/filewr.c +++ b/libXfont/src/fontfile/filewr.c @@ -1,62 +1,62 @@ -/*
-
-Copyright 1991, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-/*
- * Author: Keith Packard, MIT X Consortium
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/fonts/fntfilio.h>
-#include <X11/Xos.h>
-
-FontFilePtr
-FontFileOpenWrite (const char *name)
-{
- int fd;
-
-#if defined(WIN32) || defined(__CYGWIN__)
- fd = open (name, O_CREAT|O_TRUNC|O_RDWR|O_BINARY, 0666);
-#else
- fd = creat (name, 0666);
-#endif
- if (fd < 0)
- return 0;
- return (FontFilePtr) BufFileOpenWrite (fd);
-}
-
-FontFilePtr
-FontFileOpenWriteFd (int fd)
-{
- return (FontFilePtr) BufFileOpenWrite (fd);
-}
-
-FontFilePtr
-FontFileOpenFd (int fd)
-{
- return (FontFilePtr) BufFileOpenRead (fd);
-}
+/* + +Copyright 1991, 1998 The Open Group + +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. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ + +/* + * Author: Keith Packard, MIT X Consortium + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/fonts/fntfilio.h> +#include <X11/Xos.h> + +FontFilePtr +FontFileOpenWrite (const char *name) +{ + int fd; + +#if defined(WIN32) || defined(__CYGWIN__) + fd = open (name, O_CREAT|O_TRUNC|O_RDWR|O_BINARY, 0666); +#else + fd = creat (name, 0666); +#endif + if (fd < 0) + return 0; + return (FontFilePtr) BufFileOpenWrite (fd); +} + +FontFilePtr +FontFileOpenWriteFd (int fd) +{ + return (FontFilePtr) BufFileOpenWrite (fd); +} + +FontFilePtr +FontFileOpenFd (int fd) +{ + return (FontFilePtr) BufFileOpenRead (fd); +} diff --git a/libXfont/src/fontfile/fontdir.c b/libXfont/src/fontfile/fontdir.c index c4f8bc023..e052bb371 100644 --- a/libXfont/src/fontfile/fontdir.c +++ b/libXfont/src/fontfile/fontdir.c @@ -1,825 +1,825 @@ -/*
-
-Copyright 1991, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-/*
- * Author: Keith Packard, MIT X Consortium
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/fonts/fntfilst.h>
-#include <X11/keysym.h>
-
-#if HAVE_STDINT_H
-#include <stdint.h>
-#elif !defined(INT32_MAX)
-#define INT32_MAX 0x7fffffff
-#endif
-
-Bool
-FontFileInitTable (FontTablePtr table, int size)
-{
- if (size < 0 || (size > INT32_MAX/sizeof(FontEntryRec)))
- return FALSE;
- if (size)
- {
- table->entries = malloc(sizeof(FontEntryRec) * size);
- if (!table->entries)
- return FALSE;
- }
- else
- table->entries = 0;
- table->used = 0;
- table->size = size;
- table->sorted = FALSE;
- return TRUE;
-}
-
-void
-FontFileFreeEntry (FontEntryPtr entry)
-{
- FontScalableExtraPtr extra;
- int i;
-
- if (entry->name.name)
- free(entry->name.name);
- entry->name.name = NULL;
-
- switch (entry->type)
- {
- case FONT_ENTRY_SCALABLE:
- free (entry->u.scalable.fileName);
- extra = entry->u.scalable.extra;
- for (i = 0; i < extra->numScaled; i++)
- if (extra->scaled[i].vals.ranges)
- free (extra->scaled[i].vals.ranges);
- free (extra->scaled);
- free (extra);
- break;
- case FONT_ENTRY_BITMAP:
- free (entry->u.bitmap.fileName);
- entry->u.bitmap.fileName = NULL;
- break;
- case FONT_ENTRY_ALIAS:
- free (entry->u.alias.resolved);
- entry->u.alias.resolved = NULL;
- break;
- }
-}
-
-void
-FontFileFreeTable (FontTablePtr table)
-{
- int i;
-
- for (i = 0; i < table->used; i++)
- FontFileFreeEntry (&table->entries[i]);
- free (table->entries);
-}
-
-FontDirectoryPtr
-FontFileMakeDir(char *dirName, int size)
-{
- FontDirectoryPtr dir;
- int dirlen;
- int needslash = 0;
- char *attrib;
- int attriblen;
-
-#if !defined(WIN32)
- attrib = strchr(dirName, ':');
-#else
- /* OS/2 uses the colon in the drive letter descriptor, skip this */
- attrib = strchr(dirName+2, ':');
-#endif
- if (attrib) {
- dirlen = attrib - dirName;
- attriblen = strlen(attrib);
- } else {
- dirlen = strlen(dirName);
- attriblen = 0;
- }
- if (dirName[dirlen - 1] != '/')
-#ifdef NCD
- if (dirlen) /* leave out slash for builtins */
-#endif
- needslash = 1;
- dir = malloc(sizeof *dir + dirlen + needslash + 1 +
- (attriblen ? attriblen + 1 : 0));
- if (!dir)
- return (FontDirectoryPtr)0;
- if (!FontFileInitTable (&dir->scalable, 0))
- {
- free (dir);
- return (FontDirectoryPtr)0;
- }
- if (!FontFileInitTable (&dir->nonScalable, size))
- {
- FontFileFreeTable (&dir->scalable);
- free (dir);
- return (FontDirectoryPtr)0;
- }
- dir->directory = (char *) (dir + 1);
- dir->dir_mtime = 0;
- dir->alias_mtime = 0;
- if (attriblen)
- dir->attributes = dir->directory + dirlen + needslash + 1;
- else
- dir->attributes = NULL;
- strncpy(dir->directory, dirName, dirlen);
- dir->directory[dirlen] = '\0';
- if (dir->attributes)
- strcpy(dir->attributes, attrib);
- if (needslash)
- strcat(dir->directory, "/");
- return dir;
-}
-
-void
-FontFileFreeDir (FontDirectoryPtr dir)
-{
- FontFileFreeTable (&dir->scalable);
- FontFileFreeTable (&dir->nonScalable);
- free(dir);
-}
-
-FontEntryPtr
-FontFileAddEntry(FontTablePtr table, FontEntryPtr prototype)
-{
- FontEntryPtr entry;
- int newsize;
-
- /* can't add entries to a sorted table, pointers get broken! */
- if (table->sorted)
- return (FontEntryPtr) 0; /* "cannot" happen */
- if (table->used == table->size) {
- newsize = table->size + 100;
- entry = realloc(table->entries, newsize * sizeof(FontEntryRec));
- if (!entry)
- return (FontEntryPtr)0;
- table->size = newsize;
- table->entries = entry;
- }
- entry = &table->entries[table->used];
- *entry = *prototype;
- entry->name.name = malloc(prototype->name.length + 1);
- if (!entry->name.name)
- return (FontEntryPtr)0;
- memcpy (entry->name.name, prototype->name.name, prototype->name.length);
- entry->name.name[entry->name.length] = '\0';
- table->used++;
- return entry;
-}
-
-/*
- * Compare two strings just like strcmp, but preserve decimal integer
- * sorting order, i.e. "2" < "10" or "iso8859-2" < "iso8859-10" <
- * "iso10646-1". Strings are sorted as if sequences of digits were
- * prefixed by a length indicator (i.e., does not ignore leading zeroes).
- *
- * Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>
- */
-#define Xisdigit(c) ('\060' <= (c) && (c) <= '\071')
-
-static int strcmpn(const char *s1, const char *s2)
-{
- int digits, predigits = 0;
- const char *ss1, *ss2;
-
- while (1) {
- if (*s1 == 0 && *s2 == 0)
- return 0;
- digits = Xisdigit(*s1) && Xisdigit(*s2);
- if (digits && !predigits) {
- ss1 = s1;
- ss2 = s2;
- while (Xisdigit(*ss1) && Xisdigit(*ss2))
- ss1++, ss2++;
- if (!Xisdigit(*ss1) && Xisdigit(*ss2))
- return -1;
- if (Xisdigit(*ss1) && !Xisdigit(*ss2))
- return 1;
- }
- if ((unsigned char)*s1 < (unsigned char)*s2)
- return -1;
- if ((unsigned char)*s1 > (unsigned char)*s2)
- return 1;
- predigits = digits;
- s1++, s2++;
- }
-}
-
-
-static int
-FontFileNameCompare(const void* a, const void* b)
-{
- FontEntryPtr a_name = (FontEntryPtr) a,
- b_name = (FontEntryPtr) b;
-
- return strcmpn(a_name->name.name, b_name->name.name);
-}
-
-void
-FontFileSortTable (FontTablePtr table)
-{
- if (!table->sorted) {
- qsort((char *) table->entries, table->used, sizeof(FontEntryRec),
- FontFileNameCompare);
- table->sorted = TRUE;
- }
-}
-
-void
-FontFileSortDir(FontDirectoryPtr dir)
-{
- FontFileSortTable (&dir->scalable);
- FontFileSortTable (&dir->nonScalable);
- /* now that the table is fixed in size, swizzle the pointers */
- FontFileSwitchStringsToBitmapPointers (dir);
-}
-
-/*
- Given a Font Table, SetupWildMatch() sets up various pointers and state
- information so the table can be searched for name(s) that match a given
- fontname pattern -- which may contain wildcards. Under certain
- circumstances, SetupWildMatch() will find the one table entry that
- matches the pattern. If those circumstances do not pertain,
- SetupWildMatch() returns a range within the the table that should be
- searched for matching name(s). With the information established by
- SetupWildMatch(), including state information in "private", the
- PatternMatch() procedure is then used to test names in the range for a
- match.
-*/
-
-#define isWild(c) ((c) == XK_asterisk || (c) == XK_question)
-#define isDigit(c) (XK_0 <= (c) && (c) <= XK_9)
-
-static int
-SetupWildMatch(FontTablePtr table, FontNamePtr pat,
- int *leftp, int *rightp, int *privatep)
-{
- int nDashes;
- char c;
- char *t;
- char *firstWild;
- char *firstDigit;
- int first;
- int center,
- left,
- right;
- int result;
- char *name;
-
- name = pat->name;
- nDashes = pat->ndashes;
- firstWild = 0;
- firstDigit = 0;
- t = name;
- while ((c = *t++)) {
- if (isWild(c)) {
- if (!firstWild)
- firstWild = t - 1;
- }
- if (isDigit(c)) {
- if (!firstDigit)
- firstDigit = t - 1;
- }
- }
- left = 0;
- right = table->used;
- if (firstWild)
- *privatep = nDashes;
- else
- *privatep = -1;
- if (!table->sorted) {
- *leftp = left;
- *rightp = right;
- return -1;
- } else if (firstWild) {
- if (firstDigit && firstDigit < firstWild)
- first = firstDigit - name;
- else
- first = firstWild - name;
- while (left < right) {
- center = (left + right) / 2;
- result = strncmp(name, table->entries[center].name.name, first);
- if (result == 0)
- break;
- if (result < 0)
- right = center;
- else
- left = center + 1;
- }
- *leftp = left;
- *rightp = right;
- return -1;
- } else {
- while (left < right) {
- center = (left + right) / 2;
- result = strcmpn(name, table->entries[center].name.name);
- if (result == 0)
- return center;
- if (result < 0)
- right = center;
- else
- left = center + 1;
- }
- *leftp = 1;
- *rightp = 0;
- return -1;
- }
-}
-
-static int
-PatternMatch(char *pat, int patdashes, char *string, int stringdashes)
-{
- char c,
- t;
-
- if (stringdashes < patdashes)
- return 0;
- for (;;) {
- switch (c = *pat++) {
- case '*':
- if (!(c = *pat++))
- return 1;
- if (c == XK_minus) {
- patdashes--;
- for (;;) {
- while ((t = *string++) != XK_minus)
- if (!t)
- return 0;
- stringdashes--;
- if (PatternMatch(pat, patdashes, string, stringdashes))
- return 1;
- if (stringdashes == patdashes)
- return 0;
- }
- } else {
- for (;;) {
- while ((t = *string++) != c) {
- if (!t)
- return 0;
- if (t == XK_minus) {
- if (stringdashes-- < patdashes)
- return 0;
- }
- }
- if (PatternMatch(pat, patdashes, string, stringdashes))
- return 1;
- }
- }
- case '?':
- if (*string++ == XK_minus)
- stringdashes--;
- break;
- case '\0':
- return (*string == '\0');
- case XK_minus:
- if (*string++ == XK_minus) {
- patdashes--;
- stringdashes--;
- break;
- }
- return 0;
- default:
- if (c == *string++)
- break;
- return 0;
- }
- }
-}
-
-int
-FontFileCountDashes (char *name, int namelen)
-{
- int ndashes = 0;
-
- while (namelen--)
- if (*name++ == '\055') /* avoid non ascii systems */
- ++ndashes;
- return ndashes;
-}
-
-char *
-FontFileSaveString (char *s)
-{
- char *n;
-
- n = malloc (strlen (s) + 1);
- if (!n)
- return 0;
- strcpy (n, s);
- return n;
-}
-
-FontEntryPtr
-FontFileFindNameInScalableDir(FontTablePtr table, FontNamePtr pat,
- FontScalablePtr vals)
-{
- int i,
- start,
- stop,
- res,
- private;
- FontNamePtr name;
-
- if (!table->entries)
- return NULL;
- if ((i = SetupWildMatch(table, pat, &start, &stop, &private)) >= 0)
- return &table->entries[i];
- for (i = start; i < stop; i++) {
- name = &table->entries[i].name;
- res = PatternMatch(pat->name, private, name->name, name->ndashes);
- if (res > 0)
- {
- /* Check to see if enhancements requested are available */
- if (vals)
- {
- int vs = vals->values_supplied;
- int cap;
-
- if (table->entries[i].type == FONT_ENTRY_SCALABLE)
- cap = table->entries[i].u.scalable.renderer->capabilities;
- else if (table->entries[i].type == FONT_ENTRY_ALIAS)
- cap = ~0; /* Calling code will have to see if true */
- else
- cap = 0;
- if ((((vs & PIXELSIZE_MASK) == PIXELSIZE_ARRAY ||
- (vs & POINTSIZE_MASK) == POINTSIZE_ARRAY) &&
- !(cap & CAP_MATRIX)) ||
- ((vs & CHARSUBSET_SPECIFIED) &&
- !(cap & CAP_CHARSUBSETTING)))
- continue;
- }
- return &table->entries[i];
- }
- if (res < 0)
- break;
- }
- return (FontEntryPtr)0;
-}
-
-FontEntryPtr
-FontFileFindNameInDir(FontTablePtr table, FontNamePtr pat)
-{
- return FontFileFindNameInScalableDir(table, pat, (FontScalablePtr)0);
-}
-
-int
-FontFileFindNamesInScalableDir(FontTablePtr table, FontNamePtr pat, int max,
- FontNamesPtr names, FontScalablePtr vals,
- int alias_behavior, int *newmax)
-{
- int i,
- start,
- stop,
- res,
- private;
- int ret = Successful;
- FontEntryPtr fname;
- FontNamePtr name;
-
- if (max <= 0)
- return Successful;
- if ((i = SetupWildMatch(table, pat, &start, &stop, &private)) >= 0) {
- if (alias_behavior == NORMAL_ALIAS_BEHAVIOR ||
- table->entries[i].type != FONT_ENTRY_ALIAS)
- {
- name = &table->entries[i].name;
- if (newmax) *newmax = max - 1;
- return AddFontNamesName(names, name->name, name->length);
- }
- start = i;
- stop = i + 1;
- }
- for (i = start, fname = &table->entries[start]; i < stop; i++, fname++) {
- res = PatternMatch(pat->name, private, fname->name.name, fname->name.ndashes);
- if (res > 0) {
- if (vals)
- {
- int vs = vals->values_supplied;
- int cap;
-
- if (fname->type == FONT_ENTRY_SCALABLE)
- cap = fname->u.scalable.renderer->capabilities;
- else if (fname->type == FONT_ENTRY_ALIAS)
- cap = ~0; /* Calling code will have to see if true */
- else
- cap = 0;
- if ((((vs & PIXELSIZE_MASK) == PIXELSIZE_ARRAY ||
- (vs & POINTSIZE_MASK) == POINTSIZE_ARRAY) &&
- !(cap & CAP_MATRIX)) ||
- ((vs & CHARSUBSET_SPECIFIED) &&
- !(cap & CAP_CHARSUBSETTING)))
- continue;
- }
-
- if ((alias_behavior & IGNORE_SCALABLE_ALIASES) &&
- fname->type == FONT_ENTRY_ALIAS)
- {
- FontScalableRec tmpvals;
- if (FontParseXLFDName (fname->name.name, &tmpvals,
- FONT_XLFD_REPLACE_NONE) &&
- !(tmpvals.values_supplied & SIZE_SPECIFY_MASK))
- continue;
- }
-
- ret = AddFontNamesName(names, fname->name.name, fname->name.length);
- if (ret != Successful)
- goto bail;
-
- /* If alias_behavior is LIST_ALIASES_AND_TARGET_NAMES, mark
- this entry as an alias by negating its length and follow
- it by the resolved name */
- if ((alias_behavior & LIST_ALIASES_AND_TARGET_NAMES) &&
- fname->type == FONT_ENTRY_ALIAS)
- {
- names->length[names->nnames - 1] =
- -names->length[names->nnames - 1];
- ret = AddFontNamesName(names, fname->u.alias.resolved,
- strlen(fname->u.alias.resolved));
- if (ret != Successful)
- goto bail;
- }
-
- if (--max <= 0)
- break;
- } else if (res < 0)
- break;
- }
- bail: ;
- if (newmax) *newmax = max;
- return ret;
-}
-
-int
-FontFileFindNamesInDir(FontTablePtr table, FontNamePtr pat,
- int max, FontNamesPtr names)
-{
- return FontFileFindNamesInScalableDir(table, pat, max, names,
- (FontScalablePtr)0,
- NORMAL_ALIAS_BEHAVIOR, (int *)0);
-}
-
-Bool
-FontFileMatchName(char *name, int length, FontNamePtr pat)
-{
- /* Perform a fontfile-type name match on a single name */
- FontTableRec table;
- FontEntryRec entries[1];
-
- /* Dummy up a table */
- table.used = 1;
- table.size = 1;
- table.sorted = TRUE;
- table.entries = entries;
- entries[0].name.name = name;
- entries[0].name.length = length;
- entries[0].name.ndashes = FontFileCountDashes(name, length);
-
- return FontFileFindNameInDir(&table, pat) != (FontEntryPtr)0;
-}
-
-/*
- * Add a font file to a directory. This handles bitmap and
- * scalable names both
- */
-
-Bool
-FontFileAddFontFile (FontDirectoryPtr dir, char *fontName, char *fileName)
-{
- FontEntryRec entry;
- FontScalableRec vals, zeroVals;
- FontRendererPtr renderer;
- FontEntryPtr existing;
- FontScalableExtraPtr extra;
- FontEntryPtr bitmap = 0, scalable;
- Bool isscale;
- Bool scalable_xlfd;
-
- renderer = FontFileMatchRenderer (fileName);
- if (!renderer)
- return FALSE;
- entry.name.length = strlen (fontName);
- if (entry.name.length > MAXFONTNAMELEN)
- entry.name.length = MAXFONTNAMELEN;
- entry.name.name = fontName;
- CopyISOLatin1Lowered (entry.name.name, fontName, entry.name.length);
- entry.name.ndashes = FontFileCountDashes (entry.name.name, entry.name.length);
- entry.name.name[entry.name.length] = '\0';
- /*
- * Add a bitmap name if the incoming name isn't an XLFD name, or
- * if it isn't a scalable name (i.e. non-zero scalable fields)
- *
- * If name of bitmapped font contains XLFD enhancements, do not add
- * a scalable version of the name... this can lead to confusion and
- * ambiguity between the font name and the field enhancements.
- */
- isscale = entry.name.ndashes == 14 &&
- FontParseXLFDName(entry.name.name,
- &vals, FONT_XLFD_REPLACE_NONE) &&
- (vals.values_supplied & PIXELSIZE_MASK) != PIXELSIZE_ARRAY &&
- (vals.values_supplied & POINTSIZE_MASK) != POINTSIZE_ARRAY &&
- !(vals.values_supplied & ENHANCEMENT_SPECIFY_MASK);
-#define UNSCALED_ATTRIB "unscaled"
- scalable_xlfd = (isscale &&
- (((vals.values_supplied & PIXELSIZE_MASK) == 0) ||
- ((vals.values_supplied & POINTSIZE_MASK) == 0)));
- /*
- * For scalable fonts without a scalable XFLD, check if the "unscaled"
- * attribute is present.
- */
- if (isscale && !scalable_xlfd &&
- dir->attributes && dir->attributes[0] == ':') {
- char *ptr1 = dir->attributes + 1;
- char *ptr2;
- int length;
- int uslength = strlen(UNSCALED_ATTRIB);
-
- do {
- ptr2 = strchr(ptr1, ':');
- if (ptr2)
- length = ptr2 - ptr1;
- else
- length = dir->attributes + strlen(dir->attributes) - ptr1;
- if (length == uslength && !strncmp(ptr1, UNSCALED_ATTRIB, uslength))
- isscale = FALSE;
- if (ptr2)
- ptr1 = ptr2 + 1;
- } while (ptr2);
- }
- if (!isscale || (vals.values_supplied & SIZE_SPECIFY_MASK))
- {
- /*
- * If the renderer doesn't support OpenBitmap, FontFileOpenFont
- * will still do the right thing.
- */
- entry.type = FONT_ENTRY_BITMAP;
- entry.u.bitmap.renderer = renderer;
- entry.u.bitmap.pFont = NullFont;
- if (!(entry.u.bitmap.fileName = FontFileSaveString (fileName)))
- return FALSE;
- if (!(bitmap = FontFileAddEntry (&dir->nonScalable, &entry)))
- {
- free (entry.u.bitmap.fileName);
- return FALSE;
- }
- }
- /*
- * Parse out scalable fields from XLFD names - a scalable name
- * just gets inserted, a scaled name has more things to do.
- */
- if (isscale)
- {
- if (vals.values_supplied & SIZE_SPECIFY_MASK)
- {
- bzero((char *)&zeroVals, sizeof(zeroVals));
- zeroVals.x = vals.x;
- zeroVals.y = vals.y;
- zeroVals.values_supplied = PIXELSIZE_SCALAR | POINTSIZE_SCALAR;
- FontParseXLFDName (entry.name.name, &zeroVals,
- FONT_XLFD_REPLACE_VALUE);
- entry.name.length = strlen (entry.name.name);
- existing = FontFileFindNameInDir (&dir->scalable, &entry.name);
- if (existing)
- {
- if ((vals.values_supplied & POINTSIZE_MASK) ==
- POINTSIZE_SCALAR &&
- (int)(vals.point_matrix[3] * 10) == GetDefaultPointSize())
- {
- existing->u.scalable.extra->defaults = vals;
-
- free (existing->u.scalable.fileName);
- if (!(existing->u.scalable.fileName = FontFileSaveString (fileName)))
- return FALSE;
- }
- if(bitmap)
- {
- FontFileCompleteXLFD(&vals, &vals);
- FontFileAddScaledInstance (existing, &vals, NullFont,
- bitmap->name.name);
- return TRUE;
- }
- }
- }
- if (!(entry.u.scalable.fileName = FontFileSaveString (fileName)))
- return FALSE;
- extra = malloc (sizeof (FontScalableExtraRec));
- if (!extra)
- {
- free (entry.u.scalable.fileName);
- return FALSE;
- }
- bzero((char *)&extra->defaults, sizeof(extra->defaults));
- if ((vals.values_supplied & POINTSIZE_MASK) == POINTSIZE_SCALAR &&
- (int)(vals.point_matrix[3] * 10) == GetDefaultPointSize())
- extra->defaults = vals;
- else
- {
- FontResolutionPtr resolution;
- int num;
- int default_point_size = GetDefaultPointSize();
-
- extra->defaults.point_matrix[0] =
- extra->defaults.point_matrix[3] =
- (double)default_point_size / 10.0;
- extra->defaults.point_matrix[1] =
- extra->defaults.point_matrix[2] = 0.0;
- extra->defaults.values_supplied =
- POINTSIZE_SCALAR | PIXELSIZE_UNDEFINED;
- extra->defaults.width = -1;
- if (vals.x <= 0 || vals.y <= 0)
- {
- resolution = GetClientResolutions (&num);
- if (resolution && num > 0)
- {
- extra->defaults.x = resolution->x_resolution;
- extra->defaults.y = resolution->y_resolution;
- }
- else
- {
- extra->defaults.x = 75;
- extra->defaults.y = 75;
- }
- }
- else
- {
- extra->defaults.x = vals.x;
- extra->defaults.y = vals.y;
- }
- FontFileCompleteXLFD (&extra->defaults, &extra->defaults);
- }
- extra->numScaled = 0;
- extra->sizeScaled = 0;
- extra->scaled = 0;
- extra->private = 0;
- entry.type = FONT_ENTRY_SCALABLE;
- entry.u.scalable.renderer = renderer;
- entry.u.scalable.extra = extra;
- if (!(scalable = FontFileAddEntry (&dir->scalable, &entry)))
- {
- free (extra);
- free (entry.u.scalable.fileName);
- return FALSE;
- }
- if (vals.values_supplied & SIZE_SPECIFY_MASK)
- {
- if(bitmap)
- {
- FontFileCompleteXLFD(&vals, &vals);
- FontFileAddScaledInstance (scalable, &vals, NullFont,
- bitmap->name.name);
- }
- }
- }
- return TRUE;
-}
-
-Bool
-FontFileAddFontAlias (FontDirectoryPtr dir, char *aliasName, char *fontName)
-{
- FontEntryRec entry;
-
- if (strcmp(aliasName,fontName) == 0) {
- /* Don't allow an alias to point to itself and create a loop */
- return FALSE;
- }
- entry.name.length = strlen (aliasName);
- CopyISOLatin1Lowered (aliasName, aliasName, entry.name.length);
- entry.name.name = aliasName;
- entry.name.ndashes = FontFileCountDashes (entry.name.name, entry.name.length);
- entry.type = FONT_ENTRY_ALIAS;
- if (!(entry.u.alias.resolved = FontFileSaveString (fontName)))
- return FALSE;
- if (!FontFileAddEntry (&dir->nonScalable, &entry))
- {
- free (entry.u.alias.resolved);
- return FALSE;
- }
- return TRUE;
-}
+/* + +Copyright 1991, 1998 The Open Group + +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. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ + +/* + * Author: Keith Packard, MIT X Consortium + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/fonts/fntfilst.h> +#include <X11/keysym.h> + +#if HAVE_STDINT_H +#include <stdint.h> +#elif !defined(INT32_MAX) +#define INT32_MAX 0x7fffffff +#endif + +Bool +FontFileInitTable (FontTablePtr table, int size) +{ + if (size < 0 || (size > INT32_MAX/sizeof(FontEntryRec))) + return FALSE; + if (size) + { + table->entries = malloc(sizeof(FontEntryRec) * size); + if (!table->entries) + return FALSE; + } + else + table->entries = 0; + table->used = 0; + table->size = size; + table->sorted = FALSE; + return TRUE; +} + +void +FontFileFreeEntry (FontEntryPtr entry) +{ + FontScalableExtraPtr extra; + int i; + + if (entry->name.name) + free(entry->name.name); + entry->name.name = NULL; + + switch (entry->type) + { + case FONT_ENTRY_SCALABLE: + free (entry->u.scalable.fileName); + extra = entry->u.scalable.extra; + for (i = 0; i < extra->numScaled; i++) + if (extra->scaled[i].vals.ranges) + free (extra->scaled[i].vals.ranges); + free (extra->scaled); + free (extra); + break; + case FONT_ENTRY_BITMAP: + free (entry->u.bitmap.fileName); + entry->u.bitmap.fileName = NULL; + break; + case FONT_ENTRY_ALIAS: + free (entry->u.alias.resolved); + entry->u.alias.resolved = NULL; + break; + } +} + +void +FontFileFreeTable (FontTablePtr table) +{ + int i; + + for (i = 0; i < table->used; i++) + FontFileFreeEntry (&table->entries[i]); + free (table->entries); +} + +FontDirectoryPtr +FontFileMakeDir(char *dirName, int size) +{ + FontDirectoryPtr dir; + int dirlen; + int needslash = 0; + char *attrib; + int attriblen; + +#if !defined(WIN32) + attrib = strchr(dirName, ':'); +#else + /* OS/2 uses the colon in the drive letter descriptor, skip this */ + attrib = strchr(dirName+2, ':'); +#endif + if (attrib) { + dirlen = attrib - dirName; + attriblen = strlen(attrib); + } else { + dirlen = strlen(dirName); + attriblen = 0; + } + if (dirName[dirlen - 1] != '/') +#ifdef NCD + if (dirlen) /* leave out slash for builtins */ +#endif + needslash = 1; + dir = malloc(sizeof *dir + dirlen + needslash + 1 + + (attriblen ? attriblen + 1 : 0)); + if (!dir) + return (FontDirectoryPtr)0; + if (!FontFileInitTable (&dir->scalable, 0)) + { + free (dir); + return (FontDirectoryPtr)0; + } + if (!FontFileInitTable (&dir->nonScalable, size)) + { + FontFileFreeTable (&dir->scalable); + free (dir); + return (FontDirectoryPtr)0; + } + dir->directory = (char *) (dir + 1); + dir->dir_mtime = 0; + dir->alias_mtime = 0; + if (attriblen) + dir->attributes = dir->directory + dirlen + needslash + 1; + else + dir->attributes = NULL; + strncpy(dir->directory, dirName, dirlen); + dir->directory[dirlen] = '\0'; + if (dir->attributes) + strcpy(dir->attributes, attrib); + if (needslash) + strcat(dir->directory, "/"); + return dir; +} + +void +FontFileFreeDir (FontDirectoryPtr dir) +{ + FontFileFreeTable (&dir->scalable); + FontFileFreeTable (&dir->nonScalable); + free(dir); +} + +FontEntryPtr +FontFileAddEntry(FontTablePtr table, FontEntryPtr prototype) +{ + FontEntryPtr entry; + int newsize; + + /* can't add entries to a sorted table, pointers get broken! */ + if (table->sorted) + return (FontEntryPtr) 0; /* "cannot" happen */ + if (table->used == table->size) { + newsize = table->size + 100; + entry = realloc(table->entries, newsize * sizeof(FontEntryRec)); + if (!entry) + return (FontEntryPtr)0; + table->size = newsize; + table->entries = entry; + } + entry = &table->entries[table->used]; + *entry = *prototype; + entry->name.name = malloc(prototype->name.length + 1); + if (!entry->name.name) + return (FontEntryPtr)0; + memcpy (entry->name.name, prototype->name.name, prototype->name.length); + entry->name.name[entry->name.length] = '\0'; + table->used++; + return entry; +} + +/* + * Compare two strings just like strcmp, but preserve decimal integer + * sorting order, i.e. "2" < "10" or "iso8859-2" < "iso8859-10" < + * "iso10646-1". Strings are sorted as if sequences of digits were + * prefixed by a length indicator (i.e., does not ignore leading zeroes). + * + * Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk> + */ +#define Xisdigit(c) ('\060' <= (c) && (c) <= '\071') + +static int strcmpn(const char *s1, const char *s2) +{ + int digits, predigits = 0; + const char *ss1, *ss2; + + while (1) { + if (*s1 == 0 && *s2 == 0) + return 0; + digits = Xisdigit(*s1) && Xisdigit(*s2); + if (digits && !predigits) { + ss1 = s1; + ss2 = s2; + while (Xisdigit(*ss1) && Xisdigit(*ss2)) + ss1++, ss2++; + if (!Xisdigit(*ss1) && Xisdigit(*ss2)) + return -1; + if (Xisdigit(*ss1) && !Xisdigit(*ss2)) + return 1; + } + if ((unsigned char)*s1 < (unsigned char)*s2) + return -1; + if ((unsigned char)*s1 > (unsigned char)*s2) + return 1; + predigits = digits; + s1++, s2++; + } +} + + +static int +FontFileNameCompare(const void* a, const void* b) +{ + FontEntryPtr a_name = (FontEntryPtr) a, + b_name = (FontEntryPtr) b; + + return strcmpn(a_name->name.name, b_name->name.name); +} + +void +FontFileSortTable (FontTablePtr table) +{ + if (!table->sorted) { + qsort((char *) table->entries, table->used, sizeof(FontEntryRec), + FontFileNameCompare); + table->sorted = TRUE; + } +} + +void +FontFileSortDir(FontDirectoryPtr dir) +{ + FontFileSortTable (&dir->scalable); + FontFileSortTable (&dir->nonScalable); + /* now that the table is fixed in size, swizzle the pointers */ + FontFileSwitchStringsToBitmapPointers (dir); +} + +/* + Given a Font Table, SetupWildMatch() sets up various pointers and state + information so the table can be searched for name(s) that match a given + fontname pattern -- which may contain wildcards. Under certain + circumstances, SetupWildMatch() will find the one table entry that + matches the pattern. If those circumstances do not pertain, + SetupWildMatch() returns a range within the the table that should be + searched for matching name(s). With the information established by + SetupWildMatch(), including state information in "private", the + PatternMatch() procedure is then used to test names in the range for a + match. +*/ + +#define isWild(c) ((c) == XK_asterisk || (c) == XK_question) +#define isDigit(c) (XK_0 <= (c) && (c) <= XK_9) + +static int +SetupWildMatch(FontTablePtr table, FontNamePtr pat, + int *leftp, int *rightp, int *privatep) +{ + int nDashes; + char c; + char *t; + char *firstWild; + char *firstDigit; + int first; + int center, + left, + right; + int result; + char *name; + + name = pat->name; + nDashes = pat->ndashes; + firstWild = 0; + firstDigit = 0; + t = name; + while ((c = *t++)) { + if (isWild(c)) { + if (!firstWild) + firstWild = t - 1; + } + if (isDigit(c)) { + if (!firstDigit) + firstDigit = t - 1; + } + } + left = 0; + right = table->used; + if (firstWild) + *privatep = nDashes; + else + *privatep = -1; + if (!table->sorted) { + *leftp = left; + *rightp = right; + return -1; + } else if (firstWild) { + if (firstDigit && firstDigit < firstWild) + first = firstDigit - name; + else + first = firstWild - name; + while (left < right) { + center = (left + right) / 2; + result = strncmp(name, table->entries[center].name.name, first); + if (result == 0) + break; + if (result < 0) + right = center; + else + left = center + 1; + } + *leftp = left; + *rightp = right; + return -1; + } else { + while (left < right) { + center = (left + right) / 2; + result = strcmpn(name, table->entries[center].name.name); + if (result == 0) + return center; + if (result < 0) + right = center; + else + left = center + 1; + } + *leftp = 1; + *rightp = 0; + return -1; + } +} + +static int +PatternMatch(char *pat, int patdashes, char *string, int stringdashes) +{ + char c, + t; + + if (stringdashes < patdashes) + return 0; + for (;;) { + switch (c = *pat++) { + case '*': + if (!(c = *pat++)) + return 1; + if (c == XK_minus) { + patdashes--; + for (;;) { + while ((t = *string++) != XK_minus) + if (!t) + return 0; + stringdashes--; + if (PatternMatch(pat, patdashes, string, stringdashes)) + return 1; + if (stringdashes == patdashes) + return 0; + } + } else { + for (;;) { + while ((t = *string++) != c) { + if (!t) + return 0; + if (t == XK_minus) { + if (stringdashes-- < patdashes) + return 0; + } + } + if (PatternMatch(pat, patdashes, string, stringdashes)) + return 1; + } + } + case '?': + if (*string++ == XK_minus) + stringdashes--; + break; + case '\0': + return (*string == '\0'); + case XK_minus: + if (*string++ == XK_minus) { + patdashes--; + stringdashes--; + break; + } + return 0; + default: + if (c == *string++) + break; + return 0; + } + } +} + +int +FontFileCountDashes (char *name, int namelen) +{ + int ndashes = 0; + + while (namelen--) + if (*name++ == '\055') /* avoid non ascii systems */ + ++ndashes; + return ndashes; +} + +char * +FontFileSaveString (char *s) +{ + char *n; + + n = malloc (strlen (s) + 1); + if (!n) + return 0; + strcpy (n, s); + return n; +} + +FontEntryPtr +FontFileFindNameInScalableDir(FontTablePtr table, FontNamePtr pat, + FontScalablePtr vals) +{ + int i, + start, + stop, + res, + private; + FontNamePtr name; + + if (!table->entries) + return NULL; + if ((i = SetupWildMatch(table, pat, &start, &stop, &private)) >= 0) + return &table->entries[i]; + for (i = start; i < stop; i++) { + name = &table->entries[i].name; + res = PatternMatch(pat->name, private, name->name, name->ndashes); + if (res > 0) + { + /* Check to see if enhancements requested are available */ + if (vals) + { + int vs = vals->values_supplied; + int cap; + + if (table->entries[i].type == FONT_ENTRY_SCALABLE) + cap = table->entries[i].u.scalable.renderer->capabilities; + else if (table->entries[i].type == FONT_ENTRY_ALIAS) + cap = ~0; /* Calling code will have to see if true */ + else + cap = 0; + if ((((vs & PIXELSIZE_MASK) == PIXELSIZE_ARRAY || + (vs & POINTSIZE_MASK) == POINTSIZE_ARRAY) && + !(cap & CAP_MATRIX)) || + ((vs & CHARSUBSET_SPECIFIED) && + !(cap & CAP_CHARSUBSETTING))) + continue; + } + return &table->entries[i]; + } + if (res < 0) + break; + } + return (FontEntryPtr)0; +} + +FontEntryPtr +FontFileFindNameInDir(FontTablePtr table, FontNamePtr pat) +{ + return FontFileFindNameInScalableDir(table, pat, (FontScalablePtr)0); +} + +int +FontFileFindNamesInScalableDir(FontTablePtr table, FontNamePtr pat, int max, + FontNamesPtr names, FontScalablePtr vals, + int alias_behavior, int *newmax) +{ + int i, + start, + stop, + res, + private; + int ret = Successful; + FontEntryPtr fname; + FontNamePtr name; + + if (max <= 0) + return Successful; + if ((i = SetupWildMatch(table, pat, &start, &stop, &private)) >= 0) { + if (alias_behavior == NORMAL_ALIAS_BEHAVIOR || + table->entries[i].type != FONT_ENTRY_ALIAS) + { + name = &table->entries[i].name; + if (newmax) *newmax = max - 1; + return AddFontNamesName(names, name->name, name->length); + } + start = i; + stop = i + 1; + } + for (i = start, fname = &table->entries[start]; i < stop; i++, fname++) { + res = PatternMatch(pat->name, private, fname->name.name, fname->name.ndashes); + if (res > 0) { + if (vals) + { + int vs = vals->values_supplied; + int cap; + + if (fname->type == FONT_ENTRY_SCALABLE) + cap = fname->u.scalable.renderer->capabilities; + else if (fname->type == FONT_ENTRY_ALIAS) + cap = ~0; /* Calling code will have to see if true */ + else + cap = 0; + if ((((vs & PIXELSIZE_MASK) == PIXELSIZE_ARRAY || + (vs & POINTSIZE_MASK) == POINTSIZE_ARRAY) && + !(cap & CAP_MATRIX)) || + ((vs & CHARSUBSET_SPECIFIED) && + !(cap & CAP_CHARSUBSETTING))) + continue; + } + + if ((alias_behavior & IGNORE_SCALABLE_ALIASES) && + fname->type == FONT_ENTRY_ALIAS) + { + FontScalableRec tmpvals; + if (FontParseXLFDName (fname->name.name, &tmpvals, + FONT_XLFD_REPLACE_NONE) && + !(tmpvals.values_supplied & SIZE_SPECIFY_MASK)) + continue; + } + + ret = AddFontNamesName(names, fname->name.name, fname->name.length); + if (ret != Successful) + goto bail; + + /* If alias_behavior is LIST_ALIASES_AND_TARGET_NAMES, mark + this entry as an alias by negating its length and follow + it by the resolved name */ + if ((alias_behavior & LIST_ALIASES_AND_TARGET_NAMES) && + fname->type == FONT_ENTRY_ALIAS) + { + names->length[names->nnames - 1] = + -names->length[names->nnames - 1]; + ret = AddFontNamesName(names, fname->u.alias.resolved, + strlen(fname->u.alias.resolved)); + if (ret != Successful) + goto bail; + } + + if (--max <= 0) + break; + } else if (res < 0) + break; + } + bail: ; + if (newmax) *newmax = max; + return ret; +} + +int +FontFileFindNamesInDir(FontTablePtr table, FontNamePtr pat, + int max, FontNamesPtr names) +{ + return FontFileFindNamesInScalableDir(table, pat, max, names, + (FontScalablePtr)0, + NORMAL_ALIAS_BEHAVIOR, (int *)0); +} + +Bool +FontFileMatchName(char *name, int length, FontNamePtr pat) +{ + /* Perform a fontfile-type name match on a single name */ + FontTableRec table; + FontEntryRec entries[1]; + + /* Dummy up a table */ + table.used = 1; + table.size = 1; + table.sorted = TRUE; + table.entries = entries; + entries[0].name.name = name; + entries[0].name.length = length; + entries[0].name.ndashes = FontFileCountDashes(name, length); + + return FontFileFindNameInDir(&table, pat) != (FontEntryPtr)0; +} + +/* + * Add a font file to a directory. This handles bitmap and + * scalable names both + */ + +Bool +FontFileAddFontFile (FontDirectoryPtr dir, char *fontName, char *fileName) +{ + FontEntryRec entry; + FontScalableRec vals, zeroVals; + FontRendererPtr renderer; + FontEntryPtr existing; + FontScalableExtraPtr extra; + FontEntryPtr bitmap = 0, scalable; + Bool isscale; + Bool scalable_xlfd; + + renderer = FontFileMatchRenderer (fileName); + if (!renderer) + return FALSE; + entry.name.length = strlen (fontName); + if (entry.name.length > MAXFONTNAMELEN) + entry.name.length = MAXFONTNAMELEN; + entry.name.name = fontName; + CopyISOLatin1Lowered (entry.name.name, fontName, entry.name.length); + entry.name.ndashes = FontFileCountDashes (entry.name.name, entry.name.length); + entry.name.name[entry.name.length] = '\0'; + /* + * Add a bitmap name if the incoming name isn't an XLFD name, or + * if it isn't a scalable name (i.e. non-zero scalable fields) + * + * If name of bitmapped font contains XLFD enhancements, do not add + * a scalable version of the name... this can lead to confusion and + * ambiguity between the font name and the field enhancements. + */ + isscale = entry.name.ndashes == 14 && + FontParseXLFDName(entry.name.name, + &vals, FONT_XLFD_REPLACE_NONE) && + (vals.values_supplied & PIXELSIZE_MASK) != PIXELSIZE_ARRAY && + (vals.values_supplied & POINTSIZE_MASK) != POINTSIZE_ARRAY && + !(vals.values_supplied & ENHANCEMENT_SPECIFY_MASK); +#define UNSCALED_ATTRIB "unscaled" + scalable_xlfd = (isscale && + (((vals.values_supplied & PIXELSIZE_MASK) == 0) || + ((vals.values_supplied & POINTSIZE_MASK) == 0))); + /* + * For scalable fonts without a scalable XFLD, check if the "unscaled" + * attribute is present. + */ + if (isscale && !scalable_xlfd && + dir->attributes && dir->attributes[0] == ':') { + char *ptr1 = dir->attributes + 1; + char *ptr2; + int length; + int uslength = strlen(UNSCALED_ATTRIB); + + do { + ptr2 = strchr(ptr1, ':'); + if (ptr2) + length = ptr2 - ptr1; + else + length = dir->attributes + strlen(dir->attributes) - ptr1; + if (length == uslength && !strncmp(ptr1, UNSCALED_ATTRIB, uslength)) + isscale = FALSE; + if (ptr2) + ptr1 = ptr2 + 1; + } while (ptr2); + } + if (!isscale || (vals.values_supplied & SIZE_SPECIFY_MASK)) + { + /* + * If the renderer doesn't support OpenBitmap, FontFileOpenFont + * will still do the right thing. + */ + entry.type = FONT_ENTRY_BITMAP; + entry.u.bitmap.renderer = renderer; + entry.u.bitmap.pFont = NullFont; + if (!(entry.u.bitmap.fileName = FontFileSaveString (fileName))) + return FALSE; + if (!(bitmap = FontFileAddEntry (&dir->nonScalable, &entry))) + { + free (entry.u.bitmap.fileName); + return FALSE; + } + } + /* + * Parse out scalable fields from XLFD names - a scalable name + * just gets inserted, a scaled name has more things to do. + */ + if (isscale) + { + if (vals.values_supplied & SIZE_SPECIFY_MASK) + { + bzero((char *)&zeroVals, sizeof(zeroVals)); + zeroVals.x = vals.x; + zeroVals.y = vals.y; + zeroVals.values_supplied = PIXELSIZE_SCALAR | POINTSIZE_SCALAR; + FontParseXLFDName (entry.name.name, &zeroVals, + FONT_XLFD_REPLACE_VALUE); + entry.name.length = strlen (entry.name.name); + existing = FontFileFindNameInDir (&dir->scalable, &entry.name); + if (existing) + { + if ((vals.values_supplied & POINTSIZE_MASK) == + POINTSIZE_SCALAR && + (int)(vals.point_matrix[3] * 10) == GetDefaultPointSize()) + { + existing->u.scalable.extra->defaults = vals; + + free (existing->u.scalable.fileName); + if (!(existing->u.scalable.fileName = FontFileSaveString (fileName))) + return FALSE; + } + if(bitmap) + { + FontFileCompleteXLFD(&vals, &vals); + FontFileAddScaledInstance (existing, &vals, NullFont, + bitmap->name.name); + return TRUE; + } + } + } + if (!(entry.u.scalable.fileName = FontFileSaveString (fileName))) + return FALSE; + extra = malloc (sizeof (FontScalableExtraRec)); + if (!extra) + { + free (entry.u.scalable.fileName); + return FALSE; + } + bzero((char *)&extra->defaults, sizeof(extra->defaults)); + if ((vals.values_supplied & POINTSIZE_MASK) == POINTSIZE_SCALAR && + (int)(vals.point_matrix[3] * 10) == GetDefaultPointSize()) + extra->defaults = vals; + else + { + FontResolutionPtr resolution; + int num; + int default_point_size = GetDefaultPointSize(); + + extra->defaults.point_matrix[0] = + extra->defaults.point_matrix[3] = + (double)default_point_size / 10.0; + extra->defaults.point_matrix[1] = + extra->defaults.point_matrix[2] = 0.0; + extra->defaults.values_supplied = + POINTSIZE_SCALAR | PIXELSIZE_UNDEFINED; + extra->defaults.width = -1; + if (vals.x <= 0 || vals.y <= 0) + { + resolution = GetClientResolutions (&num); + if (resolution && num > 0) + { + extra->defaults.x = resolution->x_resolution; + extra->defaults.y = resolution->y_resolution; + } + else + { + extra->defaults.x = 75; + extra->defaults.y = 75; + } + } + else + { + extra->defaults.x = vals.x; + extra->defaults.y = vals.y; + } + FontFileCompleteXLFD (&extra->defaults, &extra->defaults); + } + extra->numScaled = 0; + extra->sizeScaled = 0; + extra->scaled = 0; + extra->private = 0; + entry.type = FONT_ENTRY_SCALABLE; + entry.u.scalable.renderer = renderer; + entry.u.scalable.extra = extra; + if (!(scalable = FontFileAddEntry (&dir->scalable, &entry))) + { + free (extra); + free (entry.u.scalable.fileName); + return FALSE; + } + if (vals.values_supplied & SIZE_SPECIFY_MASK) + { + if(bitmap) + { + FontFileCompleteXLFD(&vals, &vals); + FontFileAddScaledInstance (scalable, &vals, NullFont, + bitmap->name.name); + } + } + } + return TRUE; +} + +Bool +FontFileAddFontAlias (FontDirectoryPtr dir, char *aliasName, char *fontName) +{ + FontEntryRec entry; + + if (strcmp(aliasName,fontName) == 0) { + /* Don't allow an alias to point to itself and create a loop */ + return FALSE; + } + entry.name.length = strlen (aliasName); + CopyISOLatin1Lowered (aliasName, aliasName, entry.name.length); + entry.name.name = aliasName; + entry.name.ndashes = FontFileCountDashes (entry.name.name, entry.name.length); + entry.type = FONT_ENTRY_ALIAS; + if (!(entry.u.alias.resolved = FontFileSaveString (fontName))) + return FALSE; + if (!FontFileAddEntry (&dir->nonScalable, &entry)) + { + free (entry.u.alias.resolved); + return FALSE; + } + return TRUE; +} diff --git a/libXfont/src/fontfile/fontencc.c b/libXfont/src/fontfile/fontencc.c index ea91cd615..79977851d 100644 --- a/libXfont/src/fontfile/fontencc.c +++ b/libXfont/src/fontfile/fontencc.c @@ -1,76 +1,76 @@ -/*
-Copyright (c) 1998-2001 by Juliusz Chroboczek
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-/* Binary compatibility code. */
-
-/* This file includes code to make modules compiled for earlier
- versions of the fontenc interfaces link with this one. It does
- *not* provide source compatibility, as many of the data structures
- now have different names. */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/fonts/fontenc.h>
-#include <X11/fonts/fontencc.h>
-
-extern void ErrorF(const char *f, ...);
-
-char *
-font_encoding_from_xlfd(const char * name, int length)
-{
- return FontEncFromXLFD(name, length);
-}
-
-FontEncPtr
-font_encoding_find(const char *encoding_name, const char *filename)
-{
- return FontEncFind(encoding_name, filename);
-}
-
-unsigned
-font_encoding_recode(unsigned code,
- FontEncPtr encoding, FontMapPtr mapping)
-{
- if(encoding != mapping->encoding) {
- ErrorF("Inconsistent mapping/encoding\n");
- return 0;
- }
- return FontEncRecode(code, mapping);
-}
-
-char *
-font_encoding_name(unsigned code,
- FontEncPtr encoding, FontMapPtr mapping)
-{
- if(encoding != mapping->encoding) {
- ErrorF("Inconsistent mapping/encoding\n");
- return 0;
- }
- return FontEncName(code, mapping);
-}
-
-char **
-identifyEncodingFile(const char *filename)
-{
- return FontEncIdentify(filename);
-}
+/* +Copyright (c) 1998-2001 by Juliusz Chroboczek + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/* Binary compatibility code. */ + +/* This file includes code to make modules compiled for earlier + versions of the fontenc interfaces link with this one. It does + *not* provide source compatibility, as many of the data structures + now have different names. */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/fonts/fontenc.h> +#include <X11/fonts/fontencc.h> + +extern void ErrorF(const char *f, ...); + +char * +font_encoding_from_xlfd(const char * name, int length) +{ + return FontEncFromXLFD(name, length); +} + +FontEncPtr +font_encoding_find(const char *encoding_name, const char *filename) +{ + return FontEncFind(encoding_name, filename); +} + +unsigned +font_encoding_recode(unsigned code, + FontEncPtr encoding, FontMapPtr mapping) +{ + if(encoding != mapping->encoding) { + ErrorF("Inconsistent mapping/encoding\n"); + return 0; + } + return FontEncRecode(code, mapping); +} + +char * +font_encoding_name(unsigned code, + FontEncPtr encoding, FontMapPtr mapping) +{ + if(encoding != mapping->encoding) { + ErrorF("Inconsistent mapping/encoding\n"); + return 0; + } + return FontEncName(code, mapping); +} + +char ** +identifyEncodingFile(const char *filename) +{ + return FontEncIdentify(filename); +} diff --git a/libXfont/src/fontfile/fontfile.c b/libXfont/src/fontfile/fontfile.c index 32b5097ac..7372d3ece 100644 --- a/libXfont/src/fontfile/fontfile.c +++ b/libXfont/src/fontfile/fontfile.c @@ -1,1169 +1,1169 @@ -/*
-
-Copyright 1991, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-/*
- * Author: Keith Packard, MIT X Consortium
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/fonts/fntfilst.h>
-#include <X11/keysym.h>
-#ifdef WIN32
-#include <ctype.h>
-#endif
-#ifdef _MSC_VER
-#define BOOL W32BOOL
-#include <windows.h>
-#undef _X_HIDDEN
-#define _X_HIDDEN static
-#endif
-
-static unsigned char
-ISOLatin1ToLower(unsigned char source)
-{
- if (source >= XK_A && source <= XK_Z)
- return source + (XK_a - XK_A);
- if (source >= XK_Agrave && source <= XK_Odiaeresis)
- return source + (XK_agrave - XK_Agrave);
- if (source >= XK_Ooblique && source <= XK_Thorn)
- return source + (XK_oslash - XK_Ooblique);
- return source;
-}
-
-void
-CopyISOLatin1Lowered(char *dest, char *source, int length)
-{
- int i;
- for (i = 0; i < length; i++, source++, dest++)
- *dest = ISOLatin1ToLower(*source);
- *dest = '\0';
-}
-
-/*
- * Map FPE functions to renderer functions
- */
-
-static int FontFileOpenBitmapNCF (FontPathElementPtr fpe, FontPtr *pFont,
- int flags, FontEntryPtr entry,
- fsBitmapFormat format,
- fsBitmapFormatMask fmask,
- FontPtr non_cachable_font);
-
-int
-FontFileNameCheck (char *name)
-{
-#ifdef _MSC_VER
- WIN32_FIND_DATA FindData;
- HANDLE hFind;
- char Tmp;
- int LenName=strlen(name)-1;
- Tmp=name[LenName];
- if (Tmp=='/')
- name[LenName]=0;
- hFind=FindFirstFile(name,&FindData);
- name[LenName]=Tmp;
-
- if (hFind==INVALID_HANDLE_VALUE)
- {
- return 0;
- }
- else
- {
- FindClose(hFind);
- if (FindData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
- {
- return 1;
- }
- return 0;
- }
-
-#else
-#ifndef NCD
-#if defined(WIN32)
- /* OS/2 uses D:/... as a path name for fonts, so accept this as a valid
- * path if it starts with a letter and a colon. Same applies for WIN32
- */
- if (isalpha(*name) && name[1]==':')
- return TRUE;
-#endif
- return *name == '/';
-#else
- return ((strcmp(name, "built-ins") == 0) || (*name == '/'));
-#endif
-#endif
-}
-
-int
-FontFileInitFPE (FontPathElementPtr fpe)
-{
- int status;
- FontDirectoryPtr dir;
-
- status = FontFileReadDirectory (fpe->name, &dir);
- if (status == Successful)
- {
- if (dir->nonScalable.used > 0)
- if (!FontFileRegisterBitmapSource (fpe))
- {
- FontFileFreeFPE (fpe);
- return AllocError;
- }
- fpe->private = (pointer) dir;
- }
- return status;
-}
-
-/* ARGSUSED */
-int
-FontFileResetFPE (FontPathElementPtr fpe)
-{
- FontDirectoryPtr dir;
-
- dir = (FontDirectoryPtr) fpe->private;
- /*
- * The reset must fail for bitmap fonts because they get cleared when
- * the path is set.
- */
- if (FontFileDirectoryChanged (dir))
- {
- /* can't do it, so tell the caller to close and re-open */
- return FPEResetFailed;
- }
- else
- {
- if (dir->nonScalable.used > 0)
- if (!FontFileRegisterBitmapSource (fpe))
- {
- return FPEResetFailed;
- }
- return Successful;
- }
-}
-
-int
-FontFileFreeFPE (FontPathElementPtr fpe)
-{
- FontFileUnregisterBitmapSource (fpe);
- FontFileFreeDir ((FontDirectoryPtr) fpe->private);
- return Successful;
-}
-
-static int
-transfer_values_to_alias(char *entryname, int entrynamelength,
- char *resolvedname,
- char **aliasName, FontScalablePtr vals)
-{
- static char aliasname[MAXFONTNAMELEN];
- int nameok = 1, len;
- char lowerName[MAXFONTNAMELEN];
-
- *aliasName = resolvedname;
- if ((len = strlen(*aliasName)) <= MAXFONTNAMELEN &&
- (entrynamelength < MAXFONTNAMELEN) &&
- FontFileCountDashes (*aliasName, len) == 14)
- {
- FontScalableRec tmpVals;
- FontScalableRec tmpVals2;
-
- tmpVals2 = *vals;
-
- /* If we're aliasing a scalable name, transfer values
- from the name into the destination alias, multiplying
- by matrices that appear in the alias. */
-
- CopyISOLatin1Lowered (lowerName, entryname,
- entrynamelength);
- lowerName[entrynamelength] = '\0';
-
- if (FontParseXLFDName(lowerName, &tmpVals,
- FONT_XLFD_REPLACE_NONE) &&
- !tmpVals.values_supplied &&
- FontParseXLFDName(*aliasName, &tmpVals,
- FONT_XLFD_REPLACE_NONE))
- {
- double *matrix = 0, tempmatrix[4];
-
- /* Use a matrix iff exactly one is defined */
- if ((tmpVals.values_supplied & PIXELSIZE_MASK) ==
- PIXELSIZE_ARRAY &&
- !(tmpVals.values_supplied & POINTSIZE_MASK))
- matrix = tmpVals.pixel_matrix;
- else if ((tmpVals.values_supplied & POINTSIZE_MASK) ==
- POINTSIZE_ARRAY &&
- !(tmpVals.values_supplied & PIXELSIZE_MASK))
- matrix = tmpVals.point_matrix;
-
- /* If matrix given in the alias, compute new point
- and/or pixel matrices */
- if (matrix)
- {
- /* Complete the XLFD name to avoid potential
- gotchas */
- if (FontFileCompleteXLFD(&tmpVals2, &tmpVals2))
- {
- tempmatrix[0] =
- matrix[0] * tmpVals2.point_matrix[0] +
- matrix[1] * tmpVals2.point_matrix[2];
- tempmatrix[1] =
- matrix[0] * tmpVals2.point_matrix[1] +
- matrix[1] * tmpVals2.point_matrix[3];
- tempmatrix[2] =
- matrix[2] * tmpVals2.point_matrix[0] +
- matrix[3] * tmpVals2.point_matrix[2];
- tempmatrix[3] =
- matrix[2] * tmpVals2.point_matrix[1] +
- matrix[3] * tmpVals2.point_matrix[3];
- tmpVals2.point_matrix[0] = tempmatrix[0];
- tmpVals2.point_matrix[1] = tempmatrix[1];
- tmpVals2.point_matrix[2] = tempmatrix[2];
- tmpVals2.point_matrix[3] = tempmatrix[3];
-
- tempmatrix[0] =
- matrix[0] * tmpVals2.pixel_matrix[0] +
- matrix[1] * tmpVals2.pixel_matrix[2];
- tempmatrix[1] =
- matrix[0] * tmpVals2.pixel_matrix[1] +
- matrix[1] * tmpVals2.pixel_matrix[3];
- tempmatrix[2] =
- matrix[2] * tmpVals2.pixel_matrix[0] +
- matrix[3] * tmpVals2.pixel_matrix[2];
- tempmatrix[3] =
- matrix[2] * tmpVals2.pixel_matrix[1] +
- matrix[3] * tmpVals2.pixel_matrix[3];
- tmpVals2.pixel_matrix[0] = tempmatrix[0];
- tmpVals2.pixel_matrix[1] = tempmatrix[1];
- tmpVals2.pixel_matrix[2] = tempmatrix[2];
- tmpVals2.pixel_matrix[3] = tempmatrix[3];
-
- tmpVals2.values_supplied =
- (tmpVals2.values_supplied &
- ~(PIXELSIZE_MASK | POINTSIZE_MASK)) |
- PIXELSIZE_ARRAY | POINTSIZE_ARRAY;
- }
- else
- nameok = 0;
- }
-
- CopyISOLatin1Lowered (aliasname, *aliasName, len + 1);
- if (nameok && FontParseXLFDName(aliasname, &tmpVals2,
- FONT_XLFD_REPLACE_VALUE))
- /* Return a version of the aliasname that has
- had the vals stuffed into it. To avoid
- memory leak, this alias name lives in a
- static buffer. The caller needs to be done
- with this buffer before this procedure is
- called again to avoid reentrancy problems. */
- *aliasName = aliasname;
- }
- }
- return nameok;
-}
-
-/* ARGSUSED */
-int
-FontFileOpenFont (pointer client, FontPathElementPtr fpe, Mask flags,
- char *name, int namelen,
- fsBitmapFormat format, fsBitmapFormatMask fmask,
- XID id, FontPtr *pFont, char **aliasName,
- FontPtr non_cachable_font)
-{
- FontDirectoryPtr dir;
- char lowerName[MAXFONTNAMELEN];
- char fileName[MAXFONTFILENAMELEN*2 + 1];
- FontNameRec tmpName;
- FontEntryPtr entry;
- FontScalableRec vals;
- FontScalableEntryPtr scalable;
- FontScaledPtr scaled;
- FontBitmapEntryPtr bitmap;
- int ret;
- Bool noSpecificSize;
- int nranges;
- fsRange *ranges;
-
- if (namelen >= MAXFONTNAMELEN)
- return AllocError;
- dir = (FontDirectoryPtr) fpe->private;
-
- /* Match non-scalable pattern */
- CopyISOLatin1Lowered (lowerName, name, namelen);
- lowerName[namelen] = '\0';
- ranges = FontParseRanges(lowerName, &nranges);
- tmpName.name = lowerName;
- tmpName.length = namelen;
- tmpName.ndashes = FontFileCountDashes (lowerName, namelen);
- if (!FontParseXLFDName(lowerName, &vals, FONT_XLFD_REPLACE_NONE))
- bzero(&vals, sizeof(vals));
- if (!(entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName)) &&
- tmpName.ndashes == 14 &&
- FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO))
- {
- tmpName.length = strlen(lowerName);
- entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName);
- }
-
- if (entry)
- {
- switch (entry->type) {
- case FONT_ENTRY_BITMAP:
- bitmap = &entry->u.bitmap;
- if (bitmap->pFont)
- {
- *pFont = bitmap->pFont;
- (*pFont)->fpe = fpe;
- ret = Successful;
- }
- else
- {
- ret = FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format,
- fmask, non_cachable_font);
- if (ret == Successful && *pFont)
- (*pFont)->fpe = fpe;
- }
- break;
- case FONT_ENTRY_ALIAS:
- vals.nranges = nranges;
- vals.ranges = ranges;
- transfer_values_to_alias(entry->name.name, entry->name.length,
- entry->u.alias.resolved, aliasName, &vals);
- ret = FontNameAlias;
- break;
- default:
- ret = BadFontName;
- }
- }
- else
- {
- ret = BadFontName;
- }
-
- if (ret != BadFontName)
- {
- if (ranges) free(ranges);
- return ret;
- }
-
- /* Match XLFD patterns */
- CopyISOLatin1Lowered (lowerName, name, namelen);
- lowerName[namelen] = '\0';
- tmpName.name = lowerName;
- tmpName.length = namelen;
- tmpName.ndashes = FontFileCountDashes (lowerName, namelen);
- if (!FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO) ||
- !(tmpName.length = strlen (lowerName),
- entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName,
- &vals))) {
- CopyISOLatin1Lowered (lowerName, name, namelen);
- lowerName[namelen] = '\0';
- tmpName.name = lowerName;
- tmpName.length = namelen;
- tmpName.ndashes = FontFileCountDashes (lowerName, namelen);
- entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals);
- if (entry)
- {
- strcpy(lowerName, entry->name.name);
- tmpName.name = lowerName;
- tmpName.length = entry->name.length;
- tmpName.ndashes = entry->name.ndashes;
- }
- }
-
- if (entry)
- {
- noSpecificSize = FALSE; /* TRUE breaks XLFD enhancements */
- if (entry->type == FONT_ENTRY_SCALABLE &&
- FontFileCompleteXLFD (&vals, &entry->u.scalable.extra->defaults))
- {
- scalable = &entry->u.scalable;
- if ((vals.values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY ||
- (vals.values_supplied & POINTSIZE_MASK) == POINTSIZE_ARRAY ||
- (vals.values_supplied &
- ~SIZE_SPECIFY_MASK & ~CHARSUBSET_SPECIFIED))
- scaled = 0;
- else
- scaled = FontFileFindScaledInstance (entry, &vals,
- noSpecificSize);
- /*
- * A scaled instance can occur one of two ways:
- *
- * Either the font has been scaled to this
- * size already, in which case scaled->pFont
- * will point at that font.
- *
- * Or a bitmap instance in this size exists,
- * which is handled as if we got a pattern
- * matching the bitmap font name.
- */
- if (scaled)
- {
- if (scaled->pFont)
- {
- *pFont = scaled->pFont;
- (*pFont)->fpe = fpe;
- ret = Successful;
- }
- else if (scaled->bitmap)
- {
- entry = scaled->bitmap;
- bitmap = &entry->u.bitmap;
- if (bitmap->pFont)
- {
- *pFont = bitmap->pFont;
- (*pFont)->fpe = fpe;
- ret = Successful;
- }
- else
- {
- ret = FontFileOpenBitmapNCF (fpe, pFont, flags, entry,
- format, fmask,
- non_cachable_font);
- if (ret == Successful && *pFont)
- (*pFont)->fpe = fpe;
- }
- }
- else /* "cannot" happen */
- {
- ret = BadFontName;
- }
- }
- else
- {
- ret = FontFileMatchBitmapSource (fpe, pFont, flags, entry, &tmpName, &vals, format, fmask, noSpecificSize);
- if (ret != Successful)
- {
- char origName[MAXFONTNAMELEN];
-
- CopyISOLatin1Lowered (origName, name, namelen);
- origName[namelen] = '\0';
-
- /* Pass the original XLFD name in the vals
- structure; the rasterizer is free to examine it
- for hidden meanings. This information will not
- be saved in the scaled-instances table. */
-
- vals.xlfdName = origName;
- vals.ranges = ranges;
- vals.nranges = nranges;
-
- if (strlen(dir->directory) + strlen(scalable->fileName) >=
- sizeof(fileName)) {
- ret = BadFontName;
- } else {
- strcpy (fileName, dir->directory);
- strcat (fileName, scalable->fileName);
- if (scalable->renderer->OpenScalable) {
- ret = (*scalable->renderer->OpenScalable) (fpe, pFont,
- flags, entry, fileName, &vals, format, fmask,
- non_cachable_font);
- }
- else if (scalable->renderer->OpenBitmap) {
- ret = (*scalable->renderer->OpenBitmap) (fpe, pFont,
- flags, entry, fileName, format, fmask,
- non_cachable_font);
- }
- }
-
- /* In case rasterizer does something bad because of
- charset subsetting... */
- if (ret == Successful &&
- ((*pFont)->info.firstCol > (*pFont)->info.lastCol ||
- (*pFont)->info.firstRow > (*pFont)->info.lastRow))
- {
- (*(*pFont)->unload_font)(*pFont);
- ret = BadFontName;
- }
- /* Save the instance */
- if (ret == Successful)
- {
- if (FontFileAddScaledInstance (entry, &vals,
- *pFont, (char *) 0))
- ranges = 0;
- else
- (*pFont)->fpePrivate = (pointer) 0;
- (*pFont)->fpe = fpe;
- }
- }
- }
- }
- }
- else
- ret = BadFontName;
-
- if (ranges)
- free(ranges);
- return ret;
-}
-
-/* ARGSUSED */
-void
-FontFileCloseFont (FontPathElementPtr fpe, FontPtr pFont)
-{
- FontEntryPtr entry;
-
- if ((entry = (FontEntryPtr) pFont->fpePrivate)) {
- switch (entry->type) {
- case FONT_ENTRY_SCALABLE:
- FontFileRemoveScaledInstance (entry, pFont);
- break;
- case FONT_ENTRY_BITMAP:
- entry->u.bitmap.pFont = 0;
- break;
- default:
- /* "cannot" happen */
- break;
- }
- pFont->fpePrivate = 0;
- }
- (*pFont->unload_font) (pFont);
-}
-
-static int
-FontFileOpenBitmapNCF (FontPathElementPtr fpe, FontPtr *pFont,
- int flags, FontEntryPtr entry,
- fsBitmapFormat format, fsBitmapFormatMask fmask,
- FontPtr non_cachable_font)
-{
- FontBitmapEntryPtr bitmap;
- char fileName[MAXFONTFILENAMELEN*2+1];
- int ret;
- FontDirectoryPtr dir;
-
- dir = (FontDirectoryPtr) fpe->private;
- bitmap = &entry->u.bitmap;
- if(!bitmap || !bitmap->renderer->OpenBitmap)
- return BadFontName;
- if (strlen(dir->directory) + strlen(bitmap->fileName) >= sizeof(fileName))
- return BadFontName;
- strcpy (fileName, dir->directory);
- strcat (fileName, bitmap->fileName);
- ret = (*bitmap->renderer->OpenBitmap)
- (fpe, pFont, flags, entry, fileName, format, fmask,
- non_cachable_font);
- if (ret == Successful)
- {
- bitmap->pFont = *pFont;
- (*pFont)->fpePrivate = (pointer) entry;
- }
- return ret;
-}
-
-int
-FontFileOpenBitmap (FontPathElementPtr fpe, FontPtr *pFont,
- int flags, FontEntryPtr entry,
- fsBitmapFormat format, fsBitmapFormatMask fmask)
-{
- return FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask,
- (FontPtr)0);
-}
-
-static int
-FontFileGetInfoBitmap (FontPathElementPtr fpe, FontInfoPtr pFontInfo,
- FontEntryPtr entry)
-{
- FontBitmapEntryPtr bitmap;
- char fileName[MAXFONTFILENAMELEN*2+1];
- int ret;
- FontDirectoryPtr dir;
-
- dir = (FontDirectoryPtr) fpe->private;
- bitmap = &entry->u.bitmap;
- if (!bitmap || !bitmap->renderer->GetInfoBitmap)
- return BadFontName;
- if (strlen(dir->directory) + strlen(bitmap->fileName) >= sizeof(fileName))
- return BadFontName;
- strcpy (fileName, dir->directory);
- strcat (fileName, bitmap->fileName);
- ret = (*bitmap->renderer->GetInfoBitmap) (fpe, pFontInfo, entry, fileName);
- return ret;
-}
-
-static void
-_FontFileAddScalableNames(FontNamesPtr names, FontNamesPtr scaleNames,
- FontNamePtr nameptr, char *zeroChars,
- FontScalablePtr vals, fsRange *ranges,
- int nranges, int *max)
-{
- int i;
- FontScalableRec zeroVals, tmpVals;
- for (i = 0; i < scaleNames->nnames; i++)
- {
- char nameChars[MAXFONTNAMELEN];
- if (!*max)
- return;
- FontParseXLFDName (scaleNames->names[i], &zeroVals,
- FONT_XLFD_REPLACE_NONE);
- tmpVals = *vals;
- if (FontFileCompleteXLFD (&tmpVals, &zeroVals))
- {
- --*max;
-
- strcpy (nameChars, scaleNames->names[i]);
- if ((vals->values_supplied & PIXELSIZE_MASK) ||
- !(vals->values_supplied & PIXELSIZE_WILDCARD) ||
- vals->y == 0)
- {
- tmpVals.values_supplied =
- (tmpVals.values_supplied & ~PIXELSIZE_MASK) |
- (vals->values_supplied & PIXELSIZE_MASK);
- tmpVals.pixel_matrix[0] = vals->pixel_matrix[0];
- tmpVals.pixel_matrix[1] = vals->pixel_matrix[1];
- tmpVals.pixel_matrix[2] = vals->pixel_matrix[2];
- tmpVals.pixel_matrix[3] = vals->pixel_matrix[3];
- }
- if ((vals->values_supplied & POINTSIZE_MASK) ||
- !(vals->values_supplied & POINTSIZE_WILDCARD) ||
- vals->y == 0)
- {
- tmpVals.values_supplied =
- (tmpVals.values_supplied & ~POINTSIZE_MASK) |
- (vals->values_supplied & POINTSIZE_MASK);
- tmpVals.point_matrix[0] = vals->point_matrix[0];
- tmpVals.point_matrix[1] = vals->point_matrix[1];
- tmpVals.point_matrix[2] = vals->point_matrix[2];
- tmpVals.point_matrix[3] = vals->point_matrix[3];
- }
- if (vals->width <= 0)
- tmpVals.width = 0;
- if (vals->x == 0)
- tmpVals.x = 0;
- if (vals->y == 0)
- tmpVals.y = 0;
- tmpVals.ranges = ranges;
- tmpVals.nranges = nranges;
- FontParseXLFDName (nameChars, &tmpVals,
- FONT_XLFD_REPLACE_VALUE);
- /* If we're marking aliases with negative lengths, we
- need to concoct a valid target name to follow it.
- Otherwise we're done. */
- if (scaleNames->length[i] >= 0)
- {
- (void) AddFontNamesName (names, nameChars,
- strlen (nameChars));
- /* If our original pattern matches the name from
- the table and that name doesn't duplicate what
- we just added, add the name from the table */
- if (strcmp(nameChars, scaleNames->names[i]) &&
- FontFileMatchName(scaleNames->names[i],
- scaleNames->length[i],
- nameptr) &&
- *max)
- {
- --*max;
- (void) AddFontNamesName (names, scaleNames->names[i],
- scaleNames->length[i]);
- }
- }
- else
- {
- char *aliasName;
- vals->ranges = ranges;
- vals->nranges = nranges;
- if (transfer_values_to_alias(zeroChars,
- strlen(zeroChars),
- scaleNames->names[++i],
- &aliasName, vals))
- {
- (void) AddFontNamesName (names, nameChars,
- strlen (nameChars));
- names->length[names->nnames - 1] =
- -names->length[names->nnames - 1];
- (void) AddFontNamesName (names, aliasName,
- strlen (aliasName));
- /* If our original pattern matches the name from
- the table and that name doesn't duplicate what
- we just added, add the name from the table */
- if (strcmp(nameChars, scaleNames->names[i - 1]) &&
- FontFileMatchName(scaleNames->names[i - 1],
- -scaleNames->length[i - 1],
- nameptr) &&
- *max)
- {
- --*max;
- (void) AddFontNamesName (names,
- scaleNames->names[i - 1],
- -scaleNames->length[i - 1]);
- names->length[names->nnames - 1] =
- -names->length[names->nnames - 1];
- (void) AddFontNamesName (names, aliasName,
- strlen (aliasName));
- }
- }
- }
- }
- }
-}
-
-/* ARGSUSED */
-static int
-_FontFileListFonts (pointer client, FontPathElementPtr fpe,
- char *pat, int len, int max, FontNamesPtr names,
- int mark_aliases)
-{
- FontDirectoryPtr dir;
- char lowerChars[MAXFONTNAMELEN], zeroChars[MAXFONTNAMELEN];
- FontNameRec lowerName;
- FontNameRec zeroName;
- FontNamesPtr scaleNames;
- FontScalableRec vals;
- fsRange *ranges;
- int nranges;
- int result = BadFontName;
-
- if (len >= MAXFONTNAMELEN)
- return AllocError;
- dir = (FontDirectoryPtr) fpe->private;
- CopyISOLatin1Lowered (lowerChars, pat, len);
- lowerChars[len] = '\0';
- lowerName.name = lowerChars;
- lowerName.length = len;
- lowerName.ndashes = FontFileCountDashes (lowerChars, len);
-
- /* Match XLFD patterns */
-
- strcpy (zeroChars, lowerChars);
- if (lowerName.ndashes == 14 &&
- FontParseXLFDName (zeroChars, &vals, FONT_XLFD_REPLACE_ZERO))
- {
- ranges = FontParseRanges(lowerChars, &nranges);
- result = FontFileFindNamesInScalableDir (&dir->nonScalable,
- &lowerName, max, names,
- (FontScalablePtr)0,
- (mark_aliases ?
- LIST_ALIASES_AND_TARGET_NAMES :
- NORMAL_ALIAS_BEHAVIOR) |
- IGNORE_SCALABLE_ALIASES,
- &max);
- zeroName.name = zeroChars;
- zeroName.length = strlen (zeroChars);
- zeroName.ndashes = lowerName.ndashes;
-
- /* Look for scalable names and aliases, adding scaled instances of
- them to the output */
-
- /* Scalable names... */
- scaleNames = MakeFontNamesRecord (0);
- if (!scaleNames)
- {
- if (ranges) free(ranges);
- return AllocError;
- }
- FontFileFindNamesInScalableDir (&dir->scalable, &zeroName, max,
- scaleNames, &vals,
- mark_aliases ?
- LIST_ALIASES_AND_TARGET_NAMES :
- NORMAL_ALIAS_BEHAVIOR, (int *)0);
- _FontFileAddScalableNames(names, scaleNames, &lowerName,
- zeroChars, &vals, ranges, nranges,
- &max);
- FreeFontNames (scaleNames);
-
- /* Scalable aliases... */
- scaleNames = MakeFontNamesRecord (0);
- if (!scaleNames)
- {
- if (ranges) free(ranges);
- return AllocError;
- }
- FontFileFindNamesInScalableDir (&dir->nonScalable, &zeroName,
- max, scaleNames, &vals,
- mark_aliases ?
- LIST_ALIASES_AND_TARGET_NAMES :
- NORMAL_ALIAS_BEHAVIOR, (int *)0);
- _FontFileAddScalableNames(names, scaleNames, &lowerName,
- zeroChars, &vals, ranges, nranges,
- &max);
- FreeFontNames (scaleNames);
-
- if (ranges) free(ranges);
- }
- else
- {
- result = FontFileFindNamesInScalableDir (&dir->nonScalable,
- &lowerName, max, names,
- (FontScalablePtr)0,
- mark_aliases ?
- LIST_ALIASES_AND_TARGET_NAMES :
- NORMAL_ALIAS_BEHAVIOR,
- &max);
- if (result == Successful)
- result = FontFileFindNamesInScalableDir (&dir->scalable,
- &lowerName, max, names,
- (FontScalablePtr)0,
- mark_aliases ?
- LIST_ALIASES_AND_TARGET_NAMES :
- NORMAL_ALIAS_BEHAVIOR, (int *)0);
- }
- return result;
-}
-
-typedef struct _LFWIData {
- FontNamesPtr names;
- int current;
-} LFWIDataRec, *LFWIDataPtr;
-
-int
-FontFileListFonts (pointer client, FontPathElementPtr fpe, char *pat,
- int len, int max, FontNamesPtr names)
-{
- return _FontFileListFonts (client, fpe, pat, len, max, names, 0);
-}
-
-int
-FontFileStartListFonts(pointer client, FontPathElementPtr fpe,
- char *pat, int len, int max,
- pointer *privatep, int mark_aliases)
-{
- LFWIDataPtr data;
- int ret;
-
- data = malloc (sizeof *data);
- if (!data)
- return AllocError;
- data->names = MakeFontNamesRecord (0);
- if (!data->names)
- {
- free (data);
- return AllocError;
- }
- ret = _FontFileListFonts (client, fpe, pat, len,
- max, data->names, mark_aliases);
- if (ret != Successful)
- {
- FreeFontNames (data->names);
- free (data);
- return ret;
- }
- data->current = 0;
- *privatep = (pointer) data;
- return Successful;
-}
-
-
-int
-FontFileStartListFontsWithInfo(pointer client, FontPathElementPtr fpe,
- char *pat, int len, int max,
- pointer *privatep)
-{
- return FontFileStartListFonts(client, fpe, pat, len, max, privatep, 0);
-}
-
-/* ARGSUSED */
-static int
-FontFileListOneFontWithInfo (pointer client, FontPathElementPtr fpe,
- char **namep, int *namelenp,
- FontInfoPtr *pFontInfo)
-{
- FontDirectoryPtr dir;
- char lowerName[MAXFONTNAMELEN];
- char fileName[MAXFONTFILENAMELEN*2 + 1];
- FontNameRec tmpName;
- FontEntryPtr entry;
- FontScalableRec vals;
- FontScalableEntryPtr scalable;
- FontScaledPtr scaled;
- FontBitmapEntryPtr bitmap;
- int ret;
- Bool noSpecificSize;
- int nranges;
- fsRange *ranges;
-
- char *name = *namep;
- int namelen = *namelenp;
-
- if (namelen >= MAXFONTNAMELEN)
- return AllocError;
- dir = (FontDirectoryPtr) fpe->private;
-
- /* Match non-scalable pattern */
- CopyISOLatin1Lowered (lowerName, name, namelen);
- lowerName[namelen] = '\0';
- ranges = FontParseRanges(lowerName, &nranges);
- tmpName.name = lowerName;
- tmpName.length = namelen;
- tmpName.ndashes = FontFileCountDashes (lowerName, namelen);
- if (!FontParseXLFDName(lowerName, &vals, FONT_XLFD_REPLACE_NONE))
- bzero(&vals, sizeof(vals));
- if (!(entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName)) &&
- tmpName.ndashes == 14 &&
- FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO))
- {
- tmpName.length = strlen(lowerName);
- entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName);
- }
-
- if (entry)
- {
- switch (entry->type) {
- case FONT_ENTRY_BITMAP:
- bitmap = &entry->u.bitmap;
- if (bitmap->pFont)
- {
- *pFontInfo = &bitmap->pFont->info;
- ret = Successful;
- }
- else
- {
- ret = FontFileGetInfoBitmap (fpe, *pFontInfo, entry);
- }
- break;
- case FONT_ENTRY_ALIAS:
- vals.nranges = nranges;
- vals.ranges = ranges;
- transfer_values_to_alias(entry->name.name, entry->name.length,
- entry->u.alias.resolved, namep, &vals);
- *namelenp = strlen (*namep);
- ret = FontNameAlias;
- break;
- default:
- ret = BadFontName;
- }
- }
- else
- {
- ret = BadFontName;
- }
-
- if (ret != BadFontName)
- {
- if (ranges) free(ranges);
- return ret;
- }
-
- /* Match XLFD patterns */
- CopyISOLatin1Lowered (lowerName, name, namelen);
- lowerName[namelen] = '\0';
- tmpName.name = lowerName;
- tmpName.length = namelen;
- tmpName.ndashes = FontFileCountDashes (lowerName, namelen);
- if (!FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO) ||
- !(tmpName.length = strlen (lowerName),
- entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName,
- &vals))) {
- CopyISOLatin1Lowered (lowerName, name, namelen);
- lowerName[namelen] = '\0';
- tmpName.name = lowerName;
- tmpName.length = namelen;
- tmpName.ndashes = FontFileCountDashes (lowerName, namelen);
- entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals);
- if (entry)
- {
- strcpy(lowerName, entry->name.name);
- tmpName.name = lowerName;
- tmpName.length = entry->name.length;
- tmpName.ndashes = entry->name.ndashes;
- }
- }
-
- if (entry)
- {
- noSpecificSize = FALSE; /* TRUE breaks XLFD enhancements */
- if (entry && entry->type == FONT_ENTRY_SCALABLE &&
- FontFileCompleteXLFD (&vals, &entry->u.scalable.extra->defaults))
- {
- scalable = &entry->u.scalable;
- scaled = FontFileFindScaledInstance (entry, &vals, noSpecificSize);
- /*
- * A scaled instance can occur one of two ways:
- *
- * Either the font has been scaled to this
- * size already, in which case scaled->pFont
- * will point at that font.
- *
- * Or a bitmap instance in this size exists,
- * which is handled as if we got a pattern
- * matching the bitmap font name.
- */
- if (scaled)
- {
- if (scaled->pFont)
- {
- *pFontInfo = &scaled->pFont->info;
- ret = Successful;
- }
- else if (scaled->bitmap)
- {
- entry = scaled->bitmap;
- bitmap = &entry->u.bitmap;
- if (bitmap->pFont)
- {
- *pFontInfo = &bitmap->pFont->info;
- ret = Successful;
- }
- else
- {
- ret = FontFileGetInfoBitmap (fpe, *pFontInfo, entry);
- }
- }
- else /* "cannot" happen */
- {
- ret = BadFontName;
- }
- }
- else
- {
- {
- char origName[MAXFONTNAMELEN];
-
- CopyISOLatin1Lowered (origName, name, namelen);
- origName[namelen] = '\0';
- vals.xlfdName = origName;
- vals.ranges = ranges;
- vals.nranges = nranges;
-
- /* Make a new scaled instance */
- if (strlen(dir->directory) + strlen(scalable->fileName) >=
- sizeof(fileName)) {
- ret = BadFontName;
- } else {
- strcpy (fileName, dir->directory);
- strcat (fileName, scalable->fileName);
- if (scalable->renderer->GetInfoScalable)
- ret = (*scalable->renderer->GetInfoScalable)
- (fpe, *pFontInfo, entry, &tmpName, fileName,
- &vals);
- else if (scalable->renderer->GetInfoBitmap)
- ret = (*scalable->renderer->GetInfoBitmap)
- (fpe, *pFontInfo, entry, fileName);
- }
- if (ranges) {
- free(ranges);
- ranges = NULL;
- }
- }
- }
- if (ret == Successful) return ret;
- }
- CopyISOLatin1Lowered (lowerName, name, namelen);
- tmpName.length = namelen;
- }
- else
- ret = BadFontName;
-
- if (ranges)
- free(ranges);
- return ret;
-}
-
-int
-FontFileListNextFontWithInfo(pointer client, FontPathElementPtr fpe,
- char **namep, int *namelenp,
- FontInfoPtr *pFontInfo,
- int *numFonts, pointer private)
-{
- LFWIDataPtr data = (LFWIDataPtr) private;
- int ret;
- char *name;
- int namelen;
-
- if (data->current == data->names->nnames)
- {
- FreeFontNames (data->names);
- free (data);
- return BadFontName;
- }
- name = data->names->names[data->current];
- namelen = data->names->length[data->current];
- ret = FontFileListOneFontWithInfo (client, fpe, &name, &namelen, pFontInfo);
- if (ret == BadFontName)
- ret = AllocError;
- *namep = name;
- *namelenp = namelen;
- ++data->current;
- *numFonts = data->names->nnames - data->current;
- return ret;
-}
-
-int
-FontFileStartListFontsAndAliases(pointer client, FontPathElementPtr fpe,
- char *pat, int len, int max,
- pointer *privatep)
-{
- return FontFileStartListFonts(client, fpe, pat, len, max, privatep, 1);
-}
-
-int
-FontFileListNextFontOrAlias(pointer client, FontPathElementPtr fpe,
- char **namep, int *namelenp, char **resolvedp,
- int *resolvedlenp, pointer private)
-{
- LFWIDataPtr data = (LFWIDataPtr) private;
- int ret;
- char *name;
- int namelen;
-
- if (data->current == data->names->nnames)
- {
- FreeFontNames (data->names);
- free (data);
- return BadFontName;
- }
- name = data->names->names[data->current];
- namelen = data->names->length[data->current];
-
- /* If this is a real font name... */
- if (namelen >= 0)
- {
- *namep = name;
- *namelenp = namelen;
- ret = Successful;
- }
- /* Else if an alias */
- else
- {
- /* Tell the caller that this is an alias... let him resolve it to
- see if it's valid */
- *namep = name;
- *namelenp = -namelen;
- *resolvedp = data->names->names[++data->current];
- *resolvedlenp = data->names->length[data->current];
- ret = FontNameAlias;
- }
-
- ++data->current;
- return ret;
-}
-
-void
-FontFileRegisterLocalFpeFunctions (void)
-{
- RegisterFPEFunctions(FontFileNameCheck,
- FontFileInitFPE,
- FontFileFreeFPE,
- FontFileResetFPE,
- FontFileOpenFont,
- FontFileCloseFont,
- FontFileListFonts,
- FontFileStartListFontsWithInfo,
- FontFileListNextFontWithInfo,
- NULL,
- NULL,
- NULL,
- FontFileStartListFontsAndAliases,
- FontFileListNextFontOrAlias,
- FontFileEmptyBitmapSource);
-}
+/* + +Copyright 1991, 1998 The Open Group + +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. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ + +/* + * Author: Keith Packard, MIT X Consortium + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/fonts/fntfilst.h> +#include <X11/keysym.h> +#ifdef WIN32 +#include <ctype.h> +#endif +#ifdef _MSC_VER +#define BOOL W32BOOL +#include <windows.h> +#undef _X_HIDDEN +#define _X_HIDDEN static +#endif + +static unsigned char +ISOLatin1ToLower(unsigned char source) +{ + if (source >= XK_A && source <= XK_Z) + return source + (XK_a - XK_A); + if (source >= XK_Agrave && source <= XK_Odiaeresis) + return source + (XK_agrave - XK_Agrave); + if (source >= XK_Ooblique && source <= XK_Thorn) + return source + (XK_oslash - XK_Ooblique); + return source; +} + +void +CopyISOLatin1Lowered(char *dest, char *source, int length) +{ + int i; + for (i = 0; i < length; i++, source++, dest++) + *dest = ISOLatin1ToLower(*source); + *dest = '\0'; +} + +/* + * Map FPE functions to renderer functions + */ + +static int FontFileOpenBitmapNCF (FontPathElementPtr fpe, FontPtr *pFont, + int flags, FontEntryPtr entry, + fsBitmapFormat format, + fsBitmapFormatMask fmask, + FontPtr non_cachable_font); + +int +FontFileNameCheck (char *name) +{ +#ifdef _MSC_VER + WIN32_FIND_DATA FindData; + HANDLE hFind; + char Tmp; + int LenName=strlen(name)-1; + Tmp=name[LenName]; + if (Tmp=='/') + name[LenName]=0; + hFind=FindFirstFile(name,&FindData); + name[LenName]=Tmp; + + if (hFind==INVALID_HANDLE_VALUE) + { + return 0; + } + else + { + FindClose(hFind); + if (FindData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) + { + return 1; + } + return 0; + } + +#else +#ifndef NCD +#if defined(WIN32) + /* OS/2 uses D:/... as a path name for fonts, so accept this as a valid + * path if it starts with a letter and a colon. Same applies for WIN32 + */ + if (isalpha(*name) && name[1]==':') + return TRUE; +#endif + return *name == '/'; +#else + return ((strcmp(name, "built-ins") == 0) || (*name == '/')); +#endif +#endif +} + +int +FontFileInitFPE (FontPathElementPtr fpe) +{ + int status; + FontDirectoryPtr dir; + + status = FontFileReadDirectory (fpe->name, &dir); + if (status == Successful) + { + if (dir->nonScalable.used > 0) + if (!FontFileRegisterBitmapSource (fpe)) + { + FontFileFreeFPE (fpe); + return AllocError; + } + fpe->private = (pointer) dir; + } + return status; +} + +/* ARGSUSED */ +int +FontFileResetFPE (FontPathElementPtr fpe) +{ + FontDirectoryPtr dir; + + dir = (FontDirectoryPtr) fpe->private; + /* + * The reset must fail for bitmap fonts because they get cleared when + * the path is set. + */ + if (FontFileDirectoryChanged (dir)) + { + /* can't do it, so tell the caller to close and re-open */ + return FPEResetFailed; + } + else + { + if (dir->nonScalable.used > 0) + if (!FontFileRegisterBitmapSource (fpe)) + { + return FPEResetFailed; + } + return Successful; + } +} + +int +FontFileFreeFPE (FontPathElementPtr fpe) +{ + FontFileUnregisterBitmapSource (fpe); + FontFileFreeDir ((FontDirectoryPtr) fpe->private); + return Successful; +} + +static int +transfer_values_to_alias(char *entryname, int entrynamelength, + char *resolvedname, + char **aliasName, FontScalablePtr vals) +{ + static char aliasname[MAXFONTNAMELEN]; + int nameok = 1, len; + char lowerName[MAXFONTNAMELEN]; + + *aliasName = resolvedname; + if ((len = strlen(*aliasName)) <= MAXFONTNAMELEN && + (entrynamelength < MAXFONTNAMELEN) && + FontFileCountDashes (*aliasName, len) == 14) + { + FontScalableRec tmpVals; + FontScalableRec tmpVals2; + + tmpVals2 = *vals; + + /* If we're aliasing a scalable name, transfer values + from the name into the destination alias, multiplying + by matrices that appear in the alias. */ + + CopyISOLatin1Lowered (lowerName, entryname, + entrynamelength); + lowerName[entrynamelength] = '\0'; + + if (FontParseXLFDName(lowerName, &tmpVals, + FONT_XLFD_REPLACE_NONE) && + !tmpVals.values_supplied && + FontParseXLFDName(*aliasName, &tmpVals, + FONT_XLFD_REPLACE_NONE)) + { + double *matrix = 0, tempmatrix[4]; + + /* Use a matrix iff exactly one is defined */ + if ((tmpVals.values_supplied & PIXELSIZE_MASK) == + PIXELSIZE_ARRAY && + !(tmpVals.values_supplied & POINTSIZE_MASK)) + matrix = tmpVals.pixel_matrix; + else if ((tmpVals.values_supplied & POINTSIZE_MASK) == + POINTSIZE_ARRAY && + !(tmpVals.values_supplied & PIXELSIZE_MASK)) + matrix = tmpVals.point_matrix; + + /* If matrix given in the alias, compute new point + and/or pixel matrices */ + if (matrix) + { + /* Complete the XLFD name to avoid potential + gotchas */ + if (FontFileCompleteXLFD(&tmpVals2, &tmpVals2)) + { + tempmatrix[0] = + matrix[0] * tmpVals2.point_matrix[0] + + matrix[1] * tmpVals2.point_matrix[2]; + tempmatrix[1] = + matrix[0] * tmpVals2.point_matrix[1] + + matrix[1] * tmpVals2.point_matrix[3]; + tempmatrix[2] = + matrix[2] * tmpVals2.point_matrix[0] + + matrix[3] * tmpVals2.point_matrix[2]; + tempmatrix[3] = + matrix[2] * tmpVals2.point_matrix[1] + + matrix[3] * tmpVals2.point_matrix[3]; + tmpVals2.point_matrix[0] = tempmatrix[0]; + tmpVals2.point_matrix[1] = tempmatrix[1]; + tmpVals2.point_matrix[2] = tempmatrix[2]; + tmpVals2.point_matrix[3] = tempmatrix[3]; + + tempmatrix[0] = + matrix[0] * tmpVals2.pixel_matrix[0] + + matrix[1] * tmpVals2.pixel_matrix[2]; + tempmatrix[1] = + matrix[0] * tmpVals2.pixel_matrix[1] + + matrix[1] * tmpVals2.pixel_matrix[3]; + tempmatrix[2] = + matrix[2] * tmpVals2.pixel_matrix[0] + + matrix[3] * tmpVals2.pixel_matrix[2]; + tempmatrix[3] = + matrix[2] * tmpVals2.pixel_matrix[1] + + matrix[3] * tmpVals2.pixel_matrix[3]; + tmpVals2.pixel_matrix[0] = tempmatrix[0]; + tmpVals2.pixel_matrix[1] = tempmatrix[1]; + tmpVals2.pixel_matrix[2] = tempmatrix[2]; + tmpVals2.pixel_matrix[3] = tempmatrix[3]; + + tmpVals2.values_supplied = + (tmpVals2.values_supplied & + ~(PIXELSIZE_MASK | POINTSIZE_MASK)) | + PIXELSIZE_ARRAY | POINTSIZE_ARRAY; + } + else + nameok = 0; + } + + CopyISOLatin1Lowered (aliasname, *aliasName, len + 1); + if (nameok && FontParseXLFDName(aliasname, &tmpVals2, + FONT_XLFD_REPLACE_VALUE)) + /* Return a version of the aliasname that has + had the vals stuffed into it. To avoid + memory leak, this alias name lives in a + static buffer. The caller needs to be done + with this buffer before this procedure is + called again to avoid reentrancy problems. */ + *aliasName = aliasname; + } + } + return nameok; +} + +/* ARGSUSED */ +int +FontFileOpenFont (pointer client, FontPathElementPtr fpe, Mask flags, + char *name, int namelen, + fsBitmapFormat format, fsBitmapFormatMask fmask, + XID id, FontPtr *pFont, char **aliasName, + FontPtr non_cachable_font) +{ + FontDirectoryPtr dir; + char lowerName[MAXFONTNAMELEN]; + char fileName[MAXFONTFILENAMELEN*2 + 1]; + FontNameRec tmpName; + FontEntryPtr entry; + FontScalableRec vals; + FontScalableEntryPtr scalable; + FontScaledPtr scaled; + FontBitmapEntryPtr bitmap; + int ret; + Bool noSpecificSize; + int nranges; + fsRange *ranges; + + if (namelen >= MAXFONTNAMELEN) + return AllocError; + dir = (FontDirectoryPtr) fpe->private; + + /* Match non-scalable pattern */ + CopyISOLatin1Lowered (lowerName, name, namelen); + lowerName[namelen] = '\0'; + ranges = FontParseRanges(lowerName, &nranges); + tmpName.name = lowerName; + tmpName.length = namelen; + tmpName.ndashes = FontFileCountDashes (lowerName, namelen); + if (!FontParseXLFDName(lowerName, &vals, FONT_XLFD_REPLACE_NONE)) + bzero(&vals, sizeof(vals)); + if (!(entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName)) && + tmpName.ndashes == 14 && + FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO)) + { + tmpName.length = strlen(lowerName); + entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName); + } + + if (entry) + { + switch (entry->type) { + case FONT_ENTRY_BITMAP: + bitmap = &entry->u.bitmap; + if (bitmap->pFont) + { + *pFont = bitmap->pFont; + (*pFont)->fpe = fpe; + ret = Successful; + } + else + { + ret = FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, + fmask, non_cachable_font); + if (ret == Successful && *pFont) + (*pFont)->fpe = fpe; + } + break; + case FONT_ENTRY_ALIAS: + vals.nranges = nranges; + vals.ranges = ranges; + transfer_values_to_alias(entry->name.name, entry->name.length, + entry->u.alias.resolved, aliasName, &vals); + ret = FontNameAlias; + break; + default: + ret = BadFontName; + } + } + else + { + ret = BadFontName; + } + + if (ret != BadFontName) + { + if (ranges) free(ranges); + return ret; + } + + /* Match XLFD patterns */ + CopyISOLatin1Lowered (lowerName, name, namelen); + lowerName[namelen] = '\0'; + tmpName.name = lowerName; + tmpName.length = namelen; + tmpName.ndashes = FontFileCountDashes (lowerName, namelen); + if (!FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO) || + !(tmpName.length = strlen (lowerName), + entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, + &vals))) { + CopyISOLatin1Lowered (lowerName, name, namelen); + lowerName[namelen] = '\0'; + tmpName.name = lowerName; + tmpName.length = namelen; + tmpName.ndashes = FontFileCountDashes (lowerName, namelen); + entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals); + if (entry) + { + strcpy(lowerName, entry->name.name); + tmpName.name = lowerName; + tmpName.length = entry->name.length; + tmpName.ndashes = entry->name.ndashes; + } + } + + if (entry) + { + noSpecificSize = FALSE; /* TRUE breaks XLFD enhancements */ + if (entry->type == FONT_ENTRY_SCALABLE && + FontFileCompleteXLFD (&vals, &entry->u.scalable.extra->defaults)) + { + scalable = &entry->u.scalable; + if ((vals.values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY || + (vals.values_supplied & POINTSIZE_MASK) == POINTSIZE_ARRAY || + (vals.values_supplied & + ~SIZE_SPECIFY_MASK & ~CHARSUBSET_SPECIFIED)) + scaled = 0; + else + scaled = FontFileFindScaledInstance (entry, &vals, + noSpecificSize); + /* + * A scaled instance can occur one of two ways: + * + * Either the font has been scaled to this + * size already, in which case scaled->pFont + * will point at that font. + * + * Or a bitmap instance in this size exists, + * which is handled as if we got a pattern + * matching the bitmap font name. + */ + if (scaled) + { + if (scaled->pFont) + { + *pFont = scaled->pFont; + (*pFont)->fpe = fpe; + ret = Successful; + } + else if (scaled->bitmap) + { + entry = scaled->bitmap; + bitmap = &entry->u.bitmap; + if (bitmap->pFont) + { + *pFont = bitmap->pFont; + (*pFont)->fpe = fpe; + ret = Successful; + } + else + { + ret = FontFileOpenBitmapNCF (fpe, pFont, flags, entry, + format, fmask, + non_cachable_font); + if (ret == Successful && *pFont) + (*pFont)->fpe = fpe; + } + } + else /* "cannot" happen */ + { + ret = BadFontName; + } + } + else + { + ret = FontFileMatchBitmapSource (fpe, pFont, flags, entry, &tmpName, &vals, format, fmask, noSpecificSize); + if (ret != Successful) + { + char origName[MAXFONTNAMELEN]; + + CopyISOLatin1Lowered (origName, name, namelen); + origName[namelen] = '\0'; + + /* Pass the original XLFD name in the vals + structure; the rasterizer is free to examine it + for hidden meanings. This information will not + be saved in the scaled-instances table. */ + + vals.xlfdName = origName; + vals.ranges = ranges; + vals.nranges = nranges; + + if (strlen(dir->directory) + strlen(scalable->fileName) >= + sizeof(fileName)) { + ret = BadFontName; + } else { + strcpy (fileName, dir->directory); + strcat (fileName, scalable->fileName); + if (scalable->renderer->OpenScalable) { + ret = (*scalable->renderer->OpenScalable) (fpe, pFont, + flags, entry, fileName, &vals, format, fmask, + non_cachable_font); + } + else if (scalable->renderer->OpenBitmap) { + ret = (*scalable->renderer->OpenBitmap) (fpe, pFont, + flags, entry, fileName, format, fmask, + non_cachable_font); + } + } + + /* In case rasterizer does something bad because of + charset subsetting... */ + if (ret == Successful && + ((*pFont)->info.firstCol > (*pFont)->info.lastCol || + (*pFont)->info.firstRow > (*pFont)->info.lastRow)) + { + (*(*pFont)->unload_font)(*pFont); + ret = BadFontName; + } + /* Save the instance */ + if (ret == Successful) + { + if (FontFileAddScaledInstance (entry, &vals, + *pFont, (char *) 0)) + ranges = 0; + else + (*pFont)->fpePrivate = (pointer) 0; + (*pFont)->fpe = fpe; + } + } + } + } + } + else + ret = BadFontName; + + if (ranges) + free(ranges); + return ret; +} + +/* ARGSUSED */ +void +FontFileCloseFont (FontPathElementPtr fpe, FontPtr pFont) +{ + FontEntryPtr entry; + + if ((entry = (FontEntryPtr) pFont->fpePrivate)) { + switch (entry->type) { + case FONT_ENTRY_SCALABLE: + FontFileRemoveScaledInstance (entry, pFont); + break; + case FONT_ENTRY_BITMAP: + entry->u.bitmap.pFont = 0; + break; + default: + /* "cannot" happen */ + break; + } + pFont->fpePrivate = 0; + } + (*pFont->unload_font) (pFont); +} + +static int +FontFileOpenBitmapNCF (FontPathElementPtr fpe, FontPtr *pFont, + int flags, FontEntryPtr entry, + fsBitmapFormat format, fsBitmapFormatMask fmask, + FontPtr non_cachable_font) +{ + FontBitmapEntryPtr bitmap; + char fileName[MAXFONTFILENAMELEN*2+1]; + int ret; + FontDirectoryPtr dir; + + dir = (FontDirectoryPtr) fpe->private; + bitmap = &entry->u.bitmap; + if(!bitmap || !bitmap->renderer->OpenBitmap) + return BadFontName; + if (strlen(dir->directory) + strlen(bitmap->fileName) >= sizeof(fileName)) + return BadFontName; + strcpy (fileName, dir->directory); + strcat (fileName, bitmap->fileName); + ret = (*bitmap->renderer->OpenBitmap) + (fpe, pFont, flags, entry, fileName, format, fmask, + non_cachable_font); + if (ret == Successful) + { + bitmap->pFont = *pFont; + (*pFont)->fpePrivate = (pointer) entry; + } + return ret; +} + +int +FontFileOpenBitmap (FontPathElementPtr fpe, FontPtr *pFont, + int flags, FontEntryPtr entry, + fsBitmapFormat format, fsBitmapFormatMask fmask) +{ + return FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask, + (FontPtr)0); +} + +static int +FontFileGetInfoBitmap (FontPathElementPtr fpe, FontInfoPtr pFontInfo, + FontEntryPtr entry) +{ + FontBitmapEntryPtr bitmap; + char fileName[MAXFONTFILENAMELEN*2+1]; + int ret; + FontDirectoryPtr dir; + + dir = (FontDirectoryPtr) fpe->private; + bitmap = &entry->u.bitmap; + if (!bitmap || !bitmap->renderer->GetInfoBitmap) + return BadFontName; + if (strlen(dir->directory) + strlen(bitmap->fileName) >= sizeof(fileName)) + return BadFontName; + strcpy (fileName, dir->directory); + strcat (fileName, bitmap->fileName); + ret = (*bitmap->renderer->GetInfoBitmap) (fpe, pFontInfo, entry, fileName); + return ret; +} + +static void +_FontFileAddScalableNames(FontNamesPtr names, FontNamesPtr scaleNames, + FontNamePtr nameptr, char *zeroChars, + FontScalablePtr vals, fsRange *ranges, + int nranges, int *max) +{ + int i; + FontScalableRec zeroVals, tmpVals; + for (i = 0; i < scaleNames->nnames; i++) + { + char nameChars[MAXFONTNAMELEN]; + if (!*max) + return; + FontParseXLFDName (scaleNames->names[i], &zeroVals, + FONT_XLFD_REPLACE_NONE); + tmpVals = *vals; + if (FontFileCompleteXLFD (&tmpVals, &zeroVals)) + { + --*max; + + strcpy (nameChars, scaleNames->names[i]); + if ((vals->values_supplied & PIXELSIZE_MASK) || + !(vals->values_supplied & PIXELSIZE_WILDCARD) || + vals->y == 0) + { + tmpVals.values_supplied = + (tmpVals.values_supplied & ~PIXELSIZE_MASK) | + (vals->values_supplied & PIXELSIZE_MASK); + tmpVals.pixel_matrix[0] = vals->pixel_matrix[0]; + tmpVals.pixel_matrix[1] = vals->pixel_matrix[1]; + tmpVals.pixel_matrix[2] = vals->pixel_matrix[2]; + tmpVals.pixel_matrix[3] = vals->pixel_matrix[3]; + } + if ((vals->values_supplied & POINTSIZE_MASK) || + !(vals->values_supplied & POINTSIZE_WILDCARD) || + vals->y == 0) + { + tmpVals.values_supplied = + (tmpVals.values_supplied & ~POINTSIZE_MASK) | + (vals->values_supplied & POINTSIZE_MASK); + tmpVals.point_matrix[0] = vals->point_matrix[0]; + tmpVals.point_matrix[1] = vals->point_matrix[1]; + tmpVals.point_matrix[2] = vals->point_matrix[2]; + tmpVals.point_matrix[3] = vals->point_matrix[3]; + } + if (vals->width <= 0) + tmpVals.width = 0; + if (vals->x == 0) + tmpVals.x = 0; + if (vals->y == 0) + tmpVals.y = 0; + tmpVals.ranges = ranges; + tmpVals.nranges = nranges; + FontParseXLFDName (nameChars, &tmpVals, + FONT_XLFD_REPLACE_VALUE); + /* If we're marking aliases with negative lengths, we + need to concoct a valid target name to follow it. + Otherwise we're done. */ + if (scaleNames->length[i] >= 0) + { + (void) AddFontNamesName (names, nameChars, + strlen (nameChars)); + /* If our original pattern matches the name from + the table and that name doesn't duplicate what + we just added, add the name from the table */ + if (strcmp(nameChars, scaleNames->names[i]) && + FontFileMatchName(scaleNames->names[i], + scaleNames->length[i], + nameptr) && + *max) + { + --*max; + (void) AddFontNamesName (names, scaleNames->names[i], + scaleNames->length[i]); + } + } + else + { + char *aliasName; + vals->ranges = ranges; + vals->nranges = nranges; + if (transfer_values_to_alias(zeroChars, + strlen(zeroChars), + scaleNames->names[++i], + &aliasName, vals)) + { + (void) AddFontNamesName (names, nameChars, + strlen (nameChars)); + names->length[names->nnames - 1] = + -names->length[names->nnames - 1]; + (void) AddFontNamesName (names, aliasName, + strlen (aliasName)); + /* If our original pattern matches the name from + the table and that name doesn't duplicate what + we just added, add the name from the table */ + if (strcmp(nameChars, scaleNames->names[i - 1]) && + FontFileMatchName(scaleNames->names[i - 1], + -scaleNames->length[i - 1], + nameptr) && + *max) + { + --*max; + (void) AddFontNamesName (names, + scaleNames->names[i - 1], + -scaleNames->length[i - 1]); + names->length[names->nnames - 1] = + -names->length[names->nnames - 1]; + (void) AddFontNamesName (names, aliasName, + strlen (aliasName)); + } + } + } + } + } +} + +/* ARGSUSED */ +static int +_FontFileListFonts (pointer client, FontPathElementPtr fpe, + char *pat, int len, int max, FontNamesPtr names, + int mark_aliases) +{ + FontDirectoryPtr dir; + char lowerChars[MAXFONTNAMELEN], zeroChars[MAXFONTNAMELEN]; + FontNameRec lowerName; + FontNameRec zeroName; + FontNamesPtr scaleNames; + FontScalableRec vals; + fsRange *ranges; + int nranges; + int result = BadFontName; + + if (len >= MAXFONTNAMELEN) + return AllocError; + dir = (FontDirectoryPtr) fpe->private; + CopyISOLatin1Lowered (lowerChars, pat, len); + lowerChars[len] = '\0'; + lowerName.name = lowerChars; + lowerName.length = len; + lowerName.ndashes = FontFileCountDashes (lowerChars, len); + + /* Match XLFD patterns */ + + strcpy (zeroChars, lowerChars); + if (lowerName.ndashes == 14 && + FontParseXLFDName (zeroChars, &vals, FONT_XLFD_REPLACE_ZERO)) + { + ranges = FontParseRanges(lowerChars, &nranges); + result = FontFileFindNamesInScalableDir (&dir->nonScalable, + &lowerName, max, names, + (FontScalablePtr)0, + (mark_aliases ? + LIST_ALIASES_AND_TARGET_NAMES : + NORMAL_ALIAS_BEHAVIOR) | + IGNORE_SCALABLE_ALIASES, + &max); + zeroName.name = zeroChars; + zeroName.length = strlen (zeroChars); + zeroName.ndashes = lowerName.ndashes; + + /* Look for scalable names and aliases, adding scaled instances of + them to the output */ + + /* Scalable names... */ + scaleNames = MakeFontNamesRecord (0); + if (!scaleNames) + { + if (ranges) free(ranges); + return AllocError; + } + FontFileFindNamesInScalableDir (&dir->scalable, &zeroName, max, + scaleNames, &vals, + mark_aliases ? + LIST_ALIASES_AND_TARGET_NAMES : + NORMAL_ALIAS_BEHAVIOR, (int *)0); + _FontFileAddScalableNames(names, scaleNames, &lowerName, + zeroChars, &vals, ranges, nranges, + &max); + FreeFontNames (scaleNames); + + /* Scalable aliases... */ + scaleNames = MakeFontNamesRecord (0); + if (!scaleNames) + { + if (ranges) free(ranges); + return AllocError; + } + FontFileFindNamesInScalableDir (&dir->nonScalable, &zeroName, + max, scaleNames, &vals, + mark_aliases ? + LIST_ALIASES_AND_TARGET_NAMES : + NORMAL_ALIAS_BEHAVIOR, (int *)0); + _FontFileAddScalableNames(names, scaleNames, &lowerName, + zeroChars, &vals, ranges, nranges, + &max); + FreeFontNames (scaleNames); + + if (ranges) free(ranges); + } + else + { + result = FontFileFindNamesInScalableDir (&dir->nonScalable, + &lowerName, max, names, + (FontScalablePtr)0, + mark_aliases ? + LIST_ALIASES_AND_TARGET_NAMES : + NORMAL_ALIAS_BEHAVIOR, + &max); + if (result == Successful) + result = FontFileFindNamesInScalableDir (&dir->scalable, + &lowerName, max, names, + (FontScalablePtr)0, + mark_aliases ? + LIST_ALIASES_AND_TARGET_NAMES : + NORMAL_ALIAS_BEHAVIOR, (int *)0); + } + return result; +} + +typedef struct _LFWIData { + FontNamesPtr names; + int current; +} LFWIDataRec, *LFWIDataPtr; + +int +FontFileListFonts (pointer client, FontPathElementPtr fpe, char *pat, + int len, int max, FontNamesPtr names) +{ + return _FontFileListFonts (client, fpe, pat, len, max, names, 0); +} + +int +FontFileStartListFonts(pointer client, FontPathElementPtr fpe, + char *pat, int len, int max, + pointer *privatep, int mark_aliases) +{ + LFWIDataPtr data; + int ret; + + data = malloc (sizeof *data); + if (!data) + return AllocError; + data->names = MakeFontNamesRecord (0); + if (!data->names) + { + free (data); + return AllocError; + } + ret = _FontFileListFonts (client, fpe, pat, len, + max, data->names, mark_aliases); + if (ret != Successful) + { + FreeFontNames (data->names); + free (data); + return ret; + } + data->current = 0; + *privatep = (pointer) data; + return Successful; +} + + +int +FontFileStartListFontsWithInfo(pointer client, FontPathElementPtr fpe, + char *pat, int len, int max, + pointer *privatep) +{ + return FontFileStartListFonts(client, fpe, pat, len, max, privatep, 0); +} + +/* ARGSUSED */ +static int +FontFileListOneFontWithInfo (pointer client, FontPathElementPtr fpe, + char **namep, int *namelenp, + FontInfoPtr *pFontInfo) +{ + FontDirectoryPtr dir; + char lowerName[MAXFONTNAMELEN]; + char fileName[MAXFONTFILENAMELEN*2 + 1]; + FontNameRec tmpName; + FontEntryPtr entry; + FontScalableRec vals; + FontScalableEntryPtr scalable; + FontScaledPtr scaled; + FontBitmapEntryPtr bitmap; + int ret; + Bool noSpecificSize; + int nranges; + fsRange *ranges; + + char *name = *namep; + int namelen = *namelenp; + + if (namelen >= MAXFONTNAMELEN) + return AllocError; + dir = (FontDirectoryPtr) fpe->private; + + /* Match non-scalable pattern */ + CopyISOLatin1Lowered (lowerName, name, namelen); + lowerName[namelen] = '\0'; + ranges = FontParseRanges(lowerName, &nranges); + tmpName.name = lowerName; + tmpName.length = namelen; + tmpName.ndashes = FontFileCountDashes (lowerName, namelen); + if (!FontParseXLFDName(lowerName, &vals, FONT_XLFD_REPLACE_NONE)) + bzero(&vals, sizeof(vals)); + if (!(entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName)) && + tmpName.ndashes == 14 && + FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO)) + { + tmpName.length = strlen(lowerName); + entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName); + } + + if (entry) + { + switch (entry->type) { + case FONT_ENTRY_BITMAP: + bitmap = &entry->u.bitmap; + if (bitmap->pFont) + { + *pFontInfo = &bitmap->pFont->info; + ret = Successful; + } + else + { + ret = FontFileGetInfoBitmap (fpe, *pFontInfo, entry); + } + break; + case FONT_ENTRY_ALIAS: + vals.nranges = nranges; + vals.ranges = ranges; + transfer_values_to_alias(entry->name.name, entry->name.length, + entry->u.alias.resolved, namep, &vals); + *namelenp = strlen (*namep); + ret = FontNameAlias; + break; + default: + ret = BadFontName; + } + } + else + { + ret = BadFontName; + } + + if (ret != BadFontName) + { + if (ranges) free(ranges); + return ret; + } + + /* Match XLFD patterns */ + CopyISOLatin1Lowered (lowerName, name, namelen); + lowerName[namelen] = '\0'; + tmpName.name = lowerName; + tmpName.length = namelen; + tmpName.ndashes = FontFileCountDashes (lowerName, namelen); + if (!FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO) || + !(tmpName.length = strlen (lowerName), + entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, + &vals))) { + CopyISOLatin1Lowered (lowerName, name, namelen); + lowerName[namelen] = '\0'; + tmpName.name = lowerName; + tmpName.length = namelen; + tmpName.ndashes = FontFileCountDashes (lowerName, namelen); + entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals); + if (entry) + { + strcpy(lowerName, entry->name.name); + tmpName.name = lowerName; + tmpName.length = entry->name.length; + tmpName.ndashes = entry->name.ndashes; + } + } + + if (entry) + { + noSpecificSize = FALSE; /* TRUE breaks XLFD enhancements */ + if (entry && entry->type == FONT_ENTRY_SCALABLE && + FontFileCompleteXLFD (&vals, &entry->u.scalable.extra->defaults)) + { + scalable = &entry->u.scalable; + scaled = FontFileFindScaledInstance (entry, &vals, noSpecificSize); + /* + * A scaled instance can occur one of two ways: + * + * Either the font has been scaled to this + * size already, in which case scaled->pFont + * will point at that font. + * + * Or a bitmap instance in this size exists, + * which is handled as if we got a pattern + * matching the bitmap font name. + */ + if (scaled) + { + if (scaled->pFont) + { + *pFontInfo = &scaled->pFont->info; + ret = Successful; + } + else if (scaled->bitmap) + { + entry = scaled->bitmap; + bitmap = &entry->u.bitmap; + if (bitmap->pFont) + { + *pFontInfo = &bitmap->pFont->info; + ret = Successful; + } + else + { + ret = FontFileGetInfoBitmap (fpe, *pFontInfo, entry); + } + } + else /* "cannot" happen */ + { + ret = BadFontName; + } + } + else + { + { + char origName[MAXFONTNAMELEN]; + + CopyISOLatin1Lowered (origName, name, namelen); + origName[namelen] = '\0'; + vals.xlfdName = origName; + vals.ranges = ranges; + vals.nranges = nranges; + + /* Make a new scaled instance */ + if (strlen(dir->directory) + strlen(scalable->fileName) >= + sizeof(fileName)) { + ret = BadFontName; + } else { + strcpy (fileName, dir->directory); + strcat (fileName, scalable->fileName); + if (scalable->renderer->GetInfoScalable) + ret = (*scalable->renderer->GetInfoScalable) + (fpe, *pFontInfo, entry, &tmpName, fileName, + &vals); + else if (scalable->renderer->GetInfoBitmap) + ret = (*scalable->renderer->GetInfoBitmap) + (fpe, *pFontInfo, entry, fileName); + } + if (ranges) { + free(ranges); + ranges = NULL; + } + } + } + if (ret == Successful) return ret; + } + CopyISOLatin1Lowered (lowerName, name, namelen); + tmpName.length = namelen; + } + else + ret = BadFontName; + + if (ranges) + free(ranges); + return ret; +} + +int +FontFileListNextFontWithInfo(pointer client, FontPathElementPtr fpe, + char **namep, int *namelenp, + FontInfoPtr *pFontInfo, + int *numFonts, pointer private) +{ + LFWIDataPtr data = (LFWIDataPtr) private; + int ret; + char *name; + int namelen; + + if (data->current == data->names->nnames) + { + FreeFontNames (data->names); + free (data); + return BadFontName; + } + name = data->names->names[data->current]; + namelen = data->names->length[data->current]; + ret = FontFileListOneFontWithInfo (client, fpe, &name, &namelen, pFontInfo); + if (ret == BadFontName) + ret = AllocError; + *namep = name; + *namelenp = namelen; + ++data->current; + *numFonts = data->names->nnames - data->current; + return ret; +} + +int +FontFileStartListFontsAndAliases(pointer client, FontPathElementPtr fpe, + char *pat, int len, int max, + pointer *privatep) +{ + return FontFileStartListFonts(client, fpe, pat, len, max, privatep, 1); +} + +int +FontFileListNextFontOrAlias(pointer client, FontPathElementPtr fpe, + char **namep, int *namelenp, char **resolvedp, + int *resolvedlenp, pointer private) +{ + LFWIDataPtr data = (LFWIDataPtr) private; + int ret; + char *name; + int namelen; + + if (data->current == data->names->nnames) + { + FreeFontNames (data->names); + free (data); + return BadFontName; + } + name = data->names->names[data->current]; + namelen = data->names->length[data->current]; + + /* If this is a real font name... */ + if (namelen >= 0) + { + *namep = name; + *namelenp = namelen; + ret = Successful; + } + /* Else if an alias */ + else + { + /* Tell the caller that this is an alias... let him resolve it to + see if it's valid */ + *namep = name; + *namelenp = -namelen; + *resolvedp = data->names->names[++data->current]; + *resolvedlenp = data->names->length[data->current]; + ret = FontNameAlias; + } + + ++data->current; + return ret; +} + +void +FontFileRegisterLocalFpeFunctions (void) +{ + RegisterFPEFunctions(FontFileNameCheck, + FontFileInitFPE, + FontFileFreeFPE, + FontFileResetFPE, + FontFileOpenFont, + FontFileCloseFont, + FontFileListFonts, + FontFileStartListFontsWithInfo, + FontFileListNextFontWithInfo, + NULL, + NULL, + NULL, + FontFileStartListFontsAndAliases, + FontFileListNextFontOrAlias, + FontFileEmptyBitmapSource); +} diff --git a/libXfont/src/fontfile/fontscale.c b/libXfont/src/fontfile/fontscale.c index 524db98d0..eb8d0bb58 100644 --- a/libXfont/src/fontfile/fontscale.c +++ b/libXfont/src/fontfile/fontscale.c @@ -1,441 +1,441 @@ -/*
-
-Copyright 1991, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-/*
- * Author: Keith Packard, MIT X Consortium
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/fonts/fntfilst.h>
-#include <math.h>
-
-#ifdef _MSC_VER
-#define hypot _hypot
-#endif
-
-Bool
-FontFileAddScaledInstance (FontEntryPtr entry, FontScalablePtr vals,
- FontPtr pFont, char *bitmapName)
-{
- FontScalableEntryPtr scalable;
- FontScalableExtraPtr extra;
- FontScaledPtr new;
- int newsize;
-
- scalable = &entry->u.scalable;
- extra = scalable->extra;
- if (extra->numScaled == extra->sizeScaled)
- {
- newsize = extra->sizeScaled + 4;
- new = realloc (extra->scaled, newsize * sizeof (FontScaledRec));
- if (!new)
- return FALSE;
- extra->sizeScaled = newsize;
- extra->scaled = new;
- }
- new = &extra->scaled[extra->numScaled++];
- new->vals = *vals;
- new->pFont = pFont;
- new->bitmap = (FontEntryPtr) bitmapName;
- if (pFont)
- pFont->fpePrivate = (pointer) entry;
- return TRUE;
-}
-
-/* Must call this after the directory is sorted */
-
-void
-FontFileSwitchStringsToBitmapPointers (FontDirectoryPtr dir)
-{
- int s;
- int b;
- int i;
- FontEntryPtr scalable;
- FontEntryPtr nonScalable;
- FontScaledPtr scaled;
- FontScalableExtraPtr extra;
-
- scalable = dir->scalable.entries;
- nonScalable = dir->nonScalable.entries;
- for (s = 0; s < dir->scalable.used; s++)
- {
- extra = scalable[s].u.scalable.extra;
- scaled = extra->scaled;
- for (i = 0; i < extra->numScaled; i++)
- for (b = 0; b < dir->nonScalable.used; b++)
- if (nonScalable[b].name.name == (char *) scaled[i].bitmap)
- scaled[i].bitmap = &nonScalable[b];
- }
-}
-
-void
-FontFileRemoveScaledInstance (FontEntryPtr entry, FontPtr pFont)
-{
- FontScalableEntryPtr scalable;
- FontScalableExtraPtr extra;
- int i;
-
- scalable = &entry->u.scalable;
- extra = scalable->extra;
- for (i = 0; i < extra->numScaled; i++)
- {
- if (extra->scaled[i].pFont == pFont)
- {
- if (extra->scaled[i].vals.ranges)
- free (extra->scaled[i].vals.ranges);
- extra->numScaled--;
- for (; i < extra->numScaled; i++)
- extra->scaled[i] = extra->scaled[i+1];
- }
- }
-}
-
-Bool
-FontFileCompleteXLFD (FontScalablePtr vals, FontScalablePtr def)
-{
- FontResolutionPtr res;
- int num_res;
- double sx, sy, temp_matrix[4];
- double pixel_setsize_adjustment = 1.0;
- /*
- * If two of the three vertical scale values are specified, compute the
- * third. If all three are specified, make sure they are consistent
- * (within a pixel)
- *
- * One purpose of this procedure is to complete XLFD names in a
- * repeatable manner. That is, if the user partially specifies
- * a name (say, pixelsize but not pointsize), the results generated
- * here result in a fully specified name that will result in the
- * same font.
- */
-
- res = GetClientResolutions(&num_res);
-
- if (!(vals->values_supplied & PIXELSIZE_MASK) ||
- !(vals->values_supplied & POINTSIZE_MASK))
- {
- /* If resolution(s) unspecified and cannot be computed from
- pixelsize and pointsize, get appropriate defaults. */
-
- if (num_res)
- {
- if (vals->x <= 0)
- vals->x = res->x_resolution;
- if (vals->y <= 0)
- vals->y = res->y_resolution;
- }
-
- if (vals->x <= 0)
- vals->x = def->x;
- if (vals->y <= 0)
- vals->y = def->y;
- }
- else
- {
- /* If needed, compute resolution values from the pixel and
- pointsize information we were given. This problem is
- overdetermined (four equations, two unknowns), but we don't
- check for inconsistencies here. If they exist, they will
- show up in later tests for the point and pixel sizes. */
-
- if (vals->y <= 0)
- {
- double x = hypot(vals->pixel_matrix[1], vals->pixel_matrix[3]);
- double y = hypot(vals->point_matrix[1], vals->point_matrix[3]);
- if (y < EPS) return FALSE;
- vals->y = (int)(x * 72.27 / y + .5);
- }
- if (vals->x <= 0)
- {
- /* If the pixelsize was given as an array, or as a scalar that
- has been normalized for the pixel shape, we have enough
- information to compute a separate horizontal resolution */
-
- if ((vals->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY ||
- (vals->values_supplied & PIXELSIZE_MASK) ==
- PIXELSIZE_SCALAR_NORMALIZED)
- {
- double x = hypot(vals->pixel_matrix[0], vals->pixel_matrix[2]);
- double y = hypot(vals->point_matrix[0], vals->point_matrix[2]);
- if (y < EPS) return FALSE;
- vals->x = (int)(x * 72.27 / y + .5);
- }
- else
- {
- /* Not enough information in the pixelsize array. Just
- assume the pixels are square. */
- vals->x = vals->y;
- }
- }
- }
-
- if (vals->x <= 0 || vals->y <= 0) return FALSE;
-
- /* If neither pixelsize nor pointsize is defined, take the pointsize
- from the defaults structure we've been passed. */
- if (!(vals->values_supplied & PIXELSIZE_MASK) &&
- !(vals->values_supplied & POINTSIZE_MASK))
- {
- if (num_res)
- {
- vals->point_matrix[0] =
- vals->point_matrix[3] = (double)res->point_size / 10.0;
- vals->point_matrix[1] =
- vals->point_matrix[2] = 0;
- vals->values_supplied = (vals->values_supplied & ~POINTSIZE_MASK) |
- POINTSIZE_SCALAR;
- }
- else if (def->values_supplied & POINTSIZE_MASK)
- {
- vals->point_matrix[0] = def->point_matrix[0];
- vals->point_matrix[1] = def->point_matrix[1];
- vals->point_matrix[2] = def->point_matrix[2];
- vals->point_matrix[3] = def->point_matrix[3];
- vals->values_supplied = (vals->values_supplied & ~POINTSIZE_MASK) |
- (def->values_supplied & POINTSIZE_MASK);
- }
- else return FALSE;
- }
-
- /* At this point, at least two of the three vertical scale values
- should be specified. Our job now is to compute the missing ones
- and check for agreement between overspecified values */
-
- /* If pixelsize was specified by a scalar, we need to fix the matrix
- now that we know the resolutions. */
- if ((vals->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_SCALAR)
- {
- /* pixel_setsize_adjustment used below to modify permissible
- error in pixel/pointsize matching, since multiplying a
- number rounded to integer changes the amount of the error
- caused by the rounding */
-
- pixel_setsize_adjustment = (double)vals->x / (double)vals->y;
- vals->pixel_matrix[0] *= pixel_setsize_adjustment;
- vals->values_supplied = (vals->values_supplied & ~PIXELSIZE_MASK) |
- PIXELSIZE_SCALAR_NORMALIZED;
- }
-
- sx = (double)vals->x / 72.27;
- sy = (double)vals->y / 72.27;
-
- /* If a pointsize was specified, make sure pixelsize is consistent
- to within 1 pixel, then replace pixelsize with a consistent
- floating-point value. */
-
- if (vals->values_supplied & POINTSIZE_MASK)
- {
- recompute_pixelsize: ;
- temp_matrix[0] = vals->point_matrix[0] * sx;
- temp_matrix[1] = vals->point_matrix[1] * sy;
- temp_matrix[2] = vals->point_matrix[2] * sx;
- temp_matrix[3] = vals->point_matrix[3] * sy;
- if (vals->values_supplied & PIXELSIZE_MASK)
- {
- if (fabs(vals->pixel_matrix[0] - temp_matrix[0]) >
- pixel_setsize_adjustment ||
- fabs(vals->pixel_matrix[1] - temp_matrix[1]) > 1 ||
- fabs(vals->pixel_matrix[2] - temp_matrix[2]) > 1 ||
- fabs(vals->pixel_matrix[3] - temp_matrix[3]) > 1)
- return FALSE;
- }
- if ((vals->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY &&
- (vals->values_supplied & POINTSIZE_MASK) == POINTSIZE_SCALAR)
- {
- /* In the special case that pixelsize came as an array and
- pointsize as a scalar, recompute the pointsize matrix
- from the pixelsize matrix. */
- goto recompute_pointsize;
- }
-
- /* Refresh pixel matrix with precise values computed from
- pointsize and resolution. */
- vals->pixel_matrix[0] = temp_matrix[0];
- vals->pixel_matrix[1] = temp_matrix[1];
- vals->pixel_matrix[2] = temp_matrix[2];
- vals->pixel_matrix[3] = temp_matrix[3];
-
- /* Set values_supplied for pixel to match that for point */
- vals->values_supplied =
- (vals->values_supplied & ~PIXELSIZE_MASK) |
- (((vals->values_supplied & POINTSIZE_MASK) == POINTSIZE_ARRAY) ?
- PIXELSIZE_ARRAY : PIXELSIZE_SCALAR_NORMALIZED);
- }
- else
- {
- /* Pointsize unspecified... compute from pixel size and
- resolutions */
- recompute_pointsize: ;
- if (fabs(sx) < EPS || fabs(sy) < EPS) return FALSE;
- vals->point_matrix[0] = vals->pixel_matrix[0] / sx;
- vals->point_matrix[1] = vals->pixel_matrix[1] / sy;
- vals->point_matrix[2] = vals->pixel_matrix[2] / sx;
- vals->point_matrix[3] = vals->pixel_matrix[3] / sy;
-
- /* Set values_supplied for pixel to match that for point */
- vals->values_supplied =
- (vals->values_supplied & ~POINTSIZE_MASK) |
- (((vals->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY) ?
- POINTSIZE_ARRAY : POINTSIZE_SCALAR);
-
- /* If we computed scalar pointsize from scalar pixelsize, round
- pointsize to decipoints and recompute pixelsize so we end up
- with a repeatable name */
- if ((vals->values_supplied & POINTSIZE_MASK) == POINTSIZE_SCALAR)
- {
- /* Off-diagonal elements should be zero since no matrix was
- specified. */
- vals->point_matrix[0] =
- (double)(int)(vals->point_matrix[0] * 10.0 + .5) / 10.0;
- vals->point_matrix[3] =
- (double)(int)(vals->point_matrix[3] * 10.0 + .5) / 10.0;
- goto recompute_pixelsize;
- }
- }
-
- /* We've succeeded. Round everything to a few decimal places
- for repeatability. */
-
- vals->pixel_matrix[0] = xlfd_round_double(vals->pixel_matrix[0]);
- vals->pixel_matrix[1] = xlfd_round_double(vals->pixel_matrix[1]);
- vals->pixel_matrix[2] = xlfd_round_double(vals->pixel_matrix[2]);
- vals->pixel_matrix[3] = xlfd_round_double(vals->pixel_matrix[3]);
- vals->point_matrix[0] = xlfd_round_double(vals->point_matrix[0]);
- vals->point_matrix[1] = xlfd_round_double(vals->point_matrix[1]);
- vals->point_matrix[2] = xlfd_round_double(vals->point_matrix[2]);
- vals->point_matrix[3] = xlfd_round_double(vals->point_matrix[3]);
-
- /* Fill in the deprecated fields for the benefit of rasterizers
- that do not handle the matrices. */
- vals->point = vals->point_matrix[3] * 10;
- vals->pixel = vals->pixel_matrix[3];
-
- return TRUE;
-}
-
-static Bool
-MatchScalable (FontScalablePtr a, FontScalablePtr b)
-{
- int i;
-
- /* Some asymmetry here: we assume that the first argument (a) is
- the table entry and the second (b) the item we're trying to match
- (the key). We'll consider the fonts matched if the relevant
- metrics match *and* if a) the table entry doesn't have charset
- subsetting or b) the table entry has identical charset subsetting
- to that in the key. We could add logic to check if the table
- entry has a superset of the charset required by the key, but
- we'll resist the urge for now. */
-
-#define EQUAL(a,b) ((a)[0] == (b)[0] && \
- (a)[1] == (b)[1] && \
- (a)[2] == (b)[2] && \
- (a)[3] == (b)[3])
-
- if (!(a->x == b->x &&
- a->y == b->y &&
- (a->width == b->width || a->width == 0 || b->width == 0 || b->width == -1) &&
- (!(b->values_supplied & PIXELSIZE_MASK) ||
- ((a->values_supplied & PIXELSIZE_MASK) ==
- (b->values_supplied & PIXELSIZE_MASK) &&
- EQUAL(a->pixel_matrix, b->pixel_matrix))) &&
- (!(b->values_supplied & POINTSIZE_MASK) ||
- ((a->values_supplied & POINTSIZE_MASK) ==
- (b->values_supplied & POINTSIZE_MASK) &&
- EQUAL(a->point_matrix, b->point_matrix))) &&
- (a->nranges == 0 || a->nranges == b->nranges)))
- return FALSE;
-
- for (i = 0; i < a->nranges; i++)
- if (a->ranges[i].min_char_low != b->ranges[i].min_char_low ||
- a->ranges[i].min_char_high != b->ranges[i].min_char_high ||
- a->ranges[i].max_char_low != b->ranges[i].max_char_low ||
- a->ranges[i].max_char_high != b->ranges[i].max_char_high)
- return FALSE;
-
- return TRUE;
-}
-
-FontScaledPtr
-FontFileFindScaledInstance (FontEntryPtr entry, FontScalablePtr vals,
- int noSpecificSize)
-{
- FontScalableEntryPtr scalable;
- FontScalableExtraPtr extra;
- FontScalablePtr mvals;
- int dist, i;
- int mini;
- double mindist;
- register double temp, sum=0.0;
-
-#define NORMDIFF(a, b) ( \
- temp = (a)[0] - (b)[0], \
- sum = temp * temp, \
- temp = (a)[1] - (b)[1], \
- sum += temp * temp, \
- temp = (a)[2] - (b)[2], \
- sum += temp * temp, \
- temp = (a)[3] - (b)[3], \
- sum + temp * temp )
-
- scalable = &entry->u.scalable;
- extra = scalable->extra;
- if (noSpecificSize && extra->numScaled)
- {
- mini = 0;
- mindist = NORMDIFF(extra->scaled[0].vals.point_matrix,
- vals->point_matrix);
- for (i = 1; i < extra->numScaled; i++)
- {
- if (extra->scaled[i].pFont &&
- !extra->scaled[i].pFont->info.cachable) continue;
- mvals = &extra->scaled[i].vals;
- dist = NORMDIFF(mvals->point_matrix, vals->point_matrix);
- if (dist < mindist)
- {
- mindist = dist;
- mini = i;
- }
- }
- if (extra->scaled[mini].pFont &&
- !extra->scaled[mini].pFont->info.cachable) return 0;
- return &extra->scaled[mini];
- }
- else
- {
- /* See if we've scaled to this value yet */
- for (i = 0; i < extra->numScaled; i++)
- {
- if (extra->scaled[i].pFont &&
- !extra->scaled[i].pFont->info.cachable) continue;
- if (MatchScalable (&extra->scaled[i].vals, vals))
- return &extra->scaled[i];
- }
- }
- return 0;
-}
+/* + +Copyright 1991, 1998 The Open Group + +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. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ + +/* + * Author: Keith Packard, MIT X Consortium + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/fonts/fntfilst.h> +#include <math.h> + +#ifdef _MSC_VER +#define hypot _hypot +#endif + +Bool +FontFileAddScaledInstance (FontEntryPtr entry, FontScalablePtr vals, + FontPtr pFont, char *bitmapName) +{ + FontScalableEntryPtr scalable; + FontScalableExtraPtr extra; + FontScaledPtr new; + int newsize; + + scalable = &entry->u.scalable; + extra = scalable->extra; + if (extra->numScaled == extra->sizeScaled) + { + newsize = extra->sizeScaled + 4; + new = realloc (extra->scaled, newsize * sizeof (FontScaledRec)); + if (!new) + return FALSE; + extra->sizeScaled = newsize; + extra->scaled = new; + } + new = &extra->scaled[extra->numScaled++]; + new->vals = *vals; + new->pFont = pFont; + new->bitmap = (FontEntryPtr) bitmapName; + if (pFont) + pFont->fpePrivate = (pointer) entry; + return TRUE; +} + +/* Must call this after the directory is sorted */ + +void +FontFileSwitchStringsToBitmapPointers (FontDirectoryPtr dir) +{ + int s; + int b; + int i; + FontEntryPtr scalable; + FontEntryPtr nonScalable; + FontScaledPtr scaled; + FontScalableExtraPtr extra; + + scalable = dir->scalable.entries; + nonScalable = dir->nonScalable.entries; + for (s = 0; s < dir->scalable.used; s++) + { + extra = scalable[s].u.scalable.extra; + scaled = extra->scaled; + for (i = 0; i < extra->numScaled; i++) + for (b = 0; b < dir->nonScalable.used; b++) + if (nonScalable[b].name.name == (char *) scaled[i].bitmap) + scaled[i].bitmap = &nonScalable[b]; + } +} + +void +FontFileRemoveScaledInstance (FontEntryPtr entry, FontPtr pFont) +{ + FontScalableEntryPtr scalable; + FontScalableExtraPtr extra; + int i; + + scalable = &entry->u.scalable; + extra = scalable->extra; + for (i = 0; i < extra->numScaled; i++) + { + if (extra->scaled[i].pFont == pFont) + { + if (extra->scaled[i].vals.ranges) + free (extra->scaled[i].vals.ranges); + extra->numScaled--; + for (; i < extra->numScaled; i++) + extra->scaled[i] = extra->scaled[i+1]; + } + } +} + +Bool +FontFileCompleteXLFD (FontScalablePtr vals, FontScalablePtr def) +{ + FontResolutionPtr res; + int num_res; + double sx, sy, temp_matrix[4]; + double pixel_setsize_adjustment = 1.0; + /* + * If two of the three vertical scale values are specified, compute the + * third. If all three are specified, make sure they are consistent + * (within a pixel) + * + * One purpose of this procedure is to complete XLFD names in a + * repeatable manner. That is, if the user partially specifies + * a name (say, pixelsize but not pointsize), the results generated + * here result in a fully specified name that will result in the + * same font. + */ + + res = GetClientResolutions(&num_res); + + if (!(vals->values_supplied & PIXELSIZE_MASK) || + !(vals->values_supplied & POINTSIZE_MASK)) + { + /* If resolution(s) unspecified and cannot be computed from + pixelsize and pointsize, get appropriate defaults. */ + + if (num_res) + { + if (vals->x <= 0) + vals->x = res->x_resolution; + if (vals->y <= 0) + vals->y = res->y_resolution; + } + + if (vals->x <= 0) + vals->x = def->x; + if (vals->y <= 0) + vals->y = def->y; + } + else + { + /* If needed, compute resolution values from the pixel and + pointsize information we were given. This problem is + overdetermined (four equations, two unknowns), but we don't + check for inconsistencies here. If they exist, they will + show up in later tests for the point and pixel sizes. */ + + if (vals->y <= 0) + { + double x = hypot(vals->pixel_matrix[1], vals->pixel_matrix[3]); + double y = hypot(vals->point_matrix[1], vals->point_matrix[3]); + if (y < EPS) return FALSE; + vals->y = (int)(x * 72.27 / y + .5); + } + if (vals->x <= 0) + { + /* If the pixelsize was given as an array, or as a scalar that + has been normalized for the pixel shape, we have enough + information to compute a separate horizontal resolution */ + + if ((vals->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY || + (vals->values_supplied & PIXELSIZE_MASK) == + PIXELSIZE_SCALAR_NORMALIZED) + { + double x = hypot(vals->pixel_matrix[0], vals->pixel_matrix[2]); + double y = hypot(vals->point_matrix[0], vals->point_matrix[2]); + if (y < EPS) return FALSE; + vals->x = (int)(x * 72.27 / y + .5); + } + else + { + /* Not enough information in the pixelsize array. Just + assume the pixels are square. */ + vals->x = vals->y; + } + } + } + + if (vals->x <= 0 || vals->y <= 0) return FALSE; + + /* If neither pixelsize nor pointsize is defined, take the pointsize + from the defaults structure we've been passed. */ + if (!(vals->values_supplied & PIXELSIZE_MASK) && + !(vals->values_supplied & POINTSIZE_MASK)) + { + if (num_res) + { + vals->point_matrix[0] = + vals->point_matrix[3] = (double)res->point_size / 10.0; + vals->point_matrix[1] = + vals->point_matrix[2] = 0; + vals->values_supplied = (vals->values_supplied & ~POINTSIZE_MASK) | + POINTSIZE_SCALAR; + } + else if (def->values_supplied & POINTSIZE_MASK) + { + vals->point_matrix[0] = def->point_matrix[0]; + vals->point_matrix[1] = def->point_matrix[1]; + vals->point_matrix[2] = def->point_matrix[2]; + vals->point_matrix[3] = def->point_matrix[3]; + vals->values_supplied = (vals->values_supplied & ~POINTSIZE_MASK) | + (def->values_supplied & POINTSIZE_MASK); + } + else return FALSE; + } + + /* At this point, at least two of the three vertical scale values + should be specified. Our job now is to compute the missing ones + and check for agreement between overspecified values */ + + /* If pixelsize was specified by a scalar, we need to fix the matrix + now that we know the resolutions. */ + if ((vals->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_SCALAR) + { + /* pixel_setsize_adjustment used below to modify permissible + error in pixel/pointsize matching, since multiplying a + number rounded to integer changes the amount of the error + caused by the rounding */ + + pixel_setsize_adjustment = (double)vals->x / (double)vals->y; + vals->pixel_matrix[0] *= pixel_setsize_adjustment; + vals->values_supplied = (vals->values_supplied & ~PIXELSIZE_MASK) | + PIXELSIZE_SCALAR_NORMALIZED; + } + + sx = (double)vals->x / 72.27; + sy = (double)vals->y / 72.27; + + /* If a pointsize was specified, make sure pixelsize is consistent + to within 1 pixel, then replace pixelsize with a consistent + floating-point value. */ + + if (vals->values_supplied & POINTSIZE_MASK) + { + recompute_pixelsize: ; + temp_matrix[0] = vals->point_matrix[0] * sx; + temp_matrix[1] = vals->point_matrix[1] * sy; + temp_matrix[2] = vals->point_matrix[2] * sx; + temp_matrix[3] = vals->point_matrix[3] * sy; + if (vals->values_supplied & PIXELSIZE_MASK) + { + if (fabs(vals->pixel_matrix[0] - temp_matrix[0]) > + pixel_setsize_adjustment || + fabs(vals->pixel_matrix[1] - temp_matrix[1]) > 1 || + fabs(vals->pixel_matrix[2] - temp_matrix[2]) > 1 || + fabs(vals->pixel_matrix[3] - temp_matrix[3]) > 1) + return FALSE; + } + if ((vals->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY && + (vals->values_supplied & POINTSIZE_MASK) == POINTSIZE_SCALAR) + { + /* In the special case that pixelsize came as an array and + pointsize as a scalar, recompute the pointsize matrix + from the pixelsize matrix. */ + goto recompute_pointsize; + } + + /* Refresh pixel matrix with precise values computed from + pointsize and resolution. */ + vals->pixel_matrix[0] = temp_matrix[0]; + vals->pixel_matrix[1] = temp_matrix[1]; + vals->pixel_matrix[2] = temp_matrix[2]; + vals->pixel_matrix[3] = temp_matrix[3]; + + /* Set values_supplied for pixel to match that for point */ + vals->values_supplied = + (vals->values_supplied & ~PIXELSIZE_MASK) | + (((vals->values_supplied & POINTSIZE_MASK) == POINTSIZE_ARRAY) ? + PIXELSIZE_ARRAY : PIXELSIZE_SCALAR_NORMALIZED); + } + else + { + /* Pointsize unspecified... compute from pixel size and + resolutions */ + recompute_pointsize: ; + if (fabs(sx) < EPS || fabs(sy) < EPS) return FALSE; + vals->point_matrix[0] = vals->pixel_matrix[0] / sx; + vals->point_matrix[1] = vals->pixel_matrix[1] / sy; + vals->point_matrix[2] = vals->pixel_matrix[2] / sx; + vals->point_matrix[3] = vals->pixel_matrix[3] / sy; + + /* Set values_supplied for pixel to match that for point */ + vals->values_supplied = + (vals->values_supplied & ~POINTSIZE_MASK) | + (((vals->values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY) ? + POINTSIZE_ARRAY : POINTSIZE_SCALAR); + + /* If we computed scalar pointsize from scalar pixelsize, round + pointsize to decipoints and recompute pixelsize so we end up + with a repeatable name */ + if ((vals->values_supplied & POINTSIZE_MASK) == POINTSIZE_SCALAR) + { + /* Off-diagonal elements should be zero since no matrix was + specified. */ + vals->point_matrix[0] = + (double)(int)(vals->point_matrix[0] * 10.0 + .5) / 10.0; + vals->point_matrix[3] = + (double)(int)(vals->point_matrix[3] * 10.0 + .5) / 10.0; + goto recompute_pixelsize; + } + } + + /* We've succeeded. Round everything to a few decimal places + for repeatability. */ + + vals->pixel_matrix[0] = xlfd_round_double(vals->pixel_matrix[0]); + vals->pixel_matrix[1] = xlfd_round_double(vals->pixel_matrix[1]); + vals->pixel_matrix[2] = xlfd_round_double(vals->pixel_matrix[2]); + vals->pixel_matrix[3] = xlfd_round_double(vals->pixel_matrix[3]); + vals->point_matrix[0] = xlfd_round_double(vals->point_matrix[0]); + vals->point_matrix[1] = xlfd_round_double(vals->point_matrix[1]); + vals->point_matrix[2] = xlfd_round_double(vals->point_matrix[2]); + vals->point_matrix[3] = xlfd_round_double(vals->point_matrix[3]); + + /* Fill in the deprecated fields for the benefit of rasterizers + that do not handle the matrices. */ + vals->point = vals->point_matrix[3] * 10; + vals->pixel = vals->pixel_matrix[3]; + + return TRUE; +} + +static Bool +MatchScalable (FontScalablePtr a, FontScalablePtr b) +{ + int i; + + /* Some asymmetry here: we assume that the first argument (a) is + the table entry and the second (b) the item we're trying to match + (the key). We'll consider the fonts matched if the relevant + metrics match *and* if a) the table entry doesn't have charset + subsetting or b) the table entry has identical charset subsetting + to that in the key. We could add logic to check if the table + entry has a superset of the charset required by the key, but + we'll resist the urge for now. */ + +#define EQUAL(a,b) ((a)[0] == (b)[0] && \ + (a)[1] == (b)[1] && \ + (a)[2] == (b)[2] && \ + (a)[3] == (b)[3]) + + if (!(a->x == b->x && + a->y == b->y && + (a->width == b->width || a->width == 0 || b->width == 0 || b->width == -1) && + (!(b->values_supplied & PIXELSIZE_MASK) || + ((a->values_supplied & PIXELSIZE_MASK) == + (b->values_supplied & PIXELSIZE_MASK) && + EQUAL(a->pixel_matrix, b->pixel_matrix))) && + (!(b->values_supplied & POINTSIZE_MASK) || + ((a->values_supplied & POINTSIZE_MASK) == + (b->values_supplied & POINTSIZE_MASK) && + EQUAL(a->point_matrix, b->point_matrix))) && + (a->nranges == 0 || a->nranges == b->nranges))) + return FALSE; + + for (i = 0; i < a->nranges; i++) + if (a->ranges[i].min_char_low != b->ranges[i].min_char_low || + a->ranges[i].min_char_high != b->ranges[i].min_char_high || + a->ranges[i].max_char_low != b->ranges[i].max_char_low || + a->ranges[i].max_char_high != b->ranges[i].max_char_high) + return FALSE; + + return TRUE; +} + +FontScaledPtr +FontFileFindScaledInstance (FontEntryPtr entry, FontScalablePtr vals, + int noSpecificSize) +{ + FontScalableEntryPtr scalable; + FontScalableExtraPtr extra; + FontScalablePtr mvals; + int dist, i; + int mini; + double mindist; + register double temp, sum=0.0; + +#define NORMDIFF(a, b) ( \ + temp = (a)[0] - (b)[0], \ + sum = temp * temp, \ + temp = (a)[1] - (b)[1], \ + sum += temp * temp, \ + temp = (a)[2] - (b)[2], \ + sum += temp * temp, \ + temp = (a)[3] - (b)[3], \ + sum + temp * temp ) + + scalable = &entry->u.scalable; + extra = scalable->extra; + if (noSpecificSize && extra->numScaled) + { + mini = 0; + mindist = NORMDIFF(extra->scaled[0].vals.point_matrix, + vals->point_matrix); + for (i = 1; i < extra->numScaled; i++) + { + if (extra->scaled[i].pFont && + !extra->scaled[i].pFont->info.cachable) continue; + mvals = &extra->scaled[i].vals; + dist = NORMDIFF(mvals->point_matrix, vals->point_matrix); + if (dist < mindist) + { + mindist = dist; + mini = i; + } + } + if (extra->scaled[mini].pFont && + !extra->scaled[mini].pFont->info.cachable) return 0; + return &extra->scaled[mini]; + } + else + { + /* See if we've scaled to this value yet */ + for (i = 0; i < extra->numScaled; i++) + { + if (extra->scaled[i].pFont && + !extra->scaled[i].pFont->info.cachable) continue; + if (MatchScalable (&extra->scaled[i].vals, vals)) + return &extra->scaled[i]; + } + } + return 0; +} diff --git a/libXfont/src/fontfile/gunzip.c b/libXfont/src/fontfile/gunzip.c index 52b0a10be..9fa3eed00 100644 --- a/libXfont/src/fontfile/gunzip.c +++ b/libXfont/src/fontfile/gunzip.c @@ -1,225 +1,225 @@ -/* lib/font/fontfile/gunzip.c
- written by Mark Eichin <eichin@kitten.gen.ma.us> September 1996.
- intended for inclusion in X11 public releases. */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/fonts/fontmisc.h>
-#include <X11/fonts/bufio.h>
-#include <zlib.h>
-
-typedef struct _xzip_buf {
- z_stream z;
- int zstat;
- BufChar b[BUFFILESIZE];
- BufChar b_in[BUFFILESIZE];
- BufFilePtr f;
-} xzip_buf;
-
-static int BufZipFileClose ( BufFilePtr f, int flag );
-static int BufZipFileFill ( BufFilePtr f );
-static int BufZipFileSkip ( BufFilePtr f, int c );
-static int BufCheckZipHeader ( BufFilePtr f );
-
-BufFilePtr
-BufFilePushZIP (BufFilePtr f)
-{
- xzip_buf *x;
-
- x = malloc (sizeof (xzip_buf));
- if (!x) return 0;
- /* these are just for raw calloc/free */
- x->z.zalloc = Z_NULL;
- x->z.zfree = Z_NULL;
- x->z.opaque = Z_NULL;
- x->f = f;
-
- /* force inflateInit to allocate it's own history buffer */
- x->z.next_in = Z_NULL;
- x->z.next_out = Z_NULL;
- x->z.avail_in = x->z.avail_out = 0;
-
- /* using negative windowBits sets "nowrap" mode, which turns off
- zlib header checking [undocumented, for gzip compatibility only?] */
- x->zstat = inflateInit2(&(x->z), -MAX_WBITS);
- if (x->zstat != Z_OK) {
- free(x);
- return 0;
- }
-
- /* now that the history buffer is allocated, we provide the data buffer */
- x->z.next_out = x->b;
- x->z.avail_out = BUFFILESIZE;
- x->z.next_out = x->b_in;
- x->z.avail_in = 0;
-
- if (BufCheckZipHeader(x->f)) {
- free(x);
- return 0;
- }
-
- return BufFileCreate((char *)x,
- BufZipFileFill,
- 0,
- BufZipFileSkip,
- BufZipFileClose);
-}
-
-static int
-BufZipFileClose(BufFilePtr f, int flag)
-{
- xzip_buf *x = (xzip_buf *)f->private;
- inflateEnd (&(x->z));
- BufFileClose (x->f, flag);
- free (x);
- return 1;
-}
-
-/* here's the real work.
- -- we need to put stuff in f.buffer, update f.left and f.bufp,
- then return the first byte (or BUFFILEEOF).
- -- to do this, we need to get stuff into avail_in, and next_in,
- and call inflate appropriately.
- -- we may also need to add CRC maintenance - if inflate tells us
- Z_STREAM_END, we then have 4bytes CRC and 4bytes length...
- gzio.c:gzread shows most of the mechanism.
- */
-static int
-BufZipFileFill (BufFilePtr f)
-{
- xzip_buf *x = (xzip_buf *)f->private;
-
- /* we only get called when left == 0... */
- /* but just in case, deal */
- if (f->left >= 0) {
- f->left--;
- return *(f->bufp++);
- }
- /* did we run out last time? */
- switch (x->zstat) {
- case Z_OK:
- break;
- case Z_STREAM_END:
- case Z_DATA_ERROR:
- case Z_ERRNO:
- f->left = 0;
- return BUFFILEEOF;
- default:
- return BUFFILEEOF;
- }
- /* now we work to consume what we can */
- /* let zlib know what we can handle */
- x->z.next_out = x->b;
- x->z.avail_out = BUFFILESIZE;
-
- /* and try to consume all of it */
- while (x->z.avail_out > 0) {
- /* if we don't have anything to work from... */
- if (x->z.avail_in == 0) {
- /* ... fill the z buf from underlying file */
- int i, c;
- for (i = 0; i < sizeof(x->b_in); i++) {
- c = BufFileGet(x->f);
- if (c == BUFFILEEOF) break;
- x->b_in[i] = c;
- }
- x->z.avail_in += i;
- x->z.next_in = x->b_in;
- }
- /* so now we have some output space and some input data */
- x->zstat = inflate(&(x->z), Z_NO_FLUSH);
- /* the inflation output happens in the f buffer directly... */
- if (x->zstat == Z_STREAM_END) {
- /* deal with EOF, crc */
- break;
- }
- if (x->zstat != Z_OK) {
- break;
- }
- }
- f->bufp = x->b;
- f->left = BUFFILESIZE - x->z.avail_out;
-
- if (f->left >= 0) {
- f->left--;
- return *(f->bufp++);
- } else {
- return BUFFILEEOF;
- }
-}
-
-/* there should be a BufCommonSkip... */
-static int
-BufZipFileSkip (BufFilePtr f, int c)
-{
- /* BufFileRawSkip returns the count unchanged.
- BufCompressedSkip returns 0.
- That means it probably never gets called... */
- int retval = c;
- while(c--) {
- int get = BufFileGet(f);
- if (get == BUFFILEEOF) return get;
- }
- return retval;
-}
-
-/* now we need to duplicate check_header */
-/* contents:
- 0x1f, 0x8b -- magic number
- 1 byte -- method (Z_DEFLATED)
- 1 byte -- flags (mask with RESERVED -> fail)
- 4 byte -- time (discard)
- 1 byte -- xflags (discard)
- 1 byte -- "os" code (discard)
- [if flags & EXTRA_FIELD:
- 2 bytes -- LSBfirst length n
- n bytes -- extra data (discard)]
- [if flags & ORIG_NAME:
- n bytes -- null terminated name (discard)]
- [if flags & COMMENT:
- n bytes -- null terminated comment (discard)]
- [if flags & HEAD_CRC:
- 2 bytes -- crc of headers? (discard)]
- */
-
-/* gzip flag byte -- from gzio.c */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
-#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define RESERVED 0xE0 /* bits 5..7: reserved */
-
-#define GET(f) do {c = BufFileGet(f); if (c == BUFFILEEOF) return c;} while(0)
-static int
-BufCheckZipHeader(BufFilePtr f)
-{
- int c, flags;
- GET(f); if (c != 0x1f) return 1; /* magic 1 */
- GET(f); if (c != 0x8b) return 2; /* magic 2 */
- GET(f); if (c != Z_DEFLATED) return 3; /* method */
- GET(f); if (c & RESERVED) return 4; /* reserved flags */
- flags = c;
- GET(f); GET(f); GET(f); GET(f); /* time */
- GET(f); /* xflags */
- GET(f); /* os code */
- if (flags & EXTRA_FIELD) {
- int len;
- GET(f); len = c;
- GET(f); len += (c<<8);
- while (len-- >= 0) {
- GET(f);
- }
- }
- if (flags & ORIG_NAME) {
- do { GET(f); } while (c != 0);
- }
- if (flags & COMMENT) {
- do { GET(f); } while (c != 0);
- }
- if (flags & HEAD_CRC) {
- GET(f); GET(f); /* header crc */
- }
- return 0;
-}
+/* lib/font/fontfile/gunzip.c + written by Mark Eichin <eichin@kitten.gen.ma.us> September 1996. + intended for inclusion in X11 public releases. */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/fonts/fontmisc.h> +#include <X11/fonts/bufio.h> +#include <zlib.h> + +typedef struct _xzip_buf { + z_stream z; + int zstat; + BufChar b[BUFFILESIZE]; + BufChar b_in[BUFFILESIZE]; + BufFilePtr f; +} xzip_buf; + +static int BufZipFileClose ( BufFilePtr f, int flag ); +static int BufZipFileFill ( BufFilePtr f ); +static int BufZipFileSkip ( BufFilePtr f, int c ); +static int BufCheckZipHeader ( BufFilePtr f ); + +BufFilePtr +BufFilePushZIP (BufFilePtr f) +{ + xzip_buf *x; + + x = malloc (sizeof (xzip_buf)); + if (!x) return 0; + /* these are just for raw calloc/free */ + x->z.zalloc = Z_NULL; + x->z.zfree = Z_NULL; + x->z.opaque = Z_NULL; + x->f = f; + + /* force inflateInit to allocate it's own history buffer */ + x->z.next_in = Z_NULL; + x->z.next_out = Z_NULL; + x->z.avail_in = x->z.avail_out = 0; + + /* using negative windowBits sets "nowrap" mode, which turns off + zlib header checking [undocumented, for gzip compatibility only?] */ + x->zstat = inflateInit2(&(x->z), -MAX_WBITS); + if (x->zstat != Z_OK) { + free(x); + return 0; + } + + /* now that the history buffer is allocated, we provide the data buffer */ + x->z.next_out = x->b; + x->z.avail_out = BUFFILESIZE; + x->z.next_out = x->b_in; + x->z.avail_in = 0; + + if (BufCheckZipHeader(x->f)) { + free(x); + return 0; + } + + return BufFileCreate((char *)x, + BufZipFileFill, + 0, + BufZipFileSkip, + BufZipFileClose); +} + +static int +BufZipFileClose(BufFilePtr f, int flag) +{ + xzip_buf *x = (xzip_buf *)f->private; + inflateEnd (&(x->z)); + BufFileClose (x->f, flag); + free (x); + return 1; +} + +/* here's the real work. + -- we need to put stuff in f.buffer, update f.left and f.bufp, + then return the first byte (or BUFFILEEOF). + -- to do this, we need to get stuff into avail_in, and next_in, + and call inflate appropriately. + -- we may also need to add CRC maintenance - if inflate tells us + Z_STREAM_END, we then have 4bytes CRC and 4bytes length... + gzio.c:gzread shows most of the mechanism. + */ +static int +BufZipFileFill (BufFilePtr f) +{ + xzip_buf *x = (xzip_buf *)f->private; + + /* we only get called when left == 0... */ + /* but just in case, deal */ + if (f->left >= 0) { + f->left--; + return *(f->bufp++); + } + /* did we run out last time? */ + switch (x->zstat) { + case Z_OK: + break; + case Z_STREAM_END: + case Z_DATA_ERROR: + case Z_ERRNO: + f->left = 0; + return BUFFILEEOF; + default: + return BUFFILEEOF; + } + /* now we work to consume what we can */ + /* let zlib know what we can handle */ + x->z.next_out = x->b; + x->z.avail_out = BUFFILESIZE; + + /* and try to consume all of it */ + while (x->z.avail_out > 0) { + /* if we don't have anything to work from... */ + if (x->z.avail_in == 0) { + /* ... fill the z buf from underlying file */ + int i, c; + for (i = 0; i < sizeof(x->b_in); i++) { + c = BufFileGet(x->f); + if (c == BUFFILEEOF) break; + x->b_in[i] = c; + } + x->z.avail_in += i; + x->z.next_in = x->b_in; + } + /* so now we have some output space and some input data */ + x->zstat = inflate(&(x->z), Z_NO_FLUSH); + /* the inflation output happens in the f buffer directly... */ + if (x->zstat == Z_STREAM_END) { + /* deal with EOF, crc */ + break; + } + if (x->zstat != Z_OK) { + break; + } + } + f->bufp = x->b; + f->left = BUFFILESIZE - x->z.avail_out; + + if (f->left >= 0) { + f->left--; + return *(f->bufp++); + } else { + return BUFFILEEOF; + } +} + +/* there should be a BufCommonSkip... */ +static int +BufZipFileSkip (BufFilePtr f, int c) +{ + /* BufFileRawSkip returns the count unchanged. + BufCompressedSkip returns 0. + That means it probably never gets called... */ + int retval = c; + while(c--) { + int get = BufFileGet(f); + if (get == BUFFILEEOF) return get; + } + return retval; +} + +/* now we need to duplicate check_header */ +/* contents: + 0x1f, 0x8b -- magic number + 1 byte -- method (Z_DEFLATED) + 1 byte -- flags (mask with RESERVED -> fail) + 4 byte -- time (discard) + 1 byte -- xflags (discard) + 1 byte -- "os" code (discard) + [if flags & EXTRA_FIELD: + 2 bytes -- LSBfirst length n + n bytes -- extra data (discard)] + [if flags & ORIG_NAME: + n bytes -- null terminated name (discard)] + [if flags & COMMENT: + n bytes -- null terminated comment (discard)] + [if flags & HEAD_CRC: + 2 bytes -- crc of headers? (discard)] + */ + +/* gzip flag byte -- from gzio.c */ +#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ +#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */ +#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ +#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ +#define COMMENT 0x10 /* bit 4 set: file comment present */ +#define RESERVED 0xE0 /* bits 5..7: reserved */ + +#define GET(f) do {c = BufFileGet(f); if (c == BUFFILEEOF) return c;} while(0) +static int +BufCheckZipHeader(BufFilePtr f) +{ + int c, flags; + GET(f); if (c != 0x1f) return 1; /* magic 1 */ + GET(f); if (c != 0x8b) return 2; /* magic 2 */ + GET(f); if (c != Z_DEFLATED) return 3; /* method */ + GET(f); if (c & RESERVED) return 4; /* reserved flags */ + flags = c; + GET(f); GET(f); GET(f); GET(f); /* time */ + GET(f); /* xflags */ + GET(f); /* os code */ + if (flags & EXTRA_FIELD) { + int len; + GET(f); len = c; + GET(f); len += (c<<8); + while (len-- >= 0) { + GET(f); + } + } + if (flags & ORIG_NAME) { + do { GET(f); } while (c != 0); + } + if (flags & COMMENT) { + do { GET(f); } while (c != 0); + } + if (flags & HEAD_CRC) { + GET(f); GET(f); /* header crc */ + } + return 0; +} diff --git a/libXfont/src/fontfile/renderers.c b/libXfont/src/fontfile/renderers.c index 8adb05e1c..e17d6a77e 100644 --- a/libXfont/src/fontfile/renderers.c +++ b/libXfont/src/fontfile/renderers.c @@ -1,115 +1,115 @@ -/*
-
-Copyright 1991, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-/*
- * Author: Keith Packard, MIT X Consortium
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/fonts/fntfilst.h>
-#include <unistd.h>
-extern void ErrorF(const char *f, ...);
-
-static FontRenderersRec renderers;
-
-/*
- * XXX Maybe should allow unregistering renders. For now, just clear the
- * list at each new generation.
- */
-extern unsigned long serverGeneration;
-static unsigned long rendererGeneration = 0;
-
-Bool
-FontFileRegisterRenderer (FontRendererPtr renderer)
-{
- return FontFilePriorityRegisterRenderer(renderer, 0);
-}
-
-Bool
-FontFilePriorityRegisterRenderer (FontRendererPtr renderer, int priority)
-{
- int i;
- struct _FontRenderersElement *new;
-
- if (rendererGeneration != serverGeneration) {
- rendererGeneration = serverGeneration;
- renderers.number = 0;
- if (renderers.renderers)
- free(renderers.renderers);
- renderers.renderers = NULL;
- }
-
- for (i = 0; i < renderers.number; i++) {
- if (!strcasecmp (renderers.renderers[i].renderer->fileSuffix,
- renderer->fileSuffix)) {
- if(renderers.renderers[i].priority >= priority) {
- if(renderers.renderers[i].priority == priority) {
- if (rendererGeneration == 1)
- ErrorF("Warning: font renderer for \"%s\" "
- "already registered at priority %d\n",
- renderer->fileSuffix, priority);
- }
- return TRUE;
- } else {
- break;
- }
- }
- }
-
- if(i >= renderers.number) {
- new = realloc (renderers.renderers, sizeof(*new) * (i + 1));
- if (!new)
- return FALSE;
- renderers.renderers = new;
- renderers.number = i + 1;
- }
- renderer->number = i;
- renderers.renderers[i].renderer = renderer;
- renderers.renderers[i].priority = priority;
- return TRUE;
-}
-
-FontRendererPtr
-FontFileMatchRenderer (char *fileName)
-{
- int i;
- int fileLen;
- FontRendererPtr r;
-
- fileLen = strlen (fileName);
- for (i = 0; i < renderers.number; i++)
- {
- r = renderers.renderers[i].renderer;
- if (fileLen >= r->fileSuffixLen &&
- !strcasecmp (fileName + fileLen - r->fileSuffixLen, r->fileSuffix))
- {
- return r;
- }
- }
- return 0;
-}
+/* + +Copyright 1991, 1998 The Open Group + +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. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ + +/* + * Author: Keith Packard, MIT X Consortium + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <X11/fonts/fntfilst.h> +#include <unistd.h> +extern void ErrorF(const char *f, ...); + +static FontRenderersRec renderers; + +/* + * XXX Maybe should allow unregistering renders. For now, just clear the + * list at each new generation. + */ +extern unsigned long serverGeneration; +static unsigned long rendererGeneration = 0; + +Bool +FontFileRegisterRenderer (FontRendererPtr renderer) +{ + return FontFilePriorityRegisterRenderer(renderer, 0); +} + +Bool +FontFilePriorityRegisterRenderer (FontRendererPtr renderer, int priority) +{ + int i; + struct _FontRenderersElement *new; + + if (rendererGeneration != serverGeneration) { + rendererGeneration = serverGeneration; + renderers.number = 0; + if (renderers.renderers) + free(renderers.renderers); + renderers.renderers = NULL; + } + + for (i = 0; i < renderers.number; i++) { + if (!strcasecmp (renderers.renderers[i].renderer->fileSuffix, + renderer->fileSuffix)) { + if(renderers.renderers[i].priority >= priority) { + if(renderers.renderers[i].priority == priority) { + if (rendererGeneration == 1) + ErrorF("Warning: font renderer for \"%s\" " + "already registered at priority %d\n", + renderer->fileSuffix, priority); + } + return TRUE; + } else { + break; + } + } + } + + if(i >= renderers.number) { + new = realloc (renderers.renderers, sizeof(*new) * (i + 1)); + if (!new) + return FALSE; + renderers.renderers = new; + renderers.number = i + 1; + } + renderer->number = i; + renderers.renderers[i].renderer = renderer; + renderers.renderers[i].priority = priority; + return TRUE; +} + +FontRendererPtr +FontFileMatchRenderer (char *fileName) +{ + int i; + int fileLen; + FontRendererPtr r; + + fileLen = strlen (fileName); + for (i = 0; i < renderers.number; i++) + { + r = renderers.renderers[i].renderer; + if (fileLen >= r->fileSuffixLen && + !strcasecmp (fileName + fileLen - r->fileSuffixLen, r->fileSuffix)) + { + return r; + } + } + return 0; +} |