Skip to content

Commit

Permalink
logic should be in sugarloaf instead
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Feb 24, 2025
1 parent 8b86218 commit 27dfff1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 43 deletions.
51 changes: 15 additions & 36 deletions frontends/rioterm/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use unicode_width::UnicodeWidthChar;
pub struct Renderer {
is_vi_mode_enabled: bool,
draw_bold_text_with_light_colors: bool,
builtin_box_drawing: bool,
pub named_colors: Colors,
pub colors: List,
pub navigation: ScreenNavigation,
Expand All @@ -51,11 +50,6 @@ pub struct Renderer {
active_search: Option<String>,
}

const POWERLINE_TRIANGLE_LTR: char = '\u{e0b0}';
// const POWERLINE_ARROW_LTR: char = '\u{e0b1}';
// const POWERLINE_TRIANGLE_RTL: char = '\u{e0b2}';
const POWERLINE_ARROW_RTL: char = '\u{e0b3}';

impl Renderer {
pub fn new(
config: &Config,
Expand Down Expand Up @@ -85,7 +79,6 @@ impl Renderer {
}

Renderer {
builtin_box_drawing: config.fonts.builtin_box_drawing,
draw_bold_text_with_light_colors: config.draw_bold_text_with_light_colors,
macos_use_unified_titlebar: config.window.macos_use_unified_titlebar,
config_blinking_interval: config.cursor.blinking_interval.clamp(350, 1200),
Expand Down Expand Up @@ -339,35 +332,21 @@ impl Renderer {
let mut width = square.c.width().unwrap_or(1) as f32;
let mut font_ctx = self.font_context.inner.lock();

match (self.builtin_box_drawing, square_content) {
// Box drawing characters and block elements.
(true, '\u{2500}'..='\u{259f}' | '\u{1fb00}'..='\u{1fb3b}') => {
style.font_id = 0;
}

// Powerline symbols: '','','',''
(true, POWERLINE_TRIANGLE_LTR..=POWERLINE_ARROW_RTL) => {
style.font_id = 0;
}

_ => {
// There is no simple way to define what's emoji
// could have to refer to the Unicode tables. However it could
// be leading to misleading results. For example if we used
// unicode and internationalization functionalities like
// https://github.com/open-i18n/rust-unic/, then characters
// like "◼" would be valid emojis. For a terminal context,
// the character "◼" is not an emoji and should be treated as
// single width. So, we completely rely on what font is
// being used and then set width 2 for it.
if let Some((font_id, is_emoji)) =
font_ctx.find_best_font_match(square_content, &style)
{
style.font_id = font_id;
if is_emoji {
width = 2.0;
}
}
// There is no simple way to define what's emoji
// could have to refer to the Unicode tables. However it could
// be leading to misleading results. For example if we used
// unicode and internationalization functionalities like
// https://github.com/open-i18n/rust-unic/, then characters
// like "◼" would be valid emojis. For a terminal context,
// the character "◼" is not an emoji and should be treated as
// single width. So, we completely rely on what font is
// being used and then set width 2 for it.
if let Some((font_id, is_emoji)) =
font_ctx.find_best_font_match(square_content, &style)
{
style.font_id = font_id;
if is_emoji {
width = 2.0;
}
}

Expand Down
25 changes: 18 additions & 7 deletions sugarloaf/src/font/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ use std::sync::Arc;

pub use crate::font_introspector::{Style, Weight};

// const POWERLINE_TRIANGLE_LTR: char = '\u{e0b0}';
// const POWERLINE_ARROW_LTR: char = '\u{e0b1}';
// const POWERLINE_TRIANGLE_RTL: char = '\u{e0b2}';
// const POWERLINE_ARROW_RTL: char = '\u{e0b3}';
// match (self.builtin_box_drawing, square_content) {
// // Box drawing characters and block elements.
// (true, '\u{2500}'..='\u{259f}' | '\u{1fb00}'..='\u{1fb3b}') => {
// style.font_id = 0;
// }

// // Powerline symbols: '','','',''
// (true, POWERLINE_TRIANGLE_LTR..=POWERLINE_ARROW_RTL) => {
// style.font_id = 0;
// }

// _ => {

pub fn lookup_for_font_match(
cluster: &mut CharCluster,
synth: &mut Synthesis,
Expand All @@ -36,8 +53,7 @@ pub fn lookup_for_font_match(
let mut font_synth = Synthesis::default();
let fonts_len: usize = library.inner.len();

// Note: zero it's a built-in fallback font
for font_id in 1..fonts_len {
for font_id in 0..fonts_len {
let mut is_emoji = false;

if let Some(font) = library.inner.get(&font_id) {
Expand Down Expand Up @@ -262,11 +278,6 @@ impl FontLibraryData {
let mut db = loader::Database::new();
db.load_system_fonts();

// Index zero is a fallback font, it will not be looked up
// unless it's flagged to allow builtin fallback
// this is used mostly by box drawing characters
self.insert(load_fallback_from_memory(&spec.regular));

match find_font(&db, spec.regular, false, false) {
FindResult::Found(data) => {
self.insert(data);
Expand Down

0 comments on commit 27dfff1

Please sign in to comment.