4 * This file contains routines to attempt to add fonts to a font pattern
5 * so that XCreateFontSet will not fail because the given font(s) do not
6 * contain all the characters required by the locale. The original code
7 * was apparently written by Tomohiro Kubota; see
8 * <http://www.debian.org/doc/manuals/intro-i18n/ch-examples.en.html#s13.4.5>.
16 #include <ioncore/common.h>
17 #include <ioncore/global.h>
19 #ifndef CF_FONT_ELEMENT_SIZE
20 #define CF_FONT_ELEMENT_SIZE 50
23 #define FNT_D(X) /*X*/
26 static const char *get_font_element(const char *pattern, char *buf,
36 while((v=va_arg(va, char *))!=NULL){
37 p=libtu_strcasestr(pattern, v);
39 strncpy(buf, p+1, bufsiz-2);
47 strncpy(buf, "*", bufsiz);
52 static const char *get_font_size(const char *pattern, int *size)
58 for(p=pattern; 1; p++){
60 if(p2!=NULL && n>1 && n<72){
63 *size=16; return NULL;
66 if(n>1 && n<72 && p2!=NULL){
71 }else if(*p>='0' && *p<='9' && p2!=NULL){
81 XFontSet de_create_font_set(const char *fontname)
84 char **missing=NULL, *def="-";
85 int nmissing, pixel_size=0;
86 char weight[CF_FONT_ELEMENT_SIZE], slant[CF_FONT_ELEMENT_SIZE];
87 const char *nfontname=fontname;
91 FNT_D(fprintf(stderr, "FNTRQ: %s\n", fontname));
93 fs=XCreateFontSet(ioncore_g.dpy, fontname, &missing, &nmissing, &def);
95 if(fs && nmissing==0){
97 XFreeStringList(missing);
101 /* Not a warning, nothing serious */
102 FNT_D(fprintf(stderr, "Failed to load fontset.\n"));
108 XFreeStringList(missing);
110 lc=setlocale(LC_CTYPE, NULL);
111 if(lc!=NULL && strcmp(lc, "POSIX")!=0 && strcmp(lc, "C")!=0)
114 setlocale(LC_CTYPE, "C");
116 fs=XCreateFontSet(ioncore_g.dpy, fontname, &missing, &nmissing, &def);
119 setlocale(LC_CTYPE, lcc);
124 #ifndef CF_NO_FONTSET_KLUDGE
127 XFontStruct **fontstructs;
129 XFontsOfFontSet(fs, &fontstructs, &fontnames);
130 nfontname=fontnames[0];
133 get_font_element(nfontname, weight, CF_FONT_ELEMENT_SIZE,
134 "-medium-", "-bold-", "-demibold-", "-regular-", NULL);
135 get_font_element(nfontname, slant, CF_FONT_ELEMENT_SIZE,
136 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL);
137 get_font_size(nfontname, &pixel_size);
139 if(!strcmp(weight, "*"))
140 strncpy(weight, "medium", CF_FONT_ELEMENT_SIZE);
141 if(!strcmp(slant, "*"))
142 strncpy(slant, "r", CF_FONT_ELEMENT_SIZE);
145 else if(pixel_size>97)
148 if(ioncore_g.enc_utf8){
149 libtu_asprintf(&pattern2,
151 "-misc-fixed-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
152 "-misc-fixed-*-*-*-*-%d-*-*-*-*-*-*-*",
153 fontname, weight, slant, pixel_size, pixel_size);
155 libtu_asprintf(&pattern2,
157 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
158 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*",
159 fontname, weight, slant, pixel_size, pixel_size);
165 FNT_D(fprintf(stderr, "NRQ: %s\n", pattern2));
170 XFreeStringList(missing);
172 XFreeFontSet(ioncore_g.dpy, fs);
174 FNT_D(if(fs) fprintf(stderr, "Trying '%s'.\n", nfontname));
176 fs=XCreateFontSet(ioncore_g.dpy, nfontname, &missing, &nmissing, &def);
183 XFreeStringList(missing);