… | |
… | |
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 | #define DISPLAY R->Xdisplay |
26 | #define DISPLAY r->Xdisplay |
27 | #define DRAWABLE R->TermWin.vt |
27 | #define DRAWABLE r->TermWin.vt |
28 | #define GC R->TermWin.gc |
28 | #define GC r->TermWin.gc |
29 | |
29 | |
30 | const struct rxvt_fallback_font { |
30 | const struct rxvt_fallback_font { |
31 | codeset cs; |
31 | codeset cs; |
32 | const char *name; |
32 | const char *name; |
33 | } fallback_fonts[] = { |
33 | } fallback_fonts[] = { |
… | |
… | |
163 | { |
163 | { |
164 | if (color == Color_bg) |
164 | if (color == Color_bg) |
165 | XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); |
165 | XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); |
166 | else if (color >= 0) |
166 | else if (color >= 0) |
167 | { |
167 | { |
168 | XSetForeground (DISPLAY, GC, R->PixColors[color]); |
168 | XSetForeground (DISPLAY, GC, r->PixColors[color]); |
169 | XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
169 | XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
170 | } |
170 | } |
171 | } |
171 | } |
|
|
172 | |
|
|
173 | static const char *linedraw_cmds[128] = { |
|
|
174 | "1hH", "2hH", "1vV", "2vV", |
|
|
175 | 0, 0, 0, 0, |
|
|
176 | 0, 0, 0, 0, |
|
|
177 | "1HV", "2H1V", "1H2V", "2HV", |
|
|
178 | |
|
|
179 | // 2510 |
|
|
180 | "1hV", "2h1V", "1h2V", "2hV", |
|
|
181 | "1Hv", "2H1v", "1H2v", "2Hv", |
|
|
182 | "1hv", "2h1v", "1h2v", "2hv", |
|
|
183 | "1HvV", "2H1vV", "1HV2v", "1Hv2V", |
|
|
184 | |
|
|
185 | // 2520 |
|
|
186 | "1H2vV", "2Hv1V", "2HV1v", "2HvV", |
|
|
187 | "1hvV", "2h1vV", "1hV2v", "1hv2V", |
|
|
188 | "1h2vV", "2hv1V", "1v2hV", "2hvV", |
|
|
189 | "1hHV", "2h1HV", "2H1hV", "2hH1V", |
|
|
190 | |
|
|
191 | // 2530 |
|
|
192 | "1hH2V", "2hV1H", "1h2HV", "2hHV", |
|
|
193 | "1hHv", "1vH2h", "1hv2H", "1v2hH", |
|
|
194 | "1hH2v", "1H2hv", "1h2Hv", "2hHv", |
|
|
195 | "1hHvV", "1vVH2h", "1hvV2H", "1vV2hH", |
|
|
196 | |
|
|
197 | // 2540 |
|
|
198 | "1hHV2v", "1hHv2V", "1hH2vV", "1HV2hv", |
|
|
199 | "1hV2Hv", "1Hv2hV", "1hv2HV", "1V2hHv", |
|
|
200 | "1v2hHV", "1H2hvV", "1h2HvV", "2hHvV", |
|
|
201 | 0, 0, 0, 0, |
|
|
202 | |
|
|
203 | // 2550 |
|
|
204 | 0, 0, 0, 0, |
|
|
205 | 0, 0, 0, 0, |
|
|
206 | 0, 0, 0, 0, |
|
|
207 | 0, 0, 0, 0, |
|
|
208 | |
|
|
209 | // 2560 |
|
|
210 | 0, 0, 0, 0, |
|
|
211 | 0, 0, 0, 0, |
|
|
212 | 0, 0, 0, 0, |
|
|
213 | 0, 0, 0, 0, |
|
|
214 | |
|
|
215 | // 2570 |
|
|
216 | 0, "1a", "1b", "1ab", |
|
|
217 | "1h", "1v", "1H", "1V", |
|
|
218 | "2h", "2v", "2H", "2V", |
|
|
219 | "1h2H", "1v2V", "1H2h", "1V2v" |
|
|
220 | |
|
|
221 | // to be done |
|
|
222 | }; |
172 | |
223 | |
173 | struct rxvt_font_default : rxvt_font { |
224 | struct rxvt_font_default : rxvt_font { |
174 | bool load (int maxheight) |
225 | bool load (int maxheight) |
175 | { |
226 | { |
176 | width = 1; height = 1; |
227 | width = 1; height = 1; |
… | |
… | |
179 | return true; |
230 | return true; |
180 | } |
231 | } |
181 | |
232 | |
182 | bool has_codepoint (uint32_t unicode) |
233 | bool has_codepoint (uint32_t unicode) |
183 | { |
234 | { |
184 | if (unicode <= 0x001f |
235 | if (unicode <= 0x001f) |
|
|
236 | return true; |
185 | || (unicode >= 0x80 && unicode <= 0x9f)) |
237 | if (unicode >= 0x0080 && unicode <= 0x009f) |
|
|
238 | return true; |
|
|
239 | |
|
|
240 | if (unicode >= 0x2500 && unicode <= 0x257f |
|
|
241 | && linedraw_cmds[unicode - 0x2500]) |
186 | return true; |
242 | return true; |
187 | |
243 | |
188 | switch (unicode) |
244 | switch (unicode) |
189 | { |
245 | { |
190 | case ZERO_WIDTH_CHAR: |
246 | case ZERO_WIDTH_CHAR: |
… | |
… | |
202 | void |
258 | void |
203 | rxvt_font_default::draw (int x, int y, |
259 | rxvt_font_default::draw (int x, int y, |
204 | const text_t *text, int len, |
260 | const text_t *text, int len, |
205 | int fg, int bg) |
261 | int fg, int bg) |
206 | { |
262 | { |
207 | clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); |
263 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
|
|
264 | |
|
|
265 | XSetForeground (DISPLAY, GC, r->PixColors[fg]); |
208 | |
266 | |
209 | while (len--) |
267 | while (len--) |
210 | { |
268 | { |
|
|
269 | text_t t = *text++; |
|
|
270 | |
|
|
271 | if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) |
|
|
272 | { |
|
|
273 | const char *p = linedraw_cmds[t - 0x2500]; |
|
|
274 | |
|
|
275 | int x0 = x, x1 = x + (r->TermWin.fwidth - 1) / 2, x2 = x + r->TermWin.fwidth - 1; |
|
|
276 | int y0 = y, y1 = y + (r->TermWin.fheight - 1) / 2, y2 = y + r->TermWin.fheight - 1; |
|
|
277 | |
|
|
278 | XGCValues gcv; |
|
|
279 | |
|
|
280 | gcv.cap_style = CapButt; |
|
|
281 | XChangeGC (DISPLAY, GC, GCCapStyle, &gcv); |
|
|
282 | |
|
|
283 | while (*p) |
|
|
284 | { |
|
|
285 | switch (*p++) |
|
|
286 | { |
|
|
287 | case '1': |
|
|
288 | gcv.line_width = 0; |
|
|
289 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
290 | break; |
|
|
291 | |
|
|
292 | case '2': |
|
|
293 | gcv.line_width = 2; |
|
|
294 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
295 | break; |
|
|
296 | |
|
|
297 | case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break; |
|
|
298 | case 'H': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x2, y1); break; |
|
|
299 | case 'v': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y0, x1, y1); break; |
|
|
300 | case 'V': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x1, y2); break; |
|
|
301 | case 'a': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y2, x2, y0); break; |
|
|
302 | case 'b': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y0, x2, y2); break; |
|
|
303 | } |
|
|
304 | } |
|
|
305 | |
|
|
306 | gcv.line_width = 0; |
|
|
307 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
308 | } |
|
|
309 | else |
211 | switch (*text++) |
310 | switch (*text++) |
212 | { |
311 | { |
213 | case NOCHAR: |
312 | case NOCHAR: |
214 | case ZERO_WIDTH_CHAR: |
313 | case ZERO_WIDTH_CHAR: |
215 | break; |
314 | break; |
216 | default: |
315 | default: |
217 | XSetForeground (DISPLAY, GC, R->PixColors[fg]); |
|
|
218 | XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, R->TermWin.fwidth - 5, R->TermWin.fheight - 5); |
316 | XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
219 | } |
317 | } |
220 | |
318 | |
221 | x += R->TermWin.fwidth; |
319 | x += r->TermWin.fwidth; |
222 | } |
320 | } |
223 | } |
321 | } |
224 | |
322 | |
225 | ///////////////////////////////////////////////////////////////////////////// |
323 | ///////////////////////////////////////////////////////////////////////////// |
226 | |
324 | |
… | |
… | |
404 | // and it is a mess /. |
502 | // and it is a mess /. |
405 | // yet we are trying to be perfect /. |
503 | // yet we are trying to be perfect /. |
406 | // but the result still isn't perfect /. |
504 | // but the result still isn't perfect /. |
407 | |
505 | |
408 | bool slow = prop |
506 | bool slow = prop |
409 | || width != R->TermWin.fwidth |
507 | || width != r->TermWin.fwidth |
410 | || height != R->TermWin.fheight; |
508 | || height != r->TermWin.fheight; |
411 | |
509 | |
412 | int base = R->TermWin.fbase; |
510 | int base = r->TermWin.fbase; |
413 | |
511 | |
414 | XGCValues v; |
512 | XGCValues v; |
415 | v.foreground = R->PixColors[fg]; |
513 | v.foreground = r->PixColors[fg]; |
416 | v.background = R->PixColors[bg]; |
514 | v.background = r->PixColors[bg]; |
417 | v.font = f->fid; |
515 | v.font = f->fid; |
418 | |
516 | |
419 | if (enc2b) |
517 | if (enc2b) |
420 | { |
518 | { |
421 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
519 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
… | |
… | |
425 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
523 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
426 | XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
524 | XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
427 | } |
525 | } |
428 | else |
526 | else |
429 | { |
527 | { |
430 | clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); |
528 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
431 | |
529 | |
432 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
530 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
433 | |
531 | |
434 | if (slow) |
532 | if (slow) |
435 | { |
533 | { |
436 | do |
534 | do |
437 | { |
535 | { |
438 | if (xc->byte1 || xc->byte2) |
536 | if (xc->byte1 || xc->byte2) |
439 | XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
537 | XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
440 | |
538 | |
441 | x += R->TermWin.fwidth; |
539 | x += r->TermWin.fwidth; |
442 | xc++; len--; |
540 | xc++; len--; |
443 | } |
541 | } |
444 | while (len); |
542 | while (len); |
445 | } |
543 | } |
446 | else |
544 | else |
… | |
… | |
456 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
554 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
457 | XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
555 | XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
458 | } |
556 | } |
459 | else |
557 | else |
460 | { |
558 | { |
461 | clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); |
559 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
462 | |
560 | |
463 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
561 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
464 | |
562 | |
465 | if (slow) |
563 | if (slow) |
466 | { |
564 | { |
467 | do |
565 | do |
468 | { |
566 | { |
469 | if (*xc) |
567 | if (*xc) |
470 | XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
568 | XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
471 | |
569 | |
472 | x += R->TermWin.fwidth; |
570 | x += r->TermWin.fwidth; |
473 | xc++; len--; |
571 | xc++; len--; |
474 | } |
572 | } |
475 | while (len); |
573 | while (len); |
476 | } |
574 | } |
477 | else |
575 | else |
… | |
… | |
544 | void |
642 | void |
545 | rxvt_font_xft::clear () |
643 | rxvt_font_xft::clear () |
546 | { |
644 | { |
547 | if (f) |
645 | if (f) |
548 | { |
646 | { |
549 | XftFontClose (R->Xdisplay, f); |
647 | XftFontClose (DISPLAY, f); |
550 | f = 0; |
648 | f = 0; |
551 | } |
649 | } |
552 | |
650 | |
553 | if (d) |
651 | if (d) |
554 | { |
652 | { |
… | |
… | |
570 | cvr[i] = 0; |
668 | cvr[i] = 0; |
571 | #endif |
669 | #endif |
572 | |
670 | |
573 | clear (); |
671 | clear (); |
574 | |
672 | |
575 | f = XftFontOpenName (R->Xdisplay, DefaultScreen (R->Xdisplay), name); |
673 | f = XftFontOpenName (DISPLAY, DefaultScreen (DISPLAY), name); |
576 | |
674 | |
577 | if (!f) |
675 | if (!f) |
578 | return false; |
676 | return false; |
579 | |
677 | |
580 | FT_Face face = XftLockFace (f); |
678 | FT_Face face = XftLockFace (f); |
… | |
… | |
586 | for (;;) |
684 | for (;;) |
587 | { |
685 | { |
588 | XGlyphInfo g1, g2; |
686 | XGlyphInfo g1, g2; |
589 | FcChar8 c; |
687 | FcChar8 c; |
590 | |
688 | |
591 | c = 'i'; XftTextExtents8 (R->Xdisplay, f, &c, 1, &g1); |
689 | c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); |
592 | c = 'W'; XftTextExtents8 (R->Xdisplay, f, &c, 1, &g2); |
690 | c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); |
593 | |
691 | |
594 | prop = prop || g1.xOff != g2.xOff; // don't simply trust the font |
692 | prop = prop || g1.xOff != g2.xOff; // don't simply trust the font |
595 | |
693 | |
596 | width = g2.xOff; |
694 | width = g2.xOff; |
597 | ascent = (face->size->metrics.ascender + 63) >> 6; |
695 | ascent = (face->size->metrics.ascender + 63) >> 6; |
… | |
… | |
632 | #endif |
730 | #endif |
633 | |
731 | |
634 | bool |
732 | bool |
635 | rxvt_font_xft::has_codepoint (uint32_t unicode) |
733 | rxvt_font_xft::has_codepoint (uint32_t unicode) |
636 | { |
734 | { |
637 | return XftCharExists (R->Xdisplay, f, unicode); |
735 | return XftCharExists (DISPLAY, f, unicode); |
638 | } |
736 | } |
639 | |
737 | |
640 | void |
738 | void |
641 | rxvt_font_xft::draw (int x, int y, |
739 | rxvt_font_xft::draw (int x, int y, |
642 | const text_t *text, int len, |
740 | const text_t *text, int len, |
643 | int fg, int bg) |
741 | int fg, int bg) |
644 | { |
742 | { |
645 | if (!d) |
743 | if (!d) |
|
|
744 | { |
|
|
745 | dR; |
646 | d = XftDrawCreate (R->Xdisplay, DRAWABLE, XVISUAL, XCMAP); |
746 | d = XftDrawCreate (DISPLAY, DRAWABLE, XVISUAL, XCMAP); |
|
|
747 | } |
647 | |
748 | |
648 | if (bg >= 0 && bg != Color_bg) |
749 | if (bg >= 0 && bg != Color_bg) |
649 | XftDrawRect (d, &R->PixColors[bg].c, x, y, R->TermWin.fwidth * len, R->TermWin.fheight); |
750 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
650 | else |
751 | else |
651 | clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); |
752 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
652 | |
753 | |
653 | if (!prop && width == R->TermWin.fwidth) |
754 | if (!prop && width == r->TermWin.fwidth) |
654 | { |
755 | { |
655 | if (sizeof (text_t) == sizeof (FcChar16)) |
756 | if (sizeof (text_t) == sizeof (FcChar16)) |
656 | XftDrawString16 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar16 *)text, len); |
757 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
657 | else |
758 | else |
658 | XftDrawString32 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar32 *)text, len); |
759 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
659 | } |
760 | } |
660 | else |
761 | else |
661 | { |
762 | { |
662 | while (len) |
763 | while (len) |
663 | { |
764 | { |
664 | if (*text != NOCHAR && *text != ' ') |
765 | if (*text != NOCHAR && *text != ' ') |
665 | { |
766 | { |
666 | if (sizeof (text_t) == sizeof (FcChar16)) |
767 | if (sizeof (text_t) == sizeof (FcChar16)) |
667 | XftDrawString16 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar16 *)text, 1); |
768 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
668 | else |
769 | else |
669 | XftDrawString32 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar32 *)text, 1); |
770 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
670 | } |
771 | } |
671 | |
772 | |
672 | x += R->TermWin.fwidth; |
773 | x += r->TermWin.fwidth; |
673 | text++; |
774 | text++; |
674 | len--; |
775 | len--; |
675 | } |
776 | } |
676 | } |
777 | } |
677 | } |
778 | } |
678 | #endif |
779 | #endif |
679 | |
780 | |
680 | ///////////////////////////////////////////////////////////////////////////// |
781 | ///////////////////////////////////////////////////////////////////////////// |
681 | |
782 | |
682 | rxvt_fontset::rxvt_fontset (pR) |
783 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
683 | #ifdef EXPLICIT_CONTEXT |
784 | #ifdef EXPLICIT_CONTEXT |
684 | : rxvt_term(R) |
785 | : r(r) |
685 | #endif |
786 | #endif |
686 | { |
787 | { |
687 | clear (); |
788 | clear (); |
688 | } |
789 | } |
689 | |
790 | |
… | |
… | |
728 | f = new rxvt_font_x11; |
829 | f = new rxvt_font_x11; |
729 | } |
830 | } |
730 | else |
831 | else |
731 | f = new rxvt_font_x11; |
832 | f = new rxvt_font_x11; |
732 | |
833 | |
733 | f->set_term (aR); |
834 | f->set_term (r); |
734 | f->set_name (strdup (name)); |
835 | f->set_name (strdup (name)); |
735 | |
836 | |
736 | f->cs = cs; |
837 | f->cs = cs; |
737 | f->loaded = false; |
838 | f->loaded = false; |
738 | |
839 | |