1a96d7823Smrg/* 2a96d7823Smrg 3a96d7823SmrgCopyright 1991, 1998 The Open Group 4a96d7823Smrg 5a96d7823SmrgPermission to use, copy, modify, distribute, and sell this software and its 6a96d7823Smrgdocumentation for any purpose is hereby granted without fee, provided that 7a96d7823Smrgthe above copyright notice appear in all copies and that both that 8a96d7823Smrgcopyright notice and this permission notice appear in supporting 9a96d7823Smrgdocumentation. 10a96d7823Smrg 11a96d7823SmrgThe above copyright notice and this permission notice shall be included in 12a96d7823Smrgall copies or substantial portions of the Software. 13a96d7823Smrg 14a96d7823SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15a96d7823SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16a96d7823SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17a96d7823SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18a96d7823SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19a96d7823SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20a96d7823Smrg 21a96d7823SmrgExcept as contained in this notice, the name of The Open Group shall not be 22a96d7823Smrgused in advertising or otherwise to promote the sale, use or other dealings 23a96d7823Smrgin this Software without prior written authorization from The Open Group. 24a96d7823Smrg 25a96d7823Smrg*/ 26a96d7823Smrg 27a96d7823Smrg/* 28a96d7823Smrg * Author: Keith Packard, MIT X Consortium 29a96d7823Smrg */ 30a96d7823Smrg 31a96d7823Smrg#ifdef HAVE_CONFIG_H 32a96d7823Smrg#include <config.h> 33a96d7823Smrg#endif 34a96d7823Smrg#include "libxfontint.h" 35c7b4381aSmrg#include "src/util/replace.h" 36a96d7823Smrg#include <X11/fonts/fontmisc.h> 37a96d7823Smrg#include <X11/fonts/fontstruct.h> 38a96d7823Smrg 39a96d7823Smrgstatic int _FontPrivateAllocateIndex = 0; 40a96d7823Smrg 41a96d7823Smrgint 42a96d7823Smrgxfont2_allocate_font_private_index (void) 43a96d7823Smrg{ 44a96d7823Smrg return _FontPrivateAllocateIndex++; 45a96d7823Smrg} 46a96d7823Smrg 47a96d7823SmrgFontPtr 48a96d7823SmrgCreateFontRec (void) 49a96d7823Smrg{ 50a96d7823Smrg FontPtr pFont; 51a96d7823Smrg int size; 52a96d7823Smrg 53a96d7823Smrg size = sizeof(FontRec) + (sizeof(pointer) * _FontPrivateAllocateIndex); 54a96d7823Smrg 55a96d7823Smrg pFont = malloc(size); 56a96d7823Smrg 57a96d7823Smrg if(pFont) { 58a96d7823Smrg bzero((char*)pFont, size); 59a96d7823Smrg pFont->maxPrivate = _FontPrivateAllocateIndex - 1; 60a96d7823Smrg if(_FontPrivateAllocateIndex) 61a96d7823Smrg pFont->devPrivates = (pointer)(&pFont[1]); 62a96d7823Smrg } 63a96d7823Smrg 64a96d7823Smrg return pFont; 65a96d7823Smrg} 66a96d7823Smrg 67a96d7823Smrgvoid 68a96d7823SmrgDestroyFontRec (FontPtr pFont) 69a96d7823Smrg{ 70a96d7823Smrg if (pFont->devPrivates && pFont->devPrivates != (pointer)(&pFont[1])) 71a96d7823Smrg free(pFont->devPrivates); 72a96d7823Smrg free(pFont); 73a96d7823Smrg} 74a96d7823Smrg 75a96d7823Smrgvoid 76a96d7823SmrgResetFontPrivateIndex (void) 77a96d7823Smrg{ 78a96d7823Smrg _FontPrivateAllocateIndex = 0; 79a96d7823Smrg} 80a96d7823Smrg 81a96d7823SmrgBool 82a96d7823Smrgxfont2_font_set_private(FontPtr pFont, int n, pointer ptr) 83a96d7823Smrg{ 84a96d7823Smrg pointer *new; 85a96d7823Smrg 86a96d7823Smrg if (n > pFont->maxPrivate) { 87a96d7823Smrg if (pFont->devPrivates && pFont->devPrivates != (pointer)(&pFont[1])) { 88c7b4381aSmrg new = reallocarray (pFont->devPrivates, (n + 1), sizeof (pointer)); 89a96d7823Smrg if (!new) 90a96d7823Smrg return FALSE; 91a96d7823Smrg } else { 92a96d7823Smrg /* omg realloc */ 93c7b4381aSmrg new = reallocarray (NULL, (n + 1), sizeof (pointer)); 94a96d7823Smrg if (!new) 95a96d7823Smrg return FALSE; 96a96d7823Smrg if (pFont->devPrivates) 97a96d7823Smrg memcpy (new, pFont->devPrivates, (pFont->maxPrivate + 1) * sizeof (pointer)); 98a96d7823Smrg } 99a96d7823Smrg pFont->devPrivates = new; 100a96d7823Smrg /* zero out new, uninitialized privates */ 101a96d7823Smrg while(++pFont->maxPrivate < n) 102a96d7823Smrg pFont->devPrivates[pFont->maxPrivate] = (pointer)0; 103a96d7823Smrg } 104a96d7823Smrg pFont->devPrivates[n] = ptr; 105a96d7823Smrg return TRUE; 106a96d7823Smrg} 107a96d7823Smrg 108