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