… | |
… | |
21 | |
21 | |
22 | #include "../config.h" |
22 | #include "../config.h" |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
24 | #include "defaultfont.h" |
24 | #include "defaultfont.h" |
25 | |
25 | |
|
|
26 | #include <cstdlib> |
|
|
27 | |
26 | #define DISPLAY r->Xdisplay |
28 | #define DISPLAY r->Xdisplay |
27 | #define DRAWABLE r->TermWin.vt |
29 | #define DRAWABLE r->TermWin.vt |
28 | #define GC r->TermWin.gc |
30 | #define GC r->TermWin.gc |
29 | |
31 | |
30 | const struct rxvt_fallback_font { |
32 | const struct rxvt_fallback_font { |
… | |
… | |
57 | |
59 | |
58 | // japanese |
60 | // japanese |
59 | #if ENCODING_JP || ENCODING_JP_EXT |
61 | #if ENCODING_JP || ENCODING_JP_EXT |
60 | # if XFT |
62 | # if XFT |
61 | // prefer xft for complex scripts |
63 | // prefer xft for complex scripts |
62 | { CS_UNICODE, "xft:Kochi Gothic" }, |
64 | { CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, |
63 | # endif |
65 | # endif |
64 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
66 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
65 | { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
67 | { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
66 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
68 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
67 | #endif |
69 | #endif |
68 | |
70 | |
69 | #if ENCODING_CN || ENCODING_CN_EXT |
71 | #if ENCODING_CN || ENCODING_CN_EXT |
70 | # if XFT |
72 | # if XFT |
71 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
73 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
72 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
74 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
73 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
75 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
74 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
76 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
75 | # endif |
77 | # endif |
|
|
78 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
76 | { CS_CNS11643_1992_1, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-1" }, |
79 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
77 | { CS_CNS11643_1992_2, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-2" }, |
80 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
78 | { CS_CNS11643_1992_3, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-3" }, |
81 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
79 | { CS_CNS11643_1992_4, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-4" }, |
82 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
80 | { CS_CNS11643_1992_5, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-5" }, |
83 | { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" }, |
81 | { CS_CNS11643_1992_6, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-6" }, |
84 | { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" }, |
82 | { CS_CNS11643_1992_7, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-7" }, |
85 | { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" }, |
83 | { CS_CNS11643_1992_F, "-*-*-*-r-*-*-*-*-*-*-c-*-cns11643.1992-f" }, |
86 | { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" }, |
84 | #endif |
87 | #endif |
85 | |
88 | |
86 | #if XFT |
89 | #if XFT |
87 | { CS_UNICODE, "xft:Andale Mono" }, |
90 | { CS_UNICODE, "xft:Andale Mono" }, |
88 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
91 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
89 | #endif |
92 | #endif |
90 | { CS_UNICODE, "-*-lucidatypewriter-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
93 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
|
|
94 | { CS_UNICODE, "xft:FreeMono" }, |
|
|
95 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
|
|
96 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
91 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
97 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
92 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
|
|
93 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
|
|
94 | |
98 | |
95 | { CS_UNKNOWN, 0 } |
99 | { CS_UNKNOWN, 0 } |
96 | }; |
100 | }; |
97 | |
101 | |
98 | ///////////////////////////////////////////////////////////////////////////// |
102 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
220 | |
224 | |
221 | // to be done |
225 | // to be done |
222 | }; |
226 | }; |
223 | |
227 | |
224 | struct rxvt_font_default : rxvt_font { |
228 | struct rxvt_font_default : rxvt_font { |
225 | bool load (int maxheight) |
229 | rxvt_fontprop properties () |
|
|
230 | { |
|
|
231 | rxvt_fontprop p; |
|
|
232 | |
|
|
233 | p.width = p.height = 1; |
|
|
234 | p.weight = rxvt_fontprop::medium; |
|
|
235 | p.slant = rxvt_fontprop::roman; |
|
|
236 | |
|
|
237 | return p; |
|
|
238 | } |
|
|
239 | |
|
|
240 | bool load (const rxvt_fontprop &prop) |
226 | { |
241 | { |
227 | width = 1; height = 1; |
242 | width = 1; height = 1; |
228 | ascent = 1; descent = 0; |
243 | ascent = 1; descent = 0; |
229 | |
244 | |
230 | return true; |
245 | return true; |
… | |
… | |
322 | struct rxvt_font_x11 : rxvt_font { |
337 | struct rxvt_font_x11 : rxvt_font { |
323 | rxvt_font_x11 () { f = 0; } |
338 | rxvt_font_x11 () { f = 0; } |
324 | |
339 | |
325 | void clear (); |
340 | void clear (); |
326 | |
341 | |
327 | bool load (int maxheight); |
342 | rxvt_fontprop properties (); |
|
|
343 | |
|
|
344 | bool load (const rxvt_fontprop &prop); |
328 | |
345 | |
329 | bool has_codepoint (uint32_t unicode); |
346 | bool has_codepoint (uint32_t unicode); |
330 | |
347 | |
331 | void draw (int x, int y, |
348 | void draw (int x, int y, |
332 | const text_t *text, int len, |
349 | const text_t *text, int len, |
… | |
… | |
334 | |
351 | |
335 | XFontStruct *f; |
352 | XFontStruct *f; |
336 | codeset cs; |
353 | codeset cs; |
337 | bool enc2b, encm; |
354 | bool enc2b, encm; |
338 | |
355 | |
339 | const char *get_property (const char *property, const char *repl) const; |
356 | const char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
|
|
357 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
|
|
358 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
|
|
359 | bool set_properties (rxvt_fontprop &p, const char *name); |
340 | }; |
360 | }; |
341 | |
361 | |
342 | const char * |
362 | const char * |
343 | rxvt_font_x11::get_property (const char *property, const char *repl) const |
363 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
344 | { |
364 | { |
345 | unsigned long value; |
365 | unsigned long value; |
346 | |
366 | |
347 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
367 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
348 | return XGetAtomName (DISPLAY, value); |
368 | return XGetAtomName (DISPLAY, value); |
349 | else |
369 | else |
350 | return repl; |
370 | return repl; |
351 | } |
371 | } |
352 | |
372 | |
|
|
373 | rxvt_fontprop |
|
|
374 | rxvt_font_x11::properties () |
|
|
375 | { |
|
|
376 | rxvt_fontprop p; |
|
|
377 | set_properties (p, f); |
|
|
378 | return p; |
|
|
379 | } |
|
|
380 | |
353 | bool |
381 | bool |
354 | rxvt_font_x11::load (int maxheight) |
382 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
|
|
383 | { |
|
|
384 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
|
|
385 | p.height = height; |
|
|
386 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
|
|
387 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
|
|
388 | |
|
|
389 | return true; |
|
|
390 | } |
|
|
391 | |
|
|
392 | bool |
|
|
393 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
|
|
394 | { |
|
|
395 | const char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
|
|
396 | const char *slant = get_property (f, "SLANT", "r"); |
|
|
397 | |
|
|
398 | unsigned long height; |
|
|
399 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
|
|
400 | return false; |
|
|
401 | |
|
|
402 | unsigned long avgwidth; |
|
|
403 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
|
|
404 | avgwidth = 0; |
|
|
405 | |
|
|
406 | return set_properties (p, height, weight, slant, avgwidth); |
|
|
407 | } |
|
|
408 | |
|
|
409 | bool |
|
|
410 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
|
|
411 | { |
|
|
412 | int slashes = 0; |
|
|
413 | const char *comp[12]; |
|
|
414 | |
|
|
415 | for (const char *c = name; *c; c++) |
|
|
416 | if (*c == '-') |
|
|
417 | { |
|
|
418 | comp[slashes++] = c + 1; |
|
|
419 | if (slashes >= 13) |
|
|
420 | break; |
|
|
421 | } |
|
|
422 | |
|
|
423 | /* can we short-circuit the costly XLoadQueryFont? */ |
|
|
424 | if (slashes >= 13 |
|
|
425 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
|
|
426 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
|
|
427 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
|
|
428 | |
|
|
429 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
|
|
430 | |
|
|
431 | if (f) |
|
|
432 | { |
|
|
433 | // the font should really exists now. if not, we have a problem |
|
|
434 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
|
|
435 | // in that case, just return garbage. |
|
|
436 | bool ret = set_properties (p, f); |
|
|
437 | XFreeFont (DISPLAY, f); |
|
|
438 | return ret; |
|
|
439 | } |
|
|
440 | else |
|
|
441 | return false; |
|
|
442 | } |
|
|
443 | |
|
|
444 | // fix the size of scalable fonts |
|
|
445 | static void |
|
|
446 | fix_scalable (char *buf, const char *name, const rxvt_fontprop &prop) |
|
|
447 | { |
|
|
448 | int slashes = 0; |
|
|
449 | const char *size; |
|
|
450 | |
|
|
451 | for (const char *c = name; *c; c++) |
|
|
452 | if (*c == '-') |
|
|
453 | { |
|
|
454 | if (slashes == 6) |
|
|
455 | size = c + 1; |
|
|
456 | |
|
|
457 | if (++slashes >= 13) |
|
|
458 | break; |
|
|
459 | } |
|
|
460 | |
|
|
461 | if (slashes >= 13 && size[0] == '0') |
|
|
462 | { |
|
|
463 | strncpy (buf, name, size - name); |
|
|
464 | buf += size - name; |
|
|
465 | buf += sprintf (buf, "%d", prop.height); |
|
|
466 | strcpy (buf, size + 1); |
|
|
467 | } |
|
|
468 | else |
|
|
469 | strcpy (buf, name); |
|
|
470 | } |
|
|
471 | |
|
|
472 | bool |
|
|
473 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
355 | { |
474 | { |
356 | clear (); |
475 | clear (); |
|
|
476 | |
|
|
477 | char **list; |
|
|
478 | int count; |
|
|
479 | list = XListFonts (DISPLAY, name, 512, &count); |
|
|
480 | set_name (0); |
|
|
481 | |
|
|
482 | if (!list) |
|
|
483 | return false; |
|
|
484 | |
|
|
485 | int bestdiff = 0x7fffffff; |
|
|
486 | for (int i = 0; i < count; i++) |
|
|
487 | { |
|
|
488 | rxvt_fontprop p; |
|
|
489 | char fname[1024]; |
|
|
490 | fix_scalable (fname, list[i], prop); |
|
|
491 | |
|
|
492 | if (!set_properties (p, fname)) |
|
|
493 | continue; |
|
|
494 | |
|
|
495 | if (p.height > prop.height) // weed out too large fonts |
|
|
496 | continue; |
|
|
497 | |
|
|
498 | int diff = (prop.height - p.height) * 32 |
|
|
499 | + abs (prop.weight - p.weight) |
|
|
500 | + abs (prop.slant - p.slant ); |
|
|
501 | |
|
|
502 | if (!name // compare against best found so far |
|
|
503 | || diff < bestdiff) |
|
|
504 | { |
|
|
505 | set_name (strdup (fname)); |
|
|
506 | bestdiff = diff; |
|
|
507 | } |
|
|
508 | } |
|
|
509 | |
|
|
510 | XFreeFontNames (list); |
|
|
511 | |
|
|
512 | if (!name) |
|
|
513 | return false; |
357 | |
514 | |
358 | f = XLoadQueryFont (DISPLAY, name); |
515 | f = XLoadQueryFont (DISPLAY, name); |
359 | |
516 | |
360 | if (!f) |
517 | if (!f) |
361 | return false; |
518 | return false; |
362 | |
519 | |
363 | unsigned long value; |
520 | unsigned long value; |
364 | |
521 | |
365 | const char *registry = get_property ("CHARSET_REGISTRY", 0); |
522 | const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
366 | const char *encoding = get_property ("CHARSET_ENCODING", 0); |
523 | const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
367 | |
524 | |
368 | if (registry && encoding) |
525 | if (registry && encoding) |
369 | { |
526 | { |
370 | char charset[64]; |
527 | char charset[64]; |
371 | snprintf (charset, 64, "%s-%s", registry, encoding); |
528 | snprintf (charset, 64, "%s-%s", registry, encoding); |
372 | |
529 | |
373 | cs = codeset_from_name (charset); |
530 | cs = codeset_from_name (charset); |
374 | } |
531 | } |
375 | else |
532 | else |
376 | { |
533 | { |
377 | const char *charset = get_property ("FONT", 0); |
534 | const char *charset = get_property (f, "FONT", 0); |
378 | |
535 | |
379 | if (!charset) |
536 | if (!charset) |
380 | charset = name; |
537 | charset = name; |
381 | |
538 | |
382 | int count = 13; |
539 | int count = 13; |
… | |
… | |
395 | |
552 | |
396 | ascent = f->ascent; |
553 | ascent = f->ascent; |
397 | descent = f->descent; |
554 | descent = f->descent; |
398 | height = ascent + descent; |
555 | height = ascent + descent; |
399 | |
556 | |
400 | prop = false; |
557 | slow = false; |
401 | |
558 | |
402 | if (f->min_bounds.width == f->max_bounds.width) |
559 | if (f->min_bounds.width == f->max_bounds.width) |
403 | width = f->min_bounds.width; |
560 | width = f->min_bounds.width; |
404 | else if (f->per_char == NULL) |
561 | else if (f->per_char == NULL) |
405 | width = f->max_bounds.width; |
562 | width = f->max_bounds.width; |
406 | else |
563 | else |
407 | { |
564 | { |
408 | prop = true; |
565 | slow = true; |
409 | |
566 | |
410 | int N = f->max_char_or_byte2 - f->min_char_or_byte2; |
567 | int N = f->max_char_or_byte2 - f->min_char_or_byte2; |
411 | |
568 | |
412 | if (encm) |
569 | if (encm) |
413 | N += (f->max_byte1 - f->min_byte1) |
570 | N += (f->max_byte1 - f->min_byte1) |
… | |
… | |
498 | // this looks like a mess /. |
655 | // this looks like a mess /. |
499 | // and it is a mess /. |
656 | // and it is a mess /. |
500 | // yet we are trying to be perfect /. |
657 | // yet we are trying to be perfect /. |
501 | // but the result still isn't perfect /. |
658 | // but the result still isn't perfect /. |
502 | |
659 | |
503 | bool slow = prop |
660 | bool slow = this->slow |
504 | || width != r->TermWin.fwidth |
661 | || width != r->TermWin.fwidth |
505 | || height != r->TermWin.fheight; |
662 | || height != r->TermWin.fheight; |
506 | |
663 | |
507 | int base = r->TermWin.fbase; |
664 | int base = r->TermWin.fbase; |
508 | |
665 | |
… | |
… | |
583 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
740 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
584 | #define SWATHBITS 8 |
741 | #define SWATHBITS 8 |
585 | #endif |
742 | #endif |
586 | |
743 | |
587 | struct rxvt_font_xft : rxvt_font { |
744 | struct rxvt_font_xft : rxvt_font { |
588 | #if 0 |
|
|
589 | enum { |
|
|
590 | SWATHCOUNT = 1 << (21 - UNIBITS), |
|
|
591 | SWATHSIZE = 1 << (SWATHBITS - 5) |
|
|
592 | }; |
|
|
593 | typedef uint32_t swath[SWATHSIZE]; |
|
|
594 | |
|
|
595 | swath *cvr[SWATHCOUNT]; |
|
|
596 | #endif |
|
|
597 | |
|
|
598 | #if 0 |
|
|
599 | void gen_coverage_swath (unsigned int page); |
|
|
600 | |
|
|
601 | bool has_char (uint32_t ch) |
|
|
602 | { |
|
|
603 | unsigned int page = ch >> SWATHBITS; |
|
|
604 | unsigned int idx = ch & ((1 << SWATHBITS) - 1); |
|
|
605 | |
|
|
606 | if (page >= SWATHCOUNT) |
|
|
607 | return false; |
|
|
608 | |
|
|
609 | if (!cvr[page]) gen_coverage_swath (page); |
|
|
610 | |
|
|
611 | return cvr[page][idx >> 5] & (1 << (idx & 31)); |
|
|
612 | } |
|
|
613 | #endif |
|
|
614 | rxvt_font_xft () { f = 0; d = 0; } |
745 | rxvt_font_xft () { f = 0; d = 0; } |
615 | |
746 | |
616 | void clear (); |
747 | void clear (); |
617 | |
748 | |
618 | bool load (int maxheight); |
749 | rxvt_fontprop properties (); |
|
|
750 | |
|
|
751 | bool load (const rxvt_fontprop &prop); |
619 | |
752 | |
620 | void draw (int x, int y, |
753 | void draw (int x, int y, |
621 | const text_t *text, int len, |
754 | const text_t *text, int len, |
622 | int fg, int bg); |
755 | int fg, int bg); |
623 | |
756 | |
624 | bool has_codepoint (uint32_t unicode); |
757 | bool has_codepoint (uint32_t unicode); |
625 | |
758 | |
626 | protected: |
759 | protected: |
627 | XftFont *f; |
760 | XftFont *f; |
628 | XftDraw *d; |
761 | XftDraw *d; |
629 | |
|
|
630 | #if 0 |
|
|
631 | virtual void populate_coverage_swath (uint32_t lo, uint32_t hi) = 0; |
|
|
632 | void set_swath (uint32_t ch) |
|
|
633 | { |
|
|
634 | cvr[ch >> SWATHBITS] |= 1 << (ch & ((1 << SWATHBITS) - 1)); |
|
|
635 | } |
|
|
636 | #endif |
|
|
637 | }; |
762 | }; |
638 | |
763 | |
639 | void |
764 | void |
640 | rxvt_font_xft::clear () |
765 | rxvt_font_xft::clear () |
641 | { |
766 | { |
… | |
… | |
648 | if (d) |
773 | if (d) |
649 | { |
774 | { |
650 | XftDrawDestroy (d); |
775 | XftDrawDestroy (d); |
651 | d = 0; |
776 | d = 0; |
652 | } |
777 | } |
|
|
778 | } |
653 | |
779 | |
654 | #if 0 |
780 | rxvt_fontprop |
655 | for (int i = 0; i < SWATHCOUNT; i++) |
781 | rxvt_font_xft::properties () |
656 | delete cvr[i]; |
782 | { |
657 | #endif |
783 | rxvt_fontprop p; |
|
|
784 | |
|
|
785 | FT_Face face = XftLockFace (f); |
|
|
786 | |
|
|
787 | p.width = width; p.height = height; |
|
|
788 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
|
|
789 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
|
|
790 | |
|
|
791 | XftUnlockFace (f); |
|
|
792 | |
|
|
793 | return p; |
658 | } |
794 | } |
659 | |
795 | |
660 | bool |
796 | bool |
661 | rxvt_font_xft::load (int maxheight) |
797 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
662 | { |
798 | { |
663 | #if 0 |
799 | #if 0 |
664 | for (int i = 0; i < SWATHCOUNT; i++) |
800 | for (int i = 0; i < SWATHCOUNT; i++) |
665 | cvr[i] = 0; |
801 | cvr[i] = 0; |
666 | #endif |
802 | #endif |
667 | |
803 | |
668 | clear (); |
804 | clear (); |
669 | |
805 | |
670 | f = XftFontOpenName (DISPLAY, DefaultScreen (DISPLAY), name); |
806 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
|
|
807 | |
|
|
808 | if (!p) |
|
|
809 | return false; |
|
|
810 | |
|
|
811 | FcValue v; |
|
|
812 | |
|
|
813 | if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
|
|
814 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
|
|
815 | |
|
|
816 | if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
|
|
817 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
|
|
818 | |
|
|
819 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
|
|
820 | // clip width, we can't do better, or can we? |
|
|
821 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
|
|
822 | FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width); |
|
|
823 | #endif |
|
|
824 | |
|
|
825 | //FcPatternAddBool (p, FC_MINSPACE, 1); |
|
|
826 | |
|
|
827 | XftResult result; |
|
|
828 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
|
|
829 | |
|
|
830 | FcPatternDestroy (p); |
|
|
831 | |
|
|
832 | if (!match) |
|
|
833 | return false; |
|
|
834 | |
|
|
835 | f = XftFontOpenPattern (DISPLAY, match); |
671 | |
836 | |
672 | if (!f) |
837 | if (!f) |
|
|
838 | { |
|
|
839 | FcPatternDestroy (match); |
673 | return false; |
840 | return false; |
|
|
841 | } |
674 | |
842 | |
675 | FT_Face face = XftLockFace (f); |
843 | FT_Face face = XftLockFace (f); |
676 | |
844 | |
677 | prop = !FT_IS_FIXED_WIDTH (face); |
845 | slow = !FT_IS_FIXED_WIDTH (face); |
678 | |
846 | |
679 | int ftheight = 0; |
847 | int ftheight = 0; |
680 | |
848 | |
681 | for (;;) |
849 | for (;;) |
682 | { |
850 | { |
… | |
… | |
684 | FcChar8 c; |
852 | FcChar8 c; |
685 | |
853 | |
686 | c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); |
854 | c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); |
687 | c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); |
855 | c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); |
688 | |
856 | |
689 | prop = prop || g1.xOff != g2.xOff; // don't simply trust the font |
857 | if (g1.xOff != g2.xOff) // don't simply trust the font |
|
|
858 | slow = true; |
690 | |
859 | |
691 | width = g2.xOff; |
860 | width = g2.xOff; |
692 | ascent = (face->size->metrics.ascender + 63) >> 6; |
861 | ascent = (face->size->metrics.ascender + 63) >> 6; |
693 | descent = (-face->size->metrics.descender + 63) >> 6; |
862 | descent = (-face->size->metrics.descender + 63) >> 6; |
694 | height = ascent + descent; |
863 | height = ascent + descent; |
695 | |
864 | |
696 | if (height <= maxheight || !maxheight) |
865 | if (height <= prop.height || !prop.height) |
697 | break; |
866 | break; |
698 | |
867 | |
699 | if (ftheight) |
868 | if (ftheight) |
700 | { |
869 | { |
701 | // take smaller steps near the end |
870 | // take smaller steps near the end |
702 | if (height > maxheight + 1) ftheight++; |
871 | if (height > prop.height + 1) ftheight++; |
703 | if (height > maxheight + 2) ftheight++; |
872 | if (height > prop.height + 2) ftheight++; |
704 | if (height > maxheight + 3) ftheight++; |
873 | if (height > prop.height + 3) ftheight++; |
705 | |
874 | |
706 | FT_Set_Pixel_Sizes (face, 0, ftheight -= height - maxheight); |
875 | FT_Set_Pixel_Sizes (face, 0, ftheight -= height - prop.height); |
707 | } |
876 | } |
708 | else |
877 | else |
709 | FT_Set_Pixel_Sizes (face, 0, ftheight = maxheight); |
878 | FT_Set_Pixel_Sizes (face, 0, ftheight = prop.height); |
710 | } |
879 | } |
711 | |
880 | |
712 | XftUnlockFace (f); |
881 | XftUnlockFace (f); |
713 | |
882 | |
714 | return true; |
883 | return true; |
715 | } |
884 | } |
716 | |
|
|
717 | #if 0 |
|
|
718 | void rxvt_font::gen_coverage_swath (unsigned int page) |
|
|
719 | { |
|
|
720 | cvr[page] = new swath; |
|
|
721 | |
|
|
722 | for (int i = 0; i < SWATHSIZE; i++) |
|
|
723 | cvr[page][i] = 0; |
|
|
724 | |
|
|
725 | populate_coverage_swath (cvr[page], page << SWATHBITS, ((page + 1) << SWATHBITS) - 1); |
|
|
726 | } |
|
|
727 | #endif |
|
|
728 | |
885 | |
729 | bool |
886 | bool |
730 | rxvt_font_xft::has_codepoint (uint32_t unicode) |
887 | rxvt_font_xft::has_codepoint (uint32_t unicode) |
731 | { |
888 | { |
732 | return XftCharExists (DISPLAY, f, unicode); |
889 | return XftCharExists (DISPLAY, f, unicode); |
… | |
… | |
746 | if (bg >= 0 && bg != Color_bg) |
903 | if (bg >= 0 && bg != Color_bg) |
747 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
904 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
748 | else |
905 | else |
749 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
906 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
750 | |
907 | |
751 | if (!prop && width == r->TermWin.fwidth) |
908 | if (!slow && width == r->TermWin.fwidth && 0) |
752 | { |
909 | { |
753 | if (sizeof (text_t) == sizeof (FcChar16)) |
910 | if (sizeof (text_t) == sizeof (FcChar16)) |
754 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
911 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
755 | else |
912 | else |
756 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
913 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
… | |
… | |
759 | { |
916 | { |
760 | while (len) |
917 | while (len) |
761 | { |
918 | { |
762 | if (*text != NOCHAR && *text != ' ') |
919 | if (*text != NOCHAR && *text != ' ') |
763 | { |
920 | { |
|
|
921 | int fwidth = r->TermWin.fwidth; |
|
|
922 | if (len >= 2 && text[1] == NOCHAR) |
|
|
923 | fwidth *= 2; |
|
|
924 | |
|
|
925 | XGlyphInfo extents; |
764 | if (sizeof (text_t) == sizeof (FcChar16)) |
926 | if (sizeof (text_t) == sizeof (FcChar16)) |
765 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
927 | { |
|
|
928 | XftTextExtents16 (DISPLAY, f, (const FcChar16 *)text, 1, &extents); |
|
|
929 | XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
|
|
930 | y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
|
|
931 | } |
766 | else |
932 | else |
767 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
933 | { |
|
|
934 | XGlyphInfo extents; |
|
|
935 | XftTextExtents32 (DISPLAY, f, (const FcChar32 *)text, 1, &extents); |
|
|
936 | XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
|
|
937 | y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
|
|
938 | } |
768 | } |
939 | } |
769 | |
940 | |
770 | x += r->TermWin.fwidth; |
941 | x += r->TermWin.fwidth; |
771 | text++; |
942 | text++; |
772 | len--; |
943 | len--; |
… | |
… | |
796 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
967 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
797 | FONT_UNREF (*i); |
968 | FONT_UNREF (*i); |
798 | |
969 | |
799 | fonts.clear (); |
970 | fonts.clear (); |
800 | base_id = 0; |
971 | base_id = 0; |
801 | height = 0x7fffffff; |
972 | base_prop.height = 0x7fffffff; |
|
|
973 | base_prop.weight = rxvt_fontprop::medium; |
|
|
974 | base_prop.slant = rxvt_fontprop::roman; |
802 | |
975 | |
803 | fallback = fallback_fonts; |
976 | fallback = fallback_fonts; |
804 | } |
977 | } |
805 | |
978 | |
806 | rxvt_font * |
979 | rxvt_font * |
… | |
… | |
891 | rxvt_fontset::realize_font (int i) |
1064 | rxvt_fontset::realize_font (int i) |
892 | { |
1065 | { |
893 | if (fonts[i]->loaded) |
1066 | if (fonts[i]->loaded) |
894 | return true; |
1067 | return true; |
895 | |
1068 | |
896 | if (fonts[i]->load (height)) |
|
|
897 | return fonts[i]->loaded = true; |
1069 | fonts[i]->loaded = true; |
898 | |
1070 | |
899 | delete fonts[i]; |
1071 | if (!fonts[i]->load (base_prop)) |
900 | fonts.erase (fonts.begin () + i); |
1072 | { |
901 | |
1073 | fonts[i]->cs = CS_UNKNOWN; |
902 | return false; |
1074 | return false; |
|
|
1075 | } |
|
|
1076 | |
|
|
1077 | return true; |
903 | } |
1078 | } |
904 | |
1079 | |
905 | void |
1080 | void |
906 | rxvt_fontset::populate (const char *desc) |
1081 | rxvt_fontset::populate (const char *desc) |
907 | { |
1082 | { |
… | |
… | |
914 | |
1089 | |
915 | if (!base_id) |
1090 | if (!base_id) |
916 | base_id = 1; |
1091 | base_id = 1; |
917 | |
1092 | |
918 | // we currently need a base-font, no matter what |
1093 | // we currently need a base-font, no matter what |
919 | if (fonts.size () <= base_id) |
1094 | if (fonts.size () <= base_id || !realize_font (base_id)) |
920 | { |
1095 | { |
|
|
1096 | puts ("unable to load specified font(s), falling back to 'fixed'\n"); |
921 | add_fonts ("fixed"); |
1097 | add_fonts ("fixed"); |
922 | base_id = 1; |
1098 | base_id = fonts.size () - 1; |
923 | } |
1099 | } |
924 | |
1100 | |
925 | if (fonts.size () <= base_id || !realize_font (base_id)) |
1101 | if (fonts.size () <= base_id || !realize_font (base_id)) |
926 | { |
1102 | { |
927 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
1103 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
928 | exit (1); |
1104 | exit (1); |
929 | } |
1105 | } |
930 | |
1106 | |
931 | height = fonts[base_id]->height; |
1107 | base_prop = fonts[base_id]->properties (); |
932 | |
|
|
933 | /*add_fonts ("-efont-fixed-medium-r-normal-*-14-*-*-*-*-*-iso10646-1,"*/ |
|
|
934 | } |
1108 | } |
935 | |
1109 | |
936 | int |
1110 | int |
937 | rxvt_fontset::find_font (uint32_t unicode) |
1111 | rxvt_fontset::find_font (uint32_t unicode) |
938 | { |
1112 | { |
… | |
… | |
944 | { |
1118 | { |
945 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1119 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
946 | goto next_font; |
1120 | goto next_font; |
947 | |
1121 | |
948 | if (!realize_font (i)) |
1122 | if (!realize_font (i)) |
949 | { |
|
|
950 | --i; |
|
|
951 | goto next_font; |
1123 | goto next_font; |
952 | } |
1124 | } |
953 | |
1125 | |
954 | //printf ("added font %s for %04lx\n", f->name, unicode); |
|
|
955 | } |
|
|
956 | |
|
|
957 | if (f->has_codepoint (unicode)) |
1126 | if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode)) |
958 | return i; |
1127 | return i; |
959 | |
1128 | |
960 | next_font: |
1129 | next_font: |
961 | if (i == fonts.size () - 1 && fallback->name) |
1130 | if (i == fonts.size () - 1 && fallback->name) |
962 | { |
1131 | { |
963 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
1132 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
964 | fallback++; |
1133 | fallback++; |
|
|
1134 | i = 0; |
965 | } |
1135 | } |
966 | } |
1136 | } |
967 | |
1137 | |
968 | return 0; /* we must return SOME font */ |
1138 | return 0; /* we must return SOME font */ |
969 | } |
1139 | } |