linux: Update cosmic_text (#13095)
Bumps cosmic_text, removes some stale `todo`s and stores a ShapeBuffer to prevent reallocations Improvements: - Performance should be a lot better (haven't actually tested it) - Fixed display of `\t` in the terminal   Release Notes: - N/A
This commit is contained in:
@@ -103,7 +103,7 @@ blade-graphics.workspace = true
|
||||
blade-macros.workspace = true
|
||||
blade-util.workspace = true
|
||||
bytemuck = "1"
|
||||
cosmic-text = "0.11.2"
|
||||
cosmic-text = { git = "https://github.com/pop-os/cosmic-text", rev = "542b20c" }
|
||||
copypasta = "0.10.1"
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
|
||||
@@ -6,7 +6,8 @@ use crate::{
|
||||
use anyhow::{anyhow, Context, Ok, Result};
|
||||
use collections::HashMap;
|
||||
use cosmic_text::{
|
||||
Attrs, AttrsList, BufferLine, CacheKey, Family, Font as CosmicTextFont, FontSystem, SwashCache,
|
||||
Attrs, AttrsList, CacheKey, Family, Font as CosmicTextFont, FontSystem, ShapeBuffer, ShapeLine,
|
||||
SwashCache,
|
||||
};
|
||||
|
||||
use itertools::Itertools;
|
||||
@@ -23,6 +24,7 @@ pub(crate) struct CosmicTextSystem(RwLock<CosmicTextSystemState>);
|
||||
struct CosmicTextSystemState {
|
||||
swash_cache: SwashCache,
|
||||
font_system: FontSystem,
|
||||
scratch: ShapeBuffer,
|
||||
/// Contains all already loaded fonts, including all faces. Indexed by `FontId`.
|
||||
loaded_fonts_store: Vec<Arc<CosmicTextFont>>,
|
||||
/// Caches the `FontId`s associated with a specific family to avoid iterating the font database
|
||||
@@ -42,6 +44,7 @@ impl CosmicTextSystem {
|
||||
Self(RwLock::new(CosmicTextSystemState {
|
||||
font_system,
|
||||
swash_cache: SwashCache::new(),
|
||||
scratch: ShapeBuffer::default(),
|
||||
loaded_fonts_store: Vec::new(),
|
||||
font_ids_by_family_cache: HashMap::default(),
|
||||
postscript_names: HashMap::default(),
|
||||
@@ -60,8 +63,6 @@ impl PlatformTextSystem for CosmicTextSystem {
|
||||
self.0.write().add_fonts(fonts)
|
||||
}
|
||||
|
||||
// todo(linux) ensure that this integrates with platform font loading
|
||||
// do we need to do more than call load_system_fonts()?
|
||||
fn all_font_names(&self) -> Vec<String> {
|
||||
self.0
|
||||
.read()
|
||||
@@ -367,13 +368,11 @@ impl CosmicTextSystemState {
|
||||
}
|
||||
}
|
||||
|
||||
// todo(linux) This is all a quick first pass, maybe we should be using cosmic_text::Buffer
|
||||
#[profiling::function]
|
||||
fn layout_line(&mut self, text: &str, font_size: Pixels, font_runs: &[FontRun]) -> LineLayout {
|
||||
let mut attrs_list = AttrsList::new(Attrs::new());
|
||||
let mut offs = 0;
|
||||
for run in font_runs {
|
||||
// todo(linux) We need to check we are doing utf properly
|
||||
let font = &self.loaded_fonts_store[run.font_id.0];
|
||||
let font = self.font_system.db().face(font.id()).unwrap();
|
||||
attrs_list.add_span(
|
||||
@@ -386,17 +385,27 @@ impl CosmicTextSystemState {
|
||||
);
|
||||
offs += run.len;
|
||||
}
|
||||
let mut line = BufferLine::new(text, attrs_list, cosmic_text::Shaping::Advanced);
|
||||
|
||||
let layout = line.layout(
|
||||
let mut line = ShapeLine::new_in_buffer(
|
||||
&mut self.scratch,
|
||||
&mut self.font_system,
|
||||
text,
|
||||
&attrs_list,
|
||||
cosmic_text::Shaping::Advanced,
|
||||
4,
|
||||
);
|
||||
|
||||
let mut layout = Vec::with_capacity(1);
|
||||
line.layout_to_buffer(
|
||||
&mut self.scratch,
|
||||
font_size.0,
|
||||
f32::MAX, // We do our own wrapping
|
||||
None, // We do our own wrapping
|
||||
cosmic_text::Wrap::None,
|
||||
None,
|
||||
&mut layout,
|
||||
None,
|
||||
);
|
||||
let mut runs = Vec::new();
|
||||
|
||||
let mut runs = Vec::new();
|
||||
let layout = layout.first().unwrap();
|
||||
for glyph in &layout.glyphs {
|
||||
let font_id = glyph.font_id;
|
||||
@@ -412,7 +421,7 @@ impl CosmicTextSystemState {
|
||||
// todo(linux) this is definitely wrong, each glyph in glyphs from cosmic-text is a cluster with one glyph, ShapedRun takes a run of glyphs with the same font and direction
|
||||
glyphs.push(ShapedGlyph {
|
||||
id: GlyphId(glyph.glyph_id as u32),
|
||||
position: point((glyph.x).into(), glyph.y.into()),
|
||||
position: point(glyph.x.into(), glyph.y.into()),
|
||||
index: glyph.start,
|
||||
is_emoji,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user