Skip to content

Fix Text italic, bold strings, gradient colors, and swallowed errors - #2920

Merged
pvcraven merged 1 commit into
developmentfrom
fix/text-properties
Oct 6, 2026
Merged

pvcraven merged 1 commit into
developmentfrom
fix/text-properties

Conversation

@pvcraven

@pvcraven pvcraven commented Oct 6, 2026

Copy link
Copy Markdown
Member

Summary

PR 3 of the text improvements. It fixes four bugs in arcade.Text properties, all reproduced on development with pyglet 3.0.dev11.

Problem Before After
The italic setter had no visible effect text.italic = True drew the same as normal text Draws exactly like Text(..., italic=True)
bold strings were ignored bold="light", "semibold", even "normal": all drawn bold, and the getter returned True Sets that weight, and the getter returns "light" etc.
LinearGradient colors crashed TypeError: cannot unpack non-iterable LinearGradient object in the constructor, the setter, the getter, draw_text, and create_text_sprite Gradients work, and text.color returns the gradient
The constructor swallowed every error Text("x", 0, 0, font_name=123) or an unknown keyword "worked", then raised the first time the text was used Raises in the constructor. Creation is only deferred when there's no window yet

Details

  • italic: pyglet's Label.italic sets an "italic" document style, but pyglet picks the font from the "style" style (pyglet/text/document.py, get_font). The constructor already passed style=, so only the setter was broken. The setter and getter now use "style". "oblique" and pyglet.enums.Style values are accepted too. The getter returns True for italic, False for normal, and the name otherwise, the same as bold. This looks like a pyglet bug too; I can report it upstream if you want.
  • bold: True → "bold", False → "normal". Strings and pyglet.enums.Weight values are passed through. The docstring listed "semilight", which isn't a pyglet weight, so it now points to pyglet.enums.Weight.
  • Enum gotcha: Style is a str enum without __str__, so str(Style.ITALIC) is "Style.ITALIC" and pyglet's DirectWrite backend raises KeyError. Enum members are converted with .value.
  • Color type: the Text.color getter is now typed Color | LinearGradient. When it isn't a gradient, it's still a Color. UILabel.font_color and UILabel.update_font(font_color=...) match, and update_font takes italic: bool | str. Its docstring said False means "regular", but it means "normal".
  • mypy: this fixes the text.py error that has been on development since the dev11 upgrade, with no new errors.

Tests

  • New tests/unit/text/test_text_style.py (21 tests) uses the bundled Liberation Sans, so CI renders the same fonts:
    • The italic setter renders pixel-identical to the constructor version, and different from normal. Setting it back gives normal again.
    • Getters and setters for all italic and bold values, including enums.
    • bold="normal" renders like bold=False.
    • Gradient color: constructor, setter, getter, and switching back to a plain color. It renders red on the left and blue on the right.
    • draw_text with a gradient, alternating with a plain color, keeps one cached label.
    • A bad font_name raises in the constructor.
    • A Text created with no window still works later (with italic, bold, and gradient set).
  • New test_update_font_italic_bold_and_gradient in test_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 check bold values 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_sprite with a gradient by hand.

The changelog has an entry under Unreleased → Fixes.

🤖 Generated with Claude Code

- 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>
@pvcraven
pvcraven merged commit e82af34 into development Oct 6, 2026
7 checks passed
@pvcraven
pvcraven deleted the fix/text-properties branch October 6, 2026 14:21
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.

1 participant