Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced block rendering: handle RTL direction #312

Merged
merged 7 commits into from
Sep 29, 2019

Conversation

poire-z
Copy link
Contributor

@poire-z poire-z commented Sep 28, 2019

Followup to #309, which added support for RTL/bidi text. Some technical notes in #307.

This PR completes support for RTL documents, by handling the dir= attribute in block nodes, drawing list item markers on the right of the page, and drawing RTL tables' cells from right to left.
See commit messages for details.

Some screenshots:
image

image

image

(/\ source - \/ source)
image


I'll add to frontend a Style tweaks> Text> Text direction> section:
image
which will allow setting direction on any kind of document (needed for plain text files in arabic or hebrew).

Some english page in normal LTR => switched to RTL:
image image

image image

Note that the absence/bad handling of left/right side bearings when in RTL context in getRenderedWidths makes all the perfect fitting stuff we did for LTR, not working so well in RTL:
image image

Except for the getRenderedWidths() (to size table cells or floats) limitations, we should have now proper RTL support.
(I have not added some CSS properties and named values that could help simplifying our .css, like float: inline-start or margin-inline-start: 1em (that mean left in LTR and right in RTL) because ... well, that's too much work :)

One last remaining (minor) issue is the the landscape/dual pages, mode which will still show the first page on the left, while I guess for RTL documents it should show it on the right.

No change in logic and no obvious performance improvement,
but it makes the code more readable.
Handle direction in block rendering:
- handle direction via dir= attribute, or via CSS 'direction:'
  property (mostly to allow tweaking it via style tweaks)
- handle inheritance/propagation of the direction (which can't
  be done via styles because of the dir= attribute)
- add new flags and store direction in RenderRectAccessor for
  erm_final and erm_block so it's available after rendering,
  for drawing and text layout
- use that flag in lvtextfm.cpp as the paragraph specified
  direction, instead of looking for it in upper nodes.
- add support for text-align: start/end
- correctly position blocks with a reduced width
- display list item markers on the right (added
  renderAsListStylePositionInside() to factorize some common
  and ugly conditions)
- (FlowState: added some preliminary work to handle 'lang='
  attribute, which could be used for enhanced typography.)
Handle specified or inherited direction when walking
table nodes when rendering.
When table direction is RTL:
- reverse order of columns and cells
- render cell content with the specified or inherited direction
Also make text selection work in such RTL tables.
Mostly just to be able to put the in-page footnotes separator
on the right for RTL documents.
Switch LVRendPageInfo->type to ->flags to store additional info.
As text direction might change (albeit rarely) for elements on
a page, and as we don't have any global flag for the document
global direction (it may change per DocFragment), we just account
the nb of 'lines' and RTL 'lines', and flag the page (or footnotes
on that page) as RTL if we have > 50% of them RTL.
Added :root, :empty, and :dir(rtl).

Also fix matching when a pseudoclass is standalone, which
is allowed (previously, a standalone :first-child was
considered invalid).
Just invert margin-left/right where they are not balanced.
@poire-z
Copy link
Contributor Author

poire-z commented Sep 29, 2019

Copy link
Member

@Frenzie Frenzie left a comment

Choose a reason for hiding this comment

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

Nothing jumps out at me. ;-)

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