summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-09-02 21:39:33 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-09-02 21:39:33 +0200
commit806cc7f2a9db10aaa0de5f0bb43d7b886cd37485 (patch)
tree17c5e2f822e64bfdcf063d1e40192a5c300abfdf
parent47cef573b7e145a00182639e401148ed0b0d7f10 (diff)
downloadfeh-806cc7f2a9db10aaa0de5f0bb43d7b886cd37485.zip
imlib.c: Remove font loading code duplication (thx penma)
-rw-r--r--src/imlib.c102
1 files changed, 27 insertions, 75 deletions
diff --git a/src/imlib.c b/src/imlib.c
index 47031bd..b1a3ee0 100644
--- a/src/imlib.c
+++ b/src/imlib.c
@@ -335,29 +335,40 @@ void feh_imlib_image_fill_text_bg(Imlib_Image im, int w, int h)
gib_imlib_image_fill_rectangle(im, 0, 0, w, h, 0, 0, 0, 127);
}
-
-void feh_draw_zoom(winwidget w)
+static Imlib_Font feh_load_font(winwidget w)
{
static Imlib_Font fn = NULL;
- int tw = 0, th = 0;
- Imlib_Image im = NULL;
- char buf[100];
-
- if (!w->im)
- return;
if (opt.font)
fn = gib_imlib_load_font(opt.font);
if (!fn) {
- fn = gib_imlib_load_font(DEFAULT_FONT);
+ if (w && w->full_screen)
+ fn = gib_imlib_load_font(DEFAULT_FONT_BIG);
+ else
+ fn = gib_imlib_load_font(DEFAULT_FONT);
}
if (!fn) {
- weprintf("Couldn't load font for zoom printing");
- return;
+ eprintf("Couldn't load font to draw a message");
}
+ return fn;
+}
+
+
+void feh_draw_zoom(winwidget w)
+{
+ static Imlib_Font fn = NULL;
+ int tw = 0, th = 0;
+ Imlib_Image im = NULL;
+ char buf[100];
+
+ if (!w->im)
+ return;
+
+ fn = feh_load_font(w);
+
snprintf(buf, sizeof(buf), "%.0f%%, %dx%d", w->zoom * 100,
(int) (w->im_w * w->zoom), (int) (w->im_h * w->zoom));
@@ -410,14 +421,7 @@ void feh_draw_errstr(winwidget w)
if (!w->im)
return;
- if (opt.font)
- fn = gib_imlib_load_font(opt.font);
-
- if (!fn)
- fn = gib_imlib_load_font(DEFAULT_FONT);
-
- if (!fn)
- eprintf("Unable to draw error message. Dying to be safe.");
+ fn = feh_load_font(NULL);
/* Work out how high the font is */
gib_imlib_get_text_size(fn, w->errstr, NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT);
@@ -450,20 +454,7 @@ void feh_draw_filename(winwidget w)
|| (!FEH_FILE(w->file->data)->filename))
return;
- if (opt.font)
- fn = gib_imlib_load_font(opt.font);
-
- if (!fn) {
- if (w->full_screen)
- fn = gib_imlib_load_font(DEFAULT_FONT_BIG);
- else
- fn = gib_imlib_load_font(DEFAULT_FONT);
- }
-
- if (!fn) {
- eprintf("Couldn't load font for filename printing");
- return;
- }
+ fn = feh_load_font(w);
/* Work out how high the font is */
gib_imlib_get_text_size(fn, FEH_FILE(w->file->data)->filename, NULL, &tw,
@@ -522,20 +513,7 @@ void feh_draw_info(winwidget w)
|| (!FEH_FILE(w->file->data)->filename))
return;
- if (opt.font)
- fn = gib_imlib_load_font(opt.font);
-
- if (!fn) {
- if (w->full_screen)
- fn = gib_imlib_load_font(DEFAULT_FONT_BIG);
- else
- fn = gib_imlib_load_font(DEFAULT_FONT);
- }
-
- if (!fn) {
- eprintf("Couldn't load font for filename printing");
- return;
- }
+ fn = feh_load_font(w);
info_cmd = feh_printf(opt.info_cmd, FEH_FILE(w->file->data));
@@ -676,20 +654,7 @@ void feh_draw_caption(winwidget w)
caption_style->bits = gib_list_add_front(caption_style->bits,
gib_style_bit_new(1, 1, 0, 0, 0, 255));
- if (opt.font)
- fn = gib_imlib_load_font(opt.font);
-
- if (!fn) {
- if (w->full_screen)
- fn = gib_imlib_load_font(DEFAULT_FONT_BIG);
- else
- fn = gib_imlib_load_font(DEFAULT_FONT);
- }
-
- if (!fn) {
- eprintf("Couldn't load font for caption printing");
- return;
- }
+ fn = feh_load_font(w);
if (*(file->caption) == '\0') {
p = estrdup("Caption entry mode - Hit ESC to cancel");
@@ -999,20 +964,7 @@ void feh_draw_actions(winwidget w)
|| (!FEH_FILE(w->file->data)->filename))
return;
- if (opt.font)
- fn = gib_imlib_load_font(opt.font);
-
- if (!fn) {
- if (w->full_screen)
- fn = gib_imlib_load_font(DEFAULT_FONT_BIG);
- else
- fn = gib_imlib_load_font(DEFAULT_FONT);
- }
-
- if (!fn) {
- eprintf("Couldn't load font for actions printing");
- return;
- }
+ fn = feh_load_font(w);
gib_imlib_get_text_size(fn, "defined actions:", NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT);
/* Check for the widest line */