Draw: Simplify draw_text & textw
This commit is contained in:
30
src/draw.c
30
src/draw.c
@@ -116,14 +116,14 @@ draw_text(Drawable d, int x, int y, char* fg, char *str)
|
|||||||
|
|
||||||
/* To draw image everywhere we can draw text */
|
/* To draw image everywhere we can draw text */
|
||||||
#ifdef HAVE_IMLIB
|
#ifdef HAVE_IMLIB
|
||||||
char *ostr = xstrdup(str);
|
char *ostr;
|
||||||
bool ii = False;
|
size_t textlen = 0;
|
||||||
size_t textlen = strlen(ostr);
|
|
||||||
|
|
||||||
if(strstr(str, "i["))
|
if(strstr(str, "i["))
|
||||||
{
|
{
|
||||||
|
ostr = xstrdup(str);
|
||||||
|
textlen = strlen(ostr);
|
||||||
parse_image_block(d, str);
|
parse_image_block(d, str);
|
||||||
ii = True;
|
|
||||||
}
|
}
|
||||||
#endif /* HAVE_IMLIB */
|
#endif /* HAVE_IMLIB */
|
||||||
|
|
||||||
@@ -157,10 +157,11 @@ draw_text(Drawable d, int x, int y, char* fg, char *str)
|
|||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_IMLIB
|
#ifdef HAVE_IMLIB
|
||||||
if(ii)
|
if(textlen)
|
||||||
|
{
|
||||||
strncpy(str, ostr, textlen);
|
strncpy(str, ostr, textlen);
|
||||||
|
free(ostr);
|
||||||
free(ostr);
|
}
|
||||||
#endif /* HAVE_IMLIB */
|
#endif /* HAVE_IMLIB */
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -225,14 +226,14 @@ textw(char *text)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#ifdef HAVE_IMLIB
|
#ifdef HAVE_IMLIB
|
||||||
char *ostr = xstrdup(text);
|
char *ostr;
|
||||||
size_t textlen = strlen(ostr);
|
size_t textlen = 0;
|
||||||
bool ii = False;
|
|
||||||
|
|
||||||
if(strstr(text, "i["))
|
if(strstr(text, "i["))
|
||||||
{
|
{
|
||||||
|
ostr = xstrdup(text);
|
||||||
|
textlen = strlen(ostr);
|
||||||
parse_image_block(d, text);
|
parse_image_block(d, text);
|
||||||
ii = True;
|
|
||||||
}
|
}
|
||||||
#endif /* HAVE_IMLIB */
|
#endif /* HAVE_IMLIB */
|
||||||
|
|
||||||
@@ -254,10 +255,11 @@ textw(char *text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_IMLIB
|
#ifdef HAVE_IMLIB
|
||||||
if(ii)
|
if(textlen)
|
||||||
|
{
|
||||||
strncpy(text, ostr, textlen);
|
strncpy(text, ostr, textlen);
|
||||||
|
free(ostr);
|
||||||
free(ostr);
|
}
|
||||||
#endif /* HAVE_IMLIB */
|
#endif /* HAVE_IMLIB */
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user