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