Adding routine getfontucode()
This commit is contained in:
parent
644a15bb2d
commit
f8d55995df
54
xmenu.c
54
xmenu.c
|
@ -41,6 +41,7 @@ static struct Menu *parsestdin(void);
|
||||||
|
|
||||||
/* text drawer, and its helper routine */
|
/* text drawer, and its helper routine */
|
||||||
static FcChar32 getnextutf8char(const char *s, const char **end_ret);
|
static FcChar32 getnextutf8char(const char *s, const char **end_ret);
|
||||||
|
static XftFont *getfontucode(FcChar32 ucode);
|
||||||
static int drawtext(XftDraw *draw, XftColor *color, int x, int y, unsigned h, const char *text);
|
static int drawtext(XftDraw *draw, XftColor *color, int x, int y, unsigned h, const char *text);
|
||||||
|
|
||||||
/* structure setters, and their helper routines */
|
/* structure setters, and their helper routines */
|
||||||
|
@ -638,53 +639,54 @@ getnextutf8char(const char *s, const char **next_ret)
|
||||||
return ucode;
|
return ucode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* draw text into XftDraw */
|
/* get which font contains a given code point */
|
||||||
|
static XftFont *
|
||||||
|
getfontucode(FcChar32 ucode)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < dc.nfonts; i++)
|
||||||
|
if (XftCharExists(dpy, dc.fonts[i], ucode) == FcTrue)
|
||||||
|
return dc.fonts[i];
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* draw text into XftDraw, return width of text glyphs */
|
||||||
static int
|
static int
|
||||||
drawtext(XftDraw *draw, XftColor *color, int x, int y, unsigned h, const char *text)
|
drawtext(XftDraw *draw, XftColor *color, int x, int y, unsigned h, const char *text)
|
||||||
{
|
{
|
||||||
const char *s, *nexts;
|
int textwidth = 0;
|
||||||
FcChar32 ucode;
|
|
||||||
XftFont *currfont;
|
|
||||||
int textlen = 0;
|
|
||||||
int texty;
|
int texty;
|
||||||
|
|
||||||
texty = y + (h - (dc.fonts[0]->ascent + dc.fonts[0]->descent))/2 + dc.fonts[0]->ascent;
|
texty = y + (h - (dc.fonts[0]->ascent + dc.fonts[0]->descent))/2 + dc.fonts[0]->ascent;
|
||||||
|
|
||||||
s = text;
|
while (*text) {
|
||||||
while (*s) {
|
XftFont *currfont;
|
||||||
XGlyphInfo ext;
|
XGlyphInfo ext;
|
||||||
int charexists;
|
FcChar32 ucode;
|
||||||
|
const char *next;
|
||||||
size_t len;
|
size_t len;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
charexists = 0;
|
ucode = getnextutf8char(text, &next);
|
||||||
ucode = getnextutf8char(s, &nexts);
|
if ((currfont = getfontucode(ucode)) == NULL)
|
||||||
for (i = 0; i < dc.nfonts; i++) {
|
currfont = dc.fonts[0];
|
||||||
charexists = XftCharExists(dpy, dc.fonts[i], ucode);
|
|
||||||
if (charexists)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (charexists)
|
|
||||||
currfont = dc.fonts[i];
|
|
||||||
|
|
||||||
len = nexts - s;
|
len = next - text;
|
||||||
|
|
||||||
XftTextExtentsUtf8(dpy, currfont, (XftChar8 *)s,
|
XftTextExtentsUtf8(dpy, currfont, (XftChar8 *)text, len, &ext);
|
||||||
len, &ext);
|
textwidth += ext.xOff;
|
||||||
textlen += ext.xOff;
|
|
||||||
|
|
||||||
if (draw) {
|
if (draw) {
|
||||||
if (!fflag)
|
if (!fflag)
|
||||||
texty = y + (h - (currfont->ascent + currfont->descent))/2 + currfont->ascent;
|
texty = y + (h - (currfont->ascent + currfont->descent))/2 + currfont->ascent;
|
||||||
XftDrawStringUtf8(draw, color, currfont, x, texty,
|
XftDrawStringUtf8(draw, color, currfont, x, texty, (XftChar8 *)text, len);
|
||||||
(XftChar8 *)s, len);
|
|
||||||
x += ext.xOff;
|
x += ext.xOff;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = nexts;
|
text = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return textlen;
|
return textwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* setup the height, width and icon of the items of a menu */
|
/* setup the height, width and icon of the items of a menu */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user