From 2ec1284dceaa35ab190ae7c36de1796c53c1a876 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Tue, 15 Apr 2025 11:38:54 +0100 Subject: [PATCH 1/3] It's not possible atm for third-party crates to create their own text systems that use the existing cosmic-text `FontSystem` and font atlases. Make `FontFaceInfo`, `TextPipeline::map_handle_to_font_id`, and `load_font_fontdb` public to allow the use of the exisiting font atlases so third-party text widgets like a text input don't have to create duplicate font atlases for already loaded fonts. --- crates/bevy_text/src/pipeline.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index c1f9ca7fe4920..62fe6538241cf 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -53,11 +53,15 @@ impl Default for SwashCache { /// Information about a font collected as part of preparing for text layout. #[derive(Clone)] -struct FontFaceInfo { - stretch: cosmic_text::fontdb::Stretch, - style: cosmic_text::fontdb::Style, - weight: cosmic_text::fontdb::Weight, - family_name: Arc, +pub struct FontFaceInfo { + /// Width class (https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswidthclass) + pub stretch: cosmic_text::fontdb::Stretch, + /// Allows italic or oblique faces to be selected + pub style: cosmic_text::fontdb::Style, + /// The degree of blackness or stroke thickness + pub weight: cosmic_text::fontdb::Weight, + /// Font family name + pub family_name: Arc, } /// The `TextPipeline` is used to layout and render text blocks (see `Text`/[`Text2d`](crate::Text2d)). @@ -66,7 +70,7 @@ struct FontFaceInfo { #[derive(Default, Resource)] pub struct TextPipeline { /// Identifies a font [`ID`](cosmic_text::fontdb::ID) by its [`Font`] [`Asset`](bevy_asset::Asset). - map_handle_to_font_id: HashMap, (cosmic_text::fontdb::ID, Arc)>, + pub map_handle_to_font_id: HashMap, (cosmic_text::fontdb::ID, Arc)>, /// Buffered vec for collecting spans. /// /// See [this dark magic](https://users.rust-lang.org/t/how-to-cache-a-vectors-capacity/94478/10). @@ -452,7 +456,8 @@ impl TextMeasureInfo { } } -fn load_font_to_fontdb( +/// Add the font to the cosmic text's FontSystem's in-memory font database +pub fn load_font_to_fontdb( text_font: &TextFont, font_system: &mut cosmic_text::FontSystem, map_handle_to_font_id: &mut HashMap, (cosmic_text::fontdb::ID, Arc)>, From 1158cf5e21d22dc08a83483d89588475fa793603 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Tue, 15 Apr 2025 11:50:36 +0100 Subject: [PATCH 2/3] Add doc link --- crates/bevy_text/src/pipeline.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index 62fe6538241cf..83746bd07091a 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -456,7 +456,7 @@ impl TextMeasureInfo { } } -/// Add the font to the cosmic text's FontSystem's in-memory font database +/// Add the font to the cosmic text's `FontSystem`'s in-memory font database pub fn load_font_to_fontdb( text_font: &TextFont, font_system: &mut cosmic_text::FontSystem, From 7c113a40325147b745a075e7318c89d1df0060d1 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Mon, 12 May 2025 11:19:45 +0100 Subject: [PATCH 3/3] Fixed doc hyperlink --- crates/bevy_text/src/pipeline.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index 404f0f0c74132..7ecfc63e54ca3 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -54,7 +54,7 @@ impl Default for SwashCache { /// Information about a font collected as part of preparing for text layout. #[derive(Clone)] pub struct FontFaceInfo { - /// Width class (https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswidthclass) + /// Width class: pub stretch: cosmic_text::fontdb::Stretch, /// Allows italic or oblique faces to be selected pub style: cosmic_text::fontdb::Style,