… | |
… | |
21 | |
21 | |
22 | #include "../config.h" |
22 | #include "../config.h" |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
24 | #include "defaultfont.h" |
24 | #include "defaultfont.h" |
25 | |
25 | |
|
|
26 | #include <cstdlib> |
|
|
27 | |
26 | #define DISPLAY R->Xdisplay |
28 | #define DISPLAY r->Xdisplay |
27 | #define DRAWABLE R->TermWin.vt |
29 | #define DRAWABLE r->TermWin.vt |
28 | #define GC R->TermWin.gc |
30 | #define GC r->TermWin.gc |
29 | |
31 | |
30 | const struct rxvt_fallback_font { |
32 | const struct rxvt_fallback_font { |
31 | codeset cs; |
33 | codeset cs; |
32 | const char *name; |
34 | const char *name; |
33 | } fallback_fonts[] = { |
35 | } fallback_fonts[] = { |
… | |
… | |
57 | |
59 | |
58 | // japanese |
60 | // japanese |
59 | #if ENCODING_JP || ENCODING_JP_EXT |
61 | #if ENCODING_JP || ENCODING_JP_EXT |
60 | # if XFT |
62 | # if XFT |
61 | // prefer xft for complex scripts |
63 | // prefer xft for complex scripts |
62 | { CS_UNICODE, "xft:Kochi Gothic" }, |
64 | { CS_UNICODE, "xft:Kochi Gothic:antialias=false" }, |
63 | # endif |
65 | # endif |
64 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
66 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
65 | { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
67 | { CS_JIS0208_1983_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
66 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
68 | { CS_JIS0212_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0212*-0" }, |
67 | #endif |
69 | #endif |
… | |
… | |
163 | { |
165 | { |
164 | if (color == Color_bg) |
166 | if (color == Color_bg) |
165 | XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); |
167 | XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE); |
166 | else if (color >= 0) |
168 | else if (color >= 0) |
167 | { |
169 | { |
168 | XSetForeground (DISPLAY, GC, R->PixColors[color]); |
170 | XSetForeground (DISPLAY, GC, r->PixColors[color]); |
169 | XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
171 | XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h); |
170 | } |
172 | } |
171 | } |
173 | } |
172 | |
174 | |
|
|
175 | static const char *linedraw_cmds[128] = { |
|
|
176 | "1hH", "2hH", "1vV", "2vV", |
|
|
177 | 0, 0, 0, 0, |
|
|
178 | 0, 0, 0, 0, |
|
|
179 | "1HV", "2H1V", "1H2V", "2HV", |
|
|
180 | |
|
|
181 | // 2510 |
|
|
182 | "1hV", "2h1V", "1h2V", "2hV", |
|
|
183 | "1Hv", "2H1v", "1H2v", "2Hv", |
|
|
184 | "1hv", "2h1v", "1h2v", "2hv", |
|
|
185 | "1HvV", "2H1vV", "1HV2v", "1Hv2V", |
|
|
186 | |
|
|
187 | // 2520 |
|
|
188 | "1H2vV", "2Hv1V", "2HV1v", "2HvV", |
|
|
189 | "1hvV", "2h1vV", "1hV2v", "1hv2V", |
|
|
190 | "1h2vV", "2hv1V", "1v2hV", "2hvV", |
|
|
191 | "1hHV", "2h1HV", "2H1hV", "2hH1V", |
|
|
192 | |
|
|
193 | // 2530 |
|
|
194 | "1hH2V", "2hV1H", "1h2HV", "2hHV", |
|
|
195 | "1hHv", "1vH2h", "1hv2H", "1v2hH", |
|
|
196 | "1hH2v", "1H2hv", "1h2Hv", "2hHv", |
|
|
197 | "1hHvV", "1vVH2h", "1hvV2H", "1vV2hH", |
|
|
198 | |
|
|
199 | // 2540 |
|
|
200 | "1hHV2v", "1hHv2V", "1hH2vV", "1HV2hv", |
|
|
201 | "1hV2Hv", "1Hv2hV", "1hv2HV", "1V2hHv", |
|
|
202 | "1v2hHV", "1H2hvV", "1h2HvV", "2hHvV", |
|
|
203 | 0, 0, 0, 0, |
|
|
204 | |
|
|
205 | // 2550 |
|
|
206 | 0, 0, 0, 0, |
|
|
207 | 0, 0, 0, 0, |
|
|
208 | 0, 0, 0, 0, |
|
|
209 | 0, 0, 0, 0, |
|
|
210 | |
|
|
211 | // 2560 |
|
|
212 | 0, 0, 0, 0, |
|
|
213 | 0, 0, 0, 0, |
|
|
214 | 0, 0, 0, 0, |
|
|
215 | 0, 0, 0, 0, |
|
|
216 | |
|
|
217 | // 2570 |
|
|
218 | 0, "1a", "1b", "1ab", |
|
|
219 | "1h", "1v", "1H", "1V", |
|
|
220 | "2h", "2v", "2H", "2V", |
|
|
221 | "1h2H", "1v2V", "1H2h", "1V2v" |
|
|
222 | |
|
|
223 | // to be done |
|
|
224 | }; |
|
|
225 | |
173 | struct rxvt_font_default : rxvt_font { |
226 | struct rxvt_font_default : rxvt_font { |
174 | bool load (int maxheight) |
227 | rxvt_fontprop properties () |
|
|
228 | { |
|
|
229 | rxvt_fontprop p; |
|
|
230 | |
|
|
231 | p.height = 1; |
|
|
232 | p.weight = rxvt_fontprop::medium; |
|
|
233 | p.slant = rxvt_fontprop::roman; |
|
|
234 | |
|
|
235 | return p; |
|
|
236 | } |
|
|
237 | |
|
|
238 | bool load (const rxvt_fontprop &prop) |
175 | { |
239 | { |
176 | width = 1; height = 1; |
240 | width = 1; height = 1; |
177 | ascent = 1; descent = 0; |
241 | ascent = 1; descent = 0; |
178 | |
242 | |
179 | return true; |
243 | return true; |
180 | } |
244 | } |
181 | |
245 | |
182 | bool has_codepoint (uint32_t unicode) |
246 | bool has_codepoint (uint32_t unicode) |
183 | { |
247 | { |
184 | if (unicode <= 0x001f |
248 | if (unicode <= 0x001f) |
|
|
249 | return true; |
185 | || (unicode >= 0x80 && unicode <= 0x9f)) |
250 | if (unicode >= 0x0080 && unicode <= 0x009f) |
|
|
251 | return true; |
|
|
252 | |
|
|
253 | if (unicode >= 0x2500 && unicode <= 0x257f |
|
|
254 | && linedraw_cmds[unicode - 0x2500]) |
186 | return true; |
255 | return true; |
187 | |
256 | |
188 | switch (unicode) |
257 | switch (unicode) |
189 | { |
258 | { |
190 | case ZERO_WIDTH_CHAR: |
259 | case ZERO_WIDTH_CHAR: |
… | |
… | |
202 | void |
271 | void |
203 | rxvt_font_default::draw (int x, int y, |
272 | rxvt_font_default::draw (int x, int y, |
204 | const text_t *text, int len, |
273 | const text_t *text, int len, |
205 | int fg, int bg) |
274 | int fg, int bg) |
206 | { |
275 | { |
207 | clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); |
276 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
|
|
277 | |
|
|
278 | XSetForeground (DISPLAY, GC, r->PixColors[fg]); |
208 | |
279 | |
209 | while (len--) |
280 | while (len--) |
210 | { |
281 | { |
|
|
282 | text_t t = *text++; |
|
|
283 | |
|
|
284 | if (t >= 0x2500 & t <= 0x2580 && linedraw_cmds[t - 0x2500]) |
|
|
285 | { |
|
|
286 | const char *p = linedraw_cmds[t - 0x2500]; |
|
|
287 | |
|
|
288 | int x0 = x, x1 = x + r->TermWin.fwidth / 2, x2 = x + r->TermWin.fwidth ; |
|
|
289 | int y0 = y, y1 = y + r->TermWin.fheight / 2, y2 = y + r->TermWin.fheight; |
|
|
290 | |
|
|
291 | XGCValues gcv; |
|
|
292 | |
|
|
293 | while (*p) |
|
|
294 | { |
|
|
295 | switch (*p++) |
|
|
296 | { |
|
|
297 | case '1': |
|
|
298 | gcv.line_width = 0; |
|
|
299 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
300 | break; |
|
|
301 | |
|
|
302 | case '2': |
|
|
303 | gcv.line_width = 2; |
|
|
304 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
305 | break; |
|
|
306 | |
|
|
307 | case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break; |
|
|
308 | case 'H': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x2, y1); break; |
|
|
309 | case 'v': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y0, x1, y1); break; |
|
|
310 | case 'V': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x1, y2); break; |
|
|
311 | case 'a': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y2, x2, y0); break; |
|
|
312 | case 'b': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y0, x2, y2); break; |
|
|
313 | } |
|
|
314 | } |
|
|
315 | |
|
|
316 | gcv.line_width = 0; |
|
|
317 | XChangeGC (DISPLAY, GC, GCLineWidth, &gcv); |
|
|
318 | } |
|
|
319 | else |
211 | switch (*text++) |
320 | switch (*text++) |
212 | { |
321 | { |
213 | case NOCHAR: |
322 | case NOCHAR: |
214 | case ZERO_WIDTH_CHAR: |
323 | case ZERO_WIDTH_CHAR: |
215 | break; |
324 | break; |
216 | default: |
325 | default: |
217 | XSetForeground (DISPLAY, GC, R->PixColors[fg]); |
|
|
218 | XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, R->TermWin.fwidth - 5, R->TermWin.fheight - 5); |
326 | XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5); |
219 | } |
327 | } |
220 | |
328 | |
221 | x += R->TermWin.fwidth; |
329 | x += r->TermWin.fwidth; |
222 | } |
330 | } |
223 | } |
331 | } |
224 | |
332 | |
225 | ///////////////////////////////////////////////////////////////////////////// |
333 | ///////////////////////////////////////////////////////////////////////////// |
226 | |
334 | |
227 | struct rxvt_font_x11 : rxvt_font { |
335 | struct rxvt_font_x11 : rxvt_font { |
228 | rxvt_font_x11 () { f = 0; } |
336 | rxvt_font_x11 () { f = 0; } |
229 | |
337 | |
230 | void clear (); |
338 | void clear (); |
231 | |
339 | |
232 | bool load (int maxheight); |
340 | rxvt_fontprop properties (); |
|
|
341 | rxvt_fontprop properties (XFontStruct *f); |
|
|
342 | |
|
|
343 | bool load (const rxvt_fontprop &prop); |
233 | |
344 | |
234 | bool has_codepoint (uint32_t unicode); |
345 | bool has_codepoint (uint32_t unicode); |
235 | |
346 | |
236 | void draw (int x, int y, |
347 | void draw (int x, int y, |
237 | const text_t *text, int len, |
348 | const text_t *text, int len, |
… | |
… | |
239 | |
350 | |
240 | XFontStruct *f; |
351 | XFontStruct *f; |
241 | codeset cs; |
352 | codeset cs; |
242 | bool enc2b, encm; |
353 | bool enc2b, encm; |
243 | |
354 | |
244 | const char *get_property (const char *property, const char *repl) const; |
355 | const char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
245 | }; |
356 | }; |
246 | |
357 | |
247 | const char * |
358 | const char * |
248 | rxvt_font_x11::get_property (const char *property, const char *repl) const |
359 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
249 | { |
360 | { |
250 | unsigned long value; |
361 | unsigned long value; |
251 | |
362 | |
252 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
363 | if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) |
253 | return XGetAtomName (DISPLAY, value); |
364 | return XGetAtomName (DISPLAY, value); |
254 | else |
365 | else |
255 | return repl; |
366 | return repl; |
256 | } |
367 | } |
257 | |
368 | |
|
|
369 | rxvt_fontprop |
|
|
370 | rxvt_font_x11::properties () |
|
|
371 | { |
|
|
372 | return properties (f); |
|
|
373 | } |
|
|
374 | |
|
|
375 | rxvt_fontprop |
|
|
376 | rxvt_font_x11::properties (XFontStruct *f) |
|
|
377 | { |
|
|
378 | rxvt_fontprop p; |
|
|
379 | |
|
|
380 | const char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
|
|
381 | const char *slant = get_property (f, "SLANT", "r"); |
|
|
382 | |
|
|
383 | p.height = height; |
|
|
384 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
|
|
385 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
|
|
386 | |
|
|
387 | return p; |
|
|
388 | } |
|
|
389 | |
258 | bool |
390 | bool |
259 | rxvt_font_x11::load (int maxheight) |
391 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
260 | { |
392 | { |
261 | clear (); |
393 | clear (); |
|
|
394 | |
|
|
395 | char **list; |
|
|
396 | int count; |
|
|
397 | XFontStruct *info; |
|
|
398 | list = XListFontsWithInfo (DISPLAY, name, 128, &count, &info); |
|
|
399 | |
|
|
400 | if (!list) |
|
|
401 | return false; |
|
|
402 | |
|
|
403 | int bestdiff = 0x7fffffff; |
|
|
404 | XFontStruct *best = 0; |
|
|
405 | for (int i = 0; i < count; i++) |
|
|
406 | { |
|
|
407 | XFontStruct *f = info + i; |
|
|
408 | |
|
|
409 | if (f->ascent + f->descent <= prop.height) // weed out too large fonts |
|
|
410 | { |
|
|
411 | rxvt_fontprop p = properties (f); |
|
|
412 | int diff = (prop.height - f->ascent + f->descent) * 32 |
|
|
413 | + abs (prop.weight - p.weight) |
|
|
414 | + abs (prop.slant - p.slant ); |
|
|
415 | |
|
|
416 | if (!best // compare against best found so far |
|
|
417 | || diff < bestdiff) |
|
|
418 | { |
|
|
419 | best = f; |
|
|
420 | bestdiff = diff; |
|
|
421 | } |
|
|
422 | } |
|
|
423 | } |
|
|
424 | |
|
|
425 | set_name (strdup (list[best - info])); |
|
|
426 | |
|
|
427 | XFreeFontInfo (list, info, count); |
262 | |
428 | |
263 | f = XLoadQueryFont (DISPLAY, name); |
429 | f = XLoadQueryFont (DISPLAY, name); |
264 | |
430 | |
265 | if (!f) |
431 | if (!f) |
266 | return false; |
432 | return false; |
267 | |
433 | |
268 | unsigned long value; |
434 | unsigned long value; |
269 | |
435 | |
270 | const char *registry = get_property ("CHARSET_REGISTRY", 0); |
436 | const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
271 | const char *encoding = get_property ("CHARSET_ENCODING", 0); |
437 | const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
272 | |
438 | |
273 | if (registry && encoding) |
439 | if (registry && encoding) |
274 | { |
440 | { |
275 | char charset[64]; |
441 | char charset[64]; |
276 | snprintf (charset, 64, "%s-%s", registry, encoding); |
442 | snprintf (charset, 64, "%s-%s", registry, encoding); |
277 | |
443 | |
278 | cs = codeset_from_name (charset); |
444 | cs = codeset_from_name (charset); |
279 | } |
445 | } |
280 | else |
446 | else |
281 | { |
447 | { |
282 | const char *charset = get_property ("FONT", 0); |
448 | const char *charset = get_property (f, "FONT", 0); |
283 | |
449 | |
284 | if (!charset) |
450 | if (!charset) |
285 | charset = name; |
451 | charset = name; |
286 | |
452 | |
287 | int count = 13; |
453 | int count = 13; |
… | |
… | |
300 | |
466 | |
301 | ascent = f->ascent; |
467 | ascent = f->ascent; |
302 | descent = f->descent; |
468 | descent = f->descent; |
303 | height = ascent + descent; |
469 | height = ascent + descent; |
304 | |
470 | |
305 | prop = false; |
471 | slow = false; |
306 | |
472 | |
307 | if (f->min_bounds.width == f->max_bounds.width) |
473 | if (f->min_bounds.width == f->max_bounds.width) |
308 | width = f->min_bounds.width; |
474 | width = f->min_bounds.width; |
309 | else if (f->per_char == NULL) |
475 | else if (f->per_char == NULL) |
310 | width = f->max_bounds.width; |
476 | width = f->max_bounds.width; |
311 | else |
477 | else |
312 | { |
478 | { |
313 | prop = true; |
479 | slow = true; |
314 | |
480 | |
315 | int N = f->max_char_or_byte2 - f->min_char_or_byte2; |
481 | int N = f->max_char_or_byte2 - f->min_char_or_byte2; |
316 | |
482 | |
317 | if (encm) |
483 | if (encm) |
318 | N += (f->max_byte1 - f->min_byte1) |
484 | N += (f->max_byte1 - f->min_byte1) |
… | |
… | |
403 | // this looks like a mess /. |
569 | // this looks like a mess /. |
404 | // and it is a mess /. |
570 | // and it is a mess /. |
405 | // yet we are trying to be perfect /. |
571 | // yet we are trying to be perfect /. |
406 | // but the result still isn't perfect /. |
572 | // but the result still isn't perfect /. |
407 | |
573 | |
408 | bool slow = prop |
574 | bool slow = this->slow |
409 | || width != R->TermWin.fwidth |
575 | || width != r->TermWin.fwidth |
410 | || height != R->TermWin.fheight; |
576 | || height != r->TermWin.fheight; |
411 | |
577 | |
412 | int base = R->TermWin.fbase; |
578 | int base = r->TermWin.fbase; |
413 | |
579 | |
414 | XGCValues v; |
580 | XGCValues v; |
415 | v.foreground = R->PixColors[fg]; |
581 | v.foreground = r->PixColors[fg]; |
416 | v.background = R->PixColors[bg]; |
582 | v.background = r->PixColors[bg]; |
417 | v.font = f->fid; |
583 | v.font = f->fid; |
418 | |
584 | |
419 | if (enc2b) |
585 | if (enc2b) |
420 | { |
586 | { |
421 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
587 | const XChar2b *xc = enc_xchar2b (text, len, cs, slow); |
… | |
… | |
425 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
591 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
426 | XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
592 | XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
427 | } |
593 | } |
428 | else |
594 | else |
429 | { |
595 | { |
430 | clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); |
596 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
431 | |
597 | |
432 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
598 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
433 | |
599 | |
434 | if (slow) |
600 | if (slow) |
435 | { |
601 | { |
436 | do |
602 | do |
437 | { |
603 | { |
438 | if (xc->byte1 || xc->byte2) |
604 | if (xc->byte1 || xc->byte2) |
439 | XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
605 | XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
440 | |
606 | |
441 | x += R->TermWin.fwidth; |
607 | x += r->TermWin.fwidth; |
442 | xc++; len--; |
608 | xc++; len--; |
443 | } |
609 | } |
444 | while (len); |
610 | while (len); |
445 | } |
611 | } |
446 | else |
612 | else |
… | |
… | |
456 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
622 | XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v); |
457 | XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
623 | XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len); |
458 | } |
624 | } |
459 | else |
625 | else |
460 | { |
626 | { |
461 | clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); |
627 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
462 | |
628 | |
463 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
629 | XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v); |
464 | |
630 | |
465 | if (slow) |
631 | if (slow) |
466 | { |
632 | { |
467 | do |
633 | do |
468 | { |
634 | { |
469 | if (*xc) |
635 | if (*xc) |
470 | XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
636 | XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1); |
471 | |
637 | |
472 | x += R->TermWin.fwidth; |
638 | x += r->TermWin.fwidth; |
473 | xc++; len--; |
639 | xc++; len--; |
474 | } |
640 | } |
475 | while (len); |
641 | while (len); |
476 | } |
642 | } |
477 | else |
643 | else |
… | |
… | |
518 | #endif |
684 | #endif |
519 | rxvt_font_xft () { f = 0; d = 0; } |
685 | rxvt_font_xft () { f = 0; d = 0; } |
520 | |
686 | |
521 | void clear (); |
687 | void clear (); |
522 | |
688 | |
523 | bool load (int maxheight); |
689 | rxvt_fontprop properties (); |
|
|
690 | |
|
|
691 | bool load (const rxvt_fontprop &prop); |
524 | |
692 | |
525 | void draw (int x, int y, |
693 | void draw (int x, int y, |
526 | const text_t *text, int len, |
694 | const text_t *text, int len, |
527 | int fg, int bg); |
695 | int fg, int bg); |
528 | |
696 | |
… | |
… | |
544 | void |
712 | void |
545 | rxvt_font_xft::clear () |
713 | rxvt_font_xft::clear () |
546 | { |
714 | { |
547 | if (f) |
715 | if (f) |
548 | { |
716 | { |
549 | XftFontClose (R->Xdisplay, f); |
717 | XftFontClose (DISPLAY, f); |
550 | f = 0; |
718 | f = 0; |
551 | } |
719 | } |
552 | |
720 | |
553 | if (d) |
721 | if (d) |
554 | { |
722 | { |
… | |
… | |
560 | for (int i = 0; i < SWATHCOUNT; i++) |
728 | for (int i = 0; i < SWATHCOUNT; i++) |
561 | delete cvr[i]; |
729 | delete cvr[i]; |
562 | #endif |
730 | #endif |
563 | } |
731 | } |
564 | |
732 | |
|
|
733 | rxvt_fontprop |
|
|
734 | rxvt_font_xft::properties () |
|
|
735 | { |
|
|
736 | rxvt_fontprop p; |
|
|
737 | |
|
|
738 | FT_Face face = XftLockFace (f); |
|
|
739 | |
|
|
740 | p.height = height; |
|
|
741 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
|
|
742 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
|
|
743 | |
|
|
744 | XftUnlockFace (f); |
|
|
745 | |
|
|
746 | return p; |
|
|
747 | } |
|
|
748 | |
565 | bool |
749 | bool |
566 | rxvt_font_xft::load (int maxheight) |
750 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
567 | { |
751 | { |
568 | #if 0 |
752 | #if 0 |
569 | for (int i = 0; i < SWATHCOUNT; i++) |
753 | for (int i = 0; i < SWATHCOUNT; i++) |
570 | cvr[i] = 0; |
754 | cvr[i] = 0; |
571 | #endif |
755 | #endif |
572 | |
756 | |
573 | clear (); |
757 | clear (); |
574 | |
758 | |
575 | f = XftFontOpenName (R->Xdisplay, DefaultScreen (R->Xdisplay), name); |
759 | FcPattern *p = FcNameParse ((FcChar8 *) name); |
|
|
760 | |
|
|
761 | if (!p) |
|
|
762 | return false; |
|
|
763 | |
|
|
764 | FcValue v; |
|
|
765 | |
|
|
766 | if (FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
|
|
767 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
|
|
768 | |
|
|
769 | if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
|
|
770 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
|
|
771 | |
|
|
772 | //FcPatternAddBool (p, FC_MINSPACE, 1); |
|
|
773 | |
|
|
774 | XftResult result; |
|
|
775 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
|
|
776 | |
|
|
777 | FcPatternDestroy (p); |
|
|
778 | |
|
|
779 | if (!match) |
|
|
780 | return false; |
|
|
781 | |
|
|
782 | f = XftFontOpenPattern (DISPLAY, match); |
576 | |
783 | |
577 | if (!f) |
784 | if (!f) |
|
|
785 | { |
|
|
786 | FcPatternDestroy (match); |
578 | return false; |
787 | return false; |
|
|
788 | } |
579 | |
789 | |
580 | FT_Face face = XftLockFace (f); |
790 | FT_Face face = XftLockFace (f); |
581 | |
791 | |
582 | prop = !FT_IS_FIXED_WIDTH (face); |
792 | slow = !FT_IS_FIXED_WIDTH (face); |
583 | |
793 | |
584 | int ftheight = 0; |
794 | int ftheight = 0; |
585 | |
795 | |
586 | for (;;) |
796 | for (;;) |
587 | { |
797 | { |
588 | XGlyphInfo g1, g2; |
798 | XGlyphInfo g1, g2; |
589 | FcChar8 c; |
799 | FcChar8 c; |
590 | |
800 | |
591 | c = 'i'; XftTextExtents8 (R->Xdisplay, f, &c, 1, &g1); |
801 | c = 'i'; XftTextExtents8 (DISPLAY, f, &c, 1, &g1); |
592 | c = 'W'; XftTextExtents8 (R->Xdisplay, f, &c, 1, &g2); |
802 | c = 'W'; XftTextExtents8 (DISPLAY, f, &c, 1, &g2); |
593 | |
803 | |
594 | prop = prop || g1.xOff != g2.xOff; // don't simply trust the font |
804 | if (g1.xOff != g2.xOff) // don't simply trust the font |
|
|
805 | slow = true; |
595 | |
806 | |
596 | width = g2.xOff; |
807 | width = g2.xOff; |
597 | ascent = (face->size->metrics.ascender + 63) >> 6; |
808 | ascent = (face->size->metrics.ascender + 63) >> 6; |
598 | descent = (-face->size->metrics.descender + 63) >> 6; |
809 | descent = (-face->size->metrics.descender + 63) >> 6; |
599 | height = ascent + descent; |
810 | height = ascent + descent; |
600 | |
811 | |
601 | if (height <= maxheight || !maxheight) |
812 | if (height <= prop.height || !prop.height) |
602 | break; |
813 | break; |
603 | |
814 | |
604 | if (ftheight) |
815 | if (ftheight) |
605 | { |
816 | { |
606 | // take smaller steps near the end |
817 | // take smaller steps near the end |
607 | if (height > maxheight + 1) ftheight++; |
818 | if (height > prop.height + 1) ftheight++; |
608 | if (height > maxheight + 2) ftheight++; |
819 | if (height > prop.height + 2) ftheight++; |
609 | if (height > maxheight + 3) ftheight++; |
820 | if (height > prop.height + 3) ftheight++; |
610 | |
821 | |
611 | FT_Set_Pixel_Sizes (face, 0, ftheight -= height - maxheight); |
822 | FT_Set_Pixel_Sizes (face, 0, ftheight -= height - prop.height); |
612 | } |
823 | } |
613 | else |
824 | else |
614 | FT_Set_Pixel_Sizes (face, 0, ftheight = maxheight); |
825 | FT_Set_Pixel_Sizes (face, 0, ftheight = prop.height); |
615 | } |
826 | } |
616 | |
827 | |
617 | XftUnlockFace (f); |
828 | XftUnlockFace (f); |
618 | |
829 | |
619 | return true; |
830 | return true; |
… | |
… | |
632 | #endif |
843 | #endif |
633 | |
844 | |
634 | bool |
845 | bool |
635 | rxvt_font_xft::has_codepoint (uint32_t unicode) |
846 | rxvt_font_xft::has_codepoint (uint32_t unicode) |
636 | { |
847 | { |
637 | return XftCharExists (R->Xdisplay, f, unicode); |
848 | return XftCharExists (DISPLAY, f, unicode); |
638 | } |
849 | } |
639 | |
850 | |
640 | void |
851 | void |
641 | rxvt_font_xft::draw (int x, int y, |
852 | rxvt_font_xft::draw (int x, int y, |
642 | const text_t *text, int len, |
853 | const text_t *text, int len, |
643 | int fg, int bg) |
854 | int fg, int bg) |
644 | { |
855 | { |
645 | if (!d) |
856 | if (!d) |
|
|
857 | { |
|
|
858 | dR; |
646 | d = XftDrawCreate (R->Xdisplay, DRAWABLE, XVISUAL, XCMAP); |
859 | d = XftDrawCreate (DISPLAY, DRAWABLE, XVISUAL, XCMAP); |
|
|
860 | } |
647 | |
861 | |
648 | if (bg >= 0 && bg != Color_bg) |
862 | if (bg >= 0 && bg != Color_bg) |
649 | XftDrawRect (d, &R->PixColors[bg].c, x, y, R->TermWin.fwidth * len, R->TermWin.fheight); |
863 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
650 | else |
864 | else |
651 | clear_rect (x, y, R->TermWin.fwidth * len, R->TermWin.fheight, bg); |
865 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
652 | |
866 | |
653 | if (!prop && width == R->TermWin.fwidth) |
867 | if (!slow && width == r->TermWin.fwidth) |
654 | { |
868 | { |
655 | if (sizeof (text_t) == sizeof (FcChar16)) |
869 | if (sizeof (text_t) == sizeof (FcChar16)) |
656 | XftDrawString16 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar16 *)text, len); |
870 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
657 | else |
871 | else |
658 | XftDrawString32 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar32 *)text, len); |
872 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
659 | } |
873 | } |
660 | else |
874 | else |
661 | { |
875 | { |
662 | while (len) |
876 | while (len) |
663 | { |
877 | { |
664 | if (*text != NOCHAR && *text != ' ') |
878 | if (*text != NOCHAR && *text != ' ') |
665 | { |
879 | { |
666 | if (sizeof (text_t) == sizeof (FcChar16)) |
880 | if (sizeof (text_t) == sizeof (FcChar16)) |
667 | XftDrawString16 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar16 *)text, 1); |
881 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
668 | else |
882 | else |
669 | XftDrawString32 (d, &R->PixColors[fg].c, f, x, y + R->TermWin.fbase, (const FcChar32 *)text, 1); |
883 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
670 | } |
884 | } |
671 | |
885 | |
672 | x += R->TermWin.fwidth; |
886 | x += r->TermWin.fwidth; |
673 | text++; |
887 | text++; |
674 | len--; |
888 | len--; |
675 | } |
889 | } |
676 | } |
890 | } |
677 | } |
891 | } |
678 | #endif |
892 | #endif |
679 | |
893 | |
680 | ///////////////////////////////////////////////////////////////////////////// |
894 | ///////////////////////////////////////////////////////////////////////////// |
681 | |
895 | |
682 | rxvt_fontset::rxvt_fontset (pR) |
896 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
683 | #ifdef EXPLICIT_CONTEXT |
897 | #ifdef EXPLICIT_CONTEXT |
684 | : rxvt_term(R) |
898 | : r(r) |
685 | #endif |
899 | #endif |
686 | { |
900 | { |
687 | clear (); |
901 | clear (); |
688 | } |
902 | } |
689 | |
903 | |
… | |
… | |
698 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
912 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
699 | FONT_UNREF (*i); |
913 | FONT_UNREF (*i); |
700 | |
914 | |
701 | fonts.clear (); |
915 | fonts.clear (); |
702 | base_id = 0; |
916 | base_id = 0; |
703 | height = 0x7fffffff; |
917 | base_prop.height = 0x7fffffff; |
|
|
918 | base_prop.weight = rxvt_fontprop::medium; |
|
|
919 | base_prop.slant = rxvt_fontprop::roman; |
704 | |
920 | |
705 | fallback = fallback_fonts; |
921 | fallback = fallback_fonts; |
706 | } |
922 | } |
707 | |
923 | |
708 | rxvt_font * |
924 | rxvt_font * |
… | |
… | |
728 | f = new rxvt_font_x11; |
944 | f = new rxvt_font_x11; |
729 | } |
945 | } |
730 | else |
946 | else |
731 | f = new rxvt_font_x11; |
947 | f = new rxvt_font_x11; |
732 | |
948 | |
733 | f->set_term (aR); |
949 | f->set_term (r); |
734 | f->set_name (strdup (name)); |
950 | f->set_name (strdup (name)); |
735 | |
951 | |
736 | f->cs = cs; |
952 | f->cs = cs; |
737 | f->loaded = false; |
953 | f->loaded = false; |
738 | |
954 | |
… | |
… | |
793 | rxvt_fontset::realize_font (int i) |
1009 | rxvt_fontset::realize_font (int i) |
794 | { |
1010 | { |
795 | if (fonts[i]->loaded) |
1011 | if (fonts[i]->loaded) |
796 | return true; |
1012 | return true; |
797 | |
1013 | |
798 | if (fonts[i]->load (height)) |
|
|
799 | return fonts[i]->loaded = true; |
1014 | fonts[i]->loaded = true; |
800 | |
1015 | |
801 | delete fonts[i]; |
1016 | if (!fonts[i]->load (base_prop)) |
802 | fonts.erase (fonts.begin () + i); |
1017 | { |
803 | |
1018 | fonts[i]->cs = CS_UNKNOWN; |
804 | return false; |
1019 | return false; |
|
|
1020 | } |
|
|
1021 | |
|
|
1022 | return true; |
805 | } |
1023 | } |
806 | |
1024 | |
807 | void |
1025 | void |
808 | rxvt_fontset::populate (const char *desc) |
1026 | rxvt_fontset::populate (const char *desc) |
809 | { |
1027 | { |
… | |
… | |
816 | |
1034 | |
817 | if (!base_id) |
1035 | if (!base_id) |
818 | base_id = 1; |
1036 | base_id = 1; |
819 | |
1037 | |
820 | // we currently need a base-font, no matter what |
1038 | // we currently need a base-font, no matter what |
821 | if (fonts.size () <= base_id) |
1039 | if (fonts.size () <= base_id || !realize_font (base_id)) |
822 | { |
1040 | { |
823 | add_fonts ("fixed"); |
1041 | add_fonts ("fixed"); |
824 | base_id = 1; |
1042 | base_id = fonts.size () - 1; |
825 | } |
1043 | } |
826 | |
1044 | |
827 | if (fonts.size () <= base_id || !realize_font (base_id)) |
1045 | if (fonts.size () <= base_id || !realize_font (base_id)) |
828 | { |
1046 | { |
829 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
1047 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
830 | exit (1); |
1048 | exit (1); |
831 | } |
1049 | } |
832 | |
1050 | |
833 | height = fonts[base_id]->height; |
1051 | base_prop = fonts[base_id]->properties (); |
834 | |
|
|
835 | /*add_fonts ("-efont-fixed-medium-r-normal-*-14-*-*-*-*-*-iso10646-1,"*/ |
|
|
836 | } |
1052 | } |
837 | |
1053 | |
838 | int |
1054 | int |
839 | rxvt_fontset::find_font (uint32_t unicode) |
1055 | rxvt_fontset::find_font (uint32_t unicode) |
840 | { |
1056 | { |
… | |
… | |
846 | { |
1062 | { |
847 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
1063 | if (FROM_UNICODE (f->cs, unicode) == NOCHAR) |
848 | goto next_font; |
1064 | goto next_font; |
849 | |
1065 | |
850 | if (!realize_font (i)) |
1066 | if (!realize_font (i)) |
851 | { |
|
|
852 | --i; |
|
|
853 | goto next_font; |
1067 | goto next_font; |
854 | } |
1068 | } |
855 | |
1069 | |
856 | //printf ("added font %s for %04lx\n", f->name, unicode); |
|
|
857 | } |
|
|
858 | |
|
|
859 | if (f->has_codepoint (unicode)) |
1070 | if (f->cs != CS_UNKNOWN && f->has_codepoint (unicode)) |
860 | return i; |
1071 | return i; |
861 | |
1072 | |
862 | next_font: |
1073 | next_font: |
863 | if (i == fonts.size () - 1 && fallback->name) |
1074 | if (i == fonts.size () - 1 && fallback->name) |
864 | { |
1075 | { |
865 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
1076 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
866 | fallback++; |
1077 | fallback++; |
|
|
1078 | i = 0; |
867 | } |
1079 | } |
868 | } |
1080 | } |
869 | |
1081 | |
870 | return 0; /* we must return SOME font */ |
1082 | return 0; /* we must return SOME font */ |
871 | } |
1083 | } |