summaryrefslogtreecommitdiff
path: root/src/util/private.c
diff options
context:
space:
mode:
authorKaleb Keithley <kaleb@freedesktop.org>2003-11-14 16:48:50 +0000
committerKaleb Keithley <kaleb@freedesktop.org>2003-11-14 16:48:50 +0000
commit4349bf0fa125e2a1c32b0b49c974ff5fa588cdbe (patch)
tree2e4b857f2103cfbcdfcfd53b47334166e139a273 /src/util/private.c
parent3795e9702b3b3a6fe0594d09cdd110adeb5e42f9 (diff)
Diffstat (limited to 'src/util/private.c')
-rw-r--r--src/util/private.c57
1 files changed, 45 insertions, 12 deletions
diff --git a/src/util/private.c b/src/util/private.c
index 9cb58c6..ef7d48b 100644
--- a/src/util/private.c
+++ b/src/util/private.c
@@ -25,6 +25,7 @@ used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
+/* $XFree86: xc/lib/font/util/private.c,v 1.8 2001/12/14 19:56:57 dawes Exp $ */
/*
* Author: Keith Packard, MIT X Consortium
@@ -33,33 +34,64 @@ in this Software without prior written authorization from The Open Group.
#include "fontmisc.h"
#include "fontstruct.h"
-int _FontPrivateAllocateIndex;
+static int _FontPrivateAllocateIndex = 0;
int
-AllocateFontPrivateIndex ()
+AllocateFontPrivateIndex (void)
{
return _FontPrivateAllocateIndex++;
}
+FontPtr
+CreateFontRec (void)
+{
+ FontPtr pFont;
+ int size;
+
+ size = sizeof(FontRec) + (sizeof(pointer) * _FontPrivateAllocateIndex);
+
+ pFont = (FontPtr)xalloc(size);
+ bzero((char*)pFont, size);
+
+ if(pFont) {
+ pFont->maxPrivate = _FontPrivateAllocateIndex - 1;
+ if(_FontPrivateAllocateIndex)
+ pFont->devPrivates = (pointer)(&pFont[1]);
+ }
+
+ return pFont;
+}
+
+void DestroyFontRec (FontPtr pFont)
+{
+ if (pFont->devPrivates && pFont->devPrivates != (pointer)(&pFont[1]))
+ xfree(pFont->devPrivates);
+ xfree(pFont);
+}
+
void
-ResetFontPrivateIndex ()
+ResetFontPrivateIndex (void)
{
_FontPrivateAllocateIndex = 0;
}
Bool
-_FontSetNewPrivate (pFont, n, ptr)
- FontPtr pFont;
- int n;
- pointer ptr;
+_FontSetNewPrivate (FontPtr pFont, int n, pointer ptr)
{
pointer *new;
- if (n > pFont->maxPrivate)
- {
- new = (pointer *) xrealloc (pFont->devPrivates, (n + 1) * sizeof (pointer));
- if (!new)
- return FALSE;
+ if (n > pFont->maxPrivate) {
+ if (pFont->devPrivates && pFont->devPrivates != (pointer)(&pFont[1])) {
+ new = (pointer *) xrealloc (pFont->devPrivates, (n + 1) * sizeof (pointer));
+ if (!new)
+ return FALSE;
+ } else {
+ new = (pointer *) xalloc ((n + 1) * sizeof (pointer));
+ if (!new)
+ return FALSE;
+ if (pFont->devPrivates)
+ memcpy (new, pFont->devPrivates, (pFont->maxPrivate + 1) * sizeof (pointer));
+ }
pFont->devPrivates = new;
/* zero out new, uninitialized privates */
while(++pFont->maxPrivate < n)
@@ -68,3 +100,4 @@ _FontSetNewPrivate (pFont, n, ptr)
pFont->devPrivates[n] = ptr;
return TRUE;
}
+