Skip to content

Commit

Permalink
Use ascent and descent insead of x-height for shift in tb writing mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV authored Apr 12, 2024
1 parent b908baf commit f4289f7
Show file tree
Hide file tree
Showing 21 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions crates/resvg/tests/integration/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use once_cell::sync::Lazy;
use rgb::{FromSlice, RGBA8};
use std::process::Command;
use usvg::fontdb;

#[rustfmt::skip]
Expand Down Expand Up @@ -55,6 +56,9 @@ pub fn render(name: &str) -> usize {
resvg::render(&tree, render_ts, &mut pixmap.as_mut());

// pixmap.save_png(&format!("tests/{}.png", name)).unwrap();
// Command::new("oxipng")
// .args(["-o".to_owned(), "6".to_owned(), "-Z".to_owned(), format!("tests/{}.png", name)])
// .output().unwrap();

let mut rgba = pixmap.take();
demultiply_alpha(rgba.as_mut_slice().as_rgba_mut());
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/text/lengthAdjust/vertical.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/text/textPath/complex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/text/writing-mode/inheritance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/text/writing-mode/tb-rl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/text/writing-mode/tb-with-alignment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/text/writing-mode/tb-with-dx-on-tspan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/text/writing-mode/tb-with-rotate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/text/writing-mode/tb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/text/writing-mode/vertical-lr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/resvg/tests/tests/text/writing-mode/vertical-rl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions crates/usvg/src/text/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ struct GlyphCluster {
advance: f32,
ascent: f32,
descent: f32,
x_height: f32,
has_relative_shift: bool,
glyphs: Vec<PositionedGlyph>,
transform: Transform,
Expand Down Expand Up @@ -939,7 +938,9 @@ fn apply_writing_mode(writing_mode: WritingMode, clusters: &mut [GlyphCluster])
// Could not find a spec that explains this,
// but this is how other applications are shifting the "rotated" characters
// in the top-to-bottom mode.
cluster.transform = cluster.transform.pre_translate(0.0, cluster.x_height / 2.0);
cluster.transform = cluster
.transform
.pre_translate(0.0, (cluster.ascent + cluster.descent) / 2.0);
}
}
}
Expand Down Expand Up @@ -1060,7 +1061,6 @@ fn form_glyph_clusters(glyphs: &[Glyph], text: &str, font_size: f32) -> GlyphClu
advance: width,
ascent: font.ascent(font_size),
descent: font.descent(font_size),
x_height: font.x_height(font_size),
has_relative_shift: false,
transform: Transform::default(),
path_transform: Transform::default(),
Expand Down

0 comments on commit f4289f7

Please sign in to comment.