Configurable font stretch, font weight, and bold font weight
* Store a font name => font faces map * Only list font names that have `NORMAL` and `BOLD` faces with `Normal` stretch. This will give us defaults and fall-backs that are guaranteed to always exist. * Filter by stretch first, with `Normal` chosen as the always existing default. * Then only list font weights supported by the font name stretch selected, for the normal and bold cases. * When changing the font name selected, the stretch/weight options will stay the same if supported by the new font name, or revert to the always existing fall-backs. Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
This commit is contained in:
parent
c74d5d6f56
commit
5eba6eb4d6
6 changed files with 251 additions and 12 deletions
|
|
@ -16,7 +16,7 @@ use alacritty_terminal::{
|
|||
};
|
||||
use cosmic::{iced::advanced::graphics::text::font_system, widget::segmented_button};
|
||||
use cosmic_text::{
|
||||
Attrs, AttrsList, Buffer, BufferLine, CacheKeyFlags, Family, Metrics, Shaping, Weight, Wrap,
|
||||
Attrs, AttrsList, Buffer, BufferLine, CacheKeyFlags, Family, Metrics, Shaping, Weight, Stretch, Wrap,
|
||||
};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
|
|
@ -121,6 +121,7 @@ pub struct Terminal {
|
|||
size: Size,
|
||||
pub term: Arc<FairMutex<Term<EventProxy>>>,
|
||||
colors: Colors,
|
||||
bold_font_weight: Weight,
|
||||
notifier: Notifier,
|
||||
pub context_menu: Option<cosmic::iced::Point>,
|
||||
pub needs_update: bool,
|
||||
|
|
@ -132,12 +133,17 @@ impl Terminal {
|
|||
entity: segmented_button::Entity,
|
||||
event_tx: mpsc::Sender<(segmented_button::Entity, Event)>,
|
||||
config: Config,
|
||||
font_stretch: Stretch,
|
||||
font_weight: u16,
|
||||
bold_font_weight: u16,
|
||||
colors: Colors,
|
||||
) -> Self {
|
||||
let metrics = Metrics::new(14.0, 20.0);
|
||||
//TODO: set color to default fg
|
||||
let default_attrs = Attrs::new()
|
||||
.family(Family::Monospace)
|
||||
.weight(Weight(font_weight))
|
||||
.stretch(font_stretch)
|
||||
.color(convert_color(&colors, Color::Named(NamedColor::Foreground)))
|
||||
.metadata(convert_color(&colors, Color::Named(NamedColor::Background)).0 as usize);
|
||||
let mut buffer = Buffer::new_empty(metrics);
|
||||
|
|
@ -177,6 +183,7 @@ impl Terminal {
|
|||
|
||||
Self {
|
||||
colors,
|
||||
bold_font_weight: Weight(bold_font_weight),
|
||||
default_attrs,
|
||||
buffer: Arc::new(buffer),
|
||||
size,
|
||||
|
|
@ -327,6 +334,22 @@ impl Terminal {
|
|||
let mut update_cell_size = false;
|
||||
let mut update = false;
|
||||
|
||||
if self.default_attrs.stretch != config.typed_font_stretch() {
|
||||
self.default_attrs = self.default_attrs.stretch(config.typed_font_stretch());
|
||||
update_cell_size = true;
|
||||
}
|
||||
|
||||
if self.default_attrs.weight.0 != config.font_weight {
|
||||
self.default_attrs = self.default_attrs.weight(Weight(config.font_weight));
|
||||
update_cell_size = true;
|
||||
}
|
||||
|
||||
|
||||
if self.bold_font_weight.0 != config.font_weight {
|
||||
self.bold_font_weight = Weight(config.bold_font_weight);
|
||||
update_cell_size = true;
|
||||
}
|
||||
|
||||
let metrics = config.metrics(zoom_adj);
|
||||
if metrics != self.buffer.metrics() {
|
||||
{
|
||||
|
|
@ -347,6 +370,8 @@ impl Terminal {
|
|||
if changed {
|
||||
self.default_attrs = Attrs::new()
|
||||
.family(Family::Monospace)
|
||||
.weight(Weight(config.font_weight))
|
||||
.stretch(config.typed_font_stretch())
|
||||
.color(convert_color(&colors, Color::Named(NamedColor::Foreground)))
|
||||
.metadata(
|
||||
convert_color(&colors, Color::Named(NamedColor::Background)).0 as usize,
|
||||
|
|
@ -475,7 +500,7 @@ impl Terminal {
|
|||
attrs = attrs.metadata(bg.0 as usize);
|
||||
//TODO: more flags
|
||||
if indexed.cell.flags.contains(Flags::BOLD) {
|
||||
attrs = attrs.weight(Weight::BOLD);
|
||||
attrs = attrs.weight(self.bold_font_weight);
|
||||
}
|
||||
if indexed.cell.flags.contains(Flags::ITALIC) {
|
||||
//TODO: automatically use fake italic
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue