mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 15:48:23 +00:00
PSD export: a CR LF in an HTML Text slice's type is one line break
A type object whose text ends its lines with CR LF no longer writes two <br> tags for each line ending in its HTML Text slice's cell text.
This commit is contained in:
@@ -541,10 +541,11 @@ fn background(o: &SliceOptions) -> [u8; 4] {
|
||||
}
|
||||
|
||||
/// The text of type object `n` as the HTML an HTML Text slice shows: `&`, `<` and `>` escaped, a
|
||||
/// line break as `<br>`. Empty for anything but type.
|
||||
/// line break as `<br>` (CR LF is one break). Empty for anything but type.
|
||||
fn html_text(n: &Node) -> String {
|
||||
let NodeKind::Text(t) = &n.kind else { return String::new() };
|
||||
t.plain_text()
|
||||
.replace("\r\n", "\n")
|
||||
.split(['\n', '\r', '\u{2029}'])
|
||||
.map(|l| l.replace('&', "&").replace('<', "<").replace('>', ">"))
|
||||
.collect::<Vec<_>>()
|
||||
|
||||
@@ -452,6 +452,20 @@ fn slices_are_cut_to_the_exported_region_in_its_pixels() {
|
||||
assert!(slices_of(&file).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_html_text_slice_writes_one_break_for_each_line_ending() {
|
||||
use vectorcraft_doc::{CharStyle, NodeKind, TextObject};
|
||||
use vectorcraft_geom::Point;
|
||||
let mut d = DocBuilder::new(100.0, 60.0).build();
|
||||
let t = TextObject::point(Point::new(10.0, 30.0), "A\r\nB\rC\nD\u{2029}E", CharStyle { size: 12.0, ..CharStyle::default() });
|
||||
let mut n = Node::new(d.alloc_id(), NodeKind::Text(Box::new(t)));
|
||||
n.extras_mut().slice = Some(Box::new(SliceOptions { kind: SliceKind::HtmlText, ..SliceOptions::default() }));
|
||||
let l = d.layers[0].id;
|
||||
d.insert(Some(l), 0, n).unwrap();
|
||||
let res = slices_of(&export(&d, &opts(PsdOptions::default()))).unwrap();
|
||||
assert_eq!(res.slices[0].cell_text, "A<br>B<br>C<br>D<br>E");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slice_ids_count_from_1_and_the_limits_are_errors() {
|
||||
let mut doc = doc();
|
||||
|
||||
Reference in New Issue
Block a user