Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_text/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bevy_platform = { path = "../bevy_platform", version = "0.18.0-dev", default-fea

# other
wgpu-types = { version = "26", default-features = false }
cosmic-text = { version = "0.14", features = ["shape-run-cache"] }
cosmic-text = { version = "0.15", features = ["shape-run-cache"] }
thiserror = { version = "2", default-features = false }
serde = { version = "1", features = ["derive"] }
smallvec = { version = "1", default-features = false }
Expand Down
9 changes: 4 additions & 5 deletions crates/bevy_text/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use alloc::sync::Arc;

use bevy_asset::Asset;
use bevy_reflect::TypePath;
use cosmic_text::skrifa::raw::ReadError;
use cosmic_text::skrifa::FontRef;

/// An [`Asset`] that contains the data for a loaded font, if loaded as an asset.
///
Expand All @@ -23,11 +25,8 @@ pub struct Font {

impl Font {
/// Creates a [`Font`] from bytes
pub fn try_from_bytes(
font_data: Vec<u8>,
) -> Result<Self, cosmic_text::ttf_parser::FaceParsingError> {
use cosmic_text::ttf_parser;
ttf_parser::Face::parse(&font_data, 0)?;
pub fn try_from_bytes(font_data: Vec<u8>) -> Result<Self, ReadError> {
let _ = FontRef::from_index(&font_data, 0)?;
Ok(Self {
data: Arc::new(font_data),
})
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_text/src/font_loader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::Font;
use bevy_asset::{io::Reader, AssetLoader, LoadContext};
use cosmic_text::skrifa::raw::ReadError;
use thiserror::Error;

#[derive(Default)]
Expand All @@ -12,7 +13,7 @@ pub struct FontLoader;
pub enum FontLoaderError {
/// The contents that could not be parsed
#[error(transparent)]
Content(#[from] cosmic_text::ttf_parser::FaceParsingError),
Content(#[from] ReadError),
/// An [IO](std::io) Error
#[error(transparent)]
Io(#[from] std::io::Error),
Expand Down
7 changes: 6 additions & 1 deletion crates/bevy_text/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,12 @@ impl TextPipeline {
let Some((id, _)) = self.map_handle_to_font_id.get(font) else {
continue;
};
if let Some(font) = font_system.get_font(*id) {
let weight = font_system
.db()
.face(*id)
.map(|f| f.weight)
.unwrap_or(cosmic_text::Weight::NORMAL);
if let Some(font) = font_system.get_font(*id, weight) {
let swash = font.as_swash();
let metrics = swash.metrics(&[]);
let upem = metrics.units_per_em as f32;
Expand Down