Skip to content

GraphiteText: ATSUI-style layouts and text in pictures - #21

Merged
colemancda merged 4 commits into
masterfrom
feature/text-layout
Nov 26, 2026
Merged

colemancda merged 4 commits into
masterfrom
feature/text-layout

Conversation

@colemancda

Copy link
Copy Markdown
Member

Phase 3, sixth of the stack, against master.

Layouts (TextLayout.swift)

  • TextLayout(text:runs:fonts:width:) lays out text with styles over ranges: family, size, style and color per TextRun; text outside every run takes the first run's style.
  • It breaks lines at returns and newlines, and at the last space that fits when given a width.
  • Each character's position and advance come from QuickDraw's own text measuring, so a layout is as wide as DrawText would be, and styles a face hasn't look the same in both.
  • Measuring: width, height, per-line ascent, descent and baseline.
  • position(ofOffset:) is ATSUOffsetToPosition, and offset(atX:y:) is ATSUPositionToOffset, rounding to the nearer edge.
  • draw(in:at:) is ATSUDrawText: each run is drawn in its style and color, and the port's text settings, color and pen are restored after.

Text in pictures

  • Picture.draw takes an optional PictureTextDrawer for its text opcodes (LongText, DHText, DVText, DHDVText); FontRegistry is one. Without it text isn't drawn, as before. QuickDraw doesn't depend on GraphiteText, which depends on it.

Tests: widths agree with QuickDraw's; breaks at spaces ("ab cd ef" at 30 pixels is three lines, since "cd ef" is 36 wide) and at returns; positions and hit testing across lines; runs with their own sizes and colors drawn and the port restored; a version 2 picture with LongText drawn with and without a text drawer.

@colemancda
colemancda merged commit eadec6f into master Nov 26, 2026
3 checks passed
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