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

Support CSS font size keywords #3242

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

peschwartz
Copy link

@peschwartz peschwartz commented Mar 7, 2025

Added backend support for CSS font-size keywords to Android, Cocoa, iOS, GTK, and Windows and updated the core and travertino testing suites. Includes updated documentation.

Fixes #1814

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

sasoder and others added 2 commits March 7, 2025 10:46
Add: CSS keyword constants to Travertino and update core style component #17
Update: testbed to handle CSS keywords and improve coverage #24
Add: CSS font size keywords and tests for iOS #5 #10 (#18)
Add: windows CSS keyword support and tests #6 #11 (#22)
Add: Cocoa CSS keywords support and tests #3 #8 (#23)
Add: Gtk css keywords support and tests #4 #9 (#27)
Fix: remove xxxl keywords #29
Docs: add css keywords to style reference (#33)
Add: Android support for CSS font keywords and tests #2 #7 (#28)

----------
Co-authored-by: Phoebe Schwartz <[email protected]>
Co-authored-by: KlaraLindemalm <[email protected]>
Co-authored-by: Jacmol <[email protected]>
Co-authored-by: carltestar <[email protected]>
fix relative size tests to include parent size if one exists
Copy link
Member

@mhsmith mhsmith left a comment

Choose a reason for hiding this comment

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

Thanks, this looks very thorough.

fix: remove all relative_font_size instances and update documentation

---------

Co-authored-by: phoebe <[email protected]>
@peschwartz
Copy link
Author

Hello! We've made the changes to remove the xxxl size and the relative sizes. It passes all of the CI checks but for some reason, it is not passing the docs build. Any ideas as to why?

@freakboy3742
Copy link
Member

Hello! We've made the changes to remove the xxxl size and the relative sizes. It passes all of the CI checks but for some reason, it is not passing the docs build. Any ideas as to why?

It looks like it might be related to RTD's recent switchover to their new management UI. Your original docs builds seems to have fallen into a crack somewhere; I've manually restarted the build, and it seems to have worked. Apologies for the confusion!

@peschwartz peschwartz requested a review from mhsmith March 20, 2025 12:46
Comment on lines +136 to +138
try:
Font("Comic Sans", None)
assert False, "Should have raised TypeError"
Copy link
Member

Choose a reason for hiding this comment

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

Why not use pytest.raises here as well?


**Initial value:** System default

The size of the font to be used, in :ref:`CSS points <css-units>`.
The size of the font to be used. Can be specified in three ways:
Copy link
Member

@mhsmith mhsmith Mar 24, 2025

Choose a reason for hiding this comment

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

Better not to include a number: it's easy for it to become incorrect if the list is edited in the future.

Suggested change
The size of the font to be used. Can be specified in three ways:
The size of the font to be used. Can be specified in the following ways:

Comment on lines +66 to +68
else (
f"{self.size}" if self.size in ABSOLUTE_FONT_SIZES else f"{self.size}pt"
)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
else (
f"{self.size}" if self.size in ABSOLUTE_FONT_SIZES else f"{self.size}pt"
)
else f"{self.size}" if self.size in ABSOLUTE_FONT_SIZES
else f"{self.size}pt"

@@ -93,6 +97,13 @@ def __init__(self, interface):

if self.interface.size == SYSTEM_DEFAULT_FONT_SIZE:
font_size = NSFont.systemFontSize
elif (
isinstance(self.interface.size, str)
and self.interface.size in ABSOLUTE_FONT_SIZES
Copy link
Member

Choose a reason for hiding this comment

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

The ABSOLUTE_FONT_SIZES check is unnecessary:

  • The string must already be in ABSOLUTE_FONT_SIZES, because it was validated when the font_size property was assigned.
  • Even the string wasn't in ABSOLUTE_FONT_SIZES, we still wouldn't want to format it as {self.font_size}pt.

This also applies to the similar checks in several other backends, and in pack.py.

and self.interface.size in ABSOLUTE_FONT_SIZES
):
base_size = NSFont.systemFontSize
font_size = base_size * FONT_SIZE_SCALE.get(self.interface.size, 1.0)
Copy link
Member

@mhsmith mhsmith Mar 24, 2025

Choose a reason for hiding this comment

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

The string was validated when the font_size property was assigned, so it must be in FONT_SIZE_SCALE. We can therefore use [] rather than get.

This also applies to all the other uses of get in this PR.

}

LARGER = "larger"
SMALLER = "smaller"
FONT_SIZE_SCALE_FACTOR = 1.2
Copy link
Member

Choose a reason for hiding this comment

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

This factor isn't being used anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support CSS font size keywords
4 participants