xftname.c revision 2836776b
1/* 2 * Copyright © 2000 Keith Packard 3 * 4 * Permission to use, copy, modify, distribute, and sell this software and its 5 * documentation for any purpose is hereby granted without fee, provided that 6 * the above copyright notice appear in all copies and that both that 7 * copyright notice and this permission notice appear in supporting 8 * documentation, and that the name of Keith Packard not be used in 9 * advertising or publicity pertaining to distribution of the software without 10 * specific, written prior permission. Keith Packard makes no 11 * representations about the suitability of this software for any purpose. It 12 * is provided "as is" without express or implied warranty. 13 * 14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 20 * PERFORMANCE OF THIS SOFTWARE. 21 */ 22 23#include "xftint.h" 24 25static const FcObjectType _XftObjectTypes[] = { 26 { XFT_CORE, FcTypeBool, }, 27 { XFT_XLFD, FcTypeString, }, 28 { XFT_RENDER, FcTypeBool, }, 29 { XFT_MAX_GLYPH_MEMORY, FcTypeInteger, }, 30}; 31 32#define NUM_OBJECT_TYPES (sizeof _XftObjectTypes / sizeof _XftObjectTypes[0]) 33 34static FcBool _XftNameInitialized; 35 36_X_HIDDEN void 37_XftNameInit (void) 38{ 39 if (_XftNameInitialized) 40 return; 41 _XftNameInitialized = FcTrue; 42 FcNameRegisterObjectTypes (_XftObjectTypes, NUM_OBJECT_TYPES); 43} 44 45_X_EXPORT FcPattern 46*XftNameParse (const char *name) 47{ 48 _XftNameInit (); 49 return FcNameParse ((FcChar8 *) name); 50} 51 52_X_EXPORT FcBool 53XftNameUnparse (FcPattern *pat, char *dest, int len) 54{ 55 FcChar8 *name; 56 57 _XftNameInit (); 58 name = FcNameUnparse (pat); 59 if (!name) 60 return FcFalse; 61 if (strlen ((char *) name) + 1 > len) 62 { 63 FcPattern *new = FcPatternDuplicate (pat); 64 free (name); 65 FcPatternDel (new, FC_LANG); 66 FcPatternDel (new, FC_CHARSET); 67 name = FcNameUnparse (new); 68 FcPatternDestroy (new); 69 if (!name) 70 return FcFalse; 71 if (strlen ((char *) name) + 1 > len) 72 { 73 strncpy (dest, ((char *) name), (size_t) len - 1); 74 dest[len - 1] = '\0'; 75 free (name); 76 return FcFalse; 77 } 78 } 79 strcpy (dest, ((char *) name)); 80 free (name); 81 return FcTrue; 82} 83