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