… | |
… | |
230 | bool has_codepoint (unicode_t unicode) |
230 | bool has_codepoint (unicode_t unicode) |
231 | { |
231 | { |
232 | if (unicode <= 0x001f) |
232 | if (unicode <= 0x001f) |
233 | return true; |
233 | return true; |
234 | |
234 | |
235 | if (unicode >= 0x0080 && unicode <= 0x009f) |
235 | if (unicode <= 0x007f) |
|
|
236 | return false; |
|
|
237 | |
|
|
238 | if (unicode <= 0x009f) |
236 | return true; |
239 | return true; |
237 | |
240 | |
238 | if (unicode >= 0x2500 && unicode <= 0x259f |
241 | if (unicode >= 0x2500 && unicode <= 0x259f) |
239 | && linedraw_offs[unicode - 0x2500] & 15) |
|
|
240 | return true; |
242 | return true; |
241 | |
243 | |
242 | if (IS_COMPOSE (unicode)) |
244 | if (IS_COMPOSE (unicode)) |
243 | return true; |
245 | return true; |
244 | |
246 | |
… | |
… | |
259 | void |
261 | void |
260 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
262 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
261 | const text_t *text, int len, |
263 | const text_t *text, int len, |
262 | int fg, int bg) |
264 | int fg, int bg) |
263 | { |
265 | { |
264 | return; |
|
|
265 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
266 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
266 | |
267 | |
267 | XSetForeground (d.display->display, TGC, r->PixColors[fg]); |
268 | XSetForeground (d.display->display, TGC, r->PixColors[fg]); |
268 | |
269 | |
269 | while (len--) |
270 | while (len--) |
… | |
… | |
271 | #if ENABLE_COMBINING |
272 | #if ENABLE_COMBINING |
272 | compose_char *cc; |
273 | compose_char *cc; |
273 | #endif |
274 | #endif |
274 | text_t t = *text++; |
275 | text_t t = *text++; |
275 | |
276 | |
276 | int W = r->TermWin.fwidth , w = (W - 1) / 2; |
|
|
277 | int H = r->TermWin.fheight, h = (H - 1) / 2; |
|
|
278 | int x0 = x, x1 = x + w, x2 = x + r->TermWin.fwidth ; |
|
|
279 | int y0 = y, y1 = y + h, y2 = y + r->TermWin.fheight; |
|
|
280 | |
|
|
281 | if (0x2500 <= t && t <= 0x259f |
277 | if (0x2500 <= t && t <= 0x259f) |
282 | && linedraw_offs[t - 0x2500] & 15) |
|
|
283 | { |
278 | { |
284 | uint16_t offs = linedraw_offs[t - 0x2500]; |
279 | uint16_t offs = linedraw_offs[t - 0x2500]; |
285 | uint32_t *a = linedraw_command + (offs >> 4); |
280 | uint32_t *a = linedraw_command + (offs >> 4); |
286 | uint32_t *b = a + (offs & 15); |
281 | uint32_t *b = a + (offs & 15); |
|
|
282 | |
|
|
283 | int W = r->TermWin.fwidth; |
|
|
284 | int H = r->TermWin.fheight; |
287 | |
285 | |
288 | int x_[16]; |
286 | int x_[16]; |
289 | int y_[16]; |
287 | int y_[16]; |
290 | |
288 | |
291 | for (int i = 0; i <= 8; i++) |
289 | for (int i = 0; i <= 8; i++) |
… | |
… | |
334 | XChangeGC (d.display->display, TGC, |
332 | XChangeGC (d.display->display, TGC, |
335 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
333 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
336 | &gcv); |
334 | &gcv); |
337 | } |
335 | } |
338 | |
336 | |
339 | |
|
|
340 | XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
337 | XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
341 | |
338 | |
342 | if (a) |
339 | if (a) |
343 | { |
340 | { |
344 | XFreePixmap (d.display->display, gcv.stipple); |
341 | XFreePixmap (d.display->display, gcv.stipple); |
345 | gcv.stipple = 0; |
342 | gcv.stipple = 0; |
346 | gcv.fill_style = FillSolid; |
343 | gcv.fill_style = FillSolid; |
347 | XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); |
344 | XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); |
348 | } |
345 | } |
349 | |
|
|
350 | break; |
346 | break; |
351 | case 2: // arc |
347 | case 2: // arc |
352 | XDrawArc (d.display->display, d, TGC, |
348 | XDrawArc (d.display->display, d, TGC, |
353 | x1 - W/2, y1 - H/2, W-1, H-1, |
349 | x1 - W/2, y1 - H/2, W-1, H-1, |
354 | (a - 1) * 90*64, (b - 1) * 90*64); |
350 | (a - 1) * 90*64, (b - 1) * 90*64); |
… | |
… | |
415 | |
411 | |
416 | XFontStruct *f; |
412 | XFontStruct *f; |
417 | codeset cs; |
413 | codeset cs; |
418 | bool enc2b, encm; |
414 | bool enc2b, encm; |
419 | |
415 | |
420 | const char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
416 | char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
421 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
417 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
422 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
418 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
423 | bool set_properties (rxvt_fontprop &p, const char *name); |
419 | bool set_properties (rxvt_fontprop &p, const char *name); |
424 | }; |
420 | }; |
425 | |
421 | |
426 | const char * |
422 | char * |
427 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
423 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
428 | { |
424 | { |
429 | unsigned long value; |
425 | unsigned long value; |
430 | |
426 | |
431 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
427 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
432 | return XGetAtomName (DISPLAY, value); |
428 | return XGetAtomName (DISPLAY, value); |
433 | else |
429 | else |
434 | return repl; |
430 | return rxvt_strdup (repl); |
435 | } |
431 | } |
436 | |
432 | |
437 | rxvt_fontprop |
433 | rxvt_fontprop |
438 | rxvt_font_x11::properties () |
434 | rxvt_font_x11::properties () |
439 | { |
435 | { |
… | |
… | |
454 | } |
450 | } |
455 | |
451 | |
456 | bool |
452 | bool |
457 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
453 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
458 | { |
454 | { |
459 | const char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
|
|
460 | const char *slant = get_property (f, "SLANT", "r"); |
|
|
461 | |
|
|
462 | unsigned long height; |
455 | unsigned long height; |
463 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
456 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
464 | return false; |
457 | return false; |
465 | |
458 | |
466 | unsigned long avgwidth; |
459 | unsigned long avgwidth; |
467 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
460 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
468 | avgwidth = 0; |
461 | avgwidth = 0; |
469 | |
462 | |
|
|
463 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
|
|
464 | char *slant = get_property (f, "SLANT", "r"); |
|
|
465 | |
470 | return set_properties (p, height, weight, slant, avgwidth); |
466 | set_properties (p, height, weight, slant, avgwidth); |
|
|
467 | |
|
|
468 | free (weight); |
|
|
469 | free (slant); |
|
|
470 | |
|
|
471 | return true; |
471 | } |
472 | } |
472 | |
473 | |
473 | bool |
474 | bool |
474 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
475 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
475 | { |
476 | { |
… | |
… | |
579 | f = XLoadQueryFont (DISPLAY, name); |
580 | f = XLoadQueryFont (DISPLAY, name); |
580 | |
581 | |
581 | if (!f) |
582 | if (!f) |
582 | return false; |
583 | return false; |
583 | |
584 | |
584 | const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
585 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
585 | const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
586 | char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
586 | |
587 | |
587 | if (registry && encoding) |
588 | if (registry && encoding) |
588 | { |
589 | { |
589 | char charset[64]; |
590 | char charset[64]; |
590 | snprintf (charset, 64, "%s-%s", registry, encoding); |
591 | snprintf (charset, 64, "%s-%s", registry, encoding); |
… | |
… | |
603 | if (*charset++ == '-' && !--count) |
604 | if (*charset++ == '-' && !--count) |
604 | break; |
605 | break; |
605 | |
606 | |
606 | cs = codeset_from_name (charset); |
607 | cs = codeset_from_name (charset); |
607 | } |
608 | } |
|
|
609 | |
|
|
610 | free (registry); |
|
|
611 | free (encoding); |
608 | |
612 | |
609 | if (cs == CS_UNICODE) |
613 | if (cs == CS_UNICODE) |
610 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
614 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
611 | |
615 | |
612 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
616 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
… | |
… | |
725 | |
729 | |
726 | int base = r->TermWin.fbase; |
730 | int base = r->TermWin.fbase; |
727 | |
731 | |
728 | XGCValues v; |
732 | XGCValues v; |
729 | v.foreground = r->PixColors[fg]; |
733 | v.foreground = r->PixColors[fg]; |
730 | v.background = r->PixColors[bg]; |
|
|
731 | v.font = f->fid; |
734 | v.font = f->fid; |
732 | |
735 | |
733 | if (enc2b) |
736 | if (enc2b) |
734 | { |
737 | { |
735 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
738 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
736 | |
739 | |
737 | if (bg == Color_bg && !slow) |
740 | if (bg == Color_bg && !slow) |
738 | { |
741 | { |
|
|
742 | v.background = r->PixColors[bg]; |
739 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
743 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
740 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
744 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
741 | } |
745 | } |
742 | else |
746 | else |
743 | { |
747 | { |
… | |
… | |
765 | { |
769 | { |
766 | const char *xc = enc_char (text, len, cs, slow); |
770 | const char *xc = enc_char (text, len, cs, slow); |
767 | |
771 | |
768 | if (bg == Color_bg && !slow) |
772 | if (bg == Color_bg && !slow) |
769 | { |
773 | { |
|
|
774 | v.background = r->PixColors[bg]; |
770 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
775 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
771 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
776 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
772 | } |
777 | } |
773 | else |
778 | else |
774 | { |
779 | { |
… | |
… | |
993 | #endif |
998 | #endif |
994 | |
999 | |
995 | ///////////////////////////////////////////////////////////////////////////// |
1000 | ///////////////////////////////////////////////////////////////////////////// |
996 | |
1001 | |
997 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1002 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
998 | : r (r) |
1003 | : r (r), fontdesc (0) |
999 | { |
1004 | { |
1000 | clear (); |
1005 | clear (); |
1001 | } |
1006 | } |
1002 | |
1007 | |
1003 | rxvt_fontset::~rxvt_fontset () |
1008 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1008 | void |
1013 | void |
1009 | rxvt_fontset::clear () |
1014 | rxvt_fontset::clear () |
1010 | { |
1015 | { |
1011 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1016 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1012 | FONT_UNREF (*i); |
1017 | FONT_UNREF (*i); |
|
|
1018 | |
|
|
1019 | free (fontdesc); fontdesc = 0; |
1013 | |
1020 | |
1014 | fonts.clear (); |
1021 | fonts.clear (); |
1015 | base_id = 0; |
1022 | base_id = 0; |
1016 | base_prop.height = 0x7fffffff; |
1023 | base_prop.height = 0x7fffffff; |
1017 | base_prop.weight = rxvt_fontprop::medium; |
1024 | base_prop.weight = rxvt_fontprop::medium; |
… | |
… | |
1125 | bool |
1132 | bool |
1126 | rxvt_fontset::populate (const char *desc) |
1133 | rxvt_fontset::populate (const char *desc) |
1127 | { |
1134 | { |
1128 | clear (); |
1135 | clear (); |
1129 | |
1136 | |
|
|
1137 | fontdesc = strdup (desc); |
|
|
1138 | |
1130 | fonts.push_back (new_font (0, CS_UNICODE)); |
1139 | fonts.push_back (new_font (0, CS_UNICODE)); |
1131 | realize_font (0); |
1140 | realize_font (0); |
1132 | |
1141 | |
1133 | add_fonts (desc); |
1142 | add_fonts (desc); |
1134 | |
1143 | |
… | |
… | |
1152 | } |
1161 | } |
1153 | |
1162 | |
1154 | int |
1163 | int |
1155 | rxvt_fontset::find_font (unicode_t unicode) |
1164 | rxvt_fontset::find_font (unicode_t unicode) |
1156 | { |
1165 | { |
1157 | for (unsigned int i = 0; i < fonts.size (); i++) |
1166 | for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii |
|
|
1167 | i < fonts.size (); |
|
|
1168 | i++) |
1158 | { |
1169 | { |
1159 | rxvt_font *f = fonts[i]; |
1170 | rxvt_font *f = fonts[i]; |
1160 | |
1171 | |
1161 | if (!f->loaded) |
1172 | if (!f->loaded) |
1162 | { |
1173 | { |