From 941c55317293b060acc2675cd201d655f38f7b96 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 26 Aug 2017 14:14:51 +0530 Subject: [PATCH] Implement an option to adjust the line height Fixes #116 --- kitty/config.py | 7 +++++++ kitty/fonts/core_text.py | 3 ++- kitty/fonts/freetype.py | 3 ++- kitty/kitty.conf | 8 ++++++++ kitty/utils.py | 6 ++++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/kitty/config.py b/kitty/config.py index cfbd4ef64..d02969436 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -198,7 +198,14 @@ def positive_float(x): return max(0, float(x)) +def adjust_line_height(x): + if x.endswith('%'): + return float(x[:-1]) / 100.0 + return int(x) + + type_map = { + 'adjust_line_height': adjust_line_height, 'scrollback_lines': positive_int, 'scrollback_pager': shlex.split, 'scrollback_in_new_tab': to_bool, diff --git a/kitty/fonts/core_text.py b/kitty/fonts/core_text.py index 8ad377ebf..f9abd335e 100644 --- a/kitty/fonts/core_text.py +++ b/kitty/fonts/core_text.py @@ -7,7 +7,7 @@ import sys from kitty.fast_data_types import CTFace as Face, coretext_all_fonts -from kitty.utils import ceil_int, get_logical_dpi, safe_print, wcwidth +from kitty.utils import ceil_int, get_logical_dpi, safe_print, wcwidth, adjust_line_height main_font = {} symbol_map = {} @@ -93,6 +93,7 @@ def set_font_family(opts, override_font_size=None, ignore_dpi_failure=False): install_symbol_map(all_fonts, opts.symbol_map, font_size, dpi) mf = main_font[(False, False)] cell_width, cell_height = mf.cell_size() + cell_height = adjust_line_height(cell_height, opts.adjust_line_height) CellTexture = ctypes.c_ubyte * (cell_width * cell_height) WideCellTexture = ctypes.c_ubyte * (2 * cell_width * cell_height) baseline = int(round(mf.ascent)) diff --git a/kitty/fonts/freetype.py b/kitty/fonts/freetype.py index 848cb90fd..ddf7d7ff9 100644 --- a/kitty/fonts/freetype.py +++ b/kitty/fonts/freetype.py @@ -12,7 +12,7 @@ from kitty.fast_data_types import FT_PIXEL_MODE_GRAY, Face from kitty.fonts.box_drawing import render_missing_glyph -from kitty.utils import ceil_int, get_logical_dpi, safe_print, wcwidth +from kitty.utils import ceil_int, get_logical_dpi, safe_print, wcwidth, adjust_line_height from .fontconfig import ( FontNotFound, find_font_for_character, font_for_family, get_font_files @@ -93,6 +93,7 @@ def set_font_family(opts, override_font_size=None): cell_height = font_units_to_pixels( face.height, face.units_per_EM, size_in_pts, dpi[1] ) + cell_height = adjust_line_height(cell_height, opts.adjust_line_height) baseline = font_units_to_pixels( face.ascender, face.units_per_EM, size_in_pts, dpi[1] ) diff --git a/kitty/kitty.conf b/kitty/kitty.conf index 61f79ea06..fc865c2e6 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -25,6 +25,14 @@ font_size 11.0 # the font size in a running terminal. font_size_delta 2 + +# Adjust the line height. +# You can use either numbers, which are interpreted as pixels or percentages +# (number followed by %), which are interpreted as percentages of the +# unmodified line height. You can use negative pixels or percentages less than +# 100% to reduce line height (but this might cause rendering artifacts). +adjust_line_height 0 + # The foreground color foreground #dddddd diff --git a/kitty/utils.py b/kitty/utils.py index 60ac335f4..a3b48ef3a 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -226,3 +226,9 @@ def detach(fork=True, setsid=True, redirect=True): os.setsid() if redirect: redirect_std_streams(os.devnull) + + +def adjust_line_height(cell_height, val): + if isinstance(val, int): + return cell_height + val + return int(cell_height * val)