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.209 by root, Fri Jun 18 21:58:03 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
1368#if ENABLE_COMBINING && !UNICODE_3 1343 rxvt_compose_expand_static<FcChar32> exp;
1369 if (ecb_expect_false (IS_COMPOSE (unicode))) 1344 FcChar32 *chrs = exp (unicode);
1370 if (compose_char *cc = rxvt_composite[unicode]) 1345 int nchrs = exp.length (chrs);
1371 if (cc->c2 == NOCHAR)
1372 unicode = cc->c1;
1373#endif
1374 1346
1347 // allm chars in sequence must be available
1348 for (int i = 0; i < nchrs; ++i)
1375 if (!XftCharExists (term->dpy, f, unicode)) 1349 if (!XftCharExists (term->dpy, f, chrs [i]))
1376 return false; 1350 return false;
1377 1351
1378 if (!prop || prop->width == rxvt_fontprop::unset) 1352 if (!prop || prop->width == rxvt_fontprop::unset)
1379 return true; 1353 return true;
1380 1354
1381 // check character against base font bounding box 1355 int wcw = max (WCWIDTH (chrs [0]), 1);
1382 FcChar32 ch = unicode; 1356
1357 // we check against all glyph sizes. this is probably wrong,
1358 // due to the way ->draw positions these glyphs.
1359 for (int i = 0; i < nchrs; ++i)
1360 {
1383 XGlyphInfo g; 1361 XGlyphInfo g;
1384 XftTextExtents32 (term->dpy, f, &ch, 1, &g); 1362 XftTextExtents32 (term->dpy, f, chrs + i, 1, &g);
1385 1363
1386 int w = g.width - g.x; 1364 int w = g.width - g.x;
1387 int wcw = max (WCWIDTH (unicode), 1);
1388 1365
1389 careful = g.x > 0 || w > prop->width * wcw; 1366 careful = g.x > 0 || w > prop->width * wcw;
1390 1367
1391 if (careful && !OVERLAP_OK (w, wcw, prop)) 1368 if (careful && !OVERLAP_OK (w, wcw, prop))
1392 return false; 1369 return false;
1393 1370
1394 // this weeds out _totally_ broken fonts, or glyphs 1371 // this weeds out _totally_ broken fonts, or glyphs
1395 if (!OVERLAP_OK (g.xOff, wcw, prop)) 1372 if (!OVERLAP_OK (g.xOff, wcw, prop))
1396 return false; 1373 return false;
1374 }
1397 1375
1398 return true; 1376 return true;
1399} 1377}
1400 1378
1401void 1379void
1402rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1380rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1403 const text_t *text, int len, 1381 const text_t *text, int len,
1404 int fg, int bg) 1382 int fg, int bg)
1405{ 1383{
1406 XGlyphInfo extents;
1407 XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len); 1384 //XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len);//D
1408 XftGlyphSpec *ep = enc; 1385 //XftGlyphSpec *ep = enc;//D
1386 static vector<XftGlyphSpec> enc; enc.resize (0); // static to avoid malloc, still slow
1409 1387
1410 dTermDisplay; 1388 dTermDisplay;
1411 dTermGC; 1389 dTermGC;
1412 1390
1413 int w = term->fwidth * len; 1391 int w = term->fwidth * len;
1424 int y_ = buffered ? 0 : y; 1402 int y_ = buffered ? 0 : y;
1425 1403
1426 while (len) 1404 while (len)
1427 { 1405 {
1428 int cwidth = term->fwidth; 1406 int cwidth = term->fwidth;
1407
1408 rxvt_compose_expand_static<FcChar32> exp;
1429 FcChar32 fc = *text++; len--; 1409 FcChar32 *chrs = exp (*text++); len--;
1430 1410 int nchrs = exp.length (chrs);
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 1411
1437 while (len && *text == NOCHAR) 1412 while (len && *text == NOCHAR)
1438 text++, len--, cwidth += term->fwidth; 1413 text++, len--, cwidth += term->fwidth;
1439 1414
1440 if (fc != ' ') // skip spaces 1415 if (chrs [0] != ' ') // skip spaces
1416 {
1417 #if 1
1418 FT_UInt glyphs [decltype (exp)::max_size];
1419
1420 for (int i = 0; i < nchrs; ++i)
1421 glyphs [i] = XftCharIndex (disp, f, chrs [i]);
1422
1423 for (int i = 0; i < nchrs; ++i)
1441 { 1424 {
1425 XGlyphInfo ep;
1426 XftGlyphExtents (disp, f, glyphs+i, 1, &ep);
1427 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);
1428 }
1429 #endif
1430
1442 FT_UInt glyph = XftCharIndex (disp, f, fc); 1431 FT_UInt glyph = XftCharIndex (disp, f, chrs [0]);
1432 XGlyphInfo extents0;
1443 XftGlyphExtents (disp, f, &glyph, 1, &extents); 1433 XftGlyphExtents (disp, f, &glyph, 1, &extents0);
1444 1434
1435 int cx = x_ + (cwidth - extents0.xOff >> 1);
1436 int cy = y_ + ascent;
1437
1438 XftGlyphSpec ep;
1445 ep->glyph = glyph; 1439 ep.glyph = glyph;
1446 ep->x = x_ + (cwidth - extents.xOff >> 1); 1440 ep.x = cx + (extents0.xOff ? 0 : extents0.xOff);
1447 ep->y = y_ + ascent; 1441 ep.y = cy;
1448 1442
1449 if (extents.xOff == 0) 1443 enc.push_back (ep);
1450 ep->x = x_ + cwidth;
1451 1444
1452 ep++; 1445 for (int i = 1; ecb_expect_false (i < nchrs); ++i)
1446 {
1447 FT_UInt glyph = XftCharIndex (disp, f, chrs [i]);
1448 XGlyphInfo extents;
1449 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1450
1451 ep.glyph = glyph;
1452 ep.x = cx + (extents.xOff ? 0 : extents0.xOff);
1453
1454 enc.push_back (ep);
1455 }
1453 } 1456 }
1454 1457
1455 x_ += cwidth; 1458 x_ += cwidth;
1456 } 1459 }
1457 1460
1458 if (buffered) 1461 if (buffered)
1459 { 1462 {
1460 if (ep != enc) 1463 if (!enc.empty ())
1461 { 1464 {
1462 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); 1465 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h);
1463 1466
1464#ifdef HAVE_IMG 1467#ifdef HAVE_IMG
1465 Picture dst = 0; // the only assignment is done conditionally in the following if condition 1468 Picture dst = 0; // the only assignment is done conditionally in the following if condition
1511 } 1514 }
1512 else 1515 else
1513#endif 1516#endif
1514 XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h); 1517 XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h);
1515 1518
1516 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); 1519 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, &enc[0], enc.size ());
1517 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); 1520 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y);
1518 } 1521 }
1519 else 1522 else
1520 clear_rect (d, x, y, w, h, bg); 1523 clear_rect (d, x, y, w, h, bg);
1521 } 1524 }
1522 else 1525 else
1523 { 1526 {
1524 clear_rect (d, x, y, w, h, bg); 1527 clear_rect (d, x, y, w, h, bg);
1525 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); 1528 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, &enc[0], enc.size ());
1526 } 1529 }
1527} 1530}
1528 1531
1529#endif 1532#endif
1530 1533

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines