Repository navigation
Fix Text italic, bold strings, gradient colors, and swallowed errors - #2920
Merged
Merged
Conversation
- Setting Text.italic now changes the font. It sets pyglet's "style" document style, which picks the font, instead of Label.italic, which sets an "italic" style that doesn't. "oblique" is also accepted. - bold strings such as "light" or "semibold" set that weight instead of all being treated as bold, including "normal". The bold getter returns the weight name for weights other than bold and normal. - pyglet LinearGradient colors work in Text, draw_text, create_text_sprite, and UILabel.update_font, and the color getter returns the gradient. This also fixes the mypy error in text.py. - The Text constructor only defers label creation when there is no window yet, so bad arguments raise right away. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR 3 of the text improvements. It fixes four bugs in
arcade.Textproperties, all reproduced ondevelopmentwith pyglet 3.0.dev11.italicsetter had no visible effecttext.italic = Truedrew the same as normal textText(..., italic=True)boldstrings were ignoredbold="light","semibold", even"normal": all drawn bold, and the getter returnedTrue"light"etc.LinearGradientcolors crashedTypeError: cannot unpack non-iterable LinearGradient objectin the constructor, the setter, the getter,draw_text, andcreate_text_spritetext.colorreturns the gradientText("x", 0, 0, font_name=123)or an unknown keyword "worked", then raised the first time the text was usedDetails
Label.italicsets an"italic"document style, but pyglet picks the font from the"style"style (pyglet/text/document.py,get_font). The constructor already passedstyle=, so only the setter was broken. The setter and getter now use"style"."oblique"andpyglet.enums.Stylevalues are accepted too. The getter returnsTruefor italic,Falsefor normal, and the name otherwise, the same asbold. This looks like a pyglet bug too; I can report it upstream if you want.True→"bold",False→"normal". Strings andpyglet.enums.Weightvalues are passed through. The docstring listed"semilight", which isn't a pyglet weight, so it now points topyglet.enums.Weight.Styleis astrenum without__str__, sostr(Style.ITALIC)is"Style.ITALIC"and pyglet's DirectWrite backend raisesKeyError. Enum members are converted with.value.Text.colorgetter is now typedColor | LinearGradient. When it isn't a gradient, it's still aColor.UILabel.font_colorandUILabel.update_font(font_color=...)match, andupdate_fonttakesitalic: bool | str. Its docstring saidFalsemeans"regular", but it means"normal".text.pyerror that has been ondevelopmentsince the dev11 upgrade, with no new errors.Tests
tests/unit/text/test_text_style.py(21 tests) uses the bundled Liberation Sans, so CI renders the same fonts:italicandboldvalues, including enums.bold="normal"renders likebold=False.draw_textwith a gradient, alternating with a plain color, keeps one cached label.font_nameraises in the constructor.Textcreated with no window still works later (with italic, bold, and gradient set).test_update_font_italic_bold_and_gradientintest_uilabel.py, which also checks that re-applying the same values doesn't trigger a render.On
development, 18 of the new tests fail. The 4 that pass checkboldvalues that already worked, kept as regression guards.Full suite on pyglet 3.0.dev11: 1513 passed, no warnings, and the same 3 render tests failing only on my machine. Ruff is clean. I also checked
create_text_spritewith a gradient by hand.The changelog has an entry under Unreleased → Fixes.
🤖 Generated with Claude Code