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.203 by root, Thu Jun 17 11:21:52 2021 UTC vs.
Revision 1.216 by root, Sat Jun 19 10:08:10 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
1363bool 1338bool
1364rxvt_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
1365{ 1340{
1366 careful = false; 1341 careful = false;
1367 1342
1343 // handle non-bmp chars when text_t is 16 bit
1368#if ENABLE_COMBINING && !UNICODE_3 1344#if ENABLE_COMBINING && !UNICODE_3
1369 if (ecb_expect_false (IS_COMPOSE (unicode))) 1345 if (ecb_expect_false (IS_COMPOSE (unicode)))
1370 if (compose_char *cc = rxvt_composite[unicode]) 1346 if (compose_char *cc = rxvt_composite [unicode])
1371 if (cc->c2 == NOCHAR) 1347 if (cc->c2 == NOCHAR)
1372 unicode = cc->c1; 1348 unicode = cc->c1;
1349 else
1350 return false;
1351 else
1352 return false;
1373#endif 1353#endif
1374 1354
1355 FcChar32 chr = unicode;
1356
1375 if (!XftCharExists (term->dpy, f, unicode)) 1357 if (!XftCharExists (term->dpy, f, chr))
1376 return false; 1358 return false;
1377 1359
1378 if (!prop || prop->width == rxvt_fontprop::unset) 1360 if (!prop || prop->width == rxvt_fontprop::unset)
1379 return true; 1361 return true;
1380 1362
1381 // check character against base font bounding box 1363 int wcw = max (WCWIDTH (chr), 1);
1382 FcChar32 ch = unicode; 1364
1383 XGlyphInfo g; 1365 XGlyphInfo g;
1384 XftTextExtents32 (term->dpy, f, &ch, 1, &g); 1366 XftTextExtents32 (term->dpy, f, &chr, 1, &g);
1385 1367
1386 int w = g.width - g.x; 1368 int w = g.width - g.x;
1387 int wcw = max (WCWIDTH (unicode), 1);
1388 1369
1389 careful = g.x > 0 || w > prop->width * wcw; 1370 careful = g.x > 0 || w > prop->width * wcw;
1390 1371
1391 if (careful && !OVERLAP_OK (w, wcw, prop)) 1372 if (careful && !OVERLAP_OK (w, wcw, prop))
1392 return false; 1373 return false;
1401void 1382void
1402rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1383rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1403 const text_t *text, int len, 1384 const text_t *text, int len,
1404 int fg, int bg) 1385 int fg, int bg)
1405{ 1386{
1406 XGlyphInfo extents;
1407 XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len); 1387 XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len);
1408 XftGlyphSpec *ep = enc; 1388 XftGlyphSpec *ep = enc;
1409 1389
1410 dTermDisplay; 1390 dTermDisplay;
1411 dTermGC; 1391 dTermGC;
1424 int y_ = buffered ? 0 : y; 1404 int y_ = buffered ? 0 : y;
1425 1405
1426 while (len) 1406 while (len)
1427 { 1407 {
1428 int cwidth = term->fwidth; 1408 int cwidth = term->fwidth;
1429 FcChar32 fc = *text++; len--; 1409 FcChar32 chr = *text++; len--;
1430
1431#if ENABLE_COMBINING && !UNICODE_3
1432 if (ecb_expect_false (IS_COMPOSE (fc)))
1433 if (compose_char *cc = rxvt_composite[fc]) // should always be true, but better be safe than sorry
1434 fc = cc->c1; // c2 must be NOCHAR, as has_char handles it that way
1435#endif
1436 1410
1437 while (len && *text == NOCHAR) 1411 while (len && *text == NOCHAR)
1438 text++, len--, cwidth += term->fwidth; 1412 text++, len--, cwidth += term->fwidth;
1439 1413
1440 if (fc != ' ') // skip spaces 1414 if (chr != ' ') // skip spaces
1415 {
1416 // handle non-bmp chars when text_t is 16 bit
1417 #if ENABLE_COMBINING && !UNICODE_3
1418 if (ecb_expect_false (IS_COMPOSE (chr)))
1419 if (compose_char *cc = rxvt_composite [chr])
1420 if (cc->c2 == NOCHAR)
1421 chr = cc->c1;
1422 #endif
1423
1424 #if 0
1425 FT_UInt glyphs [decltype (exp)::max_size];
1426
1427 for (int i = 0; i < nchrs; ++i)
1428 glyphs [i] = XftCharIndex (disp, f, chrs [i]);
1429
1430 for (int i = 0; i < nchrs; ++i)
1441 { 1431 {
1432 XGlyphInfo ep;
1433 XftGlyphExtents (disp, f, glyphs+i, 1, &ep);
1434 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);
1435 }
1436 #endif
1437
1442 FT_UInt glyph = XftCharIndex (disp, f, fc); 1438 FT_UInt glyph = XftCharIndex (disp, f, chr);
1439 XGlyphInfo extents;
1443 XftGlyphExtents (disp, f, &glyph, 1, &extents); 1440 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1444 1441
1445 ep->glyph = glyph; 1442 ep->glyph = glyph;
1446 ep->x = x_ + (cwidth - extents.xOff >> 1); 1443 ep->x = x_;
1447 ep->y = y_ + ascent; 1444 ep->y = y_ + ascent;
1448 1445
1449 if (extents.xOff == 0) 1446 // the xft font cell might differ from the terminal font cell,
1450 ep->x = x_ + cwidth; 1447 // in which case we use the average between the two.
1448 ep->x += extents.xOff ? cwidth - extents.xOff >> 1 : 0;
1451 1449
1450 // xft/freetype represent combining characters as characters with zero
1451 // width rendered over the previous character with some fonts, while
1452 // in other fonts, they are considered normal characters, while yet
1453 // in other fonts, they are shifted all over the place.
1454 // we handle the first two cases by keying off on xOff being 0
1455 // for zero-width chars. normally, we would add extents.xOff
1456 // of the base character here, but we don't have that, so we use cwidth.
1457 ep->x += extents.xOff ? 0 : cwidth;
1458
1452 ep++; 1459 ++ep;
1453 } 1460 }
1454 1461
1455 x_ += cwidth; 1462 x_ += cwidth;
1456 } 1463 }
1457 1464
1726} 1733}
1727 1734
1728int 1735int
1729rxvt_fontset::find_font_idx (unicode_t unicode) 1736rxvt_fontset::find_font_idx (unicode_t unicode)
1730{ 1737{
1731 // this limits fmap size. it has to accomodate COMPOSE_HI when UNICODE_3 1738 // this limits fmap size. it has to accommodate COMPOSE_HI when UNICODE_3
1732 if (unicode > 0x1fffff) 1739 if (unicode > 0x1fffff)
1733 return 0; 1740 return 0;
1734 1741
1735 unicode_t hi = unicode >> 8; 1742 unicode_t hi = unicode >> 8;
1736 1743

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines