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.201 by root, Thu Jun 17 01:44:29 2021 UTC vs.
Revision 1.210 by root, Fri Jun 18 22:11:09 2021 UTC

212} 212}
213 213
214///////////////////////////////////////////////////////////////////////////// 214/////////////////////////////////////////////////////////////////////////////
215 215
216rxvt_font::rxvt_font () 216rxvt_font::rxvt_font ()
217: name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset), can_compose(false) 217: name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset)
218{ 218{
219} 219}
220 220
221void 221void
222rxvt_font::set_name (char *name_) 222rxvt_font::set_name (char *name_)
445#endif 445#endif
446#if ENABLE_COMBINING 446#if ENABLE_COMBINING
447 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) 447 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t]))
448 { 448 {
449 min_it (width, 2); // we only support wcwidth up to 2 449 min_it (width, 2); // we only support wcwidth up to 2
450
451 #if NOT_YET
452 vector<text_t> chrs;
453 chrs.reserve (rxvt_composite.expand (t));
454 rxvt_composite.expand (t, &chrs[0]);
455
456 while (!chrs.empty ())
457 {
458 rxvt_font *f1 = fs->find_font_idx (chrs[0])
459
460 int i = 0;
461 while (i < chrs.size () - 1
462 && f1->can_combine
463 && f1->has-char (chrs[i + 1], careful)
464 && !careful
465 ++i;
466
467 (*fs)[f1]->draw (d, x, y, &chrs[0], width, fg, bg);
468 chrs.erase (&chrs[0], &chrs[i]);
469 }
470 #endif
471
472 #if 1
473 text_t chrs[2]; 450 text_t chrs[2];
474 chrs [1] = NOCHAR; 451 chrs [1] = NOCHAR;
475 452
476 *chrs = cc->c1; 453 *chrs = cc->c1;
477 rxvt_font *f1 = (*fs)[fs->find_font_idx (cc->c1)]; 454 rxvt_font *f1 = (*fs)[fs->find_font_idx (cc->c1)];
487 ? f1 464 ? f1
488 : (*fs)[fs->find_font_idx (cc->c2)]; 465 : (*fs)[fs->find_font_idx (cc->c2)];
489 466
490 f2->draw (d, x, y, chrs, width, fg, Color_none); 467 f2->draw (d, x, y, chrs, width, fg, Color_none);
491 } 468 }
492 #endif
493 } 469 }
494#endif 470#endif
495 else 471 else
496 switch (t) 472 switch (t)
497 { 473 {
1163 1139
1164struct rxvt_font_xft : rxvt_font 1140struct rxvt_font_xft : rxvt_font
1165{ 1141{
1166 rxvt_font_xft () 1142 rxvt_font_xft ()
1167 { 1143 {
1168 can_compose = true;
1169 f = 0; 1144 f = 0;
1170 } 1145 }
1171 1146
1172 void clear (); 1147 void clear ();
1173 1148
1317 if (glheight < g.height - g.y) glheight = g.height - g.y; 1292 if (glheight < g.height - g.y) glheight = g.height - g.y;
1318 } 1293 }
1319 1294
1320 if (!width) 1295 if (!width)
1321 { 1296 {
1322 rxvt_warn ("unable to calculate font width for '%s', ignoring.\n", name); 1297 rxvt_warn ("unable to calculate font width for '%s', using max_advance_width.\n", name);
1323 1298 width = f->max_advance_width;
1324 XftFontClose (disp, f);
1325 f = 0;
1326
1327 success = false;
1328 break; 1299 break;
1329 } 1300 }
1330 1301
1331 if (prop.height == rxvt_fontprop::unset 1302 if (prop.height == rxvt_fontprop::unset
1332 || (height <= prop.height && glheight <= prop.height) 1303 || (height <= prop.height && glheight <= prop.height)
1367bool 1338bool
1368rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const 1339rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
1369{ 1340{
1370 careful = false; 1341 careful = false;
1371 1342
1343 // handle non-bmp chars when text_t is 16 bit
1372#if ENABLE_COMBINING && !UNICODE_3 1344#if ENABLE_COMBINING && !UNICODE_3
1373 if (ecb_expect_false (IS_COMPOSE (unicode))) 1345 if (ecb_expect_false (IS_COMPOSE (unicode)))
1374 if (compose_char *cc = rxvt_composite[unicode]) 1346 if (compose_char *cc = rxvt_composite [unicode])
1375 if (cc->c2 == NOCHAR) 1347 if (cc->c2 == NOCHAR)
1376 unicode = cc->c1; 1348 unicode = cc->c1;
1349 else
1350 return false;
1351 else
1352 return false;
1377#endif 1353#endif
1378 1354
1355 FcChar32 chr = unicode;
1356
1379 if (!XftCharExists (term->dpy, f, unicode)) 1357 if (!XftCharExists (term->dpy, f, chr))
1380 return false; 1358 return false;
1381 1359
1382 if (!prop || prop->width == rxvt_fontprop::unset) 1360 if (!prop || prop->width == rxvt_fontprop::unset)
1383 return true; 1361 return true;
1384 1362
1385 // check character against base font bounding box 1363 int wcw = max (WCWIDTH (chr), 1);
1386 FcChar32 ch = unicode; 1364
1387 XGlyphInfo g; 1365 XGlyphInfo g;
1388 XftTextExtents32 (term->dpy, f, &ch, 1, &g); 1366 XftTextExtents32 (term->dpy, f, &chr, 1, &g);
1389 1367
1390 int w = g.width - g.x; 1368 int w = g.width - g.x;
1391 int wcw = max (WCWIDTH (unicode), 1);
1392 1369
1393 careful = g.x > 0 || w > prop->width * wcw; 1370 careful = g.x > 0 || w > prop->width * wcw;
1394 1371
1395 if (careful && !OVERLAP_OK (w, wcw, prop)) 1372 if (careful && !OVERLAP_OK (w, wcw, prop))
1396 return false; 1373 return false;
1405void 1382void
1406rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1383rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1407 const text_t *text, int len, 1384 const text_t *text, int len,
1408 int fg, int bg) 1385 int fg, int bg)
1409{ 1386{
1410 XGlyphInfo extents;
1411 XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len); 1387 //XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len);//D
1412 XftGlyphSpec *ep = enc; 1388 //XftGlyphSpec *ep = enc;//D
1389 static vector<XftGlyphSpec> enc; enc.resize (0); // static to avoid malloc, still slow
1413 1390
1414 dTermDisplay; 1391 dTermDisplay;
1415 dTermGC; 1392 dTermGC;
1416 1393
1417 int w = term->fwidth * len; 1394 int w = term->fwidth * len;
1428 int y_ = buffered ? 0 : y; 1405 int y_ = buffered ? 0 : y;
1429 1406
1430 while (len) 1407 while (len)
1431 { 1408 {
1432 int cwidth = term->fwidth; 1409 int cwidth = term->fwidth;
1433 FcChar32 fc = *text++; len--; 1410 FcChar32 chr = *text++; len--;
1434 1411
1412 // handle non-bmp chars when text_t is 16 bit
1435#if ENABLE_COMBINING && !UNICODE_3 1413 #if ENABLE_COMBINING && !UNICODE_3
1436 if (ecb_expect_false (IS_COMPOSE (fc))) 1414 if (ecb_expect_false (IS_COMPOSE (chr)))
1437 if (compose_char *cc = rxvt_composite[fc]) // should always be true, but better be safe than sorry 1415 if (compose_char *cc = rxvt_composite [chr])
1438 fc = cc->c1; // c2 must be NOCHAR, as has_char handles it that way 1416 if (cc->c2 == NOCHAR)
1439#endif 1417 chr = cc->c1;
1418 #endif
1440 1419
1441 while (len && *text == NOCHAR) 1420 while (len && *text == NOCHAR)
1442 text++, len--, cwidth += term->fwidth; 1421 text++, len--, cwidth += term->fwidth;
1443 1422
1444 if (fc != ' ') // skip spaces 1423 if (chr != ' ') // skip spaces
1424 {
1425 #if 0
1426 FT_UInt glyphs [decltype (exp)::max_size];
1427
1428 for (int i = 0; i < nchrs; ++i)
1429 glyphs [i] = XftCharIndex (disp, f, chrs [i]);
1430
1431 for (int i = 0; i < nchrs; ++i)
1445 { 1432 {
1433 XGlyphInfo ep;
1434 XftGlyphExtents (disp, f, glyphs+i, 1, &ep);
1435 printf ("gs %4x g %4x + %3d,%3d o %3d,%3d wh %3d,%3d\n", chrs[i],glyphs[i],ep.x,ep.y,ep.xOff,ep.yOff,ep.width,ep.height);
1436 }
1437 #endif
1438
1446 FT_UInt glyph = XftCharIndex (disp, f, fc); 1439 FT_UInt glyph = XftCharIndex (disp, f, chr);
1440 XGlyphInfo extents;
1447 XftGlyphExtents (disp, f, &glyph, 1, &extents); 1441 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1448 1442
1443 XftGlyphSpec ep;
1449 ep->glyph = glyph; 1444 ep.glyph = glyph;
1450 ep->x = x_ + (cwidth - extents.xOff >> 1); 1445 ep.x = x_;
1451 ep->y = y_ + ascent; 1446 ep.y = y_ + ascent;
1452 1447
1453 if (extents.xOff == 0) 1448 // the xft font cell might differ from the terminal font cell,
1454 ep->x = x_ + cwidth; 1449 // in which we use the average between the two
1450 ep.x += cwidth - extents.xOff >> 1;
1455 1451
1456 ep++; 1452 // xft/freetype represent combining characters as characters with zero
1453 // width rendered over the previous character with some fonts, while
1454 // in other fonts, they are considered normal characters, while yet
1455 // in other fonts, they are shifted all over the place.
1456 // we handle the first two cases by keying off on xOff being 0
1457 // for zero-width chars. normally, we would add extents.xOff
1458 // of the base chaarcter here, but we don't have that, so we use cwidth.
1459 ep.x += extents.xOff ? 0 : cwidth;
1460
1461 enc.push_back (ep);
1457 } 1462 }
1458 1463
1459 x_ += cwidth; 1464 x_ += cwidth;
1460 } 1465 }
1461 1466
1462 if (buffered) 1467 if (buffered)
1463 { 1468 {
1464 if (ep != enc) 1469 if (!enc.empty ())
1465 { 1470 {
1466 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); 1471 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h);
1467 1472
1468#ifdef HAVE_IMG 1473#ifdef HAVE_IMG
1469 Picture dst = 0; // the only assignment is done conditionally in the following if condition 1474 Picture dst = 0; // the only assignment is done conditionally in the following if condition
1515 } 1520 }
1516 else 1521 else
1517#endif 1522#endif
1518 XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h); 1523 XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h);
1519 1524
1520 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); 1525 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, &enc[0], enc.size ());
1521 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); 1526 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y);
1522 } 1527 }
1523 else 1528 else
1524 clear_rect (d, x, y, w, h, bg); 1529 clear_rect (d, x, y, w, h, bg);
1525 } 1530 }
1526 else 1531 else
1527 { 1532 {
1528 clear_rect (d, x, y, w, h, bg); 1533 clear_rect (d, x, y, w, h, bg);
1529 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); 1534 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, &enc[0], enc.size ());
1530 } 1535 }
1531} 1536}
1532 1537
1533#endif 1538#endif
1534 1539
1736 if (unicode > 0x1fffff) 1741 if (unicode > 0x1fffff)
1737 return 0; 1742 return 0;
1738 1743
1739 unicode_t hi = unicode >> 8; 1744 unicode_t hi = unicode >> 8;
1740 1745
1741 if (hi < fmap.size () 1746 if (hi < fmap.size ())
1742 && fmap[hi] 1747 if (pagemap *pm = fmap[hi])
1743 && (*fmap[hi])[unicode & 0xff] != 0xff) 1748 if ((*pm)[unicode & 0xff] != 0xff)
1744 return (*fmap[hi])[unicode & 0xff]; 1749 return (*pm)[unicode & 0xff];
1745 1750
1746 unsigned int i; 1751 unsigned int i;
1747 1752
1748 for (i = 0; i < fonts.size (); i++) 1753 for (i = 0; i < fonts.size (); i++)
1749 { 1754 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines