Add open geometry exchange formats
Beffroi/beffroi-tools/pipeline/head This commit looks good
Details
Beffroi/beffroi-tools/pipeline/head This commit looks good
Details
This commit is contained in:
parent
8769caec00
commit
b95210616a
|
|
@ -2547,6 +2547,7 @@ name = "midra-layout"
|
|||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"csv",
|
||||
"directories",
|
||||
"eframe",
|
||||
"flate2",
|
||||
|
|
|
|||
|
|
@ -36,12 +36,9 @@ Run source commands from the repository root; CLI tools support `--help`.
|
|||
## Midra Layout templates
|
||||
|
||||
These starter files contain two named 16:9 layers on an exact pixel canvas.
|
||||
They can be opened in draw.io or imported into Midra Layout.
|
||||
|
||||
| Output canvas | SVG | draw.io |
|
||||
| --- | --- | --- |
|
||||
| Full HD — 1920 × 1080 | [Download SVG](docs/templates/midra-layout/midra-layout-1080p-2-layers.svg) | [Download draw.io](docs/templates/midra-layout/midra-layout-1080p-2-layers.drawio) |
|
||||
| UHD 4K — 3840 × 2160 | [Download SVG](docs/templates/midra-layout/midra-layout-4k-2-layers.svg) | [Download draw.io](docs/templates/midra-layout/midra-layout-4k-2-layers.drawio) |
|
||||
- **Full HD — 1920 × 1080:** [SVG](docs/templates/midra-layout/midra-layout-1080p-2-layers.svg) · [draw.io](docs/templates/midra-layout/midra-layout-1080p-2-layers.drawio) · [JSON](docs/templates/midra-layout/midra-layout-1080p-2-layers.json) · [CSV](docs/templates/midra-layout/midra-layout-1080p-2-layers.csv) · [DXF](docs/templates/midra-layout/midra-layout-1080p-2-layers.dxf) · [HTML](docs/templates/midra-layout/midra-layout-1080p-2-layers.html)
|
||||
- **UHD 4K — 3840 × 2160:** [SVG](docs/templates/midra-layout/midra-layout-4k-2-layers.svg) · [draw.io](docs/templates/midra-layout/midra-layout-4k-2-layers.drawio) · [JSON](docs/templates/midra-layout/midra-layout-4k-2-layers.json) · [CSV](docs/templates/midra-layout/midra-layout-4k-2-layers.csv) · [DXF](docs/templates/midra-layout/midra-layout-4k-2-layers.dxf) · [HTML](docs/templates/midra-layout/midra-layout-4k-2-layers.html)
|
||||
|
||||
## PPTX reporter visual guide
|
||||
|
||||
|
|
@ -59,7 +56,7 @@ opening reports, and reading video timings.
|
|||
- [ASCII filename cleaner](docs/ascii-names.md)
|
||||
- [Document exports](docs/exporter.md)
|
||||
- [Rundown converter](docs/rundown-converter.md) · [Sample findings](docs/rundown-corpus.md)
|
||||
- [Midra layout helper](docs/midra-layout.md) · [Plan and visual proposals](docs/midra-layout-plan.md) · [File formats](docs/interfaces/midra-layout.md)
|
||||
- [Midra layout helper](docs/midra-layout.md) · [Geometry formats](docs/interfaces/midra-layout-exchange.md) · [Project format](docs/interfaces/midra-layout.md) · [Plan](docs/midra-layout-plan.md)
|
||||
- [Development](docs/development.md) · [CI and coverage](docs/ci.md)
|
||||
- [Cross builds and portable releases](docs/releases.md) · [App icons and desktop launchers](docs/releases.md#application-artwork)
|
||||
- [MPC-HC Companion module development](companion-modules/media-player-classic/README.md)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ serde = { version = "1", features = ["derive"] }
|
|||
serde_json = { version = "1", features = ["float_roundtrip"] }
|
||||
base64 = "0.22"
|
||||
flate2 = "1"
|
||||
csv = "1.4"
|
||||
tempfile = "3"
|
||||
directories = "6"
|
||||
reqwest = { version = "0.12.28", default-features = false, features = ["blocking"] }
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ fn main() -> Result<(), String> {
|
|||
std::fs::create_dir_all(directory).map_err(|e| e.to_string())?;
|
||||
let project = Project::from_layout(&Layout::default());
|
||||
let ids = project.layers.iter().map(|l| l.id).collect::<Vec<_>>();
|
||||
for format in [Format::Svg, Format::Drawio] {
|
||||
for format in Format::ALL {
|
||||
for (name, options) in [
|
||||
("plain", Options::default()),
|
||||
(
|
||||
|
|
@ -80,7 +80,7 @@ fn main() -> Result<(), String> {
|
|||
.iter()
|
||||
.map(|layer| layer.id)
|
||||
.collect::<Vec<_>>();
|
||||
for format in [Format::Svg, Format::Drawio] {
|
||||
for format in Format::ALL {
|
||||
let contents = exchange::export(&project, &ids, format, Options::default())?;
|
||||
write_file(
|
||||
&directory.join(format!(
|
||||
|
|
@ -88,7 +88,7 @@ fn main() -> Result<(), String> {
|
|||
format.extension()
|
||||
)),
|
||||
contents.as_bytes(),
|
||||
false,
|
||||
true,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//! SVG/draw.io geometry interchange with self-contained optional artwork.
|
||||
//! Versioned geometry interchange with self-contained optional artwork.
|
||||
use crate::{
|
||||
Geometry, export_pixels,
|
||||
project::{Layer, Project},
|
||||
|
|
@ -13,6 +13,10 @@ pub enum Format {
|
|||
#[default]
|
||||
Svg,
|
||||
Drawio,
|
||||
Json,
|
||||
Csv,
|
||||
Dxf,
|
||||
Html,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct Options {
|
||||
|
|
@ -20,20 +24,48 @@ pub struct Options {
|
|||
pub placeholders: bool,
|
||||
}
|
||||
impl Format {
|
||||
pub const ALL: [Self; 6] = [
|
||||
Self::Svg,
|
||||
Self::Drawio,
|
||||
Self::Json,
|
||||
Self::Csv,
|
||||
Self::Dxf,
|
||||
Self::Html,
|
||||
];
|
||||
pub fn extension(self) -> &'static str {
|
||||
match self {
|
||||
Self::Svg => "svg",
|
||||
Self::Drawio => "drawio",
|
||||
Self::Json => "json",
|
||||
Self::Csv => "csv",
|
||||
Self::Dxf => "dxf",
|
||||
Self::Html => "html",
|
||||
}
|
||||
}
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::Svg => "SVG",
|
||||
Self::Drawio => "draw.io",
|
||||
Self::Json => "Geometry JSON",
|
||||
Self::Csv => "Geometry CSV",
|
||||
Self::Dxf => "DXF",
|
||||
Self::Html => "HTML / CSS",
|
||||
}
|
||||
}
|
||||
pub fn supports_placeholders(self) -> bool {
|
||||
matches!(self, Self::Svg | Self::Drawio | Self::Json | Self::Html)
|
||||
}
|
||||
}
|
||||
fn escape(s: &str) -> String {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct ExportShape {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub geometry: Geometry,
|
||||
pub image_png_base64: Option<String>,
|
||||
pub background: bool,
|
||||
}
|
||||
pub(crate) fn escape(s: &str) -> String {
|
||||
s.replace('&', "&")
|
||||
.replace('<', "<")
|
||||
.replace('>', ">")
|
||||
|
|
@ -148,6 +180,56 @@ pub fn export(
|
|||
}
|
||||
let w = project.output_resolution.width;
|
||||
let h = project.output_resolution.height;
|
||||
if options.placeholders && !format.supports_placeholders() {
|
||||
return Err(format!(
|
||||
"{} cannot embed placeholder pictures.",
|
||||
format.label()
|
||||
));
|
||||
}
|
||||
let mut shapes = Vec::new();
|
||||
if options.background {
|
||||
let image_png_base64 = matches!(
|
||||
format,
|
||||
Format::Svg | Format::Drawio | Format::Json | Format::Html
|
||||
)
|
||||
.then(|| background(project))
|
||||
.transpose()?;
|
||||
shapes.push(ExportShape {
|
||||
id: "midra-background".into(),
|
||||
name: "Background".into(),
|
||||
geometry: Geometry {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
width: w as f64,
|
||||
height: h as f64,
|
||||
},
|
||||
image_png_base64,
|
||||
background: true,
|
||||
});
|
||||
}
|
||||
for layer in project.layers.iter().filter(|l| ids.contains(&l.id)) {
|
||||
let g = layer.bounds;
|
||||
if g.width.round() < 1.0 || g.height.round() < 1.0 {
|
||||
return Err("A layer rounds to zero pixels; enlarge it before export.".into());
|
||||
}
|
||||
let image_png_base64 = options
|
||||
.placeholders
|
||||
.then(|| placeholder(project, layer))
|
||||
.transpose()?;
|
||||
shapes.push(ExportShape {
|
||||
id: format!("layer-{}", layer.id),
|
||||
name: layer.name.clone(),
|
||||
geometry: g,
|
||||
image_png_base64,
|
||||
background: false,
|
||||
});
|
||||
}
|
||||
if matches!(
|
||||
format,
|
||||
Format::Json | Format::Csv | Format::Dxf | Format::Html
|
||||
) {
|
||||
return crate::geometry_formats::export(format, [w, h], &shapes);
|
||||
}
|
||||
let mut out = match format {
|
||||
Format::Svg => format!(
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" data-midra-layout-geometry=\"2\" width=\"{w}\" height=\"{h}\" viewBox=\"0 0 {w} {h}\">\n<title>Midra Layout geometry</title>\n"
|
||||
|
|
@ -155,47 +237,23 @@ pub fn export(
|
|||
Format::Drawio => format!(
|
||||
"<mxfile host=\"Midra Layout\" compressed=\"false\"><diagram id=\"midra-layout\" name=\"Layout\"><mxGraphModel page=\"1\" pageScale=\"1\" pageWidth=\"{w}\" pageHeight=\"{h}\" grid=\"0\" adaptiveColors=\"none\" data-midra-layout-geometry=\"1\"><root><mxCell id=\"0\"/><mxCell id=\"1\" parent=\"0\"/>\n"
|
||||
),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
if options.background {
|
||||
let image = background(project)?;
|
||||
let geometry = Geometry {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
width: w as f64,
|
||||
height: h as f64,
|
||||
};
|
||||
for shape in &shapes {
|
||||
element(
|
||||
&mut out,
|
||||
format,
|
||||
"midra-background",
|
||||
"Background",
|
||||
geometry,
|
||||
Some(&image),
|
||||
true,
|
||||
);
|
||||
}
|
||||
for layer in project.layers.iter().filter(|l| ids.contains(&l.id)) {
|
||||
let g = layer.bounds;
|
||||
if g.width.round() < 1.0 || g.height.round() < 1.0 {
|
||||
return Err("A layer rounds to zero pixels; enlarge it before export.".into());
|
||||
}
|
||||
let image = options
|
||||
.placeholders
|
||||
.then(|| placeholder(project, layer))
|
||||
.transpose()?;
|
||||
element(
|
||||
&mut out,
|
||||
format,
|
||||
&format!("layer-{}", layer.id),
|
||||
&layer.name,
|
||||
g,
|
||||
image.as_deref(),
|
||||
false,
|
||||
&shape.id,
|
||||
&shape.name,
|
||||
shape.geometry,
|
||||
shape.image_png_base64.as_deref(),
|
||||
shape.background,
|
||||
);
|
||||
}
|
||||
out.push_str(match format {
|
||||
Format::Svg => "</svg>\n",
|
||||
Format::Drawio => "</root></mxGraphModel></diagram></mxfile>\n",
|
||||
_ => unreachable!(),
|
||||
});
|
||||
if out.len() > MAX_EXCHANGE_BYTES {
|
||||
return Err(
|
||||
|
|
@ -240,5 +298,6 @@ fn element(
|
|||
.unwrap_or_default();
|
||||
out.push_str(&format!("<mxCell id=\"{id}\" value=\"{name}\" data-midra-role=\"{role}\" vertex=\"1\" parent=\"1\" style=\"rounded=0;whiteSpace=wrap;html=0;strokeColor=none;fillColor=#173b50;fontColor=#ffffff;{image}\"><mxGeometry x=\"{x}\" y=\"{y}\" width=\"{w}\" height=\"{h}\" as=\"geometry\"/></mxCell>\n"));
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,580 @@
|
|||
//! Open, text-based geometry adapters beyond SVG and draw.io.
|
||||
use crate::{
|
||||
Geometry,
|
||||
exchange::{ExportShape, Format, MAX_EXCHANGE_BYTES},
|
||||
import::{DetectedShape, ImportDocument},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashSet;
|
||||
|
||||
const GEOMETRY_FORMAT: &str = "beffroi.midra-geometry";
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct JsonCanvas {
|
||||
width: u32,
|
||||
height: u32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct JsonShape {
|
||||
id: String,
|
||||
name: String,
|
||||
role: String,
|
||||
x: i64,
|
||||
y: i64,
|
||||
width: i64,
|
||||
height: i64,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
image_png_base64: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct JsonDocument {
|
||||
format: String,
|
||||
version: u32,
|
||||
units: String,
|
||||
canvas: JsonCanvas,
|
||||
layers: Vec<JsonShape>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct CsvShape {
|
||||
midra_geometry_version: u32,
|
||||
canvas_width: u32,
|
||||
canvas_height: u32,
|
||||
id: String,
|
||||
name: String,
|
||||
role: String,
|
||||
x: i64,
|
||||
y: i64,
|
||||
width: i64,
|
||||
height: i64,
|
||||
}
|
||||
|
||||
fn rounded(geometry: Geometry) -> [i64; 4] {
|
||||
[
|
||||
geometry.x.round() as i64,
|
||||
geometry.y.round() as i64,
|
||||
geometry.width.round() as i64,
|
||||
geometry.height.round() as i64,
|
||||
]
|
||||
}
|
||||
|
||||
fn role(background: bool) -> &'static str {
|
||||
if background { "background" } else { "layer" }
|
||||
}
|
||||
|
||||
fn validate_canvas(canvas: [u32; 2]) -> Result<(), String> {
|
||||
crate::formats::validate_resolution(canvas)
|
||||
}
|
||||
|
||||
fn document(
|
||||
format_name: &str,
|
||||
canvas: [u32; 2],
|
||||
shapes: Vec<JsonShape>,
|
||||
) -> Result<ImportDocument, String> {
|
||||
validate_canvas(canvas)?;
|
||||
if shapes.is_empty() || shapes.len() > 257 {
|
||||
return Err("Geometry exchange requires 1–256 layers and at most one background.".into());
|
||||
}
|
||||
let mut ids = HashSet::new();
|
||||
let mut backgrounds = 0;
|
||||
let mut detected = Vec::with_capacity(shapes.len());
|
||||
for shape in shapes {
|
||||
if shape.id.is_empty() || shape.id.chars().count() > 255 || !ids.insert(shape.id.clone()) {
|
||||
return Err(
|
||||
"Geometry IDs must be unique, non-empty and at most 255 characters.".into(),
|
||||
);
|
||||
}
|
||||
if shape.name.chars().count() > 1024 || shape.name.chars().any(char::is_control) {
|
||||
return Err("Geometry names must be at most 1024 characters without controls.".into());
|
||||
}
|
||||
let background = match shape.role.as_str() {
|
||||
"layer" => false,
|
||||
"background" => {
|
||||
backgrounds += 1;
|
||||
true
|
||||
}
|
||||
_ => return Err("Geometry role must be layer or background.".into()),
|
||||
};
|
||||
let geometry = Geometry {
|
||||
x: shape.x as f64,
|
||||
y: shape.y as f64,
|
||||
width: shape.width as f64,
|
||||
height: shape.height as f64,
|
||||
}
|
||||
.validate()?;
|
||||
if background
|
||||
&& (geometry.x != 0.0
|
||||
|| geometry.y != 0.0
|
||||
|| geometry.width != canvas[0] as f64
|
||||
|| geometry.height != canvas[1] as f64)
|
||||
{
|
||||
return Err("The geometry background must cover the complete canvas.".into());
|
||||
}
|
||||
detected.push(DetectedShape {
|
||||
id: if shape.name.is_empty() {
|
||||
shape.id
|
||||
} else {
|
||||
format!("{} · {}", shape.id, shape.name)
|
||||
},
|
||||
geometry,
|
||||
outline: [0.0; 2],
|
||||
background,
|
||||
background_only: background,
|
||||
zoom: None,
|
||||
});
|
||||
}
|
||||
if backgrounds > 1
|
||||
|| detected
|
||||
.iter()
|
||||
.filter(|shape| !shape.background_only)
|
||||
.count()
|
||||
> 256
|
||||
{
|
||||
return Err("Geometry exchange allows at most 256 layers and one background.".into());
|
||||
}
|
||||
Ok(ImportDocument {
|
||||
shapes: detected,
|
||||
svg: false,
|
||||
note: format!(
|
||||
"{format_name}: {} × {} px canvas; top-left whole-pixel layer boxes.",
|
||||
canvas[0], canvas[1]
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn export(
|
||||
format: Format,
|
||||
canvas: [u32; 2],
|
||||
shapes: &[ExportShape],
|
||||
) -> Result<String, String> {
|
||||
let output = match format {
|
||||
Format::Json => export_json(canvas, shapes)?,
|
||||
Format::Csv => export_csv(canvas, shapes)?,
|
||||
Format::Dxf => export_dxf(canvas, shapes),
|
||||
Format::Html => export_html(canvas, shapes),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
if output.len() > MAX_EXCHANGE_BYTES {
|
||||
return Err("Export exceeds 16 MiB; disable embedded artwork.".into());
|
||||
}
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
fn export_json(canvas: [u32; 2], shapes: &[ExportShape]) -> Result<String, String> {
|
||||
let layers = shapes
|
||||
.iter()
|
||||
.map(|shape| {
|
||||
let [x, y, width, height] = rounded(shape.geometry);
|
||||
JsonShape {
|
||||
id: shape.id.clone(),
|
||||
name: shape.name.clone(),
|
||||
role: role(shape.background).into(),
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
image_png_base64: shape.image_png_base64.clone(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let document = JsonDocument {
|
||||
format: GEOMETRY_FORMAT.into(),
|
||||
version: 1,
|
||||
units: "px".into(),
|
||||
canvas: JsonCanvas {
|
||||
width: canvas[0],
|
||||
height: canvas[1],
|
||||
},
|
||||
layers,
|
||||
};
|
||||
serde_json::to_string_pretty(&document)
|
||||
.map(|mut output| {
|
||||
output.push('\n');
|
||||
output
|
||||
})
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
fn export_csv(canvas: [u32; 2], shapes: &[ExportShape]) -> Result<String, String> {
|
||||
let mut writer = csv::WriterBuilder::new()
|
||||
.terminator(csv::Terminator::CRLF)
|
||||
.from_writer(Vec::new());
|
||||
for shape in shapes {
|
||||
let [x, y, width, height] = rounded(shape.geometry);
|
||||
writer
|
||||
.serialize(CsvShape {
|
||||
midra_geometry_version: 1,
|
||||
canvas_width: canvas[0],
|
||||
canvas_height: canvas[1],
|
||||
id: shape.id.clone(),
|
||||
name: shape.name.clone(),
|
||||
role: role(shape.background).into(),
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
})
|
||||
.map_err(|error| error.to_string())?;
|
||||
}
|
||||
String::from_utf8(writer.into_inner().map_err(|error| error.to_string())?)
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
fn export_html(canvas: [u32; 2], shapes: &[ExportShape]) -> String {
|
||||
let mut output = format!(
|
||||
"<!DOCTYPE html>\n<html xmlns=\"http://www.w3.org/1999/xhtml\" data-midra-layout-geometry=\"1\"><head><meta charset=\"utf-8\"/><title>Midra Layout geometry</title><style>html,body{{margin:0}} #midra-canvas{{position:relative;width:{}px;height:{}px;background:#122531;overflow:hidden}} .midra-layer{{position:absolute;box-sizing:border-box;background:#173b50;color:white;display:flex;align-items:center;justify-content:center;font:16px sans-serif}} img.midra-layer{{object-fit:fill}}</style></head><body><main id=\"midra-canvas\" data-width=\"{}\" data-height=\"{}\">\n",
|
||||
canvas[0], canvas[1], canvas[0], canvas[1]
|
||||
);
|
||||
for shape in shapes {
|
||||
let [x, y, width, height] = rounded(shape.geometry);
|
||||
let common = format!(
|
||||
"id=\"{}\" class=\"midra-layer\" data-midra-role=\"{}\" data-name=\"{}\" data-x=\"{x}\" data-y=\"{y}\" data-width=\"{width}\" data-height=\"{height}\" style=\"left:{x}px;top:{y}px;width:{width}px;height:{height}px\"",
|
||||
crate::exchange::escape(&shape.id),
|
||||
role(shape.background),
|
||||
crate::exchange::escape(&shape.name)
|
||||
);
|
||||
if let Some(image) = &shape.image_png_base64 {
|
||||
output.push_str(&format!(
|
||||
"<img {common} alt=\"{}\" src=\"data:image/png;base64,{image}\"/>\n",
|
||||
crate::exchange::escape(&shape.name)
|
||||
));
|
||||
} else {
|
||||
output.push_str(&format!(
|
||||
"<div {common}>{}</div>\n",
|
||||
crate::exchange::escape(&shape.name)
|
||||
));
|
||||
}
|
||||
}
|
||||
output.push_str("</main></body></html>\n");
|
||||
output
|
||||
}
|
||||
|
||||
fn dxf_pair(output: &mut String, code: i32, value: impl std::fmt::Display) {
|
||||
output.push_str(&format!("{code}\r\n{value}\r\n"));
|
||||
}
|
||||
|
||||
fn export_dxf(canvas: [u32; 2], shapes: &[ExportShape]) -> String {
|
||||
let mut output = String::new();
|
||||
dxf_pair(&mut output, 999, "MIDRA_LAYOUT_GEOMETRY 1");
|
||||
dxf_pair(&mut output, 0, "SECTION");
|
||||
dxf_pair(&mut output, 2, "HEADER");
|
||||
dxf_pair(&mut output, 9, "$ACADVER");
|
||||
dxf_pair(&mut output, 1, "AC1021");
|
||||
dxf_pair(&mut output, 9, "$INSUNITS");
|
||||
dxf_pair(&mut output, 70, 0);
|
||||
dxf_pair(&mut output, 9, "$EXTMIN");
|
||||
dxf_pair(&mut output, 10, 0);
|
||||
dxf_pair(&mut output, 20, 0);
|
||||
dxf_pair(&mut output, 9, "$EXTMAX");
|
||||
dxf_pair(&mut output, 10, canvas[0]);
|
||||
dxf_pair(&mut output, 20, canvas[1]);
|
||||
dxf_pair(&mut output, 9, "$LIMMIN");
|
||||
dxf_pair(&mut output, 10, 0);
|
||||
dxf_pair(&mut output, 20, 0);
|
||||
dxf_pair(&mut output, 9, "$LIMMAX");
|
||||
dxf_pair(&mut output, 10, canvas[0]);
|
||||
dxf_pair(&mut output, 20, canvas[1]);
|
||||
dxf_pair(&mut output, 0, "ENDSEC");
|
||||
dxf_pair(&mut output, 0, "SECTION");
|
||||
dxf_pair(&mut output, 2, "TABLES");
|
||||
dxf_pair(&mut output, 0, "TABLE");
|
||||
dxf_pair(&mut output, 2, "LAYER");
|
||||
dxf_pair(&mut output, 70, shapes.len());
|
||||
for (index, shape) in shapes.iter().enumerate() {
|
||||
dxf_pair(&mut output, 0, "LAYER");
|
||||
dxf_pair(&mut output, 2, &shape.id);
|
||||
dxf_pair(&mut output, 70, 0);
|
||||
dxf_pair(&mut output, 62, if index % 2 == 0 { 4 } else { 5 });
|
||||
dxf_pair(&mut output, 6, "CONTINUOUS");
|
||||
}
|
||||
dxf_pair(&mut output, 0, "ENDTAB");
|
||||
dxf_pair(&mut output, 0, "ENDSEC");
|
||||
dxf_pair(&mut output, 0, "SECTION");
|
||||
dxf_pair(&mut output, 2, "ENTITIES");
|
||||
for shape in shapes {
|
||||
let [x, y, width, height] = rounded(shape.geometry);
|
||||
let top = i64::from(canvas[1]) - y;
|
||||
let bottom = top - height;
|
||||
dxf_pair(&mut output, 999, format!("NAME {}", shape.name));
|
||||
dxf_pair(&mut output, 0, "LWPOLYLINE");
|
||||
dxf_pair(&mut output, 8, &shape.id);
|
||||
dxf_pair(&mut output, 90, 4);
|
||||
dxf_pair(&mut output, 70, 1);
|
||||
for [px, py] in [[x, top], [x + width, top], [x + width, bottom], [x, bottom]] {
|
||||
dxf_pair(&mut output, 10, px);
|
||||
dxf_pair(&mut output, 20, py);
|
||||
}
|
||||
}
|
||||
dxf_pair(&mut output, 0, "ENDSEC");
|
||||
dxf_pair(&mut output, 0, "EOF");
|
||||
output
|
||||
}
|
||||
|
||||
pub(crate) fn parse_json(text: &str) -> Result<ImportDocument, String> {
|
||||
let parsed: JsonDocument =
|
||||
serde_json::from_str(text).map_err(|error| format!("Invalid geometry JSON: {error}"))?;
|
||||
if parsed.format != GEOMETRY_FORMAT || parsed.version != 1 || parsed.units != "px" {
|
||||
return Err("Expected beffroi.midra-geometry version 1 in px.".into());
|
||||
}
|
||||
document(
|
||||
"Geometry JSON v1",
|
||||
[parsed.canvas.width, parsed.canvas.height],
|
||||
parsed.layers,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn parse_csv(text: &str) -> Result<ImportDocument, String> {
|
||||
let text = text.strip_prefix('\u{feff}').unwrap_or(text);
|
||||
let mut reader = csv::ReaderBuilder::new().from_reader(text.as_bytes());
|
||||
let mut canvas = None;
|
||||
let mut layers = Vec::new();
|
||||
for row in reader.deserialize::<CsvShape>() {
|
||||
let row = row.map_err(|error| format!("Invalid geometry CSV: {error}"))?;
|
||||
if row.midra_geometry_version != 1 {
|
||||
return Err("Expected geometry CSV version 1.".into());
|
||||
}
|
||||
let row_canvas = [row.canvas_width, row.canvas_height];
|
||||
if canvas
|
||||
.replace(row_canvas)
|
||||
.is_some_and(|previous| previous != row_canvas)
|
||||
{
|
||||
return Err("Every geometry CSV row must use the same canvas.".into());
|
||||
}
|
||||
layers.push(JsonShape {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
role: row.role,
|
||||
x: row.x,
|
||||
y: row.y,
|
||||
width: row.width,
|
||||
height: row.height,
|
||||
image_png_base64: None,
|
||||
});
|
||||
}
|
||||
document(
|
||||
"Geometry CSV v1",
|
||||
canvas.ok_or("Geometry CSV has no layer rows.")?,
|
||||
layers,
|
||||
)
|
||||
}
|
||||
|
||||
fn xml_number(node: roxmltree::Node, name: &str) -> Result<i64, String> {
|
||||
node.attribute(name)
|
||||
.ok_or_else(|| format!("Missing HTML {name}."))?
|
||||
.parse::<i64>()
|
||||
.map_err(|_| format!("Invalid HTML {name}."))
|
||||
}
|
||||
|
||||
pub(crate) fn parse_html(text: &str) -> Result<ImportDocument, String> {
|
||||
let document_xml = roxmltree::Document::parse_with_options(
|
||||
text,
|
||||
roxmltree::ParsingOptions {
|
||||
allow_dtd: true,
|
||||
nodes_limit: 200_000,
|
||||
},
|
||||
)
|
||||
.map_err(|error| format!("Invalid geometry HTML: {error}"))?;
|
||||
let root = document_xml.root_element();
|
||||
if !root.has_tag_name("html") || root.attribute("data-midra-layout-geometry") != Some("1") {
|
||||
return Err("Expected Midra Layout HTML geometry version 1.".into());
|
||||
}
|
||||
let canvas = root
|
||||
.descendants()
|
||||
.find(|node| node.attribute("id") == Some("midra-canvas"))
|
||||
.ok_or("HTML geometry is missing #midra-canvas.")?;
|
||||
let size = [
|
||||
xml_number(canvas, "data-width")?,
|
||||
xml_number(canvas, "data-height")?,
|
||||
];
|
||||
if size
|
||||
.iter()
|
||||
.any(|value| *value <= 0 || *value > i64::from(u32::MAX))
|
||||
{
|
||||
return Err("Invalid HTML canvas size.".into());
|
||||
}
|
||||
let mut layers = Vec::new();
|
||||
for node in canvas
|
||||
.descendants()
|
||||
.filter(|node| node.is_element() && node.attribute("data-midra-role").is_some())
|
||||
{
|
||||
layers.push(JsonShape {
|
||||
id: node.attribute("id").unwrap_or("").into(),
|
||||
name: node.attribute("data-name").unwrap_or("").into(),
|
||||
role: node.attribute("data-midra-role").unwrap().into(),
|
||||
x: xml_number(node, "data-x")?,
|
||||
y: xml_number(node, "data-y")?,
|
||||
width: xml_number(node, "data-width")?,
|
||||
height: xml_number(node, "data-height")?,
|
||||
image_png_base64: None,
|
||||
});
|
||||
}
|
||||
document(
|
||||
"HTML/CSS geometry v1",
|
||||
[size[0] as u32, size[1] as u32],
|
||||
layers,
|
||||
)
|
||||
}
|
||||
|
||||
fn dxf_pairs(text: &str) -> Result<Vec<(i32, &str)>, String> {
|
||||
let lines: Vec<_> = text.lines().collect();
|
||||
let (pairs, remainder) = lines.as_chunks::<2>();
|
||||
if !remainder.is_empty() {
|
||||
return Err("DXF must contain group-code/value line pairs.".into());
|
||||
}
|
||||
pairs
|
||||
.iter()
|
||||
.map(|pair| {
|
||||
pair[0]
|
||||
.trim()
|
||||
.parse::<i32>()
|
||||
.map(|code| (code, pair[1].trim()))
|
||||
.map_err(|_| "Invalid DXF group code.".into())
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn parse_dxf(text: &str) -> Result<ImportDocument, String> {
|
||||
let pairs = dxf_pairs(text)?;
|
||||
if !pairs
|
||||
.iter()
|
||||
.any(|(code, value)| *code == 0 && *value == "LWPOLYLINE")
|
||||
{
|
||||
return Err("DXF import requires closed LWPOLYLINE rectangles.".into());
|
||||
}
|
||||
let header_point = |name: &str| -> Result<[f64; 2], String> {
|
||||
let start = pairs
|
||||
.iter()
|
||||
.position(|pair| *pair == (9, name))
|
||||
.ok_or_else(|| format!("DXF requires {name} canvas metadata."))?;
|
||||
let mut x = None;
|
||||
let mut y = None;
|
||||
for (code, value) in &pairs[start + 1..] {
|
||||
if matches!(code, 0 | 9) {
|
||||
break;
|
||||
}
|
||||
if *code == 10 {
|
||||
x = Some(
|
||||
value
|
||||
.parse::<f64>()
|
||||
.map_err(|_| format!("Invalid DXF {name} X coordinate."))?,
|
||||
);
|
||||
} else if *code == 20 {
|
||||
y = Some(
|
||||
value
|
||||
.parse::<f64>()
|
||||
.map_err(|_| format!("Invalid DXF {name} Y coordinate."))?,
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok([
|
||||
x.ok_or_else(|| format!("DXF {name} is missing X."))?,
|
||||
y.ok_or_else(|| format!("DXF {name} is missing Y."))?,
|
||||
])
|
||||
};
|
||||
let min = header_point("$LIMMIN").or_else(|_| header_point("$EXTMIN"))?;
|
||||
let max = header_point("$LIMMAX").or_else(|_| header_point("$EXTMAX"))?;
|
||||
let canvas_f = [max[0] - min[0], max[1] - min[1]];
|
||||
if canvas_f
|
||||
.iter()
|
||||
.any(|value| !value.is_finite() || *value <= 0.0 || value.fract() != 0.0)
|
||||
{
|
||||
return Err("DXF canvas extents must be positive whole pixels.".into());
|
||||
}
|
||||
let canvas = [canvas_f[0] as u32, canvas_f[1] as u32];
|
||||
validate_canvas(canvas)?;
|
||||
let mut layers = Vec::new();
|
||||
let mut index = 0;
|
||||
while index < pairs.len() {
|
||||
if pairs[index] != (0, "LWPOLYLINE") {
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
let start = index + 1;
|
||||
index = start;
|
||||
while index < pairs.len() && pairs[index].0 != 0 {
|
||||
index += 1;
|
||||
}
|
||||
let entity = &pairs[start..index];
|
||||
let id = entity
|
||||
.iter()
|
||||
.find(|(code, _)| *code == 8)
|
||||
.map(|(_, value)| *value)
|
||||
.ok_or("DXF rectangle is missing a layer name.")?;
|
||||
let closed = entity
|
||||
.iter()
|
||||
.find(|(code, _)| *code == 70)
|
||||
.and_then(|(_, value)| value.parse::<u32>().ok())
|
||||
.is_some_and(|flags| flags & 1 != 0);
|
||||
if !closed {
|
||||
return Err("DXF rectangles must be closed LWPOLYLINE entities.".into());
|
||||
}
|
||||
let mut points = Vec::new();
|
||||
let mut point = None;
|
||||
for (code, value) in entity {
|
||||
if *code == 10 {
|
||||
if point.is_some() {
|
||||
return Err("DXF vertex is missing its Y coordinate.".into());
|
||||
}
|
||||
point = Some(
|
||||
value
|
||||
.parse::<f64>()
|
||||
.map_err(|_| "Invalid DXF X coordinate.")?,
|
||||
);
|
||||
} else if *code == 20 {
|
||||
let x = point.take().ok_or("DXF vertex Y appears before X.")?;
|
||||
points.push([
|
||||
x,
|
||||
value
|
||||
.parse::<f64>()
|
||||
.map_err(|_| "Invalid DXF Y coordinate.")?,
|
||||
]);
|
||||
}
|
||||
}
|
||||
if point.is_some() || points.len() != 4 {
|
||||
return Err("DXF rectangles require exactly four X/Y vertices.".into());
|
||||
}
|
||||
let cad = super::import::rectangle_points(points)?;
|
||||
let [x, y, width, height] = [
|
||||
cad.x - min[0],
|
||||
max[1] - (cad.y + cad.height),
|
||||
cad.width,
|
||||
cad.height,
|
||||
]
|
||||
.map(|value| value.round() as i64);
|
||||
layers.push(JsonShape {
|
||||
id: id.into(),
|
||||
name: String::new(),
|
||||
role: if id == "midra-background" {
|
||||
"background"
|
||||
} else {
|
||||
"layer"
|
||||
}
|
||||
.into(),
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
image_png_base64: None,
|
||||
});
|
||||
}
|
||||
document("DXF geometry", canvas, layers)
|
||||
}
|
||||
|
||||
pub(crate) fn looks_like_csv(text: &str) -> bool {
|
||||
text.trim_start_matches(['\u{feff}', ' ', '\t', '\r', '\n'])
|
||||
.starts_with("midra_geometry_version,canvas_width,canvas_height,")
|
||||
}
|
||||
|
||||
pub(crate) fn looks_like_dxf(text: &str) -> bool {
|
||||
let start = text.trim_start_matches(['\u{feff}', ' ', '\t', '\r', '\n']);
|
||||
start.starts_with("999\r\nMIDRA_LAYOUT_GEOMETRY")
|
||||
|| start.starts_with("999\nMIDRA_LAYOUT_GEOMETRY")
|
||||
|| (start.starts_with("0\r\nSECTION") && text.contains("LWPOLYLINE"))
|
||||
|| (start.starts_with("0\nSECTION") && text.contains("LWPOLYLINE"))
|
||||
}
|
||||
|
|
@ -582,18 +582,21 @@ impl Editor {
|
|||
}
|
||||
self.paste = Some(p);
|
||||
}
|
||||
fn import_svg_file(&mut self) {
|
||||
fn import_geometry_file(&mut self) {
|
||||
if let Some(path) = rfd::FileDialog::new()
|
||||
.add_filter("Layer geometry (SVG / draw.io)", &["svg", "drawio", "xml"])
|
||||
.add_filter(
|
||||
"Layer geometry",
|
||||
&["svg", "drawio", "xml", "json", "csv", "dxf", "html"],
|
||||
)
|
||||
.pick_file()
|
||||
{
|
||||
self.open_paste(String::new());
|
||||
if let Some(p) = self.paste.as_mut() {
|
||||
Self::read_svg(&path, p);
|
||||
Self::read_geometry(&path, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn read_svg(path: &std::path::Path, p: &mut Paste) {
|
||||
fn read_geometry(path: &std::path::Path, p: &mut Paste) {
|
||||
use std::io::Read;
|
||||
let result = (|| {
|
||||
let mut text = String::new();
|
||||
|
|
@ -872,12 +875,12 @@ impl Editor {
|
|||
} else {
|
||||
ui.label(format!("Selected destinations: {}",p.targets.iter().map(|i|self.layout.layer_label(*i)).collect::<Vec<_>>().join(", ")));
|
||||
}
|
||||
ui.label("Paste Midra Layout values, draw.io clipboard data or SVG XML, or import SVG.");
|
||||
ui.label("Paste Midra Layout values or supported geometry data, or import a geometry file.");
|
||||
egui::ScrollArea::vertical().max_height((ctx.screen_rect().height()-360.0).max(150.0)).show(ui,|ui| {
|
||||
if ui.add(egui::TextEdit::multiline(&mut p.text).desired_rows(3).desired_width(f32::INFINITY)).changed() {p.shapes.clear();p.error.clear();}
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Read geometry").clicked() {p.parse();}
|
||||
if ui.button("Import SVG / draw.io…").clicked() && let Some(path)=rfd::FileDialog::new().add_filter("Layer geometry", &["svg", "drawio", "xml"]).pick_file() {Self::read_svg(&path,&mut p);}
|
||||
if ui.button("Import geometry file…").clicked() && let Some(path)=rfd::FileDialog::new().add_filter("Layer geometry", &["svg", "drawio", "xml", "json", "csv", "dxf", "html"]).pick_file() {Self::read_geometry(&path,&mut p);}
|
||||
});
|
||||
if !p.error.is_empty() {ui.colored_label(palette.amber,&p.error);}
|
||||
if p.shapes.is_empty() {return;}
|
||||
|
|
|
|||
|
|
@ -59,12 +59,32 @@ pub fn parse_values(text: &str) -> Result<ImportDocument, String> {
|
|||
if text.contains(" — visible box (device container unverified)") {
|
||||
return parse_midra_values(text);
|
||||
}
|
||||
if text.trim_start().starts_with('{') {
|
||||
if text.contains("\"beffroi.midra-geometry\"") {
|
||||
return crate::geometry_formats::parse_json(text);
|
||||
}
|
||||
return Err(
|
||||
"This JSON is not a geometry exchange. Use Open project for .midra.json files.".into(),
|
||||
);
|
||||
}
|
||||
if crate::geometry_formats::looks_like_csv(text) {
|
||||
return crate::geometry_formats::parse_csv(text);
|
||||
}
|
||||
if crate::geometry_formats::looks_like_dxf(text) {
|
||||
return crate::geometry_formats::parse_dxf(text);
|
||||
}
|
||||
if text.trim_start().starts_with('<')
|
||||
&& roxmltree::Document::parse_with_options(text, xml_options())
|
||||
.is_ok_and(|d| d.root_element().has_tag_name("svg"))
|
||||
{
|
||||
return parse_svg(text);
|
||||
}
|
||||
if text.trim_start().starts_with('<')
|
||||
&& roxmltree::Document::parse_with_options(text, xml_options())
|
||||
.is_ok_and(|d| d.root_element().has_tag_name("html"))
|
||||
{
|
||||
return crate::geometry_formats::parse_html(text);
|
||||
}
|
||||
Ok(ImportDocument {
|
||||
shapes: parse_drawio(text)?
|
||||
.into_iter()
|
||||
|
|
@ -264,7 +284,7 @@ fn hidden(node: Node) -> Result<bool, String> {
|
|||
Some("hidden" | "collapse")
|
||||
))
|
||||
}
|
||||
fn rectangle_points(mut points: Vec<[f64; 2]>) -> Result<Geometry, String> {
|
||||
pub(crate) fn rectangle_points(mut points: Vec<[f64; 2]>) -> Result<Geometry, String> {
|
||||
if points.len() == 5 && points.first() == points.last() {
|
||||
points.pop();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ pub mod device_send;
|
|||
use std::collections::HashMap;
|
||||
pub mod exchange;
|
||||
pub mod formats;
|
||||
mod geometry_formats;
|
||||
pub mod import;
|
||||
pub mod project;
|
||||
pub mod snapping;
|
||||
|
|
|
|||
|
|
@ -50,9 +50,9 @@ impl Editor {
|
|||
ui.separator();
|
||||
ui.weak("Layer values");
|
||||
self.transfer_layer_picker(ui, "Choose destination layers…");
|
||||
if ui.button("SVG / draw.io file…").clicked() {
|
||||
if ui.button("Geometry file…").clicked() {
|
||||
ui.close_menu();
|
||||
self.import_svg_file();
|
||||
self.import_geometry_file();
|
||||
}
|
||||
if ui
|
||||
.button("Clipboard values")
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ impl Editor {
|
|||
if ui.button("Copy settings path").clicked() { ctx.copy_text(path.display().to_string()); }
|
||||
} else { ui.label("No configuration location is available."); }
|
||||
ui.separator();
|
||||
ui.label("Project JSON stores layout, sources, crops and the reference picture. SVG exports layer geometry.");
|
||||
ui.label("Project JSON stores layout, sources, crops and the reference picture. Exchange exports store layer geometry.");
|
||||
ui.weak("Opening a project may restore its viewport options without rewriting your startup defaults.");
|
||||
if ui.button("Restore default settings").clicked() {
|
||||
let defaults = settings::Settings::default();
|
||||
|
|
|
|||
|
|
@ -232,20 +232,34 @@ impl Editor {
|
|||
ui.close_menu();
|
||||
}
|
||||
ui.separator();
|
||||
for format in [
|
||||
midra_layout::exchange::Format::Svg,
|
||||
midra_layout::exchange::Format::Drawio,
|
||||
] {
|
||||
for format in midra_layout::exchange::Format::ALL {
|
||||
ui.menu_button(format!("Export {}", format.label()), |ui| {
|
||||
self.exchange_menu(ui, format)
|
||||
});
|
||||
}
|
||||
}
|
||||
fn exchange_menu(&mut self, ui: &mut egui::Ui, format: midra_layout::exchange::Format) {
|
||||
ui.checkbox(&mut self.files.exchange_options.background, "Include background layer")
|
||||
.on_hover_text("Embed the visible reference image on a screen-sized background, or a plain backdrop when none is visible.");
|
||||
ui.checkbox(&mut self.files.exchange_options.placeholders, "Include placeholder pictures")
|
||||
.on_hover_text("Embed source-pattern pictures showing current cropping. These are placeholders, not live source captures.");
|
||||
ui.checkbox(
|
||||
&mut self.files.exchange_options.background,
|
||||
"Include background layer",
|
||||
)
|
||||
.on_hover_text(if format.supports_placeholders() {
|
||||
"Embed the visible reference image on a screen-sized background, or a plain backdrop when none is visible."
|
||||
} else {
|
||||
"Include a screen-sized background rectangle. This format cannot embed its picture."
|
||||
});
|
||||
ui.add_enabled(
|
||||
format.supports_placeholders(),
|
||||
egui::Checkbox::new(
|
||||
&mut self.files.exchange_options.placeholders,
|
||||
"Include placeholder pictures",
|
||||
),
|
||||
)
|
||||
.on_hover_text(if format.supports_placeholders() {
|
||||
"Embed source-pattern pictures showing current cropping. These are placeholders, not live source captures."
|
||||
} else {
|
||||
"This format carries rectangle geometry but cannot embed placeholder pictures."
|
||||
});
|
||||
ui.separator();
|
||||
let current = self.layout.selected().map(|i| self.layout.layer_info(i).id);
|
||||
if ui
|
||||
|
|
@ -294,7 +308,7 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
ui.small(
|
||||
"Round-trip layer boxes in screen pixels. JSON preserves full source/crop settings.",
|
||||
"Round-trip layer boxes in screen pixels. Project JSON preserves full source/crop settings.",
|
||||
);
|
||||
}
|
||||
fn export_exchange(
|
||||
|
|
@ -303,12 +317,11 @@ impl Editor {
|
|||
ids: &[usize],
|
||||
name: &str,
|
||||
) {
|
||||
match midra_layout::exchange::export(
|
||||
&self.project(),
|
||||
ids,
|
||||
format,
|
||||
self.files.exchange_options,
|
||||
) {
|
||||
let mut options = self.files.exchange_options;
|
||||
if !format.supports_placeholders() {
|
||||
options.placeholders = false;
|
||||
}
|
||||
match midra_layout::exchange::export(&self.project(), ids, format, options) {
|
||||
Ok(contents) => {
|
||||
if let Some(path) = rfd::FileDialog::new()
|
||||
.add_filter(format.label(), &[format.extension()])
|
||||
|
|
@ -387,14 +400,11 @@ impl Editor {
|
|||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn both_exchange_menus_offer_current_layer_and_shared_artwork_options() {
|
||||
fn all_exchange_menus_offer_current_layer_and_format_artwork_options() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = Editor::default();
|
||||
// Render the real submenu directly so file-dialog actions remain untouched.
|
||||
for format in [
|
||||
midra_layout::exchange::Format::Svg,
|
||||
midra_layout::exchange::Format::Drawio,
|
||||
] {
|
||||
for format in midra_layout::exchange::Format::ALL {
|
||||
let output = ctx.run(egui::RawInput::default(), |ctx| {
|
||||
egui::CentralPanel::default().show(ctx, |ui| app.exchange_menu(ui, format));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -41,16 +41,88 @@ fn template(resolution: [u32; 2]) -> Project {
|
|||
|
||||
#[test]
|
||||
fn readme_templates_match_the_exporter_and_contain_two_layers() {
|
||||
for (resolution, svg, drawio) in [
|
||||
for (resolution, documented) in [
|
||||
(
|
||||
[1920, 1080],
|
||||
include_str!("../../../docs/templates/midra-layout/midra-layout-1080p-2-layers.svg"),
|
||||
include_str!("../../../docs/templates/midra-layout/midra-layout-1080p-2-layers.drawio"),
|
||||
[
|
||||
(
|
||||
Format::Svg,
|
||||
include_str!(
|
||||
"../../../docs/templates/midra-layout/midra-layout-1080p-2-layers.svg"
|
||||
),
|
||||
),
|
||||
(
|
||||
Format::Drawio,
|
||||
include_str!(
|
||||
"../../../docs/templates/midra-layout/midra-layout-1080p-2-layers.drawio"
|
||||
),
|
||||
),
|
||||
(
|
||||
Format::Json,
|
||||
include_str!(
|
||||
"../../../docs/templates/midra-layout/midra-layout-1080p-2-layers.json"
|
||||
),
|
||||
),
|
||||
(
|
||||
Format::Csv,
|
||||
include_str!(
|
||||
"../../../docs/templates/midra-layout/midra-layout-1080p-2-layers.csv"
|
||||
),
|
||||
),
|
||||
(
|
||||
Format::Dxf,
|
||||
include_str!(
|
||||
"../../../docs/templates/midra-layout/midra-layout-1080p-2-layers.dxf"
|
||||
),
|
||||
),
|
||||
(
|
||||
Format::Html,
|
||||
include_str!(
|
||||
"../../../docs/templates/midra-layout/midra-layout-1080p-2-layers.html"
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
(
|
||||
[3840, 2160],
|
||||
include_str!("../../../docs/templates/midra-layout/midra-layout-4k-2-layers.svg"),
|
||||
include_str!("../../../docs/templates/midra-layout/midra-layout-4k-2-layers.drawio"),
|
||||
[
|
||||
(
|
||||
Format::Svg,
|
||||
include_str!(
|
||||
"../../../docs/templates/midra-layout/midra-layout-4k-2-layers.svg"
|
||||
),
|
||||
),
|
||||
(
|
||||
Format::Drawio,
|
||||
include_str!(
|
||||
"../../../docs/templates/midra-layout/midra-layout-4k-2-layers.drawio"
|
||||
),
|
||||
),
|
||||
(
|
||||
Format::Json,
|
||||
include_str!(
|
||||
"../../../docs/templates/midra-layout/midra-layout-4k-2-layers.json"
|
||||
),
|
||||
),
|
||||
(
|
||||
Format::Csv,
|
||||
include_str!(
|
||||
"../../../docs/templates/midra-layout/midra-layout-4k-2-layers.csv"
|
||||
),
|
||||
),
|
||||
(
|
||||
Format::Dxf,
|
||||
include_str!(
|
||||
"../../../docs/templates/midra-layout/midra-layout-4k-2-layers.dxf"
|
||||
),
|
||||
),
|
||||
(
|
||||
Format::Html,
|
||||
include_str!(
|
||||
"../../../docs/templates/midra-layout/midra-layout-4k-2-layers.html"
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
] {
|
||||
let project = template(resolution);
|
||||
|
|
@ -59,7 +131,7 @@ fn readme_templates_match_the_exporter_and_contain_two_layers() {
|
|||
.iter()
|
||||
.map(|layer| layer.id)
|
||||
.collect::<Vec<_>>();
|
||||
for (format, documented) in [(Format::Svg, svg), (Format::Drawio, drawio)] {
|
||||
for (format, documented) in documented {
|
||||
assert_eq!(
|
||||
exchange::export(&project, &ids, format, Options::default()).unwrap(),
|
||||
documented
|
||||
|
|
@ -86,9 +158,12 @@ fn readme_templates_match_the_exporter_and_contain_two_layers() {
|
|||
fn every_format_and_artwork_option_roundtrips_geometry_and_order() {
|
||||
let project = fixture();
|
||||
let ids: Vec<_> = project.layers.iter().map(|l| l.id).collect();
|
||||
for format in [Format::Svg, Format::Drawio] {
|
||||
for format in Format::ALL {
|
||||
for background in [false, true] {
|
||||
for placeholders in [false, true] {
|
||||
if placeholders && !format.supports_placeholders() {
|
||||
continue;
|
||||
}
|
||||
let text = exchange::export(
|
||||
&project,
|
||||
&ids,
|
||||
|
|
@ -99,6 +174,9 @@ fn every_format_and_artwork_option_roundtrips_geometry_and_order() {
|
|||
},
|
||||
)
|
||||
.unwrap();
|
||||
if format.supports_placeholders() && (background || placeholders) {
|
||||
assert!(text.contains("iVBOR"), "missing embedded PNG in {format:?}");
|
||||
}
|
||||
let doc = parse_values(&text).unwrap();
|
||||
assert_eq!(
|
||||
doc.shapes.iter().filter(|s| s.background_only).count(),
|
||||
|
|
@ -157,8 +235,11 @@ fn single_full_screen_layer_is_never_mistaken_for_background() {
|
|||
width: 1920.0,
|
||||
height: 1080.0,
|
||||
};
|
||||
for format in [Format::Svg, Format::Drawio] {
|
||||
for format in Format::ALL {
|
||||
for placeholders in [false, true] {
|
||||
if placeholders && !format.supports_placeholders() {
|
||||
continue;
|
||||
}
|
||||
let text = exchange::export(
|
||||
&p,
|
||||
&[p.layers[0].id],
|
||||
|
|
@ -258,6 +339,45 @@ fn reference_image_is_embedded_and_missing_ids_or_invalid_versions_fail() {
|
|||
assert!(parse_values("<mxfile><diagram>garbage</diagram></mxfile>").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_text_adapters_reject_wrong_versions_canvases_and_non_rectangles() {
|
||||
let project = template([1920, 1080]);
|
||||
let ids = project
|
||||
.layers
|
||||
.iter()
|
||||
.map(|layer| layer.id)
|
||||
.collect::<Vec<_>>();
|
||||
assert!(
|
||||
exchange::export(
|
||||
&project,
|
||||
&ids,
|
||||
Format::Csv,
|
||||
Options {
|
||||
background: false,
|
||||
placeholders: true,
|
||||
},
|
||||
)
|
||||
.unwrap_err()
|
||||
.contains("cannot embed")
|
||||
);
|
||||
|
||||
let json = exchange::export(&project, &ids, Format::Json, Options::default()).unwrap();
|
||||
assert!(parse_values(&json.replace("\"version\": 1", "\"version\": 2")).is_err());
|
||||
|
||||
let csv = exchange::export(&project, &ids, Format::Csv, Options::default()).unwrap();
|
||||
let inconsistent = csv.replacen("1,1920,1080,layer-1", "1,3840,1080,layer-1", 1);
|
||||
assert!(parse_values(&inconsistent).is_err());
|
||||
|
||||
let html = exchange::export(&project, &ids, Format::Html, Options::default()).unwrap();
|
||||
assert!(
|
||||
parse_values(&html.replace("data-midra-role=\"layer\"", "data-midra-role=\"guide\""))
|
||||
.is_err()
|
||||
);
|
||||
|
||||
let dxf = exchange::export(&project, &ids, Format::Dxf, Options::default()).unwrap();
|
||||
assert!(parse_values(&dxf.replacen("70\r\n1\r\n", "70\r\n0\r\n", 1)).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn documented_examples_import_and_limits_are_enforced() {
|
||||
for text in [
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
# Midra Layout SVG and draw.io exchange
|
||||
# Midra Layout geometry exchange
|
||||
|
||||
The Export menu writes **SVG geometry v2** and **draw.io geometry v1**. Project
|
||||
The Export menu writes **SVG v2**, **draw.io v1**, **geometry JSON v1**,
|
||||
**geometry CSV v1**, **DXF** and **HTML/CSS v1**. Project
|
||||
JSON remains version 9 and is the full-fidelity save format. These exchanges
|
||||
preserve layer **visible-box geometry**, not sources, crop settings, zoom, pivots,
|
||||
Midra links, locks, visibility, camera or selection. Pictures illustrate current
|
||||
|
|
@ -8,16 +9,33 @@ cropping; importing a picture does not reconstruct its crop or source settings.
|
|||
|
||||
Ready-to-open two-layer templates are published under
|
||||
`docs/templates/midra-layout/` for Full HD (1920 × 1080) and UHD 4K
|
||||
(3840 × 2160), in both SVG v2 and draw.io v1. The 4K geometry is an exact 2×
|
||||
scale of the Full HD layout. Regenerate them with:
|
||||
(3840 × 2160), in every supported exchange format. The 4K geometry is an exact
|
||||
2× scale of the Full HD layout. Regenerate them with:
|
||||
|
||||
```sh
|
||||
cargo run --locked -p midra-layout --example check_geometry_exchange -- templates docs/templates/midra-layout
|
||||
```
|
||||
|
||||
## Application and format matrix
|
||||
|
||||
| Workflow | Exchange format | Import/export | Background | Placeholder pictures |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| Inkscape, Illustrator, Affinity Designer, Figma, web vector tools | SVG | Yes | Embedded PNG | Embedded PNG |
|
||||
| diagrams.net / draw.io | draw.io XML | Yes | Embedded PNG | Embedded PNG |
|
||||
| Scripts, automation and future adapters | Geometry JSON | Yes | Embedded PNG | Embedded PNG |
|
||||
| Excel, LibreOffice Calc and data tools | Geometry CSV | Yes | Geometry row | No |
|
||||
| AutoCAD, LibreCAD and QCAD | DXF | Yes | Rectangle entity | No |
|
||||
| Browsers and web layout tools | HTML/CSS | Yes | Embedded PNG | Embedded PNG |
|
||||
|
||||
Native AI, PSD, Figma, VSDX, PPTX and ODG project files are intentionally not
|
||||
separate adapters: they are proprietary or application documents, while those
|
||||
applications can consume SVG. PDF is a useful final visual but does not retain a
|
||||
reliable editable-rectangle contract for import, so it is not presented as a
|
||||
round-trip format.
|
||||
|
||||
## Scope, coordinates and artwork
|
||||
|
||||
Both formats offer Current layer (exactly one selected), Selected layers,
|
||||
All formats offer Current layer (exactly one selected), Selected layers,
|
||||
Specific layer (including hidden), All layers and Visible layers only. Stable IDs
|
||||
are `layer-N`; order is document stacking order, independent of selection order.
|
||||
All chosen layers are exported visibly, even if hidden in the editor. No layers,
|
||||
|
|
@ -27,22 +45,25 @@ screen**, including for single-layer exports. X, Y, width and height round
|
|||
independently to nearest integer; halves round away from zero. Negative positions
|
||||
are retained. No stroke expansion is necessary: exported boxes have no outline.
|
||||
|
||||
Options are shared by the SVG/draw.io menus for the current session, default off;
|
||||
Options are shared by the format menus for the current session, default off;
|
||||
they do not modify the project/settings schema:
|
||||
|
||||
- **Include background layer** adds a first, full-screen image with ID
|
||||
`midra-background`, explicitly marked as background. A visible reference is
|
||||
composited over a dark backdrop using the current fit/stretch/native-size,
|
||||
offset and opacity. Otherwise it is a plain dark backdrop. This is a baked visual
|
||||
reference, not an editable copy of reference settings. Image raster dimensions
|
||||
are proportional to the screen, capped at 1920 pixels on the longest side;
|
||||
the exported shape still has the exact screen dimensions.
|
||||
- **Include background layer** adds a first, full-screen shape with ID
|
||||
`midra-background`, explicitly marked as background. SVG, draw.io, JSON and HTML
|
||||
embed a visible reference composited over a dark backdrop using the current
|
||||
fit/stretch/native-size, offset and opacity; otherwise they embed a plain dark
|
||||
backdrop. This is a baked visual reference, not an editable copy of reference
|
||||
settings. Image raster dimensions are proportional to the screen, capped at
|
||||
1920 pixels on the longest side; the exported shape still has the exact screen
|
||||
dimensions. CSV and DXF carry only the background rectangle.
|
||||
- **Include placeholder pictures** uses embedded PNG source-grid patterns instead
|
||||
of flat layer fills. The pattern reflects native input cropping and advanced
|
||||
cropping, fitted into each visible box. Each raster is capped at 512 pixels on
|
||||
its longest side. No live source image is available/captured by this exporter.
|
||||
The images contain no external URLs and need no network access. Imported picture
|
||||
layers are still geometry-only. Without this option, the layers are rectangles.
|
||||
CSV and DXF disable this option because they cannot embed self-contained raster
|
||||
pictures in the supported profile.
|
||||
|
||||
The background is detected and ignored by default on import and cannot be mapped
|
||||
as a content layer. A legitimate full-screen layer is kept as a layer. Every
|
||||
|
|
@ -96,6 +117,53 @@ instruction to export one page, rather than silently importing the wrong page.
|
|||
Groups, edges, rotation, flips, relative/alternate bounds and nonrectangular
|
||||
shapes remain unsupported; ordinary unrotated image cells now import their box.
|
||||
|
||||
## Geometry JSON v1
|
||||
|
||||
UTF-8 JSON with root fields `format: "beffroi.midra-geometry"`, `version: 1`,
|
||||
`units: "px"`, `canvas: {width,height}` and `layers`. Each layer has `id`, `name`,
|
||||
`role`, `x`, `y`, `width` and `height`; `image_png_base64` is optional. Roles are
|
||||
`layer` or `background`. Unknown fields, versions and units are rejected. IDs
|
||||
must be unique and at most 255 characters; names are limited to 1024 characters
|
||||
without controls. This JSON is the preferred small machine interface. It is not
|
||||
the version-9 project save file and does not contain sources, crop or device links.
|
||||
|
||||
## Geometry CSV v1
|
||||
|
||||
RFC 4180 CSV with CRLF records and this fixed header:
|
||||
|
||||
```text
|
||||
midra_geometry_version,canvas_width,canvas_height,id,name,role,x,y,width,height
|
||||
```
|
||||
|
||||
Every row repeats version `1` and the same canvas so a selected row remains
|
||||
self-describing. Names use normal CSV quoting. Roles and geometry have the same
|
||||
meaning as JSON. Empty files, mismatched canvases, extra/missing fields and
|
||||
non-integer geometry are rejected. CSV carries background geometry but no image
|
||||
data or placeholder pictures.
|
||||
|
||||
## DXF profile
|
||||
|
||||
UTF-8 ASCII DXF declares `AC1021` (AutoCAD 2007), unitless `$INSUNITS=0`, and
|
||||
whole-pixel `$LIMMIN`/`$LIMMAX` canvas bounds (with matching initial extents).
|
||||
Every stable ID has a layer-table entry and every shape is one closed,
|
||||
four-vertex `LWPOLYLINE`; its DXF layer name is the stable Midra layer ID.
|
||||
Because CAD Y increases upward, export writes `cad_y = canvas_height - screen_y`
|
||||
and import reverses that conversion. The `midra-background` entity is ignored as
|
||||
background. DXF cannot embed the supported self-contained placeholder artwork;
|
||||
human names are comments and may be discarded by CAD re-saving. Import requires
|
||||
explicit extents and axis-aligned closed rectangles rather than guessing scale,
|
||||
units or page origin.
|
||||
|
||||
## HTML/CSS v1
|
||||
|
||||
The XHTML-compatible document is a directly viewable page. Root
|
||||
`data-midra-layout-geometry="1"` marks the version; `#midra-canvas` stores
|
||||
`data-width`/`data-height`. Each `<div>` or `<img>` stores authoritative
|
||||
`data-midra-role`, `data-name`, `data-x`, `data-y`, `data-width` and
|
||||
`data-height`; inline CSS renders the same box. Images use self-contained PNG data
|
||||
URLs. Import reads the data attributes, not computed CSS, scripts or browser
|
||||
layout. The file contains no script or external resource.
|
||||
|
||||
## Limits, import and round trips
|
||||
|
||||
Import files and clipboard text, and generated exports, are capped at **16 MiB**
|
||||
|
|
@ -105,7 +173,7 @@ background are allowed. No imported image is decoded or downloaded by the
|
|||
geometry importer. Export reference decoding retains the existing 8192-pixel
|
||||
per-side/256 MiB decoder bounds. Oversized exports fail before writing a file.
|
||||
|
||||
Use **Import → SVG / draw.io file…**, or paste XML, then review and map shapes to
|
||||
Use **Import → Geometry file…**, or paste supported text, then review and map shapes to
|
||||
editor layers. Destination count need not match current selection. Import with
|
||||
size and position enabled restores the rounded geometry in one Undo step. Output
|
||||
screen resolution is not imported. Mapped names, sources and Midra links stay with
|
||||
|
|
@ -126,7 +194,8 @@ the only positions present in that SVG. Include Midra Layout's background layer
|
|||
before exporting through draw.io when the full output-screen origin must survive
|
||||
the round trip.
|
||||
|
||||
Tests cover each format/artwork combination, full-screen layers vs backgrounds,
|
||||
Tests cover each format/artwork combination, all twelve published templates,
|
||||
full-screen layers vs backgrounds,
|
||||
negative/fractional coordinates, repeat round trips, compressed clipboard/files,
|
||||
embedded references, invalid IDs/versions and no-overwrite file handling.
|
||||
A manual native-editor check is available:
|
||||
|
|
@ -148,4 +217,6 @@ background preserved the page. Generated plain/illustrated SVG and draw.io files
|
|||
passed geometry verification. Native output artifacts remain in `/tmp`, not Git.
|
||||
|
||||
Protocol references: [draw.io diagram format](https://www.drawio.com/docs/reference/diagram-generation/)
|
||||
and [desktop CLI](https://github.com/jgraph/drawio/wiki/Desktop-App).
|
||||
and [desktop CLI](https://github.com/jgraph/drawio/wiki/Desktop-App),
|
||||
[SVG 2](https://www.w3.org/TR/SVG/), [CSV RFC 4180](https://datatracker.ietf.org/doc/rfc4180/),
|
||||
and Autodesk's [DXF group-code reference](https://help.autodesk.com/cloudhelp/2025/ENU/AutoCAD-DXF/files/GUID-89CB823D-614D-4D1E-8204-568EC72DF869.htm).
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ not a named project export. Headless/default editors never access this path.
|
|||
| --- | --- |
|
||||
| `version` | Integer `1`; other versions rejected |
|
||||
| `project` | Complete [project v9](midra-layout.md), including embedded reference bytes; its units, precision and validation apply without display rounding |
|
||||
| `project_path` | Last opened/successfully saved named JSON path, or null; SVG exports do not change it |
|
||||
| `project_path` | Last opened/successfully saved named JSON path, or null; geometry exports do not change it |
|
||||
| `manual_saved_at` | Unix UTC seconds of the last successful explicit project save, or null when unknown; recovery and measurement-point autosaves do not update it |
|
||||
|
||||
Unknown envelope fields and files over 100 MiB are rejected. Project validation
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ clicks and the independent-point toggle are an exception: they reread the curren
|
|||
project and atomically update only `editor.position_point` and
|
||||
`editor.position_layer_point`, preserving its other stored values (including external edits).
|
||||
Older schemas migrate to v9 on this write. No project path is stored in settings;
|
||||
new documents require a first Save. SVG exports never change the active project path.
|
||||
new documents require a first Save. Geometry exports never change the active project path.
|
||||
Missing/invalid/unwritable projects are left untouched and an error is shown;
|
||||
active in-memory choices remain available for a manual Save. A failed no-overwrite write
|
||||
leaves the existing file intact.
|
||||
|
|
@ -139,7 +139,7 @@ leaves the existing file intact.
|
|||
Add/remove/rename, reordering and folder edits are undoable. Device mappings are not implied
|
||||
by editor IDs. Selection stores stable layer IDs, not zero-based indices. At
|
||||
least one layer must remain. Visibility and locks remain local protection flags and are undoable.
|
||||
SVG export supports all, visible-only, explicit specific-layer (including hidden)
|
||||
Geometry export supports all, visible-only, explicit specific-layer (including hidden)
|
||||
or selected layers (including a single
|
||||
layer); rectangles retain stable IDs and document stacking order. Names appear as titles/labels in current geometry exchanges; folders are omitted.
|
||||
|
||||
|
|
@ -192,14 +192,14 @@ and `viewBox="0 0 W H"` equal to the output screen. The root carries
|
|||
|
||||
## Compatibility changes
|
||||
|
||||
Project version 9 and the versioned SVG/draw.io exchanges are strict contracts. A breaking project field/meaning change must bump
|
||||
Project version 9 and the versioned geometry exchanges are strict contracts. A breaking project field/meaning change must bump
|
||||
`version` and either implement a tested migration or clearly reject older/newer
|
||||
files. Changing rectangle/marker semantics requires a corresponding documented
|
||||
SVG interface revision and importer tests. Update this document and its example
|
||||
exchange-interface revision and importer tests. Update this document and its example
|
||||
with every schema or semantic change, including additive fields under the strict
|
||||
unknown-field policy. Never silently interpret a future version as a supported version.
|
||||
|
||||
Midra links belong to layer identity and survive selection changes, refresh, rename, reorder and project round trips. Link edits support Undo/Redo. New layers and older projects start unlinked. Links refer to the currently connected device; Preview/Program and sizing remain session choices, and Program permission remains an application preference. Duplicate destinations can be stored, but a send containing duplicates is rejected before any writes. Unavailable screens/layers are reported without deleting the saved links. SVG exports geometry only and omits links.
|
||||
Midra links belong to layer identity and survive selection changes, refresh, rename, reorder and project round trips. Link edits support Undo/Redo. New layers and older projects start unlinked. Links refer to the currently connected device; Preview/Program and sizing remain session choices, and Program permission remains an application preference. Duplicate destinations can be stored, but a send containing duplicates is rejected before any writes. Unavailable screens/layers are reported without deleting the saved links. Geometry exports omit links.
|
||||
|
||||
Midra destinations are identified by the pair **screen ID + layer ID**: Screen 1
|
||||
Layer 1 and Screen 2 Layer 1 are distinct links. Both IDs are already persisted
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ python3 tools/midra_probe.py --host DEVICE_IP --screen 2 --layers 1 2 --svg /tmp
|
|||
python3 tools/midra_probe.py --snapshot /tmp/eikos-state.json --screen 2 --layers 1 2 --svg /tmp/replay.svg
|
||||
```
|
||||
|
||||
Select the matching number of editor layers, choose **Import SVG**, and review
|
||||
Select the matching number of editor layers, choose **Import → Geometry file…**, and review
|
||||
mapping before applying. Match the editor output resolution to the device canvas;
|
||||
SVG geometry import does not replace the editor's screen settings.
|
||||
The helper exports **container geometry only**: center minus half-size becomes
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ from a different Midra generation's documentation. Working name: **Midra Layout*
|
|||
|
||||
The offline editor now includes source/input/layer formats and cropping, all eight
|
||||
layer and crop handles, multi-selection/group resizing/alignment, reference import,
|
||||
draw.io/native/SVG paste with review, JSON project save/load, SVG all/visible export,
|
||||
draw.io/native/SVG and open geometry formats with review, JSON project save/load,
|
||||
six-format geometry export,
|
||||
19 bundled themes, recent-theme history and persistent application preferences.
|
||||
A full Settings window and optional movement snapping with guides/Alt bypass
|
||||
are implemented. Project save/load and theme preferences are no longer future work.
|
||||
|
|
@ -525,7 +526,7 @@ and Centered-crop import round trips passed Eikos 3.3.10 hardware checks.
|
|||
- Non-Centered aspects, masks and source routing/shared input synchronization are
|
||||
outside the implemented crop adapter. Local input correction is combined into
|
||||
the destination's layer crop; no shared input setting is changed.
|
||||
- Native clipboard adapters beyond text/SVG/draw.io need actual application/version
|
||||
- Native clipboard adapters beyond the documented text formats need actual application/version
|
||||
samples; no undocumented Illustrator/Inkscape clipboard compatibility is claimed.
|
||||
- Operator-platform acceptance (Windows/macOS, DPI, GPU presentation) and release
|
||||
packaging remain separate from the Linux native UI and headless timing checks.
|
||||
|
|
@ -534,12 +535,11 @@ and Centered-crop import round trips passed Eikos 3.3.10 hardware checks.
|
|||
|
||||
## Pending stretch goals — specifications to follow
|
||||
|
||||
- [ ] **More software export/import formats.** Extend the SVG/draw.io exchange to
|
||||
additional graphics and layout applications (for example Inkscape/Illustrator
|
||||
workflows and other formats as specified). For each adapter, define supported
|
||||
geometry, optional background and placeholder-image capabilities, and validate
|
||||
round trips through the target application. Document losses and versioned
|
||||
interfaces; unsupported image features should be unavailable rather than implied.
|
||||
- [x] **More software export/import formats.** SVG/draw.io, geometry JSON/CSV,
|
||||
DXF and HTML/CSS have documented import/export adapters, artwork capabilities,
|
||||
round-trip tests and Full HD/UHD templates. Inkscape, Illustrator, Affinity and
|
||||
Figma use SVG; CAD tools use DXF; spreadsheets use CSV. Proprietary native
|
||||
project formats and PDF are explicitly outside the reliable geometry contract.
|
||||
|
||||
|
||||
- [ ] **Capture Midra input preview images.** Capture a still preview from a chosen
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
A native Rust/egui workspace for positioning rectangular layers, with offline editing
|
||||
and an explicit Eikos 4K device link.
|
||||
Select layers, paste or import draw.io/SVG geometry, move them visually or enter exact corner
|
||||
Select layers, paste or import supported geometry, move them visually or enter exact corner
|
||||
positions and dimensions. Configure source/input formats and content framing;
|
||||
visible-box coordinates and provisional crop calculations update together.
|
||||
Connection reads and reviewed device sends happen only on request.
|
||||
|
|
@ -13,15 +13,16 @@ Connection reads and reviewed device sends happen only on request.
|
|||
cargo run --locked -p midra-layout
|
||||
```
|
||||
|
||||
## Paste layer values and import SVG / draw.io
|
||||
## Paste layer values and import geometry
|
||||
|
||||
1. Choose destinations using **Choose destination layers…** in the Import menu
|
||||
or review window. Selecting them on the canvas or right-hand list also works
|
||||
(Shift-click for multiple layers).
|
||||
2. Copy layer values in Midra Layout or rectangles in draw.io, then press **Ctrl/Cmd-V** with the viewport
|
||||
focused. Alternatively, click **Paste layer(s) values**, paste into the text
|
||||
area and click **Read geometry**. **Import → SVG / draw.io file…** opens an SVG or draw.io file in the
|
||||
same review window; raw SVG/draw.io XML can also be pasted. **Import → Clipboard values**
|
||||
area and click **Read geometry**. **Import → Geometry file…** opens SVG, draw.io,
|
||||
geometry JSON/CSV, DXF or HTML in the same review window; supported text can
|
||||
also be pasted. **Import → Clipboard values**
|
||||
reads the clipboard directly and opens the mapping review.
|
||||
3. Review each detected rectangle and choose its destination layer. With nothing
|
||||
selected, each rectangle's dropdown lists all editor layers (hidden/locked
|
||||
|
|
@ -552,17 +553,17 @@ viewport preferences, and the embedded reference image. Apply pending edits
|
|||
before saving. Opening asks before replacing current work and starts a fresh
|
||||
undo history. Existing files require confirmation before replacement.
|
||||
|
||||
The root README links ready-to-open SVG and draw.io templates with two layers
|
||||
for 1920 × 1080 and 3840 × 2160 output canvases.
|
||||
The root README links ready-to-open templates in every exchange format, with two
|
||||
layers for 1920 × 1080 and 3840 × 2160 output canvases.
|
||||
|
||||
**Project → Export → Export SVG / Export draw.io** offers **Current layer…**,
|
||||
Each format under **Project → Export** offers **Current layer…**,
|
||||
**Selected layers…**, **Specific layer…**, **All layers…** and **Visible layers
|
||||
only…**. A current-layer export keeps its original screen position and full-screen
|
||||
canvas. Both menus offer **Include background layer** (visible reference or plain
|
||||
backdrop) and **Include placeholder pictures** (source-grid imagery reflecting
|
||||
cropping). Images are embedded and require no external files.
|
||||
canvas. Every menu offers **Include background layer**. SVG, draw.io, geometry
|
||||
JSON and HTML also offer **Include placeholder pictures** with embedded source-grid
|
||||
imagery; CSV and DXF explicitly disable pictures and carry rectangle geometry.
|
||||
|
||||
Import either format with **Import → SVG / draw.io file…** or paste its XML, then
|
||||
Import a supported format with **Import → Geometry file…** or paste its text, then
|
||||
map detected layers to destinations. Backgrounds are automatically ignored;
|
||||
placeholder images each count as one layer. draw.io files saved with compression
|
||||
are supported. SVG rendered by draw.io Desktop is recognized through its retained
|
||||
|
|
@ -618,7 +619,7 @@ Closing the picker without choosing leaves the theme and history unchanged.
|
|||
The viewport, grid, layer boxes and source test patterns use the selected palette;
|
||||
selected layers remain gold (darker gold for contrast in light themes). Imported
|
||||
reference images retain their colors. Theme and history survive opening projects
|
||||
and are not included in project JSON or SVG exports.
|
||||
and are not included in project JSON or geometry exports.
|
||||
|
||||
The SOTV palettes are bundled with the app from
|
||||
`sotv/song_database/styles/themes/` in the sibling `SOTV_Websites` repository;
|
||||
|
|
@ -734,7 +735,7 @@ movement, alignment and Same-handles resizing work across the selection;
|
|||
Mirror/Opposite resizing still require exactly two layers.
|
||||
|
||||
Project JSON is version 9, with tested migration from older supported versions.
|
||||
**Project → Export → Export SVG → Selected layers…** exports just the current selection,
|
||||
Every format’s **Selected layers…** action exports just the current selection,
|
||||
including a single layer. All/visible export remains available.
|
||||
|
||||
## Reference placement and loading
|
||||
|
|
@ -759,7 +760,7 @@ appear only when the resulting handle reaches the target; crop-content gestures
|
|||
remain unsnapped. At 2 logical pixels per screen pixel, adaptive coordinate rulers
|
||||
appear; at 8, a pixel grid appears. Guide drawing is limited to the visible region.
|
||||
|
||||
SVG export also offers **Specific layer…**, listing every local layer, including
|
||||
Every exchange format also offers **Specific layer…**, listing every local layer, including
|
||||
hidden/locked layers. Choosing one explicitly exports its geometry without
|
||||
changing visibility or selection. No device mapping or send is implied.
|
||||
|
||||
|
|
@ -781,12 +782,12 @@ OS/DPI behavior or performance on an operator laptop. It is not a release gate.
|
|||
You can choose layers without returning to the viewport:
|
||||
|
||||
- **Import → Choose destination layers…**, and the same picker inside the
|
||||
clipboard/SVG review, select the destinations. Paste and SVG import can open
|
||||
geometry review, select the destinations. Paste and file import can open
|
||||
with nothing selected: map each detected rectangle directly to an available
|
||||
layer using its destination dropdown. When using a selection, there must be at least as many chosen destinations as imported rectangles
|
||||
after ignoring an SVG background. Map to any subset of them; other layers stay
|
||||
after ignoring a background. Map to any subset of them; other layers stay
|
||||
unchanged. Duplicate mappings and empty imports remain invalid.
|
||||
- **Project → Export → Export SVG → Choose layers to export…** selects the group for
|
||||
- A format’s **Choose layers to export…** selects the group for
|
||||
**Selected layers…**. **Specific layer…** remains available for individual layers,
|
||||
including hidden layers.
|
||||
- Midra send preparation has **Choose editor layers to send…**, followed by a
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Add versioned geometry JSON, RFC-style CSV, DXF and HTML/CSS import/export alongside SVG and draw.io. All six formats have two-layer Full HD/UHD templates and round-trip tests; artwork support is explicit per format.
|
||||
|
||||
- Add README-linked two-layer SVG and draw.io templates for Full HD and UHD 4K, generated by the application exporter and checked byte-for-byte in regression tests.
|
||||
|
||||
- Import SVG rendered by draw.io Desktop, including its SVG 1.1 DOCTYPE, nested cell wrappers, symbol/image layers and generated label fallbacks. A background-preserved native 31.7.0 round trip was checked; draw.io's cropped SVG exports necessarily retain their rebased coordinates.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
midra_geometry_version,canvas_width,canvas_height,id,name,role,x,y,width,height
|
||||
1,1920,1080,layer-2,Slides,layer,120,180,640,360
|
||||
1,1920,1080,layer-1,Presenter,layer,1160,180,640,360
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
999
|
||||
MIDRA_LAYOUT_GEOMETRY 1
|
||||
0
|
||||
SECTION
|
||||
2
|
||||
HEADER
|
||||
9
|
||||
$ACADVER
|
||||
1
|
||||
AC1021
|
||||
9
|
||||
$INSUNITS
|
||||
70
|
||||
0
|
||||
9
|
||||
$EXTMIN
|
||||
10
|
||||
0
|
||||
20
|
||||
0
|
||||
9
|
||||
$EXTMAX
|
||||
10
|
||||
1920
|
||||
20
|
||||
1080
|
||||
9
|
||||
$LIMMIN
|
||||
10
|
||||
0
|
||||
20
|
||||
0
|
||||
9
|
||||
$LIMMAX
|
||||
10
|
||||
1920
|
||||
20
|
||||
1080
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
SECTION
|
||||
2
|
||||
TABLES
|
||||
0
|
||||
TABLE
|
||||
2
|
||||
LAYER
|
||||
70
|
||||
2
|
||||
0
|
||||
LAYER
|
||||
2
|
||||
layer-2
|
||||
70
|
||||
0
|
||||
62
|
||||
4
|
||||
6
|
||||
CONTINUOUS
|
||||
0
|
||||
LAYER
|
||||
2
|
||||
layer-1
|
||||
70
|
||||
0
|
||||
62
|
||||
5
|
||||
6
|
||||
CONTINUOUS
|
||||
0
|
||||
ENDTAB
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
999
|
||||
NAME Slides
|
||||
0
|
||||
LWPOLYLINE
|
||||
8
|
||||
layer-2
|
||||
90
|
||||
4
|
||||
70
|
||||
1
|
||||
10
|
||||
120
|
||||
20
|
||||
900
|
||||
10
|
||||
760
|
||||
20
|
||||
900
|
||||
10
|
||||
760
|
||||
20
|
||||
540
|
||||
10
|
||||
120
|
||||
20
|
||||
540
|
||||
999
|
||||
NAME Presenter
|
||||
0
|
||||
LWPOLYLINE
|
||||
8
|
||||
layer-1
|
||||
90
|
||||
4
|
||||
70
|
||||
1
|
||||
10
|
||||
1160
|
||||
20
|
||||
900
|
||||
10
|
||||
1800
|
||||
20
|
||||
900
|
||||
10
|
||||
1800
|
||||
20
|
||||
540
|
||||
10
|
||||
1160
|
||||
20
|
||||
540
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" data-midra-layout-geometry="1"><head><meta charset="utf-8"/><title>Midra Layout geometry</title><style>html,body{margin:0} #midra-canvas{position:relative;width:1920px;height:1080px;background:#122531;overflow:hidden} .midra-layer{position:absolute;box-sizing:border-box;background:#173b50;color:white;display:flex;align-items:center;justify-content:center;font:16px sans-serif} img.midra-layer{object-fit:fill}</style></head><body><main id="midra-canvas" data-width="1920" data-height="1080">
|
||||
<div id="layer-2" class="midra-layer" data-midra-role="layer" data-name="Slides" data-x="120" data-y="180" data-width="640" data-height="360" style="left:120px;top:180px;width:640px;height:360px">Slides</div>
|
||||
<div id="layer-1" class="midra-layer" data-midra-role="layer" data-name="Presenter" data-x="1160" data-y="180" data-width="640" data-height="360" style="left:1160px;top:180px;width:640px;height:360px">Presenter</div>
|
||||
</main></body></html>
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"format": "beffroi.midra-geometry",
|
||||
"version": 1,
|
||||
"units": "px",
|
||||
"canvas": {
|
||||
"width": 1920,
|
||||
"height": 1080
|
||||
},
|
||||
"layers": [
|
||||
{
|
||||
"id": "layer-2",
|
||||
"name": "Slides",
|
||||
"role": "layer",
|
||||
"x": 120,
|
||||
"y": 180,
|
||||
"width": 640,
|
||||
"height": 360
|
||||
},
|
||||
{
|
||||
"id": "layer-1",
|
||||
"name": "Presenter",
|
||||
"role": "layer",
|
||||
"x": 1160,
|
||||
"y": 180,
|
||||
"width": 640,
|
||||
"height": 360
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
midra_geometry_version,canvas_width,canvas_height,id,name,role,x,y,width,height
|
||||
1,3840,2160,layer-2,Slides,layer,240,360,1280,720
|
||||
1,3840,2160,layer-1,Presenter,layer,2320,360,1280,720
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
999
|
||||
MIDRA_LAYOUT_GEOMETRY 1
|
||||
0
|
||||
SECTION
|
||||
2
|
||||
HEADER
|
||||
9
|
||||
$ACADVER
|
||||
1
|
||||
AC1021
|
||||
9
|
||||
$INSUNITS
|
||||
70
|
||||
0
|
||||
9
|
||||
$EXTMIN
|
||||
10
|
||||
0
|
||||
20
|
||||
0
|
||||
9
|
||||
$EXTMAX
|
||||
10
|
||||
3840
|
||||
20
|
||||
2160
|
||||
9
|
||||
$LIMMIN
|
||||
10
|
||||
0
|
||||
20
|
||||
0
|
||||
9
|
||||
$LIMMAX
|
||||
10
|
||||
3840
|
||||
20
|
||||
2160
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
SECTION
|
||||
2
|
||||
TABLES
|
||||
0
|
||||
TABLE
|
||||
2
|
||||
LAYER
|
||||
70
|
||||
2
|
||||
0
|
||||
LAYER
|
||||
2
|
||||
layer-2
|
||||
70
|
||||
0
|
||||
62
|
||||
4
|
||||
6
|
||||
CONTINUOUS
|
||||
0
|
||||
LAYER
|
||||
2
|
||||
layer-1
|
||||
70
|
||||
0
|
||||
62
|
||||
5
|
||||
6
|
||||
CONTINUOUS
|
||||
0
|
||||
ENDTAB
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
SECTION
|
||||
2
|
||||
ENTITIES
|
||||
999
|
||||
NAME Slides
|
||||
0
|
||||
LWPOLYLINE
|
||||
8
|
||||
layer-2
|
||||
90
|
||||
4
|
||||
70
|
||||
1
|
||||
10
|
||||
240
|
||||
20
|
||||
1800
|
||||
10
|
||||
1520
|
||||
20
|
||||
1800
|
||||
10
|
||||
1520
|
||||
20
|
||||
1080
|
||||
10
|
||||
240
|
||||
20
|
||||
1080
|
||||
999
|
||||
NAME Presenter
|
||||
0
|
||||
LWPOLYLINE
|
||||
8
|
||||
layer-1
|
||||
90
|
||||
4
|
||||
70
|
||||
1
|
||||
10
|
||||
2320
|
||||
20
|
||||
1800
|
||||
10
|
||||
3600
|
||||
20
|
||||
1800
|
||||
10
|
||||
3600
|
||||
20
|
||||
1080
|
||||
10
|
||||
2320
|
||||
20
|
||||
1080
|
||||
0
|
||||
ENDSEC
|
||||
0
|
||||
EOF
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" data-midra-layout-geometry="1"><head><meta charset="utf-8"/><title>Midra Layout geometry</title><style>html,body{margin:0} #midra-canvas{position:relative;width:3840px;height:2160px;background:#122531;overflow:hidden} .midra-layer{position:absolute;box-sizing:border-box;background:#173b50;color:white;display:flex;align-items:center;justify-content:center;font:16px sans-serif} img.midra-layer{object-fit:fill}</style></head><body><main id="midra-canvas" data-width="3840" data-height="2160">
|
||||
<div id="layer-2" class="midra-layer" data-midra-role="layer" data-name="Slides" data-x="240" data-y="360" data-width="1280" data-height="720" style="left:240px;top:360px;width:1280px;height:720px">Slides</div>
|
||||
<div id="layer-1" class="midra-layer" data-midra-role="layer" data-name="Presenter" data-x="2320" data-y="360" data-width="1280" data-height="720" style="left:2320px;top:360px;width:1280px;height:720px">Presenter</div>
|
||||
</main></body></html>
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"format": "beffroi.midra-geometry",
|
||||
"version": 1,
|
||||
"units": "px",
|
||||
"canvas": {
|
||||
"width": 3840,
|
||||
"height": 2160
|
||||
},
|
||||
"layers": [
|
||||
{
|
||||
"id": "layer-2",
|
||||
"name": "Slides",
|
||||
"role": "layer",
|
||||
"x": 240,
|
||||
"y": 360,
|
||||
"width": 1280,
|
||||
"height": 720
|
||||
},
|
||||
{
|
||||
"id": "layer-1",
|
||||
"name": "Presenter",
|
||||
"role": "layer",
|
||||
"x": 2320,
|
||||
"y": 360,
|
||||
"width": 1280,
|
||||
"height": 720
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue