Update to latest cosmic-text

This commit is contained in:
grovesNL 2022-10-28 01:14:07 -02:30 committed by Josh Groves
parent 981a7d1682
commit 56bf0d759f
3 changed files with 8 additions and 15 deletions

View file

@ -11,8 +11,7 @@ license = "MIT OR Apache-2.0 OR Zlib"
wgpu = "0.14.0" wgpu = "0.14.0"
fontdue = { git = "https://github.com/mooman219/fontdue", rev = "828b4f4" } fontdue = { git = "https://github.com/mooman219/fontdue", rev = "828b4f4" }
etagere = "0.2.6" etagere = "0.2.6"
#cosmic-text = { git = "https://github.com/pop-os/cosmic-text", rev = "ef686f8" } cosmic-text = { git = "https://github.com/pop-os/cosmic-text", rev = "a1f7675" }
cosmic-text = { path = "../cosmic-text", features = ["swash"] }
[dev-dependencies] [dev-dependencies]
winit = "0.27.0" winit = "0.27.0"

View file

@ -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 glyphon::{Color, HasColor, Resolution, TextAtlas, TextRenderer};
use wgpu::{ use wgpu::{
Backends, CommandEncoderDescriptor, CompositeAlphaMode, DeviceDescriptor, Features, Instance, Backends, CommandEncoderDescriptor, CompositeAlphaMode, DeviceDescriptor, Features, Instance,
@ -76,19 +76,18 @@ async fn run() {
surface.configure(&device, &config); surface.configure(&device, &config);
// Set up text renderer // Set up text renderer
let mut text_renderer = TextRenderer::new(&device, &queue);
unsafe { unsafe {
FONT_SYSTEM = Some(FontSystem::new()); 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 atlas = TextAtlas::new(&device, &queue, swapchain_format);
let mut text_renderer = TextRenderer::new(&device, &queue);
let mut buffer = TextBuffer::new( let mut buffer = TextBuffer::new(
unsafe { FONT_SYSTEM.as_ref().unwrap() }, unsafe { FONT_SYSTEM.as_ref().unwrap() },
Attrs::new(),
TextMetrics::new(32, 44), TextMetrics::new(32, 44),
); );
buffer.set_size((width as f64 * scale_factor) as i32, (height as f64) as i32); 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(); buffer.shape_until_cursor();
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
@ -116,6 +115,7 @@ async fn run() {
height: config.height, height: config.height,
}, },
&mut buffer, &mut buffer,
&mut cache,
) )
.unwrap(); .unwrap();

View file

@ -21,7 +21,6 @@ pub struct TextRenderer {
vertices_to_render: u32, vertices_to_render: u32,
glyphs_in_use: HashSet<CacheKey>, glyphs_in_use: HashSet<CacheKey>,
screen_resolution: Resolution, screen_resolution: Resolution,
swash_cache: SwashCache,
} }
impl TextRenderer { impl TextRenderer {
@ -43,8 +42,6 @@ impl TextRenderer {
mapped_at_creation: false, mapped_at_creation: false,
}); });
let swash_cache = SwashCache::new();
Self { Self {
vertex_buffer, vertex_buffer,
vertex_buffer_size, vertex_buffer_size,
@ -56,7 +53,6 @@ impl TextRenderer {
width: 0, width: 0,
height: 0, height: 0,
}, },
swash_cache,
} }
} }
@ -68,6 +64,7 @@ impl TextRenderer {
atlas: &mut TextAtlas, atlas: &mut TextAtlas,
screen_resolution: Resolution, screen_resolution: Resolution,
buffer: &mut TextBuffer<'a>, buffer: &mut TextBuffer<'a>,
cache: &mut SwashCache,
) -> Result<(), PrepareError> { ) -> Result<(), PrepareError> {
self.screen_resolution = screen_resolution; self.screen_resolution = screen_resolution;
@ -106,10 +103,7 @@ impl TextRenderer {
continue; continue;
} }
let image = self let image = cache.get_image_uncached(glyph.cache_key).unwrap();
.swash_cache
.get_image_uncached(&buffer.font_matches, glyph.cache_key)
.unwrap();
let mut bitmap = image.data; let mut bitmap = image.data;
match image.content { match image.content {