Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This changelog also contains important changes in dependencies.

## [Unreleased]

### Fixed

- `dx` and `dy` on right-to-left text shift the characters after them in logical order, so multi-line `tspan`s no longer collapse onto one line. (#1093)

## [0.48.1] 2026-08-02

This release has an MSRV of 1.85.0 for `usvg` and `resvg` and the C API.
Expand Down
1 change: 1 addition & 0 deletions crates/resvg/tests/integration/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,7 @@ use crate::render;
#[test] fn text_tref_with_a_title_child() { assert_eq!(render("tests/text/tref/with-a-title-child"), 0); }
#[test] fn text_tref_with_text() { assert_eq!(render("tests/text/tref/with-text"), 0); }
#[test] fn text_tref_xml_space() { assert_eq!(render("tests/text/tref/xml-space"), 0); }
#[test] fn text_tspan_arabic_with_dy() { assert_eq!(render("tests/text/tspan/arabic-with-dy"), 0); }
#[test] fn text_tspan_bidi_reordering() { assert_eq!(render("tests/text/tspan/bidi-reordering"), 0); }
#[test] fn text_tspan_mixed_font_size() { assert_eq!(render("tests/text/tspan/mixed-font-size"), 0); }
#[test] fn text_tspan_mixed_xml_space_1() { assert_eq!(render("tests/text/tspan/mixed-xml-space-1"), 0); }
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions crates/resvg/tests/tests/text/tspan/arabic-with-dy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 24 additions & 12 deletions crates/usvg/src/text/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,23 +552,35 @@ fn resolve_clusters_positions_horizontal(
writing_mode: WritingMode,
clusters: &mut [GlyphCluster],
) -> (f32, f32) {
let mut x = process_anchor(chunk.anchor, clusters_length(clusters));
let mut y = 0.0;

for cluster in clusters {
let cp = offset + cluster.byte_idx.code_point_at(&chunk.text);
// `dx` and `dy` shift a character and all the characters after it in logical order,
// while the clusters are in visual order, which differs in right-to-left text.
let mut logical_order: Vec<usize> = (0..clusters.len()).collect();
logical_order.sort_by_key(|&i| clusters[i].byte_idx.value());
let mut shifts = vec![(0.0, 0.0); clusters.len()];
let (mut shift_x, mut shift_y) = (0.0, 0.0);
for i in logical_order {
let cp = offset + clusters[i].byte_idx.code_point_at(&chunk.text);
if let (Some(dx), Some(dy)) = (text.dx.get(cp), text.dy.get(cp)) {
if writing_mode == WritingMode::LeftToRight {
x += dx;
y += dy;
shift_x += dx;
shift_y += dy;
} else {
y -= dx;
x += dy;
shift_y -= dx;
shift_x += dy;
}
cluster.has_relative_shift = !dx.approx_zero_ulps(4) || !dy.approx_zero_ulps(4);
clusters[i].has_relative_shift = !dx.approx_zero_ulps(4) || !dy.approx_zero_ulps(4);
}
shifts[i] = (shift_x, shift_y);
}

let mut x = process_anchor(chunk.anchor, clusters_length(clusters));

for (cluster, (cluster_shift_x, cluster_shift_y)) in clusters.iter_mut().zip(shifts) {
let cp = offset + cluster.byte_idx.code_point_at(&chunk.text);

cluster.transform = cluster.transform.pre_translate(x, y);
cluster.transform = cluster
.transform
.pre_translate(x + cluster_shift_x, cluster_shift_y);

if let Some(angle) = text.rotate.get(cp).cloned() {
if !angle.approx_zero_ulps(4) {
Expand All @@ -580,7 +592,7 @@ fn resolve_clusters_positions_horizontal(
x += cluster.advance;
}

(x, y)
(x + shift_x, shift_y)
}

// Baseline resolving in SVG is a mess.
Expand Down
Loading