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