57 #include <X11/Xft/Xft.h> 96 {
" lucidatypewriter"},
97 {
"Blucidatypewriter"},
111 driver->Fl_Graphics_Driver::font(0, 0);
115 if (fnum == driver->Fl_Graphics_Driver::font() && size == driver->
size() &&
f &&
f->angle == angle)
117 driver->Fl_Graphics_Driver::font(fnum, size);
121 if (
f->size == size &&
f->angle == angle)
134 #endif // XFT_MAJOR < 2 144 bool is_xlfd =
false;
145 int hyphen_count = 0;
147 unsigned len = strlen(
name);
148 if (len > 512) len = 512;
149 for(
unsigned idx = 0; idx < len; idx++) {
150 if(
name[idx] ==
'-') hyphen_count++;
151 if(
name[idx] ==
',') comma_count++;
153 if(hyphen_count >= 14) is_xlfd =
true;
158 XftFont *the_font =
NULL;
159 XftPattern *fnt_pat = XftPatternCreate();
160 int slant = XFT_SLANT_ROMAN;
161 int weight = XFT_WEIGHT_MEDIUM;
175 case 'I': slant = XFT_SLANT_ITALIC;
break;
176 case 'P': slant = XFT_SLANT_ITALIC;
177 case 'B': weight = XFT_WEIGHT_BOLD;
break;
183 char *local_name = strdup(
name);
184 char *curr = local_name;
187 nxt = strchr(curr,
',');
194 XftPatternAddString(fnt_pat, XFT_FAMILY, curr);
209 }
while (comma_count >= 0);
213 XftPatternAddString(fnt_pat, XFT_FAMILY,
name);
217 XftPatternAddInteger(fnt_pat, XFT_WEIGHT, weight);
218 XftPatternAddInteger(fnt_pat, XFT_SLANT, slant);
219 XftPatternAddDouble (fnt_pat, XFT_PIXEL_SIZE, (
double)size);
220 XftPatternAddString (fnt_pat, XFT_ENCODING,
fl_encoding_);
226 XftMatrixRotate(&m,cos(
M_PI*angle/180.),sin(
M_PI*angle/180.));
227 XftPatternAddMatrix (fnt_pat, XFT_MATRIX,&m);
231 XftPatternAddBool(fnt_pat, XFT_CORE, FcTrue);
232 XftPatternAddBool(fnt_pat, XFT_RENDER, FcFalse);
235 XftPattern *match_pat;
236 XftResult match_result;
241 #if 0 // the XftResult never seems to get set to anything... abandon this code? 242 switch(match_result) {
244 puts(
"Object exists with the specified ID");
247 case XftResultTypeMismatch:
248 puts(
"Object exists, but the type does not match");
252 puts(
"Object exists, but has fewer values than specified");
255 case FcResultOutOfMemory:
256 puts(
"FcResult: Malloc failed");
259 case XftResultNoMatch:
260 puts(
"Object does not exist at all");
264 printf(
"Invalid XftResult status %d \n", match_result);
269 #if 0 // diagnostic to print the "full name" of the font we matched. This works. 270 FcChar8 *picked_name = FcNameUnparse(match_pat);
271 printf(
"Match: %s\n", picked_name);
276 if (match_pat) the_font = XftFontOpenPattern(
fl_display, match_pat);
278 if (!match_pat || !the_font) {
281 XFT_FAMILY, XftTypeString,
"sans",
282 XFT_SIZE, XftTypeDouble, (
double)size,
284 XftPatternDestroy(fnt_pat);
286 Fl::error(
"Unable to find fonts. Check your FontConfig configuration.\n");
292 #if 0 // diagnostic to print the "full name" of the font we actually opened. This works. 293 FcChar8 *picked_name2 = FcNameUnparse(the_font->pattern);
294 printf(
"Open : %s\n", picked_name2);
298 XftPatternDestroy(fnt_pat);
312 char *local_name = strdup(
name);
314 char *pc = strchr(local_name,
',');
319 #if 0 // diagnostic to print the "full name" of the font we actually opened. This works. 320 puts(
"Font Opened"); fflush(stdout);
321 FcChar8 *picked_name2 = FcNameUnparse(the_font->pattern);
322 printf(
"Open : %s\n", picked_name2); fflush(stdout);
350 static const wchar_t empty[] = {0};
354 if (n == 0)
return empty;
369 memset(extents, 0,
sizeof(XGlyphInfo));
400 if (!desc)
return -1.0;
448 XFontStruct* xgl_font = 0;
449 int size = driver->
size();
450 int fnum = driver->
font();
451 const char *wt_med =
"medium";
452 const char *wt_bold =
"bold";
453 const char *weight = wt_med;
457 const char *
name = pc;
460 case 'I': slant =
'i';
break;
461 case 'P': slant =
'i';
462 case 'B': weight = wt_bold;
break;
468 snprintf(xlfd, 128,
"-*-%s-%s-%c-*--*-*-*-*-*-*-*-*",
name, weight, slant);
472 snprintf(xlfd, 128,
"-*-%s-%s-%c-*--*-%d-*-*-*-*-*-*",
name, weight, slant, (size*10));
479 if (!strcmp(
name,
"sans")) {
481 }
else if (!strcmp(
name,
"mono")) {
483 }
else if (!strcmp(
name,
"serif")) {
485 }
else if (!strcmp(
name,
"screen")) {
486 name =
"lucidatypewriter";
487 }
else if (!strcmp(
name,
"dingbats")) {
488 name =
"zapf dingbats";
490 snprintf(xlfd, 128,
"-*-*%s*-%s-%c-*--*-%d-*-*-*-*-*-*",
name, weight, slant, (size*10));
497 snprintf(xlfd, 128,
"-*-helvetica-*-%c-*--*-%d-*-*-*-*-*-*", slant, (size*10));
501 if(!xgl_font && weight != wt_med) {
502 snprintf(xlfd, 128,
"-*-courier*-%s-%c-*--*-%d-*-*-*-*-*-*", weight, slant, (size*10));
507 snprintf(xlfd, 128,
"-*-courier*-medium-%c-*--*-%d-*-*-*-*-*-*", slant, (size*10));
514 if (!xgl_font) xgl_font = XLoadQueryFont(
fl_display,
"fixed");
524 static XFontStruct* xgl_font = 0;
525 static int glsize = 0;
526 static int glfont = -1;
528 if ((!xgl_font) || (glsize != driver->
size()) || (glfont != driver->
font())) {
530 if (xgl_font) XFreeFont(
fl_display, xgl_font);
531 glsize = driver->
size();
532 glfont = driver->
font();
533 xgl_font = load_xfont_for_xft2(driver);
536 # else // XFT-1 provides a means to load a "core" font directly 540 static XftFont* xftfont;
541 if (xftfont) XftFontClose (
fl_display, xftfont);
543 return xftfont->u.core.font;
544 # endif // XFT_MAJOR > 1 547 XFontStruct* Fl_XFont_On_Demand::value() {
556 extern Colormap fl_overlay_colormap;
557 extern XVisualInfo* fl_overlay_visual;
567 static XftDraw* draw_overlay;
568 static Window draw_overlay_window;
575 if (
id == draw_overlay_window)
589 fl_overlay_visual->visual, fl_overlay_colormap);
601 if (region && XEmptyRegion(region))
return;
602 XftDrawSetClip(
draw_, region);
609 color.color.red = ((int)r)*0x101;
610 color.color.green = ((int)g)*0x101;
611 color.color.blue = ((int)
b)*0x101;
612 color.color.alpha = 0xffff;
624 this->
draw(str,
n, (
int)
x, (
int)
y);
634 fl_overlay_visual->visual, fl_overlay_colormap);
646 if (region && XEmptyRegion(region))
return;
647 XftDrawSetClip(
draw_, region);
654 color.color.red = ((int)r)*0x101;
655 color.color.green = ((int)g)*0x101;
656 color.color.blue = ((int)
b)*0x101;
657 color.color.alpha = 0xffff;
665 #if defined(__GNUC__) 672 int num_chars, wid, utf_len = strlen(c);
673 FcChar8 *u8 = (FcChar8 *)c;
674 FcBool valid = FcUtf8Len(u8, utf_len, &num_chars, &wid);
680 if (num_chars <
n)
n = num_chars;
681 FcChar32 *ucs_txt =
new FcChar32[
n+1];
686 while ((out >= 0) && (utf_len > 0))
689 sz = FcUtf8ToUcs4(u8, pu, utf_len);
690 utf_len = utf_len - sz;