Skip to content

Fall back to LEFT/BASELINE for invalid textAlign() values - #9378

Open
harshiltewari2004 wants to merge 1 commit into
processing:mainfrom
harshiltewari2004:fix-textalign-invalid-fallback
Open

harshiltewari2004 wants to merge 1 commit into
processing:mainfrom
harshiltewari2004:fix-textalign-invalid-fallback

Conversation

@harshiltewari2004

Copy link
Copy Markdown
Contributor

Resolves #9356

Changes

  • textAlign() now replaces unknown horizontal values with LEFT and unknown vertical values with BASELINE before saving them (src/type/textCore.js).
  • Added a default: fallback to the 2D _positionLines switch to match WEBGL (src/core/p5.Renderer2D.js).
  • Added textAlign unit tests in test/unit/type/attributes.js.

Why the fix is in textAlign() and not only in the 2D switch

While checking vertical alignment (as suggested in the issue), I found that the 2D canvas ignores invalid values and keeps the previous one:

Case 2D before WEBGL before
textAlign(LEFT, TOP) then textAlign(LEFT, LEFT) still drawn as TOP BASELINE
textAlign(RIGHT) then textAlign(TOP) canvas textAlign still right LEFT

So a default: alone would have drawn right-aligned text in the second case. Replacing bad values in textAlign() keeps p5's state, the canvas, and both renderers in sync. The default: stays as a safety net.

FES already warns for invalid values in both renderers, so that part is unchanged.

Tests

The two fallback tests fail on main and pass with this change.

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.

[p5.js 2.0+ Bug Report]: textAlign() with an invalid horizontal value draws nothing in 2D but falls back to LEFT in WEBGL

1 participant