Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sfc-gh-dmatthews
Copy link
Collaborator

Describe your changes

Currently, when declaring a font in [[theme.fontFaces]] in config.toml, the weight field is interpreted as an integer and unicode-range is not supported at all.

This PR supports declaring weight by keyword ("normal", "bold") as well as declaring weight ranges for variable font files ("100 900"). Additionally, this adds support for unicode range. This may be beneficial if a font is broken out into different files (e.g. basic and extended latin characters) and can be helpful for localization. Even if an app developer doesn't explicitly localize their app, they can define character sets for other languages that will only conditionally load if someone uses a browser extension to translate the page, for example.

GitHub Issue Link (if applicable)

closes #11163
closes #11247

Testing Plan

  • E2E Tests added for weight and unicode range

Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@sfc-gh-dmatthews sfc-gh-dmatthews requested a review from a team as a code owner May 1, 2025 00:16
@snyk-io
Copy link
Contributor

snyk-io bot commented May 1, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@sfc-gh-dmatthews sfc-gh-dmatthews added the security-assessment-completed Security assessment has been completed for PR label May 1, 2025
@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-11248/streamlit-1.45.1-py3-none-any.whl
🕹️ Preview app pr-11248.streamlit.app (☁️ Deploy here if not accessible)

@sfc-gh-dmatthews sfc-gh-dmatthews added change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels May 1, 2025
@sfc-gh-dmatthews sfc-gh-dmatthews changed the title Fully support weight and unicode-range in @font-face declaration [WIP] Fully support weight and unicode-range in @font-face declaration May 1, 2025
@sfc-gh-dmatthews sfc-gh-dmatthews marked this pull request as draft May 1, 2025 00:18
@sfc-gh-dmatthews
Copy link
Collaborator Author

In the font tests, firefox and webkit don't show the collapse icon for the sidebar. 🤔

Comment on lines +46 to +55
{
"family": "Chimera",
"url": "./app/static/NotoSans-only-letters_and_numbers.woff2",
"unicode_range": "U+0000-0040",
},
{
"family": "Chimera",
"url": "./app/static/SourGummy-Normal-Variable.ttf",
"unicode_range": "U+0041-10FFFF",
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: Is it expected that we are trying to load in 2 more fonts with family names that do not match the underlying font file? Also curious since I see that expect_font(app, "Chimera") is failing in CI

Copy link
Collaborator Author

@sfc-gh-dmatthews sfc-gh-dmatthews May 5, 2025

Choose a reason for hiding this comment

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

Yes. This particular test case is building a font that cherry-picks different characters from different files. In this case, it uses numerals from NotoSans and alphabetic characters from SourGummy. This just happens to be an example where I can visually see that it correctly limited itself to the indicated unicode range and might not be indicative of the typical use case.

@jrieke
Copy link
Collaborator

jrieke commented May 6, 2025

@sfc-gh-dmatthews Just to double-check, the usage here would look like this, correct?

[[theme.fontFaces]]
...
weight = "100 900"
unicodeRange = "U+0025-00FF"

@sfc-gh-dmatthews
Copy link
Collaborator Author

@jrieke Yes. The following entries would all be valid:
For weight:

weight=400
weight="400"
weight="normal"
weight="400 700"

For unicode range:

unicodeRange="U+0025-00FF"
unicodeRange="U+0000-00FF, U+0131, U+0152-0153"
unicodeRange="U+0025, U+0040, U+0152"

Separately, in another PR down the road, we could also update the default font declarations to accept a string or list of strings in the same way as we allowed the dual type for weight. (When setting the default font, you can specify a list of fonts to use as fallbacks. Currently, this must be one long string, but I thought people might naturally try to enter it as an actual list in TOML, so we could offer that as a convenience.

@sfc-gh-dmatthews sfc-gh-dmatthews marked this pull request as ready for review May 22, 2025 23:04
@sfc-gh-dmatthews sfc-gh-dmatthews changed the title [WIP] Fully support weight and unicode-range in @font-face declaration Fully support weight and unicode-range in @font-face declaration May 22, 2025
const { family, weight, url, style = "normal" } = font

const { family, weight, stringWeight, url, style, unicodeRange } = font
const resolvedWeight = weight || stringWeight
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I think we might want to give stringWeight priority since its the newer option and weight is only the fallback for compatibility reasons: stringWeight || weight

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe also add a comment here that the integer based weight is used as fallback here for compatibility reasons.

Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍 I added a couple more comments. In general, I don't really like that we likely need to support two properties for weight long term. But there might not be a good alternative. We could maybe break with our compatibility guideline and change to string. This might work, but would need a bit more testing to see if it would break something in SiS.

@lukasmasuch lukasmasuch added the change:bugfix PR contains bug fix implementation label Jun 12, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch removed the change:feature PR contains new feature or enhancement implementation label Jun 12, 2025
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
@lukasmasuch lukasmasuch merged commit b262abe into develop Jun 12, 2025
37 checks passed
@lukasmasuch lukasmasuch deleted the feature/fontFaces-unicode-range branch June 12, 2025 14:54
@lukasmasuch lukasmasuch added change:feature PR contains new feature or enhancement implementation labels Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support unicode-range in font-face declaration theme.fontFaces.weight doesn't accept a weight range

7 participants