xftfont.c revision c76ae52d
1/*
2 * $Id: xftfont.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
27_X_EXPORT FcPattern *
28XftFontMatch (Display		*dpy,
29	      int		screen,
30	      _Xconst FcPattern *pattern,
31	      FcResult		*result)
32{
33    FcPattern	*new;
34    FcPattern	*match;
35
36    if (!XftInit (0))
37	return 0;
38
39    new = FcPatternDuplicate (pattern);
40    if (!new)
41	return 0;
42
43    if (XftDebug () & XFT_DBG_OPENV)
44    {
45	printf ("XftFontMatch pattern ");
46	FcPatternPrint (new);
47    }
48    FcConfigSubstitute (0, new, FcMatchPattern);
49    if (XftDebug () & XFT_DBG_OPENV)
50    {
51	printf ("XftFontMatch after FcConfig substitutions ");
52	FcPatternPrint (new);
53    }
54    XftDefaultSubstitute (dpy, screen, new);
55    if (XftDebug () & XFT_DBG_OPENV)
56    {
57	printf ("XftFontMatch after X resource substitutions ");
58	FcPatternPrint (new);
59    }
60
61    match = FcFontMatch (0, new, result);
62    if (XftDebug () & XFT_DBG_OPENV)
63    {
64	printf ("XftFontMatch result ");
65	FcPatternPrint (match);
66    }
67    FcPatternDestroy (new);
68    return match;
69}
70
71_X_EXPORT XftFont *
72XftFontOpen (Display *dpy, int screen, ...)
73{
74    va_list	    va;
75    FcPattern	    *pat;
76    FcPattern	    *match;
77    FcResult	    result;
78    XftFont	    *font;
79
80    va_start (va, screen);
81    pat = FcPatternVaBuild (0, va);
82    va_end (va);
83    if (!pat)
84    {
85	if (XftDebug () & XFT_DBG_OPEN)
86	    printf ("XftFontOpen: Invalid pattern argument\n");
87	return 0;
88    }
89    match = XftFontMatch (dpy, screen, pat, &result);
90    if (XftDebug () & XFT_DBG_OPEN)
91    {
92	printf ("Pattern ");
93	FcPatternPrint (pat);
94	if (match)
95	{
96	    printf ("Match ");
97	    FcPatternPrint (match);
98	}
99	else
100	    printf ("No Match\n");
101    }
102    FcPatternDestroy (pat);
103    if (!match)
104	return 0;
105
106    font = XftFontOpenPattern (dpy, match);
107    if (!font)
108    {
109	if (XftDebug () & XFT_DBG_OPEN)
110	    printf ("No Font\n");
111	FcPatternDestroy (match);
112    }
113
114    return font;
115}
116
117_X_EXPORT XftFont *
118XftFontOpenName (Display *dpy, int screen, const char *name)
119{
120    FcPattern	    *pat;
121    FcPattern	    *match;
122    FcResult	    result;
123    XftFont	    *font;
124
125    pat = FcNameParse ((FcChar8 *) name);
126    if (XftDebug () & XFT_DBG_OPEN)
127    {
128	printf ("XftFontOpenName \"%s\": ", name);
129	if (pat)
130	    FcPatternPrint (pat);
131	else
132	    printf ("Invalid name\n");
133    }
134
135    if (!pat)
136	return 0;
137    match = XftFontMatch (dpy, screen, pat, &result);
138    if (XftDebug () & XFT_DBG_OPEN)
139    {
140	if (match)
141	{
142	    printf ("Match ");
143	    FcPatternPrint (match);
144	}
145	else
146	    printf ("No Match\n");
147    }
148    FcPatternDestroy (pat);
149    if (!match)
150	return 0;
151
152    font = XftFontOpenPattern (dpy, match);
153    if (!font)
154    {
155	if (XftDebug () & XFT_DBG_OPEN)
156	    printf ("No Font\n");
157	FcPatternDestroy (match);
158    }
159
160    return font;
161}
162
163_X_EXPORT XftFont *
164XftFontOpenXlfd (Display *dpy, int screen, const char *xlfd)
165{
166    FcPattern	    *pat;
167    FcPattern	    *match;
168    FcResult	    result;
169    XftFont	    *font;
170
171    pat = XftXlfdParse (xlfd, FcFalse, FcFalse);
172    if (XftDebug () & XFT_DBG_OPEN)
173    {
174	printf ("XftFontOpenXlfd \"%s\": ", xlfd);
175	if (pat)
176	    printf ("Invalid xlfd\n");
177	else
178	    FcPatternPrint (pat);
179    }
180
181    if (!pat)
182	return 0;
183    match = XftFontMatch (dpy, screen, pat, &result);
184    if (XftDebug () & XFT_DBG_OPEN)
185    {
186	if (match)
187	{
188	    printf ("Match ");
189	    FcPatternPrint (match);
190	}
191	else
192	    printf ("No Match\n");
193    }
194    FcPatternDestroy (pat);
195    if (!match)
196	return 0;
197
198    font = XftFontOpenPattern (dpy, match);
199    if (!font)
200    {
201	if (XftDebug () & XFT_DBG_OPEN)
202	    printf ("No Font\n");
203	FcPatternDestroy (match);
204    }
205
206    return font;
207}
208
209