Let update_cell_emtrics() know if it is being called in response to a DPI change

This commit is contained in:
Kovid Goyal 2018-02-06 20:12:57 +05:30
parent 22cf67b407
commit 328f22adab
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 9 additions and 8 deletions

View File

@ -265,12 +265,12 @@ class Boss:
def restore_font_size(self):
self.change_font_size(self.opts.font_size)
def _change_font_size(self, new_size=None):
def _change_font_size(self, new_size=None, on_dpi_change=False):
if new_size is not None:
self.current_font_size = new_size
old_cell_width, old_cell_height = viewport_for_window()[-2:]
windows = tuple(filter(None, self.window_id_map.values()))
resize_fonts(self.current_font_size)
resize_fonts(self.current_font_size, on_dpi_change=on_dpi_change)
layout_sprite_map()
prerender()
for window in windows:

View File

@ -283,7 +283,7 @@ python_send_to_gpu(unsigned int x, unsigned int y, unsigned int z, pixel* buf) {
static inline PyObject*
update_cell_metrics() {
update_cell_metrics(bool on_dpi_change UNUSED) {
#define CALL(idx, desired_height, force) { if (idx >= 0) { Font *f = fonts.fonts + idx; if ((f)->face) { if(!set_size_for_face((f)->face, desired_height, force)) return NULL; } clear_sprite_map((f)); }}
CALL(BOX_FONT, 0, false); CALL(fonts.medium_font_idx, 0, false);
CALL(fonts.bold_font_idx, 0, false); CALL(fonts.italic_font_idx, 0, false); CALL(fonts.bi_font_idx, 0, false);
@ -320,8 +320,9 @@ update_cell_metrics() {
static PyObject*
set_font_size(PyObject UNUSED *m, PyObject *args) {
if (!PyArg_ParseTuple(args, "f", &global_state.font_sz_in_pts)) return NULL;
return update_cell_metrics();
int on_dpi_change = 0;
if (!PyArg_ParseTuple(args, "f|p", &global_state.font_sz_in_pts, &on_dpi_change)) return NULL;
return update_cell_metrics(on_dpi_change != 0);
}
static inline bool
@ -896,7 +897,7 @@ set_font(PyObject UNUSED *m, PyObject *args) {
}
fonts.first_fallback_font_idx = fonts.fonts_count;
fonts.fallback_fonts_count = 0;
return update_cell_metrics();
return update_cell_metrics(false);
}
static void

View File

@ -61,9 +61,9 @@ def set_font_family(opts=None, override_font_size=None):
return cell_width, cell_height
def resize_fonts(new_sz):
def resize_fonts(new_sz, on_dpi_change=False):
s = set_font_family.state
cell_width, cell_height, baseline, underline_position, underline_thickness = set_font_size(new_sz)
cell_width, cell_height, baseline, underline_position, underline_thickness = set_font_size(new_sz, on_dpi_change)
set_font_family.state = FontState(
s.family, new_sz, cell_width, cell_height, baseline,
underline_position, underline_thickness