1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: defaultfont.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 |
… | |
… | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
15 | * GNU General Public License for more details. |
16 | * |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program; if not, write to the Free Software |
18 | * along with this program; if not, write to the Free Software |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | *---------------------------------------------------------------------*/ |
20 | *---------------------------------------------------------------------*/ |
21 | |
21 | |
22 | #include "../config.h" |
22 | #include "../config.h" |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
|
|
24 | #include "rxvtlib.h" |
24 | #include "rxvtutil.h" |
25 | #include "rxvtutil.h" |
25 | #include "rxvtfont.h" |
26 | #include "rxvtfont.h" |
26 | |
27 | |
27 | #include <cstdlib> |
28 | #include <cstdlib> |
28 | #include <wchar.h> |
29 | #include <wchar.h> |
29 | #include <inttypes.h> |
30 | #include <inttypes.h> |
30 | |
31 | |
31 | #define DISPLAY r->display->display |
|
|
32 | #define TGC r->TermWin.gc |
|
|
33 | |
|
|
34 | #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 | ) |
35 | |
40 | |
36 | const struct rxvt_fallback_font { |
41 | const struct rxvt_fallback_font { |
37 | codeset cs; |
42 | codeset cs; |
38 | const char *name; |
43 | const char *name; |
39 | } fallback_fonts[] = { |
44 | } fallback_fonts[] = { |
… | |
… | |
130 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
135 | { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" }, |
131 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
136 | { CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, |
132 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
137 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-c-*-iso10646-1" }, |
133 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
138 | { CS_UNICODE, "-*-*-*-r-*-*-*-*-*-*-m-*-iso10646-1" }, |
134 | #if XFT |
139 | #if XFT |
135 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true"}, |
140 | { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, |
136 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
141 | { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, |
137 | { CS_UNICODE, "xft:Andale Mono:antialias=false" }, |
142 | { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, |
138 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false" }, |
143 | { CS_UNICODE, "xft:Arial Unicode MS:antialias=false:autohint=false" }, |
139 | |
144 | |
140 | // FreeMono is usually uglier than x fonts, so try last only. |
145 | // FreeMono is usually uglier than x fonts, so try last only. |
141 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
146 | { CS_UNICODE, "xft:FreeMono:autohint=true" }, |
142 | #endif |
147 | #endif |
143 | |
148 | |
… | |
… | |
152 | 0x304c, 0x672c, // が本 |
157 | 0x304c, 0x672c, // が本 |
153 | }; |
158 | }; |
154 | |
159 | |
155 | #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])) |
156 | |
161 | |
|
|
162 | #define dTermDisplay Display *disp = term->xdisp |
|
|
163 | #define dTermGC GC gc = term->gc |
|
|
164 | |
157 | ///////////////////////////////////////////////////////////////////////////// |
165 | ///////////////////////////////////////////////////////////////////////////// |
158 | |
166 | |
159 | #if XFT |
167 | #if XFT |
160 | rxvt_drawable::~rxvt_drawable () |
168 | rxvt_drawable::~rxvt_drawable () |
161 | { |
169 | { |
… | |
… | |
164 | } |
172 | } |
165 | |
173 | |
166 | rxvt_drawable::operator XftDraw *() |
174 | rxvt_drawable::operator XftDraw *() |
167 | { |
175 | { |
168 | if (!xftdrawable) |
176 | if (!xftdrawable) |
169 | xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap); |
177 | xftdrawable = XftDrawCreate (screen->xdisp, drawable, screen->visual, screen->cmap); |
170 | |
178 | |
171 | return xftdrawable; |
179 | return xftdrawable; |
172 | } |
180 | } |
173 | #endif |
181 | #endif |
174 | |
182 | |
175 | ///////////////////////////////////////////////////////////////////////////// |
183 | ///////////////////////////////////////////////////////////////////////////// |
176 | |
|
|
177 | static void *enc_buf; |
|
|
178 | static uint32_t enc_len; |
|
|
179 | |
|
|
180 | static inline void * |
|
|
181 | get_enc_buf (uint32_t len) |
|
|
182 | { |
|
|
183 | if (len > enc_len) |
|
|
184 | { |
|
|
185 | free (enc_buf); |
|
|
186 | enc_buf = malloc (len); |
|
|
187 | enc_len = len; |
|
|
188 | } |
|
|
189 | |
|
|
190 | return enc_buf; |
|
|
191 | } |
|
|
192 | |
184 | |
193 | static const char * |
185 | static const char * |
194 | 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) |
195 | { |
187 | { |
196 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
188 | uint8_t *buf = rxvt_temp_buf<uint8_t> (len); |
|
|
189 | uint8_t *res = buf; |
197 | |
190 | |
198 | while (len--) |
191 | while (len--) |
199 | { |
192 | { |
200 | uint32_t c = FROM_UNICODE (cs, *text++); |
193 | uint32_t c = FROM_UNICODE (cs, *text++); |
201 | |
194 | |
… | |
… | |
206 | } |
199 | } |
207 | |
200 | |
208 | *buf++ = c; |
201 | *buf++ = c; |
209 | } |
202 | } |
210 | |
203 | |
211 | return (const char *)enc_buf; |
204 | return (const char *)res; |
212 | } |
205 | } |
213 | |
206 | |
214 | static const XChar2b * |
207 | static const XChar2b * |
215 | 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) |
216 | { |
209 | { |
217 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
210 | XChar2b *buf = rxvt_temp_buf<XChar2b> (len); |
|
|
211 | XChar2b *res = buf; |
218 | |
212 | |
219 | while (len--) |
213 | while (len--) |
220 | { |
214 | { |
221 | uint32_t c = FROM_UNICODE (cs, *text++); |
215 | uint32_t c = FROM_UNICODE (cs, *text++); |
222 | |
216 | |
… | |
… | |
229 | buf->byte1 = c >> 8; |
223 | buf->byte1 = c >> 8; |
230 | buf->byte2 = c; |
224 | buf->byte2 = c; |
231 | buf++; |
225 | buf++; |
232 | } |
226 | } |
233 | |
227 | |
234 | return (XChar2b *)enc_buf; |
228 | return res; |
235 | } |
229 | } |
236 | |
230 | |
237 | ///////////////////////////////////////////////////////////////////////////// |
231 | ///////////////////////////////////////////////////////////////////////////// |
238 | |
232 | |
239 | void |
233 | void |
… | |
… | |
245 | if (this->name) free (this->name); // let the compiler optimize |
239 | if (this->name) free (this->name); // let the compiler optimize |
246 | this->name = name; |
240 | this->name = name; |
247 | } |
241 | } |
248 | |
242 | |
249 | void |
243 | void |
250 | 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 |
251 | { |
245 | { |
|
|
246 | dTermDisplay; |
|
|
247 | dTermGC; |
|
|
248 | |
252 | if (color == Color_bg) |
249 | if (color == Color_bg) |
253 | XClearArea (d.display->display, d, x, y, w, h, FALSE); |
250 | XClearArea (disp, d, x, y, w, h, false); |
254 | else if (color >= 0) |
251 | else if (color >= 0) |
255 | { |
252 | { |
256 | #if XFT |
253 | #if XFT |
257 | XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); |
254 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
258 | #else |
255 | #else |
259 | XSetForeground (d.display->display, TGC, r->pix_colors[color]); |
256 | XSetForeground (disp, gc, term->pix_colors[color]); |
260 | XFillRectangle (d.display->display, d, TGC, x, y, w, h); |
257 | XFillRectangle (disp, d, gc, x, y, w, h); |
261 | #endif |
258 | #endif |
262 | } |
259 | } |
263 | } |
260 | } |
264 | |
261 | |
265 | #include "table/linedraw.h" |
262 | #include "table/linedraw.h" |
… | |
… | |
276 | rxvt_fontprop properties () |
273 | rxvt_fontprop properties () |
277 | { |
274 | { |
278 | rxvt_fontprop p; |
275 | rxvt_fontprop p; |
279 | |
276 | |
280 | p.width = p.height = 1; |
277 | p.width = p.height = 1; |
|
|
278 | p.ascent = rxvt_fontprop::unset; |
281 | p.weight = rxvt_fontprop::medium; |
279 | p.weight = rxvt_fontprop::medium; |
282 | p.slant = rxvt_fontprop::roman; |
280 | p.slant = rxvt_fontprop::roman; |
283 | |
281 | |
284 | return p; |
282 | return p; |
285 | } |
283 | } |
… | |
… | |
292 | set_name (strdup ("built-in support font")); |
290 | set_name (strdup ("built-in support font")); |
293 | |
291 | |
294 | return true; |
292 | return true; |
295 | } |
293 | } |
296 | |
294 | |
297 | 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 |
298 | { |
296 | { |
299 | careful = false; |
297 | careful = false; |
300 | |
298 | |
301 | if (unicode <= 0x001f) |
299 | if (unicode <= 0x001f) |
302 | return true; |
300 | return true; |
… | |
… | |
305 | return false; |
303 | return false; |
306 | |
304 | |
307 | if (unicode <= 0x009f) |
305 | if (unicode <= 0x009f) |
308 | return true; |
306 | return true; |
309 | |
307 | |
310 | if (unicode >= 0x2500 && unicode <= 0x259f) |
308 | if (unicode >= 0x2500 && unicode <= 0x259f && |
|
|
309 | !term->option (Opt_skipBuiltinGlyphs)) |
311 | return true; |
310 | return true; |
312 | |
311 | |
313 | if (IS_COMPOSE (unicode)) |
312 | if (IS_COMPOSE (unicode)) |
314 | return true; |
313 | return true; |
315 | |
314 | |
… | |
… | |
331 | void |
330 | void |
332 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
331 | rxvt_font_default::draw (rxvt_drawable &d, int x, int y, |
333 | const text_t *text, int len, |
332 | const text_t *text, int len, |
334 | int fg, int bg) |
333 | int fg, int bg) |
335 | { |
334 | { |
|
|
335 | dTermDisplay; |
|
|
336 | dTermGC; |
|
|
337 | |
336 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
338 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
337 | |
339 | |
338 | XSetForeground (d.display->display, TGC, r->pix_colors[fg]); |
340 | XSetForeground (disp, gc, term->pix_colors[fg]); |
339 | |
341 | |
340 | while (len) |
342 | while (len) |
341 | { |
343 | { |
342 | #if ENABLE_COMBINING |
344 | #if ENABLE_COMBINING |
343 | compose_char *cc; |
345 | compose_char *cc; |
… | |
… | |
347 | |
349 | |
348 | while (++text, --len && *text == NOCHAR) |
350 | while (++text, --len && *text == NOCHAR) |
349 | ; |
351 | ; |
350 | |
352 | |
351 | int width = text - tp; |
353 | int width = text - tp; |
352 | int fwidth = r->TermWin.fwidth * width; |
354 | int fwidth = term->fwidth * width; |
353 | |
355 | |
354 | if (0x2500 <= t && t <= 0x259f) |
356 | if (0x2500 <= t && t <= 0x259f) |
355 | { |
357 | { |
356 | uint16_t offs = linedraw_offs[t - 0x2500]; |
358 | uint16_t offs = linedraw_offs[t - 0x2500]; |
357 | uint32_t *a = linedraw_command + (offs >> 4); |
359 | uint32_t *a = linedraw_command + (offs >> 4); |
358 | uint32_t *b = a + (offs & 15); |
360 | uint32_t *b = a + (offs & 15); |
359 | |
361 | |
360 | int W = fwidth; |
362 | int W = fwidth; |
361 | int H = r->TermWin.fheight; |
363 | int H = term->fheight; |
362 | |
364 | |
363 | int x_[16]; |
365 | int x_[16]; |
364 | int y_[16]; |
366 | int y_[16]; |
365 | |
367 | |
366 | for (int i = 0; i <= 8; i++) |
368 | for (int i = 0; i <= 8; i++) |
… | |
… | |
374 | |
376 | |
375 | XGCValues gcv; |
377 | XGCValues gcv; |
376 | |
378 | |
377 | gcv.cap_style = CapButt; |
379 | gcv.cap_style = CapButt; |
378 | gcv.line_width = 0; |
380 | gcv.line_width = 0; |
379 | XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv); |
381 | XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv); |
380 | |
382 | |
381 | while (a < b) |
383 | while (a < b) |
382 | { |
384 | { |
383 | uint32_t command = *a++; |
385 | uint32_t command = *a++; |
384 | |
386 | |
… | |
… | |
391 | int y2 = y_[(command >> 0) & 15]; |
393 | int y2 = y_[(command >> 0) & 15]; |
392 | |
394 | |
393 | switch (op) |
395 | switch (op) |
394 | { |
396 | { |
395 | case 0: // line |
397 | case 0: // line |
396 | XDrawLine (d.display->display, d, TGC, x1, y1, x2, y2); |
398 | XDrawLine (disp, d, gc, x1, y1, x2, y2); |
397 | break; |
399 | break; |
398 | |
400 | |
399 | case 1: // rectangle, possibly stippled |
401 | case 1: // rectangle, possibly stippled |
400 | if (a) |
402 | if (a) |
401 | { |
403 | { |
402 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
404 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
403 | |
405 | |
404 | gcv.fill_style = FillStippled; |
406 | gcv.fill_style = FillStippled; |
405 | gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); |
407 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
406 | gcv.ts_x_origin = x; |
408 | gcv.ts_x_origin = x; |
407 | gcv.ts_y_origin = y; |
409 | gcv.ts_y_origin = y; |
408 | |
410 | |
409 | XChangeGC (d.display->display, TGC, |
411 | XChangeGC (disp, gc, |
410 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
412 | GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, |
411 | &gcv); |
413 | &gcv); |
412 | } |
414 | } |
413 | |
415 | |
414 | XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
416 | XFillRectangle (disp, d, gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
415 | |
417 | |
416 | if (a) |
418 | if (a) |
417 | { |
419 | { |
418 | XFreePixmap (d.display->display, gcv.stipple); |
420 | XFreePixmap (disp, gcv.stipple); |
419 | gcv.stipple = 0; |
421 | gcv.stipple = 0; |
420 | gcv.fill_style = FillSolid; |
422 | gcv.fill_style = FillSolid; |
421 | XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); |
423 | XChangeGC (disp, gc, GCFillStyle, &gcv); |
422 | } |
424 | } |
423 | break; |
425 | break; |
424 | case 2: // arc |
426 | case 2: // arc |
425 | XDrawArc (d.display->display, d, TGC, |
427 | XDrawArc (disp, d, gc, |
426 | x1 - W/2, y1 - H/2, W-1, H-1, |
428 | x1 - W/2, y1 - H/2, W-1, H-1, |
427 | (a - 1) * 90*64, (b - 1) * 90*64); |
429 | (a - 1) * 90*64, (b - 1) * 90*64); |
428 | break; |
430 | break; |
429 | } |
431 | } |
430 | } |
432 | } |
… | |
… | |
461 | case ZERO_WIDTH_CHAR: |
463 | case ZERO_WIDTH_CHAR: |
462 | case NOCHAR: |
464 | case NOCHAR: |
463 | break; |
465 | break; |
464 | |
466 | |
465 | default: |
467 | default: |
466 | XDrawRectangle (d.display->display, d, TGC, x + 2, y + 2, |
468 | XDrawRectangle (disp, d, gc, x + 2, y + 2, |
467 | fwidth - 4, r->TermWin.fheight - 4); |
469 | fwidth - 4, term->fheight - 4); |
468 | } |
470 | } |
469 | |
471 | |
470 | x += fwidth; |
472 | x += fwidth; |
471 | } |
473 | } |
472 | } |
474 | } |
… | |
… | |
480 | |
482 | |
481 | rxvt_fontprop properties (); |
483 | rxvt_fontprop properties (); |
482 | |
484 | |
483 | bool load (const rxvt_fontprop &prop); |
485 | bool load (const rxvt_fontprop &prop); |
484 | |
486 | |
485 | 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; |
486 | |
488 | |
487 | void draw (rxvt_drawable &d, int x, int y, |
489 | void draw (rxvt_drawable &d, int x, int y, |
488 | const text_t *text, int len, |
490 | const text_t *text, int len, |
489 | int fg, int bg); |
491 | int fg, int bg); |
490 | |
492 | |
491 | bool slow; // wether this is a proportional font or has other funny characteristics |
493 | bool slow; // wether this is a proportional font or has other funny characteristics |
492 | XFontStruct *f; |
494 | XFontStruct *f; |
493 | codeset cs; |
495 | codeset cs; |
494 | bool enc2b, encm; |
496 | bool enc2b, encm; |
495 | |
497 | |
496 | char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
498 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
497 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
499 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
498 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
500 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
499 | bool set_properties (rxvt_fontprop &p, const char *name); |
501 | bool set_properties (rxvt_fontprop &p, const char *name); |
500 | }; |
502 | }; |
501 | |
503 | |
502 | char * |
504 | char * |
503 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
505 | rxvt_font_x11::get_property (XFontStruct *f, Atom property, const char *repl) const |
504 | { |
506 | { |
505 | unsigned long value; |
507 | unsigned long value; |
506 | |
508 | |
507 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
509 | if (XGetFontProperty (f, property, &value)) |
508 | return XGetAtomName (DISPLAY, value); |
510 | return XGetAtomName (term->xdisp, value); |
509 | else |
511 | else |
510 | return rxvt_strdup (repl); |
512 | return rxvt_strdup (repl); |
511 | } |
513 | } |
512 | |
514 | |
513 | rxvt_fontprop |
515 | rxvt_fontprop |
… | |
… | |
521 | bool |
523 | bool |
522 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
524 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
523 | { |
525 | { |
524 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
526 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
525 | p.height = height; |
527 | p.height = height; |
|
|
528 | p.ascent = rxvt_fontprop::unset; |
526 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
529 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
527 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
530 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
528 | |
531 | |
529 | return true; |
532 | return true; |
530 | } |
533 | } |
… | |
… | |
533 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
536 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
534 | { |
537 | { |
535 | unsigned long height; |
538 | unsigned long height; |
536 | |
539 | |
537 | #if 0 |
540 | #if 0 |
538 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
541 | if (!XGetFontProperty (f, XInternAtom (term->xdisp, "PIXEL_SIZE", 0), &height)) |
539 | return false; |
542 | return false; |
540 | #else |
543 | #else |
541 | height = f->ascent + f->descent; |
544 | height = f->ascent + f->descent; |
542 | #endif |
545 | #endif |
543 | |
546 | |
544 | unsigned long avgwidth; |
547 | unsigned long avgwidth; |
545 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
548 | if (!XGetFontProperty (f, term->xa [XA_AVERAGE_WIDTH], &avgwidth)) |
546 | avgwidth = 0; |
549 | avgwidth = 0; |
547 | |
550 | |
548 | char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
551 | char *weight = get_property (f, term->xa [XA_WEIGHT_NAME], "medium"); |
549 | char *slant = get_property (f, "SLANT", "r"); |
552 | char *slant = get_property (f, term->xa [XA_SLANT], "r"); |
550 | |
553 | |
551 | set_properties (p, height, weight, slant, avgwidth); |
554 | set_properties (p, height, weight, slant, avgwidth); |
552 | |
555 | |
553 | free (weight); |
556 | free (weight); |
554 | free (slant); |
557 | free (slant); |
555 | |
558 | |
|
|
559 | p.ascent = f->ascent; |
|
|
560 | |
556 | return true; |
561 | return true; |
557 | } |
562 | } |
558 | |
563 | |
559 | bool |
564 | bool |
560 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
565 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
561 | { |
566 | { |
|
|
567 | dTermDisplay; |
562 | int slashes = 0; |
568 | int slashes = 0; |
563 | const char *comp[13]; |
569 | const char *comp[13]; |
564 | |
570 | |
565 | for (const char *c = name; *c; c++) |
571 | for (const char *c = name; *c; c++) |
566 | if (*c == '-') |
572 | if (*c == '-') |
… | |
… | |
574 | if (slashes >= 13 |
580 | if (slashes >= 13 |
575 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
581 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
576 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
582 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
577 | 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])); |
578 | |
584 | |
579 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
585 | XFontStruct *f = XLoadQueryFont (disp, name); |
580 | |
586 | |
581 | if (f) |
587 | if (f) |
582 | { |
588 | { |
583 | // 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 |
584 | // (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). |
585 | // in that case, just return garbage. |
591 | // in that case, just return garbage. |
586 | bool ret = set_properties (p, f); |
592 | bool ret = set_properties (p, f); |
587 | XFreeFont (DISPLAY, f); |
593 | XFreeFont (disp, f); |
588 | return ret; |
594 | return ret; |
589 | } |
595 | } |
590 | else |
596 | else |
591 | return false; |
597 | return false; |
592 | } |
598 | } |
… | |
… | |
630 | } |
636 | } |
631 | |
637 | |
632 | bool |
638 | bool |
633 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
639 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
634 | { |
640 | { |
|
|
641 | dTermDisplay; |
|
|
642 | |
635 | clear (); |
643 | clear (); |
636 | |
644 | |
637 | char field_str[64]; // enough for 128 bits |
645 | char field_str[64]; // enough for 128 bits |
638 | |
646 | |
639 | // first morph the font if required |
647 | // first morph the font if required |
… | |
… | |
642 | { |
650 | { |
643 | char fname[1024]; |
651 | char fname[1024]; |
644 | |
652 | |
645 | if (name[0] != '-') |
653 | if (name[0] != '-') |
646 | { |
654 | { |
647 | f = XLoadQueryFont (DISPLAY, name); |
655 | f = XLoadQueryFont (disp, name); |
648 | |
656 | |
649 | if (!f) |
657 | if (!f) |
650 | return false; |
658 | return false; |
651 | |
659 | |
652 | char *new_name = get_property (f, "FONT", name); |
660 | char *new_name = get_property (f, XA_FONT, name); |
653 | |
661 | |
654 | if (new_name) |
662 | if (new_name) |
655 | set_name (new_name); |
663 | set_name (new_name); |
656 | else |
664 | else |
657 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
665 | rxvt_warn ("font '%s' has no FONT property, continuing without.", name); |
658 | |
666 | |
659 | XFreeFont (DISPLAY, f); |
667 | XFreeFont (disp, f); |
660 | f = 0; |
668 | f = 0; |
661 | } |
669 | } |
662 | |
670 | |
663 | if (prop.weight != rxvt_fontprop::unset) |
671 | if (prop.weight != rxvt_fontprop::unset) |
664 | { |
672 | { |
… | |
… | |
694 | ~font_weight () { free (name); } |
702 | ~font_weight () { free (name); } |
695 | }; |
703 | }; |
696 | |
704 | |
697 | char **list; |
705 | char **list; |
698 | int count; |
706 | int count; |
699 | list = XListFonts (DISPLAY, name, 4000, &count); |
707 | list = XListFonts (disp, name, 4000, &count); |
700 | |
708 | |
701 | set_name (0); |
709 | set_name (0); |
702 | |
710 | |
703 | if (!list) |
711 | if (!list) |
704 | return false; |
712 | return false; |
… | |
… | |
712 | |
720 | |
713 | int diff = 0; |
721 | int diff = 0; |
714 | |
722 | |
715 | if (replace_field (fname, list[i], 6, '0', field_str)) |
723 | if (replace_field (fname, list[i], 6, '0', field_str)) |
716 | diff += 10; // slightly penalize scalable fonts |
724 | diff += 10; // slightly penalize scalable fonts |
|
|
725 | else if (replace_field (fname, list[i], 11, '0', "0")) |
|
|
726 | diff += 300; // more heavily penalize what looks like scaled bitmap fonts |
717 | |
727 | |
718 | if (!set_properties (p, fname)) |
728 | if (!set_properties (p, fname)) |
719 | continue; |
729 | continue; |
720 | |
730 | |
721 | if (prop.height != rxvt_fontprop::unset |
731 | if (prop.height != rxvt_fontprop::unset |
… | |
… | |
737 | for (;;) |
747 | for (;;) |
738 | { |
748 | { |
739 | font_weight *best = fonts + count - 1; |
749 | font_weight *best = fonts + count - 1; |
740 | |
750 | |
741 | for (font_weight *w = best; w-- > fonts; ) |
751 | for (font_weight *w = best; w-- > fonts; ) |
742 | if (w->diff < best->diff) |
752 | if (w->diff <= best->diff) |
743 | best = w; |
753 | best = w; |
744 | |
754 | |
745 | if (!best->name |
755 | if (!best->name |
746 | || !(f = XLoadQueryFont (DISPLAY, best->name))) |
756 | || !(f = XLoadQueryFont (disp, best->name))) |
747 | break; |
757 | break; |
748 | |
758 | |
749 | set_name (best->name); |
759 | set_name (best->name); |
750 | best->clear (); |
760 | best->clear (); |
751 | |
761 | |
… | |
… | |
764 | delete [] fonts; |
774 | delete [] fonts; |
765 | |
775 | |
766 | if (!f) |
776 | if (!f) |
767 | return false; |
777 | return false; |
768 | |
778 | |
769 | char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
779 | char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0); |
770 | char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
780 | char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0); |
771 | |
781 | |
772 | if (registry && encoding) |
782 | if (registry && encoding) |
773 | { |
783 | { |
774 | char charset[64]; |
784 | char charset[64]; |
775 | snprintf (charset, 64, "%s-%s", registry, encoding); |
785 | snprintf (charset, 64, "%s-%s", registry, encoding); |
776 | |
786 | |
777 | cs = codeset_from_name (charset); |
787 | cs = codeset_from_name (charset); |
778 | } |
788 | } |
779 | else |
789 | else |
780 | { |
790 | { |
781 | const char *charset = get_property (f, "FONT", 0); |
791 | const char *charset = get_property (f, XA_FONT, 0); |
782 | |
792 | |
783 | if (!charset) |
793 | if (!charset) |
784 | charset = name; |
794 | charset = name; |
785 | |
795 | |
786 | int count = 13; |
796 | int count = 13; |
… | |
… | |
845 | |
855 | |
846 | XCharStruct g; |
856 | XCharStruct g; |
847 | int dir_ret, asc_ret, des_ret; |
857 | int dir_ret, asc_ret, des_ret; |
848 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
858 | XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); |
849 | |
859 | |
850 | int wcw = wcwidth (*t); if (wcw > 0) g.width = g.width / wcw; |
860 | int wcw = WCWIDTH (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
851 | |
861 | |
852 | if (width < g.width) width = g.width; |
862 | if (width < g.width) width = g.width; |
853 | } |
863 | } |
854 | |
864 | |
855 | if (cs == CS_UNKNOWN) |
865 | if (cs == CS_UNKNOWN) |
… | |
… | |
874 | void |
884 | void |
875 | rxvt_font_x11::clear () |
885 | rxvt_font_x11::clear () |
876 | { |
886 | { |
877 | if (f) |
887 | if (f) |
878 | { |
888 | { |
879 | XFreeFont (DISPLAY, f); |
889 | XFreeFont (term->xdisp, f); |
880 | f = 0; |
890 | f = 0; |
881 | } |
891 | } |
882 | } |
892 | } |
883 | |
893 | |
884 | bool |
894 | bool |
885 | 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 |
886 | { |
896 | { |
887 | uint32_t ch = FROM_UNICODE (cs, unicode); |
897 | uint32_t ch = FROM_UNICODE (cs, unicode); |
888 | |
898 | |
889 | if (ch == NOCHAR) |
899 | if (ch == NOCHAR) |
890 | return false; |
900 | return false; |
… | |
… | |
928 | |
938 | |
929 | if (!prop || prop->width == rxvt_fontprop::unset) |
939 | if (!prop || prop->width == rxvt_fontprop::unset) |
930 | return true; |
940 | return true; |
931 | |
941 | |
932 | // check character against base font bounding box |
942 | // check character against base font bounding box |
933 | int w = xcs->width; |
943 | int w = xcs->rbearing - xcs->lbearing; |
934 | int wcw = wcwidth (unicode); |
944 | int wcw = WCWIDTH (unicode); |
935 | if (wcw > 0) w /= wcw; |
945 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
936 | |
946 | |
937 | careful = w > prop->width; |
947 | careful = w > prop->width; |
938 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
948 | if (careful && OVERLAP_OK (w, prop)) |
939 | return false; |
949 | return false; |
940 | |
950 | |
941 | return true; |
951 | return true; |
942 | } |
952 | } |
943 | |
953 | |
… | |
… | |
949 | // this looks like a mess /. |
959 | // this looks like a mess /. |
950 | // and it is a mess /. |
960 | // and it is a mess /. |
951 | // yet we are trying to be perfect /. |
961 | // yet we are trying to be perfect /. |
952 | // but the result still isn't perfect /. |
962 | // but the result still isn't perfect /. |
953 | |
963 | |
|
|
964 | dTermDisplay; |
|
|
965 | dTermGC; |
|
|
966 | |
954 | bool slow = this->slow |
967 | bool slow = this->slow |
955 | || width != r->TermWin.fwidth |
968 | || width != term->fwidth |
956 | || height != r->TermWin.fheight; |
969 | || height != term->fheight; |
957 | |
970 | |
958 | int base = ascent; // sorry, incorrect: r->TermWin.fbase; |
971 | int base = ascent; // sorry, incorrect: term->fbase; |
959 | |
972 | |
960 | XGCValues v; |
973 | XGCValues v; |
961 | v.foreground = r->pix_colors[fg]; |
974 | v.foreground = term->pix_colors[fg]; |
962 | v.font = f->fid; |
975 | v.font = f->fid; |
963 | |
976 | |
964 | if (enc2b) |
977 | if (enc2b) |
965 | { |
978 | { |
966 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
979 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
967 | |
980 | |
968 | if (bg == Color_bg && !slow) |
981 | if (bg == Color_bg && !slow) |
969 | { |
982 | { |
970 | v.background = r->pix_colors[bg]; |
983 | v.background = term->pix_colors[bg]; |
971 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
984 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
972 | XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); |
985 | XDrawImageString16 (disp, d, gc, x, y + base, xc, len); |
973 | } |
986 | } |
974 | else |
987 | else |
975 | { |
988 | { |
976 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
989 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
977 | |
990 | |
978 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
991 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
979 | |
992 | |
980 | if (slow) |
993 | if (slow) |
981 | { |
994 | { |
982 | do |
995 | do |
983 | { |
996 | { |
984 | if (xc->byte1 || xc->byte2) |
997 | if (xc->byte1 || xc->byte2) |
985 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); |
998 | XDrawString16 (disp, d, gc, x, y + base, xc, 1); |
986 | |
999 | |
987 | x += r->TermWin.fwidth; |
1000 | x += term->fwidth; |
988 | xc++; len--; |
1001 | xc++; len--; |
989 | } |
1002 | } |
990 | while (len); |
1003 | while (len); |
991 | } |
1004 | } |
992 | else |
1005 | else |
993 | XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); |
1006 | XDrawString16 (disp, d, gc, x, y + base, xc, len); |
994 | } |
1007 | } |
995 | } |
1008 | } |
996 | else |
1009 | else |
997 | { |
1010 | { |
998 | const char *xc = enc_char (text, len, cs, slow); |
1011 | const char *xc = enc_char (text, len, cs, slow); |
999 | |
1012 | |
1000 | if (bg == Color_bg && !slow) |
1013 | if (bg == Color_bg && !slow) |
1001 | { |
1014 | { |
1002 | v.background = r->pix_colors[bg]; |
1015 | v.background = term->pix_colors[bg]; |
1003 | XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); |
1016 | XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v); |
1004 | XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); |
1017 | XDrawImageString (disp, d, gc, x, y + base, xc, len); |
1005 | } |
1018 | } |
1006 | else |
1019 | else |
1007 | { |
1020 | { |
1008 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1021 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
1009 | |
1022 | |
1010 | XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); |
1023 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
1011 | |
1024 | |
1012 | if (slow) |
1025 | if (slow) |
1013 | { |
1026 | { |
1014 | do |
1027 | do |
1015 | { |
1028 | { |
1016 | if (*xc) |
1029 | if (*xc) |
1017 | XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); |
1030 | XDrawString (disp, d, gc, x, y + base, xc, 1); |
1018 | |
1031 | |
1019 | x += r->TermWin.fwidth; |
1032 | x += term->fwidth; |
1020 | xc++; len--; |
1033 | xc++; len--; |
1021 | } |
1034 | } |
1022 | while (len); |
1035 | while (len); |
1023 | } |
1036 | } |
1024 | else |
1037 | else |
1025 | XDrawString (d.display->display, d, TGC, x, y + base, xc, len); |
1038 | XDrawString (disp, d, gc, x, y + base, xc, len); |
1026 | } |
1039 | } |
1027 | } |
1040 | } |
1028 | } |
1041 | } |
1029 | |
1042 | |
1030 | ///////////////////////////////////////////////////////////////////////////// |
1043 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
1042 | |
1055 | |
1043 | void draw (rxvt_drawable &d, int x, int y, |
1056 | void draw (rxvt_drawable &d, int x, int y, |
1044 | const text_t *text, int len, |
1057 | const text_t *text, int len, |
1045 | int fg, int bg); |
1058 | int fg, int bg); |
1046 | |
1059 | |
1047 | 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; |
1048 | |
1061 | |
1049 | protected: |
1062 | protected: |
1050 | XftFont *f; |
1063 | XftFont *f; |
1051 | }; |
1064 | }; |
1052 | |
1065 | |
1053 | void |
1066 | void |
1054 | rxvt_font_xft::clear () |
1067 | rxvt_font_xft::clear () |
1055 | { |
1068 | { |
1056 | if (f) |
1069 | if (f) |
1057 | { |
1070 | { |
1058 | XftFontClose (DISPLAY, f); |
1071 | XftFontClose (term->xdisp, f); |
1059 | f = 0; |
1072 | f = 0; |
1060 | } |
1073 | } |
1061 | } |
1074 | } |
1062 | |
1075 | |
1063 | rxvt_fontprop |
1076 | rxvt_fontprop |
… | |
… | |
1067 | |
1080 | |
1068 | FT_Face face = XftLockFace (f); |
1081 | FT_Face face = XftLockFace (f); |
1069 | |
1082 | |
1070 | p.width = width; |
1083 | p.width = width; |
1071 | p.height = height; |
1084 | p.height = height; |
|
|
1085 | p.ascent = ascent; |
1072 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1086 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD |
1073 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1087 | ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
1074 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1088 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC |
1075 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1089 | ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
1076 | |
1090 | |
… | |
… | |
1080 | } |
1094 | } |
1081 | |
1095 | |
1082 | bool |
1096 | bool |
1083 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1097 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1084 | { |
1098 | { |
|
|
1099 | dTermDisplay; |
|
|
1100 | |
1085 | clear (); |
1101 | clear (); |
1086 | |
1102 | |
1087 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1103 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
1088 | |
1104 | |
1089 | if (!p) |
1105 | if (!p) |
1090 | return false; |
1106 | return false; |
1091 | |
1107 | |
1092 | FcValue v; |
1108 | FcValue v; |
1093 | |
1109 | |
1094 | if (prop.height != rxvt_fontprop::unset |
1110 | if (prop.height != rxvt_fontprop::unset |
1095 | || (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1111 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1096 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1112 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1097 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1113 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1098 | |
1114 | |
1099 | if (prop.weight != rxvt_fontprop::unset |
1115 | if (prop.weight != rxvt_fontprop::unset |
1100 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1116 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
… | |
… | |
1115 | |
1131 | |
1116 | // store generated name so iso14755 view gives better results |
1132 | // store generated name so iso14755 view gives better results |
1117 | set_name ((char *)FcNameUnparse (p)); |
1133 | set_name ((char *)FcNameUnparse (p)); |
1118 | |
1134 | |
1119 | XftResult result; |
1135 | XftResult result; |
1120 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1136 | FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result); |
1121 | |
1137 | |
1122 | FcPatternDestroy (p); |
1138 | FcPatternDestroy (p); |
1123 | |
1139 | |
1124 | if (!match) |
1140 | if (!match) |
1125 | return false; |
1141 | return false; |
… | |
… | |
1127 | int ftheight = 0; |
1143 | int ftheight = 0; |
1128 | bool success = true; |
1144 | bool success = true; |
1129 | |
1145 | |
1130 | for (;;) |
1146 | for (;;) |
1131 | { |
1147 | { |
1132 | f = XftFontOpenPattern (DISPLAY, FcPatternDuplicate (match)); |
1148 | f = XftFontOpenPattern (disp, FcPatternDuplicate (match)); |
1133 | |
1149 | |
1134 | if (!f) |
1150 | if (!f) |
1135 | { |
1151 | { |
1136 | success = false; |
1152 | success = false; |
1137 | break; |
1153 | break; |
… | |
… | |
1146 | |
1162 | |
1147 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1163 | bool scalable = face->face_flags & FT_FACE_FLAG_SCALABLE; |
1148 | |
1164 | |
1149 | XftUnlockFace (f); |
1165 | XftUnlockFace (f); |
1150 | |
1166 | |
|
|
1167 | int glheight = height; |
|
|
1168 | |
1151 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1169 | for (uint16_t *t = extent_test_chars + NUM_EXTENT_TEST_CHARS; t-- > extent_test_chars; ) |
1152 | { |
1170 | { |
1153 | FcChar16 ch = *t; |
1171 | FcChar16 ch = *t; |
1154 | |
1172 | |
1155 | if (cs != CS_UNICODE |
1173 | if (cs != CS_UNICODE |
… | |
… | |
1161 | bool careful; |
1179 | bool careful; |
1162 | if (!has_char (*t, &prop, careful)) |
1180 | if (!has_char (*t, &prop, careful)) |
1163 | continue; |
1181 | continue; |
1164 | |
1182 | |
1165 | XGlyphInfo g; |
1183 | XGlyphInfo g; |
1166 | XftTextExtents16 (DISPLAY, f, &ch, 1, &g); |
1184 | XftTextExtents16 (disp, f, &ch, 1, &g); |
1167 | |
1185 | |
|
|
1186 | g.width -= g.x; |
|
|
1187 | |
1168 | int wcw = wcwidth (ch); |
1188 | int wcw = WCWIDTH (ch); |
1169 | if (wcw > 0) g.width = g.width / wcw; |
1189 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
1170 | |
1190 | |
1171 | if (width < g.width) width = g.width; |
1191 | if (width < g.width ) width = g.width; |
1172 | 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; |
|
|
1194 | } |
|
|
1195 | |
|
|
1196 | if (!width) |
|
|
1197 | { |
|
|
1198 | rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); |
|
|
1199 | |
|
|
1200 | XftFontClose (disp, f); |
|
|
1201 | f = 0; |
|
|
1202 | |
|
|
1203 | success = false; |
|
|
1204 | break; |
1173 | } |
1205 | } |
1174 | |
1206 | |
1175 | if (prop.height == rxvt_fontprop::unset |
1207 | if (prop.height == rxvt_fontprop::unset |
1176 | || height <= prop.height |
1208 | || (height <= prop.height && glheight <= prop.height) |
1177 | || height <= 2 |
1209 | || height <= 2 |
1178 | || !scalable) |
1210 | || !scalable) |
1179 | break; |
1211 | break; |
1180 | |
1212 | |
1181 | if (ftheight) |
1213 | if (ftheight) |
… | |
… | |
1188 | ftheight -= height - prop.height; |
1220 | ftheight -= height - prop.height; |
1189 | } |
1221 | } |
1190 | else |
1222 | else |
1191 | ftheight = prop.height - 1; |
1223 | ftheight = prop.height - 1; |
1192 | |
1224 | |
1193 | XftFontClose (DISPLAY, f); |
1225 | XftFontClose (disp, f); |
1194 | FcPatternDel (match, FC_PIXEL_SIZE); |
1226 | FcPatternDel (match, FC_PIXEL_SIZE); |
1195 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1227 | FcPatternAddInteger (match, FC_PIXEL_SIZE, ftheight); |
1196 | } |
1228 | } |
1197 | |
1229 | |
1198 | FcPatternDestroy (match); |
1230 | FcPatternDestroy (match); |
1199 | |
1231 | |
1200 | #if 0 // do it per-character |
1232 | #if 0 // do it per-character |
… | |
… | |
1207 | |
1239 | |
1208 | return success; |
1240 | return success; |
1209 | } |
1241 | } |
1210 | |
1242 | |
1211 | bool |
1243 | bool |
1212 | 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 |
1213 | { |
1245 | { |
1214 | careful = false; |
1246 | careful = false; |
1215 | |
1247 | |
1216 | if (!XftCharExists (DISPLAY, f, unicode)) |
1248 | if (!XftCharExists (term->xdisp, f, unicode)) |
1217 | return false; |
1249 | return false; |
1218 | |
1250 | |
1219 | if (!prop || prop->width == rxvt_fontprop::unset) |
1251 | if (!prop || prop->width == rxvt_fontprop::unset) |
1220 | return true; |
1252 | return true; |
1221 | |
1253 | |
1222 | // check character against base font bounding box |
1254 | // check character against base font bounding box |
1223 | FcChar32 ch = unicode; |
1255 | FcChar32 ch = unicode; |
1224 | XGlyphInfo g; |
1256 | XGlyphInfo g; |
1225 | XftTextExtents32 (DISPLAY, f, &ch, 1, &g); |
1257 | XftTextExtents32 (term->xdisp, f, &ch, 1, &g); |
1226 | |
1258 | |
1227 | int w = g.width; |
1259 | int w = g.width - g.x; |
1228 | int wcw = wcwidth (unicode); |
1260 | int wcw = WCWIDTH (unicode); |
1229 | if (wcw > 0) w /= wcw; |
1261 | if (wcw > 0) w = (w + wcw - 1) / wcw; |
1230 | |
1262 | |
1231 | careful = w > prop->width; |
1263 | careful = w > prop->width; |
1232 | if (careful && w > prop->width * MAX_OVERLAP >> 2) |
1264 | if (careful && OVERLAP_OK (w, prop)) |
1233 | return false; |
1265 | return false; |
1234 | |
1266 | |
1235 | return true; |
1267 | return true; |
1236 | } |
1268 | } |
1237 | |
1269 | |
1238 | void |
1270 | void |
1239 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1271 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1240 | const text_t *text, int len, |
1272 | const text_t *text, int len, |
1241 | int fg, int bg) |
1273 | int fg, int bg) |
1242 | { |
1274 | { |
1243 | clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
1275 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
1244 | |
|
|
1245 | int base = ascent; // should be fbase, but that is incorrect |
|
|
1246 | |
1276 | |
1247 | XGlyphInfo extents; |
1277 | XGlyphInfo extents; |
1248 | FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); |
1278 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1249 | FcChar32 *ep = enc; |
1279 | XftGlyphSpec *ep = enc; |
1250 | int ewidth = 0; |
1280 | |
1251 | int xoff = 0; |
1281 | dTermDisplay; |
|
|
1282 | dTermGC; |
|
|
1283 | |
|
|
1284 | // cut trailing spaces |
|
|
1285 | while (len && text [len - 1] == ' ') |
|
|
1286 | len--; |
1252 | |
1287 | |
1253 | while (len) |
1288 | while (len) |
1254 | { |
1289 | { |
1255 | int cwidth = r->TermWin.fwidth; |
1290 | int cwidth = term->fwidth; |
1256 | FcChar32 fc = *text++; len--; |
1291 | FcChar32 fc = *text++; len--; |
1257 | FT_UInt gl; |
|
|
1258 | |
1292 | |
1259 | while (len && *text == NOCHAR) |
1293 | while (len && *text == NOCHAR) |
1260 | text++, len--, cwidth += r->TermWin.fwidth; |
1294 | text++, len--, cwidth += term->fwidth; |
1261 | |
1295 | |
1262 | gl = XftCharIndex (d.display->display, f, fc); |
1296 | if (fc != ' ') // skip spaces |
1263 | XftGlyphExtents (d.display->display, f, &gl, 1, &extents); |
|
|
1264 | |
|
|
1265 | if (extents.xOff != cwidth && ep != enc) |
|
|
1266 | { |
|
|
1267 | if (xoff > ewidth) xoff = ewidth; |
|
|
1268 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
|
|
1269 | x + (ewidth - xoff >> 1), |
|
|
1270 | y + base, enc, ep - enc); |
|
|
1271 | x += ewidth; |
|
|
1272 | |
|
|
1273 | ep = enc; |
|
|
1274 | ewidth = 0; |
|
|
1275 | xoff = 0; |
|
|
1276 | } |
1297 | { |
|
|
1298 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
|
|
1299 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1277 | |
1300 | |
1278 | if (fc == ' ' && ep == enc) // skip leading spaces |
1301 | ep->glyph = glyph; |
|
|
1302 | ep->x = x + (cwidth - extents.xOff >> 1); |
|
|
1303 | ep->y = y + ascent; |
|
|
1304 | ep++; |
1279 | { |
1305 | } |
|
|
1306 | |
1280 | x += cwidth; |
1307 | x += cwidth; |
1281 | continue; |
|
|
1282 | } |
|
|
1283 | |
|
|
1284 | else |
|
|
1285 | { |
|
|
1286 | *ep++ = gl; |
|
|
1287 | ewidth += cwidth; |
|
|
1288 | xoff += extents.xOff; |
|
|
1289 | } |
|
|
1290 | } |
1308 | } |
1291 | |
1309 | |
1292 | if (ep != enc) |
1310 | if (ep != enc) |
1293 | { |
|
|
1294 | if (xoff > ewidth) xoff = ewidth; |
|
|
1295 | XftDrawGlyphs (d, &r->pix_colors[fg].c, f, |
1311 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1296 | x + (ewidth - xoff >> 1), |
|
|
1297 | y + base, enc, ep - enc); |
|
|
1298 | } |
|
|
1299 | } |
1312 | } |
1300 | #endif |
1313 | #endif |
1301 | |
1314 | |
1302 | ///////////////////////////////////////////////////////////////////////////// |
1315 | ///////////////////////////////////////////////////////////////////////////// |
1303 | |
1316 | |
1304 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
1317 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
1305 | : r (r), fontdesc (0) |
1318 | : fontdesc (0), term (term) |
1306 | { |
1319 | { |
1307 | clear (); |
1320 | clear (); |
1308 | } |
1321 | } |
1309 | |
1322 | |
1310 | rxvt_fontset::~rxvt_fontset () |
1323 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
1313 | } |
1326 | } |
1314 | |
1327 | |
1315 | void |
1328 | void |
1316 | rxvt_fontset::clear () |
1329 | rxvt_fontset::clear () |
1317 | { |
1330 | { |
1318 | prop.width = prop.height = prop.weight = prop.slant |
1331 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1319 | = rxvt_fontprop::unset; |
1332 | = rxvt_fontprop::unset; |
1320 | |
1333 | |
1321 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1334 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1322 | FONT_UNREF (*i); |
1335 | FONT_UNREF (*i); |
1323 | |
1336 | |
… | |
… | |
1354 | f = new rxvt_font_x11; |
1367 | f = new rxvt_font_x11; |
1355 | } |
1368 | } |
1356 | else |
1369 | else |
1357 | f = new rxvt_font_x11; |
1370 | f = new rxvt_font_x11; |
1358 | |
1371 | |
1359 | f->set_term (r); |
1372 | f->set_term (term); |
1360 | f->set_name (strdup (name)); |
1373 | f->set_name (strdup (name)); |
1361 | |
1374 | |
1362 | f->cs = cs; |
1375 | f->cs = cs; |
1363 | f->loaded = false; |
1376 | f->loaded = false; |
1364 | |
1377 | |
… | |
… | |
1375 | char buf[512]; |
1388 | char buf[512]; |
1376 | const char *end; |
1389 | const char *end; |
1377 | |
1390 | |
1378 | do |
1391 | do |
1379 | { |
1392 | { |
1380 | while (*desc <= ' ') desc++; |
1393 | while (*desc && *desc <= ' ') |
|
|
1394 | desc++; |
1381 | |
1395 | |
1382 | codeset cs = CS_UNICODE; |
1396 | codeset cs = CS_UNICODE; |
1383 | |
1397 | |
1384 | if (*desc == '[') |
1398 | if (*desc == '[') |
1385 | { |
1399 | { |
… | |
… | |
1495 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1509 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1496 | goto next_font; |
1510 | goto next_font; |
1497 | |
1511 | |
1498 | if (!realize_font (i)) |
1512 | if (!realize_font (i)) |
1499 | goto next_font; |
1513 | goto next_font; |
|
|
1514 | |
|
|
1515 | if (prop.ascent != rxvt_fontprop::unset) |
|
|
1516 | max_it (f->ascent, prop.ascent); |
1500 | } |
1517 | } |
1501 | |
1518 | |
1502 | if (f->cs == CS_UNKNOWN) |
1519 | if (f->cs == CS_UNKNOWN) |
1503 | goto next_font; |
1520 | goto next_font; |
1504 | |
1521 | |
… | |
… | |
1543 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1560 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1544 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1561 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1545 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1562 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1546 | |
1563 | |
1547 | XftResult result; |
1564 | XftResult result; |
1548 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
1565 | FcPattern *match = XftFontMatch (term->xdisp, term->display->screen, p, &result); |
1549 | |
1566 | |
1550 | FcPatternDestroy (p); |
1567 | FcPatternDestroy (p); |
1551 | |
1568 | |
1552 | if (match) |
1569 | if (match) |
1553 | { |
1570 | { |