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 |
… | |
… | |
26 | #include "rxvtfont.h" |
26 | #include "rxvtfont.h" |
27 | |
27 | |
28 | #include <cstdlib> |
28 | #include <cstdlib> |
29 | #include <wchar.h> |
29 | #include <wchar.h> |
30 | #include <inttypes.h> |
30 | #include <inttypes.h> |
31 | |
|
|
32 | #define DISPLAY r->display->display |
|
|
33 | #define TGC r->gc |
|
|
34 | |
31 | |
35 | #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 |
36 | |
33 | |
37 | const struct rxvt_fallback_font { |
34 | const struct rxvt_fallback_font { |
38 | codeset cs; |
35 | codeset cs; |
… | |
… | |
153 | 0x304c, 0x672c, // が本 |
150 | 0x304c, 0x672c, // が本 |
154 | }; |
151 | }; |
155 | |
152 | |
156 | #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])) |
157 | |
154 | |
|
|
155 | #define dTermDisplay Display *disp = term->display->display |
|
|
156 | #define dTermGC GC gc = term->gc |
|
|
157 | |
158 | ///////////////////////////////////////////////////////////////////////////// |
158 | ///////////////////////////////////////////////////////////////////////////// |
159 | |
159 | |
160 | #if XFT |
160 | #if XFT |
161 | rxvt_drawable::~rxvt_drawable () |
161 | rxvt_drawable::~rxvt_drawable () |
162 | { |
162 | { |
… | |
… | |
173 | } |
173 | } |
174 | #endif |
174 | #endif |
175 | |
175 | |
176 | ///////////////////////////////////////////////////////////////////////////// |
176 | ///////////////////////////////////////////////////////////////////////////// |
177 | |
177 | |
178 | static void *enc_buf; |
|
|
179 | static uint32_t enc_len; |
|
|
180 | |
|
|
181 | static inline void * |
|
|
182 | get_enc_buf (uint32_t len) |
|
|
183 | { |
|
|
184 | if (len > enc_len) |
|
|
185 | { |
|
|
186 | free (enc_buf); |
|
|
187 | enc_buf = malloc (len); |
|
|
188 | enc_len = len; |
|
|
189 | } |
|
|
190 | |
|
|
191 | return enc_buf; |
|
|
192 | } |
|
|
193 | |
|
|
194 | static const char * |
178 | static const char * |
195 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
179 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
196 | { |
180 | { |
197 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
181 | uint8_t *buf = rxvt_temp_buf<uint8_t> (len); |
|
|
182 | uint8_t *res = buf; |
198 | |
183 | |
199 | while (len--) |
184 | while (len--) |
200 | { |
185 | { |
201 | uint32_t c = FROM_UNICODE (cs, *text++); |
186 | uint32_t c = FROM_UNICODE (cs, *text++); |
202 | |
187 | |
… | |
… | |
207 | } |
192 | } |
208 | |
193 | |
209 | *buf++ = c; |
194 | *buf++ = c; |
210 | } |
195 | } |
211 | |
196 | |
212 | return (const char *)enc_buf; |
197 | return (const char *)res; |
213 | } |
198 | } |
214 | |
199 | |
215 | static const XChar2b * |
200 | static const XChar2b * |
216 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
201 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
217 | { |
202 | { |
218 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
203 | XChar2b *buf = rxvt_temp_buf<XChar2b> (len); |
|
|
204 | XChar2b *res = buf; |
219 | |
205 | |
220 | while (len--) |
206 | while (len--) |
221 | { |
207 | { |
222 | uint32_t c = FROM_UNICODE (cs, *text++); |
208 | uint32_t c = FROM_UNICODE (cs, *text++); |
223 | |
209 | |
… | |
… | |
230 | buf->byte1 = c >> 8; |
216 | buf->byte1 = c >> 8; |
231 | buf->byte2 = c; |
217 | buf->byte2 = c; |
232 | buf++; |
218 | buf++; |
233 | } |
219 | } |
234 | |
220 | |
235 | return (XChar2b *)enc_buf; |
221 | return res; |
236 | } |
222 | } |
237 | |
223 | |
238 | ///////////////////////////////////////////////////////////////////////////// |
224 | ///////////////////////////////////////////////////////////////////////////// |
239 | |
225 | |
240 | void |
226 | void |
… | |
… | |
246 | if (this->name) free (this->name); // let the compiler optimize |
232 | if (this->name) free (this->name); // let the compiler optimize |
247 | this->name = name; |
233 | this->name = name; |
248 | } |
234 | } |
249 | |
235 | |
250 | void |
236 | void |
251 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) |
237 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
252 | { |
238 | { |
|
|
239 | dTermDisplay; |
|
|
240 | dTermGC; |
|
|
241 | |
253 | if (color == Color_bg) |
242 | if (color == Color_bg) |
254 | XClearArea (d.display->display, d, x, y, w, h, FALSE); |
243 | XClearArea (disp, d, x, y, w, h, FALSE); |
255 | else if (color >= 0) |
244 | else if (color >= 0) |
256 | { |
245 | { |
257 | #if XFT |
246 | #if XFT |
258 | XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); |
247 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
259 | #else |
248 | #else |
260 | XSetForeground (d.display->display, TGC, r->pix_colors[color]); |
249 | XSetForeground (disp, gc, term->pix_colors[color]); |
261 | XFillRectangle (d.display->display, d, TGC, x, y, w, h); |
250 | XFillRectangle (disp, d, gc, x, y, w, h); |
262 | #endif |
251 | #endif |
263 | } |
252 | } |
264 | } |
253 | } |
265 | |
254 | |
266 | #include "table/linedraw.h" |
255 | #include "table/linedraw.h" |
… | |
… | |
294 | set_name (strdup ("built-in support font")); |
283 | set_name (strdup ("built-in support font")); |
295 | |
284 | |
296 | return true; |
285 | return true; |
297 | } |
286 | } |
298 | |
287 | |
299 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) |
288 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
300 | { |
289 | { |
301 | careful = false; |
290 | careful = false; |
302 | |
291 | |
303 | if (unicode <= 0x001f) |
292 | if (unicode <= 0x001f) |
304 | return true; |
293 | return true; |
… | |
… | |
308 | |
297 | |
309 | if (unicode <= 0x009f) |
298 | if (unicode <= 0x009f) |
310 | return true; |
299 | return true; |
311 | |
300 | |
312 | if (unicode >= 0x2500 && unicode <= 0x259f && |
301 | if (unicode >= 0x2500 && unicode <= 0x259f && |
313 | ! OPTION_R (Opt_skipBuiltinGlyphs)) |
302 | !term->option (Opt_skipBuiltinGlyphs)) |
314 | return true; |
303 | return true; |
315 | |
304 | |
316 | if (IS_COMPOSE (unicode)) |
305 | if (IS_COMPOSE (unicode)) |
317 | return true; |
306 | return true; |
318 | |
307 | |
… | |
… | |
334 | void |
323 | void |
335 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
324 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
336 | const text_t *text, int len, |
325 | const text_t *text, int len, |
337 | int fg, int bg) |
326 | int fg, int bg) |
338 | { |
327 | { |
339 | Display *disp = d.display->display; |
328 | dTermDisplay; |
|
|
329 | dTermGC; |
340 | |
330 | |
341 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
331 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
342 | |
332 | |
343 | XSetForeground (disp, TGC, r->pix_colors[fg]); |
333 | XSetForeground (disp, gc, term->pix_colors[fg]); |
344 | |
334 | |
345 | while (len) |
335 | while (len) |
346 | { |
336 | { |
347 | #if ENABLE_COMBINING |
337 | #if ENABLE_COMBINING |
348 | compose_char *cc; |
338 | compose_char *cc; |
… | |
… | |
352 | |
342 | |
353 | while (++text, --len && *text == NOCHAR) |
343 | while (++text, --len && *text == NOCHAR) |
354 | ; |
344 | ; |
355 | |
345 | |
356 | int width = text - tp; |
346 | int width = text - tp; |
357 | int fwidth = r->fwidth * width; |
347 | int fwidth = term->fwidth * width; |
358 | |
348 | |
359 | if (0x2500 <= t && t <= 0x259f && |
349 | if (0x2500 <= t && t <= 0x259f) |
360 | ! OPTION_R (Opt_skipBuiltinGlyphs)) |
|
|
361 | { |
350 | { |
362 | uint16_t offs = linedraw_offs[t - 0x2500]; |
351 | uint16_t offs = linedraw_offs[t - 0x2500]; |
363 | uint32_t *a = linedraw_command + (offs >> 4); |
352 | uint32_t *a = linedraw_command + (offs >> 4); |
364 | uint32_t *b = a + (offs & 15); |
353 | uint32_t *b = a + (offs & 15); |
365 | |
354 | |
366 | int W = fwidth; |
355 | int W = fwidth; |
367 | int H = r->fheight; |
356 | int H = term->fheight; |
368 | |
357 | |
369 | int x_[16]; |
358 | int x_[16]; |
370 | int y_[16]; |
359 | int y_[16]; |
371 | |
360 | |
372 | for (int i = 0; i <= 8; i++) |
361 | for (int i = 0; i <= 8; i++) |
… | |
… | |
380 | |
369 | |
381 | XGCValues gcv; |
370 | XGCValues gcv; |
382 | |
371 | |
383 | gcv.cap_style = CapButt; |
372 | gcv.cap_style = CapButt; |
384 | gcv.line_width = 0; |
373 | gcv.line_width = 0; |
385 | XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv); |
374 | XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv); |
386 | |
375 | |
387 | while (a < b) |
376 | while (a < b) |
388 | { |
377 | { |
389 | uint32_t command = *a++; |
378 | uint32_t command = *a++; |
390 | |
379 | |
… | |
… | |
397 | int y2 = y_[(command >> 0) & 15]; |
386 | int y2 = y_[(command >> 0) & 15]; |
398 | |
387 | |
399 | switch (op) |
388 | switch (op) |
400 | { |
389 | { |
401 | case 0: // line |
390 | case 0: // line |
402 | XDrawLine (disp, d, TGC, x1, y1, x2, y2); |
391 | XDrawLine (disp, d, gc, x1, y1, x2, y2); |
403 | break; |
392 | break; |
404 | |
393 | |
405 | case 1: // rectangle, possibly stippled |
394 | case 1: // rectangle, possibly stippled |
406 | if (a) |
395 | if (a) |
407 | { |
396 | { |
… | |
… | |
410 | gcv.fill_style = FillStippled; |
399 | gcv.fill_style = FillStippled; |
411 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
400 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
412 | gcv.ts_x_origin = x; |
401 | gcv.ts_x_origin = x; |
413 | gcv.ts_y_origin = y; |
402 | gcv.ts_y_origin = y; |
414 | |
403 | |
415 | XChangeGC (disp, TGC, |
404 | XChangeGC (disp, gc, |
416 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
405 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
417 | &gcv); |
406 | &gcv); |
418 | } |
407 | } |
419 | |
408 | |
420 | XFillRectangle (disp, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
409 | XFillRectangle (disp, d, gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
421 | |
410 | |
422 | if (a) |
411 | if (a) |
423 | { |
412 | { |
424 | XFreePixmap (disp, gcv.stipple); |
413 | XFreePixmap (disp, gcv.stipple); |
425 | gcv.stipple = 0; |
414 | gcv.stipple = 0; |
426 | gcv.fill_style = FillSolid; |
415 | gcv.fill_style = FillSolid; |
427 | XChangeGC (disp, TGC, GCFillStyle, &gcv); |
416 | XChangeGC (disp, gc, GCFillStyle, &gcv); |
428 | } |
417 | } |
429 | break; |
418 | break; |
430 | case 2: // arc |
419 | case 2: // arc |
431 | XDrawArc (disp, d, TGC, |
420 | XDrawArc (disp, d, gc, |
432 | x1 - W/2, y1 - H/2, W-1, H-1, |
421 | x1 - W/2, y1 - H/2, W-1, H-1, |
433 | (a - 1) * 90*64, (b - 1) * 90*64); |
422 | (a - 1) * 90*64, (b - 1) * 90*64); |
434 | break; |
423 | break; |
435 | } |
424 | } |
436 | } |
425 | } |
… | |
… | |
467 | case ZERO_WIDTH_CHAR: |
456 | case ZERO_WIDTH_CHAR: |
468 | case NOCHAR: |
457 | case NOCHAR: |
469 | break; |
458 | break; |
470 | |
459 | |
471 | default: |
460 | default: |
472 | XDrawRectangle (disp, d, TGC, x + 2, y + 2, |
461 | XDrawRectangle (disp, d, gc, x + 2, y + 2, |
473 | fwidth - 4, r->fheight - 4); |
462 | fwidth - 4, term->fheight - 4); |
474 | } |
463 | } |
475 | |
464 | |
476 | x += fwidth; |
465 | x += fwidth; |
477 | } |
466 | } |
478 | } |
467 | } |
… | |
… | |
486 | |
475 | |
487 | rxvt_fontprop properties (); |
476 | rxvt_fontprop properties (); |
488 | |
477 | |
489 | bool load (const rxvt_fontprop &prop); |
478 | bool load (const rxvt_fontprop &prop); |
490 | |
479 | |
491 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful); |
480 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; |
492 | |
481 | |
493 | void draw (rxvt_drawable &d, int x, int y, |
482 | void draw (rxvt_drawable &d, int x, int y, |
494 | const text_t *text, int len, |
483 | const text_t *text, int len, |
495 | int fg, int bg); |
484 | int fg, int bg); |
496 | |
485 | |
… | |
… | |
508 | char * |
497 | char * |
509 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
498 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
510 | { |
499 | { |
511 | unsigned long value; |
500 | unsigned long value; |
512 | |
501 | |
513 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
502 | if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value)) |
514 | return XGetAtomName (DISPLAY, value); |
503 | return XGetAtomName (term->display->display, value); |
515 | else |
504 | else |
516 | return rxvt_strdup (repl); |
505 | return rxvt_strdup (repl); |
517 | } |
506 | } |
518 | |
507 | |
519 | rxvt_fontprop |
508 | rxvt_fontprop |
… | |
… | |
540 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
529 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
541 | { |
530 | { |
542 | unsigned long height; |
531 | unsigned long height; |
543 | |
532 | |
544 | #if 0 |
533 | #if 0 |
545 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
534 | if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height)) |
546 | return false; |
535 | return false; |
547 | #else |
536 | #else |
548 | height = f->ascent + f->descent; |
537 | height = f->ascent + f->descent; |
549 | #endif |
538 | #endif |
550 | |
539 | |
551 | unsigned long avgwidth; |
540 | unsigned long avgwidth; |
552 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
541 | if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth)) |
553 | avgwidth = 0; |
542 | avgwidth = 0; |
554 | |
543 | |
555 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
544 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
556 | char *slant = get_property (f, "SLANT", "r"); |
545 | char *slant = get_property (f, "SLANT", "r"); |
557 | |
546 | |
… | |
… | |
566 | } |
555 | } |
567 | |
556 | |
568 | bool |
557 | bool |
569 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
558 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
570 | { |
559 | { |
|
|
560 | dTermDisplay; |
571 | int slashes = 0; |
561 | int slashes = 0; |
572 | const char *comp[13]; |
562 | const char *comp[13]; |
573 | |
563 | |
574 | for (const char *c = name; *c; c++) |
564 | for (const char *c = name; *c; c++) |
575 | if (*c == '-') |
565 | if (*c == '-') |
… | |
… | |
583 | if (slashes >= 13 |
573 | if (slashes >= 13 |
584 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
574 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
585 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
575 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
586 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
576 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
587 | |
577 | |
588 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
578 | XFontStruct *f = XLoadQueryFont (disp, name); |
589 | |
579 | |
590 | if (f) |
580 | if (f) |
591 | { |
581 | { |
592 | // the font should really exist now. if not, we have a problem |
582 | // the font should really exist now. if not, we have a problem |
593 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
583 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
594 | // in that case, just return garbage. |
584 | // in that case, just return garbage. |
595 | bool ret = set_properties (p, f); |
585 | bool ret = set_properties (p, f); |
596 | XFreeFont (DISPLAY, f); |
586 | XFreeFont (disp, f); |
597 | return ret; |
587 | return ret; |
598 | } |
588 | } |
599 | else |
589 | else |
600 | return false; |
590 | return false; |
601 | } |
591 | } |
… | |
… | |
639 | } |
629 | } |
640 | |
630 | |
641 | bool |
631 | bool |
642 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
632 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
643 | { |
633 | { |
644 | Display *disp = DISPLAY; |
634 | dTermDisplay; |
645 | |
635 | |
646 | clear (); |
636 | clear (); |
647 | |
637 | |
648 | char field_str[64]; // enough for 128 bits |
638 | char field_str[64]; // enough for 128 bits |
649 | |
639 | |
… | |
… | |
724 | int diff = 0; |
714 | int diff = 0; |
725 | |
715 | |
726 | if (replace_field (fname, list[i], 6, '0', field_str)) |
716 | if (replace_field (fname, list[i], 6, '0', field_str)) |
727 | diff += 10; // slightly penalize scalable fonts |
717 | diff += 10; // slightly penalize scalable fonts |
728 | else if (replace_field (fname, list[i], 11, '0', "0")) |
718 | else if (replace_field (fname, list[i], 11, '0', "0")) |
729 | diff += 300; // more heavily penalize what looks like scaled bitmap fotns |
719 | diff += 300; // more heavily penalize what looks like scaled bitmap fonts |
730 | |
720 | |
731 | if (!set_properties (p, fname)) |
721 | if (!set_properties (p, fname)) |
732 | continue; |
722 | continue; |
733 | |
723 | |
734 | if (prop.height != rxvt_fontprop::unset |
724 | if (prop.height != rxvt_fontprop::unset |
… | |
… | |
887 | void |
877 | void |
888 | rxvt_font_x11::clear () |
878 | rxvt_font_x11::clear () |
889 | { |
879 | { |
890 | if (f) |
880 | if (f) |
891 | { |
881 | { |
892 | XFreeFont (DISPLAY, f); |
882 | XFreeFont (term->display->display, f); |
893 | f = 0; |
883 | f = 0; |
894 | } |
884 | } |
895 | } |
885 | } |
896 | |
886 | |
897 | bool |
887 | bool |
898 | rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) |
888 | rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
899 | { |
889 | { |
900 | uint32_t ch = FROM_UNICODE (cs, unicode); |
890 | uint32_t ch = FROM_UNICODE (cs, unicode); |
901 | |
891 | |
902 | if (ch == NOCHAR) |
892 | if (ch == NOCHAR) |
903 | return false; |
893 | return false; |
… | |
… | |
962 | // this looks like a mess /. |
952 | // this looks like a mess /. |
963 | // and it is a mess /. |
953 | // and it is a mess /. |
964 | // yet we are trying to be perfect /. |
954 | // yet we are trying to be perfect /. |
965 | // but the result still isn't perfect /. |
955 | // but the result still isn't perfect /. |
966 | |
956 | |
|
|
957 | dTermDisplay; |
|
|
958 | dTermGC; |
|
|
959 | |
967 | bool slow = this->slow |
960 | bool slow = this->slow |
968 | || width != r->fwidth |
961 | || width != term->fwidth |
969 | || height != r->fheight; |
962 | || height != term->fheight; |
970 | |
963 | |
971 | int base = ascent; // sorry, incorrect: r->fbase; |
964 | int base = ascent; // sorry, incorrect: term->fbase; |
972 | |
965 | |
973 | XGCValues v; |
966 | XGCValues v; |
974 | v.foreground = r->pix_colors[fg]; |
967 | v.foreground = term->pix_colors[fg]; |
975 | v.font = f->fid; |
968 | v.font = f->fid; |
976 | |
969 | |
977 | if (enc2b) |
970 | if (enc2b) |
978 | { |
971 | { |
979 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
972 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
980 | |
973 | |
981 | if (bg == Color_bg && !slow) |
974 | if (bg == Color_bg && !slow) |
982 | { |
975 | { |
983 | v.background = r->pix_colors[bg]; |
976 | v.background = term->pix_colors[bg]; |
984 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
977 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
985 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
978 | XDrawImageString16 (disp, d, gc, x, y + base, xc, len); |
986 | } |
979 | } |
987 | else |
980 | else |
988 | { |
981 | { |
989 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
982 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
990 | |
983 | |
991 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
984 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
992 | |
985 | |
993 | if (slow) |
986 | if (slow) |
994 | { |
987 | { |
995 | do |
988 | do |
996 | { |
989 | { |
997 | if (xc->byte1 || xc->byte2) |
990 | if (xc->byte1 || xc->byte2) |
998 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
991 | XDrawString16 (disp, d, gc, x, y + base, xc, 1); |
999 | |
992 | |
1000 | x += r->fwidth; |
993 | x += term->fwidth; |
1001 | xc++; len--; |
994 | xc++; len--; |
1002 | } |
995 | } |
1003 | while (len); |
996 | while (len); |
1004 | } |
997 | } |
1005 | else |
998 | else |
1006 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); |
999 | XDrawString16 (disp, d, gc, x, y + base, xc, len); |
1007 | } |
1000 | } |
1008 | } |
1001 | } |
1009 | else |
1002 | else |
1010 | { |
1003 | { |
1011 | const char *xc = enc_char (text, len, cs, slow); |
1004 | const char *xc = enc_char (text, len, cs, slow); |
1012 | |
1005 | |
1013 | if (bg == Color_bg && !slow) |
1006 | if (bg == Color_bg && !slow) |
1014 | { |
1007 | { |
1015 | v.background = r->pix_colors[bg]; |
1008 | v.background = term->pix_colors[bg]; |
1016 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1009 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
1017 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1010 | XDrawImageString (disp, d, gc, x, y + base, xc, len); |
1018 | } |
1011 | } |
1019 | else |
1012 | else |
1020 | { |
1013 | { |
1021 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
1014 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
1022 | |
1015 | |
1023 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1016 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
1024 | |
1017 | |
1025 | if (slow) |
1018 | if (slow) |
1026 | { |
1019 | { |
1027 | do |
1020 | do |
1028 | { |
1021 | { |
1029 | if (*xc) |
1022 | if (*xc) |
1030 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1023 | XDrawString (disp, d, gc, x, y + base, xc, 1); |
1031 | |
1024 | |
1032 | x += r->fwidth; |
1025 | x += term->fwidth; |
1033 | xc++; len--; |
1026 | xc++; len--; |
1034 | } |
1027 | } |
1035 | while (len); |
1028 | while (len); |
1036 | } |
1029 | } |
1037 | else |
1030 | else |
1038 | XDrawString (d.display->display, d, TGC, x, y + base, xc, len); |
1031 | XDrawString (disp, d, gc, x, y + base, xc, len); |
1039 | } |
1032 | } |
1040 | } |
1033 | } |
1041 | } |
1034 | } |
1042 | |
1035 | |
1043 | ///////////////////////////////////////////////////////////////////////////// |
1036 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
1055 | |
1048 | |
1056 | void draw (rxvt_drawable &d, int x, int y, |
1049 | void draw (rxvt_drawable &d, int x, int y, |
1057 | const text_t *text, int len, |
1050 | const text_t *text, int len, |
1058 | int fg, int bg); |
1051 | int fg, int bg); |
1059 | |
1052 | |
1060 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull); |
1053 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const; |
1061 | |
1054 | |
1062 | protected: |
1055 | protected: |
1063 | XftFont *f; |
1056 | XftFont *f; |
1064 | }; |
1057 | }; |
1065 | |
1058 | |
1066 | void |
1059 | void |
1067 | rxvt_font_xft::clear () |
1060 | rxvt_font_xft::clear () |
1068 | { |
1061 | { |
1069 | if (f) |
1062 | if (f) |
1070 | { |
1063 | { |
1071 | XftFontClose (DISPLAY, f); |
1064 | XftFontClose (term->display->display, f); |
1072 | f = 0; |
1065 | f = 0; |
1073 | } |
1066 | } |
1074 | } |
1067 | } |
1075 | |
1068 | |
1076 | rxvt_fontprop |
1069 | rxvt_fontprop |
… | |
… | |
1094 | } |
1087 | } |
1095 | |
1088 | |
1096 | bool |
1089 | bool |
1097 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1090 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1098 | { |
1091 | { |
1099 | Display *disp = DISPLAY; |
1092 | dTermDisplay; |
1100 | |
1093 | |
1101 | clear (); |
1094 | clear (); |
1102 | |
1095 | |
1103 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1096 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1104 | |
1097 | |
… | |
… | |
1131 | |
1124 | |
1132 | // store generated name so iso14755 view gives better results |
1125 | // store generated name so iso14755 view gives better results |
1133 | set_name ((char *)FcNameUnparse (p)); |
1126 | set_name ((char *)FcNameUnparse (p)); |
1134 | |
1127 | |
1135 | XftResult result; |
1128 | XftResult result; |
1136 | FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result); |
1129 | FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result); |
1137 | |
1130 | |
1138 | FcPatternDestroy (p); |
1131 | FcPatternDestroy (p); |
1139 | |
1132 | |
1140 | if (!match) |
1133 | if (!match) |
1141 | return false; |
1134 | return false; |
… | |
… | |
1239 | |
1232 | |
1240 | return success; |
1233 | return success; |
1241 | } |
1234 | } |
1242 | |
1235 | |
1243 | bool |
1236 | bool |
1244 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) |
1237 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1245 | { |
1238 | { |
1246 | careful = false; |
1239 | careful = false; |
1247 | |
1240 | |
1248 | if (!XftCharExists (DISPLAY, f, unicode)) |
1241 | if (!XftCharExists (term->display->display, f, unicode)) |
1249 | return false; |
1242 | return false; |
1250 | |
1243 | |
1251 | if (!prop || prop->width == rxvt_fontprop::unset) |
1244 | if (!prop || prop->width == rxvt_fontprop::unset) |
1252 | return true; |
1245 | return true; |
1253 | |
1246 | |
1254 | // check character against base font bounding box |
1247 | // check character against base font bounding box |
1255 | FcChar32 ch = unicode; |
1248 | FcChar32 ch = unicode; |
1256 | XGlyphInfo g; |
1249 | XGlyphInfo g; |
1257 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1250 | XftTextExtents32 (term->display->display, f, &ch, 1, &g); |
1258 | |
1251 | |
1259 | int w = g.width - g.x; |
1252 | int w = g.width - g.x; |
1260 | int wcw = wcwidth (unicode); |
1253 | int wcw = wcwidth (unicode); |
1261 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1254 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1262 | |
1255 | |
… | |
… | |
1270 | void |
1263 | void |
1271 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1264 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1272 | const text_t *text, int len, |
1265 | const text_t *text, int len, |
1273 | int fg, int bg) |
1266 | int fg, int bg) |
1274 | { |
1267 | { |
1275 | clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); |
1268 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
1276 | |
|
|
1277 | int base = ascent; // should be fbase, but that is incorrect |
|
|
1278 | |
1269 | |
1279 | XGlyphInfo extents; |
1270 | XGlyphInfo extents; |
1280 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1271 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1281 | FcChar32 *ep = enc; |
1272 | XftGlyphSpec *ep = enc; |
1282 | int ewidth = 0; |
1273 | |
|
|
1274 | dTermDisplay; |
|
|
1275 | dTermGC; |
|
|
1276 | |
|
|
1277 | // cut trailing spaces |
|
|
1278 | while (len && text [len - 1] == ' ') |
|
|
1279 | len--; |
1283 | |
1280 | |
1284 | while (len) |
1281 | while (len) |
1285 | { |
1282 | { |
1286 | int cwidth = r->fwidth; |
1283 | int cwidth = term->fwidth; |
1287 | FcChar32 fc = *text++; len--; |
1284 | FcChar32 fc = *text++; len--; |
1288 | |
1285 | |
1289 | while (len && *text == NOCHAR) |
1286 | while (len && *text == NOCHAR) |
1290 | text++, len--, cwidth += r->fwidth; |
1287 | text++, len--, cwidth += term->fwidth; |
1291 | |
1288 | |
1292 | if (fc == ' ' && ep == enc) // skip leading spaces |
1289 | if (fc != ' ') // skip spaces |
|
|
1290 | { |
|
|
1291 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
|
|
1292 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
|
|
1293 | |
|
|
1294 | ep->glyph = glyph; |
|
|
1295 | ep->x = x + (cwidth - extents.xOff >> 1); |
|
|
1296 | ep->y = y + ascent; |
|
|
1297 | ep++; |
|
|
1298 | } |
|
|
1299 | |
1293 | x += cwidth; |
1300 | x += cwidth; |
1294 | else |
|
|
1295 | { |
|
|
1296 | FT_UInt gl = XftCharIndex (d.display->display, f, fc); |
|
|
1297 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1298 | |
|
|
1299 | if (extents.xOff != cwidth) |
|
|
1300 | { |
|
|
1301 | if (ewidth) |
|
|
1302 | { |
|
|
1303 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1304 | x, y + base, enc, ep - enc); |
|
|
1305 | x += ewidth; |
|
|
1306 | |
|
|
1307 | ep = enc; |
|
|
1308 | ewidth = 0; |
|
|
1309 | } |
|
|
1310 | |
|
|
1311 | if (extents.xOff > cwidth) |
|
|
1312 | extents.xOff = cwidth; |
|
|
1313 | |
|
|
1314 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1315 | x + (cwidth - extents.xOff >> 1), |
|
|
1316 | y + base, &gl, 1); |
|
|
1317 | x += cwidth; |
|
|
1318 | } |
|
|
1319 | else |
|
|
1320 | { |
|
|
1321 | *ep++ = gl; |
|
|
1322 | ewidth += cwidth; |
|
|
1323 | } |
|
|
1324 | } |
|
|
1325 | } |
1301 | } |
1326 | |
1302 | |
1327 | if (ep != enc) |
1303 | if (ep != enc) |
1328 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1304 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1329 | x, y + base, enc, ep - enc); |
|
|
1330 | } |
1305 | } |
1331 | #endif |
1306 | #endif |
1332 | |
1307 | |
1333 | ///////////////////////////////////////////////////////////////////////////// |
1308 | ///////////////////////////////////////////////////////////////////////////// |
1334 | |
1309 | |
1335 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1310 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
1336 | : fontdesc (0), r (r) |
1311 | : fontdesc (0), term (term) |
1337 | { |
1312 | { |
1338 | clear (); |
1313 | clear (); |
1339 | } |
1314 | } |
1340 | |
1315 | |
1341 | rxvt_fontset::~rxvt_fontset () |
1316 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1385 | f = new rxvt_font_x11; |
1360 | f = new rxvt_font_x11; |
1386 | } |
1361 | } |
1387 | else |
1362 | else |
1388 | f = new rxvt_font_x11; |
1363 | f = new rxvt_font_x11; |
1389 | |
1364 | |
1390 | f->set_term (r); |
1365 | f->set_term (term); |
1391 | f->set_name (strdup (name)); |
1366 | f->set_name (strdup (name)); |
1392 | |
1367 | |
1393 | f->cs = cs; |
1368 | f->cs = cs; |
1394 | f->loaded = false; |
1369 | f->loaded = false; |
1395 | |
1370 | |
… | |
… | |
1578 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1553 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1579 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1554 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1580 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1555 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1581 | |
1556 | |
1582 | XftResult result; |
1557 | XftResult result; |
1583 | FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result); |
1558 | FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result); |
1584 | |
1559 | |
1585 | FcPatternDestroy (p); |
1560 | FcPatternDestroy (p); |
1586 | |
1561 | |
1587 | if (match) |
1562 | if (match) |
1588 | { |
1563 | { |