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> 66258a0ebeSmrg#include "reallocarray.h" 671ab64890Smrg 681ab64890Smrg 691ab64890Smrg#define XMAXLIST 256 701ab64890Smrg 711ab64890Smrgchar ** 721ab64890Smrg_XParseBaseFontNameList( 731ab64890Smrg char *str, 741ab64890Smrg int *num) 751ab64890Smrg{ 761ab64890Smrg char *plist[XMAXLIST]; 771ab64890Smrg char **list; 781ab64890Smrg char *ptr, *psave; 791ab64890Smrg 801ab64890Smrg *num = 0; 811ab64890Smrg if (!str || !*str) { 821ab64890Smrg return (char **)NULL; 831ab64890Smrg } 841ab64890Smrg while (*str && isspace(*str)) 851ab64890Smrg str++; 861ab64890Smrg if (!*str) 871ab64890Smrg return (char **)NULL; 881ab64890Smrg 896cc2b21fSmrg if (!(ptr = strdup(str))) { 901ab64890Smrg return (char **)NULL; 911ab64890Smrg } 921ab64890Smrg 931ab64890Smrg psave = ptr; 941ab64890Smrg /* somebody who specifies more than XMAXLIST basefontnames will lose */ 951ab64890Smrg while (*num < (sizeof plist / sizeof plist[0])) { 961ab64890Smrg char *back; 971ab64890Smrg 981ab64890Smrg plist[*num] = ptr; 991ab64890Smrg if ((ptr = strchr(ptr, ','))) { 1001ab64890Smrg back = ptr; 1011ab64890Smrg } else { 1021ab64890Smrg back = plist[*num] + strlen(plist[*num]); 1031ab64890Smrg } 1041ab64890Smrg while (isspace(*(back - 1))) 1051ab64890Smrg back--; 1061ab64890Smrg *back = '\0'; 1071ab64890Smrg (*num)++; 1081ab64890Smrg if (!ptr) 1091ab64890Smrg break; 1101ab64890Smrg ptr++; 1111ab64890Smrg while (*ptr && isspace(*ptr)) 1121ab64890Smrg ptr++; 1131ab64890Smrg if (!*ptr) 1141ab64890Smrg break; 1151ab64890Smrg } 116258a0ebeSmrg if (!(list = Xmallocarray((*num + 1), sizeof(char *)))) { 1171ab64890Smrg Xfree(psave); 1181ab64890Smrg return (char **)NULL; 1191ab64890Smrg } 1209c019ec5Smaya memcpy((char *)list, (char *)plist, sizeof(char *) * (size_t) (*num)); 1211ab64890Smrg *(list + *num) = NULL; 1221ab64890Smrg 1231ab64890Smrg return list; 1241ab64890Smrg} 1251ab64890Smrg 1261ab64890Smrgstatic char ** 1271ab64890Smrgcopy_string_list( 1281ab64890Smrg char **string_list, 1291ab64890Smrg int list_count) 1301ab64890Smrg{ 1311ab64890Smrg char **string_list_ret, **list_src, **list_dst, *dst; 1321ab64890Smrg int length, count; 1331ab64890Smrg 134eb411b4bSmrg if (string_list == NULL || list_count <= 0) 1351ab64890Smrg return (char **) NULL; 1361ab64890Smrg 137258a0ebeSmrg string_list_ret = Xmallocarray(list_count, sizeof(char *)); 1381ab64890Smrg if (string_list_ret == NULL) 1391ab64890Smrg return (char **) NULL; 1401ab64890Smrg 1411ab64890Smrg list_src = string_list; 1421ab64890Smrg count = list_count; 1431ab64890Smrg for (length = 0; count-- > 0; list_src++) 1449c019ec5Smaya length = length + (int) strlen(*list_src) + 1; 1451ab64890Smrg 146eb411b4bSmrg dst = Xmalloc(length); 1471ab64890Smrg if (dst == NULL) { 1481ab64890Smrg Xfree(string_list_ret); 1491ab64890Smrg return (char **) NULL; 1501ab64890Smrg } 1511ab64890Smrg 1521ab64890Smrg list_src = string_list; 1531ab64890Smrg count = list_count; 1541ab64890Smrg list_dst = string_list_ret; 1551ab64890Smrg for ( ; count-- > 0; list_src++) { 1561ab64890Smrg strcpy(dst, *list_src); 1571ab64890Smrg *list_dst++ = dst; 1581ab64890Smrg dst += strlen(dst) + 1; 1591ab64890Smrg } 1601ab64890Smrg 1611ab64890Smrg return string_list_ret; 1621ab64890Smrg} 1631ab64890Smrg 1641ab64890SmrgXFontSet 1651ab64890SmrgXCreateFontSet ( 1661ab64890Smrg Display *dpy, 1671ab64890Smrg _Xconst char *base_font_name_list, 1681ab64890Smrg char ***missing_charset_list, 1691ab64890Smrg int *missing_charset_count, 1701ab64890Smrg char **def_string) 1711ab64890Smrg{ 1721ab64890Smrg XOM om; 1731ab64890Smrg XOC oc; 1741ab64890Smrg XOMCharSetList *list; 1751ab64890Smrg 1761ab64890Smrg *missing_charset_list = NULL; 1771ab64890Smrg *missing_charset_count = 0; 1781ab64890Smrg 1791ab64890Smrg om = XOpenOM(dpy, NULL, NULL, NULL); 1801ab64890Smrg if (om == NULL) 1811ab64890Smrg return (XFontSet) NULL; 18261b2299dSmrg 1831ab64890Smrg if ((oc = XCreateOC(om, XNBaseFontName, base_font_name_list, NULL))) { 1841ab64890Smrg list = &oc->core.missing_list; 1851ab64890Smrg oc->core.om_automatic = True; 1861ab64890Smrg } else 1871ab64890Smrg list = &om->core.required_charset; 18861b2299dSmrg 1891ab64890Smrg *missing_charset_list = copy_string_list(list->charset_list, 1901ab64890Smrg list->charset_count); 1911ab64890Smrg *missing_charset_count = list->charset_count; 1921ab64890Smrg 1931ab64890Smrg if (list->charset_list && *missing_charset_list == NULL) 1941ab64890Smrg oc = NULL; 1951ab64890Smrg 1961ab64890Smrg if (oc && def_string) { 1971ab64890Smrg *def_string = oc->core.default_string; 1981ab64890Smrg if (!*def_string) 1993233502eSmrg *def_string = (char *)""; 2001ab64890Smrg } 20161b2299dSmrg 2021ab64890Smrg if (oc == NULL) 2031ab64890Smrg XCloseOM(om); 2041ab64890Smrg 2051ab64890Smrg return (XFontSet) oc; 2061ab64890Smrg} 2071ab64890Smrg 2081ab64890Smrgint 2091ab64890SmrgXFontsOfFontSet( 2101ab64890Smrg XFontSet font_set, 2111ab64890Smrg XFontStruct ***font_struct_list, 2121ab64890Smrg char ***font_name_list) 2131ab64890Smrg{ 2141ab64890Smrg *font_name_list = font_set->core.font_info.font_name_list; 2151ab64890Smrg *font_struct_list = font_set->core.font_info.font_struct_list; 2161ab64890Smrg return font_set->core.font_info.num_font; 2171ab64890Smrg} 2181ab64890Smrg 2191ab64890Smrgchar * 2201ab64890SmrgXBaseFontNameListOfFontSet(XFontSet font_set) 2211ab64890Smrg{ 2221ab64890Smrg return font_set->core.base_name_list; 2231ab64890Smrg} 2241ab64890Smrg 2251ab64890Smrgchar * 2261ab64890SmrgXLocaleOfFontSet(XFontSet font_set) 2271ab64890Smrg{ 2281ab64890Smrg return font_set->core.om->core.lcd->core->name; 2291ab64890Smrg} 2301ab64890Smrg 2311ab64890SmrgBool 2321ab64890SmrgXContextDependentDrawing(XFontSet font_set) 2331ab64890Smrg{ 2341ab64890Smrg return font_set->core.om->core.context_dependent; 2351ab64890Smrg} 2361ab64890Smrg 2371ab64890SmrgBool 2381ab64890SmrgXDirectionalDependentDrawing(XFontSet font_set) 2391ab64890Smrg{ 2401ab64890Smrg return font_set->core.om->core.directional_dependent; 2411ab64890Smrg} 2421ab64890Smrg 2431ab64890SmrgBool 2441ab64890SmrgXContextualDrawing(XFontSet font_set) 2451ab64890Smrg{ 2461ab64890Smrg return font_set->core.om->core.contextual_drawing; 2471ab64890Smrg} 2481ab64890Smrg 2491ab64890SmrgXFontSetExtents * 2501ab64890SmrgXExtentsOfFontSet(XFontSet font_set) 2511ab64890Smrg{ 2521ab64890Smrg if (!font_set) 2531ab64890Smrg return NULL; 2541ab64890Smrg return &font_set->core.font_set_extents; 2551ab64890Smrg} 2561ab64890Smrg 2571ab64890Smrgvoid 2581ab64890SmrgXFreeFontSet( 2591ab64890Smrg Display *dpy, 2601ab64890Smrg XFontSet font_set) 2611ab64890Smrg{ 2621ab64890Smrg XCloseOM(font_set->core.om); 2631ab64890Smrg} 264