aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--font/src/lib.rs2
-rw-r--r--src/config.rs8
-rw-r--r--src/display.rs25
-rw-r--r--src/renderer/mod.rs6
-rw-r--r--src/term/mod.rs20
5 files changed, 29 insertions, 32 deletions
diff --git a/font/src/lib.rs b/font/src/lib.rs
index ad1f4f80..330ed362 100644
--- a/font/src/lib.rs
+++ b/font/src/lib.rs
@@ -166,7 +166,7 @@ impl Hash for GlyphKey {
}
/// Font size stored as integer
-#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Size(i16);
impl Size {
diff --git a/src/config.rs b/src/config.rs
index e7ab3403..2a2ba6db 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1467,13 +1467,9 @@ impl Font {
}
/// Get a font clone with a size modification
- pub fn with_size_delta(self, delta: f32) -> Font {
- let mut new_size = self.size.as_f32_pts() + delta;
- if new_size < 1.0 {
- new_size = 1.0;
- }
+ pub fn with_size(self, size: Size) -> Font {
Font {
- size : Size::new(new_size),
+ size,
.. self
}
}
diff --git a/src/display.rs b/src/display.rs
index 89403194..5ca2abb5 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -96,7 +96,7 @@ pub struct Display {
rx: mpsc::Receiver<(u32, u32)>,
tx: mpsc::Sender<(u32, u32)>,
meter: Meter,
- font_size_modifier: i8,
+ font_size: font::Size,
size_info: SizeInfo,
last_background_color: Rgb,
}
@@ -150,7 +150,7 @@ impl Display {
let mut renderer = QuadRenderer::new(config, viewport_size)?;
let (glyph_cache, cell_width, cell_height) =
- Self::new_glyph_cache(&window, &mut renderer, config, 0)?;
+ Self::new_glyph_cache(&window, &mut renderer, config)?;
let dimensions = options.dimensions()
@@ -205,17 +205,16 @@ impl Display {
tx: tx,
rx: rx,
meter: Meter::new(),
- font_size_modifier: 0,
+ font_size: font::Size::new(0.),
size_info: size_info,
last_background_color: background_color,
})
}
- fn new_glyph_cache(window : &Window, renderer : &mut QuadRenderer,
- config: &Config, font_size_delta: i8)
+ fn new_glyph_cache(window : &Window, renderer : &mut QuadRenderer, config: &Config)
-> Result<(GlyphCache, f32, f32), Error>
{
- let font = config.font().clone().with_size_delta(font_size_delta as f32);
+ let font = config.font().clone();
let dpr = window.hidpi_factor();
let rasterizer = font::Rasterizer::new(dpr, config.use_thin_strokes())?;
@@ -245,10 +244,11 @@ impl Display {
Ok((glyph_cache, cell_width as f32, cell_height as f32))
}
- pub fn update_glyph_cache(&mut self, config: &Config, font_size_delta: i8) {
+ pub fn update_glyph_cache(&mut self, config: &Config) {
let cache = &mut self.glyph_cache;
+ let size = self.font_size;
self.renderer.with_loader(|mut api| {
- let _ = cache.update_font_size(config.font(), font_size_delta, &mut api);
+ let _ = cache.update_font_size(config.font(), size, &mut api);
});
let metrics = cache.font_metrics();
@@ -282,11 +282,10 @@ impl Display {
new_size = Some(sz);
}
- if terminal.font_size_modifier != self.font_size_modifier {
- // Font size modification detected
-
- self.font_size_modifier = terminal.font_size_modifier;
- self.update_glyph_cache(config, terminal.font_size_modifier);
+ // Font size modification detected
+ if terminal.font_size != self.font_size {
+ self.font_size = terminal.font_size;
+ self.update_glyph_cache(config);
if new_size == None {
// Force a resize to refresh things
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index 318a1835..9d52b024 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -295,7 +295,7 @@ impl GlyphCache {
pub fn update_font_size<L: LoadGlyph>(
&mut self,
font: &config::Font,
- delta: i8,
+ size: font::Size,
loader: &mut L
) -> Result<(), font::Error> {
// Clear currently cached data in both GL and the registry
@@ -303,8 +303,8 @@ impl GlyphCache {
self.cache = HashMap::default();
// Recompute font keys
- let font = font.to_owned().with_size_delta(delta as _);
- println!("{:?}", font.size);
+ let font = font.to_owned().with_size(size);
+ info!("Font size changed: {:?}", font.size);
let (regular, bold, italic) = Self::compute_font_keys(&font, &mut self.rasterizer)?;
self.rasterizer.get_glyph(&GlyphKey { font_key: regular, c: 'm', size: font.size() })?;
let metrics = self.rasterizer.metrics(regular)?;
diff --git a/src/term/mod.rs b/src/term/mod.rs
index e43ea7b6..7e6ff1e0 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -22,7 +22,7 @@ use std::time::{Duration, Instant};
use arraydeque::ArrayDeque;
use unicode_width::UnicodeWidthChar;
-use font;
+use font::{self, Size};
use ansi::{self, Color, NamedColor, Attr, Handler, CharsetIndex, StandardCharset, CursorStyle};
use grid::{BidirectionalIterator, Grid, ClearRegion, ToRange, Indexed};
use index::{self, Point, Column, Line, Linear, IndexRange, Contains, RangeInclusive};
@@ -685,8 +685,9 @@ pub struct Term {
/// Scroll region
scroll_region: Range<Line>,
- /// Font size modifier
- pub font_size_modifier: i8,
+ /// Font size
+ pub font_size: Size,
+ original_font_size: Size,
/// Size
size_info: SizeInfo,
@@ -814,7 +815,8 @@ impl Term {
grid: grid,
alt_grid: alt,
alt: false,
- font_size_modifier: 0,
+ font_size: config.font().size(),
+ original_font_size: config.font().size(),
active_charset: Default::default(),
cursor: Default::default(),
cursor_save: Default::default(),
@@ -834,14 +836,14 @@ impl Term {
}
pub fn change_font_size(&mut self, delta: i8) {
- if let Some(sum) = self.font_size_modifier.checked_add(delta) {
- self.font_size_modifier = sum;
- self.dirty = true;
- }
+ // Saturating addition with minimum font size 1
+ let new_size = self.font_size + Size::new(delta as f32);
+ self.font_size = max(new_size, Size::new(1.));
+ self.dirty = true;
}
pub fn reset_font_size(&mut self) {
- self.font_size_modifier = 0;
+ self.font_size = self.original_font_size;
self.dirty = true;
}