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++) {
129 e = fl_font_word(
x,1);
130 int t = attribute(n,
x);
132 if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ =
' ';
133 if ((e -
x) < (
int)(ENDOFBUFFER - (o - f->fontname) - 1)) {
138 strlcpy(o,
x, ENDOFBUFFER - (o - f->fontname) - 1);
139 o = f->fontname+ENDOFBUFFER-1;
145 x = fl_font_word(e,2);
146 if (*
x) {
x++; *o++ =
'(';
while (*
x) *o++ = *
x++; *o++ =
')';}
149 if (type &
FL_BOLD) strlcat(f->fontname,
" bold", ENDOFBUFFER);
150 if (type &
FL_ITALIC) strlcat(f->fontname,
" italic", ENDOFBUFFER);
152 f->fontname[ENDOFBUFFER] = (char)type;
154 if (ap) *ap = f->fontname[ENDOFBUFFER];
161static int ultrasort(
const void *aa,
const void *bb) {
162 const char *a = *(
char **)aa;
163 const char *b = *(
char **)bb;
167 if (*b ==
'-')
return 1;
171 if (isdigit(*a) && isdigit(*b)) {
172 int na = strtol(a, (
char **)&a, 10);
173 int nb = strtol(b, (
char **)&b, 10);
174 if (!ret) ret = na-nb;
175 }
else if (*a != *b) {
184 if (*b !=
'-')
return -1;
188 for (a++; *a && *a++!=
'-';);
189 for (b++; *b && *b++!=
'-';);
194 for (
int n = 2; n <= 6; n++) {
195 int at = attribute(n,a);
196 int bt = attribute(n,b);
198 if (bt >= 0)
return 1;
199 for (;;) {
if (*a!=*b)
return *a-*b; b++;
if (!*a || *a++==
'-')
break;}
201 if (bt < 0)
return -1;
202 a = fl_font_word(a,1);
if (*a) a++;
203 b = fl_font_word(b,1);
if (*b) b++;
204 atype |= at; btype |= bt;
213 a = fl_font_word(a,6);
if (*a) a++;
214 b = fl_font_word(b,6);
if (*b) b++;
215 if (use_registry(a)) {
216 if (!use_registry(b))
return 1;
217 int r = strcmp(a,b);
if (r)
return r;
219 if (use_registry(b))
return -1;
222 if (atype != btype)
return atype-btype;
223 if (asize != bsize)
return asize-bsize;
226 return strcmp(*(
char**)aa, *(
char**)bb);
231static int to_canonical(
char *to,
const char *from,
size_t tolen) {
232 char* c = fl_find_fontsize((
char*)from);
235 int size = strtol(c,(
char**)&endptr,10);
236 if (from[0] ==
'-') {
238 *to++ =
'-'; *to++ =
'*';
239 for (from++; *from && *from !=
'-'; from++);
241 endptr = (
char*)fl_font_word(endptr,6);
242 if (*endptr && !use_registry(endptr+1)) endptr =
"";
246 if (n > (
int)(tolen - 1))
return -1;
249 strlcpy(to+n,endptr, tolen - n);
262 strcpy(buf,
"-*-"); strcpy(buf+3,fl_encoding);
265 char **xlist = XListFonts(fl_display, xstarname, 10000, &xlistsize);
266 if (!xlist)
return (
Fl_Font)fl_free_font;
267 qsort(xlist, xlistsize,
sizeof(*xlist), ultrasort);
269 for (
int i=0; i<xlistsize;) {
271 const char *p = xlist[i++];
273 int size = to_canonical(canon, p,
sizeof(canon));
276 if (i >= xlistsize)
break;
277 const char *q = xlist[i];
278 char this_canon[1024];
279 if (to_canonical(this_canon, q,
sizeof(this_canon)) < 0)
break;
280 if (strcmp(canon, this_canon))
break;
293 if (p == canon) p = strdup(p);
else used_xlist = 1;
298 if (!fl_fonts[j].xlist) {
299 fl_fonts[j].xlist = xlist+first_xlist;
300 fl_fonts[j].n = -(i-first_xlist);
304 if (!used_xlist) XFreeFontNames(xlist);
310 if (!s->name) s = fl_fonts;
313 s->xlist = XListFonts(fl_display, s->name, 100, &(s->n));
314 if (!s->xlist)
return 0;
316 int listsize = s->n;
if (listsize<0) listsize = -listsize;
317 static int sizes[128];
319 for (
int i = 0; i < listsize; i++) {
320 char *q = s->xlist[i];
321 char *d = fl_find_fontsize(q);
323 int s = strtol(d,0,10);
324 if (!numsizes || sizes[numsizes-1] < s) {
325 sizes[numsizes++] = s;
329 for (n = numsizes-1; n > 0; n--)
if (sizes[n-1] < s)
break;
331 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:188
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:108
static int x()
Returns the leftmost x coordinate of the main screen work area.