bitsource.c revision 23a0898a
123a0898aSmrg/* $Xorg: bitsource.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */
223a0898aSmrg
323a0898aSmrg/*
423a0898aSmrg
523a0898aSmrgCopyright 1991, 1998  The Open Group
623a0898aSmrg
723a0898aSmrgPermission to use, copy, modify, distribute, and sell this software and its
823a0898aSmrgdocumentation for any purpose is hereby granted without fee, provided that
923a0898aSmrgthe above copyright notice appear in all copies and that both that
1023a0898aSmrgcopyright notice and this permission notice appear in supporting
1123a0898aSmrgdocumentation.
1223a0898aSmrg
1323a0898aSmrgThe above copyright notice and this permission notice shall be included in
1423a0898aSmrgall copies or substantial portions of the Software.
1523a0898aSmrg
1623a0898aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1723a0898aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1823a0898aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
1923a0898aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
2023a0898aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2123a0898aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2223a0898aSmrg
2323a0898aSmrgExcept as contained in this notice, the name of The Open Group shall not be
2423a0898aSmrgused in advertising or otherwise to promote the sale, use or other dealings
2523a0898aSmrgin this Software without prior written authorization from The Open Group.
2623a0898aSmrg
2723a0898aSmrg*/
2823a0898aSmrg/* $XFree86: xc/lib/font/fontfile/bitsource.c,v 1.3 2001/01/17 19:43:29 dawes Exp $ */
2923a0898aSmrg
3023a0898aSmrg/*
3123a0898aSmrg * Author:  Keith Packard, MIT X Consortium
3223a0898aSmrg */
3323a0898aSmrg
3423a0898aSmrg#ifdef HAVE_CONFIG_H
3523a0898aSmrg#include <config.h>
3623a0898aSmrg#endif
3723a0898aSmrg#include <X11/fonts/fntfilst.h>
3823a0898aSmrg
3923a0898aSmrgBitmapSourcesRec	FontFileBitmapSources;
4023a0898aSmrg
4123a0898aSmrgBool
4223a0898aSmrgFontFileRegisterBitmapSource (FontPathElementPtr fpe)
4323a0898aSmrg{
4423a0898aSmrg    FontPathElementPtr	*new;
4523a0898aSmrg    int			i;
4623a0898aSmrg    int			newsize;
4723a0898aSmrg
4823a0898aSmrg    for (i = 0; i < FontFileBitmapSources.count; i++)
4923a0898aSmrg	if (FontFileBitmapSources.fpe[i] == fpe)
5023a0898aSmrg	    return TRUE;
5123a0898aSmrg    if (FontFileBitmapSources.count == FontFileBitmapSources.size)
5223a0898aSmrg    {
5323a0898aSmrg	newsize = FontFileBitmapSources.size + 4;
5423a0898aSmrg	new = (FontPathElementPtr *) xrealloc (FontFileBitmapSources.fpe, newsize * sizeof *new);
5523a0898aSmrg	if (!new)
5623a0898aSmrg	    return FALSE;
5723a0898aSmrg	FontFileBitmapSources.size = newsize;
5823a0898aSmrg	FontFileBitmapSources.fpe = new;
5923a0898aSmrg    }
6023a0898aSmrg    FontFileBitmapSources.fpe[FontFileBitmapSources.count++] = fpe;
6123a0898aSmrg    return TRUE;
6223a0898aSmrg}
6323a0898aSmrg
6423a0898aSmrgvoid
6523a0898aSmrgFontFileUnregisterBitmapSource (FontPathElementPtr fpe)
6623a0898aSmrg{
6723a0898aSmrg    int	    i;
6823a0898aSmrg
6923a0898aSmrg    for (i = 0; i < FontFileBitmapSources.count; i++)
7023a0898aSmrg	if (FontFileBitmapSources.fpe[i] == fpe)
7123a0898aSmrg	{
7223a0898aSmrg	    FontFileBitmapSources.count--;
7323a0898aSmrg	    if (FontFileBitmapSources.count == 0)
7423a0898aSmrg	    {
7523a0898aSmrg		FontFileBitmapSources.size = 0;
7623a0898aSmrg		xfree (FontFileBitmapSources.fpe);
7723a0898aSmrg		FontFileBitmapSources.fpe = 0;
7823a0898aSmrg	    }
7923a0898aSmrg	    else
8023a0898aSmrg	    {
8123a0898aSmrg	    	for (; i < FontFileBitmapSources.count; i++)
8223a0898aSmrg		    FontFileBitmapSources.fpe[i] = FontFileBitmapSources.fpe[i+1];
8323a0898aSmrg	    }
8423a0898aSmrg	    break;
8523a0898aSmrg	}
8623a0898aSmrg}
8723a0898aSmrg
8823a0898aSmrg/*
8923a0898aSmrg * Our set_path_hook: unregister all bitmap sources.
9023a0898aSmrg * This is necessary because already open fonts will keep their FPEs
9123a0898aSmrg * allocated, but they may not be on the new font path.
9223a0898aSmrg * The bitmap sources in the new path will be registered by the init_func.
9323a0898aSmrg */
9423a0898aSmrgvoid
9523a0898aSmrgFontFileEmptyBitmapSource(void)
9623a0898aSmrg{
9723a0898aSmrg    if (FontFileBitmapSources.count == 0)
9823a0898aSmrg	return;
9923a0898aSmrg
10023a0898aSmrg    FontFileBitmapSources.count = 0;
10123a0898aSmrg    FontFileBitmapSources.size = 0;
10223a0898aSmrg    xfree (FontFileBitmapSources.fpe);
10323a0898aSmrg    FontFileBitmapSources.fpe = 0;
10423a0898aSmrg}
10523a0898aSmrg
10623a0898aSmrgint
10723a0898aSmrgFontFileMatchBitmapSource (FontPathElementPtr fpe,
10823a0898aSmrg			   FontPtr *pFont,
10923a0898aSmrg			   int flags,
11023a0898aSmrg			   FontEntryPtr entry,
11123a0898aSmrg			   FontNamePtr zeroPat,
11223a0898aSmrg			   FontScalablePtr vals,
11323a0898aSmrg			   fsBitmapFormat format,
11423a0898aSmrg			   fsBitmapFormatMask fmask,
11523a0898aSmrg			   Bool noSpecificSize)
11623a0898aSmrg{
11723a0898aSmrg    int			source;
11823a0898aSmrg    FontEntryPtr	zero;
11923a0898aSmrg    FontBitmapEntryPtr	bitmap;
12023a0898aSmrg    int			ret;
12123a0898aSmrg    FontDirectoryPtr	dir;
12223a0898aSmrg    FontScaledPtr	scaled;
12323a0898aSmrg
12423a0898aSmrg    /*
12523a0898aSmrg     * Look through all the registered bitmap sources for
12623a0898aSmrg     * the same zero name as ours; entries along that one
12723a0898aSmrg     * can be scaled as desired.
12823a0898aSmrg     */
12923a0898aSmrg    ret = BadFontName;
13023a0898aSmrg    for (source = 0; source < FontFileBitmapSources.count; source++)
13123a0898aSmrg    {
13223a0898aSmrg    	if (FontFileBitmapSources.fpe[source] == fpe)
13323a0898aSmrg	    continue;
13423a0898aSmrg	dir = (FontDirectoryPtr) FontFileBitmapSources.fpe[source]->private;
13523a0898aSmrg	zero = FontFileFindNameInDir (&dir->scalable, zeroPat);
13623a0898aSmrg	if (!zero)
13723a0898aSmrg	    continue;
13823a0898aSmrg    	scaled = FontFileFindScaledInstance (zero, vals, noSpecificSize);
13923a0898aSmrg    	if (scaled)
14023a0898aSmrg    	{
14123a0898aSmrg	    if (scaled->pFont)
14223a0898aSmrg	    {
14323a0898aSmrg		*pFont = scaled->pFont;
14423a0898aSmrg		(*pFont)->fpe = FontFileBitmapSources.fpe[source];
14523a0898aSmrg		ret = Successful;
14623a0898aSmrg	    }
14723a0898aSmrg	    else if (scaled->bitmap)
14823a0898aSmrg	    {
14923a0898aSmrg		entry = scaled->bitmap;
15023a0898aSmrg		bitmap = &entry->u.bitmap;
15123a0898aSmrg		if (bitmap->pFont)
15223a0898aSmrg		{
15323a0898aSmrg		    *pFont = bitmap->pFont;
15423a0898aSmrg		    (*pFont)->fpe = FontFileBitmapSources.fpe[source];
15523a0898aSmrg		    ret = Successful;
15623a0898aSmrg		}
15723a0898aSmrg		else
15823a0898aSmrg		{
15923a0898aSmrg		    ret = FontFileOpenBitmap (
16023a0898aSmrg				FontFileBitmapSources.fpe[source],
16123a0898aSmrg				pFont, flags, entry, format, fmask);
16223a0898aSmrg		    if (ret == Successful && *pFont)
16323a0898aSmrg			(*pFont)->fpe = FontFileBitmapSources.fpe[source];
16423a0898aSmrg		}
16523a0898aSmrg	    }
16623a0898aSmrg	    else /* "cannot" happen */
16723a0898aSmrg	    {
16823a0898aSmrg		ret = BadFontName;
16923a0898aSmrg	    }
17023a0898aSmrg	    break;
17123a0898aSmrg    	}
17223a0898aSmrg    }
17323a0898aSmrg    return ret;
17423a0898aSmrg}
175