From 56bf0d759feb278aad5eb3944b467e47a0c2f04c Mon Sep 17 00:00:00 2001 From: grovesNL Date: Fri, 28 Oct 2022 01:14:07 -0230 Subject: [PATCH] Update to latest cosmic-text --- Cargo.toml | 3 +-- examples/hello-world.rs | 10 +++++----- src/text_render.rs | 10 ++-------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b9f5e15..abdd4eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,7 @@ license = "MIT OR Apache-2.0 OR Zlib" wgpu = "0.14.0" fontdue = { git = "https://github.com/mooman219/fontdue", rev = "828b4f4" } etagere = "0.2.6" -#cosmic-text = { git = "https://github.com/pop-os/cosmic-text", rev = "ef686f8" } -cosmic-text = { path = "../cosmic-text", features = ["swash"] } +cosmic-text = { git = "https://github.com/pop-os/cosmic-text", rev = "a1f7675" } [dev-dependencies] winit = "0.27.0" diff --git a/examples/hello-world.rs b/examples/hello-world.rs index 3d5c44a..91883c3 100644 --- a/examples/hello-world.rs +++ b/examples/hello-world.rs @@ -1,4 +1,4 @@ -use cosmic_text::{Attrs, FontSystem, TextBuffer, TextMetrics}; +use cosmic_text::{Attrs, FontSystem, SwashCache, TextBuffer, TextMetrics}; use glyphon::{Color, HasColor, Resolution, TextAtlas, TextRenderer}; use wgpu::{ Backends, CommandEncoderDescriptor, CompositeAlphaMode, DeviceDescriptor, Features, Instance, @@ -76,19 +76,18 @@ async fn run() { surface.configure(&device, &config); // Set up text renderer + let mut text_renderer = TextRenderer::new(&device, &queue); unsafe { FONT_SYSTEM = Some(FontSystem::new()); } + let mut cache = SwashCache::new(unsafe { FONT_SYSTEM.as_ref().unwrap() }); let mut atlas = TextAtlas::new(&device, &queue, swapchain_format); - let mut text_renderer = TextRenderer::new(&device, &queue); - let mut buffer = TextBuffer::new( unsafe { FONT_SYSTEM.as_ref().unwrap() }, - Attrs::new(), TextMetrics::new(32, 44), ); buffer.set_size((width as f64 * scale_factor) as i32, (height as f64) as i32); - buffer.set_text(include_str!("./ligature.txt")); + buffer.set_text(include_str!("./ligature.txt"), Attrs::new()); buffer.shape_until_cursor(); event_loop.run(move |event, _, control_flow| { @@ -116,6 +115,7 @@ async fn run() { height: config.height, }, &mut buffer, + &mut cache, ) .unwrap(); diff --git a/src/text_render.rs b/src/text_render.rs index ada8d5d..bc8b74b 100644 --- a/src/text_render.rs +++ b/src/text_render.rs @@ -21,7 +21,6 @@ pub struct TextRenderer { vertices_to_render: u32, glyphs_in_use: HashSet, screen_resolution: Resolution, - swash_cache: SwashCache, } impl TextRenderer { @@ -43,8 +42,6 @@ impl TextRenderer { mapped_at_creation: false, }); - let swash_cache = SwashCache::new(); - Self { vertex_buffer, vertex_buffer_size, @@ -56,7 +53,6 @@ impl TextRenderer { width: 0, height: 0, }, - swash_cache, } } @@ -68,6 +64,7 @@ impl TextRenderer { atlas: &mut TextAtlas, screen_resolution: Resolution, buffer: &mut TextBuffer<'a>, + cache: &mut SwashCache, ) -> Result<(), PrepareError> { self.screen_resolution = screen_resolution; @@ -106,10 +103,7 @@ impl TextRenderer { continue; } - let image = self - .swash_cache - .get_image_uncached(&buffer.font_matches, glyph.cache_key) - .unwrap(); + let image = cache.get_image_uncached(glyph.cache_key).unwrap(); let mut bitmap = image.data; match image.content {