From 3c7d6f3528432a433cd368605e4dc6f0fecaa898 Mon Sep 17 00:00:00 2001 From: Bert Münnich Date: Thu, 7 Dec 2017 14:57:02 +0100 Subject: Replace utf8codepoint with Chris Wellons' utf8_decode Code under a different license should be kept in a separate file. This implemention is a single header file with ~65 lines, so it better fits this requirement. --- window.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index d1a96fb..b2d72d1 100644 --- a/window.c +++ b/window.c @@ -20,6 +20,7 @@ #define _WINDOW_CONFIG #include "config.h" #include "icon/data.h" +#include "utf8.h" #include #include @@ -131,8 +132,9 @@ void win_init(win_t *win) win->bar.l.size = BAR_L_LEN; win->bar.r.size = BAR_R_LEN; - win->bar.l.buf = emalloc(win->bar.l.size); - win->bar.r.buf = emalloc(win->bar.r.size); + /* 3 padding bytes needed by utf8_decode */ + win->bar.l.buf = emalloc(win->bar.l.size + 3); + win->bar.r.buf = emalloc(win->bar.r.size + 3); win->bar.h = options->hide_bar ? 0 : barheight; INIT_ATOM_(WM_DELETE_WINDOW); @@ -371,14 +373,14 @@ int win_textwidth(const win_env_t *e, const char *text, unsigned int len, bool w void win_draw_bar_text(win_t *win, XftDraw *d, XftColor *color, XftFont *font, int x, int y, char *text, int maxlen, int maximum_x) { size_t len = 0; - int xshift = 0, newshift; - long codep; + int err, xshift = 0, newshift; + uint32_t codep; char *p, *nextp; FcCharSet* fccharset; XftFont* fallback = NULL; for (p = text; *p && (len < maxlen); p = nextp, len++) { - nextp = utf8codepoint(p, &codep); + nextp = utf8_decode(p, &codep, &err); if (!XftCharExists(win->env.dpy, font, codep)) { fccharset = FcCharSetCreate(); FcCharSetAddChar(fccharset, codep); -- cgit v1.2.3-54-g00ecf