FSWrap.c revision 1ab64890
11ab64890Smrg/* $Xorg: FSWrap.c,v 1.5 2001/02/09 02:03:32 xorgcvs Exp $ */ 21ab64890Smrg 31ab64890Smrg/* 41ab64890Smrg * Copyright 1991 by the Open Software Foundation 51ab64890Smrg * Copyright 1993 by the TOSHIBA Corp. 61ab64890Smrg * 71ab64890Smrg * Permission to use, copy, modify, distribute, and sell this software and its 81ab64890Smrg * documentation for any purpose is hereby granted without fee, provided that 91ab64890Smrg * the above copyright notice appear in all copies and that both that 101ab64890Smrg * copyright notice and this permission notice appear in supporting 111ab64890Smrg * documentation, and that the name Open Software Foundation 121ab64890Smrg * not be used in advertising or publicity pertaining to distribution of the 131ab64890Smrg * software without specific, written prior permission. Open Software 141ab64890Smrg * Foundation makes no representations about the suitability of this 151ab64890Smrg * software for any purpose. It is provided "as is" without express or 161ab64890Smrg * implied warranty. 171ab64890Smrg * 181ab64890Smrg * OPEN SOFTWARE FOUNDATION DISCLAIMS ALL WARRANTIES WITH REGARD TO 191ab64890Smrg * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 201ab64890Smrg * FITNESS, IN NO EVENT SHALL OPEN SOFTWARE FOUNDATIONN BE 211ab64890Smrg * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 221ab64890Smrg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 231ab64890Smrg * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 241ab64890Smrg * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 251ab64890Smrg * 261ab64890Smrg * M. Collins OSF 271ab64890Smrg * 281ab64890Smrg * Katsuhisa Yano TOSHIBA Corp. 291ab64890Smrg */ 301ab64890Smrg 311ab64890Smrg/* 321ab64890Smrg 331ab64890SmrgCopyright 1991, 1998 The Open Group 341ab64890Smrg 351ab64890SmrgPermission to use, copy, modify, distribute, and sell this software and its 361ab64890Smrgdocumentation for any purpose is hereby granted without fee, provided that 371ab64890Smrgthe above copyright notice appear in all copies and that both that 381ab64890Smrgcopyright notice and this permission notice appear in supporting 391ab64890Smrgdocumentation. 401ab64890Smrg 411ab64890SmrgThe above copyright notice and this permission notice shall be included 421ab64890Smrgin all copies or substantial portions of the Software. 431ab64890Smrg 441ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 451ab64890SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 461ab64890SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 471ab64890SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 481ab64890SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 491ab64890SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 501ab64890SmrgOTHER DEALINGS IN THE SOFTWARE. 511ab64890Smrg 521ab64890SmrgExcept as contained in this notice, the name of The Open Group shall 531ab64890Smrgnot be used in advertising or otherwise to promote the sale, use or 541ab64890Smrgother dealings in this Software without prior written authorization 551ab64890Smrgfrom The Open Group. 561ab64890Smrg 571ab64890Smrg*/ 581ab64890Smrg 591ab64890Smrg/* $XFree86: xc/lib/X11/FSWrap.c,v 1.8 2003/08/22 19:27:24 eich Exp $ */ 601ab64890Smrg 611ab64890Smrg#ifdef HAVE_CONFIG_H 621ab64890Smrg#include <config.h> 631ab64890Smrg#endif 641ab64890Smrg#include "Xlibint.h" 651ab64890Smrg#include "Xlcint.h" 661ab64890Smrg#include <ctype.h> 671ab64890Smrg#include <X11/Xos.h> 681ab64890Smrg 691ab64890Smrg 701ab64890Smrg#define XMAXLIST 256 711ab64890Smrg 721ab64890Smrgchar ** 731ab64890Smrg_XParseBaseFontNameList( 741ab64890Smrg char *str, 751ab64890Smrg int *num) 761ab64890Smrg{ 771ab64890Smrg char *plist[XMAXLIST]; 781ab64890Smrg char **list; 791ab64890Smrg char *ptr, *psave; 801ab64890Smrg 811ab64890Smrg *num = 0; 821ab64890Smrg if (!str || !*str) { 831ab64890Smrg return (char **)NULL; 841ab64890Smrg } 851ab64890Smrg while (*str && isspace(*str)) 861ab64890Smrg str++; 871ab64890Smrg if (!*str) 881ab64890Smrg return (char **)NULL; 891ab64890Smrg 901ab64890Smrg if (!(ptr = Xmalloc((unsigned)strlen(str) + 1))) { 911ab64890Smrg return (char **)NULL; 921ab64890Smrg } 931ab64890Smrg strcpy(ptr, str); 941ab64890Smrg 951ab64890Smrg psave = ptr; 961ab64890Smrg /* somebody who specifies more than XMAXLIST basefontnames will lose */ 971ab64890Smrg while (*num < (sizeof plist / sizeof plist[0])) { 981ab64890Smrg char *back; 991ab64890Smrg 1001ab64890Smrg plist[*num] = ptr; 1011ab64890Smrg if ((ptr = strchr(ptr, ','))) { 1021ab64890Smrg back = ptr; 1031ab64890Smrg } else { 1041ab64890Smrg back = plist[*num] + strlen(plist[*num]); 1051ab64890Smrg } 1061ab64890Smrg while (isspace(*(back - 1))) 1071ab64890Smrg back--; 1081ab64890Smrg *back = '\0'; 1091ab64890Smrg (*num)++; 1101ab64890Smrg if (!ptr) 1111ab64890Smrg break; 1121ab64890Smrg ptr++; 1131ab64890Smrg while (*ptr && isspace(*ptr)) 1141ab64890Smrg ptr++; 1151ab64890Smrg if (!*ptr) 1161ab64890Smrg break; 1171ab64890Smrg } 1181ab64890Smrg if (!(list = (char **) Xmalloc((unsigned)sizeof(char *) * (*num + 1)))) { 1191ab64890Smrg Xfree(psave); 1201ab64890Smrg return (char **)NULL; 1211ab64890Smrg } 1221ab64890Smrg memcpy((char *)list, (char *)plist, sizeof(char *) * (*num)); 1231ab64890Smrg *(list + *num) = NULL; 1241ab64890Smrg 1251ab64890Smrg return list; 1261ab64890Smrg} 1271ab64890Smrg 1281ab64890Smrgstatic char ** 1291ab64890Smrgcopy_string_list( 1301ab64890Smrg char **string_list, 1311ab64890Smrg int list_count) 1321ab64890Smrg{ 1331ab64890Smrg char **string_list_ret, **list_src, **list_dst, *dst; 1341ab64890Smrg int length, count; 1351ab64890Smrg 1361ab64890Smrg if (string_list == NULL) 1371ab64890Smrg return (char **) NULL; 1381ab64890Smrg 1391ab64890Smrg string_list_ret = (char **) Xmalloc(sizeof(char *) * list_count); 1401ab64890Smrg if (string_list_ret == NULL) 1411ab64890Smrg return (char **) NULL; 1421ab64890Smrg 1431ab64890Smrg list_src = string_list; 1441ab64890Smrg count = list_count; 1451ab64890Smrg for (length = 0; count-- > 0; list_src++) 1461ab64890Smrg length += strlen(*list_src) + 1; 1471ab64890Smrg 1481ab64890Smrg dst = (char *) Xmalloc(length); 1491ab64890Smrg if (dst == NULL) { 1501ab64890Smrg Xfree(string_list_ret); 1511ab64890Smrg return (char **) NULL; 1521ab64890Smrg } 1531ab64890Smrg 1541ab64890Smrg list_src = string_list; 1551ab64890Smrg count = list_count; 1561ab64890Smrg list_dst = string_list_ret; 1571ab64890Smrg for ( ; count-- > 0; list_src++) { 1581ab64890Smrg strcpy(dst, *list_src); 1591ab64890Smrg *list_dst++ = dst; 1601ab64890Smrg dst += strlen(dst) + 1; 1611ab64890Smrg } 1621ab64890Smrg 1631ab64890Smrg return string_list_ret; 1641ab64890Smrg} 1651ab64890Smrg 1661ab64890SmrgXFontSet 1671ab64890SmrgXCreateFontSet ( 1681ab64890Smrg Display *dpy, 1691ab64890Smrg _Xconst char *base_font_name_list, 1701ab64890Smrg char ***missing_charset_list, 1711ab64890Smrg int *missing_charset_count, 1721ab64890Smrg char **def_string) 1731ab64890Smrg{ 1741ab64890Smrg XOM om; 1751ab64890Smrg XOC oc; 1761ab64890Smrg XOMCharSetList *list; 1771ab64890Smrg 1781ab64890Smrg *missing_charset_list = NULL; 1791ab64890Smrg *missing_charset_count = 0; 1801ab64890Smrg 1811ab64890Smrg om = XOpenOM(dpy, NULL, NULL, NULL); 1821ab64890Smrg if (om == NULL) 1831ab64890Smrg return (XFontSet) NULL; 1841ab64890Smrg 1851ab64890Smrg if ((oc = XCreateOC(om, XNBaseFontName, base_font_name_list, NULL))) { 1861ab64890Smrg list = &oc->core.missing_list; 1871ab64890Smrg oc->core.om_automatic = True; 1881ab64890Smrg } else 1891ab64890Smrg list = &om->core.required_charset; 1901ab64890Smrg 1911ab64890Smrg *missing_charset_list = copy_string_list(list->charset_list, 1921ab64890Smrg list->charset_count); 1931ab64890Smrg *missing_charset_count = list->charset_count; 1941ab64890Smrg 1951ab64890Smrg if (list->charset_list && *missing_charset_list == NULL) 1961ab64890Smrg oc = NULL; 1971ab64890Smrg 1981ab64890Smrg if (oc && def_string) { 1991ab64890Smrg *def_string = oc->core.default_string; 2001ab64890Smrg if (!*def_string) 2011ab64890Smrg *def_string = ""; 2021ab64890Smrg } 2031ab64890Smrg 2041ab64890Smrg if (oc == NULL) 2051ab64890Smrg XCloseOM(om); 2061ab64890Smrg 2071ab64890Smrg return (XFontSet) oc; 2081ab64890Smrg} 2091ab64890Smrg 2101ab64890Smrgint 2111ab64890SmrgXFontsOfFontSet( 2121ab64890Smrg XFontSet font_set, 2131ab64890Smrg XFontStruct ***font_struct_list, 2141ab64890Smrg char ***font_name_list) 2151ab64890Smrg{ 2161ab64890Smrg *font_name_list = font_set->core.font_info.font_name_list; 2171ab64890Smrg *font_struct_list = font_set->core.font_info.font_struct_list; 2181ab64890Smrg return font_set->core.font_info.num_font; 2191ab64890Smrg} 2201ab64890Smrg 2211ab64890Smrgchar * 2221ab64890SmrgXBaseFontNameListOfFontSet(XFontSet font_set) 2231ab64890Smrg{ 2241ab64890Smrg return font_set->core.base_name_list; 2251ab64890Smrg} 2261ab64890Smrg 2271ab64890Smrgchar * 2281ab64890SmrgXLocaleOfFontSet(XFontSet font_set) 2291ab64890Smrg{ 2301ab64890Smrg return font_set->core.om->core.lcd->core->name; 2311ab64890Smrg} 2321ab64890Smrg 2331ab64890SmrgBool 2341ab64890SmrgXContextDependentDrawing(XFontSet font_set) 2351ab64890Smrg{ 2361ab64890Smrg return font_set->core.om->core.context_dependent; 2371ab64890Smrg} 2381ab64890Smrg 2391ab64890SmrgBool 2401ab64890SmrgXDirectionalDependentDrawing(XFontSet font_set) 2411ab64890Smrg{ 2421ab64890Smrg return font_set->core.om->core.directional_dependent; 2431ab64890Smrg} 2441ab64890Smrg 2451ab64890SmrgBool 2461ab64890SmrgXContextualDrawing(XFontSet font_set) 2471ab64890Smrg{ 2481ab64890Smrg return font_set->core.om->core.contextual_drawing; 2491ab64890Smrg} 2501ab64890Smrg 2511ab64890SmrgXFontSetExtents * 2521ab64890SmrgXExtentsOfFontSet(XFontSet font_set) 2531ab64890Smrg{ 2541ab64890Smrg if (!font_set) 2551ab64890Smrg return NULL; 2561ab64890Smrg return &font_set->core.font_set_extents; 2571ab64890Smrg} 2581ab64890Smrg 2591ab64890Smrgvoid 2601ab64890SmrgXFreeFontSet( 2611ab64890Smrg Display *dpy, 2621ab64890Smrg XFontSet font_set) 2631ab64890Smrg{ 2641ab64890Smrg XCloseOM(font_set->core.om); 2651ab64890Smrg} 266