mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 03:01:57 +02:00
Pass all opts to set_font_family
Makes it easier to specialize based on more opts in the future
This commit is contained in:
@@ -86,7 +86,7 @@ class Boss(Thread):
|
|||||||
self.pending_ui_thread_calls = Queue()
|
self.pending_ui_thread_calls = Queue()
|
||||||
self.write_dispatch_map = {}
|
self.write_dispatch_map = {}
|
||||||
set_boss(self)
|
set_boss(self)
|
||||||
cell_size.width, cell_size.height = set_font_family(opts.font_family, opts.font_size)
|
cell_size.width, cell_size.height = set_font_family(opts)
|
||||||
self.opts, self.args = opts, args
|
self.opts, self.args = opts, args
|
||||||
self.glfw_window = glfw_window
|
self.glfw_window = glfw_window
|
||||||
glfw_window.framebuffer_size_callback = self.on_window_resize
|
glfw_window.framebuffer_size_callback = self.on_window_resize
|
||||||
|
|||||||
@@ -351,7 +351,9 @@ def join_rows(width, height, rows):
|
|||||||
|
|
||||||
def test_drawing(sz=32, family='monospace'):
|
def test_drawing(sz=32, family='monospace'):
|
||||||
from .render import join_cells, display_bitmap, render_cell, set_font_family
|
from .render import join_cells, display_bitmap, render_cell, set_font_family
|
||||||
width, height = set_font_family(family, sz)
|
from kitty.config import defaults
|
||||||
|
opts = defaults._replace(font_family=family, font_size=sz)
|
||||||
|
width, height = set_font_family(opts)
|
||||||
pos = 0x2500
|
pos = 0x2500
|
||||||
rows = []
|
rows = []
|
||||||
space = render_cell()[0]
|
space = render_cell()[0]
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ main_font = {}
|
|||||||
cell_width = cell_height = baseline = CellTexture = WideCellTexture = underline_thickness = underline_position = None
|
cell_width = cell_height = baseline = CellTexture = WideCellTexture = underline_thickness = underline_position = None
|
||||||
|
|
||||||
|
|
||||||
def set_font_family(family, size_in_pts, ignore_dpi_failure=False):
|
def set_font_family(opts, ignore_dpi_failure=False):
|
||||||
global cell_width, cell_height, baseline, CellTexture, WideCellTexture, underline_thickness, underline_position
|
global cell_width, cell_height, baseline, CellTexture, WideCellTexture, underline_thickness, underline_position
|
||||||
try:
|
try:
|
||||||
dpi = get_logical_dpi()
|
dpi = get_logical_dpi()
|
||||||
@@ -19,11 +19,12 @@ def set_font_family(family, size_in_pts, ignore_dpi_failure=False):
|
|||||||
raise
|
raise
|
||||||
dpi = (72, 72) # Happens when running via develop() in an ssh session
|
dpi = (72, 72) # Happens when running via develop() in an ssh session
|
||||||
dpi = sum(dpi) / 2.0
|
dpi = sum(dpi) / 2.0
|
||||||
|
family = opts.font_family
|
||||||
if family.lower() == 'monospace':
|
if family.lower() == 'monospace':
|
||||||
family = 'Menlo'
|
family = 'Menlo'
|
||||||
for bold in (False, True):
|
for bold in (False, True):
|
||||||
for italic in (False, True):
|
for italic in (False, True):
|
||||||
main_font[(bold, italic)] = Face(family, bold, italic, True, size_in_pts, dpi)
|
main_font[(bold, italic)] = Face(family, bold, italic, True, opts.font_size, dpi)
|
||||||
mf = main_font[(False, False)]
|
mf = main_font[(False, False)]
|
||||||
cell_width, cell_height = mf.cell_size()
|
cell_width, cell_height = mf.cell_size()
|
||||||
CellTexture = ctypes.c_ubyte * (cell_width * cell_height)
|
CellTexture = ctypes.c_ubyte * (cell_width * cell_height)
|
||||||
@@ -67,13 +68,15 @@ def develop(family='monospace', sz=288):
|
|||||||
import pickle
|
import pickle
|
||||||
from .render import render_string
|
from .render import render_string
|
||||||
from kitty.fast_data_types import glfw_init
|
from kitty.fast_data_types import glfw_init
|
||||||
|
from kitty.config import defaults
|
||||||
import os
|
import os
|
||||||
glfw_init()
|
glfw_init()
|
||||||
try:
|
try:
|
||||||
os.remove('/tmp/cell.data')
|
os.remove('/tmp/cell.data')
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
pass
|
pass
|
||||||
set_font_family(family, sz, ignore_dpi_failure=True)
|
opts = defaults._replace(font_family=family, font_size=sz)
|
||||||
|
set_font_family(opts, ignore_dpi_failure=True)
|
||||||
for (bold, italic), face in main_font.items():
|
for (bold, italic), face in main_font.items():
|
||||||
print('bold: {} italic: {} {}'.format(bold, italic, face))
|
print('bold: {} italic: {} {}'.format(bold, italic, face))
|
||||||
print('cell_width: {}, cell_height: {}, baseline: {}'.format(cell_width, cell_height, baseline))
|
print('cell_width: {}, cell_height: {}, baseline: {}'.format(cell_width, cell_height, baseline))
|
||||||
|
|||||||
@@ -47,13 +47,14 @@ def font_units_to_pixels(x, units_per_em, size_in_pts, dpi):
|
|||||||
return ceil_int(x * ((size_in_pts * dpi) / (72 * units_per_em)))
|
return ceil_int(x * ((size_in_pts * dpi) / (72 * units_per_em)))
|
||||||
|
|
||||||
|
|
||||||
def set_font_family(family, size_in_pts):
|
def set_font_family(opts):
|
||||||
global current_font_family, current_font_family_name, cff_size, cell_width, cell_height, CharTexture, baseline
|
global current_font_family, current_font_family_name, cff_size, cell_width, cell_height, CharTexture, baseline
|
||||||
global underline_position, underline_thickness
|
global underline_position, underline_thickness
|
||||||
if current_font_family_name != family or cff_size != size_in_pts:
|
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()
|
find_font_for_character.cache_clear()
|
||||||
current_font_family = get_font_files(family)
|
current_font_family = get_font_files(opts.font_family)
|
||||||
current_font_family_name = family
|
current_font_family_name = opts.font_family
|
||||||
dpi = get_logical_dpi()
|
dpi = get_logical_dpi()
|
||||||
cff_size = ceil_int(64 * size_in_pts)
|
cff_size = ceil_int(64 * size_in_pts)
|
||||||
cff_size = {'width': cff_size, 'height': cff_size, 'hres': int(dpi[0]), 'vres': int(dpi[1])}
|
cff_size = {'width': cff_size, 'height': cff_size, 'hres': int(dpi[0]), 'vres': int(dpi[1])}
|
||||||
|
|||||||
@@ -89,5 +89,7 @@ def render_string(text='\'Qing👁a⧽'):
|
|||||||
|
|
||||||
|
|
||||||
def test_rendering(text='\'Ping👁a⧽', sz=144, family='monospace'):
|
def test_rendering(text='\'Ping👁a⧽', sz=144, family='monospace'):
|
||||||
set_font_family(family, sz)
|
from kitty.config import defaults
|
||||||
|
opts = defaults._replace(font_family=family, font_size=sz)
|
||||||
|
set_font_family(opts)
|
||||||
display_bitmap(*render_string(text))
|
display_bitmap(*render_string(text))
|
||||||
|
|||||||
Reference in New Issue
Block a user