Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge PR #5807: Type: keep superscript and subscript when a text layer is re-rendered (#5645)

David Mann2adfe0c4e272
diff --cc crates/text/src/psd.rs
index 8c502c75a,d83c04de6..a2350d10f
--- a/crates/text/src/psd.rs
+++ b/crates/text/src/psd.rs
@@@ -1365,19 -1377,19 +1380,32 @@@ mod nonfinite_tests
assert_eq!(char_style(None, &d, &[], 1.0).size_pt, 24.0);
}
+ /// #5645: `FontBaseline` (1 superscript, 2 subscript) is read and written back.
+ #[test]
+ fn font_baseline_round_trips() {
+ use photocraft_doc::text::FontBaseline;
+ let d = parse(b"<< /FontBaseline 2 >>").unwrap();
+ assert_eq!(char_style(None, &d, &[], 1.0).baseline, FontBaseline::Subscript);
+ let d = parse(b"<< /FontBaseline 1 >>").unwrap();
+ assert_eq!(char_style(None, &d, &[], 1.0).baseline, FontBaseline::Superscript);
+ let s = CharStyle { baseline: FontBaseline::Subscript, ..Default::default() };
+ let back = char_style(None, &style_sheet_data(&s, 0, 1.0), &[], 1.0);
+ assert_eq!(back.baseline, FontBaseline::Subscript);
+ }
+
+ #[test]
+ fn warp_values_beyond_f32_clamp_to_the_warp_range() {
+ let warp = Descriptor::new("warp")
+ .with("warpStyle", enumv("warpStyle", "warpArc"))
+ .with("warpValue", D::Double(1e39))
+ .with("warpPerspective", D::Double(-1e39))
+ .with("warpPerspectiveOther", D::Double(250.0))
+ .with("warpRotate", enumv("Ornt", "Hrzn"));
+ let tysh = write_tysh(&TySh { transform: Affine::IDENTITY, text: Descriptor::new("TxLr"), warp: Some(warp), bounds: [0.0; 4] });
+ let w = text_layer_from_tysh(&tysh, 72.0).and_then(|l| l.warp).unwrap();
+ assert_eq!((w.value, w.horizontal_distortion, w.vertical_distortion), (100.0, -100.0, 100.0));
+ }
+
#[test]
fn infinite_dpi_does_not_write_a_zero_size() {
let layer =