private.c revision 7f7f5e4e
123a0898aSmrg/* $Xorg: private.c,v 1.4 2001/02/09 02:04:04 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/util/private.c,v 1.8tsi 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/fontmisc.h>
3823a0898aSmrg#include    <X11/fonts/fontstruct.h>
3923a0898aSmrg
4023a0898aSmrgstatic int _FontPrivateAllocateIndex = 0;
4123a0898aSmrg
4223a0898aSmrgint
4323a0898aSmrgAllocateFontPrivateIndex (void)
4423a0898aSmrg{
4523a0898aSmrg    return _FontPrivateAllocateIndex++;
4623a0898aSmrg}
4723a0898aSmrg
4823a0898aSmrgFontPtr
4923a0898aSmrgCreateFontRec (void)
5023a0898aSmrg{
5123a0898aSmrg    FontPtr pFont;
5223a0898aSmrg    int size;
5323a0898aSmrg
5423a0898aSmrg    size = sizeof(FontRec) + (sizeof(pointer) * _FontPrivateAllocateIndex);
5523a0898aSmrg
567f7f5e4eSmrg    pFont = malloc(size);
5723a0898aSmrg
5823a0898aSmrg    if(pFont) {
5923a0898aSmrg	bzero((char*)pFont, size);
6023a0898aSmrg	pFont->maxPrivate = _FontPrivateAllocateIndex - 1;
6123a0898aSmrg	if(_FontPrivateAllocateIndex)
6223a0898aSmrg	    pFont->devPrivates = (pointer)(&pFont[1]);
6323a0898aSmrg    }
6423a0898aSmrg
6523a0898aSmrg    return pFont;
6623a0898aSmrg}
6723a0898aSmrg
6823a0898aSmrgvoid
6923a0898aSmrgDestroyFontRec (FontPtr pFont)
7023a0898aSmrg{
7123a0898aSmrg   if (pFont->devPrivates && pFont->devPrivates != (pointer)(&pFont[1]))
727f7f5e4eSmrg	free(pFont->devPrivates);
737f7f5e4eSmrg   free(pFont);
7423a0898aSmrg}
7523a0898aSmrg
7623a0898aSmrgvoid
7723a0898aSmrgResetFontPrivateIndex (void)
7823a0898aSmrg{
7923a0898aSmrg    _FontPrivateAllocateIndex = 0;
8023a0898aSmrg}
8123a0898aSmrg
8223a0898aSmrgBool
8323a0898aSmrg_FontSetNewPrivate (FontPtr pFont, int n, pointer ptr)
8423a0898aSmrg{
8523a0898aSmrg    pointer *new;
8623a0898aSmrg
8723a0898aSmrg    if (n > pFont->maxPrivate) {
8823a0898aSmrg	if (pFont->devPrivates && pFont->devPrivates != (pointer)(&pFont[1])) {
897f7f5e4eSmrg	    new = realloc (pFont->devPrivates, (n + 1) * sizeof (pointer));
9023a0898aSmrg	    if (!new)
9123a0898aSmrg		return FALSE;
9223a0898aSmrg	} else {
937f7f5e4eSmrg	    /* omg realloc */
947f7f5e4eSmrg	    new = malloc ((n + 1) * sizeof (pointer));
9523a0898aSmrg	    if (!new)
9623a0898aSmrg		return FALSE;
9723a0898aSmrg	    if (pFont->devPrivates)
9823a0898aSmrg		memcpy (new, pFont->devPrivates, (pFont->maxPrivate + 1) * sizeof (pointer));
9923a0898aSmrg	}
10023a0898aSmrg	pFont->devPrivates = new;
10123a0898aSmrg	/* zero out new, uninitialized privates */
10223a0898aSmrg	while(++pFont->maxPrivate < n)
10323a0898aSmrg	    pFont->devPrivates[pFont->maxPrivate] = (pointer)0;
10423a0898aSmrg    }
10523a0898aSmrg    pFont->devPrivates[n] = ptr;
10623a0898aSmrg    return TRUE;
10723a0898aSmrg}
10823a0898aSmrg
109