Skip to content

improve text rendering#420

Open
michaelknoch wants to merge 6 commits into
masterfrom
font-rendering
Open

improve text rendering#420
michaelknoch wants to merge 6 commits into
masterfrom
font-rendering

Conversation

@michaelknoch

@michaelknoch michaelknoch commented Jul 2, 2026

Copy link
Copy Markdown
Member

Type of change: feature

Motivation (current vs expected behavior)

  • Fix rounding for close button
  • Allow center alignment of multiline text
  • Implement lineBreakMode byTruncatingTail
  • Implement attributed text to allow rendering multiple fonts in one label text

(p.s. The headline is repeated 2x in the screenshot to demonstrate the line truncation)
Screenshot 2026-07-02 at 09 42 51

Please check if the PR fulfills these requirements

  • Self-review: I am confident this is the simplest and clearest way to achieve the expected behaviour
  • There are no dependencies on other PRs or I have linked dependencies through Zenhub
  • The commit messages are clean and understandable
  • Tests for the changes have been added (for bug fixes / features)

// Draw into a quad 1px larger on every side so the SDF's antialiased edge isn't
// clipped at the shape's cardinal points (most visible on perfect circles). The
// extra ring is effectively zero-alpha for the shape itself.
GPU_RectangleFilled(rawPointer, gpuRect(rect.insetBy(dx: -1, dy: -1)), color: color.sdlColor)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This image is heavily zoomed in, thats why it's pixelated. This shows the shape without the fix, the left border is cut-off
Image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't know if this change is just fighting a symptom tbh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems like it is fighting a symptom – it sounds like the antialising shader is antialiasing "outward", which isn't unreasonable but could cause this. I wonder if it's easy enough to adjust that shader rather than fudging pixels in seemingly unrelated places?

@michaelknoch michaelknoch marked this pull request as ready for review July 2, 2026 10:34
@michaelknoch michaelknoch requested a review from ephemer as a code owner July 2, 2026 10:34
}

@MainActor
public class NSAttributedString {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm. are we sure NSAttributedString is @MainActor in its Foundation implementation? It's not impossible but I would be surprised

Comment thread Sources/UIFont.swift
public var pointSize: CGFloat
public var lineHeight: CGFloat {
return CGFloat(renderer?.getLineHeight() ?? 0) / UIScreen.main.scale
return CGFloat(renderer?.getLineHeight() ?? 0) / (UIScreen.main?.scale ?? 2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is unfortunately still incorrect and a growing source of potential "incorrectness".

A better solution here would be to have a @MainActor static internal variable lastKnownScreenScale: CGFloat which itself defaults to 2.0 but is set whenever UIScreen.main is initialized. Then we should reference that cached value internally whenever we don't have a screen. I know it's not directly related to this PR but it would be amazing if this could happen sooner rather than later, so I would also welcome that change in this PR 🙏🏼

@ephemer ephemer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Left some minor comments that aren't really blocking, but would be good to see improvements in sooner rather than later 🙏🏼 Thanks for this @michaelknoch !

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.

2 participants