Merge pull request #224 from Azumgi/glyph_truncation_fix

Glyph truncation fix
This commit is contained in:
Luke Smith 2020-06-13 07:56:08 -04:00 committed by GitHub
commit 222eac739d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 66 deletions

6
st.h
View File

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

132
x.c
View File

@ -152,7 +152,7 @@ typedef struct {
static inline ushort sixd_to_16bit(int); static inline ushort sixd_to_16bit(int);
static int xmakeglyphfontspecs(XftGlyphFontSpec *, const Glyph *, int, int, 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 xdrawglyph(Glyph, int, int);
static void xclear(int, int, int, int); static void xclear(int, int, int, int);
static int xgeommasktogravity(int); static int xgeommasktogravity(int);
@ -1445,14 +1445,13 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
} }
void 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 charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1);
int winx = win.hborderpx + x * win.cw, winy = win.vborderpx + y * win.ch, int winx = win.hborderpx + x * win.cw, winy = win.vborderpx + y * win.ch,
width = charlen * win.cw; width = charlen * win.cw;
Color *fg, *bg, *temp, revfg, revbg, truefg, truebg; Color *fg, *bg, *temp, revfg, revbg, truefg, truebg;
XRenderColor colfg, colbg; XRenderColor colfg, colbg;
XRectangle r;
/* Fallback on color display for attributes not supported by the font */ /* Fallback on color display for attributes not supported by the font */
if (base.mode & ATTR_ITALIC && base.mode & ATTR_BOLD) { if (base.mode & ATTR_ITALIC && base.mode & ATTR_BOLD) {
@ -1532,51 +1531,45 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
if (base.mode & ATTR_INVISIBLE) if (base.mode & ATTR_INVISIBLE)
fg = bg; fg = bg;
/* Intelligent cleaning up of the borders. */ if (dmode & DRAW_BG) {
if (x == 0) { /* Intelligent cleaning up of the borders. */
xclear(0, (y == 0)? 0 : winy, win.vborderpx, if (x == 0) {
winy + win.ch + xclear(0, (y == 0)? 0 : winy, win.vborderpx,
((winy + win.ch >= win.vborderpx + win.th)? win.h : 0)); winy + win.ch +
} ((winy + win.ch >= win.vborderpx + win.th)? win.h : 0));
if (winx + width >= win.hborderpx + win.tw) { }
xclear(winx + width, (y == 0)? 0 : winy, win.w, if (winx + width >= win.hborderpx + win.tw) {
((winy + win.ch >= win.vborderpx + win.th)? win.h : (winy + win.ch))); xclear(winx + width, (y == 0)? 0 : winy, win.w,
} ((winy + win.ch >= win.vborderpx + win.th)? win.h : (winy + win.ch)));
if (y == 0) }
xclear(winx, 0, winx + width, win.hborderpx); if (y == 0)
if (winy + win.ch >= win.vborderpx + win.th) xclear(winx, 0, winx + width, win.hborderpx);
xclear(winx, winy + win.ch, winx + width, win.h); 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); XftDrawRect(xw.draw, bg, winx, winy, width, win.ch);
/* Set the clip region because Xft is sometimes dirty. */
r.x = 0;
r.y = 0;
r.height = win.ch;
r.width = width;
XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1);
if (base.mode & ATTR_BOXDRAW) {
drawboxes(winx, winy, width / len, win.ch, fg, bg, specs, len);
} else {
/* Render the glyphs. */
XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
} }
/* Render underline and strikethrough. */ if (dmode & DRAW_FG) {
if (base.mode & ATTR_UNDERLINE) { if (base.mode & ATTR_BOXDRAW) {
XftDrawRect(xw.draw, fg, winx, winy + win.cyo + dc.font.ascent + 1, drawboxes(winx, winy, width / len, win.ch, fg, bg, specs, len);
width, 1); } else {
} /* Render the glyphs. */
XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
}
if (base.mode & ATTR_STRUCK) { /* Render underline and strikethrough. */
XftDrawRect(xw.draw, fg, winx, winy + win.cyo + 2 * dc.font.ascent / 3, if (base.mode & ATTR_UNDERLINE) {
width, 1); XftDrawRect(xw.draw, fg, winx, winy + win.cyo + dc.font.ascent + 1,
} width, 1);
}
/* Reset clip to none. */ if (base.mode & ATTR_STRUCK) {
XftDrawSetClip(xw.draw, 0); XftDrawRect(xw.draw, fg, winx, winy + win.cyo + 2 * dc.font.ascent / 3,
width, 1);
}
}
} }
void void
@ -1586,7 +1579,7 @@ xdrawglyph(Glyph g, int x, int y)
XftGlyphFontSpec spec; XftGlyphFontSpec spec;
numspecs = xmakeglyphfontspecs(&spec, &g, 1, x, y); numspecs = xmakeglyphfontspecs(&spec, &g, 1, x, y);
xdrawglyphfontspecs(&spec, g, numspecs, x, y); xdrawglyphfontspecs(&spec, g, numspecs, x, y, DRAW_BG | DRAW_FG);
} }
void void
@ -1705,32 +1698,39 @@ xstartdraw(void)
void void
xdrawline(Line line, int x1, int y1, int x2) xdrawline(Line line, int x1, int y1, int x2)
{ {
int i, x, ox, numspecs; int i, x, ox, numspecs, numspecs_cached;
Glyph base, new; 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);
i = ox = 0;
for (x = x1; x < x2 && i < numspecs; x++) { /* Draw line in 2 passes: background and foreground. This way wide glyphs
new = line[x]; won't get truncated (#223) */
if (new.mode == ATTR_WDUMMY) for (int dmode = DRAW_BG; dmode <= DRAW_FG; dmode <<= 1) {
continue; specs = xw.specbuf;
if (selected(x, y1)) numspecs = numspecs_cached;
new.mode ^= ATTR_REVERSE; i = ox = 0;
if (i > 0 && ATTRCMP(base, new)) { for (x = x1; x < x2 && i < numspecs; x++) {
xdrawglyphfontspecs(specs, base, i, ox, y1); new = line[x];
specs += i; if (new.mode == ATTR_WDUMMY)
numspecs -= i; continue;
i = 0; if (selected(x, y1))
new.mode ^= ATTR_REVERSE;
if (i > 0 && ATTRCMP(base, new)) {
xdrawglyphfontspecs(specs, base, i, ox, y1, dmode);
specs += i;
numspecs -= i;
i = 0;
}
if (i == 0) {
ox = x;
base = new;
}
i++;
} }
if (i == 0) { if (i > 0)
ox = x; xdrawglyphfontspecs(specs, base, i, ox, y1, dmode);
base = new;
}
i++;
} }
if (i > 0)
xdrawglyphfontspecs(specs, base, i, ox, y1);
} }
void void