Update to crossfont 0.6.0

This commit is contained in:
Kirill Chibisov 2023-12-08 01:33:33 +04:00 committed by GitHub
parent cb03806e2a
commit e34762beae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 70 additions and 44 deletions

View File

@ -50,6 +50,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
if no exact binding (i.e. one with `Shift`) is found.
- Use built-in font for powerline symbols from `U+E0B0` to `U+E0B3`
- Default `bell.animation` is now `Linear`
- `IncreaseFontSize/DecreaseFontSize` step is now 1px
- `font.size` precision was raised to 6 floating point digits
### Fixed

27
Cargo.lock generated
View File

@ -43,7 +43,7 @@ dependencies = [
"clap_complete",
"cocoa",
"copypasta",
"crossfont",
"crossfont 0.6.0",
"dirs",
"embed-resource",
"gl_generator",
@ -584,6 +584,29 @@ dependencies = [
"winapi",
]
[[package]]
name = "crossfont"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80c5cf9f7d8f5478dbebc0e7a9ddcd350401e4cd9275d003481d8ec9613b7de1"
dependencies = [
"cocoa",
"core-foundation",
"core-foundation-sys",
"core-graphics",
"core-text",
"dwrote",
"foreign-types",
"freetype-rs",
"libc",
"log",
"objc",
"once_cell",
"pkg-config",
"servo-fontconfig",
"winapi",
]
[[package]]
name = "cursor-icon"
version = "1.1.0"
@ -1568,7 +1591,7 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1729a30a469de249c6effc17ec8d039b0aa29b3af79b819b7f51cb6ab8046a90"
dependencies = [
"crossfont",
"crossfont 0.5.2",
"log",
"smithay-client-toolkit",
"tiny-skia",

View File

@ -26,7 +26,7 @@ ahash = { version = "0.8.6", features = ["no-rng"] }
bitflags = "2.2.1"
clap = { version = "4.2.7", features = ["derive", "env"] }
copypasta = { version = "0.10.0", default-features = false }
crossfont = { version = "0.5.2", features = ["force_system_fontconfig"] }
crossfont = { version = "0.6.0", features = ["force_system_fontconfig"] }
glutin = { version = "0.31.1", default-features = false, features = ["egl", "wgl"] }
home = "0.5.5"
libc = "0.2"

View File

@ -20,7 +20,7 @@ use winit::dpi::PhysicalSize;
use winit::keyboard::ModifiersState;
use winit::window::CursorIcon;
use crossfont::{self, Rasterize, Rasterizer};
use crossfont::{self, Rasterize, Rasterizer, Size as FontSize};
use unicode_width::UnicodeWidthChar;
use alacritty_terminal::event::{EventListener, OnResize, WindowSize};
@ -375,6 +375,9 @@ pub struct Display {
/// Damage tracker for the given display.
pub damage_tracker: DamageTracker,
/// Font size used by the window.
pub font_size: FontSize,
// Mouse point position when highlighting hints.
hint_mouse_point: Option<Point>,
@ -398,10 +401,12 @@ impl Display {
let raw_window_handle = window.raw_window_handle();
let scale_factor = window.scale_factor as f32;
let rasterizer = Rasterizer::new(scale_factor)?;
let rasterizer = Rasterizer::new()?;
let font_size = config.font.size().scale(scale_factor);
debug!("Loading \"{}\" font", &config.font.normal().family);
let mut glyph_cache = GlyphCache::new(rasterizer, &config.font)?;
let font = config.font.clone().with_size(font_size);
let mut glyph_cache = GlyphCache::new(rasterizer, &font)?;
let metrics = glyph_cache.font_metrics();
let (cell_width, cell_height) = compute_cell_size(config, &metrics);
@ -509,6 +514,7 @@ impl Display {
glyph_cache,
hint_state,
size_info,
font_size,
window,
pending_renderer_update: Default::default(),
vi_highlighted_hint: Default::default(),
@ -566,11 +572,10 @@ impl Display {
/// This will return a tuple of the cell width and height.
fn update_font_size(
glyph_cache: &mut GlyphCache,
scale_factor: f64,
config: &UiConfig,
font: &Font,
) -> (f32, f32) {
let _ = glyph_cache.update_font_size(font, scale_factor);
let _ = glyph_cache.update_font_size(font);
// Compute new cell sizes.
compute_cell_size(config, &glyph_cache.font_metrics())
@ -610,9 +615,7 @@ impl Display {
// Update font size and cell dimensions.
if let Some(font) = pending_update.font() {
let scale_factor = self.window.scale_factor;
let cell_dimensions =
Self::update_font_size(&mut self.glyph_cache, scale_factor, config, font);
let cell_dimensions = Self::update_font_size(&mut self.glyph_cache, config, font);
cell_width = cell_dimensions.0;
cell_height = cell_dimensions.1;

View File

@ -1,7 +1,7 @@
//! Process window events.
use std::borrow::Cow;
use std::cmp::{max, min};
use std::cmp::min;
use std::collections::{HashMap, HashSet, VecDeque};
use std::error::Error;
use std::ffi::OsStr;
@ -14,7 +14,7 @@ use std::time::{Duration, Instant};
use std::{env, f32, mem};
use ahash::RandomState;
use crossfont::{self, Size};
use crossfont::Size as FontSize;
use glutin::display::{Display as GlutinDisplay, GetGlDisplay};
use log::{debug, error, info, warn};
use raw_window_handle::HasRawDisplayHandle;
@ -222,7 +222,6 @@ pub struct ActionContext<'a, N, T> {
pub scheduler: &'a mut Scheduler,
pub search_state: &'a mut SearchState,
pub inline_search_state: &'a mut InlineSearchState,
pub font_size: &'a mut Size,
pub dirty: &'a mut bool,
pub occluded: &'a mut bool,
pub preserve_title: bool,
@ -464,15 +463,19 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
}
}
fn change_font_size(&mut self, delta: f32) {
*self.font_size = max(*self.font_size + delta, Size::new(FONT_SIZE_STEP));
let font = self.config.font.clone().with_size(*self.font_size);
fn change_font_size(&mut self, delta: i32) {
let new_size = (self.display.font_size.as_px() as i32 + delta).clamp(1, u16::MAX as i32);
self.display.font_size = FontSize::from_px(new_size as u16);
let font = self.config.font.clone().with_size(self.display.font_size);
self.display.pending_update.set_font(font);
}
fn reset_font_size(&mut self) {
*self.font_size = self.config.font.size();
self.display.pending_update.set_font(self.config.font.clone());
let scale_factor = self.display.window.scale_factor as f32;
self.display.font_size = self.config.font.size().scale(scale_factor);
self.display
.pending_update
.set_font(self.config.font.clone().with_size(self.display.font_size));
}
#[inline]
@ -1165,7 +1168,8 @@ impl TouchZoom {
// Calculate font change in `FONT_SIZE_STEP` increments.
let delta = (self.distance() - old_distance) * TOUCH_ZOOM_FACTOR + self.fractions;
let font_delta = (delta.abs() / FONT_SIZE_STEP).floor() * FONT_SIZE_STEP * delta.signum();
let font_delta =
(delta.abs() / FONT_SIZE_STEP as f32).floor() * FONT_SIZE_STEP as f32 * delta.signum();
self.fractions = delta - font_delta;
font_delta
@ -1354,13 +1358,17 @@ impl input::Processor<EventProxy, ActionContext<'_, Notifier, EventProxy>> {
match event {
WindowEvent::CloseRequested => self.ctx.terminal.exit(),
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
self.ctx.window().scale_factor = scale_factor;
let old_scale_factor =
mem::replace(&mut self.ctx.window().scale_factor, scale_factor);
let display_update_pending = &mut self.ctx.display.pending_update;
// Push current font to update its scale factor.
// Rescale font size for the new factor.
let font_scale = scale_factor as f32 / old_scale_factor as f32;
self.ctx.display.font_size = self.ctx.display.font_size.scale(font_scale);
let font = self.ctx.config.font.clone();
display_update_pending.set_font(font.with_size(*self.ctx.font_size));
display_update_pending.set_font(font.with_size(self.ctx.display.font_size));
},
WindowEvent::Resized(size) => {
// Ignore resize events to zero in any dimension, to avoid issues with Winit

View File

@ -47,8 +47,8 @@ use crate::scheduler::{Scheduler, TimerId, Topic};
pub mod keyboard;
/// Font size change interval.
pub const FONT_SIZE_STEP: f32 = 0.5;
/// Font size change interval in px.
pub const FONT_SIZE_STEP: i32 = 1;
/// Interval for mouse scrolling during selection outside of the boundaries.
const SELECTION_SCROLLING_INTERVAL: Duration = Duration::from_millis(15);
@ -98,7 +98,7 @@ pub trait ActionContext<T: EventListener> {
fn create_new_window(&mut self, _tabbing_id: Option<String>) {}
#[cfg(not(target_os = "macos"))]
fn create_new_window(&mut self) {}
fn change_font_size(&mut self, _delta: f32) {}
fn change_font_size(&mut self, _delta: i32) {}
fn reset_font_size(&mut self) {}
fn pop_message(&mut self) {}
fn message(&self) -> Option<&Message>;
@ -321,7 +321,7 @@ impl<T: EventListener> Execute<T> for Action {
Action::Minimize => ctx.window().set_minimized(true),
Action::Quit => ctx.terminal_mut().exit(),
Action::IncreaseFontSize => ctx.change_font_size(FONT_SIZE_STEP),
Action::DecreaseFontSize => ctx.change_font_size(FONT_SIZE_STEP * -1.),
Action::DecreaseFontSize => ctx.change_font_size(-FONT_SIZE_STEP),
Action::ResetFontSize => ctx.reset_font_size(),
Action::ScrollPageUp
| Action::ScrollPageDown
@ -865,7 +865,7 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
},
TouchPurpose::Zoom(zoom) => {
let font_delta = zoom.font_delta(touch);
self.ctx.change_font_size(font_delta);
self.ctx.change_font_size(font_delta as i32);
},
TouchPurpose::Scroll(last_touch) => {
// Calculate delta and update last touch position.

View File

@ -275,13 +275,8 @@ impl GlyphCache {
///
/// NOTE: To reload the renderers's fonts [`Self::reset_glyph_cache`] should be called
/// afterwards.
pub fn update_font_size(
&mut self,
font: &Font,
scale_factor: f64,
) -> Result<(), crossfont::Error> {
pub fn update_font_size(&mut self, font: &Font) -> Result<(), crossfont::Error> {
// Update dpi scaling.
self.rasterizer.update_dpr(scale_factor as f32);
self.font_offset = font.offset;
self.glyph_offset = font.glyph_offset;
@ -296,7 +291,7 @@ impl GlyphCache {
})?;
let metrics = self.rasterizer.metrics(regular, font.size())?;
info!("Font size changed to {:?} with scale factor of {}", font.size(), scale_factor);
info!("Font size changed to {:?} px", font.size().as_px());
self.font_size = font.size();
self.font_key = regular;

View File

@ -9,7 +9,6 @@ use std::os::unix::io::{AsRawFd, RawFd};
use std::rc::Rc;
use std::sync::Arc;
use crossfont::Size;
use glutin::config::GetGlConfig;
use glutin::display::GetGlDisplay;
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
@ -56,7 +55,6 @@ pub struct WindowContext {
inline_search_state: InlineSearchState,
search_state: SearchState,
notifier: Notifier,
font_size: Size,
mouse: Mouse,
touch: TouchPurpose,
occluded: bool,
@ -239,12 +237,9 @@ impl WindowContext {
event_proxy.send_event(TerminalEvent::CursorBlinkingChange.into());
}
let font_size = config.font.size();
// Create context for the Alacritty window.
Ok(WindowContext {
preserve_title,
font_size,
terminal,
display,
#[cfg(not(windows))]
@ -283,12 +278,13 @@ impl WindowContext {
}
if old_config.font != self.config.font {
let scale_factor = self.display.window.scale_factor as f32;
// Do not update font size if it has been changed at runtime.
if self.font_size == old_config.font.size() {
self.font_size = self.config.font.size();
if self.display.font_size == old_config.font.size().scale(scale_factor) {
self.display.font_size = self.config.font.size().scale(scale_factor);
}
let font = self.config.font.clone().with_size(self.font_size);
let font = self.config.font.clone().with_size(self.display.font_size);
self.display.pending_update.set_font(font);
}
@ -435,7 +431,6 @@ impl WindowContext {
inline_search_state: &mut self.inline_search_state,
search_state: &mut self.search_state,
modifiers: &mut self.modifiers,
font_size: &mut self.font_size,
notifier: &mut self.notifier,
display: &mut self.display,
mouse: &mut self.mouse,