60static int attribute(
int n,
const char *p) {
62 if (!*p || *p==
'-' || *p==
'*')
return 0;
64 if (!strncmp(p,
"normal",6) ||
65 !strncmp(p,
"light",5) ||
66 !strncmp(p,
"medium",6) ||
67 !strncmp(p,
"book",4))
return 0;
68 if (!strncmp(p,
"bold",4) || !strncmp(p,
"demi",4))
return FL_BOLD;
70 if (*p ==
'r')
return 0;
71 if (*p ==
'i' || *p ==
'o')
return FL_ITALIC;
73 if (!strncmp(p,
"normal",6))
return 0;
79extern const char* fl_encoding;
80static int use_registry(
const char *p) {
81 return *p && *p!=
'*' && strcmp(p,fl_encoding);
88#define ENDOFBUFFER 127
92 Fl_Fontdesc *f = fl_fonts + fnum;
93 if (!f->fontname[0]) {
95 const char* p = f->name;
100 char *o = f->fontname;
103 if (strstr(p,
"bold")) type =
FL_BOLD;
106 if (*p ==
'*' || *p ==
' ' || *p ==
'-') {
107 do p++;
while (*p ==
'*' || *p ==
' ' || *p ==
'-');
109 if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ =
' ';
111 if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ = *p;
118 const char *
x = fl_font_word(p,2);
if (*
x)
x++;
if (*
x==
'*')
x++;
123 const char *e = fl_font_word(
x,1);
124 if ((e -
x) < (
int)(ENDOFBUFFER - 1)) {
129 strlcpy(f->fontname,
x, ENDOFBUFFER);
130 o = f->fontname+ENDOFBUFFER-1;
134 for (
int n = 3; n <= 6; n++) {
136 if (*e) e++;
x = e; e = fl_font_word(
x,1);
137 int t = attribute(n,
x);
139 if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ =
' ';
140 if ((e -
x) < (
int)(ENDOFBUFFER - (o - f->fontname) - 1)) {
145 strlcpy(o,
x, ENDOFBUFFER - (o - f->fontname) - 1);
146 o = f->fontname+ENDOFBUFFER-1;
152 x = fl_font_word(e,2);
153 if (*
x) {
x++; *o++ =
'(';
while (*
x) *o++ = *
x++; *o++ =
')';}
156 if (type &
FL_BOLD) strlcat(f->fontname,
" bold", ENDOFBUFFER);
157 if (type &
FL_ITALIC) strlcat(f->fontname,
" italic", ENDOFBUFFER);
159 f->fontname[ENDOFBUFFER] = (char)type;
161 if (ap) *ap = f->fontname[ENDOFBUFFER];
168static int ultrasort(
const void *aa,
const void *bb) {
169 const char *a = *(
char **)aa;
170 const char *b = *(
char **)bb;
174 if (*b ==
'-')
return 1;
178 if (isdigit(*a) && isdigit(*b)) {
179 int na = strtol(a, (
char **)&a, 10);
180 int nb = strtol(b, (
char **)&b, 10);
181 if (!ret) ret = na-nb;
182 }
else if (*a != *b) {
191 if (*b !=
'-')
return -1;
195 for (a++; *a && *a++!=
'-';);
196 for (b++; *b && *b++!=
'-';);
201 for (
int n = 2; n <= 6; n++) {
202 int at = attribute(n,a);
203 int bt = attribute(n,b);
205 if (bt >= 0)
return 1;
206 for (;;) {
if (*a!=*b)
return *a-*b; b++;
if (!*a || *a++==
'-')
break;}
208 if (bt < 0)
return -1;
209 a = fl_font_word(a,1);
if (*a) a++;
210 b = fl_font_word(b,1);
if (*b) b++;
211 atype |= at; btype |= bt;
220 a = fl_font_word(a,6);
if (*a) a++;
221 b = fl_font_word(b,6);
if (*b) b++;
222 if (use_registry(a)) {
223 if (!use_registry(b))
return 1;
224 int r = strcmp(a,b);
if (r)
return r;
226 if (use_registry(b))
return -1;
229 if (atype != btype)
return atype-btype;
230 if (asize != bsize)
return asize-bsize;
233 return strcmp(*(
char**)aa, *(
char**)bb);
238static int to_canonical(
char *to,
const char *from,
size_t tolen) {
239 char* c = fl_find_fontsize((
char*)from);
242 int size = strtol(c,(
char**)&endptr,10);
243 if (from[0] ==
'-') {
245 *to++ =
'-'; *to++ =
'*';
246 for (from++; *from && *from !=
'-'; from++);
248 endptr = (
char*)fl_font_word(endptr,6);
249 if (*endptr && !use_registry(endptr+1)) endptr =
"";
253 if (n > (
int)(tolen - 1))
return -1;
256 strlcpy(to+n,endptr, tolen - n);
269 strcpy(buf,
"-*-"); strcpy(buf+3,fl_encoding);
272 char **xlist = XListFonts(fl_display, xstarname, 10000, &xlistsize);
273 if (!xlist)
return (
Fl_Font)fl_free_font;
274 qsort(xlist, xlistsize,
sizeof(*xlist), ultrasort);
276 for (
int i=0; i<xlistsize;) {
278 const char *p = xlist[i++];
280 int size = to_canonical(canon, p,
sizeof(canon));
283 if (i >= xlistsize)
break;
284 const char *q = xlist[i];
285 char this_canon[1024];
286 if (to_canonical(this_canon, q,
sizeof(this_canon)) < 0)
break;
287 if (strcmp(canon, this_canon))
break;
300 if (p == canon) p = strdup(p);
else used_xlist = 1;
305 if (!fl_fonts[j].xlist) {
306 fl_fonts[j].xlist = xlist+first_xlist;
307 fl_fonts[j].n = -(i-first_xlist);
311 if (!used_xlist) XFreeFontNames(xlist);
316 Fl_Fontdesc *s = fl_fonts+fnum;
317 if (!s->name) s = fl_fonts;
320 s->xlist = XListFonts(fl_display, s->name, 100, &(s->n));
321 if (!s->xlist)
return 0;
323 int listsize = s->n;
if (listsize<0) listsize = -listsize;
324 static int sizes[128];
326 for (
int i = 0; i < listsize; i++) {
327 char *q = s->xlist[i];
328 char *d = fl_find_fontsize(q);
330 int s = strtol(d,0,10);
331 if (!numsizes || sizes[numsizes-1] < s) {
332 sizes[numsizes++] = s;
336 for (n = numsizes-1; n > 0; n--)
if (sizes[n-1] < s)
break;
338 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:707
const Fl_Font FL_BOLD
add this to helvetica, courier, or times
Definition Enumerations.H:727
const Fl_Font FL_ITALIC
add this to helvetica, courier, or times
Definition Enumerations.H:728
const Fl_Font FL_FREE_FONT
first one to allocate
Definition Enumerations.H:726
static void set_font(Fl_Font, const char *)
Changes a face.
Definition fl_set_font.cxx:43
static int get_font_sizes(Fl_Font, int *&sizep)
Return an array of sizes in sizep.
Definition fl_set_fonts_mac.cxx:149
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:44
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:68
static int x()
Returns the origin of the current screen work area, where 0 indicates the left side of the screen.