20Fl_Font_Descriptor::Fl_Font_Descriptor(
const char* name) {
21 font = XCreateUtf8FontStruct(fl_display, name);
24 font = XCreateUtf8FontStruct(fl_display,
"fixed");
28 for (
int u = 0; u < 64; u++) glok[u] = 0;
32Fl_XFont_On_Demand fl_xfont;
34Fl_Font_Descriptor::~Fl_Font_Descriptor() {
50 XFreeUtf8FontStruct(fl_display, font);
58{
"-*-helvetica-medium-r-normal--*"},
59{
"-*-helvetica-bold-r-normal--*"},
60{
"-*-helvetica-medium-o-normal--*"},
61{
"-*-helvetica-bold-o-normal--*"},
62{
"-*-courier-medium-r-normal--*"},
63{
"-*-courier-bold-r-normal--*"},
64{
"-*-courier-medium-o-normal--*"},
65{
"-*-courier-bold-o-normal--*"},
66{
"-*-times-medium-r-normal--*"},
67{
"-*-times-bold-r-normal--*"},
68{
"-*-times-medium-i-normal--*"},
69{
"-*-times-bold-i-normal--*"},
71{
"-*-lucidatypewriter-medium-r-normal-sans-*"},
72{
"-*-lucidatypewriter-bold-r-normal-sans-*"},
73{
"-*-*zapf dingbats-*"}
81const char* fl_font_word(
const char* p,
int n) {
82 while (*p) {
if (*p==
'-') {
if (!--n)
break;} p++;}
87char* fl_find_fontsize(
char* name) {
91 c = (
char*)fl_font_word(c,7);
92 if (*c++ && isdigit(*c))
return c;
98 if (isdigit(*c) && !isdigit(*(c-1))) r = c;
103const char* fl_encoding =
"iso10646-1";
106int fl_correct_encoding(
const char* name) {
107 if (*name !=
'-')
return 0;
108 const char* c = fl_font_word(name,13);
109 return (*c++ && !strcmp(c,fl_encoding));
112static const char *find_best_font(
const char *fname,
int size) {
114 static char **list = NULL;
116 if (list) XFreeFontNames(list);
117 list = XListFonts(fl_display, fname, 100, &cnt);
118 if (!list)
return "fixed";
121 char* name = list[0];
int ptsize = 0;
122 int matchedlength = 32767;
123 static char namebuffer[1024];
124 int found_encoding = 0;
125 int m = cnt;
if (m<0) m = -m;
126 for (
int n=0; n < m; n++) {
127 char* thisname = list[n];
128 if (fl_correct_encoding(thisname)) {
129 if (!found_encoding) ptsize = 0;
132 if (found_encoding)
continue;
134 char* c = (
char*)fl_find_fontsize(thisname);
135 int thissize = c ? atoi(c) : MAXSIZE;
136 int thislength = strlen(thisname);
137 if (thissize == size && thislength < matchedlength) {
141 matchedlength = thislength;
142 }
else if (!thissize && ptsize!=size) {
145 memcpy(namebuffer,thisname,l);
146 l += sprintf(namebuffer+l,
"%d",size);
147 while (*c ==
'0') c++;
148 strcpy(namebuffer+l,c);
151 }
else if (!ptsize ||
152 (thissize < ptsize && ptsize > size) ||
153 (thissize > ptsize && thissize <= size)
157 matchedlength = thislength;
182static char *put_font_size(
const char *n,
int size)
192 if (name[i] ==
',') {nbf++; name[i] =
'\0';}
196 buf = (
char*) malloc(nbf * 256);
200 while (ptr && nbf > 0) {
201 f = find_best_font(ptr, size);
213 while(isspace(*ptr)) ptr++;
221char *fl_get_font_xfld(
int fnum,
int size) {
223 if (!s->name) s = fl_fonts;
225 return put_font_size(s->name, size);
232 if (!s->name) s = fl_fonts;
234 for (f = s->first; f; f = f->next)
235 if (f->size == size)
return f;
238 name = put_font_size(s->name, size);
254XFontStruct* Fl_XFont_On_Demand::value() {
268 fl_xfont = f->font->fonts[0];
294 if (font_gc != fl_gc) {
300 xx = yy = ww = hh = 0;
301 if (fl_gc) XUtf8_measure_extents(fl_display, fl_window,
font_descriptor()->
font, fl_gc, &xx, &yy, &ww, &hh, c, n);
303 W = ww; H = hh; dx = xx; dy = yy;
312 if (font_gc != fl_gc) {
317 if (fl_gc) XUtf8DrawString(fl_display, fl_window,
font_descriptor()->
font, fl_gc, x, y, c, n);
321 static char warning = 0;
322 if (!warning && angle != 0) {
325 "libfltk: rotated text not implemented by X backend.\n"
326 " You should use the Xft backend. Check USE_XFT in config.h.\n");
328 this->
draw(str, n, (
int)x, (
int)y);
332 if (font_gc != fl_gc) {
336 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:117
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:875
const Fl_Font FL_HELVETICA
Helvetica (or Arial) normal (0)
Definition Enumerations.H:877
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:904
FL_EXPORT Fl_Graphics_Driver * fl_graphics_driver
Points to the driver that currently receives all graphics requests.
Definition Fl_Device.cxx:50
This a structure for an actual system font, with junk to help choose it and info on character sizes.
Definition Fl_Font.H:41
Fl_Font_Descriptor * font_descriptor()
Returns a pointer to the current Fl_Font_Descriptor for the graphics driver.
Definition Fl_Device.H:404
Fl_Fontsize size()
see fl_size().
Definition Fl_Device.H:390
Fl_Font font()
see fl_font(void).
Definition Fl_Device.H:388
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 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:505