Repository navigation
[4.0] fix(bbb-export-annotations): wrap exported text exactly as the client does - #26013
Conversation
… does Text annotations constrained to a width (autoSize=false) are re-wrapped by the export using opentype.js glyph advance sums. The client wraps them with the browser's text layout, which shapes the text with HarfBuzz and applies the font's OpenType features. Shantell Sans, the "draw" font, carries kerning in GPOS and contextual alternates in GSUB that opentype.js does not apply, so the export measured long lines 2-3% wider than they rendered live. The safety margin added for bigbluebutton#24566 (twice the narrowest glyph) is a constant, while the error grows with line length: a line the browser laid out at 1340.8 px measured 1364.1 px in the export, against a 14 px margin. Reported on 3.0.39 with a 27-line German annotation: the export wrapped one line's trailing period and the word "Dies" onto lines of their own, so the shape grew by two lines and its last items fell below the page edge. The orphaned period came from the tokenizer splitting at word boundaries (\b) and then breaking the accumulated line at character granularity, which a browser never does. Measure with HarfBuzz instead (harfbuzzjs, WebAssembly, no native build). Shaping with the font's default features reproduces Chrome's widths exactly: 1340.8 px and 1239.1 px for the report's two critical lines in both. Wrap where a browser wraps: at whitespace or after a hyphen, breaking inside a word only when the word alone exceeds the line. Whitespace hangs at the end of a line instead of forcing a wrap. Keep a tolerance of one narrowest-glyph width in the "do not wrap" direction only, since that error mode cannot interleave text. Fonts are parsed once per process and a single scratch buffer serves every measurement; the previous code re-read and re-parsed the woff2 font for every shape. Verified on a 3.0.39 server with the reported annotation at its live geometry: before the change the exported PDF had 29 lines with the last two below the page edge; after it the 27 lines match the client and the last line sits inside the page. The existing regression test (exportedAnnotationsOverlap) still covers the overlap symptom. opentype.js is no longer used and is dropped from the dependencies.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review. WalkthroughThe annotation exporter replaces Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant wrapText
participant fontCache
participant WOFF2Loader
participant HarfBuzz
wrapText->>fontCache: request font by path
fontCache->>WOFF2Loader: load and decompress WOFF2 font
WOFF2Loader->>HarfBuzz: create font and record units per em
wrapText->>HarfBuzz: shape text and measure glyph advances
HarfBuzz-->>wrapText: return glyph advances
wrapText-->>wrapText: break text into lines
Suggested reviewers: Merge Risk: ⚪ Minimal · up to The export line-break regression is covered for the tested annotation. No demonstrated issue remains to block merging after normal checks. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I intend on pushing regression test as well. Promoted from draft to obtain CodeRabbit comments. |
Regression coverage for the opentype.js wrap divergence fixed in the previous commit. A 26-line synthetic German text annotation is typed through the whiteboard, constrained to 2632 px at scale 0.5 on a blank slide and exported in its current state. The rows of the exported page are then compared with the client: every row between the annotation's first and last line must be one of its 24 non-blank paragraphs, no row may consist of punctuation alone, and the last row must be its last line. Two lines of the text are about 200 characters long on purpose. The browser measures them at 2618 px and 2623 px, the old export at 2661 px and 2666 px, so the fixture keeps 9 px of slack on the browser side even where Chromium rounds glyph advances to whole pixels (this test tree launches it without --font-render-hinting=none), while the old export still wraps both lines. Verified red against the stock bbb-export-annotations (26 rows instead of 24) and green with the fix, on a 3.0.39 server. The export step is shared with the overlap test and now opens the public chat before waiting for the download link: the link arrives as a chat message and is hidden when the sidebar is collapsed on login. An unused constant is removed and the file is formatted with the repository's eslint --fix.
✅ Automated tests have passed! |
0830dff
into
bigbluebutton:v4.0.x-develop
What does this PR do?
Makes "download presentation with annotations" wrap width-constrained text annotations exactly as the client rendered them.
The export re-wrapped text by summing glyph advances with opentype.js, while the client wraps with the browser's text layout, which shapes text with HarfBuzz and applies the font's OpenType features. The draw font (Shantell Sans) carries GPOS kerning and GSUB contextual alternates that opentype.js does not apply, so the export measured long lines 2-3% wider than they rendered live. The margin from #24566 is a constant and cannot absorb an error that grows with line length: a line the browser laid out at 1340.8 px measured 1364.1 px in the export, against a 14 px margin. A second defect orphaned trailing punctuation: the wrapper split tokens at word boundaries (
\b) and then broke the accumulated line at character granularity, which a browser never does.Changes in
bbb-export-annotations/shapes/Shape.js:harfbuzzjs). With the font's default features the widths match Chrome exactly: 1340.8 px and 1239.1 px for the two critical lines of the report, on both sides.opentype.jsfrom the dependencies.About the replacement library
harfbuzzjsis the HarfBuzz project's own JavaScript build of HarfBuzz, compiled to WebAssembly: https://github.com/harfbuzz/harfbuzzjs. It is not a fork; it lives in theharfbuzzGitHub organization and is published by two HarfBuzz core developers (Ebrahim Byagowi and Khaled Hosny). HarfBuzz is the shaping engine inside Chrome, Firefox, Android and LibreOffice, so the export now measures text with the same engine the client's browser uses..wasmfile, loaded at import time. Works on Node 18 and later.HB_TINY, which strips some non-shaping APIs (glyph names, for example). Shaping, which is all this change uses, is complete.Before and after
Filler text, not the reporter's content. Draw font, size M, box width 1355 px, on a blank slide. Client and both exports use the same annotation.
Live client (27 lines):
client-live-whiteboard

Before: stock export of the same annotation. The periods of items 2 and 3 of section B are wrapped onto lines of their own, the block is two lines taller than in the client, and items 5 and 6 of section D fall below the page edge:
before-export-stock

After: export with this PR. Same 27 lines as the client; item 6 is the last line and sits inside the page:
after-export-harfbuzz

Closes Issue(s)
Follow-up to #24566.
Motivation
Reported on 3.0.39 with a 27-line text annotation: the export wrapped one line's trailing period and one short word onto lines of their own, so the shape grew by two lines and its last items fell below the page edge.
How to test
Verified on a 3.0.39 server with the reported annotation at its live geometry: stock export 29 lines with the last two off-page, fixed export 27 lines matching the client. The
exportedAnnotationsOverlapPlaywright test still covers the overlap symptom. Result: PASS.