29Fl_Font_Descriptor::Fl_Font_Descriptor(
const char* name) {
30 font = XCreateUtf8FontStruct(fl_display, name);
33 font = XCreateUtf8FontStruct(fl_display,
"fixed");
37 for (
int u = 0; u < 64; u++) glok[u] = 0;
41Fl_XFont_On_Demand fl_xfont;
43Fl_Font_Descriptor::~Fl_Font_Descriptor() {
59 XFreeUtf8FontStruct(fl_display, font);
67{
"-*-helvetica-medium-r-normal--*"},
68{
"-*-helvetica-bold-r-normal--*"},
69{
"-*-helvetica-medium-o-normal--*"},
70{
"-*-helvetica-bold-o-normal--*"},
71{
"-*-courier-medium-r-normal--*"},
72{
"-*-courier-bold-r-normal--*"},
73{
"-*-courier-medium-o-normal--*"},
74{
"-*-courier-bold-o-normal--*"},
75{
"-*-times-medium-r-normal--*"},
76{
"-*-times-bold-r-normal--*"},
77{
"-*-times-medium-i-normal--*"},
78{
"-*-times-bold-i-normal--*"},
80{
"-*-lucidatypewriter-medium-r-normal-sans-*"},
81{
"-*-lucidatypewriter-bold-r-normal-sans-*"},
82{
"-*-*zapf dingbats-*"}
90const char* fl_font_word(
const char* p,
int n) {
91 while (*p) {
if (*p==
'-') {
if (!--n)
break;} p++;}
96char* fl_find_fontsize(
char* name) {
100 c = (
char*)fl_font_word(c,7);
101 if (*c++ && isdigit(*c))
return c;
107 if (isdigit(*c) && !isdigit(*(c-1))) r = c;
112const char* fl_encoding =
"iso10646-1";
115int fl_correct_encoding(
const char* name) {
116 if (*name !=
'-')
return 0;
117 const char* c = fl_font_word(name,13);
118 return (*c++ && !strcmp(c,fl_encoding));
121static const char *find_best_font(
const char *fname,
int size) {
123 static char **list = NULL;
125 if (list) XFreeFontNames(list);
126 list = XListFonts(fl_display, fname, 100, &cnt);
127 if (!list)
return "fixed";
130 char* name = list[0];
int ptsize = 0;
131 int matchedlength = 32767;
132 char namebuffer[1024];
133 int found_encoding = 0;
134 int m = cnt;
if (m<0) m = -m;
135 for (
int n=0; n < m; n++) {
136 char* thisname = list[n];
137 if (fl_correct_encoding(thisname)) {
138 if (!found_encoding) ptsize = 0;
141 if (found_encoding)
continue;
143 char* c = (
char*)fl_find_fontsize(thisname);
144 int thissize = c ? atoi(c) : MAXSIZE;
145 int thislength = strlen(thisname);
146 if (thissize == size && thislength < matchedlength) {
150 matchedlength = thislength;
151 }
else if (!thissize && ptsize!=size) {
154 memcpy(namebuffer,thisname,l);
155 l += sprintf(namebuffer+l,
"%d",size);
156 while (*c ==
'0') c++;
157 strcpy(namebuffer+l,c);
160 }
else if (!ptsize ||
161 (thissize < ptsize && ptsize > size) ||
162 (thissize > ptsize && thissize <= size)
166 matchedlength = thislength;
191static char *put_font_size(
const char *n,
int size)
201 if (name[i] ==
',') {nbf++; name[i] =
'\0';}
205 buf = (
char*) malloc(nbf * 256);
209 while (ptr && nbf > 0) {
210 f = find_best_font(ptr, size);
222 while(isspace(*ptr)) ptr++;
230char *fl_get_font_xfld(
int fnum,
int size) {
232 if (!s->name) s = fl_fonts;
234 return put_font_size(s->name, size);
241 if (!s->name) s = fl_fonts;
243 for (f = s->first; f; f = f->
next)
244 if (f->size == size)
return f;
247 name = put_font_size(s->name, size);
263XFontStruct* Fl_XFont_On_Demand::value() {
274 Fl_Font_Descriptor* f = find(fnum,
size);
277 fl_xfont = f->font->fonts[0];
303 if (font_gc != fl_gc) {
309 xx = yy = ww = hh = 0;
310 if (fl_gc) XUtf8_measure_extents(fl_display, fl_window,
font_descriptor()->
font, fl_gc, &xx, &yy, &ww, &hh, c, n);
312 W = ww; H = hh; dx = xx; dy = yy;
321 if (font_gc != fl_gc) {
326 if (fl_gc) XUtf8DrawString(fl_display, fl_window,
font_descriptor()->
font, fl_gc, x, y, c, n);
330 fprintf(stderr,
"ROTATING TEXT NOT IMPLEMENTED\n");
331 this->
draw(str, n, (
int)x, (
int)y);
335 if (font_gc != fl_gc) {
339 if (fl_gc) XUtf8DrawRtlString(fl_display, fl_window,
font_descriptor()->
font, fl_gc, x, y, c, n);
FL_EXPORT Fl_Fontsize FL_NORMAL_SIZE
normal font size
Definition Fl_Widget.cxx:111
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:707
const Fl_Font FL_HELVETICA
Helvetica (or Arial) normal (0)
Definition Enumerations.H:709
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:736
FL_EXPORT Fl_Graphics_Driver * fl_graphics_driver
Points to the driver that currently receives all graphics requests.
This a structure for an actual system font, with junk to help choose it and info on character sizes.
Definition Fl_Font.H:50
Fl_Font_Descriptor * next
linked list for this Fl_Fontdesc
Definition Fl_Font.H:53
Fl_Font_Descriptor * font_descriptor()
Returns a pointer to the current Fl_Font_Descriptor for the graphics driver.
Definition Fl_Device.H:402
Fl_Fontsize size()
see fl_size().
Definition Fl_Device.H:388
Fl_Font font()
see fl_font(void).
Definition Fl_Device.H:386
double width(const char *str, int n)
see fl_width(const char *str, int n).
void rtl_draw(const char *str, int n, int x, int y)
see fl_rtl_draw(const char *str, int n, int x, int y).
void text_extents(const char *, int n, int &dx, int &dy, int &w, int &h)
see fl_text_extents(const char*, int n, int& dx, int& dy, int& w, int& h).
int height()
see fl_height().
int descent()
see fl_descent().
void font(Fl_Font face, Fl_Fontsize size)
see fl_font(Fl_Font face, Fl_Fontsize size).
void draw(const char *str, int n, int x, int y)
see fl_draw(const char *str, int n, int x, int y).
static void(* warning)(const char *,...)
FLTK calls Fl::warning() to output a warning message.
Definition Fl.H:395