Skip to content

Don't draw the trailing space of wrapped right-to-left lines (#1422) - #1831

Open
ZahraaSadeqProd wants to merge 1 commit into
foliojs:masterfrom
ZahraaSadeqProd:fix/rtl-trailing-space
Open

ZahraaSadeqProd wants to merge 1 commit into
foliojs:masterfrom
ZahraaSadeqProd:fix/rtl-trailing-space

Conversation

@ZahraaSadeqProd

Copy link
Copy Markdown

Fixes #1422

What kind of change does this PR introduce?

Bug fix.

When features is set, EmbeddedFont.layout shapes a line as one run, so fontkit reverses a right-to-left line as a whole. A wrapped line keeps its trailing space ('هذا نص '), and after the reversal that space is the first glyph drawn, on the left. _fragment computes the align: 'right' offset without the trailing space (text.replace(/\s+$/, '')), so the visible glyphs end one space past the right margin. The last line has no trailing space and lines up, which is the "indent" in the issue.

_fragment now leaves the trailing whitespace of a wrapped line (options.width) out of the glyphs it draws. The justify path already does this with text.trim(). Nothing that is measured changes: the alignment, the underline, strike-through and link rectangles, and doc.x for continued text are computed from the text as before. Left-to-right lines only lose an invisible space at their end, and no existing test or visual snapshot changes.

With the issue's text in Noto Kufi Arabic at 16 pt, width: 195, align: 'right', features: ['rtla']:

Line Before After
هذا نص عربي طويل يحتوي ends 5.4 pt (one space) past the margin flush with the margin
على عدة أسطر لإظهار ends 5.4 pt past the margin flush with the margin
الخطأ (last) flush with the margin flush with the margin

Without features, layout shapes each word separately and Arabic words come out in left-to-right order. That's a separate issue (#1722 adds bidi for it) and not part of this change.

Checklist:

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

tests/unit/text.spec.js "right-to-left wrapped lines do not draw their trailing space - issue #1422" checks that the first line draws 6 glyphs and doesn't start with the space. It fails before the change. tests/fonts/NotoKufiArabic-Subset.ttf is a 5 KB subset of Noto Kufi Arabic (Apache 2.0, from the fontkit test data) with the letters of the test text; none of the existing test fonts has Arabic or Hebrew glyphs.

yarn test: 580 passed. eslint and prettier are clean.

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.

Random extra space in Arabic multiline texts

1 participant