Introduction
Introduction Statistics Contact Development Disclaimer Help
drw: simplify drw_font_xcreate and prevent a potential unneeded allocation - dm…
git clone git://git.codemadness.org/dmenu
Log
Files
Refs
README
LICENSE
---
commit e2e7fcb2198d40e2a50591932ee2b2a8f9969a5f
parent 1f2226df1380f178240bb81dddcad6c5ff2e9d62
Author: Hiltjo Posthuma <[email protected]>
Date: Tue, 20 Oct 2015 22:55:39 +0200
drw: simplify drw_font_xcreate and prevent a potential unneeded allocation
Diffstat:
M drw.c | 41 ++++++++++++++---------------…
1 file changed, 19 insertions(+), 22 deletions(-)
---
diff --git a/drw.c b/drw.c
@@ -108,12 +108,8 @@ static Fnt *
drw_font_xcreate(Drw *drw, const char *fontname, FcPattern *fontpattern)
{
Fnt *font;
-
- if (!(fontname || fontpattern))
- die("No font specified.\n");
-
- if (!(font = calloc(1, sizeof(Fnt))))
- return NULL;
+ XftFont *xfont = NULL;
+ FcPattern *pattern = NULL;
if (fontname) {
/* Using the pattern found at font->xfont->pattern does not yi…
@@ -122,28 +118,29 @@ drw_font_xcreate(Drw *drw, const char *fontname, FcPatter…
* behaviour whereas the former just results in
* missing-character-rectangles being drawn, at least with som…
*/
- if (!(font->xfont = XftFontOpenName(drw->dpy, drw->screen, fon…
- !(font->pattern = FcNameParse((FcChar8 *) fontname))) {
- if (font->xfont) {
- XftFontClose(drw->dpy, font->xfont);
- font->xfont = NULL;
- }
+ if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname)…
+ fprintf(stderr, "error, cannot load font: '%s'\n", fon…
+ return NULL;
+ }
+ if (!(pattern = FcNameParse((FcChar8 *) fontname))) {
fprintf(stderr, "error, cannot load font: '%s'\n", fon…
+ XftFontClose(drw->dpy, xfont);
+ return NULL;
}
} else if (fontpattern) {
- if (!(font->xfont = XftFontOpenPattern(drw->dpy, fontpattern)))
+ if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) {
fprintf(stderr, "error, cannot load font pattern.\n");
- else
- font->pattern = NULL;
- }
-
- if (!font->xfont) {
- free(font);
- return NULL;
+ return NULL;
+ }
+ } else {
+ die("no font specified.\n");
}
- font->ascent = font->xfont->ascent;
- font->descent = font->xfont->descent;
+ font = ecalloc(1, sizeof(Fnt));
+ font->xfont = xfont;
+ font->pattern = pattern;
+ font->ascent = xfont->ascent;
+ font->descent = xfont->descent;
font->h = font->ascent + font->descent;
font->dpy = drw->dpy;
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.