Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose the default font bytes #14406

Merged
merged 4 commits into from
Jul 22, 2024

Conversation

seabassjh
Copy link
Contributor

@seabassjh seabassjh commented Jul 20, 2024

Objective

  • Enables use cases where third-party crates would want to use the default font as well see linebender's use

Solution

  • Uses include_bytes macro and make it pub

Co-authored-by: Spencer C. Imbleau <[email protected]>
@simbleau
Copy link
Contributor

This would help me because we have a renderer that renders text, and I'd like to add a default_font feature to my crate that propagates the default font from bevy_text.

@@ -71,6 +71,10 @@ use bevy_render::{
};
use bevy_sprite::SpriteSystem;

/// The raw data for the default font used by `bevy_text`
#[cfg(feature = "default_font")]
pub const DEFAULT_FONT: &[u8; 18848] = include_bytes!("FiraMono-subset.ttf");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be used internally somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not

Copy link
Contributor

@simbleau simbleau Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only used here:

#[cfg(feature = "default_font")]
load_internal_binary_asset!(
app,
Handle::default(),
"FiraMono-subset.ttf",
|bytes: &[u8], _path: String| { Font::try_from_bytes(bytes.to_vec()).unwrap() }
);

Copy link
Member

@BD103 BD103 Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, would it be good to implement:

const MY_FONT: &[u8] = include_bytes!("FireMono-subset.ttf");

load_internal_binary_asset!(
    app,
    Handle::default(),
    MY_FONT,
    |bytes: &[u8], _path: String| { Font::try_from_bytes(bytes.to_vec()).unwrap() }
); 

So that you could reference both the underlying const and the asset?

@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Text Rendering and layout for characters S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 20, 2024
Co-authored-by: Spencer C. Imbleau <[email protected]>
crates/bevy_text/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@simbleau simbleau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved @alice-i-cecile .

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 22, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jul 22, 2024
Merged via the queue into bevyengine:main with commit d88be59 Jul 22, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Text Rendering and layout for characters C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants