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.
8 * It is based on code by Tomohiro Kubota; see
9 * <http://www.debian.org/doc/manuals/intro-i18n/ch-examples.en.html#s13.4.5>.
11 * Copyright © 1999-2001 Tomohiro KUBOTA.
13 * This manual is free software; you may redistribute it and/or modify it under
14 * the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2, or (at your option) any later
18 * This is distributed in the hope that it will be useful, but without any
19 * warranty; without even the implied warranty of merchantability or fitness
20 * for a particular purpose. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License along with
24 * this program; if not, write to the Free Software Foundation, Inc., 51
25 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 #include <ioncore/common.h>
33 #include <ioncore/global.h>
35 #ifndef CF_FONT_ELEMENT_SIZE
36 #define CF_FONT_ELEMENT_SIZE 50
39 #define FNT_D(X) /*X*/
42 static const char *get_font_element(const char *pattern
, char *buf
,
52 while((v
=va_arg(va
, char *))!=NULL
){
53 p
=libtu_strcasestr(pattern
, v
);
55 strncpy(buf
, p
+1, bufsiz
-2);
63 strncpy(buf
, "*", bufsiz
);
68 static const char *get_font_size(const char *pattern
, int *size
)
74 for(p
=pattern
; 1; p
++){
76 if(p2
!=NULL
&& n
>1 && n
<72){
79 *size
=16; return NULL
;
82 if(n
>1 && n
<72 && p2
!=NULL
){
87 }else if(*p
>='0' && *p
<='9' && p2
!=NULL
){
97 XFontSet
de_create_font_set(const char *fontname
)
100 char **missing
=NULL
, *def
="-";
101 int nmissing
, pixel_size
=0;
102 char weight
[CF_FONT_ELEMENT_SIZE
], slant
[CF_FONT_ELEMENT_SIZE
];
103 const char *nfontname
=fontname
;
107 FNT_D(fprintf(stderr
, "FNTRQ: %s\n", fontname
));
109 fs
=XCreateFontSet(ioncore_g
.dpy
, fontname
, &missing
, &nmissing
, &def
);
111 if(fs
&& nmissing
==0){
113 XFreeStringList(missing
);
117 /* Not a warning, nothing serious */
118 FNT_D(fprintf(stderr
, "Failed to load fontset.\n"));
124 XFreeStringList(missing
);
126 lc
=setlocale(LC_CTYPE
, NULL
);
127 if(lc
!=NULL
&& strcmp(lc
, "POSIX")!=0 && strcmp(lc
, "C")!=0)
130 setlocale(LC_CTYPE
, "C");
132 fs
=XCreateFontSet(ioncore_g
.dpy
, fontname
, &missing
, &nmissing
, &def
);
135 setlocale(LC_CTYPE
, lcc
);
140 #ifndef CF_NO_FONTSET_KLUDGE
143 XFontStruct
**fontstructs
;
145 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
146 nfontname
=fontnames
[0];
149 get_font_element(nfontname
, weight
, CF_FONT_ELEMENT_SIZE
,
150 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
151 get_font_element(nfontname
, slant
, CF_FONT_ELEMENT_SIZE
,
152 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
153 get_font_size(nfontname
, &pixel_size
);
155 if(!strcmp(weight
, "*"))
156 strncpy(weight
, "medium", CF_FONT_ELEMENT_SIZE
);
157 if(!strcmp(slant
, "*"))
158 strncpy(slant
, "r", CF_FONT_ELEMENT_SIZE
);
161 else if(pixel_size
>97)
164 if(ioncore_g
.enc_utf8
){
165 libtu_asprintf(&pattern2
,
167 "-misc-fixed-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
168 "-misc-fixed-*-*-*-*-%d-*-*-*-*-*-*-*",
169 fontname
, weight
, slant
, pixel_size
, pixel_size
);
171 libtu_asprintf(&pattern2
,
173 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
174 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*",
175 fontname
, weight
, slant
, pixel_size
, pixel_size
);
181 FNT_D(fprintf(stderr
, "NRQ: %s\n", pattern2
));
186 XFreeStringList(missing
);
188 XFreeFontSet(ioncore_g
.dpy
, fs
);
190 FNT_D(if(fs
) fprintf(stderr
, "Trying '%s'.\n", nfontname
));
192 fs
=XCreateFontSet(ioncore_g
.dpy
, nfontname
, &missing
, &nmissing
, &def
);
199 XFreeStringList(missing
);