Skip to content

Rework layout to use shaped glyph advances when fitting and drawing - #1885

Open
blikblum wants to merge 1 commit into
foliojs:masterfrom
blikblum:rework-layout
Open

blikblum wants to merge 1 commit into
foliojs:masterfrom
blikblum:rework-layout

Conversation

@blikblum

Copy link
Copy Markdown
Member

Rework layout to use shaped glyph advances when fitting and drawing lines. Kerned names such as Jane Walker fit at their measured width in text and tables. widthOfString() now respects wordSpacing. Fixes #1882

What kind of change does this PR introduce?

Checklist:

  • Unit Tests
  • Documentation
  • Update CHANGELOG.md
  • Ready to be merged

I tasked OpenAI Astra 6.2 to rework layout to match well established text rendering libraries / programs

This is the proposed changes.

But it comes with a 3.3x perf overhead making not suitable for prime time. Creating a PR just for record, to maybe be used as base for future improvements.

The findings:

The standalone browser bundle grew by 1.16 KiB gzipped (+0.43%). The runtime impact depends on the workload. A 100-row Helvetica table took 2 ms longer (+11%), while a long Roboto paragraph with varying text took 3.3× as long. The latter is the main performance concern.

Runtime

I compared the working tree with 3973f09, the commit containing #1846. These are median times from 15 alternating runs after warm-up on Node 24.12. Each sample started with a fresh document. The table timing includes PDF finalization. Paragraph timings cover layout and drawing with compression disabled.

Workload Before After Change
Helvetica, 100,000 widthOfString() calls on short names 88.1 ms 125.6 ms +43%
Helvetica, draw the same paragraph 100 times 33.5 ms 32.2 ms −4%
Helvetica, same workload with wordSpacing: 2 61.0 ms 64.9 ms +6%
Helvetica, generate a 100-row, 3-column table 19.3 ms 21.3 ms +11%
Roboto, draw the same paragraph 100 times 26.1 ms 26.7 ms +3%
Roboto, one 7,189-character paragraph with varying text 9.8 ms 32.3 ms +229%
Roboto, same paragraph with explicit features: ['kern'] 38.4 ms 41.4 ms +8%

Across production source files, including the two new modules, the net change is +25 lines and +631 bytes, with no added dependency. Heap usage was not measured.

…ines. Kerned names such as `Jane Walker` fit at their measured width in text and tables. `widthOfString()` now respects `wordSpacing`. Fixes foliojs#1882

This branch has not been deployed

No deployments
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.

doc.table() truncates cell text with "…" when a space is followed by a kerned letter (regression in 0.21.0)

1 participant