Compare commits

..
5 changed files with 15 additions and 37 deletions
+2 -2
View File
File diff suppressed because one or more lines are too long
+11 -6
View File
@@ -1,3 +1,5 @@
use std::borrow::Cow;
use super::date::{DateKind, builtin_date, custom_date, iso_datetime, serial_date};
use super::{
BTreeMap, Ev, Grid, HashMap, MAX_CELLS, MAX_COLS, MAX_ROWS, MAX_SHARED, MAX_SHEETS, MAX_XFS, Package, TextBudget, attr, push_capped, walk,
@@ -261,7 +263,7 @@ pub(super) fn xlsx_rows(pkg: &mut Package<'_>, path: &str) -> Result<Vec<Vec<Str
row.resize(c.col + 1, String::new());
}
if let Some(slot) = row.get_mut(c.col) {
*slot = text;
*slot = text.into_owned();
}
}
_ => {}
@@ -274,12 +276,15 @@ pub(super) fn xlsx_rows(pkg: &mut Package<'_>, path: &str) -> Result<Vec<Vec<Str
Ok(grid.rows)
}
fn xlsx_value(c: &XCell, shared: &[String], formats: &[Option<DateKind>], date1904: bool) -> String {
/// A cell's text: a shared string borrowed, so a cell the sheet then refuses (past the text
/// budget, the columns or the rows) costs no copy of it.
fn xlsx_value<'a>(c: &XCell, shared: &'a [String], formats: &[Option<DateKind>], date1904: bool) -> Cow<'a, str> {
let v = c.value.trim();
let kind = c.kind.trim();
if kind.eq_ignore_ascii_case("s") {
v.parse::<usize>().ok().and_then(|i| shared.get(i)).cloned().unwrap_or_default()
} else if kind.eq_ignore_ascii_case("inlineStr") {
return Cow::Borrowed(v.parse::<usize>().ok().and_then(|i| shared.get(i)).map_or("", String::as_str));
}
Cow::Owned(if kind.eq_ignore_ascii_case("inlineStr") {
if c.inline.is_empty() { c.value.clone() } else { c.inline.clone() }
} else if kind.eq_ignore_ascii_case("str") || kind.eq_ignore_ascii_case("e") {
c.value.clone()
@@ -290,12 +295,12 @@ fn xlsx_value(c: &XCell, shared: &[String], formats: &[Option<DateKind>], date19
} else if v.is_empty() {
c.inline.clone()
} else {
let Ok(x) = v.parse::<f64>() else { return v.to_string() };
let Ok(x) = v.parse::<f64>() else { return Cow::Owned(v.to_string()) };
match formats.get(c.style).copied().flatten() {
Some(kind) => serial_date(x, date1904, kind).unwrap_or_else(|| number(x)),
None => number(x),
}
}
})
}
/// A number as a spreadsheet shows it in General format: up to 15 significant digits, no
+1 -13
View File
@@ -836,22 +836,10 @@ fn draw_image(ctx: &mut RenderContext, fr: &Frame, it: &Draw) {
}
}
/// Widest path drawn, in device pixels a side: 64 times the largest canvas. The rasteriser
/// flattens a curve into as many points as its size asks for, before clipping, so a path with
/// coordinates of 1e15 (file data in a native document) would take it forever or run out of
/// memory; one this far past every canvas shows nothing a real drawing would.
const MAX_PATH_PIXELS: f64 = 1_048_576.0;
/// Whether `path` under `view` is small enough to draw ([`MAX_PATH_PIXELS`]) and finite.
fn path_extent_ok(view: Affine, path: &kurbo::BezPath) -> bool {
let b = view.transform_rect_bbox(path.bounding_box());
path.is_finite() && [b.x0, b.y0, b.x1, b.y1].iter().all(|v| v.is_finite() && v.abs() <= MAX_PATH_PIXELS)
}
fn draw_path(ctx: &mut RenderContext, fr: &Frame, it: &Draw) {
let Draw::Path { segs, fill, stroke, stroke_width, dash, cap } = it else { return };
let path = wordcraft_layout::display::seg_path(segs);
if path.elements().is_empty() || !path_extent_ok(fr.view, &path) {
if path.elements().is_empty() {
return;
}
ctx.set_transform(fr.view);
-15
View File
@@ -1318,18 +1318,3 @@ fn a_line_runs_from_top_left_to_bottom_right() {
let p = shape_path(ShapeKind::Line, kurbo::Rect::new(10.0, 20.0, 30.0, 60.0), None);
assert_eq!(p.elements(), &[kurbo::PathEl::MoveTo((10.0, 20.0).into()), kurbo::PathEl::LineTo((30.0, 60.0).into())]);
}
#[test]
fn paths_far_past_every_canvas_are_not_flattened() {
let line = |x: f64| {
let mut p = kurbo::BezPath::new();
p.move_to((0.0, 0.0));
p.curve_to((x, 0.0), (x, x), (0.0, x));
p
};
assert!(path_extent_ok(Affine::IDENTITY, &line(500.0)));
assert!(path_extent_ok(Affine::scale(4.0), &line(200_000.0)), "a large page at a high zoom");
assert!(!path_extent_ok(Affine::IDENTITY, &line(1e15)));
assert!(!path_extent_ok(Affine::scale(1e12), &line(10.0)));
assert!(!path_extent_ok(Affine::IDENTITY, &line(f64::NAN)));
}
+1 -1
View File
File diff suppressed because one or more lines are too long