Skip to content

Commit

Permalink
chafa: Fix --font-ratio doing nothing
Browse files Browse the repository at this point in the history
Fixes #225 (GitHub).
  • Loading branch information
hpjansson committed Nov 1, 2024
1 parent b525a80 commit cdb38c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/chafa.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Fit images to the view's width, potentially exceeding its height.
<term><option>--font-ratio <replaceable>width</replaceable>/<replaceable>height</replaceable></option></term>
<listitem><para>
Target font's width/height ratio. Can be specified as a real number or a
fraction. Defaults to 1/2.
fraction. Defaults to 1/2. This will only be applied in symbol mode.
</para></listitem>
</varlistentry>

Expand Down
13 changes: 9 additions & 4 deletions tools/chafa/chafa.c
Original file line number Diff line number Diff line change
Expand Up @@ -2190,11 +2190,16 @@ parse_options (int *argc, char **argv [])
options.cell_height = detected_term_size.height_pixels / detected_term_size.height_cells;
}

if (options.font_ratio <= 0.0
&& options.cell_width > 0
&& options.cell_height > 0)
if (options.cell_width > 0 && options.cell_height > 0)
{
options.font_ratio = (gdouble) options.cell_width / (gdouble) options.cell_height;
if (options.pixel_mode == CHAFA_PIXEL_MODE_SYMBOLS && options.font_ratio > 0.0)
{
options.cell_height = options.cell_width / options.font_ratio;
}
else
{
options.font_ratio = (gdouble) options.cell_width / (gdouble) options.cell_height;
}
}

/* Assign detected or default dimensions if none specified */
Expand Down

0 comments on commit cdb38c7

Please sign in to comment.