mirror of
https://github.com/LukeSmithxyz/st.git
synced 2024-11-24 16:05:47 +01:00
patched in st-glyph-wide-support
This commit is contained in:
parent
36d225d71d
commit
212609048b
2 changed files with 79 additions and 72 deletions
6
st.h
6
st.h
|
@ -39,6 +39,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,
|
||||||
|
|
41
x.c
41
x.c
|
@ -159,7 +159,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);
|
||||||
|
@ -1538,7 +1538,7 @@ 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 = borderpx + x * win.cw, winy = borderpx + y * win.ch,
|
int winx = borderpx + x * win.cw, winy = borderpx + y * win.ch,
|
||||||
|
@ -1629,6 +1629,7 @@ 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;
|
||||||
|
|
||||||
|
if (dmode & DRAW_BG) {
|
||||||
/* Intelligent cleaning up of the borders. */
|
/* Intelligent cleaning up of the borders. */
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
xclear(0, (y == 0)? 0 : winy, borderpx,
|
xclear(0, (y == 0)? 0 : winy, borderpx,
|
||||||
|
@ -1643,17 +1644,12 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
|
||||||
xclear(winx, 0, winx + width, borderpx);
|
xclear(winx, 0, winx + width, borderpx);
|
||||||
if (winy + win.ch >= borderpx + win.th)
|
if (winy + win.ch >= borderpx + win.th)
|
||||||
xclear(winx, winy + win.ch, winx + width, win.h);
|
xclear(winx, winy + win.ch, winx + width, win.h);
|
||||||
|
/* Fill the background */
|
||||||
/* Clean up the region we want to draw to. */
|
|
||||||
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 (dmode & DRAW_FG) {
|
||||||
if (base.mode & ATTR_BOXDRAW) {
|
if (base.mode & ATTR_BOXDRAW) {
|
||||||
drawboxes(winx, winy, width / len, win.ch, fg, bg, specs, len);
|
drawboxes(winx, winy, width / len, win.ch, fg, bg, specs, len);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1668,12 +1664,10 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base.mode & ATTR_STRUCK) {
|
if (base.mode & ATTR_STRUCK) {
|
||||||
XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent * chscale / 3,
|
XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent / 3,
|
||||||
width, 1);
|
width, 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Reset clip to none. */
|
|
||||||
XftDrawSetClip(xw.draw, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1683,7 +1677,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
|
||||||
|
@ -1821,11 +1815,17 @@ 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);
|
||||||
|
|
||||||
|
/* 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;
|
i = ox = 0;
|
||||||
for (x = x1; x < x2 && i < numspecs; x++) {
|
for (x = x1; x < x2 && i < numspecs; x++) {
|
||||||
new = line[x];
|
new = line[x];
|
||||||
|
@ -1834,7 +1834,7 @@ xdrawline(Line line, int x1, int y1, int x2)
|
||||||
if (selected(x, y1))
|
if (selected(x, y1))
|
||||||
new.mode ^= ATTR_REVERSE;
|
new.mode ^= ATTR_REVERSE;
|
||||||
if (i > 0 && ATTRCMP(base, new)) {
|
if (i > 0 && ATTRCMP(base, new)) {
|
||||||
xdrawglyphfontspecs(specs, base, i, ox, y1);
|
xdrawglyphfontspecs(specs, base, i, ox, y1, dmode);
|
||||||
specs += i;
|
specs += i;
|
||||||
numspecs -= i;
|
numspecs -= i;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
@ -1846,7 +1846,8 @@ xdrawline(Line line, int x1, int y1, int x2)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
xdrawglyphfontspecs(specs, base, i, ox, y1);
|
xdrawglyphfontspecs(specs, base, i, ox, y1, dmode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue