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 * The original code was apparently written by Tomohiro Kubota; see
9 * <http://www.debian.org/doc/manuals/intro-i18n/ch-examples.en.html#s13.4.5>.
11 * However, the code that this file is based on, was taken from:
13 * Screen.cc for Blackbox - an X11 Window manager
14 * Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
15 * Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
17 * Permission is hereby granted, free of charge, to any person obtaining a
18 * copy of this software and associated documentation files (the "Software"),
19 * to deal in the Software without restriction, including without limitation
20 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
21 * and/or sell copies of the Software, and to permit persons to whom the
22 * Software is furnished to do so, subject to the following conditions:
24 * The above copyright notice and this permission notice shall be included in
25 * all copies or substantial portions of the Software.
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
33 * DEALINGS IN THE SOFTWARE.
40 #include <ioncore/common.h>
41 #include <ioncore/global.h>
43 #ifndef CF_FONT_ELEMENT_SIZE
44 #define CF_FONT_ELEMENT_SIZE 50
47 #define FNT_D(X) /*X*/
50 static const char *get_font_element(const char *pattern
, char *buf
,
60 while((v
=va_arg(va
, char *))!=NULL
){
61 p
=libtu_strcasestr(pattern
, v
);
63 strncpy(buf
, p
+1, bufsiz
-2);
71 strncpy(buf
, "*", bufsiz
);
76 static const char *get_font_size(const char *pattern
, int *size
)
82 for(p
=pattern
; 1; p
++){
84 if(p2
!=NULL
&& n
>1 && n
<72){
87 *size
=16; return NULL
;
90 if(n
>1 && n
<72 && p2
!=NULL
){
95 }else if(*p
>='0' && *p
<='9' && p2
!=NULL
){
105 XFontSet
de_create_font_set(const char *fontname
)
108 char **missing
=NULL
, *def
="-";
109 int nmissing
, pixel_size
=0;
110 char weight
[CF_FONT_ELEMENT_SIZE
], slant
[CF_FONT_ELEMENT_SIZE
];
111 const char *nfontname
=fontname
;
115 FNT_D(fprintf(stderr
, "FNTRQ: %s\n", fontname
));
117 fs
=XCreateFontSet(ioncore_g
.dpy
, fontname
, &missing
, &nmissing
, &def
);
119 if(fs
&& nmissing
==0){
121 XFreeStringList(missing
);
125 /* Not a warning, nothing serious */
126 FNT_D(fprintf(stderr
, "Failed to load fontset.\n"));
132 XFreeStringList(missing
);
134 lc
=setlocale(LC_CTYPE
, NULL
);
135 if(lc
!=NULL
&& strcmp(lc
, "POSIX")!=0 && strcmp(lc
, "C")!=0)
138 setlocale(LC_CTYPE
, "C");
140 fs
=XCreateFontSet(ioncore_g
.dpy
, fontname
, &missing
, &nmissing
, &def
);
143 setlocale(LC_CTYPE
, lcc
);
148 #ifndef CF_NO_FONTSET_KLUDGE
151 XFontStruct
**fontstructs
;
153 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
154 nfontname
=fontnames
[0];
157 get_font_element(nfontname
, weight
, CF_FONT_ELEMENT_SIZE
,
158 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
159 get_font_element(nfontname
, slant
, CF_FONT_ELEMENT_SIZE
,
160 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
161 get_font_size(nfontname
, &pixel_size
);
163 if(!strcmp(weight
, "*"))
164 strncpy(weight
, "medium", CF_FONT_ELEMENT_SIZE
);
165 if(!strcmp(slant
, "*"))
166 strncpy(slant
, "r", CF_FONT_ELEMENT_SIZE
);
169 else if(pixel_size
>97)
172 if(ioncore_g
.enc_utf8
){
173 libtu_asprintf(&pattern2
,
175 "-misc-fixed-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
176 "-misc-fixed-*-*-*-*-%d-*-*-*-*-*-*-*",
177 fontname
, weight
, slant
, pixel_size
, pixel_size
);
179 libtu_asprintf(&pattern2
,
181 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
182 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*",
183 fontname
, weight
, slant
, pixel_size
, pixel_size
);
189 FNT_D(fprintf(stderr
, "NRQ: %s\n", pattern2
));
194 XFreeStringList(missing
);
196 XFreeFontSet(ioncore_g
.dpy
, fs
);
198 FNT_D(if(fs
) fprintf(stderr
, "Trying '%s'.\n", nfontname
));
200 fs
=XCreateFontSet(ioncore_g
.dpy
, nfontname
, &missing
, &nmissing
, &def
);
207 XFreeStringList(missing
);