51static int attribute(
int n,
const char *p) {
53 if (!*p || *p==
'-' || *p==
'*')
return 0;
55 if (!strncmp(p,
"normal",6) ||
56 !strncmp(p,
"light",5) ||
57 !strncmp(p,
"medium",6) ||
58 !strncmp(p,
"book",4))
return 0;
59 if (!strncmp(p,
"bold",4) || !strncmp(p,
"demi",4))
return FL_BOLD;
61 if (*p ==
'r')
return 0;
62 if (*p ==
'i' || *p ==
'o')
return FL_ITALIC;
64 if (!strncmp(p,
"normal",6))
return 0;
70extern const char* fl_encoding;
71static int use_registry(
const char *p) {
72 return *p && *p!=
'*' && strcmp(p,fl_encoding);
79#define ENDOFBUFFER 127
84 if (!f->fontname[0]) {
86 const char* p = f->name;
91 char *o = f->fontname;
94 if (strstr(p,
"bold")) type =
FL_BOLD;
97 if (*p ==
'*' || *p ==
' ' || *p ==
'-') {
98 do p++;
while (*p ==
'*' || *p ==
' ' || *p ==
'-');
100 if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ =
' ';
102 if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ = *p;
109 const char *
x = fl_font_word(p,2);
if (*
x)
x++;
if (*
x==
'*')
x++;
114 const char *e = fl_font_word(
x,1);
115 if ((e -
x) < (
int)(ENDOFBUFFER - 1)) {
120 strlcpy(f->fontname,
x, ENDOFBUFFER);
121 o = f->fontname+ENDOFBUFFER-1;
125 for (
int n = 3; n <= 6; n++) {
127 if (*e) e++;
x = e; e = fl_font_word(
x,1);
128 int t = attribute(n,
x);
130 if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ =
' ';
131 if ((e -
x) < (
int)(ENDOFBUFFER - (o - f->fontname) - 1)) {
136 strlcpy(o,
x, ENDOFBUFFER - (o - f->fontname) - 1);
137 o = f->fontname+ENDOFBUFFER-1;
143 x = fl_font_word(e,2);
144 if (*
x) {
x++; *o++ =
'(';
while (*
x) *o++ = *
x++; *o++ =
')';}
147 if (type &
FL_BOLD) strlcat(f->fontname,
" bold", ENDOFBUFFER);
148 if (type &
FL_ITALIC) strlcat(f->fontname,
" italic", ENDOFBUFFER);
150 f->fontname[ENDOFBUFFER] = (char)type;
152 if (ap) *ap = f->fontname[ENDOFBUFFER];
159static int ultrasort(
const void *aa,
const void *bb) {
160 const char *a = *(
char **)aa;
161 const char *b = *(
char **)bb;
165 if (*b ==
'-')
return 1;
169 if (isdigit(*a) && isdigit(*b)) {
170 int na = strtol(a, (
char **)&a, 10);
171 int nb = strtol(b, (
char **)&b, 10);
172 if (!ret) ret = na-nb;
173 }
else if (*a != *b) {
182 if (*b !=
'-')
return -1;
186 for (a++; *a && *a++!=
'-';);
187 for (b++; *b && *b++!=
'-';);
192 for (
int n = 2; n <= 6; n++) {
193 int at = attribute(n,a);
194 int bt = attribute(n,b);
196 if (bt >= 0)
return 1;
197 for (;;) {
if (*a!=*b)
return *a-*b; b++;
if (!*a || *a++==
'-')
break;}
199 if (bt < 0)
return -1;
200 a = fl_font_word(a,1);
if (*a) a++;
201 b = fl_font_word(b,1);
if (*b) b++;
202 atype |= at; btype |= bt;
211 a = fl_font_word(a,6);
if (*a) a++;
212 b = fl_font_word(b,6);
if (*b) b++;
213 if (use_registry(a)) {
214 if (!use_registry(b))
return 1;
215 int r = strcmp(a,b);
if (r)
return r;
217 if (use_registry(b))
return -1;
220 if (atype != btype)
return atype-btype;
221 if (asize != bsize)
return asize-bsize;
224 return strcmp(*(
char**)aa, *(
char**)bb);
229static int to_canonical(
char *to,
const char *from,
size_t tolen) {
230 char* c = fl_find_fontsize((
char*)from);
233 int size = strtol(c,(
char**)&endptr,10);
234 if (from[0] ==
'-') {
236 *to++ =
'-'; *to++ =
'*';
237 for (from++; *from && *from !=
'-'; from++);
239 endptr = (
char*)fl_font_word(endptr,6);
240 if (*endptr && !use_registry(endptr+1)) endptr =
"";
244 if (n > (
int)(tolen - 1))
return -1;
247 strlcpy(to+n,endptr, tolen - n);
260 strcpy(buf,
"-*-"); strcpy(buf+3,fl_encoding);
263 char **xlist = XListFonts(fl_display, xstarname, 10000, &xlistsize);
264 if (!xlist)
return (
Fl_Font)fl_free_font;
265 qsort(xlist, xlistsize,
sizeof(*xlist), ultrasort);
267 for (
int i=0; i<xlistsize;) {
269 const char *p = xlist[i++];
271 int size = to_canonical(canon, p,
sizeof(canon));
274 if (i >= xlistsize)
break;
275 const char *q = xlist[i];
276 char this_canon[1024];
277 if (to_canonical(this_canon, q,
sizeof(this_canon)) < 0)
break;
278 if (strcmp(canon, this_canon))
break;
291 if (p == canon) p = strdup(p);
else used_xlist = 1;
296 if (!fl_fonts[j].xlist) {
297 fl_fonts[j].xlist = xlist+first_xlist;
298 fl_fonts[j].n = -(i-first_xlist);
302 if (!used_xlist) XFreeFontNames(xlist);
308 if (!s->name) s = fl_fonts;
311 s->xlist = XListFonts(fl_display, s->name, 100, &(s->n));
312 if (!s->xlist)
return 0;
314 int listsize = s->n;
if (listsize<0) listsize = -listsize;
315 static int sizes[128];
317 for (
int i = 0; i < listsize; i++) {
318 char *q = s->xlist[i];
319 char *d = fl_find_fontsize(q);
321 int s = strtol(d,0,10);
322 if (!numsizes || sizes[numsizes-1] < s) {
323 sizes[numsizes++] = s;
327 for (n = numsizes-1; n > 0; n--)
if (sizes[n-1] < s)
break;
329 for (
int m = numsizes; m > n; m--) sizes[m] = sizes[m-1];
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:875
const Fl_Font FL_BOLD
add this to helvetica, courier, or times
Definition Enumerations.H:895
const Fl_Font FL_ITALIC
add this to helvetica, courier, or times
Definition Enumerations.H:896
const Fl_Font FL_FREE_FONT
first one to allocate
Definition Enumerations.H:894
static void set_font(Fl_Font, const char *)
Changes a face.
Definition fl_set_font.cxx:34
static int get_font_sizes(Fl_Font, int *&sizep)
Return an array of sizes in sizep.
Definition fl_set_fonts_mac.cxx:183
static const char * get_font_name(Fl_Font, int *attributes=0)
Get a human-readable string describing the family of this face.
Definition fl_set_fonts_mac.cxx:31
static Fl_Font set_fonts(const char *=0)
FLTK will open the display, and add every fonts on the server to the face table.
Definition fl_set_fonts_mac.cxx:103
static int x()
Returns the leftmost x coordinate of the main screen work area.