[vte/wip/sixels] all: Keep track of unscaled cell size and report window size unscaled
- From: Hans Petter Jansson <hansp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/wip/sixels] all: Keep track of unscaled cell size and report window size unscaled
- Date: Sun, 23 Aug 2020 21:48:47 +0000 (UTC)
commit 4f1f75f77baae702852528ec708884dc1ee6deae
Author: Hans Petter Jansson <hpj cl no>
Date: Sun Aug 23 23:46:42 2020 +0200
all: Keep track of unscaled cell size and report window size unscaled
This allows sixel image dimensions to be consistent when printed at
different zoom levels.
src/vte.cc | 44 ++++++++++++++++++++++++++++++++++++++------
src/vtegtk.cc | 4 ++--
src/vteinternal.hh | 6 +++++-
src/vteseq.cc | 10 +++++-----
4 files changed, 50 insertions(+), 14 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index f8592985..51c18427 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -7158,7 +7158,9 @@ Terminal::widget_mouse_leave(MouseEvent const& event)
* here. Similarly, increase cell_width_scale to get nonzero char_spacing.{left,right}.
*/
void
-Terminal::apply_font_metrics(int cell_width,
+Terminal::apply_font_metrics(int cell_width_unscaled,
+ int cell_height_unscaled,
+ int cell_width,
int cell_height,
int char_ascent,
int char_descent,
@@ -7168,6 +7170,8 @@ Terminal::apply_font_metrics(int cell_width,
bool resize = false, cresize = false;
/* Sanity check for broken font changes. */
+ cell_width_unscaled = MAX(cell_width_unscaled, 1);
+ cell_height_unscaled = MAX(cell_height_unscaled, 2);
cell_width = MAX(cell_width, 1);
cell_height = MAX(cell_height, 2);
char_ascent = MAX(char_ascent, 1);
@@ -7177,6 +7181,14 @@ Terminal::apply_font_metrics(int cell_width,
char_height = char_ascent + char_descent;
/* Change settings, and keep track of when we've changed anything. */
+ if (cell_width_unscaled != m_cell_width_unscaled) {
+ cresize = true;
+ m_cell_width_unscaled = cell_width_unscaled;
+ }
+ if (cell_height_unscaled != m_cell_height_unscaled) {
+ cresize = true;
+ m_cell_height_unscaled = cell_height_unscaled;
+ }
if (cell_width != m_cell_width) {
resize = cresize = true;
m_cell_width = cell_width;
@@ -7225,8 +7237,8 @@ Terminal::apply_font_metrics(int cell_width,
/* Update pixel size of PTY. */
pty()->set_size(m_row_count,
m_column_count,
- m_cell_height,
- m_cell_width);
+ m_cell_height_unscaled,
+ m_cell_width_unscaled);
}
emit_char_size_changed(m_cell_width, m_cell_height);
}
@@ -7243,10 +7255,23 @@ Terminal::ensure_font()
set_font_desc(m_unscaled_font_desc.get());
}
if (m_fontdirty) {
+ int cell_width_unscaled, cell_height_unscaled;
int cell_width, cell_height;
int char_ascent, char_descent;
GtkBorder char_spacing;
m_fontdirty = false;
+
+ if (!_vte_double_equal(m_font_scale, 1.)) {
+ m_draw.set_text_font(
+ m_widget,
+ m_unscaled_font_desc.get(),
+ m_cell_width_scale,
+ m_cell_height_scale);
+ m_draw.get_text_metrics(
+ &cell_width_unscaled, &cell_height_unscaled,
+ nullptr, nullptr, nullptr);
+ }
+
m_draw.set_text_font(
m_widget,
m_fontdesc.get(),
@@ -7256,7 +7281,14 @@ Terminal::ensure_font()
&cell_width, &cell_height,
&char_ascent, &char_descent,
&char_spacing);
- apply_font_metrics(cell_width, cell_height,
+
+ if (_vte_double_equal(m_font_scale, 1.)) {
+ cell_width_unscaled = cell_width;
+ cell_height_unscaled = cell_height;
+ }
+
+ apply_font_metrics(cell_width_unscaled, cell_height_unscaled,
+ cell_width, cell_height,
char_ascent, char_descent,
char_spacing);
}
@@ -7571,8 +7603,8 @@ Terminal::set_size(long columns,
*/
if (!pty()->set_size(rows,
columns,
- m_cell_height,
- m_cell_width)) {
+ m_cell_height_unscaled,
+ m_cell_width_unscaled)) {
// nothing we can do here
}
refresh_size();
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 5fcae132..eca3c32d 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -3090,8 +3090,8 @@ try
_vte_pty_set_size(pty.get(),
impl->m_row_count,
impl->m_column_count,
- impl->m_cell_height,
- impl->m_cell_width,
+ impl->m_cell_height_unscaled,
+ impl->m_cell_width_unscaled,
nullptr);
return pty.release();
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 88c2fe40..716da886 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -887,6 +887,8 @@ public:
GtkBorder m_char_padding{0, 0, 0, 0};
long m_cell_width{0};
long m_cell_height{0};
+ long m_cell_width_unscaled{0};
+ long m_cell_height_unscaled{0};
/* We allow the cell's text to draw a bit outside the cell at the top
* and bottom. The following two functions return how much is the
@@ -1307,7 +1309,9 @@ public:
void ensure_font();
void update_font();
- void apply_font_metrics(int cell_width,
+ void apply_font_metrics(int cell_width_unscaled,
+ int cell_height_unscaled,
+ int cell_width,
int cell_height,
int char_ascent,
int char_descent,
diff --git a/src/vteseq.cc b/src/vteseq.cc
index f2d1e524..66463e68 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -4385,8 +4385,8 @@ Terminal::DECSIXEL(vte::parser::Sequence const& seq)
left = m_screen->cursor.col;
top = m_screen->cursor.row;
- width = (m_sixel_state.image.width + m_cell_width - 1) / m_cell_width;
- height = (m_sixel_state.image.height + m_cell_height - 1) / m_cell_height;
+ width = (m_sixel_state.image.width + m_cell_width_unscaled - 1) / m_cell_width_unscaled;
+ height = (m_sixel_state.image.height + m_cell_height_unscaled - 1) / m_cell_height_unscaled;
pixelwidth = m_sixel_state.image.width;
pixelheight = m_sixel_state.image.height;
@@ -4414,7 +4414,7 @@ Terminal::DECSIXEL(vte::parser::Sequence const& seq)
/* Append image to Ring */
- m_screen->row_data->append_image(surface, pixelwidth, pixelheight, left, top, m_cell_width,
m_cell_height);
+ m_screen->row_data->append_image(surface, pixelwidth, pixelheight, left, top, m_cell_width_unscaled,
m_cell_height_unscaled);
/* Erase characters under the image */
@@ -8766,8 +8766,8 @@ Terminal::XTERM_WM(vte::parser::Sequence const& seq)
break;
case VTE_XTERM_WM_GET_WINDOW_SIZE_PIXELS: {
- int width = m_row_count * m_cell_height;
- int height = m_column_count * m_cell_width;
+ int width = m_row_count * m_cell_height_unscaled;
+ int height = m_column_count * m_cell_width_unscaled;
reply(seq, VTE_REPLY_XTERM_WM, {4, height, width});
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]