Fix wide glyphs truncation

This commit is contained in:
Dreomite 2020-06-13 02:29:41 +03:00
parent ca42c0cc02
commit e3b821dcb3
2 changed files with 72 additions and 55 deletions

6
st.h
View File

@ -37,6 +37,12 @@ enum glyph_attribute {
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
};
enum drawing_mode {
DRAW_NONE = 0,
DRAW_BG = 1 << 0,
DRAW_FG = 1 << 1,
};
enum selection_mode {
SEL_IDLE = 0,
SEL_EMPTY = 1,

29
x.c
View File

@ -152,7 +152,7 @@ typedef struct {
static inline ushort sixd_to_16bit(int);
static int xmakeglyphfontspecs(XftGlyphFontSpec *, const Glyph *, int, int, int);
static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int, int);
static void xdrawglyph(Glyph, int, int);
static void xclear(int, int, int, int);
static int xgeommasktogravity(int);
@ -1445,7 +1445,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
}
void
xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y, int dmode)
{
int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1);
int winx = win.hborderpx + x * win.cw, winy = win.vborderpx + y * win.ch,
@ -1531,6 +1531,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
if (base.mode & ATTR_INVISIBLE)
fg = bg;
if (dmode & DRAW_BG) {
/* Intelligent cleaning up of the borders. */
if (x == 0) {
xclear(0, (y == 0)? 0 : winy, win.vborderpx,
@ -1546,9 +1547,11 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
if (winy + win.ch >= win.vborderpx + win.th)
xclear(winx, winy + win.ch, winx + width, win.h);
/* Clean up the region we want to draw to. */
/* Fill the background */
XftDrawRect(xw.draw, bg, winx, winy, width, win.ch);
}
if (dmode & DRAW_FG) {
if (base.mode & ATTR_BOXDRAW) {
drawboxes(winx, winy, width / len, win.ch, fg, bg, specs, len);
} else {
@ -1567,6 +1570,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
width, 1);
}
}
}
void
xdrawglyph(Glyph g, int x, int y)
@ -1575,7 +1579,7 @@ xdrawglyph(Glyph g, int x, int y)
XftGlyphFontSpec spec;
numspecs = xmakeglyphfontspecs(&spec, &g, 1, x, y);
xdrawglyphfontspecs(&spec, g, numspecs, x, y);
xdrawglyphfontspecs(&spec, g, numspecs, x, y, DRAW_BG | DRAW_FG);
}
void
@ -1694,11 +1698,17 @@ xstartdraw(void)
void
xdrawline(Line line, int x1, int y1, int x2)
{
int i, x, ox, numspecs;
int i, x, ox, numspecs, numspecs_cached;
Glyph base, new;
XftGlyphFontSpec *specs = xw.specbuf;
XftGlyphFontSpec *specs;
numspecs = xmakeglyphfontspecs(specs, &line[x1], x2 - x1, x1, y1);
numspecs_cached = xmakeglyphfontspecs(xw.specbuf, &line[x1], x2 - x1, x1, y1);
/* Draw line in 2 passes: background and foreground. This way wide glyphs
won't get truncated (#223) */
for (int dmode = DRAW_BG; dmode <= DRAW_FG; dmode <<= 1) {
specs = xw.specbuf;
numspecs = numspecs_cached;
i = ox = 0;
for (x = x1; x < x2 && i < numspecs; x++) {
new = line[x];
@ -1707,7 +1717,7 @@ xdrawline(Line line, int x1, int y1, int x2)
if (selected(x, y1))
new.mode ^= ATTR_REVERSE;
if (i > 0 && ATTRCMP(base, new)) {
xdrawglyphfontspecs(specs, base, i, ox, y1);
xdrawglyphfontspecs(specs, base, i, ox, y1, dmode);
specs += i;
numspecs -= i;
i = 0;
@ -1719,7 +1729,8 @@ xdrawline(Line line, int x1, int y1, int x2)
i++;
}
if (i > 0)
xdrawglyphfontspecs(specs, base, i, ox, y1);
xdrawglyphfontspecs(specs, base, i, ox, y1, dmode);
}
}
void