diff options
author | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 15:54:40 +0000 |
---|---|---|
committer | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 15:54:40 +0000 |
commit | 153e8da44452905ae04a0e20ad0d85f40399b4ca (patch) | |
tree | b4e614de58d4b596dab3dcc7fd4054ec96db592a /src/fontfile |
R6.6 is the Xorg base-lineXORG-MAIN
Diffstat (limited to 'src/fontfile')
-rw-r--r-- | src/fontfile/bitsource.c | 173 | ||||
-rw-r--r-- | src/fontfile/bufio.c | 219 | ||||
-rw-r--r-- | src/fontfile/decompress.c | 408 | ||||
-rw-r--r-- | src/fontfile/defaults.c | 72 | ||||
-rw-r--r-- | src/fontfile/dirfile.c | 443 | ||||
-rw-r--r-- | src/fontfile/ffcheck.c | 183 | ||||
-rw-r--r-- | src/fontfile/fileio.c | 83 | ||||
-rw-r--r-- | src/fontfile/filewr.c | 63 | ||||
-rw-r--r-- | src/fontfile/fontdir.c | 762 | ||||
-rw-r--r-- | src/fontfile/fontfile.c | 1119 | ||||
-rw-r--r-- | src/fontfile/fontscale.c | 453 | ||||
-rw-r--r-- | src/fontfile/gunzip.c | 224 | ||||
-rw-r--r-- | src/fontfile/printerfont.c | 216 | ||||
-rw-r--r-- | src/fontfile/register.c | 50 | ||||
-rw-r--r-- | src/fontfile/renderers.c | 77 |
15 files changed, 4545 insertions, 0 deletions
diff --git a/src/fontfile/bitsource.c b/src/fontfile/bitsource.c new file mode 100644 index 0000000..ac77875 --- /dev/null +++ b/src/fontfile/bitsource.c @@ -0,0 +1,173 @@ +/* $Xorg: bitsource.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +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 + */ + +#include "fntfilst.h" + +BitmapSourcesRec FontFileBitmapSources; + +Bool +FontFileRegisterBitmapSource (fpe) + 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 = (FontPathElementPtr *) xrealloc (FontFileBitmapSources.fpe, newsize * sizeof *new); + if (!new) + return FALSE; + FontFileBitmapSources.size = newsize; + FontFileBitmapSources.fpe = new; + } + FontFileBitmapSources.fpe[FontFileBitmapSources.count++] = fpe; + return TRUE; +} + +void +FontFileUnregisterBitmapSource (fpe) + 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; + xfree (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() +{ + if (FontFileBitmapSources.count == 0) + return; + + FontFileBitmapSources.count = 0; + FontFileBitmapSources.size = 0; + xfree (FontFileBitmapSources.fpe); + FontFileBitmapSources.fpe = 0; +} + +int +FontFileMatchBitmapSource (fpe, pFont, flags, entry, zeroPat, vals, format, fmask, noSpecificSize) + 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/src/fontfile/bufio.c b/src/fontfile/bufio.c new file mode 100644 index 0000000..40293c5 --- /dev/null +++ b/src/fontfile/bufio.c @@ -0,0 +1,219 @@ +/* $Xorg: bufio.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +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 + */ + + +#include <X11/Xos.h> +#include <fontmisc.h> +#include <bufio.h> +#include <errno.h> +#ifdef X_NOT_STDC_ENV +extern int errno; +#endif + +BufFilePtr +BufFileCreate (private, io, skip, close) + char *private; + int (*io)(); + int (*skip)(); + int (*close)(); +{ + BufFilePtr f; + + f = (BufFilePtr) xalloc (sizeof *f); + if (!f) + return 0; + f->private = private; + f->bufp = f->buffer; + f->left = 0; + f->io = io; + f->skip = skip; + f->close = close; + return f; +} + +#define FileDes(f) ((int) (f)->private) + +static int +BufFileRawFill (f) + 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 (f, count) + 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 (f, doClose) + BufFilePtr f; +{ + if (doClose) + close (FileDes (f)); + return 1; +} + +BufFilePtr +BufFileOpenRead (fd) + int fd; +{ + return BufFileCreate ((char *) fd, BufFileRawFill, BufFileRawSkip, BufFileRawClose); +} + +static int +BufFileRawFlush (c, f) + 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; +} + +BufFilePtr +BufFileOpenWrite (fd) + int fd; +{ + BufFilePtr f; + + f = BufFileCreate ((char *) fd, BufFileRawFlush, 0, BufFileFlush); + f->bufp = f->buffer; + f->left = BUFFILESIZE; + return f; +} + +int +BufFileRead (f, b, n) + 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 (f, b, n) + BufFilePtr f; + char *b; + int n; +{ + int cnt; + cnt = n; + while (cnt--) { + if (BufFilePut (*b++, f) == BUFFILEEOF) + return BUFFILEEOF; + } + return n; +} + +int +BufFileFlush (f) + BufFilePtr f; +{ + if (f->bufp != f->buffer) + return (*f->io) (BUFFILEEOF, f); + return 0; +} + +int +BufFileClose (f, doClose) + BufFilePtr f; + int doClose; +{ + int ret; + ret = (*f->close) (f, doClose); + xfree (f); + return ret; +} + +void +BufFileFree (f) + BufFilePtr f; +{ + xfree (f); +} diff --git a/src/fontfile/decompress.c b/src/fontfile/decompress.c new file mode 100644 index 0000000..aef4461 --- /dev/null +++ b/src/fontfile/decompress.c @@ -0,0 +1,408 @@ +/* $Xorg: decompress.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ +/* + * 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 + */ + +#include "fontmisc.h" +#include <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 */ + +static code_int getcode(); + +/* + * 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 BufCompressedFill(), BufCompressedSkip(), BufCompressedClose(); + +BufFilePtr +BufFilePushCompressed (f) + 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); + 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 = (CompressedFile *) xalloc (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, + BufCompressedSkip, + BufCompressedClose); +} + +static int +BufCompressedClose (f, doClose) + BufFilePtr f; +{ + CompressedFile *file; + BufFilePtr raw; + + file = (CompressedFile *) f->private; + raw = file->file; + xfree (file); + BufFileClose (raw, doClose); + return 1; +} + +static int +BufCompressedFill (f) + 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 ) + { + *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(file) + 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 (f, bytes) + BufFilePtr f; + int bytes; +{ + int c; + while (bytes--) + { + c = BufFileGet(f); + if (c == BUFFILEEOF) + return BUFFILEEOF; + } + return 0; +} + +#ifdef TEST +main (argc, argv) + int argc; + char **argv; +{ + BufFilePtr inputraw, input, output; + int c; + + inputraw = BufFileOpenRead (0); + input = BufFilePushCompressed (inputraw); + output = BufFileOpenWrite (1); + while ((c = BufFileGet (input)) != -1) + BufFilePut (c, output); + BufFileClose (input, FALSE); + BufFileClose (output, FALSE); +} +#endif diff --git a/src/fontfile/defaults.c b/src/fontfile/defaults.c new file mode 100644 index 0000000..2738287 --- /dev/null +++ b/src/fontfile/defaults.c @@ -0,0 +1,72 @@ +/* $Xorg: defaults.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +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 + */ + +#include <X11/X.h> +#include <X11/Xproto.h> +#include <servermd.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 + +FontDefaultFormat (bit, byte, glyph, scan) + int *bit, *byte, *glyph, *scan; +{ + *bit = DEFAULT_BIT_ORDER; + *byte = DEFAULT_BYTE_ORDER; + *glyph = DEFAULT_GLYPH_PAD; + *scan = DEFAULT_SCAN_UNIT; +} diff --git a/src/fontfile/dirfile.c b/src/fontfile/dirfile.c new file mode 100644 index 0000000..82f0d10 --- /dev/null +++ b/src/fontfile/dirfile.c @@ -0,0 +1,443 @@ +/* $Xorg: dirfile.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +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 + */ + +#include "fntfilst.h" +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> +#ifdef X_NOT_STDC_ENV +extern int errno; +#endif + +static int ReadFontAlias(); + +int +FontFileReadDirectory (directory, pdir) + char *directory; + FontDirectoryPtr *pdir; +{ + char file_name[MAXFONTFILENAMELEN]; + char font_name[MAXFONTNAMELEN]; + char dir_file[MAXFONTFILENAMELEN]; + FILE *file; + int count, + i, + status; + struct stat statb; + static char format[24] = ""; + + FontDirectoryPtr dir = NullFontDirectory; + + strcpy(dir_file, directory); + if (directory[strlen(directory) - 1] != '/') + strcat(dir_file, "/"); + strcat(dir_file, FontDirFile); + file = fopen(dir_file, "r"); + if (file) { + if (fstat (fileno(file), &statb) == -1) + return BadFontPath; + count = fscanf(file, "%d\n", &i); + if ((count == EOF) || (count != 1)) { + fclose(file); + return BadFontPath; + } + dir = FontFileMakeDir(directory, i); + 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 (count != 2) { + FontFileFreeDir (dir); + fclose(file); + return BadFontPath; + } + if (!FontFileAddFontFile (dir, font_name, file_name)) + { + FontFileFreeDir (dir); + fclose(file); + return BadFontPath; + } + } + fclose(file); + } else if (errno != ENOENT) { + return BadFontPath; + } + status = ReadFontAlias(directory, FALSE, &dir); + if (status != Successful) { + if (dir) + FontFileFreeDir (dir); + return status; + } + if (!dir) + return BadFontPath; + + FontFileSortDir(dir); + + *pdir = dir; + return Successful; +} + +Bool +FontFileDirectoryChanged(dir) + FontDirectoryPtr dir; +{ + char dir_file[MAXFONTNAMELEN]; + struct stat statb; + + 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; + 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(dir) + FontDirectoryPtr dir; +{ + int i; + char copy[MAXFONTNAMELEN]; + 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; + 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 + */ + +static int lexAlias(), lexc(); + +#define NAME 0 +#define NEWLINE 1 +#define DONE 2 +#define EALLOC 3 + +static int +ReadFontAlias(directory, isFile, pdir) + char *directory; + Bool isFile; + FontDirectoryPtr *pdir; +{ + char alias[MAXFONTNAMELEN]; + char font_name[MAXFONTNAMELEN]; + char alias_file[MAXFONTNAMELEN]; + FILE *file; + FontDirectoryPtr dir; + int token; + char *lexToken; + int status = Successful; + struct stat statb; + + dir = *pdir; + strcpy(alias_file, directory); + if (!isFile) { + if (directory[strlen(directory) - 1] != '/') + strcat(alias_file, "/"); + strcat(alias_file, FontAliasFile); + } + file = fopen(alias_file, "r"); + if (!file) + return ((errno == ENOENT) ? Successful : BadFontPath); + if (!dir) + *pdir = dir = FontFileMakeDir(directory, 10); + if (!dir) + { + fclose (file); + return AllocError; + } + if (fstat (fileno (file), &statb) == -1) + { + 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: + 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: + CopyISOLatin1Lowered((unsigned char *) alias, + (unsigned char *) alias, + strlen(alias)); + CopyISOLatin1Lowered((unsigned char *) font_name, + (unsigned char *) 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, lexToken) + 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 = (char *) xrealloc(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; + } + *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 *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 '\n': + charClass = NL; + break; + case '!': + charClass = BANG; + break; + default: + charClass = NORMAL; + break; + } + return c; +} diff --git a/src/fontfile/ffcheck.c b/src/fontfile/ffcheck.c new file mode 100644 index 0000000..6f29801 --- /dev/null +++ b/src/fontfile/ffcheck.c @@ -0,0 +1,183 @@ +/* $Xorg: ffcheck.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +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 + */ +/* $NCDId: @(#)fontfile.c,v 1.6 1991/07/02 17:00:46 lemke Exp $ */ + +#include "fntfilst.h" + +/* + * Map FPE functions to renderer functions + */ + +extern int FontFileNameCheck(); +extern int FontFileInitFPE(); +extern int FontFileResetFPE(); +extern int FontFileFreeFPE(); +extern void FontFileCloseFont(); + + +/* Here we must check the client to see if it has a context attached to + * it that allows us to access the printer fonts + */ + +int +FontFileCheckOpenFont (client, fpe, flags, name, namelen, format, fmask, + id, pFont, aliasName, non_cachable_font) + pointer client; + FontPathElementPtr fpe; + int flags; + char *name; + int namelen; + fsBitmapFormat format; + fsBitmapFormatMask fmask; + XID id; + FontPtr *pFont; + char **aliasName; + FontPtr non_cachable_font; +{ + if (XpClientIsBitmapClient(client)) + return (FontFileOpenFont (client, fpe, flags, name, namelen, format, + fmask, id, pFont, aliasName, non_cachable_font)); + return BadFontName; +} + +int +FontFileCheckListFonts (client, fpe, pat, len, max, names) + pointer client; + FontPathElementPtr fpe; + char *pat; + int len; + int max; + FontNamesPtr names; +{ + if (XpClientIsBitmapClient(client)) + return FontFileListFonts (client, fpe, pat, len, max, names); + return BadFontName; +} + +int +FontFileCheckStartListFontsWithInfo(client, fpe, pat, len, max, privatep) + pointer client; + FontPathElementPtr fpe; + char *pat; + int len; + int max; + pointer *privatep; +{ + if (XpClientIsBitmapClient(client)) + return FontFileStartListFontsWithInfo(client, fpe, pat, len, + max, privatep); + return BadFontName; +} + +int +FontFileCheckListNextFontWithInfo(client, fpe, namep, namelenp, pFontInfo, + numFonts, private) + pointer client; + FontPathElementPtr fpe; + char **namep; + int *namelenp; + FontInfoPtr *pFontInfo; + int *numFonts; + pointer private; +{ + if (XpClientIsBitmapClient(client)) + return FontFileListNextFontWithInfo(client, fpe, namep, namelenp, + pFontInfo, numFonts, private); + return BadFontName; +} + +int +FontFileCheckStartListFontsAndAliases(client, fpe, pat, len, max, privatep) + pointer client; + FontPathElementPtr fpe; + char *pat; + int len; + int max; + pointer *privatep; +{ + if (XpClientIsBitmapClient(client)) + return FontFileStartListFontsAndAliases(client, fpe, pat, len, + max, privatep); + return BadFontName; +} + +int +FontFileCheckListNextFontOrAlias(client, fpe, namep, namelenp, resolvedp, + resolvedlenp, private) + pointer client; + FontPathElementPtr fpe; + char **namep; + int *namelenp; + char **resolvedp; + int *resolvedlenp; + pointer private; +{ + if (XpClientIsBitmapClient(client)) + return FontFileListNextFontOrAlias(client, fpe, namep, namelenp, + resolvedp, resolvedlenp, private); + return BadFontName; +} + +extern void FontFileEmptyBitmapSource(); +typedef int (*IntFunc) (); +static int font_file_check_type; + +void +FontFileCheckRegisterFpeFunctions () +{ + BitmapRegisterFontFileFunctions (); + +#ifndef LOWMEMFTPT + +#ifndef CRAY + SpeedoRegisterFontFileFunctions (); + Type1RegisterFontFileFunctions(); +#endif + +#endif /* ifndef LOWMEMFTPT */ + + font_file_check_type = RegisterFPEFunctions(FontFileNameCheck, + FontFileInitFPE, + FontFileFreeFPE, + FontFileResetFPE, + FontFileCheckOpenFont, + FontFileCloseFont, + FontFileCheckListFonts, + FontFileCheckStartListFontsWithInfo, + FontFileCheckListNextFontWithInfo, + (IntFunc) 0, + (IntFunc) 0, + (IntFunc) 0, + FontFileCheckStartListFontsAndAliases, + FontFileCheckListNextFontOrAlias, + FontFileEmptyBitmapSource); +} diff --git a/src/fontfile/fileio.c b/src/fontfile/fileio.c new file mode 100644 index 0000000..43c84ab --- /dev/null +++ b/src/fontfile/fileio.c @@ -0,0 +1,83 @@ +/* $Xorg: fileio.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +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 + */ + +#include <fntfilio.h> +#include <X11/Xos.h> +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +FontFilePtr +FontFileOpen (name) + 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 + } + return (FontFilePtr) raw; +} + +int +FontFileClose (f) + FontFilePtr f; +{ + return BufFileClose ((BufFilePtr) f, TRUE); +} + diff --git a/src/fontfile/filewr.c b/src/fontfile/filewr.c new file mode 100644 index 0000000..d8ed5b5 --- /dev/null +++ b/src/fontfile/filewr.c @@ -0,0 +1,63 @@ +/* $Xorg: filewr.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +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 + */ + +#include <fntfilio.h> +#include <X11/Xos.h> + +FontFilePtr +FontFileOpenWrite (name) + char *name; +{ + int fd; + +#ifdef WIN32 + 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 (fd) +{ + return (FontFilePtr) BufFileOpenWrite (fd); +} + +FontFilePtr +FontFileOpenFd (fd) + int fd; +{ + return (FontFilePtr) BufFileOpenRead (fd); +} diff --git a/src/fontfile/fontdir.c b/src/fontfile/fontdir.c new file mode 100644 index 0000000..beca5af --- /dev/null +++ b/src/fontfile/fontdir.c @@ -0,0 +1,762 @@ +/* $Xorg: fontdir.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +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 + */ + +#include "fntfilst.h" +#include <X11/keysym.h> + +Bool +FontFileInitTable (table, size) + FontTablePtr table; + int size; +{ + if (size) + { + table->entries = (FontEntryPtr) xalloc(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 (entry) + FontEntryPtr entry; +{ + FontScalableExtraPtr extra; + int i; + + if (entry->name.name) + xfree(entry->name.name); + + switch (entry->type) + { + case FONT_ENTRY_SCALABLE: + xfree (entry->u.scalable.fileName); + extra = entry->u.scalable.extra; + for (i = 0; i < extra->numScaled; i++) + if (extra->scaled[i].vals.ranges) + xfree (extra->scaled[i].vals.ranges); + xfree (extra->scaled); + xfree (extra); + break; + case FONT_ENTRY_BITMAP: + xfree (entry->u.bitmap.fileName); + break; + case FONT_ENTRY_ALIAS: + xfree (entry->u.alias.resolved); + break; +#ifdef NOTYET + case FONT_ENTRY_BC: + break; +#endif + } +} + +void +FontFileFreeTable (table) + FontTablePtr table; +{ + int i; + + for (i = 0; i < table->used; i++) + FontFileFreeEntry (&table->entries[i]); + xfree (table->entries); +} + +FontDirectoryPtr +FontFileMakeDir(dirName, size) + char *dirName; + int size; +{ + FontDirectoryPtr dir; + int dirlen; + int needslash = 0; + + dirlen = strlen(dirName); + if (dirName[dirlen - 1] != '/') +#ifdef NCD + if (dirlen) /* leave out slash for builtins */ +#endif + needslash = 1; + dir = (FontDirectoryPtr) xalloc(sizeof *dir + dirlen + needslash + 1); + if (!dir) + return (FontDirectoryPtr)0; + if (!FontFileInitTable (&dir->scalable, 0)) + { + xfree (dir); + return (FontDirectoryPtr)0; + } + if (!FontFileInitTable (&dir->nonScalable, size)) + { + FontFileFreeTable (&dir->scalable); + xfree (dir); + return (FontDirectoryPtr)0; + } + dir->directory = (char *) (dir + 1); + dir->dir_mtime = 0; + dir->alias_mtime = 0; + strcpy(dir->directory, dirName); + if (needslash) + strcat(dir->directory, "/"); + return dir; +} + +void +FontFileFreeDir (dir) + FontDirectoryPtr dir; +{ + FontFileFreeTable (&dir->scalable); + FontFileFreeTable (&dir->nonScalable); + xfree(dir); +} + +FontEntryPtr +FontFileAddEntry(table, prototype) + 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 = (FontEntryPtr) xrealloc(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 = (char *) xalloc(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; +} + +static int +#ifdef NeedFunctionPrototypes +FontFileNameCompare(const void* a, const void* b) +#else +FontFileNameCompare(a, b) + char *a, + *b; +#endif +{ + FontEntryPtr a_name = (FontEntryPtr) a, + b_name = (FontEntryPtr) b; + + return strcmp(a_name->name.name, b_name->name.name); +} + +void +FontFileSortTable (table) + FontTablePtr table; +{ + if (!table->sorted) { + qsort((char *) table->entries, table->used, sizeof(FontEntryRec), + FontFileNameCompare); + table->sorted = TRUE; + } +} + +void +FontFileSortDir(dir) + 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) + +static int +SetupWildMatch(table, pat, leftp, rightp, privatep) + FontTablePtr table; + FontNamePtr pat; + int *leftp, + *rightp; + int *privatep; +{ + int nDashes; + char c; + char *t; + char *firstWild; + int first; + int center, + left, + right; + int result; + char *name; + + name = pat->name; + nDashes = pat->ndashes; + firstWild = 0; + t = name; + while ((c = *t++)) { + if (isWild(c)) { + if (!firstWild) + firstWild = 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) { + 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 = strcmp(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(pat, patdashes, string, stringdashes) + char *pat; + char *string; +{ + 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 (name, namelen) + char *name; + int namelen; +{ + int ndashes = 0; + + while (namelen--) + if (*name++ == '\055') /* avoid non ascii systems */ + ++ndashes; + return ndashes; +} + +char * +FontFileSaveString (s) + char *s; +{ + char *n; + + n = (char *) xalloc (strlen (s) + 1); + if (!n) + return 0; + strcpy (n, s); + return n; +} + +FontEntryPtr +FontFileFindNameInScalableDir(table, pat, vals) + FontTablePtr table; + FontNamePtr pat; + FontScalablePtr vals; +{ + int i, + start, + stop, + res, + private; + FontNamePtr name; + + 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(table, pat) + FontTablePtr table; + FontNamePtr pat; +{ + return FontFileFindNameInScalableDir(table, pat, (FontScalablePtr)0); +} + +int +FontFileFindNamesInScalableDir(table, pat, max, names, vals, + alias_behavior, newmax) + 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(table, pat, max, names) + FontTablePtr table; + FontNamePtr pat; + int max; + FontNamesPtr names; +{ + return FontFileFindNamesInScalableDir(table, pat, max, names, + (FontScalablePtr)0, + NORMAL_ALIAS_BEHAVIOR, (int *)0); +} + +Bool +FontFileMatchName(name, length, pat) + 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 (dir, fontName, fileName) + FontDirectoryPtr dir; + char *fontName; + char *fileName; +{ + FontEntryRec entry; + FontScalableRec vals, zeroVals; + FontRendererPtr renderer; + FontEntryPtr existing; + FontScalableExtraPtr extra; + FontEntryPtr bitmap, scalable; + Bool isscale; + + 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); + if (!isscale || (vals.values_supplied & SIZE_SPECIFY_MASK)) + { + /* If the fontname says it is nonScalable, make sure that the + * renderer supports OpenBitmap and GetInfoBitmap. + */ + if (renderer->OpenBitmap && renderer->GetInfoBitmap) + { + 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))) + { + xfree (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 the fontname says it is scalable, make sure that the + * renderer supports OpenScalable and GetInfoScalable. + */ + if (renderer->OpenScalable && renderer->GetInfoScalable) + { + 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; + + xfree (existing->u.scalable.fileName); + if (!(existing->u.scalable.fileName = FontFileSaveString (fileName))) + return FALSE; + } + FontFileCompleteXLFD(&vals, &vals); + FontFileAddScaledInstance (existing, &vals, NullFont, + bitmap->name.name); + return TRUE; + } + } + if (!(entry.u.scalable.fileName = FontFileSaveString (fileName))) + return FALSE; + extra = (FontScalableExtraPtr) xalloc (sizeof (FontScalableExtraRec)); + if (!extra) + { + xfree (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; + + extra->defaults.point_matrix[0] = + extra->defaults.point_matrix[3] = + (double)GetDefaultPointSize() / 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))) + { + xfree (extra); + xfree (entry.u.scalable.fileName); + return FALSE; + } + if (vals.values_supplied & SIZE_SPECIFY_MASK) + { + FontFileCompleteXLFD(&vals, &vals); + FontFileAddScaledInstance (scalable, &vals, NullFont, + bitmap->name.name); + } + } + } + return TRUE; +} + +Bool +FontFileAddFontAlias (dir, aliasName, fontName) + FontDirectoryPtr dir; + char *aliasName; + char *fontName; +{ + FontEntryRec entry; + + 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)) + { + xfree (entry.u.alias.resolved); + return FALSE; + } + return TRUE; +} diff --git a/src/fontfile/fontfile.c b/src/fontfile/fontfile.c new file mode 100644 index 0000000..5230a15 --- /dev/null +++ b/src/fontfile/fontfile.c @@ -0,0 +1,1119 @@ +/* $Xorg: fontfile.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +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 + */ +/* $NCDId: @(#)fontfile.c,v 1.6 1991/07/02 17:00:46 lemke Exp $ */ + +#include "fntfilst.h" + +/* + * Map FPE functions to renderer functions + */ + +int +FontFileNameCheck (name) + char *name; +{ +#ifndef NCD + return *name == '/'; +#else + return ((strcmp(name, "built-ins") == 0) || (*name == '/')); +#endif +} + +int +FontFileInitFPE (fpe) + 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 (fpe) + FontPathElementPtr fpe; +{ + FontDirectoryPtr dir; + + dir = (FontDirectoryPtr) fpe->private; + 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 (fpe) + FontPathElementPtr fpe; +{ + FontFileUnregisterBitmapSource (fpe); + FontFileFreeDir ((FontDirectoryPtr) fpe->private); + return Successful; +} + +static int +transfer_values_to_alias(entryname, entrynamelength, resolvedname, + aliasName, vals) + 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 && + 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)) + { + double hypot(); + 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 (client, fpe, flags, name, namelen, format, fmask, + id, pFont, aliasName, non_cachable_font) + pointer client; + FontPathElementPtr fpe; + int 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; +#ifdef NOTYET + case FONT_ENTRY_BC: + bc = &entry->u.bc; + entry = bc->entry; + ret = (*scalable->renderer->OpenScalable) + (fpe, pFont, flags, entry, &bc->vals, format, fmask, + non_cachable_font); + if (ret == Successful && *pFont) + (*pFont)->fpe = fpe; + break; +#endif + default: + ret = BadFontName; + } + } + else + { + ret = BadFontName; + } + + if (ret != BadFontName) + { + if (ranges) xfree(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; + + strcpy (fileName, dir->directory); + strcat (fileName, scalable->fileName); + ret = (*scalable->renderer->OpenScalable) (fpe, pFont, + flags, entry, fileName, &vals, 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) + xfree(ranges); + return ret; +} + +/* ARGSUSED */ +void +FontFileCloseFont (fpe, pFont) + 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); +} + +int +FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask, + non_cachable_font) + FontPathElementPtr fpe; + int flags; + FontEntryPtr entry; + FontPtr *pFont; + FontPtr non_cachable_font; +{ + FontBitmapEntryPtr bitmap; + char fileName[MAXFONTFILENAMELEN*2+1]; + int ret; + FontDirectoryPtr dir; + + dir = (FontDirectoryPtr) fpe->private; + bitmap = &entry->u.bitmap; + 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 (fpe, pFont, flags, entry, format, fmask) + FontPathElementPtr fpe; + int flags; + FontEntryPtr entry; + FontPtr *pFont; +{ + return FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask, + (FontPtr)0); +} + +int +FontFileGetInfoBitmap (fpe, pFontInfo, entry) + 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; + strcpy (fileName, dir->directory); + strcat (fileName, bitmap->fileName); + ret = (*bitmap->renderer->GetInfoBitmap) (fpe, pFontInfo, entry, fileName); + return ret; +} + +static void +_FontFileAddScalableNames(names, scaleNames, nameptr, zeroChars, vals, ranges, + nranges, max) + 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 (client, fpe, pat, len, max, names, mark_aliases) + 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) xfree(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) xfree(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) xfree(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 (client, fpe, pat, len, max, names) + pointer client; + FontPathElementPtr fpe; + char *pat; + int len; + int max; + FontNamesPtr names; +{ + return _FontFileListFonts (client, fpe, pat, len, max, names, 0); +} + +int +FontFileStartListFontsWithInfo(client, fpe, pat, len, max, privatep) + pointer client; + FontPathElementPtr fpe; + char *pat; + int len; + int max; + pointer *privatep; +{ + LFWIDataPtr data; + int ret; + + data = (LFWIDataPtr) xalloc (sizeof *data); + if (!data) + return AllocError; + data->names = MakeFontNamesRecord (0); + if (!data->names) + { + xfree (data); + return AllocError; + } + ret = FontFileListFonts (client, fpe, pat, len, max, data->names); + if (ret != Successful) + { + FreeFontNames (data->names); + xfree (data); + return ret; + } + data->current = 0; + *privatep = (pointer) data; + return Successful; +} + +/* ARGSUSED */ +static int +FontFileListOneFontWithInfo (client, fpe, namep, namelenp, pFontInfo) + 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; + FontAliasEntryPtr alias; + int ret; + char *name = *namep; + int namelen = *namelenp; + Bool noSpecificSize; + + if (namelen >= MAXFONTNAMELEN) + return AllocError; + dir = (FontDirectoryPtr) fpe->private; + CopyISOLatin1Lowered (lowerName, name, namelen); + lowerName[namelen] = '\0'; + tmpName.name = lowerName; + tmpName.length = namelen; + tmpName.ndashes = FontFileCountDashes (lowerName, namelen); + /* Match XLFD patterns */ + if (tmpName.ndashes == 14 && + FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO)) + { + tmpName.length = strlen (lowerName); + entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals); + 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 + { +#ifdef NOTDEF + /* no special case yet */ + ret = FontFileMatchBitmapSource (fpe, pFont, flags, entry, &vals, format, fmask, noSpecificSize); + if (ret != Successful) +#endif + { + char origName[MAXFONTNAMELEN]; + fsRange *ranges; + + CopyISOLatin1Lowered (origName, name, namelen); + origName[namelen] = '\0'; + vals.xlfdName = origName; + vals.ranges = FontParseRanges(origName, &vals.nranges); + ranges = vals.ranges; + /* Make a new scaled instance */ + strcpy (fileName, dir->directory); + strcat (fileName, scalable->fileName); + ret = (*scalable->renderer->GetInfoScalable) + (fpe, *pFontInfo, entry, &tmpName, fileName, &vals); + if (ranges) xfree(ranges); + } + } + if (ret == Successful) return ret; + } + CopyISOLatin1Lowered (lowerName, name, namelen); + tmpName.length = namelen; + } + /* Match non XLFD pattern */ + if ((entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName))) + { + 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: + alias = &entry->u.alias; + *(char **)pFontInfo = name; + *namelenp = strlen (*namep = alias->resolved); + ret = FontNameAlias; + break; +#ifdef NOTYET + case FONT_ENTRY_BC: + /* no LFWI for this yet */ + bc = &entry->u.bc; + entry = bc->entry; + /* Make a new scaled instance */ + strcpy (fileName, dir->directory); + strcat (fileName, scalable->fileName); + ret = (*scalable->renderer->GetInfoScalable) + (fpe, *pFontInfo, entry, tmpName, fileName, &bc->vals); + break; +#endif + default: + ret = BadFontName; + } + } + else + { + ret = BadFontName; + } + return ret; +} + +int +FontFileListNextFontWithInfo(client, fpe, namep, namelenp, pFontInfo, + numFonts, private) + 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); + xfree (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(client, fpe, pat, len, max, privatep) + pointer client; + FontPathElementPtr fpe; + char *pat; + int len; + int max; + pointer *privatep; +{ + LFWIDataPtr data; + int ret; + + data = (LFWIDataPtr) xalloc (sizeof *data); + if (!data) + return AllocError; + data->names = MakeFontNamesRecord (0); + if (!data->names) + { + xfree (data); + return AllocError; + } + ret = _FontFileListFonts (client, fpe, pat, len, max, data->names, 1); + if (ret != Successful) + { + FreeFontNames (data->names); + xfree (data); + return ret; + } + data->current = 0; + *privatep = (pointer) data; + return Successful; +} + +int +FontFileListNextFontOrAlias(client, fpe, namep, namelenp, resolvedp, + resolvedlenp, private) + 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); + xfree (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; +} + + +extern void FontFileEmptyBitmapSource(); +typedef int (*IntFunc) (); +static int font_file_type; + +void +FontFileRegisterLocalFpeFunctions () +{ + font_file_type = RegisterFPEFunctions(FontFileNameCheck, + FontFileInitFPE, + FontFileFreeFPE, + FontFileResetFPE, + FontFileOpenFont, + FontFileCloseFont, + FontFileListFonts, + FontFileStartListFontsWithInfo, + FontFileListNextFontWithInfo, + (IntFunc) 0, + (IntFunc) 0, + (IntFunc) 0, + FontFileStartListFontsAndAliases, + FontFileListNextFontOrAlias, + FontFileEmptyBitmapSource); +} diff --git a/src/fontfile/fontscale.c b/src/fontfile/fontscale.c new file mode 100644 index 0000000..56ed691 --- /dev/null +++ b/src/fontfile/fontscale.c @@ -0,0 +1,453 @@ +/* $Xorg: fontscale.c,v 1.5 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +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 + */ + +#include "fntfilst.h" +#ifdef _XOPEN_SOURCE +#include <math.h> +#else +#define _XOPEN_SOURCE /* to get prototype for hypot on some systems */ +#include <math.h> +#undef _XOPEN_SOURCE +#endif + +Bool +FontFileAddScaledInstance (entry, vals, pFont, bitmapName) + 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 = (FontScaledPtr) xrealloc (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 (dir) + 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 (entry, pFont) + 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) + xfree (extra->scaled[i].vals.ranges); + extra->numScaled--; + for (; i < extra->numScaled; i++) + extra->scaled[i] = extra->scaled[i+1]; + } + } +} + +Bool +FontFileCompleteXLFD (vals, def) + register 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 (a, b) + FontScalablePtr a, 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->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 (entry, vals, noSpecificSize) + FontEntryPtr entry; + FontScalablePtr vals; +{ + 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/src/fontfile/gunzip.c b/src/fontfile/gunzip.c new file mode 100644 index 0000000..a303f21 --- /dev/null +++ b/src/fontfile/gunzip.c @@ -0,0 +1,224 @@ +/* $Xorg: gunzip.c,v 1.3 2000/08/17 19:46:37 cpqbld Exp $ */ +/* lib/font/fontfile/gunzip.c + written by Mark Eichin <eichin@kitten.gen.ma.us> September 1996. + intended for inclusion in X11 public releases. */ + +#include "fontmisc.h" +#include <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 BufZipFileSkip(); /* f, count */ +static int BufZipFileFill(); /* read: f; write: char, f */ +static int BufZipFileClose(); /* f, flag */ +static int BufCheckZipHeader(); /* f */ + +BufFilePtr +BufFilePushZIP (f) + BufFilePtr f; +{ + xzip_buf *x; + + x = (xzip_buf *) xalloc (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) { + xfree(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)) { + xfree(x); + return 0; + } + + return BufFileCreate(x, + BufZipFileFill, + BufZipFileSkip, + BufZipFileClose); +} + +static int BufZipFileClose(f, flag) + BufFilePtr f; + int flag; +{ + xzip_buf *x = (xzip_buf *)f->private; + inflateEnd (&(x->z)); + BufFileClose (x->f, flag); + xfree (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 (f) + 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: + 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 (f, c) + 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(f) + 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/src/fontfile/printerfont.c b/src/fontfile/printerfont.c new file mode 100644 index 0000000..5632aa5 --- /dev/null +++ b/src/fontfile/printerfont.c @@ -0,0 +1,216 @@ +/* $Xorg: printerfont.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +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 + */ +/* $NCDId: @(#)fontfile.c,v 1.6 1991/07/02 17:00:46 lemke Exp $ */ + +#include "fntfilst.h" + +/* + * Map FPE functions to renderer functions + */ + +extern int FontFileInitFPE(); +extern int FontFileResetFPE(); +extern int FontFileFreeFPE(); +extern void FontFileCloseFont(); +#define PRINTERPATHPREFIX "PRINTER:" + +/* STUB +int XpClientIsPrintClient(client,fpe) +pointer client; +FontPathElementPtr fpe; +{ return 1; } + */ + +int +PrinterFontNameCheck (name) + char *name; +{ + if (strncmp(name,PRINTERPATHPREFIX,strlen(PRINTERPATHPREFIX)) != 0) + return 0; + name += strlen(PRINTERPATHPREFIX); +#ifndef NCD + return *name == '/'; +#else + return ((strcmp(name, "built-ins") == 0) || (*name == '/')); +#endif +} + +int +PrinterFontInitFPE (fpe) + FontPathElementPtr fpe; +{ + int status; + FontDirectoryPtr dir; + char * name; + + name = fpe->name + strlen(PRINTERPATHPREFIX); + status = FontFileReadDirectory (name, &dir); + if (status == Successful) + { + if (dir->nonScalable.used > 0) + if (!FontFileRegisterBitmapSource (fpe)) + { + FontFileFreeFPE (fpe); + return AllocError; + } + fpe->private = (pointer) dir; + } + return status; +} + +/* Here we must check the client to see if it has a context attached to + * it that allows us to access the printer fonts + */ + +int +PrinterFontOpenFont (client, fpe, flags, name, namelen, format, fmask, + id, pFont, aliasName, non_cachable_font) + pointer client; + FontPathElementPtr fpe; + int flags; + char *name; + int namelen; + fsBitmapFormat format; + fsBitmapFormatMask fmask; + XID id; + FontPtr *pFont; + char **aliasName; + FontPtr non_cachable_font; +{ + if (XpClientIsPrintClient(client,fpe)) + return (FontFileOpenFont (client, fpe, flags, name, namelen, format, + fmask, id, pFont, aliasName, non_cachable_font)); + return BadFontName; +} + +int +PrinterFontListFonts (client, fpe, pat, len, max, names) + pointer client; + FontPathElementPtr fpe; + char *pat; + int len; + int max; + FontNamesPtr names; +{ + if (XpClientIsPrintClient(client,fpe)) + return FontFileListFonts (client, fpe, pat, len, max, names); + return BadFontName; +} + +int +PrinterFontStartListFontsWithInfo(client, fpe, pat, len, max, privatep) + pointer client; + FontPathElementPtr fpe; + char *pat; + int len; + int max; + pointer *privatep; +{ + if (XpClientIsPrintClient(client,fpe)) + return FontFileStartListFontsWithInfo(client, fpe, pat, len, + max, privatep); + return BadFontName; +} + +int +PrinterFontListNextFontWithInfo(client, fpe, namep, namelenp, pFontInfo, + numFonts, private) + pointer client; + FontPathElementPtr fpe; + char **namep; + int *namelenp; + FontInfoPtr *pFontInfo; + int *numFonts; + pointer private; +{ + if (XpClientIsPrintClient(client,fpe)) + return FontFileListNextFontWithInfo(client, fpe, namep, namelenp, + pFontInfo, numFonts, private); + return BadFontName; +} + +int +PrinterFontStartListFontsAndAliases(client, fpe, pat, len, max, privatep) + pointer client; + FontPathElementPtr fpe; + char *pat; + int len; + int max; + pointer *privatep; +{ + if (XpClientIsPrintClient(client,fpe)) + return FontFileStartListFontsAndAliases(client, fpe, pat, len, + max, privatep); + return BadFontName; +} + +int +PrinterFontListNextFontOrAlias(client, fpe, namep, namelenp, resolvedp, + resolvedlenp, private) + pointer client; + FontPathElementPtr fpe; + char **namep; + int *namelenp; + char **resolvedp; + int *resolvedlenp; + pointer private; +{ + if (XpClientIsPrintClient(client,fpe)) + return FontFileListNextFontOrAlias(client, fpe, namep, namelenp, + resolvedp, resolvedlenp, private); + return BadFontName; +} + +extern void FontFileEmptyBitmapSource(); +typedef int (*IntFunc) (); +static int printer_font_type; + +void +PrinterFontRegisterFpeFunctions () +{ + /* what is the use of printer font type? */ + printer_font_type = RegisterFPEFunctions(PrinterFontNameCheck, + PrinterFontInitFPE, + FontFileFreeFPE, + FontFileResetFPE, + PrinterFontOpenFont, + FontFileCloseFont, + PrinterFontListFonts, + PrinterFontStartListFontsWithInfo, + PrinterFontListNextFontWithInfo, + (IntFunc) 0, + (IntFunc) 0, + (IntFunc) 0, + PrinterFontStartListFontsAndAliases, + PrinterFontListNextFontOrAlias, + FontFileEmptyBitmapSource); +} diff --git a/src/fontfile/register.c b/src/fontfile/register.c new file mode 100644 index 0000000..8379f85 --- /dev/null +++ b/src/fontfile/register.c @@ -0,0 +1,50 @@ +/* $Xorg: register.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +Copyright 1994, 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. + +*/ + +/* + * This is in a separate source file so that small programs + * such as mkfontdir that want to use the fontfile utilities don't + * end up dragging in code from all the renderers, which is not small. + */ + +void +FontFileRegisterFpeFunctions() +{ + BitmapRegisterFontFileFunctions (); + +#ifndef LOWMEMFTPT + +#ifndef CRAY + SpeedoRegisterFontFileFunctions (); + Type1RegisterFontFileFunctions(); +#endif + +#endif /* ifndef LOWMEMFTPT */ + + FontFileRegisterLocalFpeFunctions (); +} diff --git a/src/fontfile/renderers.c b/src/fontfile/renderers.c new file mode 100644 index 0000000..c997f27 --- /dev/null +++ b/src/fontfile/renderers.c @@ -0,0 +1,77 @@ +/* $Xorg: renderers.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ + +/* + +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 + */ + +#include "fntfilst.h" + +static FontRenderersRec renderers; + +Bool +FontFileRegisterRenderer (renderer) + FontRendererPtr renderer; +{ + int i; + FontRendererPtr *new; + + for (i = 0; i < renderers.number; i++) + if (!strcmp (renderers.renderers[i]->fileSuffix, renderer->fileSuffix)) + return TRUE; + i = renderers.number + 1; + new = (FontRendererPtr *) xrealloc (renderers.renderers, sizeof *new * i); + if (!new) + return FALSE; + renderer->number = i - 1; + renderers.renderers = new; + renderers.renderers[i - 1] = renderer; + renderers.number = i; + return TRUE; +} + +FontRendererPtr +FontFileMatchRenderer (fileName) + char *fileName; +{ + int i; + int fileLen; + FontRendererPtr r; + + fileLen = strlen (fileName); + for (i = 0; i < renderers.number; i++) + { + r = renderers.renderers[i]; + if (fileLen >= r->fileSuffixLen && + !strcmp (fileName + fileLen - r->fileSuffixLen, r->fileSuffix)) + { + return r; + } + } + return 0; +} |