summaryrefslogtreecommitdiff
path: root/crates/typst-layout/src/grid/rowspans.rs
diff options
context:
space:
mode:
authorTobias Schmitz <tobiasschmitz2001@gmail.com>2025-05-06 10:26:55 +0200
committerGitHub <noreply@github.com>2025-05-06 08:26:55 +0000
commitb322da930fe35ee3d19896de6ab653e2f321e301 (patch)
tree17d60077855344e966bb49964cab4daf078d6790 /crates/typst-layout/src/grid/rowspans.rs
parent14241ec1aae43ce3bff96411f62af76a01c7f709 (diff)
Respect RTL cell layouting order in grid layout (#6232)
Co-authored-by: PgBiel <9021226+PgBiel@users.noreply.github.com>
Diffstat (limited to 'crates/typst-layout/src/grid/rowspans.rs')
-rw-r--r--crates/typst-layout/src/grid/rowspans.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/crates/typst-layout/src/grid/rowspans.rs b/crates/typst-layout/src/grid/rowspans.rs
index 21992ed0..5ab0417d 100644
--- a/crates/typst-layout/src/grid/rowspans.rs
+++ b/crates/typst-layout/src/grid/rowspans.rs
@@ -3,7 +3,6 @@ use typst_library::engine::Engine;
use typst_library::foundations::Resolve;
use typst_library::layout::grid::resolve::Repeatable;
use typst_library::layout::{Abs, Axes, Frame, Point, Region, Regions, Size, Sizing};
-use typst_utils::MaybeReverseIter;
use super::layouter::{in_last_with_offset, points, Row, RowPiece};
use super::{layout_cell, Cell, GridLayouter};
@@ -23,6 +22,10 @@ pub struct Rowspan {
/// specified for the parent cell's `breakable` field.
pub is_effectively_unbreakable: bool,
/// The horizontal offset of this rowspan in all regions.
+ ///
+ /// This is the offset from the text direction start, meaning that, on RTL
+ /// grids, this is the offset from the right of the grid, whereas, on LTR
+ /// grids, it is the offset from the left.
pub dx: Abs,
/// The vertical offset of this rowspan in the first region.
pub dy: Abs,
@@ -118,10 +121,11 @@ impl GridLayouter<'_> {
// Nothing to layout.
return Ok(());
};
- let first_column = self.rcols[x];
let cell = self.grid.cell(x, y).unwrap();
let width = self.cell_spanned_width(cell, x);
- let dx = if self.is_rtl { dx - width + first_column } else { dx };
+ // In RTL cells expand to the left, thus the position
+ // must additionally be offset by the cell's width.
+ let dx = if self.is_rtl { self.width - (dx + width) } else { dx };
// Prepare regions.
let size = Size::new(width, *first_height);
@@ -185,10 +189,8 @@ impl GridLayouter<'_> {
/// Checks if a row contains the beginning of one or more rowspan cells.
/// If so, adds them to the rowspans vector.
pub fn check_for_rowspans(&mut self, disambiguator: usize, y: usize) {
- // We will compute the horizontal offset of each rowspan in advance.
- // For that reason, we must reverse the column order when using RTL.
- let offsets = points(self.rcols.iter().copied().rev_if(self.is_rtl));
- for (x, dx) in (0..self.rcols.len()).rev_if(self.is_rtl).zip(offsets) {
+ let offsets = points(self.rcols.iter().copied());
+ for (x, dx) in (0..self.rcols.len()).zip(offsets) {
let Some(cell) = self.grid.cell(x, y) else {
continue;
};