Pass all opts to set_font_family

Makes it easier to specialize based on more opts in the future
This commit is contained in:
Kovid Goyal 2017-01-24 08:41:32 +05:30
parent 598c5d313b
commit def51f856b
5 changed files with 18 additions and 10 deletions

View File

@ -86,7 +86,7 @@ class Boss(Thread):
self.pending_ui_thread_calls = Queue()
self.write_dispatch_map = {}
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.glfw_window = glfw_window
glfw_window.framebuffer_size_callback = self.on_window_resize

View File

@ -351,7 +351,9 @@ def join_rows(width, height, rows):
def test_drawing(sz=32, family='monospace'):
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
rows = []
space = render_cell()[0]

View File

@ -10,7 +10,7 @@ main_font = {}
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
try:
dpi = get_logical_dpi()
@ -19,11 +19,12 @@ def set_font_family(family, size_in_pts, 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'
for bold 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)]
cell_width, cell_height = mf.cell_size()
CellTexture = ctypes.c_ubyte * (cell_width * cell_height)
@ -67,13 +68,15 @@ def develop(family='monospace', sz=288):
import pickle
from .render import render_string
from kitty.fast_data_types import glfw_init
from kitty.config import defaults
import os
glfw_init()
try:
os.remove('/tmp/cell.data')
except EnvironmentError:
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():
print('bold: {} italic: {} {}'.format(bold, italic, face))
print('cell_width: {}, cell_height: {}, baseline: {}'.format(cell_width, cell_height, baseline))

View File

@ -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)))
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 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()
current_font_family = get_font_files(family)
current_font_family_name = family
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])}

View File

@ -89,5 +89,7 @@ def render_string(text='\'Qing👁a⧽'):
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))