1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: rxvtfont.C |
2 | * File: rxvtfont.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
4 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
5 | * - original version. |
5 | * - original version. |
6 | * |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
9 | * the Free Software Foundation; either version 2 of the License, or |
… | |
… | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | *---------------------------------------------------------------------*/ |
20 | *---------------------------------------------------------------------*/ |
21 | |
21 | |
22 | #include "../config.h" |
22 | #include "../config.h" |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
|
|
24 | #include "rxvtlib.h" |
24 | #include "rxvtutil.h" |
25 | #include "rxvtutil.h" |
25 | #include "rxvtfont.h" |
26 | #include "rxvtfont.h" |
26 | |
27 | |
27 | #include <cstdlib> |
28 | #include <cstdlib> |
28 | #include <wchar.h> |
29 | #include <wchar.h> |
29 | #include <inttypes.h> |
30 | #include <inttypes.h> |
30 | |
|
|
31 | #define DISPLAY r->display->display |
|
|
32 | #define TGC r->TermWin.gc |
|
|
33 | |
31 | |
34 | #define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width |
32 | #define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width |
35 | |
33 | |
36 | const struct rxvt_fallback_font { |
34 | const struct rxvt_fallback_font { |
37 | codeset cs; |
35 | codeset cs; |
… | |
… | |
152 | 0x304c, 0x672c, // が本 |
150 | 0x304c, 0x672c, // が本 |
153 | }; |
151 | }; |
154 | |
152 | |
155 | #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) |
153 | #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) |
156 | |
154 | |
|
|
155 | #define dTermDisplay Display *disp = term->display->display |
|
|
156 | #define dTermGC GC gc = term->gc |
|
|
157 | |
157 | ///////////////////////////////////////////////////////////////////////////// |
158 | ///////////////////////////////////////////////////////////////////////////// |
158 | |
159 | |
159 | #if XFT |
160 | #if XFT |
160 | rxvt_drawable::~rxvt_drawable () |
161 | rxvt_drawable::~rxvt_drawable () |
161 | { |
162 | { |
… | |
… | |
245 | if (this->name) free (this->name); // let the compiler optimize |
246 | if (this->name) free (this->name); // let the compiler optimize |
246 | this->name = name; |
247 | this->name = name; |
247 | } |
248 | } |
248 | |
249 | |
249 | void |
250 | void |
250 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) |
251 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
251 | { |
252 | { |
|
|
253 | dTermDisplay; |
|
|
254 | dTermGC; |
|
|
255 | |
252 | if (color == Color_bg) |
256 | if (color == Color_bg) |
253 | XClearArea (d.display->display, d, x, y, w, h, FALSE); |
257 | XClearArea (disp, d, x, y, w, h, FALSE); |
254 | else if (color >= 0) |
258 | else if (color >= 0) |
255 | { |
259 | { |
256 | #if XFT |
260 | #if XFT |
257 | XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); |
261 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
258 | #else |
262 | #else |
259 | XSetForeground (d.display->display, TGC, r->pix_colors[color]); |
263 | XSetForeground (disp, gc, term->pix_colors[color]); |
260 | XFillRectangle (d.display->display, d, TGC, x, y, w, h); |
264 | XFillRectangle (disp, d, gc, x, y, w, h); |
261 | #endif |
265 | #endif |
262 | } |
266 | } |
263 | } |
267 | } |
264 | |
268 | |
265 | #include "table/linedraw.h" |
269 | #include "table/linedraw.h" |
… | |
… | |
276 | rxvt_fontprop properties () |
280 | rxvt_fontprop properties () |
277 | { |
281 | { |
278 | rxvt_fontprop p; |
282 | rxvt_fontprop p; |
279 | |
283 | |
280 | p.width = p.height = 1; |
284 | p.width = p.height = 1; |
|
|
285 | p.ascent = rxvt_fontprop::unset; |
281 | p.weight = rxvt_fontprop::medium; |
286 | p.weight = rxvt_fontprop::medium; |
282 | p.slant = rxvt_fontprop::roman; |
287 | p.slant = rxvt_fontprop::roman; |
283 | |
288 | |
284 | return p; |
289 | return p; |
285 | } |
290 | } |
… | |
… | |
292 | set_name (strdup ("built-in support font")); |
297 | set_name (strdup ("built-in support font")); |
293 | |
298 | |
294 | return true; |
299 | return true; |
295 | } |
300 | } |
296 | |
301 | |
297 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) |
302 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
298 | { |
303 | { |
299 | careful = false; |
304 | careful = false; |
300 | |
305 | |
301 | if (unicode <= 0x001f) |
306 | if (unicode <= 0x001f) |
302 | return true; |
307 | return true; |
… | |
… | |
305 | return false; |
310 | return false; |
306 | |
311 | |
307 | if (unicode <= 0x009f) |
312 | if (unicode <= 0x009f) |
308 | return true; |
313 | return true; |
309 | |
314 | |
310 | if (unicode >= 0x2500 && unicode <= 0x259f) |
315 | if (unicode >= 0x2500 && unicode <= 0x259f && |
|
|
316 | !term->option (Opt_skipBuiltinGlyphs)) |
311 | return true; |
317 | return true; |
312 | |
318 | |
313 | if (IS_COMPOSE (unicode)) |
319 | if (IS_COMPOSE (unicode)) |
314 | return true; |
320 | return true; |
315 | |
321 | |
… | |
… | |
331 | void |
337 | void |
332 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
338 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
333 | const text_t *text, int len, |
339 | const text_t *text, int len, |
334 | int fg, int bg) |
340 | int fg, int bg) |
335 | { |
341 | { |
336 | Display *disp = d.display->display; |
342 | dTermDisplay; |
|
|
343 | dTermGC; |
337 | |
344 | |
338 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
345 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
339 | |
346 | |
340 | XSetForeground (disp, TGC, r->pix_colors[fg]); |
347 | XSetForeground (disp, gc, term->pix_colors[fg]); |
341 | |
348 | |
342 | while (len) |
349 | while (len) |
343 | { |
350 | { |
344 | #if ENABLE_COMBINING |
351 | #if ENABLE_COMBINING |
345 | compose_char *cc; |
352 | compose_char *cc; |
… | |
… | |
349 | |
356 | |
350 | while (++text, --len && *text == NOCHAR) |
357 | while (++text, --len && *text == NOCHAR) |
351 | ; |
358 | ; |
352 | |
359 | |
353 | int width = text - tp; |
360 | int width = text - tp; |
354 | int fwidth = r->TermWin.fwidth * width; |
361 | int fwidth = term->fwidth * width; |
355 | |
362 | |
356 | if (0x2500 <= t && t <= 0x259f) |
363 | if (0x2500 <= t && t <= 0x259f) |
357 | { |
364 | { |
358 | uint16_t offs = linedraw_offs[t - 0x2500]; |
365 | uint16_t offs = linedraw_offs[t - 0x2500]; |
359 | uint32_t *a = linedraw_command + (offs >> 4); |
366 | uint32_t *a = linedraw_command + (offs >> 4); |
360 | uint32_t *b = a + (offs & 15); |
367 | uint32_t *b = a + (offs & 15); |
361 | |
368 | |
362 | int W = fwidth; |
369 | int W = fwidth; |
363 | int H = r->TermWin.fheight; |
370 | int H = term->fheight; |
364 | |
371 | |
365 | int x_[16]; |
372 | int x_[16]; |
366 | int y_[16]; |
373 | int y_[16]; |
367 | |
374 | |
368 | for (int i = 0; i <= 8; i++) |
375 | for (int i = 0; i <= 8; i++) |
… | |
… | |
376 | |
383 | |
377 | XGCValues gcv; |
384 | XGCValues gcv; |
378 | |
385 | |
379 | gcv.cap_style = CapButt; |
386 | gcv.cap_style = CapButt; |
380 | gcv.line_width = 0; |
387 | gcv.line_width = 0; |
381 | XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv); |
388 | XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv); |
382 | |
389 | |
383 | while (a < b) |
390 | while (a < b) |
384 | { |
391 | { |
385 | uint32_t command = *a++; |
392 | uint32_t command = *a++; |
386 | |
393 | |
… | |
… | |
393 | int y2 = y_[(command >> 0) & 15]; |
400 | int y2 = y_[(command >> 0) & 15]; |
394 | |
401 | |
395 | switch (op) |
402 | switch (op) |
396 | { |
403 | { |
397 | case 0: // line |
404 | case 0: // line |
398 | XDrawLine (disp, d, TGC, x1, y1, x2, y2); |
405 | XDrawLine (disp, d, gc, x1, y1, x2, y2); |
399 | break; |
406 | break; |
400 | |
407 | |
401 | case 1: // rectangle, possibly stippled |
408 | case 1: // rectangle, possibly stippled |
402 | if (a) |
409 | if (a) |
403 | { |
410 | { |
… | |
… | |
406 | gcv.fill_style = FillStippled; |
413 | gcv.fill_style = FillStippled; |
407 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
414 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
408 | gcv.ts_x_origin = x; |
415 | gcv.ts_x_origin = x; |
409 | gcv.ts_y_origin = y; |
416 | gcv.ts_y_origin = y; |
410 | |
417 | |
411 | XChangeGC (disp, TGC, |
418 | XChangeGC (disp, gc, |
412 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
419 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
413 | &gcv); |
420 | &gcv); |
414 | } |
421 | } |
415 | |
422 | |
416 | XFillRectangle (disp, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
423 | XFillRectangle (disp, d, gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
417 | |
424 | |
418 | if (a) |
425 | if (a) |
419 | { |
426 | { |
420 | XFreePixmap (disp, gcv.stipple); |
427 | XFreePixmap (disp, gcv.stipple); |
421 | gcv.stipple = 0; |
428 | gcv.stipple = 0; |
422 | gcv.fill_style = FillSolid; |
429 | gcv.fill_style = FillSolid; |
423 | XChangeGC (disp, TGC, GCFillStyle, &gcv); |
430 | XChangeGC (disp, gc, GCFillStyle, &gcv); |
424 | } |
431 | } |
425 | break; |
432 | break; |
426 | case 2: // arc |
433 | case 2: // arc |
427 | XDrawArc (disp, d, TGC, |
434 | XDrawArc (disp, d, gc, |
428 | x1 - W/2, y1 - H/2, W-1, H-1, |
435 | x1 - W/2, y1 - H/2, W-1, H-1, |
429 | (a - 1) * 90*64, (b - 1) * 90*64); |
436 | (a - 1) * 90*64, (b - 1) * 90*64); |
430 | break; |
437 | break; |
431 | } |
438 | } |
432 | } |
439 | } |
… | |
… | |
463 | case ZERO_WIDTH_CHAR: |
470 | case ZERO_WIDTH_CHAR: |
464 | case NOCHAR: |
471 | case NOCHAR: |
465 | break; |
472 | break; |
466 | |
473 | |
467 | default: |
474 | default: |
468 | XDrawRectangle (disp, d, TGC, x + 2, y + 2, |
475 | XDrawRectangle (disp, d, gc, x + 2, y + 2, |
469 | fwidth - 4, r->TermWin.fheight - 4); |
476 | fwidth - 4, term->fheight - 4); |
470 | } |
477 | } |
471 | |
478 | |
472 | x += fwidth; |
479 | x += fwidth; |
473 | } |
480 | } |
474 | } |
481 | } |
… | |
… | |
482 | |
489 | |
483 | rxvt_fontprop properties (); |
490 | rxvt_fontprop properties (); |
484 | |
491 | |
485 | bool load (const rxvt_fontprop &prop); |
492 | bool load (const rxvt_fontprop &prop); |
486 | |
493 | |
487 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful); |
494 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; |
488 | |
495 | |
489 | void draw (rxvt_drawable &d, int x, int y, |
496 | void draw (rxvt_drawable &d, int x, int y, |
490 | const text_t *text, int len, |
497 | const text_t *text, int len, |
491 | int fg, int bg); |
498 | int fg, int bg); |
492 | |
499 | |
… | |
… | |
504 | char * |
511 | char * |
505 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
512 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
506 | { |
513 | { |
507 | unsigned long value; |
514 | unsigned long value; |
508 | |
515 | |
509 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
516 | if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value)) |
510 | return XGetAtomName (DISPLAY, value); |
517 | return XGetAtomName (term->display->display, value); |
511 | else |
518 | else |
512 | return rxvt_strdup (repl); |
519 | return rxvt_strdup (repl); |
513 | } |
520 | } |
514 | |
521 | |
515 | rxvt_fontprop |
522 | rxvt_fontprop |
… | |
… | |
523 | bool |
530 | bool |
524 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
531 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
525 | { |
532 | { |
526 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
533 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
527 | p.height = height; |
534 | p.height = height; |
|
|
535 | p.ascent = rxvt_fontprop::unset; |
528 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
536 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
529 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
537 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
530 | |
538 | |
531 | return true; |
539 | return true; |
532 | } |
540 | } |
… | |
… | |
535 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
543 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
536 | { |
544 | { |
537 | unsigned long height; |
545 | unsigned long height; |
538 | |
546 | |
539 | #if 0 |
547 | #if 0 |
540 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
548 | if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height)) |
541 | return false; |
549 | return false; |
542 | #else |
550 | #else |
543 | height = f->ascent + f->descent; |
551 | height = f->ascent + f->descent; |
544 | #endif |
552 | #endif |
545 | |
553 | |
546 | unsigned long avgwidth; |
554 | unsigned long avgwidth; |
547 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
555 | if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth)) |
548 | avgwidth = 0; |
556 | avgwidth = 0; |
549 | |
557 | |
550 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
558 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
551 | char *slant = get_property (f, "SLANT", "r"); |
559 | char *slant = get_property (f, "SLANT", "r"); |
552 | |
560 | |
553 | set_properties (p, height, weight, slant, avgwidth); |
561 | set_properties (p, height, weight, slant, avgwidth); |
554 | |
562 | |
555 | free (weight); |
563 | free (weight); |
556 | free (slant); |
564 | free (slant); |
557 | |
565 | |
|
|
566 | p.ascent = f->ascent; |
|
|
567 | |
558 | return true; |
568 | return true; |
559 | } |
569 | } |
560 | |
570 | |
561 | bool |
571 | bool |
562 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
572 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
563 | { |
573 | { |
|
|
574 | dTermDisplay; |
564 | int slashes = 0; |
575 | int slashes = 0; |
565 | const char *comp[13]; |
576 | const char *comp[13]; |
566 | |
577 | |
567 | for (const char *c = name; *c; c++) |
578 | for (const char *c = name; *c; c++) |
568 | if (*c == '-') |
579 | if (*c == '-') |
… | |
… | |
576 | if (slashes >= 13 |
587 | if (slashes >= 13 |
577 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
588 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
578 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
589 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
579 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
590 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
580 | |
591 | |
581 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
592 | XFontStruct *f = XLoadQueryFont (disp, name); |
582 | |
593 | |
583 | if (f) |
594 | if (f) |
584 | { |
595 | { |
585 | // the font should really exist now. if not, we have a problem |
596 | // the font should really exist now. if not, we have a problem |
586 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
597 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
587 | // in that case, just return garbage. |
598 | // in that case, just return garbage. |
588 | bool ret = set_properties (p, f); |
599 | bool ret = set_properties (p, f); |
589 | XFreeFont (DISPLAY, f); |
600 | XFreeFont (disp, f); |
590 | return ret; |
601 | return ret; |
591 | } |
602 | } |
592 | else |
603 | else |
593 | return false; |
604 | return false; |
594 | } |
605 | } |
… | |
… | |
632 | } |
643 | } |
633 | |
644 | |
634 | bool |
645 | bool |
635 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
646 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
636 | { |
647 | { |
637 | Display *disp = DISPLAY; |
648 | dTermDisplay; |
638 | |
649 | |
639 | clear (); |
650 | clear (); |
640 | |
651 | |
641 | char field_str[64]; // enough for 128 bits |
652 | char field_str[64]; // enough for 128 bits |
642 | |
653 | |
… | |
… | |
717 | int diff = 0; |
728 | int diff = 0; |
718 | |
729 | |
719 | if (replace_field (fname, list[i], 6, '0', field_str)) |
730 | if (replace_field (fname, list[i], 6, '0', field_str)) |
720 | diff += 10; // slightly penalize scalable fonts |
731 | diff += 10; // slightly penalize scalable fonts |
721 | else if (replace_field (fname, list[i], 11, '0', "0")) |
732 | else if (replace_field (fname, list[i], 11, '0', "0")) |
722 | diff += 300; // more heavily penalize what looks like scaled bitmap fotns |
733 | diff += 300; // more heavily penalize what looks like scaled bitmap fonts |
723 | |
734 | |
724 | if (!set_properties (p, fname)) |
735 | if (!set_properties (p, fname)) |
725 | continue; |
736 | continue; |
726 | |
737 | |
727 | if (prop.height != rxvt_fontprop::unset |
738 | if (prop.height != rxvt_fontprop::unset |
… | |
… | |
880 | void |
891 | void |
881 | rxvt_font_x11::clear () |
892 | rxvt_font_x11::clear () |
882 | { |
893 | { |
883 | if (f) |
894 | if (f) |
884 | { |
895 | { |
885 | XFreeFont (DISPLAY, f); |
896 | XFreeFont (term->display->display, f); |
886 | f = 0; |
897 | f = 0; |
887 | } |
898 | } |
888 | } |
899 | } |
889 | |
900 | |
890 | bool |
901 | bool |
891 | rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) |
902 | rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
892 | { |
903 | { |
893 | uint32_t ch = FROM_UNICODE (cs, unicode); |
904 | uint32_t ch = FROM_UNICODE (cs, unicode); |
894 | |
905 | |
895 | if (ch == NOCHAR) |
906 | if (ch == NOCHAR) |
896 | return false; |
907 | return false; |
… | |
… | |
955 | // this looks like a mess /. |
966 | // this looks like a mess /. |
956 | // and it is a mess /. |
967 | // and it is a mess /. |
957 | // yet we are trying to be perfect /. |
968 | // yet we are trying to be perfect /. |
958 | // but the result still isn't perfect /. |
969 | // but the result still isn't perfect /. |
959 | |
970 | |
|
|
971 | dTermDisplay; |
|
|
972 | dTermGC; |
|
|
973 | |
960 | bool slow = this->slow |
974 | bool slow = this->slow |
961 | || width != r->TermWin.fwidth |
975 | || width != term->fwidth |
962 | || height != r->TermWin.fheight; |
976 | || height != term->fheight; |
963 | |
977 | |
964 | int base = ascent; // sorry, incorrect: r->TermWin.fbase; |
978 | int base = ascent; // sorry, incorrect: term->fbase; |
965 | |
979 | |
966 | XGCValues v; |
980 | XGCValues v; |
967 | v.foreground = r->pix_colors[fg]; |
981 | v.foreground = term->pix_colors[fg]; |
968 | v.font = f->fid; |
982 | v.font = f->fid; |
969 | |
983 | |
970 | if (enc2b) |
984 | if (enc2b) |
971 | { |
985 | { |
972 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
986 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
973 | |
987 | |
974 | if (bg == Color_bg && !slow) |
988 | if (bg == Color_bg && !slow) |
975 | { |
989 | { |
976 | v.background = r->pix_colors[bg]; |
990 | v.background = term->pix_colors[bg]; |
977 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
991 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
978 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
992 | XDrawImageString16 (disp, d, gc, x, y + base, xc, len); |
979 | } |
993 | } |
980 | else |
994 | else |
981 | { |
995 | { |
982 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
996 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
983 | |
997 | |
984 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
998 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
985 | |
999 | |
986 | if (slow) |
1000 | if (slow) |
987 | { |
1001 | { |
988 | do |
1002 | do |
989 | { |
1003 | { |
990 | if (xc->byte1 || xc->byte2) |
1004 | if (xc->byte1 || xc->byte2) |
991 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
1005 | XDrawString16 (disp, d, gc, x, y + base, xc, 1); |
992 | |
1006 | |
993 | x += r->TermWin.fwidth; |
1007 | x += term->fwidth; |
994 | xc++; len--; |
1008 | xc++; len--; |
995 | } |
1009 | } |
996 | while (len); |
1010 | while (len); |
997 | } |
1011 | } |
998 | else |
1012 | else |
999 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); |
1013 | XDrawString16 (disp, d, gc, x, y + base, xc, len); |
1000 | } |
1014 | } |
1001 | } |
1015 | } |
1002 | else |
1016 | else |
1003 | { |
1017 | { |
1004 | const char *xc = enc_char (text, len, cs, slow); |
1018 | const char *xc = enc_char (text, len, cs, slow); |
1005 | |
1019 | |
1006 | if (bg == Color_bg && !slow) |
1020 | if (bg == Color_bg && !slow) |
1007 | { |
1021 | { |
1008 | v.background = r->pix_colors[bg]; |
1022 | v.background = term->pix_colors[bg]; |
1009 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1023 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
1010 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1024 | XDrawImageString (disp, d, gc, x, y + base, xc, len); |
1011 | } |
1025 | } |
1012 | else |
1026 | else |
1013 | { |
1027 | { |
1014 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1028 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
1015 | |
1029 | |
1016 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1030 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
1017 | |
1031 | |
1018 | if (slow) |
1032 | if (slow) |
1019 | { |
1033 | { |
1020 | do |
1034 | do |
1021 | { |
1035 | { |
1022 | if (*xc) |
1036 | if (*xc) |
1023 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1037 | XDrawString (disp, d, gc, x, y + base, xc, 1); |
1024 | |
1038 | |
1025 | x += r->TermWin.fwidth; |
1039 | x += term->fwidth; |
1026 | xc++; len--; |
1040 | xc++; len--; |
1027 | } |
1041 | } |
1028 | while (len); |
1042 | while (len); |
1029 | } |
1043 | } |
1030 | else |
1044 | else |
1031 | XDrawString (d.display->display, d, TGC, x, y + base, xc, len); |
1045 | XDrawString (disp, d, gc, x, y + base, xc, len); |
1032 | } |
1046 | } |
1033 | } |
1047 | } |
1034 | } |
1048 | } |
1035 | |
1049 | |
1036 | ///////////////////////////////////////////////////////////////////////////// |
1050 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
1048 | |
1062 | |
1049 | void draw (rxvt_drawable &d, int x, int y, |
1063 | void draw (rxvt_drawable &d, int x, int y, |
1050 | const text_t *text, int len, |
1064 | const text_t *text, int len, |
1051 | int fg, int bg); |
1065 | int fg, int bg); |
1052 | |
1066 | |
1053 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull); |
1067 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const; |
1054 | |
1068 | |
1055 | protected: |
1069 | protected: |
1056 | XftFont *f; |
1070 | XftFont *f; |
1057 | }; |
1071 | }; |
1058 | |
1072 | |
1059 | void |
1073 | void |
1060 | rxvt_font_xft::clear () |
1074 | rxvt_font_xft::clear () |
1061 | { |
1075 | { |
1062 | if (f) |
1076 | if (f) |
1063 | { |
1077 | { |
1064 | XftFontClose (DISPLAY, f); |
1078 | XftFontClose (term->display->display, f); |
1065 | f = 0; |
1079 | f = 0; |
1066 | } |
1080 | } |
1067 | } |
1081 | } |
1068 | |
1082 | |
1069 | rxvt_fontprop |
1083 | rxvt_fontprop |
… | |
… | |
1073 | |
1087 | |
1074 | FT_Face face = XftLockFace (f); |
1088 | FT_Face face = XftLockFace (f); |
1075 | |
1089 | |
1076 | p.width = width; |
1090 | p.width = width; |
1077 | p.height = height; |
1091 | p.height = height; |
|
|
1092 | p.ascent = ascent; |
1078 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1093 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1079 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1094 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1080 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1095 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1081 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1096 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1082 | |
1097 | |
… | |
… | |
1086 | } |
1101 | } |
1087 | |
1102 | |
1088 | bool |
1103 | bool |
1089 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1104 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1090 | { |
1105 | { |
1091 | Display *disp = DISPLAY; |
1106 | dTermDisplay; |
1092 | |
1107 | |
1093 | clear (); |
1108 | clear (); |
1094 | |
1109 | |
1095 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1110 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1096 | |
1111 | |
… | |
… | |
1123 | |
1138 | |
1124 | // store generated name so iso14755 view gives better results |
1139 | // store generated name so iso14755 view gives better results |
1125 | set_name ((char *)FcNameUnparse (p)); |
1140 | set_name ((char *)FcNameUnparse (p)); |
1126 | |
1141 | |
1127 | XftResult result; |
1142 | XftResult result; |
1128 | FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result); |
1143 | FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result); |
1129 | |
1144 | |
1130 | FcPatternDestroy (p); |
1145 | FcPatternDestroy (p); |
1131 | |
1146 | |
1132 | if (!match) |
1147 | if (!match) |
1133 | return false; |
1148 | return false; |
… | |
… | |
1181 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1196 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1182 | |
1197 | |
1183 | if (width < g.width ) width = g.width; |
1198 | if (width < g.width ) width = g.width; |
1184 | if (height < g.height ) height = g.height; |
1199 | if (height < g.height ) height = g.height; |
1185 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
1200 | if (glheight < g.height - g.y) glheight = g.height - g.y; |
|
|
1201 | } |
|
|
1202 | |
|
|
1203 | if (!width) |
|
|
1204 | { |
|
|
1205 | rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); |
|
|
1206 | |
|
|
1207 | XftFontClose (disp, f); |
|
|
1208 | f = 0; |
|
|
1209 | |
|
|
1210 | success = false; |
|
|
1211 | break; |
1186 | } |
1212 | } |
1187 | |
1213 | |
1188 | if (prop.height == rxvt_fontprop::unset |
1214 | if (prop.height == rxvt_fontprop::unset |
1189 | || (height <= prop.height && glheight <= prop.height) |
1215 | || (height <= prop.height && glheight <= prop.height) |
1190 | || height <= 2 |
1216 | || height <= 2 |
… | |
… | |
1201 | ftheight -= height - prop.height; |
1227 | ftheight -= height - prop.height; |
1202 | } |
1228 | } |
1203 | else |
1229 | else |
1204 | ftheight = prop.height - 1; |
1230 | ftheight = prop.height - 1; |
1205 | |
1231 | |
1206 | XftFontClose (disp, f); |
1232 | XftFontClose (disp, f); |
1207 | FcPatternDel (match, FC_PIXEL_SIZE); |
1233 | FcPatternDel (match, FC_PIXEL_SIZE); |
1208 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1234 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1209 | } |
1235 | } |
1210 | |
1236 | |
1211 | FcPatternDestroy (match); |
1237 | FcPatternDestroy (match); |
1212 | |
1238 | |
1213 | #if 0 // do it per-character |
1239 | #if 0 // do it per-character |
… | |
… | |
1220 | |
1246 | |
1221 | return success; |
1247 | return success; |
1222 | } |
1248 | } |
1223 | |
1249 | |
1224 | bool |
1250 | bool |
1225 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) |
1251 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1226 | { |
1252 | { |
1227 | careful = false; |
1253 | careful = false; |
1228 | |
1254 | |
1229 | if (!XftCharExists (DISPLAY, f, unicode)) |
1255 | if (!XftCharExists (term->display->display, f, unicode)) |
1230 | return false; |
1256 | return false; |
1231 | |
1257 | |
1232 | if (!prop || prop->width == rxvt_fontprop::unset) |
1258 | if (!prop || prop->width == rxvt_fontprop::unset) |
1233 | return true; |
1259 | return true; |
1234 | |
1260 | |
1235 | // check character against base font bounding box |
1261 | // check character against base font bounding box |
1236 | FcChar32 ch = unicode; |
1262 | FcChar32 ch = unicode; |
1237 | XGlyphInfo g; |
1263 | XGlyphInfo g; |
1238 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1264 | XftTextExtents32 (term->display->display, f, &ch, 1, &g); |
1239 | |
1265 | |
1240 | int w = g.width - g.x; |
1266 | int w = g.width - g.x; |
1241 | int wcw = wcwidth (unicode); |
1267 | int wcw = wcwidth (unicode); |
1242 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1268 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1243 | |
1269 | |
… | |
… | |
1251 | void |
1277 | void |
1252 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1278 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1253 | const text_t *text, int len, |
1279 | const text_t *text, int len, |
1254 | int fg, int bg) |
1280 | int fg, int bg) |
1255 | { |
1281 | { |
1256 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1282 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
1257 | |
|
|
1258 | int base = ascent; // should be fbase, but that is incorrect |
|
|
1259 | |
1283 | |
1260 | XGlyphInfo extents; |
1284 | XGlyphInfo extents; |
1261 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1285 | XftGlyphSpec *enc = (XftGlyphSpec *)get_enc_buf (len * sizeof (XftGlyphSpec)); |
1262 | FcChar32 *ep = enc; |
1286 | XftGlyphSpec *ep = enc; |
1263 | int ewidth = 0; |
1287 | |
|
|
1288 | dTermDisplay; |
|
|
1289 | dTermGC; |
|
|
1290 | |
|
|
1291 | // cut trailing spaces |
|
|
1292 | while (len && text [len - 1] == ' ') |
|
|
1293 | len--; |
1264 | |
1294 | |
1265 | while (len) |
1295 | while (len) |
1266 | { |
1296 | { |
1267 | int cwidth = r->TermWin.fwidth; |
1297 | int cwidth = term->fwidth; |
1268 | FcChar32 fc = *text++; len--; |
1298 | FcChar32 fc = *text++; len--; |
1269 | |
1299 | |
1270 | while (len && *text == NOCHAR) |
1300 | while (len && *text == NOCHAR) |
1271 | text++, len--, cwidth += r->TermWin.fwidth; |
1301 | text++, len--, cwidth += term->fwidth; |
1272 | |
1302 | |
1273 | if (fc == ' ' && ep == enc) // skip leading spaces |
1303 | if (fc != ' ') // skip spaces |
|
|
1304 | { |
|
|
1305 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
|
|
1306 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
|
|
1307 | |
|
|
1308 | ep->glyph = glyph; |
|
|
1309 | ep->x = x + (cwidth - extents.xOff >> 1); |
|
|
1310 | ep->y = y + ascent; |
|
|
1311 | ep++; |
|
|
1312 | } |
|
|
1313 | |
1274 | x += cwidth; |
1314 | x += cwidth; |
1275 | else |
|
|
1276 | { |
|
|
1277 | FT_UInt gl = XftCharIndex (d.display->display, f, fc); |
|
|
1278 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1279 | |
|
|
1280 | if (extents.xOff != cwidth) |
|
|
1281 | { |
|
|
1282 | if (ewidth) |
|
|
1283 | { |
|
|
1284 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1285 | x, y + base, enc, ep - enc); |
|
|
1286 | x += ewidth; |
|
|
1287 | |
|
|
1288 | ep = enc; |
|
|
1289 | ewidth = 0; |
|
|
1290 | } |
|
|
1291 | |
|
|
1292 | if (extents.xOff > cwidth) |
|
|
1293 | extents.xOff = cwidth; |
|
|
1294 | |
|
|
1295 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1296 | x + (cwidth - extents.xOff >> 1), |
|
|
1297 | y + base, &gl, 1); |
|
|
1298 | x += cwidth; |
|
|
1299 | } |
|
|
1300 | else |
|
|
1301 | { |
|
|
1302 | *ep++ = gl; |
|
|
1303 | ewidth += cwidth; |
|
|
1304 | } |
|
|
1305 | } |
|
|
1306 | } |
1315 | } |
1307 | |
1316 | |
1308 | if (ep != enc) |
1317 | if (ep != enc) |
1309 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1318 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1310 | x, y + base, enc, ep - enc); |
|
|
1311 | } |
1319 | } |
1312 | #endif |
1320 | #endif |
1313 | |
1321 | |
1314 | ///////////////////////////////////////////////////////////////////////////// |
1322 | ///////////////////////////////////////////////////////////////////////////// |
1315 | |
1323 | |
1316 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1324 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
1317 | : fontdesc (0), r (r) |
1325 | : fontdesc (0), term (term) |
1318 | { |
1326 | { |
1319 | clear (); |
1327 | clear (); |
1320 | } |
1328 | } |
1321 | |
1329 | |
1322 | rxvt_fontset::~rxvt_fontset () |
1330 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1325 | } |
1333 | } |
1326 | |
1334 | |
1327 | void |
1335 | void |
1328 | rxvt_fontset::clear () |
1336 | rxvt_fontset::clear () |
1329 | { |
1337 | { |
1330 | prop.width = prop.height = prop.weight = prop.slant |
1338 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1331 | = rxvt_fontprop::unset; |
1339 | = rxvt_fontprop::unset; |
1332 | |
1340 | |
1333 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1341 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1334 | FONT_UNREF (*i); |
1342 | FONT_UNREF (*i); |
1335 | |
1343 | |
… | |
… | |
1366 | f = new rxvt_font_x11; |
1374 | f = new rxvt_font_x11; |
1367 | } |
1375 | } |
1368 | else |
1376 | else |
1369 | f = new rxvt_font_x11; |
1377 | f = new rxvt_font_x11; |
1370 | |
1378 | |
1371 | f->set_term (r); |
1379 | f->set_term (term); |
1372 | f->set_name (strdup (name)); |
1380 | f->set_name (strdup (name)); |
1373 | |
1381 | |
1374 | f->cs = cs; |
1382 | f->cs = cs; |
1375 | f->loaded = false; |
1383 | f->loaded = false; |
1376 | |
1384 | |
… | |
… | |
1508 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1516 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1509 | goto next_font; |
1517 | goto next_font; |
1510 | |
1518 | |
1511 | if (!realize_font (i)) |
1519 | if (!realize_font (i)) |
1512 | goto next_font; |
1520 | goto next_font; |
|
|
1521 | |
|
|
1522 | if (prop.ascent != rxvt_fontprop::unset) |
|
|
1523 | max_it (f->ascent, prop.ascent); |
1513 | } |
1524 | } |
1514 | |
1525 | |
1515 | if (f->cs == CS_UNKNOWN) |
1526 | if (f->cs == CS_UNKNOWN) |
1516 | goto next_font; |
1527 | goto next_font; |
1517 | |
1528 | |
… | |
… | |
1556 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1567 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1557 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1568 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1558 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1569 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1559 | |
1570 | |
1560 | XftResult result; |
1571 | XftResult result; |
1561 | FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result); |
1572 | FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result); |
1562 | |
1573 | |
1563 | FcPatternDestroy (p); |
1574 | FcPatternDestroy (p); |
1564 | |
1575 | |
1565 | if (match) |
1576 | if (match) |
1566 | { |
1577 | { |