diff --git a/library/src/layout/columns.rs b/library/src/layout/columns.rs index 55cda5d8c..7da9c4a06 100644 --- a/library/src/layout/columns.rs +++ b/library/src/layout/columns.rs @@ -131,7 +131,7 @@ impl Layout for ColumnsNode { } let width = frame.width(); - let x = if dir.is_positive() { + let x = if dir == Dir::LTR { cursor } else { regions.first.x - cursor - width diff --git a/library/src/layout/grid.rs b/library/src/layout/grid.rs index 544b76ed8..818bf53d2 100644 --- a/library/src/layout/grid.rs +++ b/library/src/layout/grid.rs @@ -1,4 +1,5 @@ use crate::prelude::*; +use crate::text::TextNode; use super::Spacing; @@ -218,6 +219,8 @@ struct GridLayouter<'a, 'v> { vt: &'a mut Vt<'v>, /// The grid cells. cells: &'a [Content], + /// Whether this is an RTL grid. + rtl: bool, /// The column tracks including gutter tracks. cols: Vec, /// The row tracks including gutter tracks. @@ -299,6 +302,12 @@ impl<'a, 'v> GridLayouter<'a, 'v> { cols.pop(); rows.pop(); + // Reverse for RTL. + let rtl = styles.get(TextNode::DIR) == Dir::RTL; + if rtl { + cols.reverse(); + } + let full = regions.first.y; let rcols = vec![Abs::zero(); cols.len()]; let lrows = vec![]; @@ -311,6 +320,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> { Self { vt, cells, + rtl, cols, rows, regions, @@ -680,10 +690,15 @@ impl<'a, 'v> GridLayouter<'a, 'v> { /// /// Returns `None` if it's a gutter cell. #[track_caller] - fn cell(&self, x: usize, y: usize) -> Option<&'a Content> { + fn cell(&self, mut x: usize, y: usize) -> Option<&'a Content> { assert!(x < self.cols.len()); assert!(y < self.rows.len()); + // Columns are reorded, but the cell slice is not. + if self.rtl { + x = self.cols.len() - 1 - x; + } + // Even columns and rows are children, odd ones are gutter. if x % 2 == 0 && y % 2 == 0 { let c = 1 + self.cols.len() / 2; diff --git a/tests/ref/layout/grid-rtl.png b/tests/ref/layout/grid-rtl.png new file mode 100644 index 000000000..8b8384801 Binary files /dev/null and b/tests/ref/layout/grid-rtl.png differ diff --git a/tests/typ/layout/grid-rtl.typ b/tests/typ/layout/grid-rtl.typ new file mode 100644 index 000000000..31015097e --- /dev/null +++ b/tests/typ/layout/grid-rtl.typ @@ -0,0 +1,9 @@ +// Test RTL grid. + +--- +#set text(dir: rtl) +- מימין לשמאל + +--- +#set text(dir: rtl) +#table(columns: 2, gutter: 5pt)[A][B][C][D]