diff --git a/README.md b/README.md index 42b7093..a28b7f8 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,12 @@ See `examples` for more usage patterns! ### Supported Tags - `b`: \[b]**bold**\[/b] text -- `i`: \[i]*italic*\[/i] text +- `i`: \[i]_italic_\[/i] text - `c`: \[c=\#ff0000]colored\[/c] text - Register named colors via `ResMut` and use the names instead of hex values - `m`: \[m=foo]text with marker component\[/m] - Register marker components via `BbcodeSettings::with_marker` and use them to update text dynamically +- `font`: \[font="Fira Sans"]change the font family\[/font] ## License diff --git a/assets/fonts/FiraSans-Black.ttf b/assets/fonts/FiraSans/FiraSans-Black.ttf similarity index 100% rename from assets/fonts/FiraSans-Black.ttf rename to assets/fonts/FiraSans/FiraSans-Black.ttf diff --git a/assets/fonts/FiraSans-BlackItalic.ttf b/assets/fonts/FiraSans/FiraSans-BlackItalic.ttf similarity index 100% rename from assets/fonts/FiraSans-BlackItalic.ttf rename to assets/fonts/FiraSans/FiraSans-BlackItalic.ttf diff --git a/assets/fonts/FiraSans-Bold.ttf b/assets/fonts/FiraSans/FiraSans-Bold.ttf similarity index 100% rename from assets/fonts/FiraSans-Bold.ttf rename to assets/fonts/FiraSans/FiraSans-Bold.ttf diff --git a/assets/fonts/FiraSans-BoldItalic.ttf b/assets/fonts/FiraSans/FiraSans-BoldItalic.ttf similarity index 100% rename from assets/fonts/FiraSans-BoldItalic.ttf rename to assets/fonts/FiraSans/FiraSans-BoldItalic.ttf diff --git a/assets/fonts/FiraSans-ExtraBold.ttf b/assets/fonts/FiraSans/FiraSans-ExtraBold.ttf similarity index 100% rename from assets/fonts/FiraSans-ExtraBold.ttf rename to assets/fonts/FiraSans/FiraSans-ExtraBold.ttf diff --git a/assets/fonts/FiraSans-ExtraBoldItalic.ttf b/assets/fonts/FiraSans/FiraSans-ExtraBoldItalic.ttf similarity index 100% rename from assets/fonts/FiraSans-ExtraBoldItalic.ttf rename to assets/fonts/FiraSans/FiraSans-ExtraBoldItalic.ttf diff --git a/assets/fonts/FiraSans-ExtraLight.ttf b/assets/fonts/FiraSans/FiraSans-ExtraLight.ttf similarity index 100% rename from assets/fonts/FiraSans-ExtraLight.ttf rename to assets/fonts/FiraSans/FiraSans-ExtraLight.ttf diff --git a/assets/fonts/FiraSans-ExtraLightItalic.ttf b/assets/fonts/FiraSans/FiraSans-ExtraLightItalic.ttf similarity index 100% rename from assets/fonts/FiraSans-ExtraLightItalic.ttf rename to assets/fonts/FiraSans/FiraSans-ExtraLightItalic.ttf diff --git a/assets/fonts/FiraSans-Italic.ttf b/assets/fonts/FiraSans/FiraSans-Italic.ttf similarity index 100% rename from assets/fonts/FiraSans-Italic.ttf rename to assets/fonts/FiraSans/FiraSans-Italic.ttf diff --git a/assets/fonts/FiraSans-Light.ttf b/assets/fonts/FiraSans/FiraSans-Light.ttf similarity index 100% rename from assets/fonts/FiraSans-Light.ttf rename to assets/fonts/FiraSans/FiraSans-Light.ttf diff --git a/assets/fonts/FiraSans-LightItalic.ttf b/assets/fonts/FiraSans/FiraSans-LightItalic.ttf similarity index 100% rename from assets/fonts/FiraSans-LightItalic.ttf rename to assets/fonts/FiraSans/FiraSans-LightItalic.ttf diff --git a/assets/fonts/FiraSans-Medium.ttf b/assets/fonts/FiraSans/FiraSans-Medium.ttf similarity index 100% rename from assets/fonts/FiraSans-Medium.ttf rename to assets/fonts/FiraSans/FiraSans-Medium.ttf diff --git a/assets/fonts/FiraSans-MediumItalic.ttf b/assets/fonts/FiraSans/FiraSans-MediumItalic.ttf similarity index 100% rename from assets/fonts/FiraSans-MediumItalic.ttf rename to assets/fonts/FiraSans/FiraSans-MediumItalic.ttf diff --git a/assets/fonts/FiraSans-Regular.ttf b/assets/fonts/FiraSans/FiraSans-Regular.ttf similarity index 100% rename from assets/fonts/FiraSans-Regular.ttf rename to assets/fonts/FiraSans/FiraSans-Regular.ttf diff --git a/assets/fonts/FiraSans-SemiBold.ttf b/assets/fonts/FiraSans/FiraSans-SemiBold.ttf similarity index 100% rename from assets/fonts/FiraSans-SemiBold.ttf rename to assets/fonts/FiraSans/FiraSans-SemiBold.ttf diff --git a/assets/fonts/FiraSans-SemiBoldItalic.ttf b/assets/fonts/FiraSans/FiraSans-SemiBoldItalic.ttf similarity index 100% rename from assets/fonts/FiraSans-SemiBoldItalic.ttf rename to assets/fonts/FiraSans/FiraSans-SemiBoldItalic.ttf diff --git a/assets/fonts/FiraSans-Thin.ttf b/assets/fonts/FiraSans/FiraSans-Thin.ttf similarity index 100% rename from assets/fonts/FiraSans-Thin.ttf rename to assets/fonts/FiraSans/FiraSans-Thin.ttf diff --git a/assets/fonts/FiraSans-ThinItalic.ttf b/assets/fonts/FiraSans/FiraSans-ThinItalic.ttf similarity index 100% rename from assets/fonts/FiraSans-ThinItalic.ttf rename to assets/fonts/FiraSans/FiraSans-ThinItalic.ttf diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-Bold.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-Bold.ttf new file mode 100644 index 0000000..8c93043 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-Bold.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-BoldItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-BoldItalic.ttf new file mode 100644 index 0000000..1ddf216 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-BoldItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-ExtraBold.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-ExtraBold.ttf new file mode 100644 index 0000000..435d7a7 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-ExtraBold.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-ExtraBoldItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-ExtraBoldItalic.ttf new file mode 100644 index 0000000..79e616e Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-ExtraBoldItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-ExtraLight.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-ExtraLight.ttf new file mode 100644 index 0000000..c131cbf Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-ExtraLight.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-ExtraLightItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-ExtraLightItalic.ttf new file mode 100644 index 0000000..a768985 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-ExtraLightItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-Italic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-Italic.ttf new file mode 100644 index 0000000..ccc9d6a Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-Italic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-Light.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-Light.ttf new file mode 100644 index 0000000..15f15a2 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-Light.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-LightItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-LightItalic.ttf new file mode 100644 index 0000000..506208f Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-LightItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-Medium.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-Medium.ttf new file mode 100644 index 0000000..9767115 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-Medium.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-MediumItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-MediumItalic.ttf new file mode 100644 index 0000000..415a9e3 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-MediumItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-Regular.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-Regular.ttf new file mode 100644 index 0000000..dff66cc Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-Regular.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-SemiBold.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-SemiBold.ttf new file mode 100644 index 0000000..a70e69b Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-SemiBold.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-SemiBoldItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-SemiBoldItalic.ttf new file mode 100644 index 0000000..968602e Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-SemiBoldItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-Thin.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-Thin.ttf new file mode 100644 index 0000000..7dbe2ac Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-Thin.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMono-ThinItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMono-ThinItalic.ttf new file mode 100644 index 0000000..c6ad6c2 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMono-ThinItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Bold.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Bold.ttf new file mode 100644 index 0000000..f78f84f Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Bold.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-BoldItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-BoldItalic.ttf new file mode 100644 index 0000000..9fb8c83 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-BoldItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ExtraBold.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ExtraBold.ttf new file mode 100644 index 0000000..fe5be6a Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ExtraBold.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ExtraBoldItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ExtraBoldItalic.ttf new file mode 100644 index 0000000..59fc980 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ExtraBoldItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ExtraLight.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ExtraLight.ttf new file mode 100644 index 0000000..6da7b75 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ExtraLight.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ExtraLightItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ExtraLightItalic.ttf new file mode 100644 index 0000000..5733efc Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ExtraLightItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Italic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Italic.ttf new file mode 100644 index 0000000..4e9c380 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Italic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Light.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Light.ttf new file mode 100644 index 0000000..0b79b0c Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Light.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-LightItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-LightItalic.ttf new file mode 100644 index 0000000..b5e0842 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-LightItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Medium.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Medium.ttf new file mode 100644 index 0000000..1454372 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Medium.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-MediumItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-MediumItalic.ttf new file mode 100644 index 0000000..8d63c6c Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-MediumItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Regular.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Regular.ttf new file mode 100644 index 0000000..70d2ec9 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Regular.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-SemiBold.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-SemiBold.ttf new file mode 100644 index 0000000..ce60a88 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-SemiBold.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-SemiBoldItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-SemiBoldItalic.ttf new file mode 100644 index 0000000..3b3f8f6 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-SemiBoldItalic.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Thin.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Thin.ttf new file mode 100644 index 0000000..bea837e Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-Thin.ttf differ diff --git a/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ThinItalic.ttf b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ThinItalic.ttf new file mode 100644 index 0000000..f0bfed7 Binary files /dev/null and b/assets/fonts/JetBrainsMono/JetBrainsMonoNL-ThinItalic.ttf differ diff --git a/examples/static.rs b/examples/static.rs index 8e3b7f8..7c0e63d 100644 --- a/examples/static.rs +++ b/examples/static.rs @@ -13,7 +13,7 @@ fn setup(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); commands.spawn(BbcodeBundle::from_content( - "test [b]bold with [i]italic[/i][/b] and [c=#ff00ff]color[/c]", + r#"test [b]bold with [i]italic[/i][/b] and [c=#ff00ff]color[/c] and [font="JetBrains Mono"]different font[/font]"#, // Use the "Fira Sans" font family with a default font size of 40 BbcodeSettings::new("Fira Sans", 40., Color::WHITE), )); diff --git a/src/bevy/conversion.rs b/src/bevy/conversion.rs index eaba0f7..1e0ff8a 100644 --- a/src/bevy/conversion.rs +++ b/src/bevy/conversion.rs @@ -13,6 +13,8 @@ use super::{ #[derive(Debug, Clone)] struct BbcodeContext { + /// The name of the font family to use for the text. + font_family: String, /// Whether the text should be written **bold**. is_bold: bool, /// Whether the text should be written *italic*. @@ -69,6 +71,17 @@ impl BbcodeContext { self.clone() } } + "font" => { + if let Some(font_family) = tag.simple_param() { + Self { + font_family: font_family.clone(), + ..self.clone() + } + } else { + warn!("Missing font family name on [{}] tag", tag.name()); + self.clone() + } + } _ => self.clone(), } } @@ -103,6 +116,7 @@ pub fn convert_bbcode( construct_recursively( &mut entity_commands, BbcodeContext { + font_family: settings.font_family.clone(), is_bold: false, is_italic: false, color: settings.color.clone(), @@ -128,7 +142,10 @@ fn construct_recursively( match **node { BbcodeNode::Text(ref text) => { let font_query = fontdb::Query { - families: &[fontdb::Family::Name(&settings.font_family)], + families: &[ + fontdb::Family::Name(&context.font_family), + fontdb::Family::Name(&settings.font_family), + ], weight: if context.is_bold { fontdb::Weight::BOLD } else {