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

Comparing rxvt-unicode/src/rxvtfont.C (file contents):
Revision 1.93 by root, Tue Jan 31 00:25:16 2006 UTC vs.
Revision 1.103 by root, Sun Aug 27 10:10:25 2006 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvtfont.C 2 * File: rxvtfont.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> 4 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com>
5 * - original version. 5 * - original version.
6 * 6 *
158 0x304c, 0x672c, // が本 158 0x304c, 0x672c, // が本
159}; 159};
160 160
161#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) 161#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0]))
162 162
163#define dTermDisplay Display *disp = term->xdisp 163#define dTermDisplay Display *disp = term->dpy
164#define dTermGC GC gc = term->gc 164#define dTermGC GC gc = term->gc
165
166/////////////////////////////////////////////////////////////////////////////
167
168#if XFT
169rxvt_drawable::~rxvt_drawable ()
170{
171 if (xftdrawable)
172 XftDrawDestroy (xftdrawable);
173}
174
175rxvt_drawable::operator XftDraw *()
176{
177 if (!xftdrawable)
178 xftdrawable = XftDrawCreate (screen->xdisp, drawable, screen->visual, screen->cmap);
179
180 return xftdrawable;
181}
182#endif
183 165
184///////////////////////////////////////////////////////////////////////////// 166/////////////////////////////////////////////////////////////////////////////
185 167
186static const char * 168static const char *
187enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) 169enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero)
250rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const 232rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const
251{ 233{
252 dTermDisplay; 234 dTermDisplay;
253 dTermGC; 235 dTermGC;
254 236
255 if (color == Color_bg) 237 if (color < 0 || color == Color_bg)
256 XClearArea (disp, d, x, y, w, h, false); 238 XClearArea (disp, d, x, y, w, h, false);
257 else if (color >= 0) 239 else
258 { 240 {
259#if XFT 241#if XFT
260 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); 242 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h);
261#else 243#else
262 XSetForeground (disp, gc, term->pix_colors[color]); 244 XSetForeground (disp, gc, term->pix_colors[color]);
288 p.slant = rxvt_fontprop::roman; 270 p.slant = rxvt_fontprop::roman;
289 271
290 return p; 272 return p;
291 } 273 }
292 274
293 bool load (const rxvt_fontprop &prop) 275 bool load (const rxvt_fontprop &prop, bool force_prop)
294 { 276 {
295 width = 1; height = 1; 277 width = 1; height = 1;
296 ascent = 1; descent = 0; 278 ascent = 1; descent = 0;
297 279
298 set_name (strdup ("built-in support font")); 280 set_name (strdup ("built-in support font"));
489 471
490 void clear (); 472 void clear ();
491 473
492 rxvt_fontprop properties (); 474 rxvt_fontprop properties ();
493 475
494 bool load (const rxvt_fontprop &prop); 476 bool load (const rxvt_fontprop &prop, bool force_prop);
495 477
496 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; 478 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const;
497 479
498 void draw (rxvt_drawable &d, int x, int y, 480 void draw (rxvt_drawable &d, int x, int y,
499 const text_t *text, int len, 481 const text_t *text, int len,
514rxvt_font_x11::get_property (XFontStruct *f, Atom property, const char *repl) const 496rxvt_font_x11::get_property (XFontStruct *f, Atom property, const char *repl) const
515{ 497{
516 unsigned long value; 498 unsigned long value;
517 499
518 if (XGetFontProperty (f, property, &value)) 500 if (XGetFontProperty (f, property, &value))
519 return XGetAtomName (term->xdisp, value); 501 return XGetAtomName (term->dpy, value);
520 else 502 else
521 return rxvt_strdup (repl); 503 return rxvt_strdup (repl);
522} 504}
523 505
524rxvt_fontprop 506rxvt_fontprop
547rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 529rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
548{ 530{
549 unsigned long height; 531 unsigned long height;
550 532
551#if 0 533#if 0
552 if (!XGetFontProperty (f, XInternAtom (term->xdisp, "PIXEL_SIZE", 0), &height)) 534 if (!XGetFontProperty (f, XInternAtom (term->dpy, "PIXEL_SIZE", 0), &height))
553 return false; 535 return false;
554#else 536#else
555 height = f->ascent + f->descent; 537 height = f->ascent + f->descent;
556#endif 538#endif
557 539
645 return false; 627 return false;
646 } 628 }
647} 629}
648 630
649bool 631bool
650rxvt_font_x11::load (const rxvt_fontprop &prop) 632rxvt_font_x11::load (const rxvt_fontprop &prop, bool force_prop)
651{ 633{
652 dTermDisplay; 634 dTermDisplay;
653 635
654 clear (); 636 clear ();
655 637
656 char field_str[64]; // enough for 128 bits 638 char field_str[64]; // enough for 128 bits
657 639
658 // first morph the font if required 640 // first morph the font if required
659 if (prop.weight != rxvt_fontprop::unset 641 if (force_prop)
660 || prop.slant != rxvt_fontprop::unset)
661 { 642 {
662 char fname[1024]; 643 char fname[1024];
663 644
664 if (name[0] != '-') 645 if (name[0] != '-')
665 { 646 {
892void 873void
893rxvt_font_x11::clear () 874rxvt_font_x11::clear ()
894{ 875{
895 if (f) 876 if (f)
896 { 877 {
897 XFreeFont (term->xdisp, f); 878 XFreeFont (term->dpy, f);
898 f = 0; 879 f = 0;
899 } 880 }
900} 881}
901 882
902bool 883bool
1057 1038
1058 void clear (); 1039 void clear ();
1059 1040
1060 rxvt_fontprop properties (); 1041 rxvt_fontprop properties ();
1061 1042
1062 bool load (const rxvt_fontprop &prop); 1043 bool load (const rxvt_fontprop &prop, bool force_prop);
1063 1044
1064 void draw (rxvt_drawable &d, int x, int y, 1045 void draw (rxvt_drawable &d, int x, int y,
1065 const text_t *text, int len, 1046 const text_t *text, int len,
1066 int fg, int bg); 1047 int fg, int bg);
1067 1048
1074void 1055void
1075rxvt_font_xft::clear () 1056rxvt_font_xft::clear ()
1076{ 1057{
1077 if (f) 1058 if (f)
1078 { 1059 {
1079 XftFontClose (term->xdisp, f); 1060 XftFontClose (term->dpy, f);
1080 f = 0; 1061 f = 0;
1081 } 1062 }
1082} 1063}
1083 1064
1084rxvt_fontprop 1065rxvt_fontprop
1100 1081
1101 return p; 1082 return p;
1102} 1083}
1103 1084
1104bool 1085bool
1105rxvt_font_xft::load (const rxvt_fontprop &prop) 1086rxvt_font_xft::load (const rxvt_fontprop &prop, bool force_prop)
1106{ 1087{
1107 dTermDisplay; 1088 dTermDisplay;
1108 1089
1109 clear (); 1090 clear ();
1110 1091
1119 && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch 1100 && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch
1120 && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) 1101 && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch))
1121 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); 1102 FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height);
1122 1103
1123 if (prop.weight != rxvt_fontprop::unset 1104 if (prop.weight != rxvt_fontprop::unset
1124 && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) 1105 && (force_prop || FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch))
1125 FcPatternAddInteger (p, FC_WEIGHT, prop.weight); 1106 FcPatternAddInteger (p, FC_WEIGHT, prop.weight);
1126 1107
1127 if (prop.slant != rxvt_fontprop::unset 1108 if (prop.slant != rxvt_fontprop::unset
1128 && FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) 1109 && (force_prop || FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch))
1129 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1110 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1130 1111
1131#if 0 // clipping unfortunately destroys our precious double-width-characters 1112#if 0 // clipping unfortunately destroys our precious double-width-characters
1132 // clip width, we can't do better, or can we? 1113 // clip width, we can't do better, or can we?
1133 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) 1114 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch)
1251bool 1232bool
1252rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const 1233rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
1253{ 1234{
1254 careful = false; 1235 careful = false;
1255 1236
1256 if (!XftCharExists (term->xdisp, f, unicode)) 1237 if (!XftCharExists (term->dpy, f, unicode))
1257 return false; 1238 return false;
1258 1239
1259 if (!prop || prop->width == rxvt_fontprop::unset) 1240 if (!prop || prop->width == rxvt_fontprop::unset)
1260 return true; 1241 return true;
1261 1242
1262 // check character against base font bounding box 1243 // check character against base font bounding box
1263 FcChar32 ch = unicode; 1244 FcChar32 ch = unicode;
1264 XGlyphInfo g; 1245 XGlyphInfo g;
1265 XftTextExtents32 (term->xdisp, f, &ch, 1, &g); 1246 XftTextExtents32 (term->dpy, f, &ch, 1, &g);
1266 1247
1267 int w = g.width - g.x; 1248 int w = g.width - g.x;
1268 int wcw = max (WCWIDTH (unicode), 1); 1249 int wcw = max (WCWIDTH (unicode), 1);
1269 1250
1270 careful = g.x > 0 || w > prop->width * wcw; 1251 careful = g.x > 0 || w > prop->width * wcw;
1282void 1263void
1283rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1264rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1284 const text_t *text, int len, 1265 const text_t *text, int len,
1285 int fg, int bg) 1266 int fg, int bg)
1286{ 1267{
1287 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1288
1289 XGlyphInfo extents; 1268 XGlyphInfo extents;
1290 XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); 1269 XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec));
1291 XftGlyphSpec *ep = enc; 1270 XftGlyphSpec *ep = enc;
1292 1271
1293 dTermDisplay; 1272 dTermDisplay;
1294 dTermGC; 1273 dTermGC;
1295 1274
1275 int w = term->fwidth * len;
1276 int h = term->fheight;
1277
1278 bool buffered = bg >= 0 // we don't use a transparent bg
1279#ifndef FORCE_UNBUFFERED_XFT
1280# if defined(XPM_BACKGROUND) || defined(TRANSPARENT)
1281 || !term->am_transparent // we aren't transparent
1282 || term->am_pixmap_trans // we have a pixmap
1283# endif
1284#endif
1285 ;
1286
1296 // cut trailing spaces 1287 // cut trailing spaces
1297 while (len && text [len - 1] == ' ') 1288 while (len && text [len - 1] == ' ')
1298 len--; 1289 len--;
1290
1291 int x_ = buffered ? 0 : x;
1292 int y_ = buffered ? 0 : y;
1299 1293
1300 while (len) 1294 while (len)
1301 { 1295 {
1302 int cwidth = term->fwidth; 1296 int cwidth = term->fwidth;
1303 FcChar32 fc = *text++; len--; 1297 FcChar32 fc = *text++; len--;
1309 { 1303 {
1310 FT_UInt glyph = XftCharIndex (disp, f, fc); 1304 FT_UInt glyph = XftCharIndex (disp, f, fc);
1311 XftGlyphExtents (disp, f, &glyph, 1, &extents); 1305 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1312 1306
1313 ep->glyph = glyph; 1307 ep->glyph = glyph;
1314 ep->x = x + (cwidth - extents.xOff >> 1); 1308 ep->x = x_ + (cwidth - extents.xOff >> 1);
1315 ep->y = y + ascent; 1309 ep->y = y_ + ascent;
1316 1310
1317 if (extents.xOff == 0) 1311 if (extents.xOff == 0)
1318 ep->x = x + cwidth; 1312 ep->x = x_ + cwidth;
1319 1313
1320 ep++; 1314 ep++;
1321 } 1315 }
1322 1316
1323 x += cwidth; 1317 x_ += cwidth;
1318 }
1319
1320 if (buffered)
1324 } 1321 {
1325
1326 if (ep != enc) 1322 if (ep != enc)
1323 {
1324 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h);
1325
1326 if (0)
1327 ;
1328#ifdef TRANSPARENT
1329 else if (bg < 0 && term->am_pixmap_trans)
1330 XCopyArea (disp, term->pixmap, d2, gc,
1331 x + term->window_vt_x, y + term->window_vt_y,
1332 w, h, 0, 0);
1333#endif
1334#ifdef XPM_BACKGROUND
1335 else if (bg < 0 && term->bgPixmap.pixmap)
1336 {
1337 XGCValues gcv;
1338
1339 gcv.fill_style = FillTiled;
1340 gcv.tile = term->pixmap;
1341 gcv.ts_x_origin = -x;
1342 gcv.ts_y_origin = -y;
1343
1344 GC gc2 = XCreateGC (disp, d2,
1345 GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle,
1346 &gcv);
1347
1348 XFillRectangle (disp, d2, gc2, 0, 0, w, h);
1349
1350 XFreeGC (disp, gc2);
1351 }
1352#endif
1353 else
1354 XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h);
1355
1356 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc);
1357 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y);
1358 }
1359 else
1360 clear_rect (d, x, y, w, h, bg);
1361 }
1362 else
1363 {
1364 clear_rect (d, x, y, w, h, bg);
1327 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); 1365 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc);
1366 }
1328} 1367}
1368
1329#endif 1369#endif
1330 1370
1331///////////////////////////////////////////////////////////////////////////// 1371/////////////////////////////////////////////////////////////////////////////
1332 1372
1333rxvt_fontset::rxvt_fontset (rxvt_term *term) 1373rxvt_fontset::rxvt_fontset (rxvt_term *term)
1344void 1384void
1345rxvt_fontset::clear () 1385rxvt_fontset::clear ()
1346{ 1386{
1347 prop.width = prop.height = prop.ascent = prop.weight = prop.slant 1387 prop.width = prop.height = prop.ascent = prop.weight = prop.slant
1348 = rxvt_fontprop::unset; 1388 = rxvt_fontprop::unset;
1389 force_prop = false;
1349 1390
1350 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) 1391 for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++)
1351 FONT_UNREF (*i); 1392 FONT_UNREF (*i);
1352 1393
1353 for (pagemap **p = fmap.begin (); p != fmap.end (); p++) 1394 for (pagemap **p = fmap.begin (); p != fmap.end (); p++)
1465 if (fonts[i]->loaded) 1506 if (fonts[i]->loaded)
1466 return true; 1507 return true;
1467 1508
1468 fonts[i]->loaded = true; 1509 fonts[i]->loaded = true;
1469 1510
1470 if (!fonts[i]->load (prop)) 1511 if (!fonts[i]->load (prop, force_prop))
1471 { 1512 {
1472 fonts[i]->cs = CS_UNKNOWN; 1513 fonts[i]->cs = CS_UNKNOWN;
1473 return false; 1514 return false;
1474 } 1515 }
1475 1516
1576 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1617 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1577 FcPatternAddBool (p, FC_MINSPACE, 1); 1618 FcPatternAddBool (p, FC_MINSPACE, 1);
1578 //FcPatternAddBool (p, FC_ANTIALIAS, 1); 1619 //FcPatternAddBool (p, FC_ANTIALIAS, 1);
1579 1620
1580 XftResult result; 1621 XftResult result;
1581 FcPattern *match = XftFontMatch (term->xdisp, term->display->screen, p, &result); 1622 FcPattern *match = XftFontMatch (term->dpy, term->display->screen, p, &result);
1582 1623
1583 FcPatternDestroy (p); 1624 FcPatternDestroy (p);
1584 1625
1585 if (match) 1626 if (match)
1586 { 1627 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines