Skip to content

[rtextures] ImageTextEx(): use MeasureTextEx() line spacing, fix multiline scaling - #6311

Merged
raysan5 merged 2 commits into
raysan5:masterfrom
drgropp:fix-imagetextex-line-spacing
Oct 22, 2026
Merged

raysan5 merged 2 commits into
raysan5:masterfrom
drgropp:fix-imagetextex-line-spacing

Conversation

@drgropp

@drgropp drgropp commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #6308

ImageTextEx() sized the image with MeasureTextEx() but drew lines a fixed baseSize + baseSize/2 apart, so multiline text was clipped (or padded with large spacing), ignored SetTextLineSpacing(), and was scaled by textSize.y/imSize.y (1.88 instead of 2.0 in the issue repro).

Changes, all inside ImageTextEx():

  • Derive the line spacing from the MeasureTextEx() result already computed in the function (textLineSpacing is private to rtext.c), and step lines by the equivalent amount at base size.
  • Size the image from the actual line layout.
  • Scale by fontSize/baseSize, using the image's real dimensions.
  • Remove the stale NOTE/TODO about fixed 1.5 line height.

Tested with the repro from #6308 (default font, size 20) on Windows:

Case Before After
Default spacing (2) 109x64, scale 1.88, third line clipped 116x64, scale 2.0, all lines visible
SetTextLineSpacing(0) clipped fits, matches DrawText()
SetTextLineSpacing(12) padded fits, matches DrawText()
Single line unchanged unchanged

If you'd prefer exposing the line spacing (e.g. a GetTextLineSpacing()) instead of deriving it, I'm happy to rework it that way.

Comment thread src/rtextures.c

// Scale image depending on text size
if (textSize.y != imSize.y)
if (fontSize != (float)font.baseSize)
Comment thread src/rtextures.c Outdated
@raysan5
raysan5 merged commit 7b677dd into raysan5:master Oct 22, 2026
16 checks passed
@raysan5

raysan5 commented Oct 22, 2026

Copy link
Copy Markdown
Owner

@drgropp thanks for the review, looks ok

@drgropp
drgropp deleted the fix-imagetextex-line-spacing branch October 22, 2026 17:36
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.

[rtextures] ImageTextEx() clips multiline text, ignores SetTextLineSpacing()

4 participants