Update to latest cosmic-text
This commit is contained in:
parent
981a7d1682
commit
56bf0d759f
3 changed files with 8 additions and 15 deletions
|
@ -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"
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ pub struct TextRenderer {
|
|||
vertices_to_render: u32,
|
||||
glyphs_in_use: HashSet<CacheKey>,
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue