FSWrap.c revision 61b2299d
1/* $Xorg: FSWrap.c,v 1.5 2001/02/09 02:03:32 xorgcvs Exp $ */
2
3/*
4 * Copyright 1991 by the Open Software Foundation
5 * Copyright 1993 by the TOSHIBA Corp.
6 *
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name Open Software Foundation
12 * not be used in advertising or publicity pertaining to distribution of the
13 * software without specific, written prior permission.  Open Software
14 * Foundation makes no representations about the suitability of this
15 * software for any purpose.  It is provided "as is" without express or
16 * implied warranty.
17 *
18 * OPEN SOFTWARE FOUNDATION DISCLAIMS ALL WARRANTIES WITH REGARD TO
19 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS, IN NO EVENT SHALL OPEN SOFTWARE FOUNDATIONN BE
21 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
23 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
24 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 *
26 *		 M. Collins		OSF
27 *
28 *		 Katsuhisa Yano		TOSHIBA Corp.
29 */
30
31/*
32
33Copyright 1991, 1998  The Open Group
34
35Permission to use, copy, modify, distribute, and sell this software and its
36documentation for any purpose is hereby granted without fee, provided that
37the above copyright notice appear in all copies and that both that
38copyright notice and this permission notice appear in supporting
39documentation.
40
41The above copyright notice and this permission notice shall be included
42in all copies or substantial portions of the Software.
43
44THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
45OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
48OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
49ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
50OTHER DEALINGS IN THE SOFTWARE.
51
52Except as contained in this notice, the name of The Open Group shall
53not be used in advertising or otherwise to promote the sale, use or
54other dealings in this Software without prior written authorization
55from The Open Group.
56
57*/
58
59/* $XFree86: xc/lib/X11/FSWrap.c,v 1.8 2003/08/22 19:27:24 eich Exp $ */
60
61#ifdef HAVE_CONFIG_H
62#include <config.h>
63#endif
64#include "Xlibint.h"
65#include "Xlcint.h"
66#include <ctype.h>
67#include <X11/Xos.h>
68
69
70#define	XMAXLIST	256
71
72char **
73_XParseBaseFontNameList(
74    char           *str,
75    int            *num)
76{
77    char           *plist[XMAXLIST];
78    char          **list;
79    char           *ptr, *psave;
80
81    *num = 0;
82    if (!str || !*str) {
83	return (char **)NULL;
84    }
85    while (*str && isspace(*str))
86	str++;
87    if (!*str)
88	return (char **)NULL;
89
90    if (!(ptr = Xmalloc((unsigned)strlen(str) + 1))) {
91	return (char **)NULL;
92    }
93    strcpy(ptr, str);
94
95    psave = ptr;
96    /* somebody who specifies more than XMAXLIST basefontnames will lose */
97    while (*num < (sizeof plist / sizeof plist[0])) {
98	char	*back;
99
100	plist[*num] = ptr;
101	if ((ptr = strchr(ptr, ','))) {
102	    back = ptr;
103	} else {
104	    back = plist[*num] + strlen(plist[*num]);
105	}
106	while (isspace(*(back - 1)))
107	    back--;
108	*back = '\0';
109	(*num)++;
110	if (!ptr)
111	    break;
112	ptr++;
113	while (*ptr && isspace(*ptr))
114	    ptr++;
115	if (!*ptr)
116	    break;
117    }
118    if (!(list = (char **) Xmalloc((unsigned)sizeof(char *) * (*num + 1)))) {
119	Xfree(psave);
120	return (char **)NULL;
121    }
122    memcpy((char *)list, (char *)plist, sizeof(char *) * (*num));
123    *(list + *num) = NULL;
124
125    return list;
126}
127
128static char **
129copy_string_list(
130    char **string_list,
131    int list_count)
132{
133    char **string_list_ret, **list_src, **list_dst, *dst;
134    int length, count;
135
136    if (string_list == NULL)
137	return (char **) NULL;
138
139    string_list_ret = (char **) Xmalloc(sizeof(char *) * list_count);
140    if (string_list_ret == NULL)
141	return (char **) NULL;
142
143    list_src = string_list;
144    count = list_count;
145    for (length = 0; count-- > 0; list_src++)
146	length += strlen(*list_src) + 1;
147
148    dst = (char *) Xmalloc(length);
149    if (dst == NULL) {
150	Xfree(string_list_ret);
151	return (char **) NULL;
152    }
153
154    list_src = string_list;
155    count = list_count;
156    list_dst = string_list_ret;
157    for ( ;  count-- > 0; list_src++) {
158	strcpy(dst, *list_src);
159	*list_dst++ = dst;
160	dst += strlen(dst) + 1;
161    }
162
163    return string_list_ret;
164}
165
166XFontSet
167XCreateFontSet (
168    Display        *dpy,
169    _Xconst char   *base_font_name_list,
170    char         ***missing_charset_list,
171    int            *missing_charset_count,
172    char          **def_string)
173{
174    XOM om;
175    XOC oc;
176    XOMCharSetList *list;
177
178    *missing_charset_list = NULL;
179    *missing_charset_count = 0;
180
181    om = XOpenOM(dpy, NULL, NULL, NULL);
182    if (om == NULL)
183	return (XFontSet) NULL;
184
185    if ((oc = XCreateOC(om, XNBaseFontName, base_font_name_list, NULL))) {
186	list = &oc->core.missing_list;
187	oc->core.om_automatic = True;
188    } else
189	list = &om->core.required_charset;
190
191    *missing_charset_list = copy_string_list(list->charset_list,
192					     list->charset_count);
193    *missing_charset_count = list->charset_count;
194
195    if (list->charset_list && *missing_charset_list == NULL)
196	oc = NULL;
197
198    if (oc && def_string) {
199	*def_string = oc->core.default_string;
200	if (!*def_string)
201	    *def_string = "";
202    }
203
204    if (oc == NULL)
205	XCloseOM(om);
206
207    return (XFontSet) oc;
208}
209
210int
211XFontsOfFontSet(
212    XFontSet        font_set,
213    XFontStruct  ***font_struct_list,
214    char         ***font_name_list)
215{
216    *font_name_list   = font_set->core.font_info.font_name_list;
217    *font_struct_list = font_set->core.font_info.font_struct_list;
218    return font_set->core.font_info.num_font;
219}
220
221char *
222XBaseFontNameListOfFontSet(XFontSet font_set)
223{
224    return font_set->core.base_name_list;
225}
226
227char *
228XLocaleOfFontSet(XFontSet font_set)
229{
230    return font_set->core.om->core.lcd->core->name;
231}
232
233Bool
234XContextDependentDrawing(XFontSet font_set)
235{
236    return font_set->core.om->core.context_dependent;
237}
238
239Bool
240XDirectionalDependentDrawing(XFontSet font_set)
241{
242    return font_set->core.om->core.directional_dependent;
243}
244
245Bool
246XContextualDrawing(XFontSet font_set)
247{
248    return font_set->core.om->core.contextual_drawing;
249}
250
251XFontSetExtents *
252XExtentsOfFontSet(XFontSet font_set)
253{
254    if (!font_set)
255	return NULL;
256    return &font_set->core.font_set_extents;
257}
258
259void
260XFreeFontSet(
261    Display        *dpy,
262    XFontSet        font_set)
263{
264    XCloseOM(font_set->core.om);
265}
266