ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/defaultfont.C
(Generate patch)

Comparing rxvt-unicode/src/defaultfont.C (file contents):
Revision 1.44 by pcg, Tue Mar 16 04:52:20 2004 UTC vs.
Revision 1.50 by pcg, Sun Mar 28 02:07:08 2004 UTC

200 XFillRectangle (d.display->display, d, TGC, x, y, w, h); 200 XFillRectangle (d.display->display, d, TGC, x, y, w, h);
201#endif 201#endif
202 } 202 }
203} 203}
204 204
205#include "table/linedraw.h"
206
205struct rxvt_font_default : rxvt_font { 207struct rxvt_font_default : rxvt_font {
208
206 rxvt_fontprop properties () 209 rxvt_fontprop properties ()
207 { 210 {
208 rxvt_fontprop p; 211 rxvt_fontprop p;
209 212
210 p.width = p.height = 1; 213 p.width = p.height = 1;
217 bool load (const rxvt_fontprop &prop) 220 bool load (const rxvt_fontprop &prop)
218 { 221 {
219 width = 1; height = 1; 222 width = 1; height = 1;
220 ascent = 1; descent = 0; 223 ascent = 1; descent = 0;
221 224
222 set_name ("built-in pseudofont"); 225 set_name (strdup ("built-in pseudofont"));
223 226
224 return true; 227 return true;
225 } 228 }
226 229
227 bool has_codepoint (unicode_t unicode) 230 bool has_codepoint (unicode_t unicode)
228 { 231 {
229 if (unicode <= 0x001f) 232 if (unicode <= 0x001f)
230 return true; 233 return true;
231 234
232 if (unicode >= 0x0080 && unicode <= 0x009f) 235 if (unicode <= 0x007f)
236 return false;
237
238 if (unicode <= 0x009f)
233 return true; 239 return true;
234 240
235 if (unicode >= 0x2500 && unicode <= 0x259f) 241 if (unicode >= 0x2500 && unicode <= 0x259f)
236 return true; 242 return true;
237 243
250 void draw (rxvt_drawable &d, int x, int y, 256 void draw (rxvt_drawable &d, int x, int y,
251 const text_t *text, int len, 257 const text_t *text, int len,
252 int fg, int bg); 258 int fg, int bg);
253}; 259};
254 260
255static void rect_stipple (Display *display, Drawable d, GC gc, int s1, int s2, int x, int y, int w, int h)
256{
257 XGCValues gcv;
258 char bm[2] = { s1, s2 };
259
260 gcv.fill_style = FillStippled;
261 gcv.stipple = XCreateBitmapFromData (display, d, bm, 2, 2);
262 gcv.ts_x_origin = x;
263 gcv.ts_y_origin = y;
264
265 if (!gcv.stipple)
266 return;
267
268 XChangeGC (display, gc, GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
269 XFillRectangle (display, d, gc, x, y, w, h);
270
271 XFreePixmap (display, gcv.stipple);
272
273 gcv.fill_style = FillSolid;
274 XChangeGC (display, gc, GCFillStyle, &gcv);
275}
276
277#include "table/linedraw.h"
278
279void 261void
280rxvt_font_default::draw (rxvt_drawable &d, int x, int y, 262rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
281 const text_t *text, int len, 263 const text_t *text, int len,
282 int fg, int bg) 264 int fg, int bg)
283{ 265{
290#if ENABLE_COMBINING 272#if ENABLE_COMBINING
291 compose_char *cc; 273 compose_char *cc;
292#endif 274#endif
293 text_t t = *text++; 275 text_t t = *text++;
294 276
277 if (0x2500 <= t && t <= 0x259f)
278 {
279 uint16_t offs = linedraw_offs[t - 0x2500];
280 uint32_t *a = linedraw_command + (offs >> 4);
281 uint32_t *b = a + (offs & 15);
282
283 int W = r->TermWin.fwidth;
284 int H = r->TermWin.fheight;
285
295 int x_[16]; 286 int x_[16];
296 int y_[16]; 287 int y_[16];
297 288
298 int W = r->TermWin.fwidth , w = (W - 1) / 2;
299 int H = r->TermWin.fheight, h = (H - 1) / 2;
300 int x0 = x, x1 = x + w, x2 = x + r->TermWin.fwidth ;
301 int y0 = y, y1 = y + h, y2 = y + r->TermWin.fheight;
302
303 for (int i = 0; i <= 8; i++) 289 for (int i = 0; i <= 8; i++)
304 {
305 x_[i] = x + ((W-1) * i + (i*7/8)) / 8;
306 y_[i] = y + ((H-1) * i + (i*7/8)) / 8;
307 }
308
309 x_[10] = x + (W - 1) / 2; x_[9] = x_[10] - 1; x_[11] = x_[10] + 1;
310 y_[10] = y + (H - 1) / 2; y_[9] = y_[10] - 1; y_[11] = y_[10] + 1;
311
312 int i1 = linedraw_offs[t - 0x2500];
313 int i2 = linedraw_offs[t - 0x2500 + 1];
314
315 XGCValues gcv;
316
317 gcv.cap_style = CapButt;
318 gcv.line_width = 0;
319 XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv);
320
321 if (i1 != i2)
322 {
323 while (i1 < i2)
324 { 290 {
291 x_[i] = x + ((W-1) * i + (i*7/8)) / 8;
292 y_[i] = y + ((H-1) * i + (i*7/8)) / 8;
293 }
294
295 x_[10] = x + (W - 1) / 2; x_[9] = x_[10] - 1; x_[11] = x_[10] + 1;
296 y_[10] = y + (H - 1) / 2; y_[9] = y_[10] - 1; y_[11] = y_[10] + 1;
297
298 XGCValues gcv;
299
300 gcv.cap_style = CapButt;
301 gcv.line_width = 0;
302 XChangeGC (d.display->display, TGC, GCLineWidth | GCCapStyle, &gcv);
303
304 while (a < b)
305 {
325 uint32_t command = linedraw_command [i1++]; 306 uint32_t command = *a++;
326 307
327 int op = (command >> 24) & 255; 308 int op = (command >> 24) & 255;
328 int a = (command >> 20) & 15; 309 int a = (command >> 20) & 15;
329 int b = (command >> 16) & 15; 310 int b = (command >> 16) & 15;
330 int x1 = x_[(command >> 12) & 15]; 311 int x1 = x_[(command >> 12) & 15];
339 break; 320 break;
340 321
341 case 1: // rectangle, possibly stippled 322 case 1: // rectangle, possibly stippled
342 if (a) 323 if (a)
343 { 324 {
344 static char bm[] = { 0,0 , 1,3 , 2,1 , 0,1 }; 325 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 };
345 326
346 gcv.fill_style = FillStippled; 327 gcv.fill_style = FillStippled;
347 gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2); 328 gcv.stipple = XCreateBitmapFromData (d.display->display, d, bm + a * 2, 2, 2);
348 gcv.ts_x_origin = x; 329 gcv.ts_x_origin = x;
349 gcv.ts_y_origin = y; 330 gcv.ts_y_origin = y;
351 XChangeGC (d.display->display, TGC, 332 XChangeGC (d.display->display, TGC,
352 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, 333 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
353 &gcv); 334 &gcv);
354 } 335 }
355 336
356
357 XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); 337 XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
358 338
359 if (a) 339 if (a)
360 { 340 {
361 XFreePixmap (d.display->display, gcv.stipple); 341 XFreePixmap (d.display->display, gcv.stipple);
342 gcv.stipple = 0;
362 gcv.fill_style = FillSolid; 343 gcv.fill_style = FillSolid;
363 XChangeGC (d.display->display, TGC, GCFillStyle, &gcv); 344 XChangeGC (d.display->display, TGC, GCFillStyle, &gcv);
364 } 345 }
365
366 break; 346 break;
367 case 2: // arc 347 case 2: // arc
348 XDrawArc (d.display->display, d, TGC,
349 x1 - W/2, y1 - H/2, W-1, H-1,
350 (a - 1) * 90*64, (b - 1) * 90*64);
368 break; 351 break;
369 } 352 }
370 } 353 }
371
372#if 0
373 case 'A': XDrawArc (d.display->display, d, TGC, x1 , y1 , W-1, H-1, 90*64, 90*64); break;
374 case 'B': XDrawArc (d.display->display, d, TGC, x1-W+1, y1 , W-1, H-1, 0*64, 90*64); break;
375 case 'C': XDrawArc (d.display->display, d, TGC, x1-W+1, y1-H+1, W-1, H-1, 0*64, -90*64); break;
376 case 'D': XDrawArc (d.display->display, d, TGC, x1 , y1-H+1, W-1, H-1, -90*64, -90*64); break;
377
378 case 'i': XFillRectangle (d.display->display, d, TGC, x0, y0, x1 - x0 + 1, y1 - y0 + 1); break;
379 case 'j': XFillRectangle (d.display->display, d, TGC, x1, y0, x2 - x1, y1 - y0 + 1); break;
380 case 'k': XFillRectangle (d.display->display, d, TGC, x0, y1, x1 - x0 + 1, y2 - y1); break;
381 case 'l': XFillRectangle (d.display->display, d, TGC, x1, y1, x2 - x1, y2 - y1); break;
382 }
383 }
384#endif
385
386 } 354 }
387#if ENABLE_COMBINING 355#if ENABLE_COMBINING
388 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) 356 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t]))
389 { 357 {
390 rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)]; 358 rxvt_font *f1 = (*fs)[fs->find_font (cc->c1)];
404 switch (t) 372 switch (t)
405 { 373 {
406 case ZERO_WIDTH_CHAR: 374 case ZERO_WIDTH_CHAR:
407 break; 375 break;
408 376
409#if 0
410 case 0x2580: XFillRectangle (d.display->display, d, TGC, x0, y0, W, y1 - y0 + 1); break;
411 case 0x2581: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 7 - 1) / 8, W, H - (H * 7 - 1) / 8); break;
412 case 0x2582: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 6 - 2) / 8, W, H - (H * 6 - 2) / 8); break;
413 case 0x2583: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 5 - 3) / 8, W, H - (H * 5 - 3) / 8); break;
414 case 0x2584: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 4 - 4) / 8, W, H - (H * 4 - 4) / 8); break;
415 case 0x2585: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 3 - 5) / 8, W, H - (H * 3 - 5) / 8); break;
416 case 0x2586: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 2 - 6) / 8, W, H - (H * 2 - 6) / 8); break;
417 case 0x2587: XFillRectangle (d.display->display, d, TGC, x0, y0 + (H * 1 - 7) / 8, W, H - (H * 1 - 7) / 8); break;
418 case 0x2588: XFillRectangle (d.display->display, d, TGC, x0, y0, W, H); break;
419 case 0x2589: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 7 - 1) / 8, H); break;
420 case 0x258a: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 6 - 2) / 8, H); break;
421 case 0x258b: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 5 - 3) / 8, H); break;
422 case 0x258c: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 4 - 4) / 8, H); break;
423 case 0x258d: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 3 - 5) / 8, H); break;
424 case 0x258e: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 2 - 6) / 8, H); break;
425 case 0x258f: XFillRectangle (d.display->display, d, TGC, x0, y0, (W * 1 - 7) / 8, H); break;
426 case 0x2590: XFillRectangle (d.display->display, d, TGC, x1, y0, x2 - x1, H); break;
427
428 case 0x2591: rect_stipple (d.display->display, d, TGC, 0x00, 0x01, x0, y0, W, H); break;
429 case 0x2592: rect_stipple (d.display->display, d, TGC, 0x02, 0x01, x0, y0, W, H); break;
430 case 0x2593: rect_stipple (d.display->display, d, TGC, 0x01, 0x03, x0, y0, W, H); break;
431
432 case 0x2594: XFillRectangle (d.display->display, d, TGC, x0, y0, W, (H * 1 - 7) / 8); break;
433 case 0x2595: XFillRectangle (d.display->display, d, TGC, x0 + (W * 7 - 1) / 8, y0, W - (W * 7 - 1) / 8, H); break;
434#endif
435
436 default: 377 default:
437 int w = 0; 378 int w = 0;
438 while (len > 0 && *text == NOCHAR) 379 while (len > 0 && *text == NOCHAR)
439 { 380 {
440 ++text; 381 ++text;
470 411
471 XFontStruct *f; 412 XFontStruct *f;
472 codeset cs; 413 codeset cs;
473 bool enc2b, encm; 414 bool enc2b, encm;
474 415
475 const char *get_property (XFontStruct *f, const char *property, const char *repl) const; 416 char *get_property (XFontStruct *f, const char *property, const char *repl) const;
476 bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); 417 bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth);
477 bool set_properties (rxvt_fontprop &p, XFontStruct *f); 418 bool set_properties (rxvt_fontprop &p, XFontStruct *f);
478 bool set_properties (rxvt_fontprop &p, const char *name); 419 bool set_properties (rxvt_fontprop &p, const char *name);
479}; 420};
480 421
481const char * 422char *
482rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const 423rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
483{ 424{
484 unsigned long value; 425 unsigned long value;
485 426
486 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 427 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value))
487 return XGetAtomName (DISPLAY, value); 428 return XGetAtomName (DISPLAY, value);
488 else 429 else
489 return repl; 430 return rxvt_strdup (repl);
490} 431}
491 432
492rxvt_fontprop 433rxvt_fontprop
493rxvt_font_x11::properties () 434rxvt_font_x11::properties ()
494{ 435{
509} 450}
510 451
511bool 452bool
512rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 453rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
513{ 454{
514 const char *weight = get_property (f, "WEIGHT_NAME", "medium");
515 const char *slant = get_property (f, "SLANT", "r");
516
517 unsigned long height; 455 unsigned long height;
518 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) 456 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height))
519 return false; 457 return false;
520 458
521 unsigned long avgwidth; 459 unsigned long avgwidth;
522 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) 460 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth))
523 avgwidth = 0; 461 avgwidth = 0;
524 462
463 char *weight = get_property (f, "WEIGHT_NAME", "medium");
464 char *slant = get_property (f, "SLANT", "r");
465
525 return set_properties (p, height, weight, slant, avgwidth); 466 set_properties (p, height, weight, slant, avgwidth);
467
468 free (weight);
469 free (slant);
470
471 return true;
526} 472}
527 473
528bool 474bool
529rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 475rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
530{ 476{
634 f = XLoadQueryFont (DISPLAY, name); 580 f = XLoadQueryFont (DISPLAY, name);
635 581
636 if (!f) 582 if (!f)
637 return false; 583 return false;
638 584
639 const char *registry = get_property (f, "CHARSET_REGISTRY", 0); 585 char *registry = get_property (f, "CHARSET_REGISTRY", 0);
640 const char *encoding = get_property (f, "CHARSET_ENCODING", 0); 586 char *encoding = get_property (f, "CHARSET_ENCODING", 0);
641 587
642 if (registry && encoding) 588 if (registry && encoding)
643 { 589 {
644 char charset[64]; 590 char charset[64];
645 snprintf (charset, 64, "%s-%s", registry, encoding); 591 snprintf (charset, 64, "%s-%s", registry, encoding);
658 if (*charset++ == '-' && !--count) 604 if (*charset++ == '-' && !--count)
659 break; 605 break;
660 606
661 cs = codeset_from_name (charset); 607 cs = codeset_from_name (charset);
662 } 608 }
609
610 free (registry);
611 free (encoding);
663 612
664 if (cs == CS_UNICODE) 613 if (cs == CS_UNICODE)
665 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font 614 cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font
666 615
667 encm = f->min_byte1 != 0 || f->max_byte1 != 0; 616 encm = f->min_byte1 != 0 || f->max_byte1 != 0;
780 729
781 int base = r->TermWin.fbase; 730 int base = r->TermWin.fbase;
782 731
783 XGCValues v; 732 XGCValues v;
784 v.foreground = r->PixColors[fg]; 733 v.foreground = r->PixColors[fg];
785 v.background = r->PixColors[bg];
786 v.font = f->fid; 734 v.font = f->fid;
787 735
788 if (enc2b) 736 if (enc2b)
789 { 737 {
790 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 738 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
791 739
792 if (bg == Color_bg && !slow) 740 if (bg == Color_bg && !slow)
793 { 741 {
742 v.background = r->PixColors[bg];
794 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 743 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
795 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); 744 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len);
796 } 745 }
797 else 746 else
798 { 747 {
820 { 769 {
821 const char *xc = enc_char (text, len, cs, slow); 770 const char *xc = enc_char (text, len, cs, slow);
822 771
823 if (bg == Color_bg && !slow) 772 if (bg == Color_bg && !slow)
824 { 773 {
774 v.background = r->PixColors[bg];
825 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 775 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v);
826 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); 776 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len);
827 } 777 }
828 else 778 else
829 { 779 {
1207} 1157}
1208 1158
1209int 1159int
1210rxvt_fontset::find_font (unicode_t unicode) 1160rxvt_fontset::find_font (unicode_t unicode)
1211{ 1161{
1212 for (unsigned int i = 0; i < fonts.size (); i++) 1162 for (unsigned int i = !!(0x20 <= unicode && unicode <= 0x7f); // skip pseudo-font for ascii
1163 i < fonts.size ();
1164 i++)
1213 { 1165 {
1214 rxvt_font *f = fonts[i]; 1166 rxvt_font *f = fonts[i];
1215 1167
1216 if (!f->loaded) 1168 if (!f->loaded)
1217 { 1169 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines