📄 xcrfntset.c
字号:
/* * $XConsortium: XCrFntSet.c,v 1.48 92/09/10 17:06:53 rws Exp $ *//* * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation, * and Nippon Telegraph and Telephone Corporation * Copyright 1991 by the Massachusetts Institute of Technology * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the names of OMRON, NTT Software, NTT, and M.I.T. * not be used in advertising or publicity pertaining to distribution of the * software without specific, written prior permission. OMRON, NTT Software, * NTT, and M.I.T. make no representations about the suitability of this * software for any purpose. It is provided "as is" without express or * implied warranty. * * OMRON, NTT SOFTWARE, NTT, AND M.I.T. DISCLAIM ALL WARRANTIES WITH REGARD * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL OMRON, NTT SOFTWARE, NTT, OR M.I.T. BE * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Authors: Li Yuhong OMRON Corporation * Tatsuya Kato NTT Software Corporation * Hiroshi Kuribayashi OMRON Coproration * Muneiyoshi Suzuki Nippon Telegraph and Telephone Co. * *//* * _XsiCreateFontSet() * XmlCreateFontSet() * _XsiQueryFontSetFromId() * _XsiQueryFontSetWithName() * */#include <X11/Xatom.h>#include "Xlibint.h"#include "Xi18nint.h"#include <X11/Xos.h>#ifdef DEBUG#include <stdio.h>#endif#include <ctype.h>#define PRELOAD 1 /* preload fonts if locale exists */ #ifdef DEBUG#define dbg_printf(f, p1, p2) fprintf(stderr, f, p1, p2)#else#define dbg_printf(f, p1, p2)#endif#define XFNEXT_PREFIX '+' /* XLFD External prefix */#define XFNDELIM '-' /* XLFD Delimiter */#define DELIM_COUNT 13 /* Number of delimiters */#define CSETPOS 13 /* CHARSET-REGISTRY position */#if __STDC__ && !defined(NORCONST)#define RConst const#else#define RConst /**/#endif/*ARGSUSED*/static void_XsiFreeFontSet(dpy, font_set) Display *dpy; XFontSet font_set;{ if (((XsiFontSet)font_set)->xlc) _XlcFreeLocale(((XsiFontSet)font_set)->xlc); if (font_set->core.num_of_fonts > 0) Xfree((char *) ((XsiFontSet)font_set)->ctid);}static RConst XFontSetMethodsRec fs_methods = { _XsiFreeFontSet, _XsimbTextEscapement, _XsimbTextExtents, _XsimbTextPerCharExtents, _XsimbDrawString, _XsimbDrawImageString, _XsiwcTextEscapement, _XsiwcTextExtents, _XsiwcTextPerCharExtents, _XsiwcDrawString, _XsiwcDrawImageString};static RConst XFontSetMethodsRec fs8_methods = { _XsiFreeFontSet, _Xsimb8TextEscapement, _Xsimb8TextExtents, _XsimbTextPerCharExtents, _Xsimb8DrawString, _Xsimb8DrawImageString, _XsiwcTextEscapement, _XsiwcTextExtents, _XsiwcTextPerCharExtents, _XsiwcDrawString, _XsiwcDrawImageString};#define lowercase(c) ((isalpha(c) && isupper(c)) ? tolower(c) : c)#if defined(MUSTCOPY)static voidSetFontInfo(des, src)XFontStruct *des, *src ;{ des->ext_data = src->ext_data; des->fid = src->fid; des->direction = src->direction; des->min_char_or_byte2 = src->min_char_or_byte2; des->max_char_or_byte2 = src->max_char_or_byte2; des->min_byte1 = src->min_byte1; des->max_byte1 = src->max_byte1; des->all_chars_exist = src->all_chars_exist; des->default_char = src->default_char; des->n_properties = src->n_properties; des->properties = src->properties; des->min_bounds = src->min_bounds; des->max_bounds = src->max_bounds; des->per_char = src->per_char; des->ascent = src->ascent; des->descent = src->descent;}#endifstatic intcompareLowercase(s1, s2)char *s1;char *s2;{ register char c1, c2; while ((c1 = *s1) && (c2 = *s2)) { c1 = lowercase(c1); c2 = lowercase(c2); if (c1 != c2) break; s1++, s2++; } /* * do not use c1 and c2 here. */ return (*s1 - *s2);}static intcompareNLowercase(s1, s2, n)char *s1;char *s2;int n;{ register char c1, c2; while ((n > 0) && (c1 = *s1) && (c2 = *s2)) { c1 = lowercase(c1); c2 = lowercase(c2); if (c1 != c2) break; s1++, s2++, n--; } /* * do not use c1 and c2 here. * in the case, if (c1 = *s1) is NULL, stop while, so no value of c2. */ return (n == 0)? 0: (*s1 - *s2);}#ifdef XMLstatic char *copyLowercase(s1, s2)char *s1, *s2;{ register char c; while (c = *s2++) *s1++ = lowercase(c); *s1 = 0; return s1;}#endifstatic char **reallocList(list, count)char *list[];int count;{ char **ret; int i, j; int datalen; char *data; ret = (char **) Xmalloc((unsigned)sizeof(char *) * (count + 1)); if (!ret) return NULL; datalen = 0; for (i = 0, j = 0; j < count; i++) { if (list[i]) { datalen += strlen(list[i]); j++; } } data = (char *) Xmalloc ((unsigned)(datalen + count) * sizeof (char)); if (!data) { Xfree ((char *) ret); return NULL; } for (i = 0, j = 0; j < count; i++) { if (list[i]) { ret[j] = data; strcpy(data, list[i]); data += strlen(list[i]) + 1; j++; } } ret[j] = NULL; return ret;}static XFontStruct **reallocFontStruct(font, count)XFontStruct *font[];int count;{ XFontStruct **ret; int i, j;#if !defined(PRELOAD) || defined(XML) XFontStruct *data;#endif ret = (XFontStruct **) Xmalloc((unsigned)sizeof(XFontStruct *) * count); if (!ret) return NULL;#if defined(PRELOAD) && !defined(XML) for (i = 0, j = 0; j < count; i++) { if (font[i]) { if (font[i]->fid > 0) { ret[j] = font[i]; j++; } } }#else for (i = 0, j = 0; j < count; i++) { if (font[i]) { if (font[i]->fid > 0) { ret[j] = font[i]; } else { data = (XFontStruct *) Xmalloc (sizeof(XFontStruct)); if (!data) { for (j--; j >= 0; j--) { if (ret[j]) Xfree ((char *) ret[j]); } Xfree ((char *) ret); return NULL; } ret[j] = data; bcopy((char *)font[i], (char *)data, sizeof (XFontStruct)); } j++; } }#endif return ret;}static int *reallocCtidList(fn, list, count)char *fn[];int list[];int count;{ int *ret; int i, j; ret = (int *) Xmalloc((unsigned)sizeof(int) * count); if (!ret) return NULL; for (i = 0, j = 0; j < count; i++) { if (fn[i]) { ret[j] = list[i]; j++; } } return ret;}static BoolisXLFDname(font_name)char *font_name;{ int i; char *ptr = font_name; if (*ptr == XFNEXT_PREFIX) { if ((ptr = index(ptr, XFNDELIM)) == NULL) { return False; } } if (*ptr != XFNDELIM) { return False; } for (i = 0; i < DELIM_COUNT; i++) { if ((ptr = index(ptr + 1, XFNDELIM)) == NULL) { return False; } } return True;}static BoolisBaseFontName(font_name) char *font_name;{ int i; char *ptr = font_name; if (*ptr == XFNEXT_PREFIX) { if ((ptr = index(ptr, XFNDELIM)) == NULL) { return False; } } if (*ptr != XFNDELIM) { return False; } for (i = 0; i < DELIM_COUNT-2; i++) { if ((ptr = index(ptr + 1, XFNDELIM)) == NULL) { return False; } } if ((ptr = index(ptr + 1, XFNDELIM)) == NULL) { return True; } return False;}static char *getXLFDName(dpy, info)Display *dpy;XFontStruct *info;{ char *return_value; unsigned long val; if (XGetFontProperty(info, XA_FONT, &val) == False) { dbg_printf("getXLFD: XGetFontProperty == False\n", 0, 0); return NULL; } return_value = XGetAtomName(dpy, val); if (isXLFDname(return_value)) { return return_value; } else { dbg_printf("getXLFD: isXLFDname == Not XLFD\n", 0, 0); Xfree(return_value); return NULL; }}static BoolmatchCharset(font_name, cset, GLorGR) char *font_name, *cset; _CSID GLorGR;{ char *start = font_name; int i; for (i = 0; i < CSETPOS; i++) { start = index(start, XFNDELIM); if (start == NULL) { return False; } start++; } if (compareLowercase(start, cset) == 0) return (True); /* jisx0208.1990-0 is super set of jisx0208.1983-0 */ if (strlen(cset) == 15 && strlen(start) == 15 && *(cset+14) == *(start+14) && !strncmp(cset, "jisx0208.1983", 13)) { return ((compareNLowercase(start, "jisx0208.1990", 13) == 0) ? True : False); } /* GL of ISO8859.* is same as GL of ISO8859.1 */ if (GLorGR == GL && !strncmp(cset, "iso8859-", 8)) { return ((compareNLowercase(start, cset, 8) == 0) ? True : False); } return (False);}static intfindFont(dpy, fname, xlocale, f_tmp, s_tmp, id_tmp) Display *dpy; char *fname; XLocale xlocale; char *f_tmp[]; XFontStruct *s_tmp[]; int id_tmp[];{ XFontStruct *info = NULL; char **list; int count; int cset_count; char *fn = NULL; int ret = 0; _CSID i; if (isXLFDname(fname)) { if(! (fn = Xmalloc((unsigned)strlen(fname) + 1))) return 0; strcpy(fn, fname); } else { list = XListFontsWithInfo(dpy, fname, 1, &count, &info); if (count != 1) { /* never go to here. */ goto _err_return; } if ((fn = getXLFDName(dpy, &info[0])) == NULL) { goto _err_return; } } dbg_printf("findFont: %s\n", fn, 0); cset_count = _Xmbfsnum(xlocale); for (i = CODESET0; (int)i < cset_count; i++) { if (s_tmp[i] == NULL) { Charset *cset = _Xmbfscs(xlocale, i); dbg_printf("findFont: charset[%d] = %s\n", i, cset->cs_name); if (matchCharset(fn, cset->cs_name, cset->cs_GLorGR) == True) { dbg_printf("findFont: matched\n", 0, 0); ret++;#ifdef PRELOAD if (!(s_tmp[i] = XLoadQueryFont(dpy, fn))) ret--;#else /* PRELOAD */ if (!info) list = XListFontsWithInfo(dpy, fname, 1, &count, &info); if (count != 1) { /* never go to here. */ goto _err_return; } if(! (s_tmp[i] = (XFontStruct *) Xmalloc(sizeof(XFontStruct)))){ goto _err_return; }# ifndef MUSTCOPY s_tmp[i] = info[0];# else /* MUSTCOPY */ SetFontInfo(&s_tmp[i], &info[0]);# endif /* MUSTCOPY */ /* indicate the font has not loaded, only info. */ s_tmp[i]->fid = 0;#endif /* PRELOAD */ id_tmp[i] = cset->cs_id; if(! (f_tmp[i] = (char *) Xmalloc(strlen(fn) + 1))) { --ret; goto _err_return; } strcpy(f_tmp[i], fn); } else { f_tmp[i] = NULL; } } }_err_return: if (info) { XFreeFontInfo(list, info, count); } if (fn) Xfree((char *)fn); return ret;}#undef MIN#undef MAX#define MIN(a, b) ((a) = (((a) > (b))? (b): (a)))#define MAX(a, b) ((a) = (((a) < (b))? (b): (a)))/* _MinBounds: if any element of src XCharStruct is less than *//* that of des, replace the des XCharStruct's *//* corresponding element with that of src *//* des: destination min_bound *//* src: source min_bound */static void_MinBounds(des, src)XCharStruct *des;XCharStruct *src;{ MIN(des->lbearing, src->lbearing); MIN(des->rbearing, src->rbearing); MIN(des->width, src->width); MIN(des->ascent, src->ascent); MIN(des->descent, src->descent); MIN(des->attributes, src->attributes);}/* _MinBounds: if any element of src XCharStruct is greater than *//* that of des, replace the des XCharStruct's *//* corresponding element with that of src *//* des: destination min_bound *//* src: source min_bound */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -