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