mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-28 03:37:00 -06:00
crates/metafile import: EMF and WMF (placeable or not) records play on a small device-context model (objects numbered as GDI does, saved DCs, world transforms and mapping modes, path brackets, the current position) into one artboard (the picture's frame) and one layer: paths with fills and strokes (pens with caps, joins, dashes), clipping groups for clips, images from DIBs (StretchDIBits, BitBlt, StretchBlt, AlphaBlend, StretchDIB, DIBBitBlt) and point type in the font the file names. Lines drawn one after another join into one path; a clip around the whole picture is dropped; objects far outside it are left out; unknown records are skipped with one warning. document.open and file.place read .emf and .wmf through the shared loader (Open and Place filters list them). clipboard.importEmf loads a picture into the clipboard, and Paste takes image/emf from a system clipboard service ahead of text and bitmaps. The import fuzzer covers mutated and random-record metafiles opened, placed and pasted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
1.3 KiB
Rust
29 lines
1.3 KiB
Rust
//! Windows metafiles another app copied paste as vector art (M4.95, through the system clipboard
|
|
//! service of M4.57).
|
|
|
|
use serde_json::json;
|
|
use vectorcraft_doc::NodeKind;
|
|
use vectorcraft_engine::Session;
|
|
use vectorcraft_engine::cmd::clipboard::{EMF, PNG};
|
|
|
|
use crate::sysclip::import_command;
|
|
use crate::tests_sysclip::{app, blue_png, copy_elsewhere, pasted, run};
|
|
|
|
#[test]
|
|
fn an_emf_from_another_app_pastes_as_vectors_ahead_of_its_bitmap() {
|
|
let (mut app, board) = app();
|
|
let mut other = Session::new();
|
|
other.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
|
other.execute("shape.ellipse", &json!({"x": 10, "y": 10, "width": 30, "height": 30})).unwrap();
|
|
let emf = other.execute("document.export", &json!({"format": "emf"})).unwrap();
|
|
let emf = vectorcraft_format::base64_decode(emf["dataBase64"].as_str().unwrap()).unwrap();
|
|
let flavour = vectorcraft_engine::cmd::clipboard::Flavour { mime: EMF, data: emf.clone() };
|
|
assert_eq!(import_command(&flavour, None).0, "clipboard.importEmf");
|
|
copy_elsewhere(&board, vec![(PNG, blue_png()), (EMF, emf)]);
|
|
run(&mut app, "edit.paste", json!({}));
|
|
let p = pasted(&app);
|
|
assert!(!p.is_empty() && p.iter().all(|n| !matches!(n.kind, NodeKind::Image(_))), "{p:?}");
|
|
let b = p[0].geometric_bounds().unwrap();
|
|
assert!((b.width() - 30.0).abs() < 0.05, "{b:?}");
|
|
}
|