Compare commits

..
5 changed files with 24 additions and 39 deletions
+12 -1
View File
@@ -390,6 +390,7 @@ pub fn pdf_options(p: &Value, count: usize) -> Result<deckcraft_pdf::PdfOptions>
pub fn parse_slide_range(text: &str, count: usize) -> Result<Vec<usize>> {
let invalid = || bad("file.export", format!("“{text}” isn't a valid slide range: use numbers and ranges such as 1-3, 5"));
let mut out: Vec<usize> = vec![];
let mut seen: std::collections::HashSet<usize> = std::collections::HashSet::new();
for part in text.split([',', ';']).map(str::trim).filter(|p| !p.is_empty()) {
let (a, b) = match part.split_once('-') {
Some((a, b)) => (a.trim(), b.trim()),
@@ -405,7 +406,7 @@ pub fn parse_slide_range(text: &str, count: usize) -> Result<Vec<usize>> {
return Err(bad("file.export", format!("the presentation has {count} slides; “{part}” is outside them")));
}
for i in lo - 1..hi {
if !out.contains(&i) {
if seen.insert(i) {
out.push(i);
}
}
@@ -769,6 +770,16 @@ mod tests {
use super::{parse_slide_range, write_file};
#[test]
fn broad_and_repeated_slide_ranges_expand_once() {
// 200 copies of a 100,000-slide range: each index once, in order, without a scan per index.
let text = vec!["1-100000"; 200].join(",");
let v = parse_slide_range(&text, 100_000).unwrap();
assert_eq!(v.len(), 100_000);
assert!(v.windows(2).all(|w| w[0] < w[1]));
assert_eq!(parse_slide_range("3, 1-3, 2", 3).unwrap(), vec![2, 0, 1]);
}
#[test]
fn slide_range_rejects_plus_sign() {
assert!(parse_slide_range("+2", 3).is_err());
+1 -1
View File
@@ -367,7 +367,7 @@ fn spelling(s: &mut Session, p: &Value) -> Result<Value> {
}
out.push(v);
}
let rep: Vec<usize> = crate::spell::repeated(para, &default).iter().map(|w| w.start).collect();
let rep: std::collections::HashSet<usize> = crate::spell::repeated(para, &default).iter().map(|w| w.start).collect();
for w in crate::spell::paragraph_words(para, &default) {
if ignore.contains(&w.text.to_lowercase()) || rep.contains(&w.start) {
continue;
+2 -1
View File
@@ -405,8 +405,9 @@ fn select_slides(s: &mut Session, p: &Value) -> Result<Value> {
};
s.select(|doc, sel| {
if add {
let mut have: std::collections::HashSet<_> = sel.slides.iter().copied().collect();
for i in &ids {
if !sel.slides.contains(i) {
if have.insert(*i) {
sel.slides.push(*i);
}
}
+9 -19
View File
@@ -928,25 +928,11 @@ impl Warp {
k_fill = 1.0;
}
zoom = zoom.max(k_fill);
// Per band, measured once: its widest line and its first and last lines' baselines.
let mut stats: Vec<Option<(f64, f64, f64)>> = vec![None; nb];
for (l, &b) in lines.iter().zip(&band_of) {
let w = l.extent.1 - l.extent.0;
if let Some(slot) = stats.get_mut(b) {
match slot {
Some((widest, _, last)) => {
*widest = widest.max(w);
*last = l.ref_y;
}
None => *slot = Some((0.0f64.max(w), l.ref_y, l.ref_y)),
}
}
}
let mut maps = Vec::with_capacity(n);
let mut offsets = Vec::new();
for (i, l) in lines.iter().enumerate() {
let b = band_of.get(i).copied().unwrap_or(0);
let band = stats.get(b).copied().flatten();
let in_band = |j: &usize| band_of.get(*j) == Some(&b);
match self.bands.get(b) {
Some(Band::Fill { .. }) | None => {
let (y0, y1) = band_y.get(b).copied().flatten().unwrap_or((0.0, 1.0));
@@ -955,12 +941,16 @@ impl Warp {
}
Some(Band::Follow { path, anchor }) => {
let len = path.length();
let widest = band.map_or(0.0, |s| s.0);
let widest = (0..n).filter(in_band).filter_map(|j| lines.get(j)).map(|l| l.extent.1 - l.extent.0).fold(0.0, f64::max);
let k = if widest > len && widest > 1e-9 { len / widest } else { 1.0 };
let members: Vec<&WarpLine> = (0..n).filter(in_band).filter_map(|j| lines.get(j)).collect();
let ref_y = match anchor {
LineAnchor::Last => band.map(|s| s.2),
LineAnchor::First => band.map(|s| s.1),
LineAnchor::Middle => band.map(|s| (s.1 + s.2) / 2.0),
LineAnchor::Last => members.last().map(|l| l.ref_y),
LineAnchor::First => members.first().map(|l| l.ref_y),
LineAnchor::Middle => match (members.first(), members.last()) {
(Some(a), Some(z)) => Some((a.ref_y + z.ref_y) / 2.0),
_ => None,
},
}
.unwrap_or(l.ref_y);
// Lines off the guide run on a parallel curve at their natural length.
-17
View File
@@ -319,20 +319,3 @@ fn arch_and_inflate_handles_follow_the_pointer() {
assert!(more > adjust_defaults("textInflate")[0], "{more}");
assert!((more - 20_000.0).abs() < 1.0, "{more}");
}
#[test]
fn many_lines_on_a_follow_band_are_mapped_from_one_measurement() {
// 50,000 lines on an arch: each line's scale and anchor come from the band measured once.
let w = warp("textArchUp", &[], rect()).unwrap();
let inner = Rect::new(7.2, 3.6, W - 7.2, H - 3.6);
let lines: Vec<WarpLine> = (0..50_000)
.map(|i| {
let y = i as f64 * 0.01;
WarpLine { ink: Some(Rect::new(190.0, y, 230.0, y + 1.0)), extent: (190.0, 230.0), ref_y: y + 1.0 }
})
.collect();
let m = w.mapper(&lines, inner);
// The last line sits on the arc, as with two lines.
let last = lines.len() - 1;
assert!(m.map(last, Point::new(210.0, lines[last].ref_y)).y.abs() < 0.05);
}