Skip to content

Commit c8872c7

Browse files
authored
Allow access to font atlases (#18851)
# Objective 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. ## Solution Make `FontFaceInfo`, `TextPipeline::map_handle_to_font_id`, and `load_font_fontdb` public so third-party crates can access and update the existing font atlases
1 parent 3edacb5 commit c8872c7

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

crates/bevy_text/src/pipeline.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,15 @@ impl Default for SwashCache {
5353

5454
/// Information about a font collected as part of preparing for text layout.
5555
#[derive(Clone)]
56-
struct FontFaceInfo {
57-
stretch: cosmic_text::fontdb::Stretch,
58-
style: cosmic_text::fontdb::Style,
59-
weight: cosmic_text::fontdb::Weight,
60-
family_name: Arc<str>,
56+
pub struct FontFaceInfo {
57+
/// Width class: <https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswidthclass>
58+
pub stretch: cosmic_text::fontdb::Stretch,
59+
/// Allows italic or oblique faces to be selected
60+
pub style: cosmic_text::fontdb::Style,
61+
/// The degree of blackness or stroke thickness
62+
pub weight: cosmic_text::fontdb::Weight,
63+
/// Font family name
64+
pub family_name: Arc<str>,
6165
}
6266

6367
/// The `TextPipeline` is used to layout and render text blocks (see `Text`/[`Text2d`](crate::Text2d)).
@@ -66,7 +70,7 @@ struct FontFaceInfo {
6670
#[derive(Default, Resource)]
6771
pub struct TextPipeline {
6872
/// Identifies a font [`ID`](cosmic_text::fontdb::ID) by its [`Font`] [`Asset`](bevy_asset::Asset).
69-
map_handle_to_font_id: HashMap<AssetId<Font>, (cosmic_text::fontdb::ID, Arc<str>)>,
73+
pub map_handle_to_font_id: HashMap<AssetId<Font>, (cosmic_text::fontdb::ID, Arc<str>)>,
7074
/// Buffered vec for collecting spans.
7175
///
7276
/// See [this dark magic](https://users.rust-lang.org/t/how-to-cache-a-vectors-capacity/94478/10).
@@ -484,7 +488,8 @@ impl TextMeasureInfo {
484488
}
485489
}
486490

487-
fn load_font_to_fontdb(
491+
/// Add the font to the cosmic text's `FontSystem`'s in-memory font database
492+
pub fn load_font_to_fontdb(
488493
text_font: &TextFont,
489494
font_system: &mut cosmic_text::FontSystem,
490495
map_handle_to_font_id: &mut HashMap<AssetId<Font>, (cosmic_text::fontdb::ID, Arc<str>)>,

0 commit comments

Comments
 (0)