Repository navigation
Open
Labels
A-layout/blockA-layout/floatsA-layout/inlineA-layout/textA-layout/writing-modeB-feature-trackingThis issue tracks a particular high-level featureB-roadmapThis issue tracks tasks that are part of Servo's roadmap
Description
Roadmap Issue
Description:
The goal would be to add support for writing modes in Servo's layout engine, this is a key feature that interacts with the rest of layout features. This is an important feature for internationalization specially for non-latin scripts.
Area: Layout
People: We at https://github.com/Igalia have plans to work on this, starting at some point in 2026, but we cannot commit to the task just yet.
- Implement logic for propagating the principal writing mode from the root element or
<body>to the initial containing block. - Implement support for documents written entirely using a
vertical-lrwriting mode, or avertical-rlwriting mode. - Implement support for documents mixing
vertical-lrandvertical-rlwriting modes. - Implement orthogonal flows in block layout.
- Implement orthogonal flows in inline layout.
- Implement orthogonal flows in table layout.
- Implement orthogonal flows in flex layout.
- Implement orthogonal flows in absolutely positioned layout.
Metadata
Metadata
Assignees
Labels
A-layout/blockA-layout/floatsA-layout/inlineA-layout/textA-layout/writing-modeB-feature-trackingThis issue tracks a particular high-level featureB-roadmapThis issue tracks tasks that are part of Servo's roadmap
Type
Projects
- StatusShow more project fieldsIn Progress
Activity
SimonSapin commentedon Jun 3, 2014
Abstract dimension geometry.
Mailing list discussion: https://groups.google.com/forum/#!topic/mozilla.dev.servo/HfNwjucmdys
Initial commit: https://github.com/SimonSapin/servo/compare/d6caf26
Branch: https://github.com/SimonSapin/servo/compare/abstract-geometry
Relevant spec: http://dev.w3.org/csswg/css-writing-modes/#abstract-box
Gankra commentedon Jan 15, 2018
upstream webrender work just landed: servo/webrender#2288
Gankra commentedon Jan 15, 2018
(well bors is throwing a fit but, you know)
tigercosmos commentedon May 26, 2018
@SimonSapin So do we still have not implement
writing-modeyet?SimonSapin commentedon May 27, 2018
We do have some support behind the
layout.writing-mode.enabledpref. But it’s buggy, in particular orthogonal flows (a change of horizontal v.s. vertical direction in the same document) are very broken.mrobinson commentedon Nov 2, 2026
The main issue we have when implementing full support for CSS writing modes is that we readily convert logical fragment rectangles to physical rectangles when creating them. With writing modes enabled, we do not know the physical rectangle that corresponds to a fragment's logical rectangle until we know the block size of its parent fragment. Typically during layout of children, we only know the inline size of the parent during layout. Only after layout of the children do we know the block size.
In order to solve this issue, we need to more thoroughly do layout in logical coordinates and collect a vector of child fragments and their logical rectangles that are resolved when the parent fragment is created. This implies a new call to
BaseFragment::set_rectwhen child fragments are added to theirparent.
We already do something like this to support RTL in line layout, where the final inline size of the containing boxes is used to flip rectangles in the inline axis as the final step. We need to do this flipping now in the block axis for
vertical-rlandsideways-rlwriting modes. The main idea of this work is that we would extend this approach to all of layout.FragmentAndDatais used in line layout to hold aFragmentand its logical rectangle. This would be generalized and we would start using it in other layout modes. This data structure could be calledFragmentAndLogicalRect.LogicalRect::as_physicalingeom.rstakes an argument for the container size now, an optionalContainingBlock. ThisContainingBlockdoes not necessarily have a definite block size.Optionneeds to be removed. All callers should pass container size information.ContainingBlock, but these should eventually be moved when logical rectangles are converted to physical ones later in layout.geom.rsand unit tests should be written proving these conversions are correct and as we expect them to be.FragmentAndLogicalRectdata structure. Floats will require particular care. We need to stop converting quickly to physical rectangles and we need to look at how to delay this conversion across various layout modes. This can be done by moving all conversion to physical rectangles to the point where fragments are added to their parents. In addition we need more work to support orthogonal flows, which should start at the places where we removed assertions about orthogonal writing modes.line-height, and the baseline in vertical writing modes.5 remaining items
Remove `FragmentChildren::PhysicalDeprecated` in inline layout
nicoburns commentedon Nov 18, 2026
@SimonSapin Is there are design doc somewhere for how we're planning to implement
writing-modein Servo?The issue description above (admittedly written in 2014) seems to suggest that there will be per-layout algorithm changes. But Blink and Blitz both implement writing-mode without changing the layout algorithms meaningfully. And I think that strategy would make a lot of sense in Servo too. The method I'm proposing is: For vertical writing modes: transpose styles on the way in to the algorithm, transpose fragments on the way out. Add a little logic in the glue between layout modes to account for orthogonal flows. And... that's it
(perhaps that's already what's planned, but I can't tell either from what's been posted publicly)
The implementation in Blitz was surprisingly small (~1k Loc): DioxusLabs/blitz#1090
Port table layout to create fragments with logical rects
SimonSapin commentedon Nov 18, 2026
The issue description as it is now was written somewhat recently. I the bullet points listing per-layout algorithm changes refers to the same as what you describe as:
As to this strategy:
This means having most of the layout code work with logical aka flow-relative coordinates while pretending its not. This says “width” but really means “inline size”, that says “height” but really means “block size”. That doesn’t sound great because you have to know somehow where the boundary of pretending is exactly.
Instead, part of the “Layout 2020” rewrite was using logical terminology in code from the start.
(Also, just swapping dimensions works for sizes but is not enough for positions: the inline-start block-start corner used as the origin for relative logical positions maps do different physical corners in different writing modes.)
I don’t think we have a formal design doc, #2560 (comment) highlights the current and next steps.
It’s not gonna be a single PR but given the code already uses logical terminology I expect the overall diff for “most of the feature” won’t be huge, then there’ll be a long tail of bug fixes for unusual combinations like orthogonal float that is also replaced
nicoburns commentedon Nov 18, 2026
Ok cool. I'm glad to hear it's mostly a style swapping solution.
Yeah, that's fair. In Taffy that boundary reasonably clear because it's the entire crate! But explicitly using logical terminology would make sense. I think everything being physical in Taffy helped, because at least it was consistent.
Interesting that your going with logical fragments. Blitz has physical outputs (it doesn't really have fragments at all yet). I wonder if there's a real trade-off there. Or it's mostly equivalent. Perhaps it only starts to matter once you're actually doing fragmented layout?
layout: Collect child fragments of grid containers with logical recta…
layout: Collect child fragments of replaced layout with logical recta…
layout: Collect child fragments of flex containers with logical recta…
Remove `FragmentChildren::PhysicalDeprecated` in inline layout
servoshell: Turn `layout_css_writing_mode_enabled` into an experiment…
Remove `FragmentChildren::PhysicalDeprecated` in inline layout (servo…
layout: Implement basic values of `dominant-baseline` (servo#50196)
layout: Port flow layout to create fragments with logical rects (serv…
servoshell: Turn `layout_css_writing_mode_enabled` into an experiment…
Remove `FragmentChildren::PhysicalDeprecated` in inline layout (servo…