From 346af3f8b0baa418fd37b878bc2930ff0bd57cc0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 11 Sep 2023 02:47:24 +0200 Subject: Make `FontSystem` global and simplify `Paragraph` API --- wgpu/src/text.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'wgpu/src/text.rs') diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index bd4f3e06..5c9f4d7e 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -2,7 +2,7 @@ use crate::core::alignment; use crate::core::{Rectangle, Size}; use crate::graphics::color; use crate::graphics::text::cache::{self, Cache}; -use crate::graphics::text::{FontSystem, Paragraph}; +use crate::graphics::text::{font_system, Paragraph}; use crate::layer::Text; use std::borrow::Cow; @@ -10,7 +10,6 @@ use std::cell::RefCell; #[allow(missing_debug_implementations)] pub struct Pipeline { - font_system: FontSystem, renderers: Vec, atlas: glyphon::TextAtlas, prepare_layer: usize, @@ -24,7 +23,6 @@ impl Pipeline { format: wgpu::TextureFormat, ) -> Self { Pipeline { - font_system: FontSystem::new(), renderers: Vec::new(), atlas: glyphon::TextAtlas::with_color_mode( device, @@ -41,12 +39,11 @@ impl Pipeline { } } - pub fn font_system(&self) -> &FontSystem { - &self.font_system - } - pub fn load_font(&mut self, bytes: Cow<'static, [u8]>) { - self.font_system.load_font(bytes); + font_system() + .write() + .expect("Write font system") + .load_font(bytes); self.cache = RefCell::new(Cache::new()); } @@ -69,7 +66,9 @@ impl Pipeline { )); } - let font_system = self.font_system.get_mut(); + let mut font_system = font_system().write().expect("Write font system"); + let font_system = font_system.raw(); + let renderer = &mut self.renderers[self.prepare_layer]; let cache = self.cache.get_mut(); -- cgit From 6448429103c9c82b90040ac5a5a097bdded23f82 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 12 Sep 2023 14:51:00 +0200 Subject: Draft `Editor` API and `TextEditor` widget --- wgpu/src/text.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'wgpu/src/text.rs') diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 5c9f4d7e..397c38dd 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -2,7 +2,7 @@ use crate::core::alignment; use crate::core::{Rectangle, Size}; use crate::graphics::color; use crate::graphics::text::cache::{self, Cache}; -use crate::graphics::text::{font_system, Paragraph}; +use crate::graphics::text::{font_system, Editor, Paragraph}; use crate::layer::Text; use std::borrow::Cow; @@ -74,15 +74,19 @@ impl Pipeline { enum Allocation { Paragraph(Paragraph), + Editor(Editor), Cache(cache::KeyHash), } let allocations: Vec<_> = sections .iter() .map(|section| match section { - Text::Managed { paragraph, .. } => { + Text::Paragraph { paragraph, .. } => { paragraph.upgrade().map(Allocation::Paragraph) } + Text::Editor { editor, .. } => { + editor.upgrade().map(Allocation::Editor) + } Text::Cached(text) => { let (key, _) = cache.allocate( font_system, @@ -117,7 +121,7 @@ impl Pipeline { vertical_alignment, color, ) = match section { - Text::Managed { + Text::Paragraph { position, color, .. } => { use crate::core::text::Paragraph as _; @@ -135,6 +139,24 @@ impl Pipeline { *color, ) } + Text::Editor { + position, color, .. + } => { + use crate::core::text::Editor as _; + + let Some(Allocation::Editor(editor)) = allocation + else { + return None; + }; + + ( + editor.buffer(), + Rectangle::new(*position, editor.min_bounds()), + alignment::Horizontal::Left, + alignment::Vertical::Top, + *color, + ) + } Text::Cached(text) => { let Some(Allocation::Cache(key)) = allocation else { return None; -- cgit From c7d02e24e6f8265c205a68bd97b2643d40ae30ee Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 14 Sep 2023 18:57:09 +0200 Subject: Remove `Editor::min_bounds` and use `bounds` instead --- wgpu/src/text.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src/text.rs') diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 397c38dd..581df0cb 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -151,7 +151,7 @@ impl Pipeline { ( editor.buffer(), - Rectangle::new(*position, editor.min_bounds()), + Rectangle::new(*position, editor.bounds()), alignment::Horizontal::Left, alignment::Vertical::Top, *color, -- cgit From be340a8cd822be1ea0fe4c1b1f3a62ca66d705b4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 19 Sep 2023 23:00:20 +0200 Subject: Fix gamma correction for colored glyphs in `iced_wgpu` --- wgpu/src/text.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'wgpu/src/text.rs') diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 581df0cb..f746be63 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -2,7 +2,7 @@ use crate::core::alignment; use crate::core::{Rectangle, Size}; use crate::graphics::color; use crate::graphics::text::cache::{self, Cache}; -use crate::graphics::text::{font_system, Editor, Paragraph}; +use crate::graphics::text::{font_system, to_color, Editor, Paragraph}; use crate::layer::Text; use std::borrow::Cow; @@ -214,16 +214,7 @@ impl Pipeline { right: (clip_bounds.x + clip_bounds.width) as i32, bottom: (clip_bounds.y + clip_bounds.height) as i32, }, - default_color: { - let [r, g, b, a] = color::pack(color).components(); - - glyphon::Color::rgba( - (r * 255.0) as u8, - (g * 255.0) as u8, - (b * 255.0) as u8, - (a * 255.0) as u8, - ) - }, + default_color: to_color(color), }) }, ); -- cgit From 936d480267578d7e80675e78ec1880aaaaab72d6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 1 Dec 2023 16:04:27 +0100 Subject: Clip text to `viewport` bounds instead of layout bounds --- wgpu/src/text.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'wgpu/src/text.rs') diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 08a8bea6..7d73c87b 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -120,9 +120,13 @@ impl Pipeline { horizontal_alignment, vertical_alignment, color, + viewport, ) = match section { Text::Paragraph { - position, color, .. + position, + color, + viewport, + .. } => { use crate::core::text::Paragraph as _; @@ -137,10 +141,14 @@ impl Pipeline { paragraph.horizontal_alignment(), paragraph.vertical_alignment(), *color, + *viewport, ) } Text::Editor { - position, color, .. + position, + color, + viewport, + .. } => { use crate::core::text::Editor as _; @@ -155,6 +163,7 @@ impl Pipeline { alignment::Horizontal::Left, alignment::Vertical::Top, *color, + *viewport, ) } Text::Cached(text) => { @@ -173,6 +182,7 @@ impl Pipeline { text.horizontal_alignment, text.vertical_alignment, text.color, + text.viewport, ) } }; @@ -195,13 +205,8 @@ impl Pipeline { alignment::Vertical::Bottom => bounds.y - bounds.height, }; - let section_bounds = Rectangle { - x: left, - y: top, - ..bounds - }; - - let clip_bounds = layer_bounds.intersection(§ion_bounds)?; + let clip_bounds = + layer_bounds.intersection(&(viewport * scale_factor))?; Some(glyphon::TextArea { buffer, -- cgit From b526ce4958b28208395276dd4078ffe0d780e1d7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 2 Dec 2023 15:53:02 +0100 Subject: Rename `viewport` to `clip_bounds` --- wgpu/src/text.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'wgpu/src/text.rs') diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 7d73c87b..888b1924 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -120,12 +120,12 @@ impl Pipeline { horizontal_alignment, vertical_alignment, color, - viewport, + clip_bounds, ) = match section { Text::Paragraph { position, color, - viewport, + clip_bounds, .. } => { use crate::core::text::Paragraph as _; @@ -141,13 +141,13 @@ impl Pipeline { paragraph.horizontal_alignment(), paragraph.vertical_alignment(), *color, - *viewport, + *clip_bounds, ) } Text::Editor { position, color, - viewport, + clip_bounds, .. } => { use crate::core::text::Editor as _; @@ -163,7 +163,7 @@ impl Pipeline { alignment::Horizontal::Left, alignment::Vertical::Top, *color, - *viewport, + *clip_bounds, ) } Text::Cached(text) => { @@ -182,7 +182,7 @@ impl Pipeline { text.horizontal_alignment, text.vertical_alignment, text.color, - text.viewport, + text.clip_bounds, ) } }; @@ -206,7 +206,7 @@ impl Pipeline { }; let clip_bounds = - layer_bounds.intersection(&(viewport * scale_factor))?; + layer_bounds.intersection(&(clip_bounds * scale_factor))?; Some(glyphon::TextArea { buffer, -- cgit From 603832e66c710ea39a95009ddc905de20c6856bd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 5 Dec 2023 02:19:17 +0100 Subject: Introduce `RawText` to `Primitive` in `iced_graphics` This should allow users to directly render a `cosmic_text::Buffer`. --- wgpu/src/text.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'wgpu/src/text.rs') diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 888b1924..dca09cb8 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -7,6 +7,7 @@ use crate::layer::Text; use std::borrow::Cow; use std::cell::RefCell; +use std::sync::Arc; #[allow(missing_debug_implementations)] pub struct Pipeline { @@ -76,6 +77,7 @@ impl Pipeline { Paragraph(Paragraph), Editor(Editor), Cache(cache::KeyHash), + Raw(Arc), } let allocations: Vec<_> = sections @@ -107,6 +109,7 @@ impl Pipeline { Some(Allocation::Cache(key)) } + Text::Raw(text) => text.buffer.upgrade().map(Allocation::Raw), }) .collect(); @@ -185,6 +188,25 @@ impl Pipeline { text.clip_bounds, ) } + Text::Raw(text) => { + let Some(Allocation::Raw(buffer)) = allocation else { + return None; + }; + + let (width, height) = buffer.size(); + + ( + buffer.as_ref(), + Rectangle::new( + text.position, + Size::new(width, height), + ), + alignment::Horizontal::Left, + alignment::Vertical::Top, + text.color, + text.clip_bounds, + ) + } }; let bounds = bounds * scale_factor; -- cgit