mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-09 23:54:20 +02:00
Allow setting bold/italic font variants individually
This commit is contained in:
@@ -105,7 +105,6 @@ type_map = {
|
||||
'window_border_width': float,
|
||||
'wheel_scroll_multiplier': float,
|
||||
'click_interval': float,
|
||||
'select_by_word_characters': str,
|
||||
'mouse_hide_wait': float,
|
||||
'cursor_blink_interval': float,
|
||||
'cursor_stop_blinking_after': float,
|
||||
|
||||
@@ -19,12 +19,19 @@ def set_font_family(opts, ignore_dpi_failure=False):
|
||||
raise
|
||||
dpi = (72, 72) # Happens when running via develop() in an ssh session
|
||||
dpi = sum(dpi) / 2.0
|
||||
family = opts.font_family
|
||||
if family.lower() == 'monospace':
|
||||
family = 'Menlo'
|
||||
attr_map = {(False, False): 'font_family', (True, False): 'bold_font', (False, True): 'italic_font', (True, True): 'bold_italic_font'}
|
||||
|
||||
def get_family(bold, italic):
|
||||
ans = getattr(opts, attr_map[(bold, italic)])
|
||||
if ans.lower() == 'monospace':
|
||||
ans = 'Menlo'
|
||||
if ans == 'auto' and (bold or italic):
|
||||
ans = get_family(False, False)
|
||||
return ans
|
||||
|
||||
for bold in (False, True):
|
||||
for italic in (False, True):
|
||||
main_font[(bold, italic)] = Face(family, bold, italic, True, opts.font_size, dpi)
|
||||
main_font[(bold, italic)] = Face(get_family(bold, italic), bold, italic, True, opts.font_size, dpi)
|
||||
mf = main_font[(False, False)]
|
||||
cell_width, cell_height = mf.cell_size()
|
||||
CellTexture = ctypes.c_ubyte * (cell_width * cell_height)
|
||||
|
||||
@@ -50,13 +50,21 @@ def get_font_information(q, bold=False, italic=False):
|
||||
return get_font(q, bold, italic)
|
||||
|
||||
|
||||
def get_font_files(family):
|
||||
def get_font_files(opts):
|
||||
ans = {}
|
||||
n = get_font_information(family)
|
||||
attr_map = {'bold': 'bold_font', 'italic': 'italic_font', 'bi': 'bold_italic_font'}
|
||||
|
||||
def get_family(key=None):
|
||||
ans = getattr(opts, attr_map.get(key, 'font_family'))
|
||||
if ans == 'auto' and key:
|
||||
ans = get_family()
|
||||
return ans
|
||||
|
||||
n = get_font_information(get_family())
|
||||
ans['regular'] = Font(Face(n.face), n.hinting, n.hintstyle, n.bold, n.italic)
|
||||
|
||||
def do(key):
|
||||
b = get_font_information(family, bold=key in ('bold', 'bi'), italic=key in ('italic', 'bi'))
|
||||
b = get_font_information(get_family(key), bold=key in ('bold', 'bi'), italic=key in ('italic', 'bi'))
|
||||
if b.face != n.face:
|
||||
ans[key] = Font(Face(b.face), b.hinting, b.hintstyle, b.bold, b.italic)
|
||||
do('bold'), do('italic'), do('bi')
|
||||
|
||||
@@ -51,24 +51,23 @@ def set_font_family(opts):
|
||||
global current_font_family, current_font_family_name, cff_size, cell_width, cell_height, CharTexture, baseline
|
||||
global underline_position, underline_thickness
|
||||
size_in_pts = opts.font_size
|
||||
if current_font_family_name != opts.font_family or cff_size != size_in_pts:
|
||||
find_font_for_character.cache_clear()
|
||||
current_font_family = get_font_files(opts.font_family)
|
||||
current_font_family_name = opts.font_family
|
||||
dpi = get_logical_dpi()
|
||||
cff_size = ceil_int(64 * size_in_pts)
|
||||
cff_size = {'width': cff_size, 'height': cff_size, 'hres': int(dpi[0]), 'vres': int(dpi[1])}
|
||||
for fobj in current_font_family.values():
|
||||
set_char_size(fobj.face, **cff_size)
|
||||
face = current_font_family['regular'].face
|
||||
cell_width = calc_cell_width(current_font_family['regular'], face)
|
||||
cell_height = font_units_to_pixels(face.height, face.units_per_EM, size_in_pts, dpi[1])
|
||||
baseline = font_units_to_pixels(face.ascender, face.units_per_EM, size_in_pts, dpi[1])
|
||||
underline_position = min(baseline - font_units_to_pixels(face.underline_position, face.units_per_EM, size_in_pts, dpi[1]), cell_height - 1)
|
||||
underline_thickness = font_units_to_pixels(face.underline_thickness, face.units_per_EM, size_in_pts, dpi[1])
|
||||
CharTexture = ctypes.c_ubyte * (cell_width * cell_height)
|
||||
font_for_char.cache_clear()
|
||||
alt_face_cache.clear()
|
||||
find_font_for_character.cache_clear()
|
||||
current_font_family = get_font_files(opts)
|
||||
current_font_family_name = opts.font_family
|
||||
dpi = get_logical_dpi()
|
||||
cff_size = ceil_int(64 * size_in_pts)
|
||||
cff_size = {'width': cff_size, 'height': cff_size, 'hres': int(dpi[0]), 'vres': int(dpi[1])}
|
||||
for fobj in current_font_family.values():
|
||||
set_char_size(fobj.face, **cff_size)
|
||||
face = current_font_family['regular'].face
|
||||
cell_width = calc_cell_width(current_font_family['regular'], face)
|
||||
cell_height = font_units_to_pixels(face.height, face.units_per_EM, size_in_pts, dpi[1])
|
||||
baseline = font_units_to_pixels(face.ascender, face.units_per_EM, size_in_pts, dpi[1])
|
||||
underline_position = min(baseline - font_units_to_pixels(face.underline_position, face.units_per_EM, size_in_pts, dpi[1]), cell_height - 1)
|
||||
underline_thickness = font_units_to_pixels(face.underline_thickness, face.units_per_EM, size_in_pts, dpi[1])
|
||||
CharTexture = ctypes.c_ubyte * (cell_width * cell_height)
|
||||
font_for_char.cache_clear()
|
||||
alt_face_cache.clear()
|
||||
return cell_width, cell_height
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
# vim:fileencoding=utf-8:ft=conf
|
||||
|
||||
# Font family
|
||||
# Font family. You can also specify different fonts for the
|
||||
# bold/italic/bold-italic variants. By default they are derived automatically,
|
||||
# by the OSes font system. Setting them manually is useful for font families
|
||||
# that have many weight variants like Book, Medium, Thick, etc. For example:
|
||||
# font_family Operator Mono Book
|
||||
# bold_font Operator Mono Thick
|
||||
# bold_talic_font Operator Mono Medium
|
||||
font_family monospace
|
||||
italic_font auto
|
||||
bold_font auto
|
||||
bold_italic_font auto
|
||||
|
||||
# Font size (in pts)
|
||||
font_size 11.0
|
||||
|
||||
Reference in New Issue
Block a user