style(src-tauri): cargo fmt
Pure mechanical rustfmt reformat (default config, no rustfmt.toml).
This commit is contained in:
+43
-12
@@ -224,7 +224,8 @@ fn quantize_colour(img: &mut RgbaImage) {
|
||||
|
||||
fn encode_png(img: &DynamicImage) -> Result<Vec<u8>, LogoError> {
|
||||
let mut buf = Vec::new();
|
||||
let encoder = PngEncoder::new_with_quality(&mut buf, CompressionType::Best, FilterType::Adaptive);
|
||||
let encoder =
|
||||
PngEncoder::new_with_quality(&mut buf, CompressionType::Best, FilterType::Adaptive);
|
||||
img.write_with_encoder(encoder)
|
||||
.map_err(|e| LogoError::Encode(e.to_string()))?;
|
||||
Ok(buf)
|
||||
@@ -360,7 +361,9 @@ mod tests {
|
||||
}
|
||||
|
||||
fn decode_png(bytes: &[u8]) -> RgbaImage {
|
||||
image::load_from_memory_with_format(bytes, ImageFormat::Png).unwrap().to_rgba8()
|
||||
image::load_from_memory_with_format(bytes, ImageFormat::Png)
|
||||
.unwrap()
|
||||
.to_rgba8()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -427,7 +430,8 @@ mod tests {
|
||||
assert!((38..=42).contains(&m.height), "{}", m.height);
|
||||
assert!(out.knockout_png.is_none());
|
||||
// The input pixels are not edited: the printed corners are still the logo colour, not transparent.
|
||||
let printed = image::load_from_memory_with_format(&out.print_png, ImageFormat::Png).unwrap();
|
||||
let printed =
|
||||
image::load_from_memory_with_format(&out.print_png, ImageFormat::Png).unwrap();
|
||||
assert!(!printed.color().has_alpha());
|
||||
}
|
||||
|
||||
@@ -459,7 +463,10 @@ mod tests {
|
||||
// Right magic, broken body.
|
||||
let mut truncated = png_bytes(&alpha_logo(20, 20, (2, 2, 5, 5), [0; 3]));
|
||||
truncated.truncate(30);
|
||||
assert!(matches!(process_logo(&truncated), Err(LogoError::Decode(_))));
|
||||
assert!(matches!(
|
||||
process_logo(&truncated),
|
||||
Err(LogoError::Decode(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -470,14 +477,23 @@ mod tests {
|
||||
|
||||
// A blank image 8193 px wide compresses to a few KB, so it passes the byte cap.
|
||||
let wide = RgbaImage::new(8193, 2);
|
||||
assert!(matches!(process_logo(&png_bytes(&wide)), Err(LogoError::Dimensions)));
|
||||
assert!(matches!(
|
||||
process_logo(&png_bytes(&wide)),
|
||||
Err(LogoError::Dimensions)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blank_images_have_no_content() {
|
||||
assert!(matches!(process_logo(&png_bytes(&RgbaImage::new(40, 40))), Err(LogoError::Empty)));
|
||||
assert!(matches!(
|
||||
process_logo(&png_bytes(&RgbaImage::new(40, 40))),
|
||||
Err(LogoError::Empty)
|
||||
));
|
||||
let white = RgbaImage::from_pixel(40, 40, Rgba([255, 255, 255, 255]));
|
||||
assert!(matches!(process_logo(&png_bytes(&white)), Err(LogoError::Empty)));
|
||||
assert!(matches!(
|
||||
process_logo(&png_bytes(&white)),
|
||||
Err(LogoError::Empty)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -508,9 +524,15 @@ mod tests {
|
||||
assert!((m.ink_density - 0.52).abs() < 1e-9, "{}", m.ink_density);
|
||||
|
||||
let square = alpha_logo(50, 50, (10, 10, 30, 30), [0; 3]);
|
||||
assert_eq!(process_logo(&png_bytes(&square)).unwrap().metrics.kind, LogoKind::Mark);
|
||||
assert_eq!(
|
||||
process_logo(&png_bytes(&square)).unwrap().metrics.kind,
|
||||
LogoKind::Mark
|
||||
);
|
||||
let tall = alpha_logo(50, 100, (10, 10, 12, 40), [0; 3]);
|
||||
assert_eq!(process_logo(&png_bytes(&tall)).unwrap().metrics.kind, LogoKind::Tall);
|
||||
assert_eq!(
|
||||
process_logo(&png_bytes(&tall)).unwrap().metrics.kind,
|
||||
LogoKind::Tall
|
||||
);
|
||||
assert_eq!(kind_for(2.49), LogoKind::Mark);
|
||||
assert_eq!(kind_for(0.6), LogoKind::Tall);
|
||||
}
|
||||
@@ -535,15 +557,24 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn sample_logo_is_trimmed_and_small() {
|
||||
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../src/pdf/testing/fixtures/sample-wordmark-logo.png");
|
||||
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../src/pdf/testing/fixtures/sample-wordmark-logo.png");
|
||||
let bytes = std::fs::read(path).unwrap();
|
||||
let out = process_logo(&bytes).unwrap();
|
||||
let m = &out.metrics;
|
||||
assert_eq!((m.source_width, m.source_height), (2172, 724));
|
||||
assert!((5.3..=5.6).contains(&m.aspect), "aspect {}", m.aspect);
|
||||
assert!((0.50..=0.60).contains(&m.ink_density), "density {}", m.ink_density);
|
||||
assert!(
|
||||
(0.50..=0.60).contains(&m.ink_density),
|
||||
"density {}",
|
||||
m.ink_density
|
||||
);
|
||||
assert_eq!(m.kind, LogoKind::Wordmark);
|
||||
assert!(out.print_png.len() <= 120 * 1024, "print is {} bytes", out.print_png.len());
|
||||
assert!(
|
||||
out.print_png.len() <= 120 * 1024,
|
||||
"print is {} bytes",
|
||||
out.print_png.len()
|
||||
);
|
||||
assert!(out.knockout_png.is_some());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user