⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xcrfntset.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
static void_MaxBounds(des, src)XCharStruct    *des;XCharStruct    *src;{    MAX(des->lbearing, src->lbearing);    MAX(des->rbearing, src->rbearing);    MAX(des->width, src->width);    MAX(des->ascent, src->ascent);    MAX(des->descent, src->descent);    MAX(des->attributes, src->attributes);}static voidgetFontCharStruct(font_strct, font_count,          min_bounds, max_bounds, ascent, descent)XFontStruct   **font_strct;int             font_count;XCharStruct    *min_bounds,               *max_bounds;int            *ascent,               *descent;{    int		i;    *min_bounds = font_strct[0]->min_bounds;    *max_bounds = font_strct[0]->max_bounds;    *ascent = font_strct[0]->ascent;    *descent = font_strct[0]->descent;    for (i = 1; i < font_count; i++) {	_MinBounds(min_bounds, &font_strct[i]->min_bounds);	_MaxBounds(max_bounds, &font_strct[i]->max_bounds);	if (*ascent < font_strct[i]->ascent) {	    *ascent = font_strct[i]->ascent;	}	if (*descent < font_strct[i]->descent) {	    *descent = font_strct[i]->descent;	}    }}#ifdef XMLstatic intAlreadyLoad(id_tmp, found, charset, GLorGR)int		id_tmp[];int		found;char		*charset;_CSID		GLorGR;{    int		i;    if ((id_tmp[found] = _XcwNameGetGLorGRId(charset, GLorGR)) == ND)	return 0;    for (i = 0; i < found; i++) {	if (id_tmp[i] == id_tmp[found])	    return 0;    }    return 1;}static intTryLoad(s_tmp, id_tmp, found, info, charset, GLorGR)XFontStruct	*s_tmp[];int		id_tmp[];int		found;XFontStruct     *info;char		*charset;_CSID		GLorGR;{    if (! (s_tmp[found] = (XFontStruct *)Xmalloc(sizeof(XFontStruct))))	return 0;#ifndef MUSTCOPY    *s_tmp[found] = info[0];#else /* MUSTCOPY */    SetFontInfo(s_tmp[found], &info[0]);#endif /* MUSTCOPY */    s_tmp[found]->fid = 0;      /* make sure unloaded */    return 1;}XFontSet_XsimlCreateFontSet(lcd, dpy, base_font_name_list, font_list, font_count,		    missing_charset_list, missing_charset_count)    XLCd	    lcd;    Display        *dpy;    char           *base_font_name_list;    char          **font_list;    int             font_count;    char         ***missing_charset_list;    int            *missing_charset_count;{    XsiFontSet      font_set;    char           *m_tmp[MAXCHARSETS],                   *f_tmp[MAXCHARSETS];    XFontStruct    *s_tmp[MAXCHARSETS];    int             id_tmp[MAXCHARSETS];    int             found = 1, miss = 0, loadASCIIFONT = 0;    int             count, i, j, notfound;    for (i = 0; i < font_count; i++) {        char	**list;	char	tmp[256];	if (isBaseFontName(font_list[i])) {	    strcpy(tmp, font_list[i]);	    strcat(tmp, "-*-*");	    list = XListFonts(dpy, tmp, 1024, &count);	} else {	    list = XListFonts(dpy, font_list[i], 1024, &count);	}        notfound = 1;        for (j = 0; j < count; j++) {	    XFontStruct  *info;	    char	**info_list;	    int		  count_list;	    if (found >= (MAXCHARSETS - 1))		break;	    info = NULL;	    if (isXLFDname(list[j]) ) {		if (! (f_tmp[found] = Xmalloc((unsigned)strlen(list[j]) + 1))) {		    return NULL;		}		strcpy(f_tmp[found], list[j]);	    } else  {		info_list = XListFontsWithInfo(dpy, list[j], 1, &count_list, &info);		if (count_list != 1) {		    /* never go to here. */		    continue;		}		f_tmp[found] = getXLFDName(dpy, &info[0]);	    }	    if (f_tmp[found] != NULL) {		char	charset[64];		char	*start = f_tmp[found];		int	k;		for (k = 0; k < CSETPOS; k++) {		    start = index(start, XFNDELIM);		    if (start == NULL)			/* not goes here */			return NULL;		    start++;		}		copyLowercase(charset, start);		/* If font name is ISO8859.* Treate for ISO8859.1 GL */		if (strncmp(charset, "iso8859-", 8) == 0) {		    if(!loadASCIIFONT) {			f_tmp[0] = f_tmp[found];			s_tmp[0] = XLoadQueryFont(dpy, f_tmp[0]);			id_tmp[0] = CODESET0;			loadASCIIFONT = 1;		    }		} else {		    if (AlreadyLoad(id_tmp, found, charset, GL)) {			if (!info)			    info_list = XListFontsWithInfo(dpy, list[j], 1, &count_list, &info);			if (count_list != 1)			    /* never go to here. */			    continue;			f_tmp[found+1] = f_tmp[found];			found += TryLoad(s_tmp, id_tmp, found, info, charset, GL);		    }		}		if (AlreadyLoad(id_tmp, found, charset, GR)) {		    if (!info)			info_list = XListFontsWithInfo(dpy, list[j], 1, &count_list, &info);		    if (count_list != 1)			/* never go to here. */			continue;		    found += TryLoad(s_tmp, id_tmp, found, info, charset, GR);		}		notfound = 0;		if (info)		    XFreeFontInfo(info_list, info, count_list);	    }	}        if (notfound)            m_tmp[miss++] = font_list[i];	XFreeFontNames(list);    }    *missing_charset_list = reallocList(m_tmp, miss);    *missing_charset_count = miss;    if (miss == font_count) {        return NULL;    }    if (!loadASCIIFONT) {	if(! (f_tmp[0] = (char *)Xmalloc(strlen("fixed") + 1)))	    return NULL;	strcpy(f_tmp[0], "fixed");	/* use defalt font */	s_tmp[0] = XLoadQueryFont(dpy, f_tmp[0]);    }    if(! (font_set = (XsiFontSet) Xmalloc(sizeof(XsiFontSetRec)))) {	if (s_tmp[0] && s_tmp[0]->fid) {	    XFreeFont(dpy, s_tmp[0]);	}	return NULL;    }        XFreeStringList(font_list);    font_set->methods = (XFontSetMethods) &fs_methods;    font_set->core.base_name_list = base_font_name_list;    font_set->core.num_of_fonts = found;    font_set->core.lcd = lcd;    font_set->core.font_name_list = reallocList(f_tmp, found);    font_set->core.font_struct_list = reallocFontStruct(s_tmp, found);    font_set->core.context_dependent = False;    font_set->display = dpy;    font_set->xlc = NULL;    font_set->ctid = reallocCtidList(f_tmp, id_tmp, found);    getFontCharStruct(font_set->core.font_struct_list, found,		      &font_set->min_bounds, &font_set->max_bounds,		      &font_set->ascent, &font_set->descent);    font_set->core.default_string = NULL;    for (i = 0; (int)i < found; i++) {	Xfree((char *)f_tmp[i]);    }    /*     * set the ink bounding box of font_set.     */    font_set->core.font_set_extents.max_ink_extent.x =            font_set->min_bounds.lbearing;    font_set->core.font_set_extents.max_ink_extent.y =            - font_set->max_bounds.ascent;    font_set->core.font_set_extents.max_ink_extent.width =            font_set->max_bounds.rbearing - font_set->min_bounds.lbearing;    font_set->core.font_set_extents.max_ink_extent.height =            font_set->max_bounds.ascent + font_set->max_bounds.descent;    /*     * set the logical bounding box of font_set.     * suppose the lbearing >= 0;     */    font_set->core.font_set_extents.max_logical_extent.x = 0;    font_set->core.font_set_extents.max_logical_extent.y =            - font_set->ascent;    font_set->core.font_set_extents.max_logical_extent.width =            font_set->max_bounds.width;    font_set->core.font_set_extents.max_logical_extent.height =            font_set->ascent + font_set->descent;    return (XFontSet)font_set;}XFontSetXmlCreateFontSet (dpy, base_font_name_list, missing_charset_list,		  missing_charset_count, def_string)    Display        *dpy;    char           *base_font_name_list;    char         ***missing_charset_list;    int            *missing_charset_count;    char          **def_string;{    XLCd lcd = _XlcCurrentLC();    char *base_name;    char **name_list;    int count;    XFontSet font_set;    *missing_charset_list = NULL;    *missing_charset_count = 0;    if (!lcd)	return NULL;    base_name = (char *)Xmalloc(strlen(base_font_name_list) + 1);    if (!base_name)	return NULL;    strcpy(base_name, base_font_name_list);    name_list = _XParseBaseFontNameList(base_name, &count);    if (!name_list) {	Xfree(base_name);        return NULL;    }    font_set = _XsimlCreateFontSet (lcd, dpy, base_name, name_list, count,				    missing_charset_list,				    missing_charset_count);    if (!font_set) {	XFreeStringList(name_list);	Xfree(base_name);    } else if (def_string) {	*def_string = font_set->core.default_string;	if (!*def_string)	    *def_string = "";    }    return font_set;}#endif /* XML */XFontSet_XsiCreateFontSet(lcd, dpy, base_font_name_list, font_list, font_count,		  missing_charset_list, missing_charset_count)    XLCd	    lcd;    Display        *dpy;    char           *base_font_name_list;    char          **font_list;    int             font_count;    char         ***missing_charset_list;    int            *missing_charset_count;{    XsiFontSet      font_set;    int             cset_count;    char           *m_tmp[MAXCHARSETS],                   *f_tmp[MAXCHARSETS];    XFontStruct    *s_tmp[MAXCHARSETS];    int		    id_tmp[MAXCHARSETS];    int             found = 0, miss = 0, j;    _CSID	    i;    XLocale	    xlocale = ((XsiLCd)lcd)->xlc;    cset_count = _Xmbfsnum(xlocale);    for (i = 0; (int)i < cset_count; i++) {	s_tmp[i] = NULL;    }    for (j = 0; j < font_count && found < cset_count; j++) {        char  **list;        int	k, count;	char	tmp[256];	if (isBaseFontName(font_list[j])) {	    strcpy(tmp, font_list[j]);	    strcat(tmp, "-*-*");	    list = XListFonts(dpy, tmp, 1024, &count);	} else {	    list = XListFonts(dpy, font_list[j], 1024, &count);	}	for (k = 0; k < count && found < cset_count; k++) {	    dbg_printf("XCreateFontSet: font = %s\n", list[k], 0);	    found += findFont(dpy, list[k], xlocale, f_tmp, s_tmp, id_tmp);	}	XFreeFontNames(list);    }    if (found < cset_count) {	/* find missing charset */	for (i = 0; (int)i < cset_count; i++) {	    if (s_tmp[i] == NULL) {		Charset	*cset = _Xmbfscs(xlocale, i);		m_tmp[miss] = cset->cs_name;		dbg_printf("XCreateFontSet: m_tmp[%d] = %s\n",			   miss, m_tmp[miss]);		miss++;	    }	}    }    *missing_charset_list = reallocList(m_tmp, miss);    *missing_charset_count = miss;    if (miss == cset_count) {        return NULL;    }    if (! (font_set = (XsiFontSet)Xmalloc(sizeof(XsiFontSetRec)))) {	for (i = 0; (int)i < found; i++) {	    if (s_tmp[i] && s_tmp[i]->fid)		XFreeFont(dpy, s_tmp[i]);	}        return NULL;    }    XFreeStringList(font_list);#ifdef PRELOAD    if (!miss && _Xmbtype(xlocale) == CDS_STATELESS && cset_count <= 2 &&	xlocale->xlc_db->lc_codeset->cds_mblen[0] == 1 &&	(cset_count == 1 || xlocale->xlc_db->lc_codeset->cds_mblen[1] == 1) &&	found <= 2 && (found == 1 || !strcmp(f_tmp[0], f_tmp[1])))	font_set->methods = (XFontSetMethods) &fs8_methods;    else#endif	font_set->methods = (XFontSetMethods) &fs_methods;    font_set->core.base_name_list = base_font_name_list;    font_set->core.num_of_fonts = found;    font_set->core.lcd = lcd;    font_set->display = dpy;    font_set->xlc = _XlcDupLocale(xlocale);    font_set->core.font_name_list = reallocList(f_tmp, found);    font_set->core.font_struct_list = reallocFontStruct(s_tmp, found);    font_set->core.context_dependent = False;    font_set->ctid = reallocCtidList(f_tmp, id_tmp, found);    getFontCharStruct(font_set->core.font_struct_list, found,		      &font_set->min_bounds, &font_set->max_bounds,		      &font_set->ascent, &font_set->descent);    font_set->core.default_string = NULL;    for (i = 0; (int)i < found; i++) {	if (f_tmp[i]) Xfree((char *)f_tmp[i]);    }    /*     * set the ink bounding box of font_set.     */    font_set->core.font_set_extents.max_ink_extent.x =             font_set->min_bounds.lbearing;    font_set->core.font_set_extents.max_ink_extent.y =             - font_set->max_bounds.ascent;    font_set->core.font_set_extents.max_ink_extent.width =             font_set->max_bounds.rbearing - font_set->min_bounds.lbearing;    font_set->core.font_set_extents.max_ink_extent.height =             font_set->max_bounds.ascent + font_set->max_bounds.descent;    /*     * set the logical bounding box of font_set.     * suppose the lbearing >= 0;     */    font_set->core.font_set_extents.max_logical_extent.x = 0;    font_set->core.font_set_extents.max_logical_extent.y =             - font_set->ascent;    font_set->core.font_set_extents.max_logical_extent.width =             font_set->max_bounds.width;    font_set->core.font_set_extents.max_logical_extent.height =             font_set->ascent + font_set->descent;    return (XFontSet)font_set;}XFontStruct *_XsiQueryFontSetFromId(font_set, ctid)    XFontSet   font_set;    int	       ctid;{    XFontStruct *font;    int          i;    for (i = 0; i < font_set->core.num_of_fonts; i++) {	if (((XsiFontSet)font_set)->ctid[i] == ctid)	    break;    }    if (i == font_set->core.num_of_fonts)	return NULL;    if (font_set->core.font_struct_list[i]->fid > 0)        /* already loaded */        return font_set->core.font_struct_list[i];    if ((font = XLoadQueryFont(((XsiFontSet)font_set)->display,			       font_set->core.font_name_list[i])) == NULL)        return NULL;    Xfree((char *)font_set->core.font_struct_list[i]);    font_set->core.font_struct_list[i] = font;    return font;}#ifdef XMLvoid_XsiQueryFontSetWithName(font_set, font_name)    XFontSet	font_set;    char       *font_name; /* font name or charset name */{    Display    *dpy = ((XsiFontSet)font_set)->display;    char       *fname;    int		ctid;    int		count, i;    char	**list;    char	tmp[256];    char	charset[64];    if (isBaseFontName(font_name)) {	strcpy(tmp, font_name);	strcat(tmp, "-*-*");	list = XListFonts(dpy, tmp, 1024, &count);    } else {	list = XListFonts(dpy, font_name, 1024, &count);    }    if (count == 0) { /* charset name */	copyLowercase(charset, font_name);	if ((ctid = _XcwNameGetGLorGRId(charset, GL)) != ND) {	    _XsiQueryFontSetFromId(font_set, ctid);	}	if ((ctid = _XcwNameGetGLorGRId(charset, GR)) != ND) {	    _XsiQueryFontSetFromId(font_set, ctid);	}    } else {	/* font name */	for (i = 0; i < count; i++) {	    if (isXLFDname(list[i])) {		fname = list[i];	    } else  {		char	**info_list;		XFontStruct *font;		info_list = XListFontsWithInfo(dpy, list[i],					       1, &count, &font);		if (count != 1)		    /* not goes here */		    return;		fname = getXLFDName(dpy, font);		XFreeFontInfo(info_list, font, count);	    }	    if (fname != NULL) {		char	*start = fname;		int	k;		for (k = 0; k < CSETPOS; k++) {		    start = index(start, XFNDELIM);		    if (start == NULL)			/* not goes here */			return;		    start++;		}		copyLowercase(charset, start);		if ((ctid = _XcwNameGetGLorGRId(charset, GL)) != ND) {		    _XsiQueryFontSetFromId(font_set, ctid);		}		if ((ctid = _XcwNameGetGLorGRId(charset, GR)) != ND) {		    _XsiQueryFontSetFromId(font_set, ctid);		}	    }	}    }    XFreeFontNames(list);}#endif /* XML */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -