pango: Remove unused format specifier - wmenu - 🔧 fork of wmenu
 (HTM) git clone git@git.drkhsh.at/wmenu.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 554f3e7445234b5a60dd403aed9ef0db7437eb90
 (DIR) parent ccca01d3cd6b7cc13cd9d65896f6d577acf7eee7
 (HTM) Author: adnano <me@adnano.co>
       Date:   Sat, 15 Jul 2023 18:51:45 -0400
       
       pango: Remove unused format specifier
       
       Diffstat:
         M main.c                              |      12 ++++++------
         M pango.c                             |      41 ++++---------------------------
         M pango.h                             |       4 ++--
       
       3 files changed, 13 insertions(+), 44 deletions(-)
       ---
 (DIR) diff --git a/main.c b/main.c
       @@ -110,7 +110,7 @@ int render_text(struct menu_state *state, cairo_t *cairo, const char *str,
                        int left_padding, int right_padding) {
        
                int text_width, text_height;
       -        get_text_size(cairo, state->font, &text_width, &text_height, NULL, 1, "%s", str);
       +        get_text_size(cairo, state->font, &text_width, &text_height, NULL, 1, str);
                int text_y = (state->line_height / 2.0) - (text_height / 2.0);
        
                if (background) {
       @@ -122,7 +122,7 @@ int render_text(struct menu_state *state, cairo_t *cairo, const char *str,
        
                cairo_move_to(cairo, x + left_padding, y + text_y);
                cairo_set_source_u32(cairo, foreground);
       -        pango_printf(cairo, state->font, 1, "%s", str);
       +        pango_printf(cairo, state->font, 1, str);
        
                return x + text_width + left_padding + right_padding;
        }
       @@ -133,7 +133,7 @@ int render_horizontal_item(struct menu_state *state, cairo_t *cairo, const char 
                        int left_padding, int right_padding) {
        
                int text_width, text_height;
       -        get_text_size(cairo, state->font, &text_width, &text_height, NULL, 1, "%s", str);
       +        get_text_size(cairo, state->font, &text_width, &text_height, NULL, 1, str);
                int text_y = (state->line_height / 2.0) - (text_height / 2.0);
        
                if (x + left_padding + text_width > width) {
       @@ -148,7 +148,7 @@ int render_horizontal_item(struct menu_state *state, cairo_t *cairo, const char 
        
                        cairo_move_to(cairo, x + left_padding, y + text_y);
                        cairo_set_source_u32(cairo, foreground);
       -                pango_printf(cairo, state->font, 1, "%s", str);
       +                pango_printf(cairo, state->font, 1, str);
                }
        
                return x + text_width + left_padding + right_padding;
       @@ -160,7 +160,7 @@ void render_vertical_item(struct menu_state *state, cairo_t *cairo, const char *
                        int left_padding) {
        
                int text_height;
       -        get_text_size(cairo, state->font, NULL, &text_height, NULL, 1, "%s", str);
       +        get_text_size(cairo, state->font, NULL, &text_height, NULL, 1, str);
                int text_y = (state->line_height / 2.0) - (text_height / 2.0);
        
                if (background) {
       @@ -172,7 +172,7 @@ void render_vertical_item(struct menu_state *state, cairo_t *cairo, const char *
        
                cairo_move_to(cairo, x + left_padding, y + text_y);
                cairo_set_source_u32(cairo, foreground);
       -        pango_printf(cairo, state->font, 1, "%s", str);
       +        pango_printf(cairo, state->font, 1, str);
        }
        
        void scroll_matches(struct menu_state *state) {
 (DIR) diff --git a/pango.c b/pango.c
       @@ -38,55 +38,25 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
        }
        
        void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
       -                int *baseline, double scale, const char *fmt, ...) {
       -        va_list args;
       -        va_start(args, fmt);
       -        // Add one since vsnprintf excludes null terminator.
       -        int length = vsnprintf(NULL, 0, fmt, args) + 1;
       -        va_end(args);
       -
       -        char *buf = malloc(length);
       -        if (buf == NULL) {
       -                return;
       -        }
       -        va_start(args, fmt);
       -        vsnprintf(buf, length, fmt, args);
       -        va_end(args);
       -
       -        PangoLayout *layout = get_pango_layout(cairo, font, buf, scale);
       +                int *baseline, double scale, const char *text) {
       +        PangoLayout *layout = get_pango_layout(cairo, font, text, scale);
                pango_cairo_update_layout(cairo, layout);
                pango_layout_get_pixel_size(layout, width, height);
                if (baseline) {
                        *baseline = pango_layout_get_baseline(layout) / PANGO_SCALE;
                }
       -
                g_object_unref(layout);
       -        free(buf);
        }
        
        int text_width(cairo_t *cairo, const char *font, const char *text) {
                int text_width;
       -        get_text_size(cairo, font, &text_width, NULL, NULL, 1, "%s", text);
       +        get_text_size(cairo, font, &text_width, NULL, NULL, 1, text);
                return text_width;
        }
        
        void pango_printf(cairo_t *cairo, const char *font, double scale,
       -                const char *fmt, ...) {
       -        va_list args;
       -        va_start(args, fmt);
       -        // Add one since vsnprintf excludes null terminator.
       -        int length = vsnprintf(NULL, 0, fmt, args) + 1;
       -        va_end(args);
       -
       -        char *buf = malloc(length);
       -        if (buf == NULL) {
       -                return;
       -        }
       -        va_start(args, fmt);
       -        vsnprintf(buf, length, fmt, args);
       -        va_end(args);
       -
       -        PangoLayout *layout = get_pango_layout(cairo, font, buf, scale);
       +                const char *text) {
       +        PangoLayout *layout = get_pango_layout(cairo, font, text, scale);
                cairo_font_options_t *fo = cairo_font_options_create();
                cairo_get_font_options(cairo, fo);
                pango_cairo_context_set_font_options(pango_layout_get_context(layout), fo);
       @@ -94,5 +64,4 @@ void pango_printf(cairo_t *cairo, const char *font, double scale,
                pango_cairo_update_layout(cairo, layout);
                pango_cairo_show_layout(cairo, layout);
                g_object_unref(layout);
       -        free(buf);
        }
 (DIR) diff --git a/pango.h b/pango.h
       @@ -10,9 +10,9 @@ int get_font_height(const char *font);
        PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
                        const char *text, double scale);
        void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
       -                int *baseline, double scale, const char *fmt, ...);
       +                int *baseline, double scale, const char *text);
        int text_width(cairo_t *cairo, const char *font, const char *text);
        void pango_printf(cairo_t *cairo, const char *font, double scale,
       -                const char *fmt, ...);
       +                const char *text);
        
        #endif