mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-22 18:34:42 +01:00
Merge remote-tracking branch 'origin/main' into SidePanelCollapseArrow
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # docs/roadmap.md # docs/target-app-parity.md
This commit is contained in:
commit
b2b9348ebd
130 files changed
+4971
-566
No files matched your search
Generated
+2
-1
@@ -1059,7 +1059,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-update"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c365d75c48b0e47f4b43cdb6592d0cdc39d2d52e#c365d75c48b0e47f4b43cdb6592d0cdc39d2d52e"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=1b34eba41e62138fc2438d2734523b302840b45d#1b34eba41e62138fc2438d2734523b302840b45d"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"dunce",
|
||||
@@ -6511,6 +6511,7 @@ name = "vectorcraft-eps"
|
||||
version = "0.21.0"
|
||||
dependencies = [
|
||||
"craft-pdf",
|
||||
"encoding_rs",
|
||||
"fax",
|
||||
"flate2",
|
||||
"hayro-ccitt",
|
||||
|
||||
+4
-1
@@ -22,7 +22,7 @@ craft-window = { git = "https://github.com/storytold/craft-libs", rev = "9be9a63
|
||||
# The `.vectorcraft` envelope: its members, version, embedded images and the data after the JSON.
|
||||
craft-vectorcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "9be9a63782298ab59cd9b7a42ee9cba4f42a5ccb" }
|
||||
# craft-update: app-specific pretend versions apply to startup and manual checks.
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "c365d75c48b0e47f4b43cdb6592d0cdc39d2d52e", features = ["egui"] }
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "1b34eba41e62138fc2438d2734523b302840b45d", features = ["egui"] }
|
||||
# internal
|
||||
vectorcraft-geom = { path = "crates/geom" }
|
||||
vectorcraft-color = { path = "crates/color" }
|
||||
@@ -99,6 +99,9 @@ ruzstd = { version = "0.9.1", default-features = false, features = ["std"] }
|
||||
hayro-ccitt = "0.3"
|
||||
# Substring search for the EPS reader's PostScript `search`.
|
||||
memchr = "2"
|
||||
# The WHATWG Encoding Standard's legacy encodings: names in legacy .ai files read in the code page
|
||||
# the user picks (Mac OS Roman, Korean, Japanese, Chinese).
|
||||
encoding_rs = "0.8.42"
|
||||
jpeg-encoder = { version = "0.6", default-features = false, features = ["std"] }
|
||||
gif = { version = "0.14", default-features = false, features = ["std", "raii_no_panic"] }
|
||||
# CMYK image samples (vectorcraft-doc's cmyk module): the image crate's own TIFF and JPEG
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//! vectorcraft-cli mcp [--connect 127.0.0.1:7979 | --headless] [--automation-read-root DIR]... [--automation-write-root DIR]...
|
||||
//! vectorcraft-cli run [--in FILE] [--cmd id [--params '{json}'] | --commands FILE|-]... [--export out.svg]... [--scale 2] [--ppi 300]
|
||||
//! vectorcraft-cli commands
|
||||
//! vectorcraft-cli convert IN OUT [--scale 2] [--ppi 300] [--artboard 0 | --range 1-3,5] [--outline-text] [--decimals N] [--replace-lossy] [--editing-data] [--preserve-editing] [--ai-version 7|pdf] [--hidden-objects layer|omit|visible] [--transparent-images flatten|omit]
|
||||
//! vectorcraft-cli convert IN OUT [--scale 2] [--ppi 300] [--artboard 0 | --range 1-3,5] [--outline-text] [--decimals N] [--replace-lossy] [--editing-data] [--legacy-name-encoding ENC] [--preserve-editing] [--ai-version 7|pdf] [--hidden-objects layer|omit|visible] [--transparent-images flatten|omit]
|
||||
//! vectorcraft-cli info FILE
|
||||
//! vectorcraft-cli bench FILE [--size 2880x1800] [--iters 5]
|
||||
//! vectorcraft-cli perf [--paths 50000] [--deep]
|
||||
@@ -101,7 +101,7 @@ USAGE:
|
||||
vectorcraft-cli commands
|
||||
Print the command catalogue as JSON.
|
||||
|
||||
vectorcraft-cli convert IN OUT [--scale N] [--ppi N] [--artboard I | --range R] [--outline-text] [--decimals N] [--replace-lossy] [--editing-data] [--preserve-editing] [--ai-version 7|pdf] [--hidden-objects layer|omit|visible] [--transparent-images flatten|omit]
|
||||
vectorcraft-cli convert IN OUT [--scale N] [--ppi N] [--artboard I | --range R] [--outline-text] [--decimals N] [--replace-lossy] [--editing-data] [--legacy-name-encoding ENC] [--preserve-editing] [--ai-version 7|pdf] [--hidden-objects layer|omit|visible] [--transparent-images flatten|omit]
|
||||
Open IN (any readable format) and export OUT in the format its extension picks (see Writable
|
||||
formats). Raster resolution: --ppi, else 72 times --scale, else the document's raster effects
|
||||
resolution; other formats leave them out. --artboard is 0-based, --range 1-based (\"1-3,5\"); a PDF gets every artboard
|
||||
@@ -114,7 +114,10 @@ USAGE:
|
||||
IN left things out (hidden text, art or layers it could not read; the notes say which) unless
|
||||
--replace-lossy is given. --editing-data opens a .ai or an EPS with editing data from its editing copy
|
||||
even where that draws differently from its PDF part or page (which can be older), as long as
|
||||
it can be read. A PDF OUT omits the embedded native document unless --preserve-editing is
|
||||
it can be read. --legacy-name-encoding reads the names in a .ai's or an EPS's editing data
|
||||
that aren't UTF-8 (layers, objects, artboards, colors, gradients, patterns, graphic styles,
|
||||
swatches, brushes, symbols, variables and data sets, and data sets' text values) in
|
||||
windows-1252 (the default), macintosh, windows-949, shift_jis, gbk or big5. A PDF OUT omits the embedded native document unless --preserve-editing is
|
||||
given (the app's Save As PDF still defaults to keeping it). With --preserve-editing, when the
|
||||
attachment is written the result's warnings say so (it is left out, with its own warning, for
|
||||
--artboard or a --range without every artboard).
|
||||
@@ -302,8 +305,20 @@ fn commands() -> Result<(), String> {
|
||||
}
|
||||
|
||||
fn convert(args: &[String]) -> Result<(), String> {
|
||||
let valued =
|
||||
["--scale", "-s", "--ppi", "--artboard", "-a", "--range", "-r", "--decimals", "--ai-version", "--hidden-objects", "--transparent-images"];
|
||||
let valued = [
|
||||
"--scale",
|
||||
"-s",
|
||||
"--ppi",
|
||||
"--artboard",
|
||||
"-a",
|
||||
"--range",
|
||||
"-r",
|
||||
"--decimals",
|
||||
"--ai-version",
|
||||
"--hidden-objects",
|
||||
"--transparent-images",
|
||||
"--legacy-name-encoding",
|
||||
];
|
||||
if help_requested(args, &valued) {
|
||||
return help();
|
||||
}
|
||||
@@ -312,6 +327,9 @@ fn convert(args: &[String]) -> Result<(), String> {
|
||||
(None::<f64>, None::<u64>, None::<String>, false, false, false, false);
|
||||
let mut ppi = None::<f64>;
|
||||
let mut decimals = None::<u64>;
|
||||
// The encoding of a legacy `.ai`'s names that aren't UTF-8, passed on as `document.open`'s
|
||||
// `legacyNameEncoding`; the engine checks it.
|
||||
let mut legacy_names = None::<String>;
|
||||
// Legacy `.ai` options, passed on as the export's own (`aiVersion`, `hiddenObjects`,
|
||||
// `transparentImages`); the engine checks their values.
|
||||
let mut legacy: Vec<(&str, String)> = vec![];
|
||||
@@ -334,6 +352,9 @@ fn convert(args: &[String]) -> Result<(), String> {
|
||||
"--replace-lossy" => replace_lossy = true,
|
||||
"--editing-data" => editing_data = true,
|
||||
"--preserve-editing" => preserve_editing = true,
|
||||
"--legacy-name-encoding" => {
|
||||
legacy_names = Some(it.next().cloned().ok_or("--legacy-name-encoding needs an encoding such as windows-949")?);
|
||||
}
|
||||
"--ai-version" => legacy.push(("aiVersion", it.next().cloned().ok_or("--ai-version needs 7 or pdf")?)),
|
||||
"--hidden-objects" => legacy.push(("hiddenObjects", it.next().cloned().ok_or("--hidden-objects needs layer, omit or visible")?)),
|
||||
"--transparent-images" => legacy.push(("transparentImages", it.next().cloned().ok_or("--transparent-images needs flatten or omit")?)),
|
||||
@@ -346,8 +367,14 @@ fn convert(args: &[String]) -> Result<(), String> {
|
||||
return Err("a .ait template holds every artboard: --artboard and --range don't apply".into());
|
||||
}
|
||||
let mut h = Headless::new();
|
||||
let opened = if editing_data {
|
||||
let params = json!({"path": input, "editingData": "always"});
|
||||
let opened = if editing_data || legacy_names.is_some() {
|
||||
let mut params = json!({"path": input});
|
||||
if editing_data {
|
||||
params["editingData"] = json!("always");
|
||||
}
|
||||
if let Some(e) = &legacy_names {
|
||||
params["legacyNameEncoding"] = json!(e);
|
||||
}
|
||||
h.call("engine.execute", json!({"command": "document.open", "params": params})).map_err(|e| format!("open {input}: {e}"))?
|
||||
} else {
|
||||
h.call("app.open", json!({"path": input})).map_err(|e| format!("open {input}: {e}"))?
|
||||
|
||||
@@ -193,7 +193,8 @@ fn the_system_title_bar_preference_keeps_the_window_decorations() {
|
||||
|
||||
/// Preferences › User Interface › VectorCraft Title Bar on Every Desktop gives the app frame where
|
||||
/// the probe chose the desktop's (KDE, X11, a window opened through XWayland); without it the probe
|
||||
/// decides, and `VECTORCRAFT_TITLEBAR` takes precedence over both.
|
||||
/// decides, and `VECTORCRAFT_TITLEBAR` set to `app`, `system` or `desktop` takes precedence over
|
||||
/// both.
|
||||
#[test]
|
||||
fn the_app_title_bar_preference_gives_the_app_frame_on_desktop_frames() {
|
||||
assert!(!super::opted_into_app_title_bar(None), "no preferences: the default");
|
||||
|
||||
@@ -42,7 +42,7 @@ pub(crate) const CUSTOM_TITLEBAR: bool = !cfg!(target_os = "macos");
|
||||
/// Whether the user asked for the system title bar in Preferences › User Interface › System Title
|
||||
/// Bar. Read from the saved preferences before the window opens; a missing or unreadable value is
|
||||
/// `false` (the default). This preference forces the desktop/native frame back on unless
|
||||
/// `VECTORCRAFT_TITLEBAR` is set ([`system_title_bar_applies`]).
|
||||
/// `VECTORCRAFT_TITLEBAR` is set to `app`, `system` or `desktop` ([`system_title_bar_applies`]).
|
||||
pub(crate) fn opted_into_system_title_bar(saved: Option<&vectorcraft_ui_egui::UiState>) -> bool {
|
||||
saved.map(|ui| ui.engine_prefs.get("systemTitleBar").and_then(serde_json::Value::as_bool).unwrap_or(false)).unwrap_or(false)
|
||||
}
|
||||
@@ -56,8 +56,8 @@ pub(crate) fn opted_into_app_title_bar(saved: Option<&vectorcraft_ui_egui::UiSta
|
||||
|
||||
/// Whether the app draws the frame on this start, before the System Title Bar preference is
|
||||
/// applied ([`custom_titlebar_from`]). `probed_app` is the `craft-window` probe's answer and
|
||||
/// `overridden` its `VECTORCRAFT_TITLEBAR` override. In order: the override decides when it is
|
||||
/// set; VectorCraft Title Bar on Every Desktop (`opted_into_app`) gives the app frame; a window
|
||||
/// `overridden` its `VECTORCRAFT_TITLEBAR` override. In order: the override decides when the
|
||||
/// variable is set to `app`, `system` or `desktop`;VectorCraft Title Bar on Every Desktop (`opted_into_app`) gives the app frame; a window
|
||||
/// that opens through XWayland (`forced_to_x11`) gets the desktop frame; otherwise the probe
|
||||
/// decides.
|
||||
pub(crate) fn app_draws_frame(probed_app: bool, overridden: Option<bool>, forced_to_x11: bool, opted_into_app: bool) -> bool {
|
||||
@@ -89,13 +89,14 @@ fn probed_choice() -> &'static craft_window::Choice {
|
||||
|
||||
/// Whether `VECTORCRAFT_TITLEBAR` chose this window's frame (Linux and the BSDs), so Preferences ›
|
||||
/// User Interface › System Title Bar and VectorCraft Title Bar on Every Desktop do not apply while
|
||||
/// it is set. Always `false` on macOS and Windows.
|
||||
/// it is set to `app`, `system` or `desktop`. Always `false` on macOS and Windows.
|
||||
pub(crate) fn titlebar_from_env() -> bool {
|
||||
cfg!(not(any(target_os = "macos", target_os = "windows"))) && probed_choice().overridden().is_some()
|
||||
}
|
||||
|
||||
/// Whether System Title Bar decides this start: `opted_into_system` unless `VECTORCRAFT_TITLEBAR`
|
||||
/// is set (`from_env`), which chooses the frame for the run it is set in.
|
||||
/// is set to `app`, `system` or `desktop` (`from_env`), which chooses the frame for the run it is
|
||||
/// set in.
|
||||
pub(crate) fn system_title_bar_applies(opted_into_system: bool, from_env: bool) -> bool {
|
||||
opted_into_system && !from_env
|
||||
}
|
||||
@@ -107,10 +108,10 @@ pub(crate) fn system_title_bar_applies(opted_into_system: bool, from_env: bool)
|
||||
/// ([`craft_window::Frame::Desktop`]) on macOS, Windows, X11 and any Wayland compositor with
|
||||
/// server-side decorations (KDE, Sway, Hyprland, COSMIC); the app draws it
|
||||
/// ([`craft_window::Frame::App`]) only where the compositor leaves it to the app (GNOME's Mutter),
|
||||
/// or when `VECTORCRAFT_TITLEBAR` overrides the probe. VectorCraft draws its own title bar exactly
|
||||
/// or when `VECTORCRAFT_TITLEBAR` set to `app`, `system` or `desktop` overrides the probe. VectorCraft draws its own title bar exactly
|
||||
/// when `craft-window` says the app owns the frame **and** the user has not opted into the system
|
||||
/// title bar; the preference forces the native frame back on unless `VECTORCRAFT_TITLEBAR` is set
|
||||
/// ([`system_title_bar_applies`]).
|
||||
/// to one of those values ([`system_title_bar_applies`]).
|
||||
///
|
||||
/// macOS and Windows keep today's behavior and are decided by [`CUSTOM_TITLEBAR`] rather than the
|
||||
/// probe: `craft-window` returns `Frame::Desktop` for both (the OS always draws a frame), but
|
||||
@@ -132,13 +133,14 @@ pub(crate) fn custom_titlebar_from(_frame: &craft_window::Frame, opted_into_syst
|
||||
|
||||
/// Whether this start draws its own title bar. Probes the shared `craft-window` crate once (its
|
||||
/// override variable is `VECTORCRAFT_TITLEBAR`) and combines its decision with the saved System
|
||||
/// Title Bar preference, which does not apply while the variable is set. Call once at startup,
|
||||
/// Title Bar preference, which does not apply while the variable is set to `app`, `system` or
|
||||
/// `desktop`. Call once at startup,
|
||||
/// before [`native_options`].
|
||||
///
|
||||
/// On Linux, Preferences › Performance › Linux Display Server › X11 opens the window through
|
||||
/// XWayland (below). A GNOME/Wayland probe would say `Frame::App` there, but the window really runs
|
||||
/// on X11, whose window manager draws the frame — so when XWayland is being forced, keep the native
|
||||
/// frame, the same as a real X11 session. An explicit `VECTORCRAFT_TITLEBAR` override still wins,
|
||||
/// frame, the same as a real X11 session. A recognized `VECTORCRAFT_TITLEBAR` override still wins,
|
||||
/// and so does VectorCraft Title Bar on Every Desktop ([`app_draws_frame`]).
|
||||
pub(crate) fn custom_titlebar(saved: Option<&vectorcraft_ui_egui::UiState>) -> bool {
|
||||
let choice = probed_choice();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::{
|
||||
Beside, BuilderMap, EngineError, FillRule, Node, NodeId, PathData, Point, Rect, Result, Session, SubPath, Touched, Value, b, bad, check_numbers,
|
||||
Arc, Beside, BuilderMap, EngineError, FillRule, Node, NodeId, PathData, Point, Rect, Result, Session, Touched, Value, b, bad, check_numbers,
|
||||
f64_or, fill_param, finite, gap_param, ids_json, json, marquee_param, po, points_param, remnant, replace_leaves, replace_with_pieces, root_ids,
|
||||
shape_node, switch_or,
|
||||
};
|
||||
@@ -41,6 +41,7 @@ pub(super) fn sb_merge(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let gap = gap_param(p);
|
||||
// The map the Shape Builder tool already has, which a click or drag of it is made over.
|
||||
let shared = s.tool.shape_builder_map().filter(|(_, g)| *g == gap);
|
||||
let prepared = s.tool.shape_builder_merge();
|
||||
let label = if erase { "Shape Builder Delete" } else { "Shape Builder" };
|
||||
let (ids, merged, touched, split) = s.edit(label, |d, sel| {
|
||||
let (shapes, leaves) = b::shape_builder_shapes(d, &roots, open_filled_as_closed);
|
||||
@@ -89,16 +90,28 @@ pub(super) fn sb_merge(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
touched.add(map.hit(q, Some(tol)));
|
||||
return Ok((ids, None, touched, Some(split)));
|
||||
}
|
||||
let mut touched = Touched { regions: marquee.map(|(a, b)| map.regions_in_marquee(a, b)).unwrap_or_default(), ..Default::default() };
|
||||
touched.extend(&map.builder_hits_along(&pts, piece_tol));
|
||||
touched.edges = map.erased_edges(&touched);
|
||||
let touched = map.merge_touched(&pts, marquee, piece_tol);
|
||||
if touched.is_empty() {
|
||||
return Err(EngineError::Other("Shape Builder: no region under the pointer".into()));
|
||||
}
|
||||
let cuts: Vec<&SubPath> = touched.edges.iter().filter_map(|&k| map.edges.get(k)?.0.path.subpaths.first()).collect();
|
||||
let inputs = b::merge_inputs(&leaves.iter().collect::<Vec<_>>(), open_filled_as_closed);
|
||||
// The tool computed this merge on another thread when it would come out the same.
|
||||
let ready = prepared.as_ref().filter(|m| {
|
||||
shared.as_ref().is_some_and(|(s, _)| Arc::ptr_eq(s, &m.map) && std::ptr::eq(s.as_ref(), map))
|
||||
&& m.gap == gap
|
||||
&& m.touched == touched
|
||||
&& m.inputs == inputs
|
||||
});
|
||||
let computed;
|
||||
let geometry = match ready {
|
||||
Some(m) => &m.geometry,
|
||||
None => {
|
||||
computed = b::merge_geometry(map, &touched, gap, &inputs);
|
||||
&computed
|
||||
}
|
||||
};
|
||||
let picked: Vec<&po::Region> = touched.regions.iter().filter_map(|&i| map.regions.get(i).map(|r| &r.0)).collect();
|
||||
let faces = po::FaceMerger::with_gap(&map.shapes, gap_param(p));
|
||||
let union = if picked.is_empty() { PathData::default() } else { faces.merge(&picked) };
|
||||
let union = &geometry.union;
|
||||
// Pick Color From Artwork: the merged shape takes the look of the front-most object under the
|
||||
// drag's first point, else under its last point, else of the front-most object. Color
|
||||
// Swatches: the current fill, with the rest of the look of the front-most object over the
|
||||
@@ -115,7 +128,7 @@ pub(super) fn sb_merge(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// What goes in place of each object the map was made from (none: it stays as it is).
|
||||
let mut outs: Vec<Option<Vec<Node>>> = vec![];
|
||||
let mut merged_id = None;
|
||||
for (i, (sh, leaf)) in map.shapes.iter().zip(&leaves).enumerate() {
|
||||
for (i, leaf) in leaves.iter().take(map.shapes.len()).enumerate() {
|
||||
let mut out = None;
|
||||
let pieces: Vec<usize> = map.lines.iter().enumerate().filter(|(_, (l, _))| l.key == i as u64).map(|(k, _)| k).collect();
|
||||
if !pieces.is_empty() {
|
||||
@@ -131,41 +144,15 @@ pub(super) fn sb_merge(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
out = Some(kept);
|
||||
}
|
||||
} else {
|
||||
} else if let Some(Some(rest)) = geometry.rests.get(i) {
|
||||
// A shape loses the regions deleted or merged, then the edges deleted (each one on
|
||||
// its outline, shared edges from every shape along them).
|
||||
let in_union = picked.iter().any(|r| r.sources.contains(&i));
|
||||
let mut rest = if in_union {
|
||||
// What is left of it: its faces not merged or deleted, united. They share their
|
||||
// edges with the merged faces exactly, where subtracting the merged shape left
|
||||
// slivers of the outline along them (#569). A sliver goes in only where the
|
||||
// shape covers it and the merged shape does not take it in.
|
||||
let kept: Vec<&po::Region> = map
|
||||
.regions
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(k, (r, ..))| r.sources.contains(&i) && !touched.regions.contains(k))
|
||||
.map(|(_, (r, ..))| r)
|
||||
.collect();
|
||||
if kept.is_empty() { PathData::default() } else { faces.merge_rest(i, &kept, &picked) }
|
||||
// its outline, shared edges from every shape along them). What is left of its own
|
||||
// outline keeps its fill rule; united faces fill with non-zero.
|
||||
out = Some(if rest.path.is_empty() {
|
||||
vec![]
|
||||
} else {
|
||||
b::node_outline(leaf).map_or_else(|| sh.path.clone(), |o| o.0)
|
||||
};
|
||||
let fill_closes = open_filled_as_closed && !leaf.appearance.fill_paint().is_none();
|
||||
// Edges come back from the planar map within a few hundredths of the outlines they
|
||||
// follow, whatever else is selected.
|
||||
let cut_tol = b::outline_snap(&sh.path);
|
||||
let mut cut = false;
|
||||
for piece in &cuts {
|
||||
if let Some(r) = po::cut_out(&rest, piece, fill_closes, cut_tol) {
|
||||
rest = r;
|
||||
cut = true;
|
||||
}
|
||||
}
|
||||
if in_union || cut {
|
||||
// What is left of its own outline keeps its fill rule; united faces fill with non-zero.
|
||||
out = Some(if rest.is_empty() { vec![] } else { vec![remnant(d, leaf, rest, in_union.then_some(FillRule::NonZero))] });
|
||||
}
|
||||
vec![remnant(d, leaf, rest.path.clone(), rest.united.then_some(FillRule::NonZero))]
|
||||
});
|
||||
}
|
||||
// The merged shape goes in place of the object it takes its look from, so it stays in
|
||||
// that object's group (a clip group too).
|
||||
|
||||
@@ -93,16 +93,17 @@ pub use save::{
|
||||
remembered_save_options, save_filters, save_format, save_job, save_plan, save_with, stamp_save_dates, template_filters, templates_dialog_folder,
|
||||
templates_folder,
|
||||
};
|
||||
pub(crate) use screens::{
|
||||
PARAM_KEYS as SCREEN_PARAM_KEYS, ROW_KEYS as SCREEN_ROW_KEYS, UNWRITTEN_FORMATS as SCREEN_UNWRITTEN_FORMATS,
|
||||
check_settings as check_screen_settings, export as export_screens, safe_file_name, store_settings as store_screen_settings,
|
||||
with_export_preset as with_screen_export_preset,
|
||||
};
|
||||
pub use screens::{
|
||||
PRESET_FILE_EXTS as SCREEN_EXPORT_PRESET_EXTS, PRESET_FILE_FORMAT as SCREEN_EXPORT_PRESET_FORMAT, PRESET_KEYS as SCREEN_EXPORT_PRESET_KEYS,
|
||||
PRESETS as SCREEN_PRESETS, SHARED_KEYS as SCREEN_SETTINGS_KEYS, ScreenExport, ScreenExportPreset, ScreenSize,
|
||||
builtin_presets as screen_export_builtin_presets, first_file as screen_first_file, preset_list as screen_export_preset_list,
|
||||
preset_rows as screen_preset_rows,
|
||||
};
|
||||
pub(crate) use screens::{
|
||||
check_settings as check_screen_settings, export as export_screens, safe_file_name, store_settings as store_screen_settings,
|
||||
with_export_preset as with_screen_export_preset,
|
||||
};
|
||||
pub use svg::options_map as svg_options;
|
||||
/// Atomic file writes (a temporary file renamed over the target: a failed write never damages the
|
||||
/// file it replaces), for the apps' own writers too.
|
||||
|
||||
@@ -9,7 +9,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Open Document",
|
||||
[],
|
||||
None,
|
||||
"{path | name | dataBase64 (a file's path, or its name with its bytes), pages?: \"2-3, 5\" (PDF/.ai: 1-based, default all; one artboard each) | page?: n, cropTo?: bounding|art|crop (default)|trim|bleed|media (the box each artboard gets; bounding: the art's bounds; trim: the bleed box round it becomes the document's bleed; a PDF-compatible .ai or a PDF saved with its editing data opens on its trim boxes for crop), password? (encrypted PDFs; see document.pdfInfo), textAs?: text (default: point type per line, lines wrapped in a frame as area type where they lay out the same, in the file's fonts by name; missing ones are listed in warnings) | outlines (glyph paths), layers?: true (default: optional content groups become layers with their visibility, print state and lock — art that is off comes in as a hidden layer; other art goes to a layer per page) | false (one layer per page, without the art that is off; Save then asks for a name), editingData?: true (default: an EPS, .ai or PDF that carries its editor's own copy of the art opens from it, with its layers, hidden objects, guides, artboards and the art outside them; a .ai or PDF whose type shows opens from its PDF part with textAs: outlines) | \"always\" (as true, and a .ai's editing copy is used even where it draws differently from its PDF part, which can be older; the warnings say so) | false (only what its page or PDF part prints, for print pipelines; a .ai saved without PDF compatibility then can't be opened), colorMode?: rgb|cmyk (the mode the document opens in, its colours converted as file.documentColorMode does, grays? as there; default: the file's — a PDF keeps CMYK, Gray and spot inks (spot swatches at a tint) and opens in CMYK when painted mostly in CMYK), grays?: as file.documentColorMode, dxf?: {layout?: \"Model\" (default) | a paper layout's name (document.dxfInfo lists them), unit?, scale? (the ratio: 1 unit of the art = scale drawing units; default: the drawing at 1:1 in its own unit), fit?: false (scale to fit an artboard of fitTo?: [612, 792], turned to the art's orientation), scaleLineweights?: false (lineweights scale with the art), center?: true (false: the drawing's origin on the artboard's bottom-left corner; fitted art's bottom-left corner), mergeLayers?: false (all art on one layer)} (DXF), crop?: as cropTo (its older name), importer?: \"plugin.<id>\" (an importer plug-in's format id, see document.formats: it opens the file, which must have an extension it lists, also one a built-in format reads), params?: {…} (the importer's own parameters, see plugin.info)} → {index, title, format, warnings, restored, missingLinks, modifiedLinks, updatedLinks: [{name, path, ids}]}; any readable format (see document.formats): .vectorcraft/.drawcraft, .svg/.svgz, .pdf/.ai, .ait, ASCII .dxf (each DXF layer with art a layer; blocks symbols; what can't come in is listed in warnings), PNG/JPEG/GIF/WebP/TIFF/BMP (an image opens as a document of its size at the resolution it declares, as file.place sizes it; 72 ppi, 1 px = 1 pt, when it declares none), .emf/.wmf (one artboard, the picture's frame; records VectorCraft doesn't read are skipped with one warning), .eps and PostScript .ai (one artboard, the bounding box: an EPS file VectorCraft wrote restores the document it carries, restored: true; other files are read by a PostScript interpreter — paths, colours and spot inks, clips, gradients, images, type in the fonts named — and come in as their TIFF preview, with a warning, when their PostScript can't be read). A PDF/.ai/.ait or SVG saved with Preserve Editing restores the native document it carries (restored: true; a PDF only when no pages are picked), unless the file was changed elsewhere since or the data can't be read: then its artwork is imported and the first warning says why. Templates (native templates, .ait) open as a new untitled document; a restored .ai keeps its path (Save writes .ai again) and opens on the artboard its editing copy names as active. A file that no built-in format reads, by its content or its extension, opens with the installed importer plug-in that lists its extension (the one whose id sorts first, when several do): it is given the file, at most 128 MiB, and its objects become a new document whose artboard is their bounds; Save then asks for a name, and the warnings are the importer's. Linked images are read from their files (looked for at their path, then relative to the document): missing ones show their saved preview (links.relink), modified ones are read again only with Preferences › Update Links: Automatically (else links.update). An SVG's <image> files (relative links from the SVG's folder) stay linked, SVG files become art, missing ones a placeholder in their box (a warning and missingLinks)",
|
||||
"{path | name | dataBase64 (a file's path, or its name with its bytes), pages?: \"2-3, 5\" (PDF/.ai: 1-based, default all; one artboard each) | page?: n, cropTo?: bounding|art|crop (default)|trim|bleed|media (the box each artboard gets; bounding: the art's bounds; trim: the bleed box round it becomes the document's bleed; a PDF-compatible .ai or a PDF saved with its editing data opens on its trim boxes for crop), password? (encrypted PDFs; see document.pdfInfo), textAs?: text (default: point type per line, lines wrapped in a frame as area type where they lay out the same, in the file's fonts by name; missing ones are listed in warnings) | outlines (glyph paths), layers?: true (default: optional content groups become layers with their visibility, print state and lock — art that is off comes in as a hidden layer; other art goes to a layer per page) | false (one layer per page, without the art that is off; Save then asks for a name), editingData?: true (default: an EPS, .ai or PDF that carries its editor's own copy of the art opens from it, with its layers, hidden objects, guides, artboards and the art outside them; a .ai or PDF whose type shows opens from its PDF part with textAs: outlines) | \"always\" (as true, and a .ai's editing copy is used even where it draws differently from its PDF part, which can be older; the warnings say so) | false (only what its page or PDF part prints, for print pipelines; a .ai saved without PDF compatibility then can't be opened), legacyNameEncoding?: windows-1252 (default) | macintosh | windows-949 (also euc-kr) | shift_jis | gbk | big5 (the code page names in the editing data of a .ai or an EPS are read in when they aren't UTF-8: layers, objects, artboards, colors, gradients, patterns, graphic styles, swatches, brushes, symbols, variables and data sets, and data sets' text values; warnings list the first three such names as read, and count the rest), colorMode?: rgb|cmyk (the mode the document opens in, its colours converted as file.documentColorMode does, grays? as there; default: the file's — a PDF keeps CMYK, Gray and spot inks (spot swatches at a tint) and opens in CMYK when painted mostly in CMYK), grays?: as file.documentColorMode, dxf?: {layout?: \"Model\" (default) | a paper layout's name (document.dxfInfo lists them), unit?, scale? (the ratio: 1 unit of the art = scale drawing units; default: the drawing at 1:1 in its own unit), fit?: false (scale to fit an artboard of fitTo?: [612, 792], turned to the art's orientation), scaleLineweights?: false (lineweights scale with the art), center?: true (false: the drawing's origin on the artboard's bottom-left corner; fitted art's bottom-left corner), mergeLayers?: false (all art on one layer)} (DXF), crop?: as cropTo (its older name), importer?: \"plugin.<id>\" (an importer plug-in's format id, see document.formats: it opens the file, which must have an extension it lists, also one a built-in format reads), params?: {…} (the importer's own parameters, see plugin.info)} → {index, title, format, warnings, restored, missingLinks, modifiedLinks, updatedLinks: [{name, path, ids}]}; any readable format (see document.formats): .vectorcraft/.drawcraft, .svg/.svgz, .pdf/.ai, .ait, ASCII .dxf (each DXF layer with art a layer; blocks symbols; what can't come in is listed in warnings), PNG/JPEG/GIF/WebP/TIFF/BMP (an image opens as a document of its size at the resolution it declares, as file.place sizes it; 72 ppi, 1 px = 1 pt, when it declares none), .emf/.wmf (one artboard, the picture's frame; records VectorCraft doesn't read are skipped with one warning), .eps and PostScript .ai (one artboard, the bounding box: an EPS file VectorCraft wrote restores the document it carries, restored: true; other files are read by a PostScript interpreter — paths, colours and spot inks, clips, gradients, images, type in the fonts named — and come in as their TIFF preview, with a warning, when their PostScript can't be read). A PDF/.ai/.ait or SVG saved with Preserve Editing restores the native document it carries (restored: true; a PDF only when no pages are picked), unless the file was changed elsewhere since or the data can't be read: then its artwork is imported and the first warning says why. Templates (native templates, .ait) open as a new untitled document; a restored .ai keeps its path (Save writes .ai again) and opens on the artboard its editing copy names as active. A file that no built-in format reads, by its content or its extension, opens with the installed importer plug-in that lists its extension (the one whose id sorts first, when several do): it is given the file, at most 128 MiB, and its objects become a new document whose artboard is their bounds; Save then asks for a name, and the warnings are the importer's. Linked images are read from their files (looked for at their path, then relative to the document): missing ones show their saved preview (links.relink), modified ones are read again only with Preferen
Line truncated
|
||||
always,
|
||||
load::open
|
||||
),
|
||||
@@ -54,7 +54,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Export for Screens",
|
||||
["File", "Export"],
|
||||
None,
|
||||
"{folder?, zip?: false (one .zip of every file, each deflated or stored, whichever is smaller: no folder → {name, dataBase64, bytes, files: [name…]}; with a folder it is written there → {path, bytes, files}), artboards?: [index…] | range?: \"1-3\" (default all), assets?: [asset id…] (instead of artboards: each asset's art alone, cropped to its bounds and named after the asset; see assets.list), layers?: [layer id…] (instead of artboards: each layer's art alone, sublayers included, named after the layer), selection?: one|each (instead of artboards: the selected art as one file, or a file per selected object, named after it), fullDocument?: false (one file per format instead: a PDF of every artboard, other formats the bounds of all visible art, named after the document), includeBleed?: false (artboards grown by the document's bleed), includeArtboardFill?: true (Include Artboard Fill: each artboard's background color behind its art; false leaves it out), pdfs?: multiple|single (Export PDFs As: with several artboards, single writes them as the pages of one PDF per PDF row, named after the document), exportPreset?: (a preset of document.exportPresets.list: its settings, under these params), subfolders?: false (each row's files in a sub-folder: its folder, else its size for raster (1x, 2x, 100w…) or its format (SVG, PDF)), folders?: none|rows (as subfolders)|format (a folder per extension: png, svg, pdf…)|item (a folder per artboard, asset, layer or object)|itemFormat (item/extension) (default: rows with subfolders or a preset, else none), name?: (a file name pattern instead of the item's name, with <filename> for the document, <name> for the artboard, asset, layer or object, <index> from 1, #### for the counter zero-padded to the run of #, <format>, <scale>, <suffix> (else the row's suffix ends the name), YYYYMMDD, YYYY-MM-DD, YYYY, <date>, <time>, <YYYY>, <MM>, <DD>, <hh>, <mm> and <ss>; a trailing .ext is dropped, as in `COMPANY-Logo-<filename>-####-YYYYMMDD`; different files it names alike get -2, -3…), counterStart?: 1, counterPer?: item (every file of an item has its number)|file, date?: YYYY-MM-DD (the date the pattern uses; default today, UTC), preset?: mobile (PNG 1x, 2x, 3x) | density (PNG 0.75x–4x in ldpi…xxxhdpi sub-folders) instead of formats (turns subfolders on), formats?: [{format: png|png8|jpg|webp|gif|tiff|bmp|tga|psd|svg|svgz|pdf|eps|ai|vectorcraft, scale?: 1 | \"2x\" | \"100w\" | \"100h\" | \"72ppi\", width?: px | height?: px | ppi? (raster only; width, then height, then ppi win over scale), suffix?: (raster default: @2x, @100w, @100h, none at 1x; vector formats drop size suffixes), folder?: (its sub-folder), quality?: (jpg 0–100), …the format's options (antiAlias, background, preset (pdf)…)}], settings?: {png|png8|jpg|webp|gif|tiff|bmp|tga|psd|svg|svgz|pdf|eps|ai|vectorcraft: {…options for every row of that format}} (rows' own options win), prefix?, antiAlias?: none|art|type (raster rows without their own), openLocation?: (remembered; the app shows the files after exporting)} one file per artboard and format (a PDF holds its artboard alone; artboards with the same name, in any case, get -2, -3…; an unnamed one is Artboard-N; a row whose file would take a name another row's file has, in any case, gets -2, -3… too, and identical rows write one file; row folders that differ only in case are one folder, spelled as the first row spells it) → {files: [path…]}; no folder → {files: [{name, dataBase64}]} (names include sub-folders: 2x/Icon@2x.png); every reply has warnings: [the encoders' warnings for the files, each once: an image that couldn't be decoded, type written in the fallback font…]. eps, ai and vectorcraft rows write a document of the item alone (its one artboard). The params (but zip and assets) are remembered in the document (document.exportSettings; not an undo step)",
|
||||
"{folder?, zip?: false (one .zip of every file, each deflated or stored, whichever is smaller: no folder → {name, dataBase64, bytes, files: [name…]}; with a folder it is written there → {path, bytes, files}), artboard?: index | artboards?: [index…] | range?: \"1-3\" (default all), assets?: [asset id…] (instead of artboards: each asset's art alone, cropped to its bounds and named after the asset; see assets.list), layers?: [layer id…] (instead of artboards: each layer's art alone, sublayers included, named after the layer), selection?: one|each (instead of artboards: the selected art as one file, or a file per selected object, named after it), fullDocument?: false (one file per format instead: a PDF of every artboard, other formats the bounds of all visible art, named after the document), includeBleed?: false (artboards grown by the document's bleed), includeArtboardFill?: true (Include Artboard Fill: each artboard's background color behind its art; false leaves it out), pdfs?: multiple|single (Export PDFs As: with several artboards, single writes them as the pages of one PDF per PDF row, named after the document), exportPreset?: (a preset of document.exportPresets.list: its settings, under these params), subfolders?: false (each row's files in a sub-folder: its folder, else its size for raster (1x, 2x, 100w…) or its format (SVG, PDF)), folders?: none|rows (as subfolders)|format (a folder per extension: png, svg, pdf…)|item (a folder per artboard, asset, layer or object)|itemFormat (item/extension) (default: rows with subfolders or a preset, else none), name?: (a file name pattern instead of the item's name, with <filename> for the document, <name> for the artboard, asset, layer or object, <index> from 1, #### for the counter zero-padded to the run of #, <format>, <scale>, <suffix> (else the row's suffix ends the name), YYYYMMDD, YYYY-MM-DD, YYYY, <date>, <time>, <YYYY>, <MM>, <DD>, <hh>, <mm> and <ss>; a trailing .ext is dropped, as in `COMPANY-Logo-<filename>-####-YYYYMMDD`; different files it names alike get -2, -3…), counterStart?: 1, counterPer?: item (every file of an item has its number)|file, date?: YYYY-MM-DD (the date the pattern uses; default today, UTC), preset?: mobile (PNG 1x, 2x, 3x) | density (PNG 0.75x–4x in ldpi…xxxhdpi sub-folders) instead of formats (turns subfolders on), formats?: [{format: png|png8|jpg|webp|gif|tiff|bmp|tga|psd|svg|svgz|pdf|eps|ai|vectorcraft, scale?: 1 | \"2x\" | \"100w\" | \"100h\" | \"72ppi\", width?: px | height?: px | ppi? (raster only; width, then height, then ppi win over scale), suffix?: (raster default: @2x, @100w, @100h, none at 1x; vector formats drop size suffixes), folder?: (its sub-folder), quality?: (jpg 0–100), …the format's options (antiAlias, background, preset (pdf)…)}], settings?: {png|png8|jpg|webp|gif|tiff|bmp|tga|psd|svg|svgz|pdf|eps|ai|vectorcraft: {…options for every row of that format}} (rows' own options win), prefix?, antiAlias?: none|art|type (raster rows without their own), openLocation?: (remembered; the app shows the files after exporting)} one file per artboard and format (a PDF holds its artboard alone; artboards with the same name, in any case, get -2, -3…; an unnamed one is Artboard-N; a row whose file would take a name another row's file has, in any case, gets -2, -3… too, and identical rows write one file; row folders that differ only in case are one folder, spelled as the first row spells it) → {files: [path…]}; no folder → {files: [{name, dataBase64}]} (names include sub-folders: 2x/Icon@2x.png); every reply has warnings: [the encoders' warnings for the files, each once: an image that couldn't be decoded, type written in the fallback font…]. eps, ai and vectorcraft rows write a document of the item alone (its one artboard). The params (but zip and assets) are remembered in the document (document.exportSettings; not an undo step). A key it doesn't take, a key no format takes in a format row or in settings, settings for a format it doesn't write, and an unknown key inside a PDF, EPS or SVG option's object, are refused",
|
||||
has_doc,
|
||||
screens::export_for_screens
|
||||
),
|
||||
@@ -72,7 +72,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Save Export Preset",
|
||||
[],
|
||||
None,
|
||||
"{name, settings: {formats, settings, preset, name, prefix, counterStart, counterPer, folders, subfolders, includeBleed, includeArtboardFill, antiAlias, folder, fullDocument} (as document.exportForScreens; other keys are left out)} save (or replace) a batch export preset, kept with the preferences; built-in names are refused → {name, created, settings}",
|
||||
"{name, settings: {formats, settings, preset, name, prefix, counterStart, counterPer, folders, subfolders, includeBleed, includeArtboardFill, antiAlias, folder, fullDocument} (as document.exportForScreens; its other keys are left out)} save (or replace) a batch export preset, kept with the preferences; built-in names are refused, and so are the keys document.exportForScreens refuses, in settings and in its format rows and settings → {name, created, settings}",
|
||||
always,
|
||||
screens::presets_save
|
||||
),
|
||||
|
||||
@@ -184,7 +184,8 @@ fn through_editing_data(
|
||||
) -> (Document, Vec<String>, bool) {
|
||||
let Some(layers) = layers else { return (doc, warnings, false) };
|
||||
let outlined = opts.text_as == vectorcraft_pdf::TextAs::Outlines;
|
||||
let (doc, mut warnings, read) = vectorcraft_eps::layered_ai_from(layers, doc, warnings, outlined, opts.trust_editing_data, unit);
|
||||
let (doc, mut warnings, read) =
|
||||
vectorcraft_eps::layered_ai_from(layers, doc, warnings, outlined, opts.trust_editing_data, unit, opts.legacy_names);
|
||||
// The layers weren't read (or couldn't be): the notes of reading the PDF part still hold.
|
||||
if !read {
|
||||
return (doc, warnings, false);
|
||||
@@ -209,12 +210,12 @@ fn from_editing_data_alone(opened: &vectorcraft_pdf::Opened, opts: &LoadOptions)
|
||||
return None;
|
||||
}
|
||||
let private = opened.illustrator_data()?;
|
||||
Some(editing_copy_alone(&private))
|
||||
Some(editing_copy_alone(&private, opts))
|
||||
}
|
||||
|
||||
/// [`from_editing_data_alone`] of `private`, the editor's copy already read.
|
||||
fn editing_copy_alone(private: &[u8]) -> Result<(Document, Vec<String>)> {
|
||||
vectorcraft_eps::ai_alone(private)
|
||||
fn editing_copy_alone(private: &[u8], opts: &LoadOptions) -> Result<(Document, Vec<String>)> {
|
||||
vectorcraft_eps::ai_alone_with(private, opts.legacy_names)
|
||||
.map_err(|why| err(format!("this file was saved without PDF compatibility, and its editing data can't be read ({why})")))
|
||||
}
|
||||
|
||||
@@ -247,7 +248,7 @@ fn without_pdf_part(bytes: &[u8], opts: &LoadOptions, e: &EngineError) -> Option
|
||||
return None;
|
||||
}
|
||||
let private = vectorcraft_pdf::illustrator_data_without_pdf_part(bytes, opts.password.as_deref())?;
|
||||
let (doc, warnings) = vectorcraft_eps::ai_alone_on_page(&private.data, private.trim, private.user_unit).ok()?;
|
||||
let (doc, warnings) = vectorcraft_eps::ai_alone_on_page(&private.data, private.trim, private.user_unit, opts.legacy_names).ok()?;
|
||||
let notes = std::iter::once(format!("the PDF part couldn't be read ({e}): the file opened from its editing data")).chain(warnings).collect();
|
||||
Some(outlined_if_asked(doc, notes, opts))
|
||||
}
|
||||
@@ -323,7 +324,7 @@ pub(crate) fn page_or_editing_data(
|
||||
match read {
|
||||
Ok((doc, notes)) => Ok((doc, notes, false)),
|
||||
Err(e) if is_placeholder(&e) => {
|
||||
let l = load_with(name, bytes, &LoadOptions { password: opts.password.clone(), ..Default::default() })?;
|
||||
let l = load_with(name, bytes, &LoadOptions { password: opts.password.clone(), legacy_names: opts.legacy_names, ..Default::default() })?;
|
||||
Ok((l.doc, l.warnings, true))
|
||||
}
|
||||
Err(e) if page_index == 0 => match load_with(name, bytes, &LoadOptions { pages: None, ..opts.clone() }) {
|
||||
@@ -352,7 +353,7 @@ pub fn load_with(name: &str, bytes: &[u8], opts: &LoadOptions) -> Result<Loaded>
|
||||
_ if matches!(format.id, "eps" | "ps") || vectorcraft_pdf::is_postscript(bytes) => {
|
||||
let editing = vectorcraft_eps::has_native(bytes).then_some((true, || vectorcraft_eps::native(bytes)));
|
||||
restore_or_import(editing, || {
|
||||
let r = vectorcraft_eps::import_trusting(bytes, opts.editing_data, opts.trust_editing_data)
|
||||
let r = vectorcraft_eps::import_names(bytes, opts.editing_data, opts.trust_editing_data, opts.legacy_names)
|
||||
.map_err(|e| err(format!("can't open `{}`: {e}", file_name(name))))?;
|
||||
Ok((r.document, r.warnings))
|
||||
})?
|
||||
@@ -391,7 +392,7 @@ pub fn load_with(name: &str, bytes: &[u8], opts: &LoadOptions) -> Result<Loaded>
|
||||
if let Some((o, private)) = opened.as_ref().ok().filter(|_| reads_layers_alone(opts)).and_then(|o| Some((o, editing_copy(o, opts)?)))
|
||||
{
|
||||
let pages = o.trim_pages();
|
||||
match vectorcraft_eps::ai_layers_alone(&private, &pages.sizes, pages.user_unit) {
|
||||
match vectorcraft_eps::ai_layers_alone(&private, &pages.sizes, pages.user_unit, opts.legacy_names) {
|
||||
Ok((mut doc, warnings)) => {
|
||||
doc.setup.bleed = pages.bleed;
|
||||
editing_data = true;
|
||||
@@ -413,8 +414,10 @@ pub fn load_with(name: &str, bytes: &[u8], opts: &LoadOptions) -> Result<Loaded>
|
||||
// decoded draws nothing either): its notes are at most the page's own.
|
||||
let empty = draws_nothing(&r.document) && r.warnings.iter().all(|w| is_page_note(w));
|
||||
let copy_alone = || match &private {
|
||||
Some(private) => Some(editing_copy_alone(private)),
|
||||
None if layers.is_some() => opened.as_ref().ok().and_then(|o| editing_copy(o, opts)).map(|p| editing_copy_alone(&p)),
|
||||
Some(private) => Some(editing_copy_alone(private, opts)),
|
||||
None if layers.is_some() => {
|
||||
opened.as_ref().ok().and_then(|o| editing_copy(o, opts)).map(|p| editing_copy_alone(&p, opts))
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let alone = (r.only_text || empty)
|
||||
|
||||
@@ -39,6 +39,9 @@ pub struct LoadOptions {
|
||||
/// A `.ai` opens from its editing copy even where that draws differently from its PDF part
|
||||
/// (which can be older than it), with a warning, instead of from the PDF part.
|
||||
pub trust_editing_data: bool,
|
||||
/// The encoding names in a `.ai` or EPS's editing data are read in when they aren't UTF-8
|
||||
/// (`legacyNameEncoding`).
|
||||
pub legacy_names: vectorcraft_eps::NameEncoding,
|
||||
/// A PDF or `.ai` saved with Preserve Editing opens from the VectorCraft document it carries;
|
||||
/// off, it opens as another app would open it, from the editing copy of its art or its pages.
|
||||
pub native: bool,
|
||||
@@ -57,6 +60,7 @@ impl Default for LoadOptions {
|
||||
dxf: Default::default(),
|
||||
editing_data: true,
|
||||
trust_editing_data: false,
|
||||
legacy_names: vectorcraft_eps::NameEncoding::default(),
|
||||
native: true,
|
||||
}
|
||||
}
|
||||
@@ -65,8 +69,9 @@ impl Default for LoadOptions {
|
||||
impl LoadOptions {
|
||||
/// From command params: `pages` (`"2-3, 5"`, a page number or `"all"`), `page` (one page, when
|
||||
/// `pages` isn't given), `cropTo` (or `crop`), `password`, `colorMode` (`rgb` | `cmyk`) with `grays`,
|
||||
/// `textAs` (`text` | `outlines`), `layers` (true | false), `editingData` (true | false | `always`) and `dxf`
|
||||
/// (the DXF import options).
|
||||
/// `textAs` (`text` | `outlines`), `layers` (true | false), `editingData` (true | false | `always`),
|
||||
/// `legacyNameEncoding` (one of [`vectorcraft_eps::NameEncoding::LABELS`]) and `dxf` (the DXF
|
||||
/// import options).
|
||||
pub fn from_params(cmd: &str, p: &Value) -> Result<Self> {
|
||||
let pages = match p.get("pages").filter(|v| !v.is_null()).or_else(|| p.get("page").filter(|v| !v.is_null())) {
|
||||
None => None,
|
||||
@@ -95,8 +100,15 @@ impl LoadOptions {
|
||||
Some(Value::String(s)) if s.eq_ignore_ascii_case("always") => (true, true),
|
||||
Some(v) => (v.as_bool().ok_or_else(|| bad(cmd, "editingData must be true, false or \"always\""))?, false),
|
||||
};
|
||||
let legacy_names = match p.get("legacyNameEncoding").filter(|v| !v.is_null()) {
|
||||
None => vectorcraft_eps::NameEncoding::default(),
|
||||
Some(v) => v
|
||||
.as_str()
|
||||
.and_then(vectorcraft_eps::NameEncoding::from_label)
|
||||
.ok_or_else(|| bad(cmd, format!("legacyNameEncoding must be one of {}", vectorcraft_eps::NameEncoding::LABELS.join(", "))))?,
|
||||
};
|
||||
let dxf = super::dxfimport::options(cmd, p.get("dxf"))?;
|
||||
Ok(Self { pages, crop, password, color_mode, grays, text_as, layers, dxf, editing_data, trust_editing_data, native: true })
|
||||
Ok(Self { pages, crop, password, color_mode, grays, text_as, layers, dxf, editing_data, trust_editing_data, legacy_names, native: true })
|
||||
}
|
||||
|
||||
/// Does the document read only part of the file, or read it differently (a page range, another
|
||||
|
||||
@@ -752,6 +752,8 @@ pub(super) fn encode_ai(cmd: &str, f: &Format, doc: &Document, p: &Value) -> Res
|
||||
/// file becomes the document's own; the live document gets them in [`SaveJob::finish`]). Bad
|
||||
/// options fail here, before anything is encoded.
|
||||
pub fn save_job(s: &mut Session, plan: SavePlan) -> Result<SaveJob> {
|
||||
// A Shape Builder merge still being computed for a click is saved with the document.
|
||||
s.finish_tool_edit_later()?;
|
||||
// The web build, without a clock, leaves the dates unless given one.
|
||||
let at = if plan.path.is_some() && plan.retargets() { clock_date(s, "modified", plan.modified) } else { None };
|
||||
job_for_stamped(s, s.doc()?, plan, at)
|
||||
@@ -1102,7 +1104,7 @@ pub(super) fn specs() -> Vec<CommandSpec> {
|
||||
"Save Document",
|
||||
[],
|
||||
None,
|
||||
"{path?, format?: vectorcraft|template|pdf|svg|svgz|ai|eps (default: the path's extension, else the document's own format), options?: {…the format's options, see file.formatOptions; default: as last saved}, svg?: {…SVG options} (an SVG save keeps hidden layers, display:none, unless hiddenLayers is false), …the SVG and PDF options given flat instead (an option given flat or in svg and in options with different values is an error), compress?: bool (native, also in options: gzip; default: the useCompression preference; warnings say when the format doesn't read compress, version, preview or precision given flat, or a key given in options), version?: 4 (3, 2 or 1: for older VectorCraft versions; 1 and 2 are never compressed), preview?: false (embed a PNG of the first artboard, at most 256 px), precision?: 0..9 (native: round path anchors and handles to this many decimal places, a smaller file; colors, transforms and type stay exact; default: exact, and a later save without it writes exactly again), separateArtboards?: false (native and .ai: also save each artboard of `range` to <name>-<artboard>.<ext> beside the file, holding that artboard and the art touching it; the result's files lists every file written), range?: \"1-3, 5\"|\"all\" (default; with separateArtboards), includeLinked?: false (keep linked files' own pixels, not just their previews; they stay linked), embedProfiles?: true (carry the ICC profiles loaded from files that the document is tagged with; opening the file installs them where missing), pdfCompatible?: true (native: also carry a PDF of every artboard; false omits it) | true for .ai (false: blank pages, only the native document; a .ai file's compress, default true, is its compression.compressText), modified?: Unix seconds|null (the File Info modified date, and created date when there is none, a save to a file stamps; default now, recorded in the journal so a replay matches; null: leave the dates)} → {path, format, bytes, warnings, files?: [path…] (the file and its artboards' files), linked?: [path…] (images an SVG links to)}. Save writes one artboard, except a .ai file: a PDF-compatible file of every artboard carrying the native document (preserveEditing always on; PDF options flat or in options), which document.open restores exactly, on the active artboard (the app's, else the one the document opened on; with editingData: false, the first); separateArtboards writes more files, one per artboard. EPS saves the chosen artboard (first by default), retaining its page margins and the whole editable document; its PostScript appearance flattens transparency, as EPS requires. Without a path it writes the document's own file in its own format: a document opened from or saved as SVG/PDF/EPS saves as that again (warnings name what the format loses). No path known (never saved, converted from an older version, restored by Data Recovery, or another format) → {dataBase64, format, name, folder?, warnings} and the document stays modified",
|
||||
"{path?, format?: vectorcraft|template|pdf|svg|svgz|ai|eps (default: the path's extension, else the document's own format), options?: {…the format's options, see file.formatOptions; default: as last saved}, svg?: {…SVG options} (an SVG save keeps hidden layers, display:none, unless hiddenLayers is false), …the SVG and PDF options given flat instead (an option given flat or in svg and in options with different values is an error), compress?: bool (native, also in options: gzip; default: the useCompression preference; warnings say when the format doesn't read compress, version, preview or precision given flat, or a key given in options), version?: 4 (3, 2 or 1: for older VectorCraft versions; 1 and 2 are never compressed), preview?: false (embed a PNG of the first artboard, at most 256 px), precision?: 0..9 (native: round path anchors and handles to this many decimal places, a smaller file; colors, transforms and type stay exact; default: exact, and a later save without it writes exactly again), separateArtboards?: false (native and .ai: also save each artboard of `range` to <name>-<artboard>.<ext> beside the file, holding that artboard and the art touching it; the result's files lists every file written), range?: \"1-3, 5\"|\"all\" (default; with separateArtboards), includeLinked?: false (keep linked files' own pixels, not just their previews; they stay linked), embedProfiles?: true (carry the ICC profiles loaded from files that the document is tagged with; opening the file installs them where missing), pdfCompatible?: true (native: also carry a PDF of every artboard; false omits it) | true for .ai (false: blank pages, only the native document; a .ai file's compress, default true, is its compression.compressText), modified?: Unix seconds|null (the File Info modified date, and created date when there is none, a save to a file stamps; default now, recorded in the journal so a replay matches; null: leave the dates)} → {path, format, bytes, warnings, files?: [path…] (the file and its artboards' files), linked?: [path…] (images an SVG links to)}. Save writes one artboard, except a .ai file: a PDF-compatible file of every artboard carrying the native document (preserveEditing always on; PDF options flat or in options), which document.open restores exactly, on the active artboard (the app's, else the one the document opened on; with editingData: false, the first); separateArtboards writes more files, one per artboard. EPS saves the chosen artboard (first by default), retaining its page margins and the whole editable document; its PostScript appearance flattens transparency, as EPS requires. Without a path it writes the document's own file in its own format: a document opened from or saved as SVG/PDF/EPS saves as that again (warnings name what the format loses). No path known (never saved, converted from an older version, restored by Data Recovery, or another format) → {dataBase64, format, name, folder?, warnings} and the document stays modified. A key that no save format takes, beside the path or in options, and an unknown key inside a PDF option's object or svg, are refused",
|
||||
has_doc,
|
||||
|s, p| save(s, SaveMode::Save, p)
|
||||
),
|
||||
|
||||
@@ -193,7 +193,10 @@ pub(super) fn name_without_device(name: &str) -> String {
|
||||
}
|
||||
|
||||
/// Keys of a format row that aren't encoder options.
|
||||
const ROW_KEYS: [&str; 7] = ["format", "scale", "ppi", "width", "height", "suffix", "folder"];
|
||||
pub(crate) const ROW_KEYS: [&str; 7] = ["format", "scale", "ppi", "width", "height", "suffix", "folder"];
|
||||
|
||||
/// The writable formats a format row can't name.
|
||||
pub(crate) const UNWRITTEN_FORMATS: [&str; 5] = ["template", "txt", "dxf", "emf", "wmf"];
|
||||
|
||||
/// One format row: what to write, at which size, with which suffix, into which sub-folder.
|
||||
struct Row {
|
||||
@@ -214,7 +217,7 @@ impl Row {
|
||||
return Err(bad(C, "each format is an object {format, scale?, suffix?}"));
|
||||
}
|
||||
let format = writable(C, Some(str_param(row, "format").unwrap_or("png")), None)?;
|
||||
if matches!(format.id, "template" | "txt" | "dxf" | "emf" | "wmf") {
|
||||
if UNWRITTEN_FORMATS.contains(&format.id) {
|
||||
return Err(bad(C, "Export for Screens writes png, png8, jpg, webp, gif, tiff, bmp, tga, psd, svg, svgz, pdf, eps, ai or vectorcraft"));
|
||||
}
|
||||
// Vector formats have no pixel size: it doesn't apply and adds no @2x suffix (not even one
|
||||
@@ -285,6 +288,36 @@ impl Row {
|
||||
/// or where to.
|
||||
pub const SHARED_KEYS: [&str; 6] = ["formats", "preset", "settings", "prefix", "subfolders", "antiAlias"];
|
||||
|
||||
/// The keys `document.exportForScreens` reads: those of [`ScreenParams`], the formats and their
|
||||
/// settings, `antiAlias`, `exportPreset` and `openLocation`, which the app reads.
|
||||
pub(crate) const PARAM_KEYS: [&str; 25] = [
|
||||
"artboard",
|
||||
"artboards",
|
||||
"range",
|
||||
"folder",
|
||||
"zip",
|
||||
"fullDocument",
|
||||
"includeBleed",
|
||||
"includeArtboardFill",
|
||||
"subfolders",
|
||||
"preset",
|
||||
"prefix",
|
||||
"assets",
|
||||
"layers",
|
||||
"selection",
|
||||
"name",
|
||||
"counterStart",
|
||||
"counterPer",
|
||||
"date",
|
||||
"folders",
|
||||
"pdfs",
|
||||
"formats",
|
||||
"settings",
|
||||
"antiAlias",
|
||||
"exportPreset",
|
||||
"openLocation",
|
||||
];
|
||||
|
||||
/// What `document.exportForScreens` reads besides the formats.
|
||||
#[derive(Default, Deserialize)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
|
||||
@@ -1022,6 +1022,21 @@ fn an_ai_file_saved_without_its_pdf_part_pastes_from_its_editing_data() {
|
||||
assert!(e.contains("placeholder"), "{e}");
|
||||
}
|
||||
|
||||
/// `file.place` reads a `.ai` saved without its PDF part in the `legacyNameEncoding` it is given.
|
||||
#[test]
|
||||
fn an_ai_file_saved_without_its_pdf_part_places_in_the_encoding_picked() {
|
||||
let mut data = ai::sample_data();
|
||||
let at = data.windows(4).position(|w| w == b"Pair").unwrap();
|
||||
// 빨강 in code page 949.
|
||||
data.splice(at..at + 4, br"\273\241\260\255".iter().copied());
|
||||
let file = vectorcraft_format::base64_encode(&ai::ai(&compressed(&data), PLACEHOLDER));
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({})).unwrap();
|
||||
let r = s.execute("file.place", &json!({"name": "art.ai", "dataBase64": file, "link": false, "legacyNameEncoding": "windows-949"})).unwrap();
|
||||
let placed = s.doc().unwrap().doc.layers[0].children().unwrap()[0].clone();
|
||||
assert_eq!(names(&placed.children().unwrap()[1..]), ["빨강", "Ring", "Window"], "{r}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_ai_file_saved_without_its_pdf_part_places_from_its_editing_data() {
|
||||
let [sample, damaged, plain] = placeholder_files();
|
||||
|
||||
@@ -184,6 +184,41 @@ showpage
|
||||
assert!(e.contains("junk.eps"), "{e}");
|
||||
}
|
||||
|
||||
/// `legacyNameEncoding` picks the code page of a legacy `.ai`'s layer names that aren't UTF-8; by
|
||||
/// default they come in as Windows-1252, with a warning naming them. An encoding it doesn't know is
|
||||
/// refused.
|
||||
#[test]
|
||||
fn legacy_ai_layer_names_open_in_the_encoding_picked() {
|
||||
let mut s = Session::new();
|
||||
// A layer named 레이어 1 in Windows code page 949.
|
||||
let ai = b"%!PS-Adobe-3.0\n%%BoundingBox: 0 0 100 100\n%%DocumentNeededResources: procset Adobe_IllustratorA_AI3 1.0 0\n%AI3_TemplateBox: 50 50 50 50\n%%EndComments\n\
|
||||
%%BeginProlog\n%%IncludeResource: procset Adobe_IllustratorA_AI3 1.0 0\n%%EndProlog\n%%BeginSetup\nAdobe_IllustratorA_AI3 /initialize get exec\n%%EndSetup\n\
|
||||
%AI5_BeginLayer\n1 1 1 1 0 0 2 0 0 0 Lb\n(\\267\\271\\300\\314\\276\\356 1) Ln\n0 0 0 1 K\n0 i 1 w\n10 10 m\n90 90 L\nS\nLB\n%AI5_EndLayer--\n%%PageTrailer\n%%Trailer\n%%EOF\n";
|
||||
let open_as = |s: &mut Session, encoding: Option<&str>| {
|
||||
let mut p = json!({"name": "korean.ai", "dataBase64": vectorcraft_format::base64_encode(ai)});
|
||||
if let Some(e) = encoding {
|
||||
p["legacyNameEncoding"] = json!(e);
|
||||
}
|
||||
s.execute("document.open", &p)
|
||||
};
|
||||
let r = open_as(&mut s, None).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.layers[0].name.as_deref(), Some("·¹À̾î 1"));
|
||||
assert_eq!(
|
||||
r["warnings"],
|
||||
json!(["the name `·¹À̾î 1` isn't UTF-8 and was read as windows-1252: if it looks wrong, open the file with another legacyNameEncoding"])
|
||||
);
|
||||
for encoding in ["windows-949", "EUC-KR"] {
|
||||
let r = open_as(&mut s, Some(encoding)).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.layers[0].name.as_deref(), Some("레이어 1"), "{encoding}");
|
||||
assert!(r["warnings"][0].as_str().is_some_and(|w| w.contains("`레이어 1`") && w.contains("windows-949")), "{r}");
|
||||
}
|
||||
let e = open_as(&mut s, Some("utf-16")).unwrap_err();
|
||||
assert!(
|
||||
matches!(&e, EngineError::BadParams { msg, .. } if msg == "legacyNameEncoding must be one of windows-1252, macintosh, windows-949, shift_jis, gbk, big5"),
|
||||
"{e}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eps_files_place_as_one_group_clipped_to_their_bounding_box() {
|
||||
let mut s = rich();
|
||||
|
||||
+178
-34
@@ -6,9 +6,9 @@
|
||||
//! by `|`; a `?` marks an optional one, and a `:`, `=` or `(` starts what the entry says about it. An entry that starts
|
||||
//! with `…` stands for keys listed elsewhere: those of each command it names after `as` or `of`
|
||||
//! (`…settings as file.new`), or, naming none, any key (the options of the format an export picks). Objects inside a value aren't
|
||||
//! described key by key, so only the top level is checked, except in an export's options: those
|
||||
//! are checked against the options of the formats the command can write, in `marks`, `bleed` and
|
||||
//! the other objects too ([`check_export_options`]).
|
||||
//! described key by key, so only the top level is checked, except in the options of an export, a
|
||||
//! save or Export for Screens: those are checked against the options of the formats the command
|
||||
//! can write, in `marks`, `bleed` and the other objects too ([`check_export_options`]).
|
||||
//!
|
||||
//! [`Session::execute`] answers a key the description doesn't name with a parameter error
|
||||
//! ([`check_params`]), for every caller (the app, the control channel, MCP, the CLI) and for the
|
||||
@@ -531,25 +531,183 @@ fn check_option_tree(id: &str, within: &str, given: &serde_json::Map<String, Val
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The options of an export command `id`. `document.export`, `document.exportSelection` and
|
||||
/// `document.serialize` take a key that some format reads (one object can carry several formats'
|
||||
/// options; `document.formats` lists them). `document.exportPdf`, `document.pdfSettings` and
|
||||
/// `pdf.preset.save` take a key that PDF reads, `document.exportEps` one that EPS reads and
|
||||
/// `document.exportDxf` one that DXF reads. Where a command takes `marks`, `bleed`, `flattener` or
|
||||
/// another object option of PDF or EPS, only the object's own keys pass. An SVG export's `svg`
|
||||
/// object is checked when it is read. Saved presets are not checked: one with a key that is no
|
||||
/// longer read keeps loading.
|
||||
/// `given`, the options object at `within` (`""` for the params themselves, `options.`,
|
||||
/// `formats[0].`), has only `keys`, and only their own keys in the PDF and EPS object options
|
||||
/// (`trees`). `why_not` says why a key that is not near any of `keys` is refused, and where the
|
||||
/// keys are listed.
|
||||
fn check_option_keys(id: &str, within: &str, given: &serde_json::Map<String, Value>, keys: &[&str], why_not: &str, trees: &Value) -> Result<()> {
|
||||
for (key, value) in given {
|
||||
if !keys.contains(&key.as_str()) {
|
||||
return Err(bad(
|
||||
id,
|
||||
match nearest(key, keys) {
|
||||
Some(near) => format!("unknown parameter `{within}{key}`; did you mean `{within}{near}`?"),
|
||||
None => format!("unknown parameter `{within}{key}`; {why_not}"),
|
||||
},
|
||||
));
|
||||
}
|
||||
if let (Some(Value::Object(schema)), Value::Object(value)) = (trees.get(key), value) {
|
||||
check_option_tree(id, &format!("{within}{key}."), value, schema)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Why an export option that no format reads is refused.
|
||||
const NO_FORMAT: &str = "no format takes it (see document.formats)";
|
||||
|
||||
/// Why a save option that no save format reads is refused.
|
||||
const NO_SAVE_FORMAT: &str = "no save format takes it (see file.formatOptions)";
|
||||
|
||||
/// The format ids Export for Screens writes: the writable formats, those exporter plug-ins add
|
||||
/// included, but those it doesn't write.
|
||||
pub fn screen_formats() -> Vec<&'static str> {
|
||||
use super::fileio::{FORMATS, SCREEN_UNWRITTEN_FORMATS, plugin_formats};
|
||||
let added = plugin_formats();
|
||||
FORMATS.iter().chain(added.iter().copied()).filter(|f| f.write && !SCREEN_UNWRITTEN_FORMATS.contains(&f.id)).map(|f| f.id).collect()
|
||||
}
|
||||
|
||||
/// The keys a format row of Export for Screens, and the settings of a format, take: the row's own
|
||||
/// (`format`, `scale`…), `includeArtboardFill` and `richBlack`, which the encoders read from a
|
||||
/// row's options (`with_artboard_fills`, the render options), `params`, an exporter plug-in's own,
|
||||
/// and a key some format reads, as `document.export` takes them.
|
||||
fn screen_option_keys() -> Vec<&'static str> {
|
||||
use super::fileio::{FORMATS, SCREEN_ROW_KEYS};
|
||||
let mut keys: Vec<&str> = SCREEN_ROW_KEYS.to_vec();
|
||||
keys.extend(["includeArtboardFill", "richBlack", "params"]);
|
||||
keys.extend(FORMATS.iter().filter(|f| f.write).flat_map(|f| f.options).map(|o| o.name));
|
||||
keys
|
||||
}
|
||||
|
||||
/// A format row of Export for Screens, or the settings of a format, without the keys the export
|
||||
/// refuses in it ([`check_screen_rows`]), inside `marks`, `svg` and the other object options too:
|
||||
/// a saved row or preset that holds a key that is no longer read loads without it.
|
||||
pub fn drop_unread_row_options(row: &mut serde_json::Map<String, Value>) {
|
||||
fn retain_tree(o: &mut serde_json::Map<String, Value>, schema: &serde_json::Map<String, Value>) {
|
||||
o.retain(|k, _| schema.contains_key(k));
|
||||
for (k, v) in o.iter_mut() {
|
||||
if let (Some(Value::Object(inner)), Value::Object(v)) = (schema.get(k), v) {
|
||||
retain_tree(v, inner);
|
||||
}
|
||||
}
|
||||
}
|
||||
let keys = screen_option_keys();
|
||||
row.retain(|k, _| keys.contains(&k.as_str()));
|
||||
let trees = screen_option_trees();
|
||||
for (k, v) in row.iter_mut() {
|
||||
if let (Some(Value::Object(schema)), Value::Object(v)) = (trees.get(k), v) {
|
||||
retain_tree(v, schema);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// [`option_trees`] of Export for Screens: its remembered settings mark PDF security whose
|
||||
/// passwords were left out with `security.passwordRequired`, which the export reads.
|
||||
fn screen_option_trees() -> Value {
|
||||
let mut trees = option_trees();
|
||||
if let Some(security) = trees.get_mut("security").and_then(Value::as_object_mut) {
|
||||
security.insert("passwordRequired".into(), Value::Null);
|
||||
}
|
||||
trees
|
||||
}
|
||||
|
||||
/// The object options an export or save checks key by key: PDF's `marks`, `bleed` and the others,
|
||||
/// the flattener's, and SVG's `svg` with the artboard keys it may carry.
|
||||
fn option_trees() -> Value {
|
||||
let mut trees = pdf_option_tree();
|
||||
if let Some(tree) = trees.as_object_mut() {
|
||||
tree.insert("flattener".into(), serde_json::to_value(super::flatten::FlattenOptions::default()).unwrap_or_default());
|
||||
let mut svg = serde_json::to_value(vectorcraft_svg::ExportOptions::default()).unwrap_or_default();
|
||||
if let Some(svg) = svg.as_object_mut() {
|
||||
svg.extend(super::fileio::ARTBOARD_PARAMS.iter().chain(&["useArtboards"]).map(|k| (k.to_string(), Value::Null)));
|
||||
}
|
||||
tree.insert("svg".into(), svg);
|
||||
}
|
||||
trees
|
||||
}
|
||||
|
||||
/// The format rows (`formats`) and the per-format `settings` of Export for Screens params `p`, at
|
||||
/// `within` (`settings.` in `document.exportPresets.save`). A row, and the settings of a format,
|
||||
/// take [`screen_option_keys`]; `settings` takes the formats Export for Screens writes.
|
||||
fn check_screen_rows(id: &str, within: &str, p: &serde_json::Map<String, Value>) -> Result<()> {
|
||||
let keys = screen_option_keys();
|
||||
let trees = &screen_option_trees();
|
||||
if let Some(Value::Array(rows)) = p.get("formats") {
|
||||
for (i, row) in rows.iter().enumerate() {
|
||||
if let Value::Object(row) = row {
|
||||
check_option_keys(id, &format!("{within}formats[{i}]."), row, &keys, NO_FORMAT, trees)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(Value::Object(settings)) = p.get("settings") {
|
||||
let formats = screen_formats();
|
||||
for (format, options) in settings {
|
||||
if !formats.contains(&format.as_str()) {
|
||||
let why = match nearest(format, &formats) {
|
||||
Some(near) => format!("did you mean `{within}settings.{near}`?"),
|
||||
None => format!("`{within}settings` takes: {}", formats.join(", ")),
|
||||
};
|
||||
return Err(bad(id, format!("unknown parameter `{within}settings.{format}`; {why}")));
|
||||
}
|
||||
if let Value::Object(options) = options {
|
||||
check_option_keys(id, &format!("{within}settings.{format}."), options, &keys, NO_FORMAT, trees)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The options of an export or save command `id`. `document.export`, `document.exportSelection`
|
||||
/// and `document.serialize` take a key that some format reads (one object can carry several
|
||||
/// formats' options; `document.formats` lists them). `document.exportPdf`, `document.pdfSettings`
|
||||
/// and `pdf.preset.save` take a key that PDF reads, `document.exportEps` one that EPS reads and
|
||||
/// `document.exportDxf` one that DXF reads. `document.save`, `file.saveAs`, `file.saveCopy` and
|
||||
/// `file.saveAsTemplate` take, beside the path and in `options`, a key that some save format
|
||||
/// reads. `document.exportForScreens` takes the keys it reads, and checks its format rows and
|
||||
/// settings ([`check_screen_rows`]), as `document.exportPresets.save` does in its `settings` and
|
||||
/// `assets.export` and `assets.settings.set` do in theirs.
|
||||
/// Where a command takes `marks`, `bleed`, `flattener`, `svg` or another object option of PDF,
|
||||
/// EPS or SVG, only the object's own keys pass ([`option_trees`]). Saved presets are not checked:
|
||||
/// one with a key that is no longer read keeps loading.
|
||||
fn check_export_options(id: &str, params: &Value) -> Result<()> {
|
||||
use super::fileio::{FORMATS, dxf, eps, pdf};
|
||||
use super::fileio::{FORMATS, SAVE_FORMATS, SCREEN_PARAM_KEYS, TEMPLATE_FORMATS, dxf, eps, pdf};
|
||||
let Value::Object(given) = params else { return Ok(()) };
|
||||
match (id, given.get("settings")) {
|
||||
("document.exportForScreens", _) => {
|
||||
if let Some(key) = given.keys().find(|k| !SCREEN_PARAM_KEYS.contains(&k.as_str())) {
|
||||
return Err(unknown(id, key, &SCREEN_PARAM_KEYS));
|
||||
}
|
||||
return check_screen_rows(id, "", given);
|
||||
}
|
||||
("document.exportPresets.save", Some(Value::Object(settings))) => {
|
||||
let why = format!("`settings` takes: {}", SCREEN_PARAM_KEYS.join(", "));
|
||||
check_option_keys(id, "settings.", settings, &SCREEN_PARAM_KEYS, &why, &Value::Null)?;
|
||||
return check_screen_rows(id, "settings.", settings);
|
||||
}
|
||||
// Export Assets exports with, and stores, Export for Screens' format rows and settings.
|
||||
("assets.export" | "assets.settings.set", _) => return check_screen_rows(id, "", given),
|
||||
_ => {}
|
||||
}
|
||||
let mut keys: Vec<&str> = vec!["path", "format", "acknowledgeLoss"];
|
||||
// A save's `options` and the keys they take.
|
||||
let mut inner: Option<(&serde_json::Map<String, Value>, Vec<&str>)> = None;
|
||||
let why_not = match id {
|
||||
"document.save" | "file.saveAs" | "file.saveCopy" | "file.saveAsTemplate" => {
|
||||
let saved = FORMATS.iter().filter(|f| SAVE_FORMATS.contains(&f.id) || TEMPLATE_FORMATS.contains(&f.id));
|
||||
let options: Vec<&str> = saved.flat_map(|f| f.options).map(|o| o.name).collect();
|
||||
if let Some(Value::Object(o)) = given.get("options") {
|
||||
inner = Some((o, options.clone()));
|
||||
}
|
||||
keys.extend(["options", "modified"]);
|
||||
keys.extend(options);
|
||||
NO_SAVE_FORMAT
|
||||
}
|
||||
"document.export" | "document.exportSelection" | "document.serialize" => {
|
||||
// `richBlack` is Appearance of Black's setting for a raster export, and `params` an
|
||||
// exporter plug-in's own.
|
||||
keys.extend(["includeArtboardFill", "selectedOnly", "richBlack", "params"]);
|
||||
keys.extend(FORMATS.iter().filter(|f| f.write).flat_map(|f| f.options).map(|o| o.name));
|
||||
"no format takes it"
|
||||
NO_FORMAT
|
||||
}
|
||||
"document.exportPdf" | "document.pdfSettings" | "pdf.preset.save" => {
|
||||
keys.push("includeArtboardFill");
|
||||
@@ -559,38 +717,24 @@ fn check_export_options(id: &str, params: &Value) -> Result<()> {
|
||||
"pdf.preset.save" => keys.extend(["name", "newName", "description"]),
|
||||
_ => {}
|
||||
}
|
||||
"PDF doesn't take it"
|
||||
"PDF doesn't take it (see document.formats)"
|
||||
}
|
||||
"document.exportEps" => {
|
||||
keys.push("includeArtboardFill");
|
||||
keys.extend(eps::OPTIONS.iter().map(|o| o.name));
|
||||
"EPS doesn't take it"
|
||||
"EPS doesn't take it (see document.formats)"
|
||||
}
|
||||
"document.exportDxf" => {
|
||||
keys.extend(dxf::OPTIONS.iter().map(|o| o.name));
|
||||
"DXF doesn't take it"
|
||||
"DXF doesn't take it (see document.formats)"
|
||||
}
|
||||
_ => return Ok(()),
|
||||
};
|
||||
let mut trees = pdf_option_tree();
|
||||
if let Some(tree) = trees.as_object_mut() {
|
||||
tree.insert("flattener".into(), serde_json::to_value(super::flatten::FlattenOptions::default()).unwrap_or_default());
|
||||
let trees = option_trees();
|
||||
if let Some((o, options)) = inner {
|
||||
check_option_keys(id, "options.", o, &options, NO_SAVE_FORMAT, &trees)?;
|
||||
}
|
||||
for (key, value) in given {
|
||||
if !keys.contains(&key.as_str()) {
|
||||
return Err(bad(
|
||||
id,
|
||||
match nearest(key, &keys) {
|
||||
Some(near) => format!("unknown parameter `{key}`; did you mean `{near}`?"),
|
||||
None => format!("unknown parameter `{key}`; {why_not} (see document.formats)"),
|
||||
},
|
||||
));
|
||||
}
|
||||
if let (Some(Value::Object(schema)), Value::Object(value)) = (trees.get(key), value) {
|
||||
check_option_tree(id, &format!("{key}."), value, schema)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
check_option_keys(id, "", given, &keys, why_not, &trees)
|
||||
}
|
||||
|
||||
/// [`check_keys`] for an engine command, the steps of a `command.batch` or an `action.batch` included,
|
||||
|
||||
@@ -678,6 +678,12 @@ impl Session {
|
||||
for e in self.prefs.keep_folders(&mut p) {
|
||||
log::warn!("{e}");
|
||||
}
|
||||
// The edit the active tool computes on another thread is applied first (the Preferences
|
||||
// dialog applies its settings here, outside a command). A failure to apply it was the
|
||||
// edit's own, and the preferences apply all the same.
|
||||
if self.depth == 0 {
|
||||
let _ = self.finish_tool_edit_later();
|
||||
}
|
||||
let grid_changed = p.gridline_every != self.prefs.gridline_every || p.grid_subdivisions != self.prefs.grid_subdivisions;
|
||||
let history_changed = p.history_states != self.prefs.history_states;
|
||||
let tile_edge_changed = p.pattern_tile_edge_color != self.prefs.pattern_tile_edge_color;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{NodeId, Value, cmd};
|
||||
use super::{NodeId, Value, cmd, find_command};
|
||||
|
||||
/// The commands that act on the active artboard (#693), which the app passes as their `artboard`:
|
||||
/// Paste in Place, in Front and in Back paste onto it, Align to Artboard aligns to it, Distribute
|
||||
@@ -78,6 +78,34 @@ pub(crate) fn strip_replay_only(id: &str, p: &mut Value) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Queries that apply the edit the active tool is computing before they run, as edits do
|
||||
/// ([`Session::finish_tool_edit`]): a batch runs edits, Find Objects with `select`, Select All
|
||||
/// Instances and Lock Guides change the selection, and the proof views, the preferences and added
|
||||
/// fonts give the documents new revisions (they draw again, and type lays out again).
|
||||
const WAIT_FOR_TOOL_EDIT: &[&str] = &[
|
||||
"command.batch",
|
||||
"document.find",
|
||||
"symbol.selectInstances",
|
||||
"view.guides.lock",
|
||||
"view.proofSetup",
|
||||
"view.proofColors",
|
||||
"view.overprintPreview",
|
||||
"view.separationsPreview",
|
||||
"prefs.set",
|
||||
"prefs.reset",
|
||||
"text.addFontFiles",
|
||||
];
|
||||
|
||||
/// Does command `id`, run on its own, first apply the edit the active tool is computing on
|
||||
/// another thread and the input held for it ([`Session::finish_tool_edit`])? Every command that
|
||||
/// can edit, select, save or give a document a new revision does; queries that only read do not
|
||||
/// (`commands_that_do_not_wait_for_a_tool_edit_change_no_document` in the command sweep checks
|
||||
/// them). A frontend that adds params from
|
||||
/// its own state (the active artboard) applies them first itself.
|
||||
pub fn waits_for_tool_edit(id: &str) -> bool {
|
||||
find_command(id).is_some_and(|spec| spec.journal || WAIT_FOR_TOOL_EDIT.contains(&id))
|
||||
}
|
||||
|
||||
/// Journaled commands that write a file and change nothing in the document: with an object of a
|
||||
/// dynamic symbol instance's art selected, they read the instance as queries do
|
||||
/// ([`crate::Session::execute`]).
|
||||
|
||||
@@ -62,6 +62,19 @@ pub struct Session {
|
||||
/// While Cmd lends `tool` (a selection tool) for a drag: the tool it was lent to, which comes
|
||||
/// back as it was at the release ([`Session::pointer`]).
|
||||
pub(crate) lender: Option<Box<dyn Tool>>,
|
||||
/// Pointer and key input that came while the tool computed an edit on another thread, each with
|
||||
/// its number and view, made in order once the edit is applied.
|
||||
held_input: std::collections::VecDeque<(u64, tooling::HeldInput, ViewInfo)>,
|
||||
/// The number the next pointer or key event handed to the session gets.
|
||||
input_count: u64,
|
||||
/// The number of the event whose handling started the edit the tool is computing.
|
||||
edit_started_by: Option<u64>,
|
||||
/// Set while the tool's edit and the input held for it are applied: the commands that run then
|
||||
/// do not start applying them again.
|
||||
settling_tool_edit: bool,
|
||||
/// Requests for the UI from making held input where nothing could take them (a command, a tool
|
||||
/// switch), which the next [`Session::tool_poll`] returns.
|
||||
held_ui: Vec<UiRequest>,
|
||||
/// The active document (its uid) and its [`History::step`] when the tool last handled a pointer
|
||||
/// event or drew its overlays: when they differ at the next one, the tool is told first
|
||||
/// ([`vectorcraft_tools::Tool::history_moved`]). None until the first.
|
||||
@@ -308,7 +321,7 @@ mod session;
|
||||
pub(crate) use command_sets::SELECTS_GIVEN_IDS;
|
||||
#[cfg(test)]
|
||||
use command_sets::given_ids;
|
||||
pub use command_sets::{FIT_ACTIVE_ARTBOARD, ON_ACTIVE_ARTBOARD};
|
||||
pub use command_sets::{FIT_ACTIVE_ARTBOARD, ON_ACTIVE_ARTBOARD, waits_for_tool_edit};
|
||||
pub use doc_state::{DocState, OpenRows, RecalledSelection};
|
||||
pub use error::{EngineError, Result};
|
||||
pub use history::{History, HistoryEntry, NamedStep, default_history_budget};
|
||||
|
||||
@@ -176,7 +176,7 @@ pub struct Prefs {
|
||||
pub system_title_bar: bool,
|
||||
/// Linux and the BSDs: draw the app bar as the title bar in sessions where the desktop draws
|
||||
/// the frame (X11, Wayland compositors with server-side decorations, XWayland), as on GNOME.
|
||||
/// Read when the app starts; System Title Bar and `VECTORCRAFT_TITLEBAR` take precedence over it.
|
||||
/// Read when the app starts; System Title Bar and `VECTORCRAFT_TITLEBAR` set to `app`, `system` or `desktop` take precedence over it.
|
||||
pub app_title_bar: bool,
|
||||
// Performance
|
||||
pub gpu_performance: bool,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::command_sets::{JOURNALED_READS, SELECTS_GIVEN_IDS, given_ids, strip_replay_only};
|
||||
use super::command_sets::{JOURNALED_READS, SELECTS_GIVEN_IDS, given_ids, strip_replay_only, waits_for_tool_edit};
|
||||
use super::doc_state::DocState;
|
||||
use super::error::{EngineError, Result};
|
||||
use super::history::NamedStep;
|
||||
|
||||
@@ -46,6 +46,11 @@ impl Session {
|
||||
journal: Journal::default(),
|
||||
tool: vectorcraft_tools::create("selection"),
|
||||
lender: None,
|
||||
held_input: Default::default(),
|
||||
input_count: 0,
|
||||
edit_started_by: None,
|
||||
settling_tool_edit: false,
|
||||
held_ui: vec![],
|
||||
tool_step: None,
|
||||
selection_at_lend: None,
|
||||
lent_selection: None,
|
||||
@@ -160,6 +165,9 @@ impl Session {
|
||||
}
|
||||
self.press_type_selection = None;
|
||||
let view = self.last_view;
|
||||
// The edit the tool computes on another thread and the input held for it belong to the
|
||||
// document being left. The switch goes on whatever they did, as for the deactivation.
|
||||
let _ = self.finish_tool_edit_later();
|
||||
// The switch goes on whatever the lent tool's last actions did, as for the deactivation.
|
||||
let _ = self.give_back_tool(view);
|
||||
let acts = self.with_tool_cx(view, |t, cx| t.deactivate(cx));
|
||||
|
||||
@@ -230,6 +230,11 @@ impl Session {
|
||||
if label != "Typing" && cmd::typing_in_progress(self) {
|
||||
cmd::settle_interaction(self)?;
|
||||
}
|
||||
// An edit the tool computes on another thread (a Shape Builder merge) is applied first too,
|
||||
// so the snapshot the interaction previews from and goes back to holds it.
|
||||
if !self.in_interaction() {
|
||||
self.finish_tool_edit_later()?;
|
||||
}
|
||||
self.clear_deferred_overlay_cache();
|
||||
let paint = self.paint.clone();
|
||||
let st = self.doc_mut()?;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::{
|
||||
CommandSpec, EngineError, JOURNALED_READS, NodeId, Result, SELECTS_GIVEN_IDS, Selection, Session, Value, cmd, find_command, given_ids, guard,
|
||||
strip_replay_only,
|
||||
strip_replay_only, waits_for_tool_edit,
|
||||
};
|
||||
|
||||
impl Session {
|
||||
@@ -39,6 +39,12 @@ impl Session {
|
||||
/// Execute a command by id. This is THE entry point for every frontend.
|
||||
pub fn execute(&mut self, id: &str, params: &Value) -> Result<Value> {
|
||||
let spec = find_command(id).ok_or_else(|| cmd::params::unknown_command(id))?;
|
||||
// An edit the active tool is computing on another thread (a Shape Builder merge) is
|
||||
// applied before a command that may edit, select, save or give a document a new revision,
|
||||
// as the click came first. Queries that only read do not wait for it.
|
||||
if self.depth == 0 && waits_for_tool_edit(id) {
|
||||
self.finish_tool_edit_later()?;
|
||||
}
|
||||
let outer = std::mem::replace(&mut self.reading, !spec.journal || JOURNALED_READS.contains(&id));
|
||||
let r = self.execute_spec(spec, id, params);
|
||||
self.reading = outer;
|
||||
|
||||
@@ -207,6 +207,10 @@ impl Session {
|
||||
/// [`Session::end_undo_scope`]: open an undo group there or, when one is open already, join it,
|
||||
/// so that the edits are part of its step. `None` without a document.
|
||||
pub fn begin_undo_scope(&mut self) -> Option<UndoScope> {
|
||||
// An edit the tool computes on another thread is a step before the scope, so the scope's
|
||||
// snapshot holds it. A failure to apply it was the edit's own, and the scope begins all the
|
||||
// same.
|
||||
let _ = self.finish_tool_edit_later();
|
||||
let journal = self.journal.len();
|
||||
let st = self.active()?;
|
||||
let uid = st.uid;
|
||||
|
||||
@@ -607,6 +607,486 @@ fn shape_builder_merge_uses_the_map_the_tool_has() {
|
||||
assert_eq!(maps_built(), built + 1, "another gap");
|
||||
}
|
||||
|
||||
/// 40 squares 20 pt wide in a row, each 10 pt right of the one before (160 segments, which the
|
||||
/// Shape Builder merges on another thread), all selected.
|
||||
fn square_row(s: &mut Session) -> Vec<NodeId> {
|
||||
let ids: Vec<NodeId> = (0..40).map(|k| rect(s, f64::from(k) * 10.0, 0.0, 20.0, 20.0)).collect();
|
||||
s.execute("select.set", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})).unwrap();
|
||||
ids
|
||||
}
|
||||
|
||||
/// The active document of `s` without its dates, so documents made in two sessions at different
|
||||
/// times compare equal when their art is.
|
||||
fn undated(s: &Session) -> vectorcraft_doc::Document {
|
||||
let mut d = (*s.doc().unwrap().doc).clone();
|
||||
(d.metadata.created, d.metadata.modified) = (None, None);
|
||||
d
|
||||
}
|
||||
|
||||
/// The Shape Builder over [`square_row`], its map built, after a click at (15, 10): the merge is
|
||||
/// being computed on another thread, and the document is as it was.
|
||||
fn click_row(s: &mut Session, v: ViewInfo) {
|
||||
s.select_tool("shapeBuilder", v).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Move, 15.0, 10.0), v).unwrap();
|
||||
s.tool_poll(v, true).unwrap();
|
||||
let revision = s.doc().unwrap().revision;
|
||||
s.pointer(&PointerEvent::new(PointerKind::Down, 15.0, 10.0), v).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Up, 15.0, 10.0), v).unwrap();
|
||||
assert!(s.tool_editing() && s.tool_waiting());
|
||||
assert_eq!(s.doc().unwrap().revision, revision, "the release returns before the merge is applied");
|
||||
}
|
||||
|
||||
/// A click of the Shape Builder on a large selection merges on another thread, and the merge the
|
||||
/// next poll applies is the command's own, as one undo step.
|
||||
#[test]
|
||||
fn shape_builder_merges_a_large_selection_on_another_thread() {
|
||||
use vectorcraft_tools::builder::merges_computed;
|
||||
let v = ViewInfo::default();
|
||||
let mut s = session();
|
||||
square_row(&mut s);
|
||||
click_row(&mut s, v);
|
||||
let computed = merges_computed();
|
||||
s.tool_poll(v, true).unwrap();
|
||||
assert!(!s.tool_editing());
|
||||
assert_eq!(merges_computed(), computed, "the command takes the merge computed on another thread");
|
||||
assert_eq!(s.journal.last().unwrap().0, "shapeBuilder.merge");
|
||||
assert_eq!(layer_children(&s), 41, "the overlap and what is left of the two squares over it");
|
||||
let mut direct = session();
|
||||
square_row(&mut direct);
|
||||
direct.execute("shapeBuilder.merge", &json!({"points": [[15, 10]]})).unwrap();
|
||||
assert!(undated(&s) == undated(&direct), "the same document as the command gives");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(layer_children(&s), 40, "one undo step");
|
||||
}
|
||||
|
||||
/// What comes after a click whose merge is being computed on another thread waits for the merge
|
||||
/// and runs on the merged art, as when the merge ran on the calling thread: a command (an edit,
|
||||
/// an undo, a selection, a save, a batch, Lock Guides, the proof views, a preference, Add Font
|
||||
/// Files), an option change, another tool, a save made outside a command, preferences applied
|
||||
/// outside a command, a dialog's preview, a scrubbed field's undo scope, a Cmd-click or Cmd-drag
|
||||
/// with the selection tool. The merge is the one computed on the other thread.
|
||||
#[test]
|
||||
fn shape_builder_applies_a_merge_before_what_comes_next() {
|
||||
use vectorcraft_tools::builder::merges_computed;
|
||||
type Next = (&'static str, fn(&mut Session, &[NodeId], &std::path::Path));
|
||||
let v = ViewInfo::default();
|
||||
let next: Vec<Next> = vec![
|
||||
("Select All Instances", |s, _, _| {
|
||||
s.execute("symbol.selectInstances", &json!({"name": "S"})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().selection.objects.len(), 1);
|
||||
}),
|
||||
("an edit", |s, _, _| {
|
||||
s.execute("object.move", &json!({"dx": 0, "dy": 100})).unwrap();
|
||||
}),
|
||||
("an undo", |s, _, _| {
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(layer_children(s), 40, "the undo takes the merge back");
|
||||
s.execute("edit.redo", &json!({})).unwrap();
|
||||
}),
|
||||
("another selection", |s, _, _| {
|
||||
s.execute("select.inverse", &json!({})).unwrap();
|
||||
}),
|
||||
("Select All", |s, _, _| {
|
||||
s.execute("select.all", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().selection.objects.len(), 41);
|
||||
}),
|
||||
("a save", |s, _, dir| {
|
||||
s.execute("file.saveAs", &json!({"path": dir.join("a.vectorcraft").to_string_lossy()})).unwrap();
|
||||
assert!(!s.doc().unwrap().is_dirty(), "the file holds the merge");
|
||||
}),
|
||||
("a save outside a command", |s, _, dir| {
|
||||
let p = json!({"path": dir.join("b.vectorcraft").to_string_lossy()});
|
||||
let plan = cmd::fileio::save_plan(s, cmd::fileio::SaveMode::SaveAs, &p).unwrap();
|
||||
assert_eq!(layer_children(s), 40, "planning a save leaves the document");
|
||||
let job = cmd::fileio::save_job(s, plan).unwrap();
|
||||
assert_eq!(layer_children(s), 41, "the snapshot is taken after the merge");
|
||||
drop(job);
|
||||
}),
|
||||
("a batch", |s, _, _| {
|
||||
s.execute("command.batch", &json!({"commands": [{"command": "object.move", "params": {"dx": 0, "dy": 50}}]})).unwrap();
|
||||
}),
|
||||
("an option change", |s, _, _| {
|
||||
s.set_tool_option_cmd(&json!({"key": "gapDetection", "value": true})).unwrap();
|
||||
}),
|
||||
("another tool", |s, _, _| {
|
||||
s.select_tool("selection", ViewInfo::default()).unwrap();
|
||||
}),
|
||||
("a closed document", |s, _, _| {
|
||||
s.execute("file.close", &json!({})).unwrap();
|
||||
}),
|
||||
("Lock Guides", |s, _, _| {
|
||||
s.execute("view.guides.lock", &json!({"locked": true})).unwrap();
|
||||
}),
|
||||
("an option set from a panel", |s, _, _| {
|
||||
s.set_tool_option("gapDetection", &json!(true));
|
||||
}),
|
||||
("a dialog's preview, canceled", |s, _, _| {
|
||||
s.begin_interaction("Move").unwrap();
|
||||
s.preview("object.move", &json!({"dx": 7, "dy": 0})).unwrap();
|
||||
s.preview("object.move", &json!({"dx": 9, "dy": 0})).unwrap();
|
||||
s.cancel_interaction().unwrap();
|
||||
assert_eq!(layer_children(s), 41, "canceling the preview keeps the merge");
|
||||
}),
|
||||
("a dialog's preview, kept", |s, _, _| {
|
||||
s.begin_interaction("Move").unwrap();
|
||||
s.preview("object.move", &json!({"dx": 7, "dy": 0})).unwrap();
|
||||
s.commit_interaction().unwrap();
|
||||
let labels: Vec<&str> = s.doc().unwrap().history.undo.iter().rev().take(2).map(|e| e.label.as_str()).collect();
|
||||
assert_eq!(labels, ["Move", "Shape Builder"]);
|
||||
}),
|
||||
("a scrubbed field, canceled", |s, _, _| {
|
||||
let scope = s.begin_undo_scope().unwrap();
|
||||
s.execute("object.move", &json!({"dx": 5, "dy": 0})).unwrap();
|
||||
s.end_undo_scope(scope, true);
|
||||
assert_eq!(
|
||||
s.doc().unwrap().history.undo.last().map(|e| e.label.as_str()),
|
||||
Some("Shape Builder"),
|
||||
"the scrub's step is undone, not the merge"
|
||||
);
|
||||
}),
|
||||
("a held click, then another tool", |s, _, _| {
|
||||
let v = ViewInfo::default();
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(&PointerEvent::new(kind, 55.0, 10.0), v).unwrap();
|
||||
}
|
||||
assert!(s.tool_editing(), "the click is held");
|
||||
s.select_tool("selection", v).unwrap();
|
||||
let labels: Vec<&str> = s.doc().unwrap().history.undo.iter().rev().take(2).map(|e| e.label.as_str()).collect();
|
||||
assert_eq!(labels, ["Shape Builder", "Shape Builder"], "the held click merges with the Shape Builder first");
|
||||
}),
|
||||
("a held click, then another document", |s, _, _| {
|
||||
let v = ViewInfo::default();
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(&PointerEvent::new(kind, 55.0, 10.0), v).unwrap();
|
||||
}
|
||||
let first = s.active_index().unwrap();
|
||||
s.add_document(vectorcraft_doc::Document::new(100.0, 100.0), None);
|
||||
assert!(!s.tool_editing());
|
||||
let labels: Vec<&str> = s.documents()[first].history.undo.iter().rev().take(2).map(|e| e.label.as_str()).collect();
|
||||
assert_eq!(labels, ["Shape Builder", "Shape Builder"], "the held click merges in its own document first");
|
||||
s.set_active(first);
|
||||
}),
|
||||
("a Cmd-click", |s, _, _| {
|
||||
let v = ViewInfo::default();
|
||||
let cmd = Mods { cmd: true, ..Default::default() };
|
||||
assert_eq!(s.cursor(Point::new(500.0, 300.0), cmd, v), vectorcraft_tools::Cursor::Busy, "Cmd shows the merge is computed");
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(&PointerEvent::new(kind, 500.0, 300.0).with_mods(cmd), v).unwrap();
|
||||
}
|
||||
assert!(s.tool_editing(), "the click is held");
|
||||
while s.tool_waiting() {
|
||||
s.tool_poll(v, true).unwrap();
|
||||
}
|
||||
assert!(s.doc().unwrap().selection.is_empty(), "the lent selection tool deselects after the merge");
|
||||
assert_eq!(s.tool_id(), "shapeBuilder");
|
||||
}),
|
||||
("a Cmd-drag", |s, _, _| {
|
||||
let v = ViewInfo::default();
|
||||
let cmd = Mods { cmd: true, ..Default::default() };
|
||||
for (kind, y) in [(PointerKind::Down, 10.0), (PointerKind::Drag, 60.0), (PointerKind::Drag, 110.0), (PointerKind::Up, 110.0)] {
|
||||
s.pointer(&PointerEvent::new(kind, 305.0, y).with_mods(cmd), v).unwrap();
|
||||
}
|
||||
assert!(s.tool_editing(), "the drag is held");
|
||||
while s.tool_waiting() {
|
||||
s.tool_poll(v, true).unwrap();
|
||||
}
|
||||
let labels: Vec<&str> = s.doc().unwrap().history.undo.iter().rev().take(2).map(|e| e.label.as_str()).collect();
|
||||
assert_eq!(labels, ["Move", "Shape Builder"]);
|
||||
}),
|
||||
// The proof views redraw every document (a new revision); they are left off, as the
|
||||
// other tests of the process-wide proof view expect.
|
||||
("Separations Preview", |s, _, _| {
|
||||
s.execute("view.separationsPreview", &json!({"on": false})).unwrap();
|
||||
}),
|
||||
("Overprint Preview", |s, _, _| {
|
||||
s.execute("view.overprintPreview", &json!({"on": false})).unwrap();
|
||||
}),
|
||||
("Proof Colors", |s, _, _| {
|
||||
s.execute("view.proofColors", &json!({"on": false})).unwrap();
|
||||
}),
|
||||
("Proof Setup", |s, _, _| {
|
||||
s.execute("view.proofSetup", &json!({})).unwrap();
|
||||
}),
|
||||
("a preference", |s, _, _| {
|
||||
let every = s.prefs.gridline_every;
|
||||
s.execute("prefs.set", &json!({"key": "gridlineEvery", "value": every + 10.0})).unwrap();
|
||||
}),
|
||||
("Reset Preferences", |s, _, _| {
|
||||
s.execute("prefs.reset", &json!({})).unwrap();
|
||||
}),
|
||||
("preferences applied outside a command", |s, _, _| {
|
||||
let mut p = s.prefs.clone();
|
||||
p.gridline_every += 10.0;
|
||||
s.apply_prefs(p);
|
||||
}),
|
||||
("Add Font Files", |s, _, _| {
|
||||
// No files: the command fails after the merge.
|
||||
assert!(s.execute("text.addFontFiles", &json!({"files": []})).is_err());
|
||||
}),
|
||||
];
|
||||
let _proof = crate::tests_colormgmt::GLOBAL.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let dir = vectorcraft_testkit::temp_dir("shape-builder-merge-first");
|
||||
for (what, then) in next {
|
||||
let mut s = session();
|
||||
if what == "Select All Instances" {
|
||||
let far = rect(&mut s, 500.0, 500.0, 20.0, 20.0);
|
||||
s.execute("symbol.new", &json!({"name": "S", "ids": [far.0]})).unwrap();
|
||||
}
|
||||
let ids = square_row(&mut s);
|
||||
click_row(&mut s, v);
|
||||
let computed = merges_computed();
|
||||
let journal = s.journal.len();
|
||||
then(&mut s, &ids, &dir);
|
||||
assert!(!s.tool_editing(), "{what}");
|
||||
assert_eq!(merges_computed(), computed, "{what}: the merge computed on another thread");
|
||||
assert_eq!(s.journal.since(journal).first().map(|j| j.0.as_str()), Some("shapeBuilder.merge"), "{what}: the merge comes first");
|
||||
if what != "a closed document" {
|
||||
assert!(layer_children(&s) >= 41, "{what}: the merge stays");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Gestures and arrow keys that come while a merge is computed on another thread are held and
|
||||
/// made after it, in order: the document is the one they make one after the other, and the
|
||||
/// events count as made once they are and the merge they start is applied.
|
||||
#[test]
|
||||
fn shape_builder_holds_gestures_made_during_a_merge() {
|
||||
type Gesture = fn(&mut Session, ViewInfo);
|
||||
let cases: [(&str, bool, Gesture); 6] = [
|
||||
("a second click", false, |s, v| {
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(&PointerEvent::new(kind, 55.0, 10.0), v).unwrap();
|
||||
}
|
||||
}),
|
||||
("a drag", false, |s, v| {
|
||||
for (kind, x) in [(PointerKind::Down, 75.0), (PointerKind::Drag, 85.0), (PointerKind::Drag, 95.0), (PointerKind::Up, 95.0)] {
|
||||
s.pointer(&PointerEvent::new(kind, x, 10.0), v).unwrap();
|
||||
}
|
||||
}),
|
||||
("two clicks", false, |s, v| {
|
||||
for x in [55.0, 135.0] {
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(&PointerEvent::new(kind, x, 10.0), v).unwrap();
|
||||
}
|
||||
}
|
||||
}),
|
||||
("a Cmd-click", false, |s, v| {
|
||||
let cmd = Mods { cmd: true, ..Default::default() };
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(&PointerEvent::new(kind, 500.0, 300.0).with_mods(cmd), v).unwrap();
|
||||
}
|
||||
}),
|
||||
("a Cmd-drag and a click", false, |s, v| {
|
||||
let cmd = Mods { cmd: true, ..Default::default() };
|
||||
for (kind, y) in [(PointerKind::Down, 10.0), (PointerKind::Drag, 110.0), (PointerKind::Up, 110.0)] {
|
||||
s.pointer(&PointerEvent::new(kind, 305.0, y).with_mods(cmd), v).unwrap();
|
||||
}
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(&PointerEvent::new(kind, 55.0, 10.0), v).unwrap();
|
||||
}
|
||||
}),
|
||||
("an arrow key", true, |s, v| {
|
||||
s.tool_key(ToolKey::Right, Mods::default(), v).unwrap();
|
||||
}),
|
||||
];
|
||||
let v = ViewInfo::default();
|
||||
let start = |swatches: bool| {
|
||||
let mut s = session();
|
||||
if swatches {
|
||||
s.select_tool("shapeBuilder", v).unwrap();
|
||||
s.set_tool_option_cmd(&json!({"key": "pickColorFrom", "value": "swatches"})).unwrap();
|
||||
}
|
||||
square_row(&mut s);
|
||||
click_row(&mut s, v);
|
||||
s
|
||||
};
|
||||
for (what, swatches, send) in cases {
|
||||
// One after the other: the merge applied before the gesture, and each merge after its own.
|
||||
let mut one = start(swatches);
|
||||
while one.tool_waiting() {
|
||||
one.tool_poll(v, true).unwrap();
|
||||
}
|
||||
send(&mut one, v);
|
||||
while one.tool_waiting() {
|
||||
one.tool_poll(v, true).unwrap();
|
||||
}
|
||||
// While the merge is computed.
|
||||
let mut s = start(swatches);
|
||||
let revision = s.doc().unwrap().revision;
|
||||
let from = s.input_count();
|
||||
send(&mut s, v);
|
||||
let to = s.input_count();
|
||||
assert!(s.tool_editing() && !s.input_applied(from, to), "{what}: held");
|
||||
assert_eq!(s.doc().unwrap().revision, revision, "{what}: nothing made before the merge");
|
||||
while s.tool_waiting() {
|
||||
s.tool_poll(v, true).unwrap();
|
||||
}
|
||||
assert!(!s.tool_editing() && s.input_applied(from, to), "{what}");
|
||||
assert!(undated(&s) == undated(&one), "{what}: the document the gestures make one after the other");
|
||||
assert_eq!(s.doc().unwrap().selection, one.doc().unwrap().selection, "{what}");
|
||||
assert_eq!(s.paint.fill, one.paint.fill, "{what}");
|
||||
let labels = |s: &Session| s.doc().unwrap().history.undo.iter().map(|e| e.label.clone()).collect::<Vec<_>>();
|
||||
assert_eq!(labels(&s), labels(&one), "{what}");
|
||||
// The click's merge alone.
|
||||
let mut merged = start(swatches);
|
||||
while merged.tool_waiting() {
|
||||
merged.tool_poll(v, true).unwrap();
|
||||
}
|
||||
let changed = labels(&s).len() > labels(&merged).len()
|
||||
|| s.paint.fill != merged.paint.fill
|
||||
|| s.doc().unwrap().selection != merged.doc().unwrap().selection;
|
||||
assert!(changed, "{what}: the gesture did something");
|
||||
}
|
||||
}
|
||||
|
||||
/// A press held while a merge is computed on another thread, then dropped (a long touch, a
|
||||
/// canceled touch, a second finger), is never made: once the merge is applied, the tool is at
|
||||
/// rest and the document is the one the same input makes, dropped the same way, after the merge.
|
||||
/// A held click before the press is still made, and so is a perspective plane key held after it.
|
||||
#[test]
|
||||
fn shape_builder_drops_a_press_held_during_a_merge() {
|
||||
use vectorcraft_tools::distort::perspective::{PerspectiveGrid, Plane};
|
||||
type Gesture = fn(&mut Session, ViewInfo);
|
||||
fn press(s: &mut Session, v: ViewInfo, x: f64, mods: Mods) {
|
||||
s.pointer(&PointerEvent::new(PointerKind::Down, x, 10.0).with_mods(mods), v).unwrap();
|
||||
}
|
||||
fn click(s: &mut Session, v: ViewInfo) {
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(&PointerEvent::new(kind, 55.0, 10.0), v).unwrap();
|
||||
}
|
||||
}
|
||||
// What a case sends, and whether the perspective grid is shown.
|
||||
let cases: [(&str, bool, Gesture); 7] = [
|
||||
("a press", false, |s, v| press(s, v, 75.0, Mods::default())),
|
||||
("a drag", false, |s, v| {
|
||||
press(s, v, 75.0, Mods::default());
|
||||
s.pointer(&PointerEvent::new(PointerKind::Drag, 95.0, 10.0), v).unwrap();
|
||||
}),
|
||||
("a Cmd-press", false, |s, v| press(s, v, 305.0, Mods { cmd: true, ..Default::default() })),
|
||||
("a press and a key", false, |s, v| {
|
||||
press(s, v, 75.0, Mods::default());
|
||||
s.tool_key(ToolKey::Escape, Mods::default(), v).unwrap();
|
||||
}),
|
||||
("a press and an arrow key", false, |s, v| {
|
||||
press(s, v, 75.0, Mods::default());
|
||||
s.tool_key(ToolKey::Right, Mods::default(), v).unwrap();
|
||||
}),
|
||||
("a press and a plane key", true, |s, v| {
|
||||
press(s, v, 75.0, Mods::default());
|
||||
s.tool_key(ToolKey::Digit(3), Mods::default(), v).unwrap();
|
||||
}),
|
||||
("a click, then a press", false, |s, v| {
|
||||
click(s, v);
|
||||
press(s, v, 135.0, Mods::default());
|
||||
}),
|
||||
];
|
||||
let v = ViewInfo::default();
|
||||
let start = |grid: bool| {
|
||||
let mut s = session();
|
||||
s.select_tool("shapeBuilder", v).unwrap();
|
||||
s.set_tool_option_cmd(&json!({"key": "pickColorFrom", "value": "swatches"})).unwrap();
|
||||
if grid {
|
||||
s.execute("perspective.grid.preset", &json!({"kind": 2})).unwrap();
|
||||
}
|
||||
square_row(&mut s);
|
||||
click_row(&mut s, v);
|
||||
s
|
||||
};
|
||||
// A tool left in the middle of a gesture keeps waiting: the polls stop after a few.
|
||||
let settle = |s: &mut Session| {
|
||||
for _ in 0..8 {
|
||||
if !s.tool_waiting() {
|
||||
return;
|
||||
}
|
||||
s.tool_poll(v, true).unwrap();
|
||||
}
|
||||
};
|
||||
let labels = |s: &Session| s.doc().unwrap().history.undo.iter().map(|e| e.label.clone()).collect::<Vec<_>>();
|
||||
let plane = |s: &Session| PerspectiveGrid::from_doc(&s.doc().unwrap().doc).unwrap().plane;
|
||||
for (what, grid, send) in cases {
|
||||
// The same input after the merge, dropped the same way.
|
||||
let mut one = start(grid);
|
||||
settle(&mut one);
|
||||
send(&mut one, v);
|
||||
one.drop_tool_press(v).unwrap();
|
||||
settle(&mut one);
|
||||
let mut s = start(grid);
|
||||
if grid {
|
||||
assert_ne!(plane(&s), Plane::Right, "{what}: the plane before the key");
|
||||
}
|
||||
let from = s.input_count();
|
||||
send(&mut s, v);
|
||||
let to = s.input_count();
|
||||
assert!(s.tool_editing() && !s.input_applied(from, to), "{what}: held");
|
||||
s.drop_tool_press(v).unwrap();
|
||||
settle(&mut s);
|
||||
assert!(!s.tool_waiting() && !s.tool_editing() && s.input_applied(from, to), "{what}");
|
||||
assert!(!s.tool_busy(), "{what}: the tool is at rest");
|
||||
assert_eq!(s.tool_id(), "shapeBuilder", "{what}: no tool is lent");
|
||||
assert!(undated(&s) == undated(&one), "{what}: the document the input makes after the merge");
|
||||
assert_eq!(labels(&s), labels(&one), "{what}");
|
||||
assert_eq!(s.doc().unwrap().selection, one.doc().unwrap().selection, "{what}");
|
||||
assert_eq!(s.paint.fill, one.paint.fill, "{what}");
|
||||
if grid {
|
||||
assert_eq!(plane(&one), Plane::Right, "{what}: the plane key is made after the merge");
|
||||
assert_eq!(plane(&s), Plane::Right, "{what}: the plane key is made");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A new revision of the document made outside a command while a merge is computed on another
|
||||
/// thread keeps the merge when the selected art is as it was (the next poll applies it, as the
|
||||
/// command computes it), and drops it when the art changed.
|
||||
#[test]
|
||||
fn shape_builder_keeps_a_merge_over_a_new_revision_of_the_same_art() {
|
||||
use vectorcraft_tools::builder::merges_computed;
|
||||
let v = ViewInfo::default();
|
||||
let mut s = session();
|
||||
square_row(&mut s);
|
||||
click_row(&mut s, v);
|
||||
let computed = merges_computed();
|
||||
s.active_mut().unwrap().revision += 1;
|
||||
s.tool_poll(v, true).unwrap();
|
||||
assert!(!s.tool_editing());
|
||||
assert_eq!(merges_computed(), computed, "the merge computed on another thread");
|
||||
assert_eq!(s.journal.last().unwrap().0, "shapeBuilder.merge");
|
||||
let mut direct = session();
|
||||
square_row(&mut direct);
|
||||
direct.execute("shapeBuilder.merge", &json!({"points": [[15, 10]]})).unwrap();
|
||||
assert!(undated(&s) == undated(&direct), "the same document as the command gives");
|
||||
// The art changed: the merge is dropped.
|
||||
let mut s = session();
|
||||
let ids = square_row(&mut s);
|
||||
click_row(&mut s, v);
|
||||
let journal = s.journal.len();
|
||||
let st = s.active_mut().unwrap();
|
||||
Arc::make_mut(&mut st.doc).node_mut(ids[1]).unwrap().transform(Affine::translate((0.0, 50.0)), false);
|
||||
st.revision += 1;
|
||||
s.tool_poll(v, true).unwrap();
|
||||
assert!(!s.tool_editing());
|
||||
assert_eq!(s.journal.len(), journal, "nothing merged");
|
||||
assert_eq!(layer_children(&s), 40);
|
||||
}
|
||||
|
||||
/// A merge computed for the tool Cmd lent the selection tool's drag away from is applied before
|
||||
/// a command too.
|
||||
#[test]
|
||||
fn shape_builder_merge_of_the_lending_tool_comes_first() {
|
||||
let v = ViewInfo::default();
|
||||
let mut s = session();
|
||||
square_row(&mut s);
|
||||
click_row(&mut s, v);
|
||||
let lent = s.make_tool("selection");
|
||||
s.lender = Some(std::mem::replace(&mut s.tool, lent));
|
||||
assert!(s.tool_editing());
|
||||
let journal = s.journal.len();
|
||||
s.execute("object.move", &json!({"dx": 0, "dy": 100})).unwrap();
|
||||
assert!(!s.tool_editing());
|
||||
assert_eq!(s.journal.since(journal).first().map(|j| j.0.as_str()), Some("shapeBuilder.merge"));
|
||||
assert_eq!(s.tool_id(), "selection", "the lent tool stays active until the release");
|
||||
assert_eq!(s.lender.as_ref().map(|t| t.id()), Some("shapeBuilder"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shape_builder_tool_merges_the_narrow_shape_it_highlights_in_a_wide_selection() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -177,6 +177,208 @@ fn export_options_pass_every_listed_key() {
|
||||
}
|
||||
}
|
||||
|
||||
const SAVES: [&str; 4] = ["document.save", "file.saveAs", "file.saveCopy", "file.saveAsTemplate"];
|
||||
|
||||
/// A save refuses a key no save format reads, beside the path, in `options` and in the PDF and
|
||||
/// SVG objects of either, under each save command.
|
||||
#[test]
|
||||
fn save_options_refuse_a_key_no_save_format_reads() {
|
||||
let why = "no save format takes it (see file.formatOptions)";
|
||||
for id in SAVES {
|
||||
assert_eq!(refusal(id, json!({"path": "a.pdf", "noSuchOption": true})), format!("unknown parameter `noSuchOption`; {why}"));
|
||||
assert_eq!(
|
||||
refusal(id, json!({"path": "a.pdf", "options": {"noSuchOption": true}})),
|
||||
format!("unknown parameter `options.noSuchOption`; {why}")
|
||||
);
|
||||
assert_eq!(refusal(id, json!({"compres": true})), "unknown parameter `compres`; did you mean `compress`?");
|
||||
assert_eq!(refusal(id, json!({"options": {"compres": true}})), "unknown parameter `options.compres`; did you mean `options.compress`?");
|
||||
// An export's own key is not a save's.
|
||||
assert_eq!(refusal(id, json!({"path": "a.png", "quality": 80})), format!("unknown parameter `quality`; {why}"));
|
||||
for (given, message) in [
|
||||
(json!({"path": "a.pdf", "marks": {"useDocumentBleed": true}}), "unknown parameter `marks.useDocumentBleed`; `marks` takes:"),
|
||||
(json!({"path": "a.pdf", "options": {"marks": {"x": 1}}}), "unknown parameter `options.marks.x`; `options.marks` takes:"),
|
||||
(json!({"path": "a.ai", "bleed": {"useDocumen": true}}), "unknown parameter `bleed.useDocumen`; did you mean `bleed.useDocument`?"),
|
||||
// The `svg` object is checked when the save writes no SVG too.
|
||||
(json!({"path": "a.pdf", "svg": {"noSuchOption": true}}), "unknown parameter `svg.noSuchOption`; `svg` takes:"),
|
||||
(
|
||||
json!({"path": "a.pdf", "options": {"svg": {"minfy": true}}}),
|
||||
"unknown parameter `options.svg.minfy`; did you mean `options.svg.minify`?",
|
||||
),
|
||||
] {
|
||||
let got = refusal(id, given.clone());
|
||||
assert!(got.starts_with(message), "{id} {given}: {got}");
|
||||
}
|
||||
// A key that another format a save writes reads still passes: the save leaves it out.
|
||||
for given in [
|
||||
json!({"path": "a.svg", "compress": true}),
|
||||
json!({"path": "a.pdf", "options": {"preview": true, "styling": "style"}}),
|
||||
json!({"path": "a.vectorcraft", "standard": "pdfX4", "marks": {"trim": true}}),
|
||||
json!({"path": "a.ai", "acknowledgeLoss": true, "modified": null, "svg": {"minify": true}}),
|
||||
json!({"path": "a.svg", "svg": {"styling": "css", "artboard": 0, "useArtboards": true}}),
|
||||
] {
|
||||
check_params(id, &given).unwrap_or_else(|e| panic!("{id} {given}: {e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A save passes each option of each format it writes, beside the path and in `options`, and
|
||||
/// each key its description names.
|
||||
#[test]
|
||||
fn save_options_pass_every_listed_key() {
|
||||
use crate::cmd::fileio::{FORMATS, SAVE_FORMATS, TEMPLATE_FORMATS};
|
||||
for f in FORMATS.iter().filter(|f| SAVE_FORMATS.contains(&f.id) || TEMPLATE_FORMATS.contains(&f.id)) {
|
||||
for o in f.options {
|
||||
for params in [json!({"format": f.id, o.name: null}), json!({"format": f.id, "options": {o.name: null}})] {
|
||||
for id in SAVES {
|
||||
check_params(id, ¶ms).unwrap_or_else(|e| panic!("{id} {params}: {e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for id in SAVES {
|
||||
let keys = doc_keys(find_command(id).unwrap().params).unwrap().keys;
|
||||
let refused: Vec<&str> = keys.into_iter().filter(|key| check_params(id, &json!({*key: null})).is_err()).collect();
|
||||
assert_eq!(refused, Vec::<&str>::new(), "{id} names and refuses these");
|
||||
}
|
||||
}
|
||||
|
||||
/// Export for Screens refuses a key it doesn't take, and in its rows and settings a key no format
|
||||
/// reads, by the row's path; `document.exportPresets.save` checks the rows of its settings.
|
||||
#[test]
|
||||
fn export_for_screens_refuses_a_key_no_format_reads() {
|
||||
let id = "document.exportForScreens";
|
||||
assert!(
|
||||
refusal(id, json!({"folder": "out", "noSuchOption": true})).starts_with("unknown parameter `noSuchOption`; the command takes: artboard, ")
|
||||
);
|
||||
assert_eq!(refusal(id, json!({"subfolder": true})), "unknown parameter `subfolder`; did you mean `subfolders`?");
|
||||
let no_format = "no format takes it (see document.formats)";
|
||||
for (given, message) in [
|
||||
(json!({"formats": [{"format": "png", "noSuchOption": 1}]}), format!("unknown parameter `formats[0].noSuchOption`; {no_format}")),
|
||||
(
|
||||
json!({"formats": [{"format": "png"}, {"format": "pdf", "marks": {"useDocumentBleed": true}}]}),
|
||||
"unknown parameter `formats[1].marks.useDocumentBleed`; `formats[1].marks` takes:".into(),
|
||||
),
|
||||
(
|
||||
json!({"formats": [{"format": "pdf", "security": {"openPasswrd": "x"}}]}),
|
||||
"unknown parameter `formats[0].security.openPasswrd`; did you mean `formats[0].security.openPassword`?".into(),
|
||||
),
|
||||
(
|
||||
json!({"formats": [{"format": "eps", "flattener": {"balanse": 50}}]}),
|
||||
"unknown parameter `formats[0].flattener.balanse`; did you mean `formats[0].flattener.balance`?".into(),
|
||||
),
|
||||
(json!({"formats": [{"format": "jpg", "sufix": "@2x"}]}), "unknown parameter `formats[0].sufix`; did you mean `formats[0].suffix`?".into()),
|
||||
(json!({"settings": {"pnj": {}}}), "unknown parameter `settings.pnj`; did you mean `settings.png`?".into()),
|
||||
(json!({"settings": {"dxf": {}}}), "unknown parameter `settings.dxf`; `settings` takes: ".into()),
|
||||
(
|
||||
json!({"settings": {"png": {"bckground": "white"}}}),
|
||||
"unknown parameter `settings.png.bckground`; did you mean `settings.png.background`?".into(),
|
||||
),
|
||||
(json!({"settings": {"pdf": {"bleed": {"top": 9, "inner": 1}}}}), "unknown parameter `settings.pdf.bleed.inner`;".into()),
|
||||
] {
|
||||
let got = refusal(id, given.clone());
|
||||
assert!(got.starts_with(&message), "{given}: {got}");
|
||||
}
|
||||
let save = "document.exportPresets.save";
|
||||
assert_eq!(
|
||||
refusal(save, json!({"name": "a", "settings": {"formats": [{"format": "png", "noSuchOption": 1}]}})),
|
||||
format!("unknown parameter `settings.formats[0].noSuchOption`; {no_format}")
|
||||
);
|
||||
assert!(
|
||||
refusal(save, json!({"name": "a", "settings": {"settings": {"pdf": {"marks": {"x": 1}}}}}))
|
||||
.starts_with("unknown parameter `settings.settings.pdf.marks.x`;")
|
||||
);
|
||||
assert_eq!(
|
||||
refusal(save, json!({"name": "a", "settings": {"formtas": [{"format": "png"}]}})),
|
||||
"unknown parameter `settings.formtas`; did you mean `settings.formats`?"
|
||||
);
|
||||
assert!(
|
||||
refusal(save, json!({"name": "a", "settings": {"noSuchOption": true}}))
|
||||
.starts_with("unknown parameter `settings.noSuchOption`; `settings` takes: artboard, ")
|
||||
);
|
||||
// Export Assets takes the same rows and settings, and stores them.
|
||||
for asset in ["assets.export", "assets.settings.set"] {
|
||||
assert_eq!(
|
||||
refusal(asset, json!({"formats": [{"format": "png", "noSuchOption": 1}]})),
|
||||
format!("unknown parameter `formats[0].noSuchOption`; {no_format}")
|
||||
);
|
||||
assert!(refusal(asset, json!({"settings": {"pdf": {"marks": {"x": 1}}}})).starts_with("unknown parameter `settings.pdf.marks.x`;"));
|
||||
check_params(asset, &json!({"formats": [{"format": "jpg", "scale": "2x", "quality": 80}]})).unwrap();
|
||||
}
|
||||
// An exporter plug-in's `params` in a row (its format is a plug-in's: tests/plugin_export.rs).
|
||||
check_params(id, &json!({"formats": [{"format": "png", "params": {}}]})).unwrap();
|
||||
// Keys the preset leaves out are still Export for Screens params.
|
||||
check_params(save, &json!({"name": "a", "settings": {"zip": true, "formats": [{"format": "jpg", "quality": 80}]}})).unwrap();
|
||||
// The encoders read Include Artboard Fill and Appearance of Black from a row or a format's
|
||||
// settings.
|
||||
for given in [
|
||||
json!({"formats": [{"format": "png", "includeArtboardFill": false, "richBlack": true}]}),
|
||||
json!({"settings": {"png": {"includeArtboardFill": false, "richBlack": true}}}),
|
||||
] {
|
||||
check_params(id, &given).unwrap_or_else(|e| panic!("{given}: {e}"));
|
||||
}
|
||||
}
|
||||
|
||||
/// Export for Screens passes each key its description names, each option of a format in a row or
|
||||
/// in settings, and the built-in presets; `settings` takes the formats a row can write.
|
||||
#[test]
|
||||
fn export_for_screens_passes_every_listed_key() {
|
||||
use crate::cmd::fileio::{FORMATS, check_screen_settings, screen_export_builtin_presets};
|
||||
let id = "document.exportForScreens";
|
||||
let keys = doc_keys(find_command(id).unwrap().params).unwrap().keys;
|
||||
assert!(keys.len() > 20, "{keys:?}");
|
||||
// The keys the check takes are the ones the description names.
|
||||
let (mut named, mut taken) = (keys.clone(), crate::cmd::fileio::SCREEN_PARAM_KEYS.to_vec());
|
||||
named.sort_unstable();
|
||||
taken.sort_unstable();
|
||||
assert_eq!(named, taken);
|
||||
let refused: Vec<&str> = keys.into_iter().filter(|key| check_params(id, &json!({*key: null})).is_err()).collect();
|
||||
assert_eq!(refused, Vec::<&str>::new(), "{id} names and refuses these");
|
||||
check_params(id, &json!({"artboard": 0, "openLocation": true})).unwrap();
|
||||
let s = Session::new();
|
||||
for f in FORMATS.iter().filter(|f| f.write) {
|
||||
for o in f.options {
|
||||
let row = json!({"formats": [{"format": "png", "scale": 2, "suffix": "", "folder": "x", o.name: null}]});
|
||||
check_params(id, &row).unwrap_or_else(|e| panic!("{row}: {e}"));
|
||||
}
|
||||
let written = check_screen_settings(&s, &json!({"formats": [{"format": f.id}]})).is_ok();
|
||||
let settings = json!({"settings": {f.id: {}}});
|
||||
assert_eq!(check_params(id, &settings).is_ok(), written, "{settings}");
|
||||
}
|
||||
for preset in screen_export_builtin_presets() {
|
||||
let settings = serde_json::Value::Object(preset.settings);
|
||||
check_params(id, &settings).unwrap_or_else(|e| panic!("{}: {e}", preset.name));
|
||||
check_params("document.exportPresets.save", &json!({"name": "a", "settings": settings})).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// A saved row loses the keys Export for Screens refuses in it, inside its object options too, and
|
||||
/// keeps the others.
|
||||
#[test]
|
||||
fn a_saved_row_drops_the_keys_no_format_reads() {
|
||||
use crate::cmd::params::drop_unread_row_options;
|
||||
let serde_json::Value::Object(mut row) = json!({
|
||||
"format": "pdf", "scale": "1x", "noSuchOption": 1, "params": {"x": 1},
|
||||
"marks": {"useDocumentBleed": true, "trim": true}, "preset": "High Quality Print",
|
||||
"security": {"passwordRequired": true, "noSuchLock": 1}
|
||||
}) else {
|
||||
panic!("an object")
|
||||
};
|
||||
drop_unread_row_options(&mut row);
|
||||
assert_eq!(
|
||||
serde_json::Value::Object(row.clone()),
|
||||
json!({
|
||||
"format": "pdf", "scale": "1x", "params": {"x": 1}, "marks": {"trim": true}, "preset": "High Quality Print",
|
||||
"security": {"passwordRequired": true}
|
||||
})
|
||||
);
|
||||
check_params("document.exportForScreens", &json!({"formats": [row]})).unwrap();
|
||||
// Remembered security whose passwords were left out, with one given again.
|
||||
let security = json!({"passwordRequired": true, "openPassword": "x"});
|
||||
for id in ["document.exportForScreens", "assets.export", "assets.settings.set"] {
|
||||
check_params(id, &json!({"formats": [{"format": "pdf", "security": security}], "settings": {"pdf": {"security": security}}})).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// `stroke.set` names every key it reads (its own, `item`, and `ids`/`id`/`target`), so a
|
||||
/// misnamed one is refused instead of answering `objects: 1` with nothing changed.
|
||||
#[test]
|
||||
|
||||
@@ -72,7 +72,7 @@ fn save_as_takes_on_path_format_and_options() {
|
||||
let d = dir("saveas");
|
||||
let mut s = session();
|
||||
let pdf = path(&d, "doc.pdf");
|
||||
s.execute("file.saveAs", &json!({"path": pdf, "options": {"range": "1", "bogus": 1}})).unwrap();
|
||||
s.execute("file.saveAs", &json!({"path": pdf, "options": {"range": "1", "preview": true}})).unwrap();
|
||||
let st = s.doc().unwrap();
|
||||
assert_eq!((st.format, st.title()), ("pdf", "doc.pdf".to_string()));
|
||||
assert_eq!(Value::Object(st.save_options.clone()), json!({"range": "1"}), "only the format's own options are kept");
|
||||
|
||||
@@ -83,6 +83,23 @@ pub enum UiRequest {
|
||||
/// Place a file with these `file.place` params: a click or drag of the place cursor, when
|
||||
/// [`Session::place_cursor_requests`] is set.
|
||||
Place(Value),
|
||||
/// A press held while the tool computed an edit on another thread was made now, at `pos` in the
|
||||
/// document with [`crate::DocState::uid`] `doc`, with tool `tool` active (the selection tool Cmd
|
||||
/// lent): the frontend does what it does after a press it hands over itself.
|
||||
HeldPress {
|
||||
doc: Option<u64>,
|
||||
pos: Point,
|
||||
tool: &'static str,
|
||||
},
|
||||
}
|
||||
|
||||
/// Pointer or key input that came while the active tool computed an edit on another thread
|
||||
/// ([`Tool::editing`]), made in order once the edit is applied ([`Session::tool_poll`],
|
||||
/// [`Session::finish_tool_edit`]).
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) enum HeldInput {
|
||||
Pointer(PointerEvent),
|
||||
Key(ToolKey, Mods),
|
||||
}
|
||||
|
||||
impl Session {
|
||||
@@ -106,6 +123,7 @@ impl Session {
|
||||
|
||||
/// Choose a tool (the toolbar, its shortcut, MCP), finishing any pending tool work first.
|
||||
pub fn select_tool(&mut self, id: &str, view: ViewInfo) -> Result<()> {
|
||||
self.finish_tool_edit_later()?;
|
||||
// Choosing a perspective tool shows the document's perspective grid; Hide Grid hides it
|
||||
// again, the tool staying chosen.
|
||||
if matches!(id, "perspectiveGrid" | "perspectiveSelection")
|
||||
@@ -129,6 +147,8 @@ impl Session {
|
||||
/// Switch to tool `id` without choosing it afresh (back from a temporary tool: a hidden
|
||||
/// perspective grid stays hidden), finishing any pending tool work first.
|
||||
pub fn switch_tool(&mut self, id: &str, view: ViewInfo) -> Result<()> {
|
||||
// The edit the tool computes on another thread and the input held for it come first.
|
||||
self.finish_tool_edit_later()?;
|
||||
self.give_back_tool(view)?;
|
||||
if self.tool.id() == id {
|
||||
return Ok(());
|
||||
@@ -430,8 +450,85 @@ impl Session {
|
||||
self.tool_step = now;
|
||||
}
|
||||
|
||||
/// Feed a pointer event to the active tool. Returns requests for the UI.
|
||||
/// Feed a pointer event to the active tool. Returns requests for the UI. While the tool computes
|
||||
/// an edit on another thread, a press and what follows it are held and made once the edit is
|
||||
/// applied, in order ([`Session::tool_poll`]); moves of the pointer with no button held go to
|
||||
/// the tool at once.
|
||||
pub fn pointer(&mut self, ev: &PointerEvent, view: ViewInfo) -> Result<Vec<UiRequest>> {
|
||||
let n = self.next_input();
|
||||
if ev.kind != PointerKind::Move && (!self.held_input.is_empty() || self.tool_edit_pending()) {
|
||||
self.held_input.push_back((n, HeldInput::Pointer(*ev), view));
|
||||
return Ok(vec![]);
|
||||
}
|
||||
let r = self.pointer_now(ev, view);
|
||||
self.note_edit_start(n);
|
||||
r
|
||||
}
|
||||
|
||||
/// The number of the next pointer or key event handed to the session.
|
||||
fn next_input(&mut self) -> u64 {
|
||||
let n = self.input_count;
|
||||
self.input_count = n.wrapping_add(1);
|
||||
n
|
||||
}
|
||||
|
||||
/// How many pointer and key events have been handed to the session ([`Session::pointer`],
|
||||
/// [`Session::tool_key`]); with [`Session::input_applied`], a frontend tells when the events it
|
||||
/// handed over have been made.
|
||||
pub fn input_count(&self) -> u64 {
|
||||
self.input_count
|
||||
}
|
||||
|
||||
/// Have the events numbered `from..to` ([`Session::input_count`] before and after handing them
|
||||
/// over) been made, and the edit they started on another thread applied?
|
||||
pub fn input_applied(&self, from: u64, to: u64) -> bool {
|
||||
let ours = |n: &u64| (from..to).contains(n);
|
||||
!self.held_input.iter().any(|(n, ..)| ours(n)) && !(self.tool_edit_pending() && self.edit_started_by.as_ref().is_some_and(ours))
|
||||
}
|
||||
|
||||
/// After event `n` was made: the event that started the edit being computed, if one is.
|
||||
fn note_edit_start(&mut self, n: u64) {
|
||||
if !self.tool_edit_pending() {
|
||||
self.edit_started_by = None;
|
||||
} else if self.edit_started_by.is_none() {
|
||||
self.edit_started_by = Some(n);
|
||||
}
|
||||
}
|
||||
|
||||
/// Is the active tool, or the tool Cmd lent the selection tool's drag away from, computing an
|
||||
/// edit on another thread?
|
||||
fn tool_edit_pending(&self) -> bool {
|
||||
self.tool.editing() || self.lender.as_ref().is_some_and(|t| t.editing())
|
||||
}
|
||||
|
||||
/// Makes the input held while the tool computed an edit, in order, until a held gesture starts
|
||||
/// another such edit.
|
||||
fn replay_held_input(&mut self) -> Result<Vec<UiRequest>> {
|
||||
let mut ui = vec![];
|
||||
let mut failed = None;
|
||||
while !self.tool_edit_pending()
|
||||
&& let Some((n, input, view)) = self.held_input.pop_front()
|
||||
{
|
||||
let r = match input {
|
||||
HeldInput::Pointer(ev) => self.pointer_now(&ev, view).map(|mut r| {
|
||||
if ev.kind == PointerKind::Down {
|
||||
r.push(UiRequest::HeldPress { doc: self.active().map(|d| d.uid), pos: ev.pos, tool: self.tool.id() });
|
||||
}
|
||||
r
|
||||
}),
|
||||
HeldInput::Key(key, mods) => self.tool_key_now(key, mods, view),
|
||||
};
|
||||
self.note_edit_start(n);
|
||||
match r {
|
||||
Ok(r) => ui.extend(r),
|
||||
// The input after it is still made, as it was when each event came on its own.
|
||||
Err(e) => failed = failed.or(Some(e)),
|
||||
}
|
||||
}
|
||||
failed.map_or(Ok(ui), Err)
|
||||
}
|
||||
|
||||
fn pointer_now(&mut self, ev: &PointerEvent, view: ViewInfo) -> Result<Vec<UiRequest>> {
|
||||
self.pointer_event(ev, view, true)
|
||||
}
|
||||
|
||||
@@ -442,8 +539,25 @@ impl Session {
|
||||
/// nothing and a click opens no size dialog. The tool gets back the persistent options it had
|
||||
/// when the press began, and none of the press's changes to them are stored. A dropped Type
|
||||
/// press restores the prior selection. The freeform gradient point selected once the tool
|
||||
/// took the press is selected again.
|
||||
/// took the press is selected again. A press held while the tool computes an edit on another
|
||||
/// thread has not reached the tool: it is removed from the held input with the pointer events
|
||||
/// and tool keys held after it, and the tool is left as it is. A perspective plane key held
|
||||
/// after it stays held, since the plane it picks outlasts a dropped press. Pointer events held
|
||||
/// after the last held release belong to the press the tool has, and are removed with it.
|
||||
pub fn drop_tool_press(&mut self, view: ViewInfo) -> Result<()> {
|
||||
let (from, held) = self.held_press();
|
||||
let keep: Vec<bool> = (self.held_input.iter().enumerate())
|
||||
.map(|(j, (_, input, _))| match input {
|
||||
_ if j < from => true,
|
||||
HeldInput::Pointer(_) => false,
|
||||
HeldInput::Key(key, _) => !held || self.plane_key(*key).is_some(),
|
||||
})
|
||||
.collect();
|
||||
let mut keep = keep.into_iter();
|
||||
self.held_input.retain(|_| keep.next().unwrap_or(true));
|
||||
if held {
|
||||
return Ok(());
|
||||
}
|
||||
// Nothing to roll back without a document; the tool still drops the press and gets the release.
|
||||
let _ = self.cancel_interaction();
|
||||
let before = self.press_options.take();
|
||||
@@ -485,6 +599,19 @@ impl Session {
|
||||
r.map(drop)
|
||||
}
|
||||
|
||||
/// Where the input of the press in progress starts in the held input, and whether the press
|
||||
/// itself is held: the last held press when no release is held after it; otherwise the input
|
||||
/// after the last held release (all of it when none is held), which follows a press the tool
|
||||
/// already has.
|
||||
fn held_press(&self) -> (usize, bool) {
|
||||
let ends = |kind: PointerKind| matches!(kind, PointerKind::Down | PointerKind::Up);
|
||||
match self.held_input.iter().rposition(|(_, input, _)| matches!(input, HeldInput::Pointer(ev) if ends(ev.kind))) {
|
||||
Some(i) if matches!(self.held_input.get(i), Some((_, HeldInput::Pointer(ev), _)) if ev.kind == PointerKind::Down) => (i, true),
|
||||
Some(i) => (i + 1, false),
|
||||
None => (0, false),
|
||||
}
|
||||
}
|
||||
|
||||
/// The options of `t` that [`Self::store_tool_settings`] stores.
|
||||
fn persistent_options(t: &dyn Tool) -> Map<String, Value> {
|
||||
let opts = t.options();
|
||||
@@ -619,19 +746,148 @@ impl Session {
|
||||
self.tool.wants_samples()
|
||||
}
|
||||
|
||||
/// Is the active tool waiting for work it runs on another thread ([`Tool::waiting`])?
|
||||
/// Is the active tool waiting for work it runs on another thread ([`Tool::waiting`]), is input
|
||||
/// held until an edit it computes is applied, or are requests for the UI left from making it?
|
||||
pub fn tool_waiting(&self) -> bool {
|
||||
self.tool.waiting()
|
||||
self.tool.waiting() || !self.held_input.is_empty() || !self.held_ui.is_empty()
|
||||
}
|
||||
|
||||
/// Lets the active tool check on the work [`Session::tool_waiting`] reports, and with `wait`
|
||||
/// wait for it to finish ([`Tool::poll`]).
|
||||
pub fn tool_poll(&mut self, view: ViewInfo, wait: bool) -> Result<()> {
|
||||
self.with_tool_cx(view, |t, cx| t.poll(cx, wait));
|
||||
self.take_tool_panic()
|
||||
/// wait for it to finish ([`Tool::poll`]); an edit the work made is applied, and then the input
|
||||
/// held for it is made. Returns requests for the UI, those left from making held input where
|
||||
/// nothing could take them first ([`Session::finish_tool_edit_later`]).
|
||||
pub fn tool_poll(&mut self, view: ViewInfo, wait: bool) -> Result<Vec<UiRequest>> {
|
||||
if self.settling_tool_edit {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
self.settling_tool_edit = true;
|
||||
let r = self.tool_poll_now(view, wait);
|
||||
self.settling_tool_edit = false;
|
||||
// On an error the requests left wait for the next poll.
|
||||
let r = r?;
|
||||
let mut ui = std::mem::take(&mut self.held_ui);
|
||||
ui.extend(r);
|
||||
Ok(ui)
|
||||
}
|
||||
|
||||
fn tool_poll_now(&mut self, view: ViewInfo, wait: bool) -> Result<Vec<UiRequest>> {
|
||||
let acts = self.with_tool_cx(view, |t, cx| t.poll(cx, wait));
|
||||
self.take_tool_panic()?;
|
||||
let applied = !acts.is_empty();
|
||||
let mut ui = self.apply_actions(acts)?;
|
||||
if !self.tool_edit_pending() {
|
||||
self.edit_started_by = None;
|
||||
// The input held for an edit applied now is made at the next poll, so what waits for the
|
||||
// edit alone (a `ui.pointer` reply) sees the document as the edit left it.
|
||||
if !applied {
|
||||
ui.extend(self.replay_held_input()?);
|
||||
}
|
||||
}
|
||||
Ok(ui)
|
||||
}
|
||||
|
||||
/// Is the active tool computing an edit on another thread ([`Tool::editing`]), or is input held
|
||||
/// until it is applied?
|
||||
pub fn tool_editing(&self) -> bool {
|
||||
self.tool_edit_pending() || !self.held_input.is_empty()
|
||||
}
|
||||
|
||||
/// Waits for the edit the active tool computes on another thread and applies it
|
||||
/// ([`Tool::finish_edit`]), then makes the input held for it, waiting in turn for an edit that
|
||||
/// starts, so what runs next sees the document as the gestures left it. Commands, saves, option
|
||||
/// changes, interactions, undo scopes and tool or document switches call it first. Returns
|
||||
/// requests for the UI, with those left from earlier ([`Session::finish_tool_edit_later`]); on
|
||||
/// an error, the next [`Session::tool_poll`] returns them.
|
||||
pub fn finish_tool_edit(&mut self) -> Result<Vec<UiRequest>> {
|
||||
if self.settling_tool_edit {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
let mut ui = std::mem::take(&mut self.held_ui);
|
||||
if self.tool_editing() {
|
||||
self.settling_tool_edit = true;
|
||||
let r = self.finish_tool_edit_now();
|
||||
self.settling_tool_edit = false;
|
||||
match r {
|
||||
Ok(r) => ui.extend(r),
|
||||
Err(e) => {
|
||||
ui.append(&mut self.held_ui);
|
||||
self.held_ui = ui;
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(ui)
|
||||
}
|
||||
|
||||
/// [`Session::finish_tool_edit`] for a caller that cannot hand requests to the UI (a command, a
|
||||
/// tool switch): the next [`Session::tool_poll`] returns them, and [`Session::tool_waiting`]
|
||||
/// holds until then.
|
||||
pub(crate) fn finish_tool_edit_later(&mut self) -> Result<()> {
|
||||
let ui = self.finish_tool_edit()?;
|
||||
self.held_ui.extend(ui);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn finish_tool_edit_now(&mut self) -> Result<Vec<UiRequest>> {
|
||||
let mut ui = vec![];
|
||||
let mut failed = None;
|
||||
loop {
|
||||
match self.finish_pending_edit() {
|
||||
Ok(r) => ui.extend(r),
|
||||
Err(e) => failed = failed.or(Some(e)),
|
||||
}
|
||||
// A tool that cannot finish its edit keeps the input held.
|
||||
if self.tool_edit_pending() {
|
||||
break;
|
||||
}
|
||||
self.edit_started_by = None;
|
||||
if self.held_input.is_empty() {
|
||||
break;
|
||||
}
|
||||
match self.replay_held_input() {
|
||||
Ok(r) => ui.extend(r),
|
||||
Err(e) => failed = failed.or(Some(e)),
|
||||
}
|
||||
}
|
||||
match failed {
|
||||
None => Ok(ui),
|
||||
Some(e) => {
|
||||
self.held_ui.extend(ui);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Waits for the edit being computed and applies it: the active tool's, or that of the tool
|
||||
/// Cmd lent the selection tool's drag away from, which is active meanwhile.
|
||||
fn finish_pending_edit(&mut self) -> Result<Vec<UiRequest>> {
|
||||
if self.tool.editing() {
|
||||
let acts = self.with_tool_cx(self.last_view, |t, cx| t.finish_edit(cx));
|
||||
self.take_tool_panic()?;
|
||||
return self.apply_actions(acts);
|
||||
}
|
||||
let Some(lender) = self.lender.take_if(|t| t.editing()) else { return Ok(vec![]) };
|
||||
let lent = std::mem::replace(&mut self.tool, lender);
|
||||
let acts = self.with_tool_cx(self.last_view, |t, cx| t.finish_edit(cx));
|
||||
let r = self.take_tool_panic().and_then(|()| self.apply_actions(acts));
|
||||
self.lender = Some(std::mem::replace(&mut self.tool, lent));
|
||||
r
|
||||
}
|
||||
|
||||
/// A key for the active tool. While the tool computes an edit on another thread, the key is held
|
||||
/// and made once the edit is applied, after the input held before it.
|
||||
pub fn tool_key(&mut self, key: ToolKey, mods: Mods, view: ViewInfo) -> Result<Vec<UiRequest>> {
|
||||
let n = self.next_input();
|
||||
if self.tool_editing() {
|
||||
self.held_input.push_back((n, HeldInput::Key(key, mods), view));
|
||||
return Ok(vec![]);
|
||||
}
|
||||
let r = self.tool_key_now(key, mods, view);
|
||||
self.note_edit_start(n);
|
||||
r
|
||||
}
|
||||
|
||||
fn tool_key_now(&mut self, key: ToolKey, mods: Mods, view: ViewInfo) -> Result<Vec<UiRequest>> {
|
||||
// 1–4 pick the active perspective plane while the grid is shown.
|
||||
if let Some(plane) = self.plane_key(key) {
|
||||
self.execute("perspective.plane.set", &serde_json::json!({ "plane": plane.id() }))?;
|
||||
@@ -837,7 +1093,8 @@ impl Session {
|
||||
/// it is on, makes the drawing tools' a crosshair, [`Cursor::precise`]). With Cmd held, the pointer of the selection tool a
|
||||
/// press would borrow ([`Self::lend_selection_tool`]).
|
||||
pub fn cursor(&mut self, p: Point, mods: Mods, view: ViewInfo) -> Cursor {
|
||||
let lent = if mods.cmd && self.lender.is_none() { self.lent_tool(self.tool.id(), &mods) } else { None };
|
||||
// While an edit is computed, a Cmd press is held for the active tool, which shows it is busy.
|
||||
let lent = if mods.cmd && self.lender.is_none() && !self.tool_editing() { self.lent_tool(self.tool.id(), &mods) } else { None };
|
||||
let c = match lent {
|
||||
Some(id) => {
|
||||
let lent = self.make_tool(id);
|
||||
@@ -860,6 +1117,9 @@ impl Session {
|
||||
self.tool.options()
|
||||
}
|
||||
pub fn set_tool_option(&mut self, key: &str, v: &Value) {
|
||||
// The active tool's edit being computed is applied with the options it was started with. A
|
||||
// failure to apply it was the edit's own, and the option is set all the same.
|
||||
let _ = self.finish_tool_edit_later();
|
||||
if key == "queue" && self.tool.id() == "place" {
|
||||
self.note_place_queue_roots();
|
||||
}
|
||||
@@ -934,6 +1194,10 @@ impl Session {
|
||||
{
|
||||
return Err(format!("unknown tool `{t}`"));
|
||||
}
|
||||
// The active tool's merge being computed is applied with the options it was started with.
|
||||
if tool.is_none_or(|t| t == self.tool.id()) {
|
||||
self.finish_tool_edit_later().map_err(|e| e.to_string())?;
|
||||
}
|
||||
let mut values = p.get("values").and_then(Value::as_object).cloned().unwrap_or_default();
|
||||
if let Some(k) = p.get("key").and_then(Value::as_str) {
|
||||
values.insert(k.to_string(), p.get("value").cloned().unwrap_or(Value::Null));
|
||||
|
||||
@@ -219,6 +219,56 @@ fn every_command_with_junk_params() {
|
||||
);
|
||||
}
|
||||
|
||||
/// Each document's uid, revision and selected ids, the active document and the current paint.
|
||||
type ToolEditState = (Vec<(u64, u64, Vec<u64>)>, Option<usize>, vectorcraft_tools::PaintDefaults);
|
||||
|
||||
/// What a command that runs while the active tool computes an edit on another thread must leave
|
||||
/// as it was: every document's revision and selection, which document is active, and the current
|
||||
/// paint.
|
||||
fn tool_edit_state(s: &Session) -> ToolEditState {
|
||||
let docs = s.documents().iter().map(|d| (d.uid, d.revision, d.selection.objects.iter().map(|i| i.0).collect())).collect();
|
||||
(docs, s.active_index(), s.paint.clone())
|
||||
}
|
||||
|
||||
/// Every command that runs at once while the active tool computes an edit on another thread (a
|
||||
/// Shape Builder merge), rather than applying the edit first (`waits_for_tool_edit`), leaves the
|
||||
/// documents' revisions and selections, the active document and the current paint as they were,
|
||||
/// with `{}`, junk params and params that turn its options on and off: the edit, computed for the
|
||||
/// document as it was, still applies after it.
|
||||
#[test]
|
||||
fn commands_that_do_not_wait_for_a_tool_edit_change_no_document() {
|
||||
let path = safe_path();
|
||||
let mut failures = vec![];
|
||||
for fx in [Fixture::Single, Fixture::Multi] {
|
||||
for c in command_specs().iter().filter(|c| !vectorcraft_engine::waits_for_tool_edit(c.id)) {
|
||||
let mut cases = junk_params(c.params, &path);
|
||||
if heavy(c.id) {
|
||||
cases.truncate(12);
|
||||
}
|
||||
for k in param_keys(c.params) {
|
||||
for v in [json!(true), json!(false), json!(1), json!("on")] {
|
||||
cases.push(json!({ k.as_str(): v }));
|
||||
}
|
||||
}
|
||||
// Find Objects selects only with a filter, which one key at a time does not give it.
|
||||
if c.id == "document.find" {
|
||||
cases.extend([json!({"kind": "Path", "select": true}), json!({"name": "no such name", "select": true})]);
|
||||
}
|
||||
for p in &cases {
|
||||
let mut s = fx.session();
|
||||
let before = tool_edit_state(&s);
|
||||
let _ = catch_quiet(|| no_panic(s.execute(c.id, p)));
|
||||
if tool_edit_state(&s) != before {
|
||||
failures.push(format!("{} {p} [{fx:?}]", c.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
failures.sort();
|
||||
failures.dedup_by(|a, b| a.split(' ').next() == b.split(' ').next());
|
||||
assert!(failures.is_empty(), "{} commands change a document without waiting for a tool edit:\n{}", failures.len(), failures.join("\n"));
|
||||
}
|
||||
|
||||
/// Junk inside the obvious structured params: ids arrays, anchors, matrices, colours, stops.
|
||||
#[test]
|
||||
fn structured_junk() {
|
||||
|
||||
@@ -3239,6 +3239,50 @@ fn text_editing_of(document: &str, objects: &str) -> String {
|
||||
|
||||
/// Area Type Options as an area frame's data may keep them: rows, columns, gutters and the first
|
||||
/// baseline, and keys besides, each with a value of any kind, in or out of range.
|
||||
/// A paragraph's attributes as a text document might keep them: an alignment (key 0), auto leading
|
||||
/// (7), hyphenation options (10 to 15) and tab stops (30) of any value or type, the stops a list of
|
||||
/// any length whose entries may be anything.
|
||||
fn arb_paragraph_attributes() -> impl Strategy<Value = String> {
|
||||
let values = prop::sample::select(vec![
|
||||
"0",
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"6",
|
||||
"7",
|
||||
"-1",
|
||||
"2.5",
|
||||
"1e400",
|
||||
"-1e400",
|
||||
"NaN",
|
||||
"inf",
|
||||
"1e9",
|
||||
"(x)",
|
||||
"true",
|
||||
"false",
|
||||
"/nil",
|
||||
"[ 1 ]",
|
||||
"<< /0 1 >>",
|
||||
]);
|
||||
let keys = prop::sample::select(vec!["0", "7", "10", "11", "12", "13", "14", "15"]);
|
||||
let stop = (values.clone(), values.clone(), 0usize..3).prop_map(|(at, align, shape)| match shape {
|
||||
0 => format!("<< /0 {at} /1 {align} >>"),
|
||||
1 => format!("<< /1 {align} >>"),
|
||||
_ => at.to_string(),
|
||||
});
|
||||
let tabs = (prop::collection::vec(stop, 0..40), 0usize..4).prop_map(|(stops, shape)| match shape {
|
||||
0 => format!("/30 << /0 [ {} ] >>", stops.join(" ")),
|
||||
1 => "/30 << /0 7 >>".to_string(),
|
||||
2 => "/30 [ 1 2 ]".to_string(),
|
||||
_ => String::new(),
|
||||
});
|
||||
(prop::collection::vec((keys, values), 0..8), tabs).prop_map(|(kv, tabs)| {
|
||||
let mut attrs: Vec<String> = kv.iter().map(|(k, v)| format!("/{k} {v}")).collect();
|
||||
attrs.push(tabs);
|
||||
attrs.join(" ")
|
||||
})
|
||||
}
|
||||
|
||||
fn arb_area_options() -> impl Strategy<Value = String> {
|
||||
let keys = prop::sample::select(vec!["3", "4", "5", "7", "8", "10", "13", "14"]);
|
||||
let values = prop::sample::select(vec![
|
||||
@@ -3399,6 +3443,23 @@ fn the_shown_stories_fixture_opens_with_its_layers() {
|
||||
assert!(texts.iter().all(|t| t.contains('\u{2028}') && t.contains('\n')), "{texts:?}");
|
||||
}
|
||||
|
||||
/// The fuzzed editing data with its layer, pattern and global colour named in code page 949 opens
|
||||
/// with those names, read in that encoding, from its layers.
|
||||
#[test]
|
||||
fn the_editing_fixture_reads_names_in_a_legacy_encoding() {
|
||||
// 레이어 1, then 빨강.
|
||||
let text = editing_text()
|
||||
.replace("(One) Ln", r"(\267\271\300\314\276\356 1) Ln")
|
||||
.replace("(Dots)", r"(\273\241\260\255)")
|
||||
.replace("(Black global)", r"(\273\241\260\255 global)");
|
||||
let bytes = editing_eps(&text);
|
||||
let r = vectorcraft_eps::import_names(&bytes, true, true, vectorcraft_eps::NameEncoding::Korean).unwrap();
|
||||
let names: Vec<_> = r.document.layers.iter().map(|l| l.name.clone().unwrap_or_default()).collect();
|
||||
assert_eq!(names, ["레이어 1", "Two"], "{:?}", r.warnings);
|
||||
assert!(r.document.pattern("빨강").is_some(), "{:?}", r.warnings);
|
||||
assert!(r.document.swatch("빨강 global").is_some_and(|s| s.global), "{:?}", r.warnings);
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#![proptest_config(config())]
|
||||
|
||||
@@ -3446,6 +3507,18 @@ proptest! {
|
||||
survive(".ai text frames with hostile area options", || Some(vectorcraft_eps::layered_ai(&private, Document::new(100.0, 100.0), vec![], false, false, 1.0).0))?;
|
||||
}
|
||||
|
||||
/// The same text document with hostile paragraph attributes: an alignment, auto leading,
|
||||
/// hyphenation options and tab stops of any value, type or size.
|
||||
#[test]
|
||||
fn text_frames_with_hostile_paragraph_attributes_never_panic(attrs in arb_paragraph_attributes()) {
|
||||
let text = frames_document_text().replace("/5 << /0 2 /1 4 /2 6 >>", &format!("/5 << /1 4 /2 6 {attrs} >>"));
|
||||
let editing = text_editing_of(&text, FRAME_OBJECTS);
|
||||
let bytes = editing_eps(&editing);
|
||||
survive("EPS text frames with hostile paragraph attributes", || vectorcraft_engine::cmd::fileio::load("x.eps", &bytes).ok().map(|l| l.doc))?;
|
||||
let private = [b"%AI24_ZStandard_Data".as_slice(), &zstd(&editing)].concat();
|
||||
survive(".ai text frames with hostile paragraph attributes", || Some(vectorcraft_eps::layered_ai(&private, Document::new(100.0, 100.0), vec![], false, false, 1.0).0))?;
|
||||
}
|
||||
|
||||
/// The type on a path of the same text document with hostile Type on a Path Options, opened as
|
||||
/// an EPS document and as a `.ai`'s editing data.
|
||||
#[test]
|
||||
@@ -3475,6 +3548,26 @@ proptest! {
|
||||
survive("mutated EPS editing data", || vectorcraft_eps::import(&bytes).ok().map(|r| r.document))?;
|
||||
}
|
||||
|
||||
/// Names of any bytes (a layer's, a pattern's, a global colour's) read in any legacy name
|
||||
/// encoding: each byte written as an octal escape, so every code page sees bytes it doesn't
|
||||
/// define, cut sequences and UTF-8 alike.
|
||||
#[test]
|
||||
fn eps_editing_data_names_in_any_encoding_never_panic(
|
||||
name in prop::collection::vec(any::<u8>(), 0..24),
|
||||
encoding in prop::sample::select(vectorcraft_eps::NameEncoding::LABELS.to_vec()),
|
||||
) {
|
||||
let escaped: String = name.iter().map(|b| format!("\\{b:03o}")).collect();
|
||||
let text = editing_text()
|
||||
.replace("(One) Ln", &format!("({escaped}) Ln"))
|
||||
.replace("(Dots)", &format!("({escaped})"))
|
||||
.replace("(Black global)", &format!("({escaped} global)"));
|
||||
let bytes = editing_eps(&text);
|
||||
let encoding = vectorcraft_eps::NameEncoding::from_label(encoding).unwrap();
|
||||
survive("EPS editing data names in a legacy encoding", || {
|
||||
vectorcraft_eps::import_names(&bytes, true, false, encoding).ok().map(|r| r.document)
|
||||
})?;
|
||||
}
|
||||
|
||||
/// A `.ai` whose envelopes are damaged or hostile: any kind, warp style, options word,
|
||||
/// Fidelity and grid size, corners out of range or repeated, the contents block cut short.
|
||||
#[test]
|
||||
|
||||
@@ -125,6 +125,27 @@ fn an_export_step_or_preset_with_a_key_no_longer_read_still_runs() {
|
||||
s.execute("document.export", &json!({"format": "pdf", "preset": "Old"})).unwrap();
|
||||
}
|
||||
|
||||
/// So does a save, or an Export for Screens, with a key that is no longer read, and an Export for
|
||||
/// Screens preset file that holds one in a row still loads and exports. `Session::execute`
|
||||
/// refuses the same options.
|
||||
#[test]
|
||||
fn a_save_or_screens_step_with_a_key_no_longer_read_still_runs() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({})).unwrap();
|
||||
let save = json!({"format": "pdf", "noSuchOption": true, "options": {"retired": 1, "marks": {"useDocumentBleed": true}}});
|
||||
assert!(check_params("file.saveCopy", &save).is_err());
|
||||
assert!(s.execute("file.saveCopy", &save).is_err());
|
||||
s.replay("file.saveCopy", &save).unwrap();
|
||||
let screens = json!({"noSuchOption": true, "formats": [{"format": "png", "retired": 1}], "settings": {"pdf": {"marks": {"retired": true}}}});
|
||||
assert!(check_params("document.exportForScreens", &screens).is_err());
|
||||
assert!(s.execute("document.exportForScreens", &screens).is_err());
|
||||
s.replay("document.exportForScreens", &screens).unwrap();
|
||||
let file = json!({"format": "vcexportpresets", "presets": [{"name": "Old", "settings": {"formats": [{"format": "png", "noLongerRead": 1}]}}]});
|
||||
s.execute("document.exportPresets.import", &json!({"data": file.to_string()})).unwrap();
|
||||
check_params("document.exportForScreens", &json!({"exportPreset": "Old"})).unwrap();
|
||||
s.execute("document.exportForScreens", &json!({"exportPreset": "Old"})).unwrap();
|
||||
}
|
||||
|
||||
/// So do an effect's own parameters (#1592): a journal or a file with a key the effect doesn't
|
||||
/// take, or a value of another type, replays and opens; the effect reads what it knows, clamped.
|
||||
#[test]
|
||||
|
||||
@@ -157,6 +157,22 @@ fn the_exporter_is_given_its_parameters_and_the_file_it_writes() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// Export for Screens writes an exporter's format from a row, with the row's `params`, and takes
|
||||
/// settings for that format.
|
||||
#[test]
|
||||
fn export_for_screens_takes_an_exporter_s_format_and_params() {
|
||||
let mut s = session();
|
||||
let params = r#"{"density":{"type":"number","min":0,"max":10,"default":4}}"#;
|
||||
install(&mut s, &tpl::echo_exporter(&tpl::exporter("test.screens", r#"["tss"]"#, params), Echo::Params));
|
||||
let r = s.execute("document.exportForScreens", &json!({"formats": [{"format": "plugin.test.screens", "params": {"density": 7}}]})).unwrap();
|
||||
let file = &r["files"][0];
|
||||
assert!(file["name"].as_str().unwrap().ends_with(".tss"), "{r}");
|
||||
let got: Value = serde_json::from_slice(&vectorcraft_format::base64_decode(file["dataBase64"].as_str().unwrap()).unwrap()).unwrap();
|
||||
assert_eq!(got["density"], json!(7.0));
|
||||
let settings = json!({"formats": [{"format": "plugin.test.screens"}], "settings": {"plugin.test.screens": {"params": {"density": 2}}}});
|
||||
s.execute("document.exportForScreens", &settings).unwrap();
|
||||
}
|
||||
|
||||
/// Only the selected objects, with `selectedOnly`, as for the built-in formats.
|
||||
#[test]
|
||||
fn selected_only_hands_over_the_selection() {
|
||||
|
||||
@@ -37,6 +37,8 @@ hayro-ccitt = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
# Substring search for PostScript `search`.
|
||||
memchr = { workspace = true }
|
||||
# Names in legacy .ai files that aren't UTF-8, read in the encoding the user picks.
|
||||
encoding_rs = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
vectorcraft-testkit = { workspace = true }
|
||||
|
||||
@@ -462,7 +462,7 @@ fn an_artboard_larger_than_the_canvas_is_written_on_a_large_canvas() {
|
||||
let bounds = read.layers.iter().filter_map(|l| l.visual_bounds()).reduce(|a, b| a.union(b)).unwrap();
|
||||
assert!((bounds.x0 - 1000.0).abs() < 1e-6 && (bounds.y1 - 2000.0).abs() < 1e-6 && (bounds.width() - 2000.0).abs() < 1e-6, "{bounds:?}");
|
||||
// The same without a readable PDF part, on its first page's size.
|
||||
let (alone, notes) = crate::ai_alone_on_page(&p.data, (20_000.0, 20_000.0), 1.389).unwrap();
|
||||
let (alone, notes) = crate::ai_alone_on_page(&p.data, (20_000.0, 20_000.0), 1.389, crate::NameEncoding::default()).unwrap();
|
||||
assert_eq!(alone.artboards.iter().map(|a| a.rect).collect::<Vec<_>>(), [Rect::new(0.0, 0.0, 20_000.0, 20_000.0)], "{notes:?}");
|
||||
// And from the editing data alone, as a file saved without its PDF part opens.
|
||||
let alone = read_back(&doc);
|
||||
|
||||
@@ -73,6 +73,7 @@ use graphics::{GState, Out};
|
||||
use interp::{Fault, Interp};
|
||||
use obj::PsError;
|
||||
|
||||
pub use ai::NameEncoding;
|
||||
#[cfg(test)]
|
||||
pub(crate) use ai::objects_read;
|
||||
pub(crate) use ai::{
|
||||
@@ -80,7 +81,7 @@ pub(crate) use ai::{
|
||||
symbol_art_member, warp_number,
|
||||
};
|
||||
pub(crate) use ate::{MAX_BYTES as MAX_TEXT_DOCUMENT, MAX_FRAMES, MAX_SEGMENTS, MAX_STORY, MAX_VALUES as MAX_TEXT_VALUES};
|
||||
pub use native::{AiLayers, ai_alone, ai_alone_on_page, ai_layers_alone, ai_opened_artboard, is_loss, layered_ai, layered_ai_from};
|
||||
pub use native::{AiLayers, ai_alone, ai_alone_on_page, ai_alone_with, ai_layers_alone, ai_opened_artboard, is_loss, layered_ai, layered_ai_from};
|
||||
pub(crate) use native::{MAX_TEXT, scale_document};
|
||||
pub use text::family_style;
|
||||
|
||||
@@ -251,6 +252,13 @@ pub fn import_with(bytes: &[u8], editing_data: bool) -> Result<Imported, String>
|
||||
/// [`import_with`]; `trust`: an Illustrator EPS's layers are used even where they draw differently
|
||||
/// from its page, with a note (`editingData: "always"`, as for a `.ai`).
|
||||
pub fn import_trusting(bytes: &[u8], editing_data: bool, trust: bool) -> Result<Imported, String> {
|
||||
import_names(bytes, editing_data, trust, NameEncoding::default())
|
||||
}
|
||||
|
||||
/// [`import_trusting`], with the names in the editing copy that aren't UTF-8 (layers, objects,
|
||||
/// artboards, colors, gradients, patterns, graphic styles, swatches, brushes, symbols, variables
|
||||
/// and data sets) read in `names`.
|
||||
pub fn import_names(bytes: &[u8], editing_data: bool, trust: bool, names: NameEncoding) -> Result<Imported, String> {
|
||||
let ps = program(bytes)?;
|
||||
let dsc = Dsc::read(ps);
|
||||
// A legacy `.ai` VectorCraft wrote: its prolog prints the art plainly (gradients flat, no
|
||||
@@ -258,7 +266,7 @@ pub fn import_trusting(bytes: &[u8], editing_data: bool, trust: bool) -> Result<
|
||||
// printed).
|
||||
if editing_data
|
||||
&& dsc.own_legacy
|
||||
&& let Some(Ok((document, warnings))) = native::program_alone(ps, dsc.illustrator)
|
||||
&& let Some(Ok((document, warnings))) = native::program_alone(ps, dsc.illustrator, names)
|
||||
{
|
||||
return Ok(Imported { document, warnings, preview: false });
|
||||
}
|
||||
@@ -278,7 +286,7 @@ pub fn import_trusting(bytes: &[u8], editing_data: bool, trust: bool) -> Result<
|
||||
}
|
||||
let drew = !out.drawn.is_empty();
|
||||
let why = match (&result, drew) {
|
||||
(Ok(()), true) if editing_data => return Ok(native::layered(ps, finish(out), trust, dsc.illustrator)),
|
||||
(Ok(()), true) if editing_data => return Ok(native::layered(ps, finish(out), trust, dsc.illustrator, names)),
|
||||
(Ok(()), true) => return Ok(finish(out)),
|
||||
(Ok(()), false) => "it draws nothing VectorCraft's PostScript reader can show".to_string(),
|
||||
(Err(e), _) => reason(e, fault.as_ref()),
|
||||
@@ -286,7 +294,7 @@ pub fn import_trusting(bytes: &[u8], editing_data: bool, trust: bool) -> Result<
|
||||
// A file in the legacy Illustrator format whose program can't be run (a `.ai` that names the
|
||||
// prolog defining its operators without including it): its layers, which the program has, or
|
||||
// its art on one layer when it has none (Illustrator 3).
|
||||
let why = match editing_data.then(|| native::program_alone(ps, dsc.illustrator)).flatten() {
|
||||
let why = match editing_data.then(|| native::program_alone(ps, dsc.illustrator, names)).flatten() {
|
||||
Some(Ok((document, warnings))) => return Ok(Imported { document, warnings, preview: false }),
|
||||
Some(Err(e)) => format!("{why}; its layers couldn't be read either ({e})"),
|
||||
None => why,
|
||||
|
||||
@@ -39,14 +39,17 @@ pub(crate) use envelope::DRAWN as ENVELOPE_DRAWN;
|
||||
pub(crate) use envelope::MAX_CHECKED;
|
||||
pub(crate) use envelope::{WARPED_TYPE_DRAWN, WarpedType};
|
||||
pub(crate) use frames::text_frames;
|
||||
pub use obj::{NameEncoding, Names};
|
||||
pub(crate) use paint::MAX_STOPS as MAX_GRADIENT_STOPS;
|
||||
#[cfg(test)]
|
||||
pub(crate) use read::objects_read;
|
||||
#[cfg(test)]
|
||||
pub use read::read;
|
||||
#[cfg(test)]
|
||||
pub(crate) use read::with_image_limits;
|
||||
pub use read::{
|
||||
BindingRef, Brushes, PaletteSwatches, PlacedPage, Structure, Symbols, active_artboard, artboards, bindings_note, brushes, graphic_styles,
|
||||
palette, read, read_beside, symbols, variables,
|
||||
palette, read_beside, read_in, symbols, variables,
|
||||
};
|
||||
pub(crate) use read::{
|
||||
MAX_NODES as MAX_EDITING_OBJECTS, MAX_SYMBOLS, join_and, read_art_style, read_over_page, read_style_list, slot_frame, slot_of, style_moves_with,
|
||||
|
||||
@@ -57,7 +57,7 @@ use vectorcraft_color::Paint;
|
||||
use vectorcraft_doc::{AppearanceItem, Node, NodeKind};
|
||||
|
||||
use super::lex::{Lexer, Tok};
|
||||
use super::obj;
|
||||
use super::obj::Names;
|
||||
|
||||
/// The brush manager's order: the plug-in name of its object.
|
||||
pub(super) const MANAGER: &str = "Adobe Brush Manager Order"; // brand-ok: the plug-in name the files use
|
||||
@@ -157,16 +157,17 @@ pub(super) enum BrushError {
|
||||
}
|
||||
|
||||
/// The strings of a plug-in object's section (`section`: what follows `%AI8_BeginPluginObject`):
|
||||
/// its plug-in name, its name and its parameters, joined. The name is `None` with one string, and
|
||||
/// the whole is `None` with none.
|
||||
pub(super) fn plugin_strings(section: &[u8]) -> Option<(String, Option<String>, String)> {
|
||||
/// its plug-in name, the bytes of its name and its parameters, joined, read by `names` without
|
||||
/// notes. The name is `None` with one string, and the whole is `None` with none. A brush's name has
|
||||
/// its note when the brush is read, and the names of its art when their art is read.
|
||||
pub(super) fn plugin_strings(section: &[u8], names: &Names) -> Option<(String, Option<Vec<u8>>, String)> {
|
||||
let mut lex = Lexer::new(section);
|
||||
let mut strings = vec![];
|
||||
let mut params = vec![];
|
||||
while let Some(t) = lex.next_token() {
|
||||
if let Tok::Str(s) | Tok::Hex(s) = t.tok {
|
||||
if strings.len() < 2 {
|
||||
strings.push(obj::text(&s));
|
||||
strings.push(s);
|
||||
} else {
|
||||
// Joined before they are text: a string may end inside a character.
|
||||
let room = MAX_PARAMS.saturating_sub(params.len());
|
||||
@@ -175,8 +176,8 @@ pub(super) fn plugin_strings(section: &[u8]) -> Option<(String, Option<String>,
|
||||
}
|
||||
}
|
||||
let mut strings = strings.into_iter();
|
||||
let kind = strings.next()?;
|
||||
Some((kind, strings.next(), obj::text(¶ms)))
|
||||
let kind = names.quiet(&strings.next()?);
|
||||
Some((kind, strings.next(), names.quiet(¶ms)))
|
||||
}
|
||||
|
||||
/// The brush manager's order (`params`: its parameters): the kind and name of each brush. Pairs
|
||||
|
||||
@@ -47,6 +47,237 @@ pub(super) fn text(bytes: &[u8]) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// The encoding names in the editing data that aren't UTF-8 are read in (layers, objects,
|
||||
/// artboards, colors, gradients, patterns, graphic styles, swatches, brushes, symbols, variables
|
||||
/// and data sets, and data sets' text values). Legacy files store them in the code page of the
|
||||
/// system that wrote them and don't say which.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum NameEncoding {
|
||||
/// Windows-1252, Latin-1 for its gaps.
|
||||
#[default]
|
||||
Windows1252,
|
||||
/// Mac OS Roman.
|
||||
Macintosh,
|
||||
/// Korean: Windows code page 949 (EUC-KR and Unified Hangul Code).
|
||||
Korean,
|
||||
/// Japanese: Shift_JIS (Windows code page 932).
|
||||
ShiftJis,
|
||||
/// Simplified Chinese: GBK (Windows code page 936).
|
||||
Gbk,
|
||||
/// Traditional Chinese: Big5 (Windows code page 950).
|
||||
Big5,
|
||||
}
|
||||
|
||||
impl NameEncoding {
|
||||
/// The labels [`NameEncoding::from_label`] reads, one for each encoding.
|
||||
pub const LABELS: [&str; 6] = ["windows-1252", "macintosh", "windows-949", "shift_jis", "gbk", "big5"];
|
||||
|
||||
/// The encoding with label `label` (any case): one of [`Self::LABELS`], or `euc-kr` for
|
||||
/// [`NameEncoding::Korean`].
|
||||
pub fn from_label(label: &str) -> Option<Self> {
|
||||
let label = label.trim().to_ascii_lowercase();
|
||||
Some(match label.as_str() {
|
||||
"windows-1252" => Self::Windows1252,
|
||||
"macintosh" => Self::Macintosh,
|
||||
"windows-949" | "euc-kr" => Self::Korean,
|
||||
"shift_jis" => Self::ShiftJis,
|
||||
"gbk" => Self::Gbk,
|
||||
"big5" => Self::Big5,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// The encoding's label, as [`Self::LABELS`] gives it.
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::Windows1252 => "windows-1252",
|
||||
Self::Macintosh => "macintosh",
|
||||
Self::Korean => "windows-949",
|
||||
Self::ShiftJis => "shift_jis",
|
||||
Self::Gbk => "gbk",
|
||||
Self::Big5 => "big5",
|
||||
}
|
||||
}
|
||||
|
||||
/// `bytes` as text: UTF-8 as it is, else read in this encoding, with each sequence it doesn't
|
||||
/// define as U+FFFD (Windows-1252 defines every byte).
|
||||
fn decode(self, bytes: &[u8]) -> Decoded {
|
||||
if let Ok(s) = std::str::from_utf8(bytes) {
|
||||
return Decoded { text: s.to_string(), fallback: false, replaced: false };
|
||||
}
|
||||
let other = match self {
|
||||
Self::Windows1252 => return Decoded { text: bytes.iter().map(|b| cp1252(*b)).collect(), fallback: true, replaced: false },
|
||||
Self::Macintosh => encoding_rs::MACINTOSH,
|
||||
Self::Korean => encoding_rs::EUC_KR,
|
||||
Self::ShiftJis => encoding_rs::SHIFT_JIS,
|
||||
Self::Gbk => encoding_rs::GBK,
|
||||
Self::Big5 => encoding_rs::BIG5,
|
||||
};
|
||||
let (text, replaced) = other.decode_without_bom_handling(bytes);
|
||||
Decoded { text: text.into_owned(), fallback: true, replaced }
|
||||
}
|
||||
|
||||
/// [`NameEncoding::decode`] as the text, whether the bytes weren't UTF-8, and whether some
|
||||
/// weren't valid in the encoding either.
|
||||
pub(super) fn decoded(self, bytes: &[u8]) -> (String, bool, bool) {
|
||||
let d = self.decode(bytes);
|
||||
(d.text, d.fallback, d.replaced)
|
||||
}
|
||||
}
|
||||
|
||||
/// A name's hash, for counting the names past the notes.
|
||||
fn hash(name: &str) -> u64 {
|
||||
use std::hash::{Hash, Hasher};
|
||||
let mut h = std::collections::hash_map::DefaultHasher::new();
|
||||
name.hash(&mut h);
|
||||
h.finish()
|
||||
}
|
||||
|
||||
/// Bytes read as text by [`NameEncoding::decode`].
|
||||
struct Decoded {
|
||||
text: String,
|
||||
/// The bytes weren't UTF-8.
|
||||
fallback: bool,
|
||||
/// Some weren't valid in the encoding either, and became U+FFFD.
|
||||
replaced: bool,
|
||||
}
|
||||
|
||||
/// Most names that weren't UTF-8 each named in a note; the rest are counted in one.
|
||||
const MAX_NAME_NOTES: usize = 3;
|
||||
/// Most other names counted (the count stops there).
|
||||
const MAX_NAMES_COUNTED: usize = 10_000;
|
||||
|
||||
/// The names read in a [`NameEncoding`], and the notes on those that weren't UTF-8: one for each
|
||||
/// name (the first [`MAX_NAME_NOTES`]), then one counting the others (up to
|
||||
/// [`MAX_NAMES_COUNTED`]).
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Names {
|
||||
pub encoding: NameEncoding,
|
||||
noted: Vec<(String, bool)>,
|
||||
/// Hashes of the other names.
|
||||
more: std::collections::HashSet<u64>,
|
||||
}
|
||||
|
||||
impl Names {
|
||||
pub fn new(encoding: NameEncoding) -> Self {
|
||||
Self { encoding, ..Self::default() }
|
||||
}
|
||||
|
||||
/// `bytes` read in the encoding, without a note (a list or a parameter string that repeats
|
||||
/// names noted where they are defined).
|
||||
pub fn quiet(&self, bytes: &[u8]) -> String {
|
||||
self.encoding.decode(bytes).text
|
||||
}
|
||||
|
||||
/// A string's or name's text as a name: a string that isn't UTF-8 read in the encoding,
|
||||
/// with a note.
|
||||
pub(super) fn text(&mut self, v: &V) -> Option<String> {
|
||||
match v {
|
||||
V::Str(s) => Some(self.bytes(s)),
|
||||
V::Name(n) => Some(n.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// `bytes` read as a name (see [`Names::text`]).
|
||||
pub fn bytes(&mut self, bytes: &[u8]) -> String {
|
||||
let d = self.encoding.decode(bytes);
|
||||
if d.fallback {
|
||||
self.note(&d.text, d.replaced);
|
||||
}
|
||||
d.text
|
||||
}
|
||||
|
||||
/// The first text value of `o`'s entry `key`, as a name.
|
||||
pub(super) fn entry(&mut self, o: &Obj, key: &str) -> Option<String> {
|
||||
let v = o.get(key)?.iter().find(|v| matches!(v, V::Str(_)))?;
|
||||
self.text(v)
|
||||
}
|
||||
|
||||
/// The name the XML id in `id` (an `AI10_ArtUID`) gives its object ([`xml_name`]): a string that
|
||||
/// isn't UTF-8 is read in the encoding, with a note on the name.
|
||||
pub(super) fn xml_id_name(&mut self, id: &Obj) -> Option<String> {
|
||||
match id.content.iter().find(|v| matches!(v, V::Str(_) | V::Name(_)))? {
|
||||
V::Str(bytes) => {
|
||||
let d = self.encoding.decode(bytes);
|
||||
let name = xml_name(&d.text);
|
||||
if d.fallback {
|
||||
self.note(&name, d.replaced);
|
||||
}
|
||||
Some(name)
|
||||
}
|
||||
v => v.text().map(|t| xml_name(&t)),
|
||||
}
|
||||
}
|
||||
|
||||
/// A note on `name`, which wasn't UTF-8 (`replaced`: parts of it weren't valid in the encoding
|
||||
/// either).
|
||||
pub(super) fn note(&mut self, name: &str, replaced: bool) {
|
||||
if self.noted.iter().any(|(n, _)| n == name) {
|
||||
return;
|
||||
}
|
||||
if self.noted.len() < MAX_NAME_NOTES {
|
||||
self.noted.push((name.to_string(), replaced));
|
||||
} else {
|
||||
self.count(hash(name));
|
||||
}
|
||||
}
|
||||
|
||||
fn count(&mut self, h: u64) {
|
||||
if self.more.len() < MAX_NAMES_COUNTED {
|
||||
self.more.insert(h);
|
||||
}
|
||||
}
|
||||
|
||||
/// Take the notes of `other`, a reader's for part of the same data.
|
||||
pub fn absorb(&mut self, other: Names) {
|
||||
for (name, replaced) in other.noted {
|
||||
self.note(&name, replaced);
|
||||
}
|
||||
for h in other.more {
|
||||
self.count(h);
|
||||
}
|
||||
}
|
||||
|
||||
/// Take the notes of `other` on the names in `used` (names read but then not used, such as the
|
||||
/// layers of data whose layers aren't used, left out).
|
||||
pub fn absorb_among(&mut self, other: Names, used: &[&str]) {
|
||||
for (name, replaced) in other.noted {
|
||||
if used.contains(&name.as_str()) {
|
||||
self.note(&name, replaced);
|
||||
}
|
||||
}
|
||||
for n in used {
|
||||
let h = hash(n);
|
||||
if other.more.contains(&h) {
|
||||
self.count(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The notes on the names that weren't UTF-8.
|
||||
pub fn notes(&self) -> Vec<String> {
|
||||
let label = self.encoding.label();
|
||||
let mut out: Vec<String> = self
|
||||
.noted
|
||||
.iter()
|
||||
.map(|(name, replaced)| {
|
||||
if *replaced {
|
||||
format!(
|
||||
"the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding"
|
||||
)
|
||||
} else {
|
||||
format!("the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding")
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
if !self.more.is_empty() {
|
||||
out.push(format!("more names that aren't UTF-8 were read as {label} ({count})", count = self.more.len()));
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
fn cp1252(b: u8) -> char {
|
||||
const HIGH: [char; 32] = [
|
||||
'€', '\u{81}', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', '\u{8d}', 'Ž', '\u{8f}', '\u{90}', '‘', '’', '“', '”', '•', '–', '—',
|
||||
@@ -172,4 +403,107 @@ mod tests {
|
||||
assert_eq!(text(b"caf\xe9 \x80"), "café €");
|
||||
assert_eq!(text("ü".as_bytes()), "ü");
|
||||
}
|
||||
|
||||
/// The default reads every byte as Windows-1252 does, the five bytes it leaves undefined as the
|
||||
/// C1 controls of Latin-1, as `text` always has.
|
||||
#[test]
|
||||
fn names_default_to_windows_1252_with_latin_1_in_its_gaps() {
|
||||
let all: Vec<u8> = (0x80..=0xff).collect();
|
||||
let mut names = Names::default();
|
||||
assert_eq!(names.bytes(&all), text(&all));
|
||||
let gaps: String = [0x81u8, 0x8d, 0x8f, 0x90, 0x9d].iter().map(|b| names.bytes(&[*b])).collect();
|
||||
assert_eq!(gaps, "\u{81}\u{8d}\u{8f}\u{90}\u{9d}");
|
||||
assert_eq!(names.bytes(b"\x80\x9f"), "€Ÿ");
|
||||
}
|
||||
|
||||
/// A name that is UTF-8 is read as it is in every encoding, without a note.
|
||||
#[test]
|
||||
fn utf8_names_need_no_encoding() {
|
||||
for label in NameEncoding::LABELS {
|
||||
let mut names = Names::new(NameEncoding::from_label(label).unwrap());
|
||||
assert_eq!(names.bytes("레이어 1".as_bytes()), "레이어 1");
|
||||
assert_eq!(names.text(&V::Str(b"Layer 1".to_vec())).as_deref(), Some("Layer 1"));
|
||||
assert!(names.notes().is_empty(), "{label}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Each encoding reads the bytes of a name written in it.
|
||||
#[test]
|
||||
fn names_in_each_encoding() {
|
||||
for (label, bytes, want) in [
|
||||
("windows-1252", &b"Caf\xe9"[..], "Café"),
|
||||
("macintosh", b"Caf\x8e", "Café"),
|
||||
("windows-949", b"\xb7\xb9\xc0\xcc\xbe\xee 1", "레이어 1"),
|
||||
("euc-kr", b"\xb7\xb9\xc0\xcc\xbe\xee 1", "레이어 1"),
|
||||
("shift_jis", b"\x83\x8c\x83\x43\x83\x84\x81\x5b 1", "レイヤー 1"),
|
||||
("gbk", b"\xcd\xbc\xb2\xe3 1", "图层 1"),
|
||||
("big5", b"\xb9\xcf\xbch 1", "圖層 1"),
|
||||
] {
|
||||
let mut names = Names::new(NameEncoding::from_label(label).unwrap());
|
||||
assert_eq!(names.bytes(bytes), want, "{label}");
|
||||
assert_eq!(
|
||||
names.notes(),
|
||||
vec![format!(
|
||||
"the name `{want}` isn't UTF-8 and was read as {}: if it looks wrong, open the file with another legacyNameEncoding",
|
||||
names.encoding.label()
|
||||
)]
|
||||
);
|
||||
}
|
||||
assert_eq!(NameEncoding::from_label(" Windows-949 "), Some(NameEncoding::Korean));
|
||||
assert_eq!(NameEncoding::from_label("utf-8"), None);
|
||||
for label in NameEncoding::LABELS {
|
||||
assert_eq!(NameEncoding::from_label(label).map(NameEncoding::label), Some(label));
|
||||
}
|
||||
}
|
||||
|
||||
/// The Korean bytes read by default come in as Windows-1252, with a note naming what they
|
||||
/// became.
|
||||
#[test]
|
||||
fn korean_bytes_by_default_come_in_as_windows_1252_with_a_note() {
|
||||
let mut names = Names::default();
|
||||
let name = names.bytes(b"\xb7\xb9\xc0\xcc\xbe\xee 1");
|
||||
assert_eq!(name, "·¹À̾î 1");
|
||||
assert_eq!(
|
||||
names.notes(),
|
||||
vec!["the name `·¹À̾î 1` isn't UTF-8 and was read as windows-1252: if it looks wrong, open the file with another legacyNameEncoding"]
|
||||
);
|
||||
}
|
||||
|
||||
/// Bytes the encoding doesn't define come in as U+FFFD, and the note says so.
|
||||
#[test]
|
||||
fn malformed_names_keep_a_replacement_character() {
|
||||
let mut names = Names::new(NameEncoding::Korean);
|
||||
let name = names.bytes(b"\xb7\xb9\xc0 1");
|
||||
assert!(name.contains('\u{fffd}'), "{name:?}");
|
||||
assert!(name.starts_with('레'), "{name:?}");
|
||||
let notes = names.notes();
|
||||
assert_eq!(notes.len(), 1);
|
||||
assert!(notes[0].contains("isn't UTF-8, and parts of it aren't valid windows-949 either:"), "{notes:?}");
|
||||
}
|
||||
|
||||
/// The notes name the first names once each, and count the others.
|
||||
#[test]
|
||||
fn name_notes_are_capped() {
|
||||
let mut names = Names::new(NameEncoding::Macintosh);
|
||||
for i in 0..10u8 {
|
||||
let bytes = [b'a' + i, 0x8e];
|
||||
names.bytes(&bytes);
|
||||
names.bytes(&bytes);
|
||||
}
|
||||
let notes = names.notes();
|
||||
assert_eq!(notes.len(), MAX_NAME_NOTES + 1);
|
||||
assert!(notes[0].contains("`aé`"), "{notes:?}");
|
||||
assert_eq!(notes.last().map(String::as_str), Some("more names that aren't UTF-8 were read as macintosh (7)"));
|
||||
let mut all = Names::new(NameEncoding::Macintosh);
|
||||
all.absorb(names);
|
||||
assert_eq!(all.notes(), notes);
|
||||
// The count stops at its limit, whatever the file holds.
|
||||
let mut many = Names::new(NameEncoding::Macintosh);
|
||||
for i in 0..MAX_NAME_NOTES + MAX_NAMES_COUNTED + 50 {
|
||||
let mut bytes = i.to_string().into_bytes();
|
||||
bytes.push(0x8e);
|
||||
many.bytes(&bytes);
|
||||
}
|
||||
assert_eq!(many.notes().last().map(String::as_str), Some("more names that aren't UTF-8 were read as macintosh (10000)"));
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ use vectorcraft_color::gradient::{Gradient, GradientGeom, GradientKind, Gradient
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
|
||||
use super::lex::{Lexer, Tok};
|
||||
use super::obj::V;
|
||||
use super::obj::{NameEncoding, Names, V};
|
||||
|
||||
/// Largest number of stops read in one gradient.
|
||||
pub(crate) const MAX_STOPS: usize = 256;
|
||||
@@ -49,8 +49,8 @@ pub(super) struct Named {
|
||||
}
|
||||
|
||||
/// The paint of a colour operator's operands (`op`: its name, lower case or not), with the named
|
||||
/// colour it uses. `None` when the operands don't fit.
|
||||
pub(super) fn color_op(op: &str, vals: &[V]) -> Option<(Paint, Option<Named>)> {
|
||||
/// colour it uses, its name read by `names`. `None` when the operands don't fit.
|
||||
pub(super) fn color_op_in(op: &str, vals: &[V], names: &mut Names) -> Option<(Paint, Option<Named>)> {
|
||||
let nums: Vec<f32> = vals.iter().filter_map(V::num).map(|v| v as f32).collect();
|
||||
let unit = |v: f32| v.clamp(0.0, 1.0);
|
||||
let last = |n: usize| nums.get(nums.len().checked_sub(n)?..);
|
||||
@@ -64,9 +64,9 @@ pub(super) fn color_op(op: &str, vals: &[V]) -> Option<(Paint, Option<Named>)> {
|
||||
let [r, g, b] = last(3)? else { return None };
|
||||
Some((Paint::solid(Color::rgb(unit(*r), unit(*g), unit(*b))), None))
|
||||
}
|
||||
"x" => named(vals, Some(false)),
|
||||
"xx" => named(vals, None),
|
||||
"xk" => named(vals, None).map(|(p, n)| (p, n.map(|n| Named { spot: false, ..n }))),
|
||||
"x" => named(vals, Some(false), names),
|
||||
"xx" => named(vals, None, names),
|
||||
"xk" => named(vals, None, names).map(|(p, n)| (p, n.map(|n| Named { spot: false, ..n }))),
|
||||
"xs" | "xz" => registration(op, vals),
|
||||
_ => None,
|
||||
}
|
||||
@@ -78,14 +78,14 @@ fn is_registration(name: &str) -> bool {
|
||||
|
||||
/// `c m y k (name) tint x` or `c m y k [r g b | L a b] (name) tint type Xx` (type 1: RGB, 2: Lab);
|
||||
/// `rgb` forces RGB or CMYK.
|
||||
fn named(vals: &[V], rgb: Option<bool>) -> Option<(Paint, Option<Named>)> {
|
||||
fn named(vals: &[V], rgb: Option<bool>, names: &mut Names) -> Option<(Paint, Option<Named>)> {
|
||||
let at = vals.iter().rposition(|v| matches!(v, V::Str(_) | V::Name(_)))?;
|
||||
let name = vals.get(at)?.text()?;
|
||||
let name = vals.get(at)?;
|
||||
let before: Vec<f32> = vals.get(..at)?.iter().filter_map(V::num).map(|v| v as f32).collect();
|
||||
let after: Vec<f32> = vals.get(at + 1..)?.iter().filter_map(V::num).map(|v| v as f32).collect();
|
||||
let unit = |v: f32| v.clamp(0.0, 1.0);
|
||||
let tint = 1.0 - unit(*after.first()?);
|
||||
if is_registration(&name) {
|
||||
if is_registration(&name.text()?) {
|
||||
let full = Color::cmyk(1.0, 1.0, 1.0, 1.0);
|
||||
let paint = Paint::Solid { color: full.tinted(tint), swatch: Some(vectorcraft_color::swatch::REGISTRATION.into()), tint };
|
||||
return Some((paint, None));
|
||||
@@ -105,6 +105,7 @@ fn named(vals: &[V], rgb: Option<bool>) -> Option<(Paint, Option<Named>)> {
|
||||
let [c, m, y, k] = before.get(from..from + 4)? else { return None };
|
||||
Color::cmyk(unit(*c), unit(*m), unit(*y), unit(*k))
|
||||
};
|
||||
let name = names.text(name)?;
|
||||
let paint = Paint::Solid { color: color.tinted(tint), swatch: Some(name.clone()), tint };
|
||||
Some((paint, Some(Named { name, color, tint, spot: true })))
|
||||
}
|
||||
@@ -130,7 +131,7 @@ fn registration(op: &str, vals: &[V]) -> Option<(Paint, Option<Named>)> {
|
||||
}
|
||||
|
||||
/// The colour of a gradient stop's colour values and style.
|
||||
fn stop_color(style: f64, comps: &[V]) -> Option<(Color, Option<Named>)> {
|
||||
fn stop_color(style: f64, comps: &[V], names: &mut Names) -> Option<(Color, Option<Named>)> {
|
||||
let nums: Vec<f32> = comps.iter().filter_map(V::num).map(|v| v as f32).collect();
|
||||
let unit = |v: f32| v.clamp(0.0, 1.0);
|
||||
let tail = |n: usize| nums.get(nums.len().checked_sub(n)?..);
|
||||
@@ -145,7 +146,7 @@ fn stop_color(style: f64, comps: &[V]) -> Option<(Color, Option<Named>)> {
|
||||
(Color::rgb(unit(*r), unit(*g), unit(*b)), None)
|
||||
}
|
||||
_ => {
|
||||
let (paint, named) = named(comps, Some(style as i64 == 4))?;
|
||||
let (paint, named) = named(comps, Some(style as i64 == 4), names)?;
|
||||
(paint.color()?, named)
|
||||
}
|
||||
})
|
||||
@@ -159,16 +160,16 @@ pub(super) struct GradientDef {
|
||||
}
|
||||
|
||||
impl GradientDef {
|
||||
/// `(name) type stops Bd`.
|
||||
pub fn begin(vals: &[V]) -> Option<Self> {
|
||||
let name = vals.iter().find_map(|v| if let V::Str(_) = v { v.text() } else { None })?;
|
||||
/// `(name) type stops Bd`, the name read by `names`.
|
||||
pub fn begin(vals: &[V], names: &mut Names) -> Option<Self> {
|
||||
let name = vals.iter().find(|v| matches!(v, V::Str(_))).and_then(|v| names.text(v))?;
|
||||
let nums: Vec<f64> = vals.iter().filter_map(V::num).collect();
|
||||
let kind = if nums.first().copied() == Some(1.0) { GradientKind::Radial } else { GradientKind::Linear };
|
||||
Some(Self { name, gradient: Gradient::new(kind, vec![]) })
|
||||
}
|
||||
|
||||
/// A stop (`Bs`).
|
||||
pub fn stop(&mut self, vals: &[V], spots: &mut Vec<Named>) {
|
||||
/// A stop (`Bs`), the name of its colour read by `names`.
|
||||
pub fn stop(&mut self, vals: &[V], spots: &mut Vec<Named>, names: &mut Names) {
|
||||
if self.gradient.stops.len() >= MAX_STOPS {
|
||||
return;
|
||||
}
|
||||
@@ -179,7 +180,7 @@ impl GradientDef {
|
||||
let newer = n >= 5 && n.checked_sub(3).and_then(num) == Some(6.0);
|
||||
let (style_at, opacity) = if newer { (n.checked_sub(5), n.checked_sub(4).and_then(num).unwrap_or(1.0)) } else { (n.checked_sub(3), 1.0) };
|
||||
let (Some(style_at), Some(style)) = (style_at, style_at.and_then(num)) else { return };
|
||||
let Some((color, named)) = stop_color(style, vals.get(..style_at).unwrap_or_default()) else { return };
|
||||
let Some((color, named)) = stop_color(style, vals.get(..style_at).unwrap_or_default(), names) else { return };
|
||||
let mut stop = GradientStop::new((ramp / 100.0).clamp(0.0, 1.0) as f32, color);
|
||||
stop.opacity = opacity.clamp(0.0, 1.0) as f32;
|
||||
stop.midpoint = (mid / 100.0).clamp(0.13, 0.87) as f32;
|
||||
@@ -225,9 +226,16 @@ pub(super) struct ColorNames {
|
||||
vals: Vec<V>,
|
||||
def: Option<GradientDef>,
|
||||
spots: Vec<Named>,
|
||||
/// Reads the names found (the reader reads them again, and keeps the notes on them).
|
||||
decoder: Names,
|
||||
}
|
||||
|
||||
impl ColorNames {
|
||||
/// The names found to be read in `encoding`.
|
||||
pub fn new(encoding: NameEncoding) -> Self {
|
||||
Self { decoder: Names::new(encoding), ..Self::default() }
|
||||
}
|
||||
|
||||
pub fn token(&mut self, tok: Tok<'_>) {
|
||||
self.take(tok, true);
|
||||
}
|
||||
@@ -252,7 +260,7 @@ impl ColorNames {
|
||||
};
|
||||
let vals = std::mem::take(&mut self.vals);
|
||||
match w {
|
||||
b"Bd" => self.def = GradientDef::begin(&vals),
|
||||
b"Bd" => self.def = GradientDef::begin(&vals, &mut self.decoder),
|
||||
b"BD" => {
|
||||
if let Some((name, _)) = self.def.take().and_then(GradientDef::finish) {
|
||||
self.gradients.push(name);
|
||||
@@ -260,18 +268,18 @@ impl ColorNames {
|
||||
}
|
||||
b"Bs" => {
|
||||
if let Some(d) = self.def.as_mut() {
|
||||
d.stop(&vals, &mut self.spots);
|
||||
d.stop(&vals, &mut self.spots, &mut self.decoder);
|
||||
}
|
||||
}
|
||||
b"x" | b"X" | b"Xx" | b"XX" | b"Xk" | b"XK" => {
|
||||
if let Some((_, Some(n))) = std::str::from_utf8(w).ok().and_then(|op| color_op(op, &vals)) {
|
||||
if let Some((_, Some(n))) = std::str::from_utf8(w).ok().and_then(|op| color_op_in(op, &vals, &mut self.decoder)) {
|
||||
self.spots.push(n);
|
||||
}
|
||||
}
|
||||
b"@" | b"&" if outer => {
|
||||
for v in &vals {
|
||||
if let V::Str(s) = v {
|
||||
let mut inner = ColorNames::default();
|
||||
let mut inner = ColorNames::new(self.decoder.encoding);
|
||||
let mut lex = Lexer::new(s);
|
||||
while let Some(t) = lex.next_token() {
|
||||
inner.take(t.tok, false);
|
||||
@@ -396,10 +404,10 @@ impl Instance {
|
||||
Self { stroke, length: 1.0, ..Self::default() }
|
||||
}
|
||||
|
||||
/// `flag (name) x y angle length a b c d tx ty Bg`.
|
||||
pub fn bg(&mut self, vals: &[V]) {
|
||||
/// `flag (name) x y angle length a b c d tx ty Bg`, the name read by `names`.
|
||||
pub fn bg(&mut self, vals: &[V], names: &mut Names) {
|
||||
let Some(at) = vals.iter().rposition(|v| matches!(v, V::Str(_))) else { return };
|
||||
self.name = vals.get(at).and_then(V::text);
|
||||
self.name = vals.get(at).and_then(|v| names.text(v));
|
||||
let n: Vec<f64> = vals.get(at + 1..).unwrap_or_default().iter().filter_map(V::num).collect();
|
||||
if let [x, y, angle, length, m @ ..] = n.as_slice() {
|
||||
self.origin = Point::new(*x, *y);
|
||||
@@ -520,6 +528,35 @@ mod tests {
|
||||
v.iter().map(|n| V::Num(*n)).collect()
|
||||
}
|
||||
|
||||
fn color_op(op: &str, vals: &[V]) -> Option<(Paint, Option<Named>)> {
|
||||
color_op_in(op, vals, &mut Names::default())
|
||||
}
|
||||
|
||||
/// A named colour, a gradient and its stop's colour, and the gradient an object names, read in
|
||||
/// the encoding picked, so that names written alike match.
|
||||
#[test]
|
||||
fn colour_and_gradient_names_read_in_the_encoding() {
|
||||
let mut names = Names::new(super::super::obj::NameEncoding::Korean);
|
||||
let mut v = nums(&[0.0, 0.5, 1.0, 0.0]);
|
||||
v.extend([V::Str(b"\xbb\xa1\xb0\xad".to_vec()), V::Num(0.0)]);
|
||||
let (_, named) = color_op_in("x", &v, &mut names).unwrap();
|
||||
assert_eq!(named.unwrap().name, "빨강");
|
||||
let mut d = GradientDef::begin(&[V::Str(b"\xb1\xd7\xb6\xf3".to_vec()), V::Num(0.0)], &mut names).unwrap();
|
||||
let mut stop = nums(&[0.0, 0.5, 1.0, 0.0]);
|
||||
stop.extend([V::Str(b"\xbb\xa1\xb0\xad".to_vec()), V::Num(0.0), V::Num(3.0), V::Num(50.0), V::Num(0.0)]);
|
||||
let mut spots = vec![];
|
||||
d.stop(&stop, &mut spots, &mut names);
|
||||
assert_eq!(spots.first().map(|s| s.name.as_str()), Some("빨강"));
|
||||
let (name, g) = d.finish().unwrap();
|
||||
assert_eq!(name, "그라");
|
||||
let mut i = Instance::begin(&[]);
|
||||
let mut bg = vec![V::Num(1.0), V::Str(b"\xb1\xd7\xb6\xf3".to_vec())];
|
||||
bg.extend(nums(&[0.0, 0.0, 0.0, 10.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0]));
|
||||
i.bg(&bg, &mut names);
|
||||
assert!(i.paint(&HashMap::from([(name, g)]), &ShownNames::default(), Affine::IDENTITY).is_some());
|
||||
assert_eq!(names.notes().len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn registration_paints_with_the_registration_swatch_at_its_tint() {
|
||||
let mut v = nums(&[0.75, 0.68, 0.67, 0.9, 0.0, 0.0, 0.0]);
|
||||
@@ -608,10 +645,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn gradient_definition_and_instance() {
|
||||
let mut d = GradientDef::begin(&[V::Str(b"G".to_vec()), V::Num(1.0), V::Num(2.0)]).unwrap();
|
||||
let names = &mut Names::default();
|
||||
let mut d = GradientDef::begin(&[V::Str(b"G".to_vec()), V::Num(1.0), V::Num(2.0)], names).unwrap();
|
||||
let mut spots = vec![];
|
||||
d.stop(&nums(&[0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 2.0, 0.5, 6.0, 30.0, 100.0]), &mut spots);
|
||||
d.stop(&nums(&[0.81, 0.0, 1.0, 6.0, 50.0, 0.0]), &mut spots);
|
||||
d.stop(&nums(&[0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 2.0, 0.5, 6.0, 30.0, 100.0]), &mut spots, names);
|
||||
d.stop(&nums(&[0.81, 0.0, 1.0, 6.0, 50.0, 0.0]), &mut spots, names);
|
||||
let (name, g) = d.finish().unwrap();
|
||||
assert_eq!(name, "G");
|
||||
assert_eq!(g.kind, GradientKind::Radial);
|
||||
@@ -622,7 +660,7 @@ mod tests {
|
||||
let mut i = Instance::begin(&[]);
|
||||
let mut bg = vec![V::Num(1.0), V::Str(b"G".to_vec())];
|
||||
bg.extend(nums(&[100.0, 100.0, 0.0, 50.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0]));
|
||||
i.bg(&bg);
|
||||
i.bg(&bg, names);
|
||||
i.bm(&nums(&[50.0, 0.0, 0.0, -50.0, 100.0, 100.0]));
|
||||
let shown = ShownNames::default();
|
||||
let Some(Paint::Gradient(gp)) = i.paint(&defs, &shown, Affine::IDENTITY) else { panic!() };
|
||||
@@ -634,7 +672,7 @@ mod tests {
|
||||
assert!(i.paint(&HashMap::new(), &shown, Affine::IDENTITY).is_none());
|
||||
// Newer files give the matrix with `Xm`; the `Bm`s after it are bands of a cached ramp.
|
||||
let mut i = Instance::begin(&[]);
|
||||
i.bg(&bg);
|
||||
i.bg(&bg, names);
|
||||
i.xm(&nums(&[40.0, 0.0, 0.0, -40.0, 10.0, 10.0]));
|
||||
i.bm(&nums(&[5.0, 0.0, 0.0, -40.0, 30.0, 10.0]));
|
||||
let Some(Paint::Gradient(gp)) = i.paint(&defs, &shown, Affine::IDENTITY) else { panic!() };
|
||||
@@ -679,11 +717,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn gradient_stops_beyond_the_cap_are_ignored() {
|
||||
let mut d = GradientDef::begin(&[V::Str(b"H".to_vec()), V::Num(0.0)]).unwrap();
|
||||
let names = &mut Names::default();
|
||||
let mut d = GradientDef::begin(&[V::Str(b"H".to_vec()), V::Num(0.0)], names).unwrap();
|
||||
let mut spots = vec![];
|
||||
for i in 0..257 {
|
||||
let ramp = i as f64 / 256.0 * 100.0;
|
||||
d.stop(&nums(&[0.2, 0.4, 0.6, 0.0, 1.0, 1.0, 6.0, 50.0, ramp]), &mut spots);
|
||||
d.stop(&nums(&[0.2, 0.4, 0.6, 0.0, 1.0, 1.0, 6.0, 50.0, ramp]), &mut spots, names);
|
||||
}
|
||||
let (_, g) = d.finish().unwrap();
|
||||
assert_eq!(g.stops.len(), MAX_STOPS);
|
||||
@@ -694,9 +733,10 @@ mod tests {
|
||||
#[test]
|
||||
fn stops_at_one_ramp_point_keep_their_sides() {
|
||||
for (kind, listed) in [(0.0, [0.75, 0.25]), (1.0, [0.25, 0.75])] {
|
||||
let mut d = GradientDef::begin(&[V::Str(b"E".to_vec()), V::Num(kind), V::Num(2.0)]).unwrap();
|
||||
let names = &mut Names::default();
|
||||
let mut d = GradientDef::begin(&[V::Str(b"E".to_vec()), V::Num(kind), V::Num(2.0)], names).unwrap();
|
||||
for (gray, mid) in listed.into_iter().zip([40.0, 70.0]) {
|
||||
d.stop(&nums(&[gray, 0.0, 1.0, 6.0, mid, 30.0]), &mut vec![]);
|
||||
d.stop(&nums(&[gray, 0.0, 1.0, 6.0, mid, 30.0]), &mut vec![], names);
|
||||
}
|
||||
let (_, g) = d.finish().unwrap();
|
||||
let lightness: Vec<f32> = g.stops.iter().map(|s| (s.color.to_rgb()[0] * 100.0).round() / 100.0).collect();
|
||||
@@ -711,16 +751,17 @@ mod tests {
|
||||
/// art space, `Xm` for the whole ramp and a `Bm` for each pair of stops.
|
||||
#[test]
|
||||
fn a_linear_gradient_runs_its_whole_ramp_not_its_last_part() {
|
||||
let mut d = GradientDef::begin(&[V::Str(b"L".to_vec()), V::Num(0.0), V::Num(3.0)]).unwrap();
|
||||
let names = &mut Names::default();
|
||||
let mut d = GradientDef::begin(&[V::Str(b"L".to_vec()), V::Num(0.0), V::Num(3.0)], names).unwrap();
|
||||
for ramp in [100.0, 60.0, 20.0] {
|
||||
d.stop(&nums(&[0.2, 0.4, 0.6, 0.0, 1.0, 1.0, 6.0, 50.0, ramp]), &mut vec![]);
|
||||
d.stop(&nums(&[0.2, 0.4, 0.6, 0.0, 1.0, 1.0, 6.0, 50.0, ramp]), &mut vec![], names);
|
||||
}
|
||||
let defs = HashMap::from([d.finish().unwrap()]);
|
||||
let instance = |xm: bool| {
|
||||
let mut i = Instance::begin(&[]);
|
||||
let mut bg = vec![V::Num(1.0), V::Str(b"L".to_vec())];
|
||||
bg.extend(nums(&[0.3, -0.2, -90.0, 0.5, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0]));
|
||||
i.bg(&bg);
|
||||
i.bg(&bg, &mut Names::default());
|
||||
if xm {
|
||||
i.xm(&nums(&[0.0, -200.0, -30.0, 0.0, 10.0, 300.0]));
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ use vectorcraft_color::Color;
|
||||
use vectorcraft_doc::swatches::color_name;
|
||||
|
||||
use super::lex::{Lexer, Tok};
|
||||
use super::obj::V;
|
||||
use super::obj::{Names, V};
|
||||
use super::paint::{self, Named};
|
||||
|
||||
/// Largest number of swatches read from one palette.
|
||||
@@ -73,8 +73,9 @@ impl Palette {
|
||||
}
|
||||
}
|
||||
|
||||
/// The palette of `data`: what follows `%AI5_BeginPalette`, up to its end.
|
||||
pub(super) fn palette(data: &[u8]) -> Palette {
|
||||
/// The palette of `data`: what follows `%AI5_BeginPalette`, up to its end, its names read by
|
||||
/// `names`.
|
||||
pub(super) fn palette(data: &[u8], names: &mut Names) -> Palette {
|
||||
let mut lex = Lexer::new(data);
|
||||
let mut out = Palette::default();
|
||||
let mut vals: Vec<V> = Vec::new();
|
||||
@@ -125,15 +126,15 @@ pub(super) fn palette(data: &[u8]) -> Palette {
|
||||
cell = None;
|
||||
}
|
||||
"Bg" if in_gradient => {
|
||||
if let Some(name) = last_text(&vals) {
|
||||
if let Some(name) = last_text(&vals, names) {
|
||||
cell = Some(Entry { cell: Cell::Gradient(name.clone()), name });
|
||||
}
|
||||
}
|
||||
"BB" => in_gradient = false,
|
||||
"p" => cell = first_text(&vals).map(|name| Entry { cell: Cell::Pattern(name.clone()), name }),
|
||||
"p" => cell = first_text(&vals, names).map(|name| Entry { cell: Cell::Pattern(name.clone()), name }),
|
||||
"Xs" | "Xz" | "XS" | "XZ" => cell = None,
|
||||
"g" | "k" | "x" | "Xa" | "Xx" | "Xk" => {
|
||||
cell = paint::color_op(w, &vals).and_then(|(p, named)| match named {
|
||||
cell = paint::color_op_in(w, &vals, names).and_then(|(p, named)| match named {
|
||||
Some(Named { name, color, spot, .. }) => Some(Entry { name, cell: Cell::Color { color, global: true, spot } }),
|
||||
None => p.color().map(|color| Entry { name: color_name(color), cell: Cell::Color { color, global: false, spot: false } }),
|
||||
});
|
||||
@@ -141,7 +142,7 @@ pub(super) fn palette(data: &[u8]) -> Palette {
|
||||
"Pg" => {
|
||||
cell = None;
|
||||
// Capped as swatches are: a file of many `Pg` would make as many empty groups.
|
||||
if let Some(name) = first_text(&vals)
|
||||
if let Some(name) = first_text(&vals, names)
|
||||
&& out.groups.len() < MAX_SWATCHES
|
||||
{
|
||||
out.groups.push((name, Vec::new()));
|
||||
@@ -150,7 +151,7 @@ pub(super) fn palette(data: &[u8]) -> Palette {
|
||||
"Pc" => {
|
||||
// The name before `Pc`, or the one the paint gives; `[Registration]` and the other
|
||||
// built-in swatches every document has are left out.
|
||||
let name = last_text(&vals);
|
||||
let name = last_text(&vals, names);
|
||||
if let Some(mut e) = cell.take()
|
||||
&& !name.as_ref().is_some_and(|n| n.starts_with('['))
|
||||
&& count < MAX_SWATCHES
|
||||
@@ -181,12 +182,12 @@ fn push(vals: &mut Vec<V>, v: V) {
|
||||
}
|
||||
}
|
||||
|
||||
fn first_text(vals: &[V]) -> Option<String> {
|
||||
vals.iter().find(|v| matches!(v, V::Str(_))).and_then(V::text)
|
||||
fn first_text(vals: &[V], names: &mut Names) -> Option<String> {
|
||||
vals.iter().find(|v| matches!(v, V::Str(_))).and_then(|v| names.text(v))
|
||||
}
|
||||
|
||||
fn last_text(vals: &[V]) -> Option<String> {
|
||||
vals.iter().rev().find(|v| matches!(v, V::Str(_))).and_then(V::text)
|
||||
fn last_text(vals: &[V], names: &mut Names) -> Option<String> {
|
||||
vals.iter().rev().find(|v| matches!(v, V::Str(_))).and_then(|v| names.text(v))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -197,6 +198,21 @@ mod tests {
|
||||
Entry { name: name.into(), cell: Cell::Color { color, global, spot } }
|
||||
}
|
||||
|
||||
fn palette(data: &[u8]) -> Palette {
|
||||
super::palette(data, &mut Names::default())
|
||||
}
|
||||
|
||||
/// Swatch, group and spot colour names that aren't UTF-8 are read in the encoding picked.
|
||||
#[test]
|
||||
fn palette_names_read_in_the_encoding() {
|
||||
let mut names = Names::new(super::super::obj::NameEncoding::ShiftJis);
|
||||
// 赤 (red) and 色 (color) in Shift_JIS.
|
||||
let p = super::palette(b"0 0 Pb\n0 (\x90\x46) 1 Pg\n0 1 1 0 (\x90\xd4) 0 x\n(\x90\xd4)\nPc\nPB\n", &mut names);
|
||||
assert_eq!(p.groups.first().map(|(n, s)| (n.as_str(), s.len())), Some(("色", 1)));
|
||||
assert_eq!(p.groups.first().and_then(|(_, s)| s.first()), Some(&color("赤", Color::cmyk(0.0, 1.0, 1.0, 0.0), true, true)));
|
||||
assert_eq!(names.notes().len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_palette_gives_its_swatches_in_order() {
|
||||
let p = palette(
|
||||
|
||||
@@ -125,7 +125,7 @@ use vectorcraft_geom::{AnchorKind, FillRule, PathData};
|
||||
use super::super::ate::CANVAS_CENTRE;
|
||||
use super::super::graphics::HAIRLINE;
|
||||
use super::lex::{Lexer, Tok};
|
||||
use super::obj::{self, Obj, V};
|
||||
use super::obj::{self, NameEncoding, Obj, V};
|
||||
use super::paint::{self, Global, GradientDef, Instance, Named, ShownNames};
|
||||
use crate::ps;
|
||||
|
||||
@@ -238,22 +238,30 @@ pub(super) fn remember_xml_id(xml_ids: &mut HashMap<String, Option<NodeId>>, byt
|
||||
}
|
||||
}
|
||||
|
||||
/// [`read_in`], names that aren't UTF-8 read as Windows-1252.
|
||||
#[cfg(test)]
|
||||
pub fn read(data: &[u8], large_canvas: bool) -> Result<Structure, String> {
|
||||
read_in(data, large_canvas, NameEncoding::default())
|
||||
}
|
||||
|
||||
/// Read the structure of the editing data `data`, applying the file's `%AI24_LargeCanvasScale` only
|
||||
/// when `large_canvas` is set: an EPS's page is drawn at the full size, but a `.ai`'s PDF part may
|
||||
/// keep the reduced one, which the PDF import reads as it is (#2031).
|
||||
pub fn read(data: &[u8], large_canvas: bool) -> Result<Structure, String> {
|
||||
read_with(data, large_canvas, false)
|
||||
/// keep the reduced one, which the PDF import reads as it is (#2031). Names that aren't UTF-8
|
||||
/// (layers, objects, artboards, colors, gradients, patterns, graphic styles, swatches, brushes,
|
||||
/// symbols, variables and data sets) are read in `names`, each with a warning.
|
||||
pub fn read_in(data: &[u8], large_canvas: bool, names: NameEncoding) -> Result<Structure, String> {
|
||||
read_with(data, large_canvas, false, names)
|
||||
}
|
||||
|
||||
/// [`read`] for a file whose page art replaces the objects the reader doesn't read (see
|
||||
/// [`read_in`] for a file whose page art replaces the objects the reader doesn't read (see
|
||||
/// [`Reader::unread_box`]): an image past the hard limits ([`raster::Limits`]) is then such an
|
||||
/// object, where [`read`] leaves it out with a note.
|
||||
pub(crate) fn read_over_page(data: &[u8], large_canvas: bool) -> Result<Structure, String> {
|
||||
read_with(data, large_canvas, true)
|
||||
/// object, where [`read_in`] leaves it out with a note.
|
||||
pub(crate) fn read_over_page(data: &[u8], large_canvas: bool, names: NameEncoding) -> Result<Structure, String> {
|
||||
read_with(data, large_canvas, true, names)
|
||||
}
|
||||
|
||||
fn read_with(data: &[u8], large_canvas: bool, page_art: bool) -> Result<Structure, String> {
|
||||
let mut r = Reader::with_names(data);
|
||||
fn read_with(data: &[u8], large_canvas: bool, page_art: bool, names: NameEncoding) -> Result<Structure, String> {
|
||||
let mut r = Reader::with_names(data, names);
|
||||
r.large_canvas = large_canvas.then_some(1.0);
|
||||
r.page_art = page_art;
|
||||
r.run()?;
|
||||
@@ -263,17 +271,18 @@ fn read_with(data: &[u8], large_canvas: bool, page_art: bool) -> Result<Structur
|
||||
/// How many objects [`read`] counts against [`MAX_NODES`] in the editing data `data`.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn objects_read(data: &[u8]) -> Result<usize, String> {
|
||||
let mut r = Reader::with_names(data);
|
||||
let mut r = Reader::with_names(data, NameEncoding::default());
|
||||
r.run()?;
|
||||
Ok(r.nodes)
|
||||
}
|
||||
|
||||
/// [`read`] for editing data kept apart from the program `ps` it came with (an EPS's private
|
||||
/// data): the program's header gives the author and the custom colors the editing data's header
|
||||
/// doesn't. `page_art`: as [`read_over_page`] reads a file.
|
||||
pub fn read_beside(data: &[u8], large_canvas: bool, ps: &[u8], page_art: bool) -> Result<Structure, String> {
|
||||
let header = Reader::header_of(ps);
|
||||
let mut r = Reader::with_names(data);
|
||||
/// doesn't. `page_art`: as [`read_over_page`] reads a file. `names`: the encoding of names that
|
||||
/// aren't UTF-8.
|
||||
pub fn read_beside(data: &[u8], large_canvas: bool, ps: &[u8], page_art: bool, names: NameEncoding) -> Result<Structure, String> {
|
||||
let header = Reader::header_of(ps, names);
|
||||
let mut r = Reader::with_names(data, names);
|
||||
r.large_canvas = large_canvas.then_some(1.0);
|
||||
r.page_art = page_art;
|
||||
// The program's custom colors have swatches of their names, which no gradient or pattern takes.
|
||||
@@ -292,8 +301,8 @@ pub fn read_beside(data: &[u8], large_canvas: bool, ps: &[u8], page_art: bool) -
|
||||
/// and patterns. Names come only from what the reader reads: not from the alternates of versioned
|
||||
/// content, the prolog, resources, sections it skips (such as symbols and the text document) or
|
||||
/// what follows the trailer. The palette the reader keeps is the last one outside those and the
|
||||
/// sections it reads on their own.
|
||||
fn swatch_names(data: &[u8]) -> (ShownNames, Option<&[u8]>) {
|
||||
/// sections it reads on their own. Names that aren't UTF-8 are read in `encoding`.
|
||||
fn swatch_names(data: &[u8], encoding: NameEncoding) -> (ShownNames, Option<&[u8]>) {
|
||||
/// The sections the reader reads on their own whose definitions and colors it keeps.
|
||||
const READ_APART: &[&str] = &["BeginPattern", "BeginBrushPattern", "BeginPluginObject", "BeginArtStyles", "BeginArtStyleList"];
|
||||
/// Whether the marker `m` ends what began with `begin` and ends with `end`, `depth` of its kind
|
||||
@@ -311,7 +320,9 @@ fn swatch_names(data: &[u8]) -> (ShownNames, Option<&[u8]>) {
|
||||
}
|
||||
let mut names = ShownNames::default();
|
||||
names.reserve(vectorcraft_color::swatch::REGISTRATION);
|
||||
let mut colors = paint::ColorNames::default();
|
||||
// The reader reads these names again, and keeps the notes on them.
|
||||
let mut decoder = obj::Names::new(encoding);
|
||||
let mut colors = paint::ColorNames::new(encoding);
|
||||
let mut lex = Lexer::new(data);
|
||||
// What the reader skips wherever it is (the marker of one of its kind nested in it, its end
|
||||
// marker, how many are open inside it, and where reading goes on when it doesn't end), the
|
||||
@@ -386,7 +397,7 @@ fn swatch_names(data: &[u8]) -> (ShownNames, Option<&[u8]>) {
|
||||
// A palette's names are those of the palette kept, as the palette reads them.
|
||||
_ if skip.is_some() || palette_at.is_some() || section.is_some_and(|s| !s.3) => continue,
|
||||
Tok::Str(s) | Tok::Hex(s) if std::mem::take(&mut head) => {
|
||||
let text = obj::text(s);
|
||||
let text = decoder.bytes(s);
|
||||
if !text.contains('\n') {
|
||||
names.reserve(&text);
|
||||
}
|
||||
@@ -396,7 +407,7 @@ fn swatch_names(data: &[u8]) -> (ShownNames, Option<&[u8]>) {
|
||||
colors.token(t.tok);
|
||||
}
|
||||
colors.gradients.iter().filter(|n| !n.contains('\n')).for_each(|n| names.reserve(n));
|
||||
let palette = palette.map(super::palette::palette).unwrap_or_default();
|
||||
let palette = palette.map(|p| super::palette::palette(p, &mut decoder)).unwrap_or_default();
|
||||
if palette.is_empty() {
|
||||
for mode in [ColorMode::Rgb, ColorMode::Cmyk] {
|
||||
let (swatches, groups) = vectorcraft_color::default_swatches(mode.model());
|
||||
@@ -631,6 +642,8 @@ struct Reader<'a> {
|
||||
/// The legacy text object being read (`To` … `TO`), and the modal type attributes.
|
||||
text: Option<legacy_text::LegacyText>,
|
||||
type_state: legacy_text::TypeState,
|
||||
/// How names that aren't UTF-8 are read, and the notes on them.
|
||||
names: obj::Names,
|
||||
/// The file has brush objects (the brush manager's order or a brush).
|
||||
brush_objects: bool,
|
||||
/// The brush manager's order.
|
||||
@@ -668,13 +681,14 @@ pub(crate) fn is_look_slot(name: Option<&str>) -> bool {
|
||||
impl<'a> Reader<'a> {
|
||||
/// A reader of the editing data `data` as a whole, with the names its gradients and patterns
|
||||
/// get in the document and its art styles found first ([`swatch_names`]): the symbols defined
|
||||
/// before the art styles section use them too.
|
||||
fn with_names(data: &'a [u8]) -> Self {
|
||||
/// before the art styles section use them too. Names that aren't UTF-8 are read in `encoding`.
|
||||
fn with_names(data: &'a [u8], encoding: NameEncoding) -> Self {
|
||||
let mut r = Self::new(data);
|
||||
let (names, styles) = swatch_names(data);
|
||||
r.names = obj::Names::new(encoding);
|
||||
let (names, styles) = swatch_names(data, encoding);
|
||||
r.global_names = names;
|
||||
if let Some(section) = styles {
|
||||
r.styles = super::style::art_styles(section);
|
||||
r.styles = super::style::art_styles_in(section, &mut r.names);
|
||||
}
|
||||
r
|
||||
}
|
||||
@@ -794,6 +808,7 @@ impl<'a> Reader<'a> {
|
||||
v7_patterns: HashSet::new(),
|
||||
text: None,
|
||||
type_state: legacy_text::TypeState::default(),
|
||||
names: obj::Names::default(),
|
||||
brush_objects: false,
|
||||
brush_order: None,
|
||||
brush_drafts: Vec::new(),
|
||||
|
||||
@@ -640,7 +640,7 @@ impl<'a> Reader<'a> {
|
||||
/// comes in as the page draws it, within the symbol's box placed by the matrix when the box is
|
||||
/// known.
|
||||
fn symbol_instance(&mut self, o: &Obj) -> Result<(), String> {
|
||||
let name = o.text("SymbolRef");
|
||||
let name = self.names.entry(o, "SymbolRef");
|
||||
let affine = |n: &[f64]| match n {
|
||||
[a, b, c, d, e, f] if [a, b, c, d, e, f].iter().all(|v| v.is_finite()) => Some(super::Affine::new([*a, *b, *c, *d, *e, *f])),
|
||||
_ => None,
|
||||
|
||||
@@ -123,7 +123,7 @@ impl<'a> Reader<'a> {
|
||||
// GUARDS: a definition's art takes the file's art styles and hands them back, so a
|
||||
// section inside it would replace the file's own.
|
||||
if self.subreader_depth == 0 {
|
||||
self.styles = crate::import::ai::style::art_styles(section);
|
||||
self.styles = crate::import::ai::style::art_styles_in(section, &mut self.names);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
@@ -134,7 +134,7 @@ impl<'a> Reader<'a> {
|
||||
}
|
||||
if m == "BeginPalette" {
|
||||
let section = self.section("EndPalette")?;
|
||||
self.palette = crate::import::ai::palette::palette(section);
|
||||
self.palette = crate::import::ai::palette::palette(section, &mut self.names);
|
||||
return Ok(());
|
||||
}
|
||||
if m == "BeginEncoding" {
|
||||
@@ -309,7 +309,7 @@ impl<'a> Reader<'a> {
|
||||
return;
|
||||
}
|
||||
let Some(open) = v.iter().position(|&b| b == b'(') else { return };
|
||||
let (Some(head), Some(name)) = (v.get(..open), v.get(open..).and_then(ps_string)) else { return };
|
||||
let (Some(head), Some(name)) = (v.get(..open), v.get(open..).and_then(ps_bytes)) else { return };
|
||||
// One more than a color has, so that too many are seen.
|
||||
let parts: Vec<Option<f32>> = head
|
||||
.split(u8::is_ascii_whitespace)
|
||||
@@ -322,6 +322,7 @@ impl<'a> Reader<'a> {
|
||||
[Some(r), Some(g), Some(b)] if !cmyk => vectorcraft_color::Color::rgb(*r, *g, *b),
|
||||
_ => return,
|
||||
};
|
||||
let name = self.names.bytes(&name);
|
||||
if !name.trim().is_empty() && !self.custom_colors.iter().any(|n| n.name == name) {
|
||||
// A gradient or pattern defined after it does not take its swatch's name.
|
||||
self.global_names.reserve(&name);
|
||||
@@ -378,6 +379,7 @@ impl<'a> Reader<'a> {
|
||||
Legacy::Yes(def) => return self.define_legacy_pattern(&def),
|
||||
}
|
||||
let mut sub = Reader::new(section);
|
||||
sub.names = super::obj::Names::new(self.names.encoding);
|
||||
sub.subreader_depth = self.subreader_depth + 1;
|
||||
sub.pattern = Some(PatternHead::default());
|
||||
// The gradients and art styles defined so far and the names given, lent (and the gradients
|
||||
@@ -392,6 +394,7 @@ impl<'a> Reader<'a> {
|
||||
self.take_back_budgets(&mut sub);
|
||||
self.nodes = sub.nodes;
|
||||
self.gradients = std::mem::take(&mut sub.gradients);
|
||||
self.names.absorb(std::mem::take(&mut sub.names));
|
||||
self.global_names = std::mem::take(&mut sub.global_names);
|
||||
self.styles = std::mem::take(&mut sub.styles);
|
||||
// Unread art in the definition, hidden or not, leaves the tile incomplete.
|
||||
@@ -409,8 +412,9 @@ impl<'a> Reader<'a> {
|
||||
/// tile's box (`_ &`). Each layer starts from the state the definition starts with.
|
||||
fn define_legacy_pattern(&mut self, def: &LegacyPattern) {
|
||||
let mut sub = Reader::new(b"");
|
||||
sub.names = super::obj::Names::new(self.names.encoding);
|
||||
sub.subreader_depth = self.subreader_depth + 1;
|
||||
sub.pattern = Some(PatternHead { taken: true, name: def.name.clone(), tile: Some(def.tile) });
|
||||
sub.pattern = Some(PatternHead { taken: true, name: self.names.bytes(&def.name), tile: Some(def.tile) });
|
||||
sub.gradients = std::mem::take(&mut self.gradients);
|
||||
sub.global_names = std::mem::take(&mut self.global_names);
|
||||
sub.styles = std::mem::take(&mut self.styles);
|
||||
@@ -429,6 +433,7 @@ impl<'a> Reader<'a> {
|
||||
self.gradients = std::mem::take(&mut sub.gradients);
|
||||
self.global_names = std::mem::take(&mut sub.global_names);
|
||||
self.styles = std::mem::take(&mut sub.styles);
|
||||
self.names.absorb(std::mem::take(&mut sub.names));
|
||||
let whole = read.is_ok()
|
||||
&& sub.unsupported.is_empty()
|
||||
&& sub.unknown.is_empty()
|
||||
@@ -569,10 +574,11 @@ impl<'a> Reader<'a> {
|
||||
return;
|
||||
}
|
||||
let name = match Lexer::new(section).next_token().map(|t| t.tok) {
|
||||
Some(Tok::Str(bytes)) => obj::text(&bytes),
|
||||
Some(Tok::Str(bytes)) => self.names.bytes(&bytes),
|
||||
_ => return,
|
||||
};
|
||||
let mut sub = Reader::new(section);
|
||||
sub.names = super::obj::Names::new(self.names.encoding);
|
||||
sub.subreader_depth = self.subreader_depth + 1;
|
||||
sub.symbol = Some(SymbolHead::default());
|
||||
sub.template = self.template;
|
||||
@@ -591,6 +597,7 @@ impl<'a> Reader<'a> {
|
||||
self.global_names = std::mem::take(&mut sub.global_names);
|
||||
self.styles = std::mem::take(&mut sub.styles);
|
||||
self.pattern_tiles = std::mem::take(&mut sub.pattern_tiles);
|
||||
self.names.absorb(std::mem::take(&mut sub.names));
|
||||
// Art stopped by a trailer, or with an array, type, image, placed file, gradient mesh or
|
||||
// gradient still open at the end (as [`Reader::run_string`] checks), isn't whole.
|
||||
let open = sub.done
|
||||
@@ -709,7 +716,7 @@ impl<'a> Reader<'a> {
|
||||
if names.len() >= MAX_LISTED {
|
||||
break;
|
||||
}
|
||||
names.push(obj::text(&bytes));
|
||||
names.push(self.names.quiet(&bytes));
|
||||
}
|
||||
}
|
||||
self.symbol_list = Some(names);
|
||||
@@ -719,7 +726,7 @@ impl<'a> Reader<'a> {
|
||||
/// order or a brush ([`brush`]); other objects are left alone. A brush without a name is counted
|
||||
/// as not read.
|
||||
fn plugin_object(&mut self, section: &[u8]) {
|
||||
let Some((kind, name, params)) = brush::plugin_strings(section) else { return };
|
||||
let Some((kind, name, params)) = brush::plugin_strings(section, &self.names) else { return };
|
||||
if kind == brush::MANAGER {
|
||||
if name.is_some() {
|
||||
self.brush_objects = true;
|
||||
@@ -737,8 +744,12 @@ impl<'a> Reader<'a> {
|
||||
self.brushes_unread += 1;
|
||||
return;
|
||||
}
|
||||
match brush::parse_tool_object(tool, &name, ¶ms) {
|
||||
Ok(d) => self.brush_drafts.push(d),
|
||||
match brush::parse_tool_object(tool, &self.names.quiet(&name), ¶ms) {
|
||||
Ok(d) => {
|
||||
// Only the name of a brush that is read gets a note.
|
||||
self.names.bytes(&name);
|
||||
self.brush_drafts.push(d);
|
||||
}
|
||||
Err(_) => self.brushes_unread += 1,
|
||||
}
|
||||
}
|
||||
@@ -756,8 +767,9 @@ impl<'a> Reader<'a> {
|
||||
self.brush_art_sections += 1;
|
||||
let mut lex = Lexer::new(section);
|
||||
let Some(Tok::Str(name) | Tok::Hex(name)) = lex.next_token().map(|t| t.tok) else { return };
|
||||
let name = obj::text(&name);
|
||||
let name = self.names.bytes(&name);
|
||||
let mut sub = Reader::new(lex.slice(lex.offset(), section.len()));
|
||||
sub.names = obj::Names::new(self.names.encoding);
|
||||
// In a space of its own (y down), with no head to take.
|
||||
sub.pattern = Some(PatternHead { taken: true, ..PatternHead::default() });
|
||||
sub.subreader_depth = self.subreader_depth + 1;
|
||||
@@ -779,6 +791,7 @@ impl<'a> Reader<'a> {
|
||||
self.pattern_tiles = std::mem::take(&mut sub.pattern_tiles);
|
||||
self.v7_patterns = std::mem::take(&mut sub.v7_patterns);
|
||||
self.global_names = std::mem::take(&mut sub.global_names);
|
||||
self.names.absorb(std::mem::take(&mut sub.names));
|
||||
// Images aren't kept: the document's images don't count a brush's art among their users. Art
|
||||
// read with a note (something left out of it) isn't kept either.
|
||||
let whole = read.is_ok()
|
||||
@@ -834,7 +847,8 @@ impl<'a> Reader<'a> {
|
||||
head.taken = true;
|
||||
let Some(at) = vals.iter().position(|v| matches!(v, V::Str(_))) else { return vals };
|
||||
let tile = Self::nums(vals.get(at + 1..at + 5).unwrap_or_default());
|
||||
let ([x0, y0, x1, y1], Some(name)) = (tile.as_slice(), vals.get(at).and_then(V::text)) else { return vals };
|
||||
let [x0, y0, x1, y1] = tile.as_slice() else { return vals };
|
||||
let Some(name) = vals.get(at).and_then(|v| self.names.text(v)) else { return vals };
|
||||
head.name = name;
|
||||
head.tile = Some(Rect::new(*x0, *y0, *x1, *y1));
|
||||
vals.split_off(at + 5)
|
||||
@@ -853,7 +867,7 @@ const MAX_LAYERS: usize = 65_536;
|
||||
/// A pattern's definition in the version 7 form: its head, then a list of layers painted in order,
|
||||
/// the first the lowest.
|
||||
struct LegacyPattern {
|
||||
name: String,
|
||||
name: Vec<u8>,
|
||||
/// The tile in the pattern's space (y up).
|
||||
tile: Rect,
|
||||
layers: Vec<LegacyLayer>,
|
||||
@@ -892,7 +906,7 @@ fn legacy_pattern(section: &[u8]) -> Legacy {
|
||||
let mut lex = super::Lexer::new(section);
|
||||
let mut next = || next_operand(&mut lex).ok().flatten().map(|t| (t.tok, t.hidden));
|
||||
let name = match next() {
|
||||
Some((Tok::Str(s), _)) => super::obj::text(&s),
|
||||
Some((Tok::Str(s), _)) => s,
|
||||
_ => return Legacy::No,
|
||||
};
|
||||
let mut tile = [0.0; 4];
|
||||
@@ -961,6 +975,11 @@ const MAX_STRING: usize = 4096;
|
||||
/// The PostScript string `v` starts with (after spaces), its escapes read, when it ends on the line
|
||||
/// and holds at most [`MAX_STRING`] bytes.
|
||||
fn ps_string(v: &[u8]) -> Option<String> {
|
||||
ps_bytes(v).map(|bytes| obj::text(&bytes))
|
||||
}
|
||||
|
||||
/// [`ps_string`] as the string's bytes.
|
||||
fn ps_bytes(v: &[u8]) -> Option<Vec<u8>> {
|
||||
let mut bytes = v.trim_ascii_start().iter().copied().peekable();
|
||||
if bytes.next()? != b'(' {
|
||||
return None;
|
||||
@@ -997,7 +1016,7 @@ fn ps_string(v: &[u8]) -> Option<String> {
|
||||
out.push(b);
|
||||
}
|
||||
b')' => {
|
||||
let Some(d) = depth.checked_sub(1) else { return Some(super::obj::text(&out)) };
|
||||
let Some(d) = depth.checked_sub(1) else { return Some(out) };
|
||||
depth = d;
|
||||
out.push(b);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use super::{
|
||||
Affine, Arc, Artboard, CANVAS_CENTRE, ColorMode, Document, Global, HashMap, Node, NodeId, NodeKind, Obj, OpacityMask, Paint, Point, Reader, Rect,
|
||||
Structure, Swatch, Unit, V, obj,
|
||||
};
|
||||
use crate::import::ai::NameEncoding;
|
||||
use vectorcraft_doc::{DataSet, DataValue, GraphicStyle, Guide, ImageBlob, PatternDef, Symbol, TextWrap, Variable, VariableKind, Variables};
|
||||
|
||||
/// `%AI5_RulerUnits` → [`Unit`] (Illustrator 7 spec table 3; centimeters is 4; pixels is 6 in later files).
|
||||
@@ -141,21 +142,31 @@ pub(crate) const LOOK_SLOT: &str = "\u{0}text:look";
|
||||
|
||||
/// The artboards (names, and rects in art space) of the editing data `data` that [`read`] can't
|
||||
/// read as a whole, as far as it gets: where to put the pages of its PDF part instead, and what to
|
||||
/// call them (#1068); and the index among them of the active artboard (`CropAreaActive`).
|
||||
pub fn artboards(data: &[u8]) -> (Vec<(String, Rect)>, Option<usize>) {
|
||||
let found = artboards_read(data);
|
||||
/// call them (#1068); and the index among them of the active artboard (`CropAreaActive`). `names`
|
||||
/// reads their names and keeps the notes on them.
|
||||
pub fn artboards(data: &[u8], names: &mut obj::Names) -> (Vec<(String, Rect)>, Option<usize>) {
|
||||
let mut from_start = obj::Names::new(names.encoding);
|
||||
let found = artboards_read(data, &mut from_start);
|
||||
if !found.0.is_empty() && found.1.is_some() {
|
||||
names.absorb(from_start);
|
||||
return found;
|
||||
}
|
||||
// Reading can stop before the artboards (art kept in the document's data comes first), or
|
||||
// between them and the active artboard's entry: read their array on its own.
|
||||
let Some((boards, active)) = artboard_array_read(data) else { return found };
|
||||
let mut from_array = obj::Names::new(names.encoding);
|
||||
let Some((boards, active)) = artboard_array_read(data, &mut from_array) else {
|
||||
names.absorb(from_start);
|
||||
return found;
|
||||
};
|
||||
if found.0.is_empty() {
|
||||
names.absorb(from_array);
|
||||
(boards, active)
|
||||
} else if boards == found.0 {
|
||||
// The same array: its names and rects read alike.
|
||||
names.absorb(from_start);
|
||||
(found.0, active)
|
||||
} else {
|
||||
names.absorb(from_start);
|
||||
found
|
||||
}
|
||||
}
|
||||
@@ -163,7 +174,7 @@ pub fn artboards(data: &[u8]) -> (Vec<(String, Rect)>, Option<usize>) {
|
||||
/// The index of the active artboard (`CropAreaActive`) in the `ArtboardArray` of the editing data
|
||||
/// `data`, as [`artboards`] reads it, from that array and the entry beside it alone.
|
||||
pub fn active_artboard(data: &[u8]) -> Option<usize> {
|
||||
artboard_array_read(data)?.1
|
||||
artboard_array_read(data, &mut obj::Names::default())?.1
|
||||
}
|
||||
|
||||
/// Artboards as [`artboards`] gives them: names and rects in art space, and the active one's index.
|
||||
@@ -171,7 +182,7 @@ type ArtboardsRead = (Vec<(String, Rect)>, Option<usize>);
|
||||
|
||||
/// The `ArtboardArray` entry of the editing data `data` ([`artboard_array`]), with the
|
||||
/// `CropAreaActive` entry beside it, read on their own as [`artboards_read`] reads them.
|
||||
fn artboard_array_read(data: &[u8]) -> Option<ArtboardsRead> {
|
||||
fn artboard_array_read(data: &[u8], names: &mut obj::Names) -> Option<ArtboardsRead> {
|
||||
let (array, active) = artboard_array(data)?;
|
||||
let mut alone = b"%_/Document :\n%_/Dictionary :\n".to_vec();
|
||||
alone.extend_from_slice(array);
|
||||
@@ -180,7 +191,7 @@ fn artboard_array_read(data: &[u8]) -> Option<ArtboardsRead> {
|
||||
alone.extend_from_slice(active);
|
||||
}
|
||||
alone.extend_from_slice(b"\n%_; /NotRecorded ,\n%_;\n");
|
||||
Some(artboards_read(&alone))
|
||||
Some(artboards_read(&alone, names))
|
||||
}
|
||||
|
||||
/// The key that ends the `ArtboardArray` entry of the editing data.
|
||||
@@ -278,6 +289,26 @@ fn beside(mut defined: Vec<PatternDef>, have: &[PatternDef]) -> (Vec<PatternDef>
|
||||
(defined, renamed)
|
||||
}
|
||||
|
||||
/// The names of the objects in `art` and what they hold, masks included.
|
||||
fn art_names<'a>(art: impl IntoIterator<Item = &'a Node>) -> Vec<&'a str> {
|
||||
let mut stack: Vec<&Node> = art.into_iter().collect();
|
||||
let mut names = vec![];
|
||||
while let Some(n) = stack.pop() {
|
||||
stack.extend(n.children().into_iter().flatten().chain(n.extras().mask.as_ref().map(|m| &m.art)).map(|c| &**c));
|
||||
names.extend(n.name.as_deref());
|
||||
}
|
||||
names
|
||||
}
|
||||
|
||||
/// The names read for the patterns `added` that the patterns don't show as their own: those
|
||||
/// `renamed` replaced, and the names of the objects of their art.
|
||||
fn pattern_names_read<'a>(added: &'a [PatternDef], renamed: &'a std::collections::BTreeMap<String, String>) -> Vec<&'a str> {
|
||||
let shown: std::collections::HashSet<&str> = added.iter().map(|p| p.name.as_str()).collect();
|
||||
let mut names: Vec<&str> = renamed.iter().filter(|(_, new)| shown.contains(new.as_str())).map(|(old, _)| old.as_str()).collect();
|
||||
names.extend(art_names(added.iter().flat_map(|p| p.art.iter().map(|a| &**a))));
|
||||
names
|
||||
}
|
||||
|
||||
/// `n` and what it holds painting with the patterns `renamed` renames (old to new) by their new names.
|
||||
fn repoint(n: &mut Node, renamed: &std::collections::BTreeMap<String, String>) {
|
||||
for p in vectorcraft_doc::swatches::node_paints_mut(n) {
|
||||
@@ -301,9 +332,10 @@ fn repoint(n: &mut Node, renamed: &std::collections::BTreeMap<String, String>) {
|
||||
/// layers aren't read: the swatches its PDF part has are the defaults (#4036). They come as
|
||||
/// [`read`] makes them, with pattern swatches only for the patterns in `patterns` and those the
|
||||
/// editing data defines, which are named apart from `patterns` ([`beside`]); `None` when the
|
||||
/// palette is empty or reading stops before it.
|
||||
pub fn palette(data: &[u8], patterns: &[PatternDef]) -> Option<PaletteSwatches> {
|
||||
let mut r = Reader::with_names(data);
|
||||
/// palette is empty or reading stops before it. `names` reads their names and keeps the notes on
|
||||
/// those the swatches take.
|
||||
pub fn palette(data: &[u8], patterns: &[PatternDef], names: &mut obj::Names) -> Option<PaletteSwatches> {
|
||||
let mut r = Reader::with_names(data, names.encoding);
|
||||
// The palette, the gradients and the patterns it names come before the art, so an error in the
|
||||
// art leaves them read.
|
||||
let _ = r.run();
|
||||
@@ -331,6 +363,15 @@ pub fn palette(data: &[u8], patterns: &[PatternDef]) -> Option<PaletteSwatches>
|
||||
images.insert(im.key.clone(), blob.clone());
|
||||
}
|
||||
});
|
||||
let used: Vec<&str> = swatches
|
||||
.iter()
|
||||
.chain(groups.iter().flat_map(|g| &g.swatches))
|
||||
.map(|s| s.name.as_str())
|
||||
.chain(groups.iter().map(|g| g.name.as_str()))
|
||||
.chain(added.iter().map(|p| p.name.as_str()))
|
||||
.chain(pattern_names_read(&added, &renamed))
|
||||
.collect();
|
||||
names.absorb_among(std::mem::take(&mut r.names), &used);
|
||||
Some(PaletteSwatches { swatches, groups, patterns: added, images })
|
||||
}
|
||||
|
||||
@@ -349,11 +390,12 @@ pub struct Brushes {
|
||||
/// The brushes of the editing data `data`, for a file whose layers aren't read (a brush library
|
||||
/// has none), as [`read`] makes them, with the patterns of the editing data their art paints with,
|
||||
/// named apart from `patterns` ([`beside`]) as [`palette`] names them. `None` when the file has no
|
||||
/// brush objects or reading stops before them.
|
||||
pub fn brushes(data: &[u8], patterns: &[PatternDef]) -> Option<Brushes> {
|
||||
/// brush objects or reading stops before them. `names` reads their names and keeps the notes on
|
||||
/// those it brings in.
|
||||
pub fn brushes(data: &[u8], patterns: &[PatternDef], names: &mut obj::Names) -> Option<Brushes> {
|
||||
// Brush objects are plug-in objects: data without one isn't read again.
|
||||
memchr::memmem::find(data, b"BeginPluginObject")?;
|
||||
let mut r = Reader::with_names(data);
|
||||
let mut r = Reader::with_names(data, names.encoding);
|
||||
// The brushes come before the art, so an error in the art leaves them read.
|
||||
let _ = r.run();
|
||||
let (mut lib, unread) = r.brush_library()?;
|
||||
@@ -386,6 +428,14 @@ pub fn brushes(data: &[u8], patterns: &[PatternDef]) -> Option<Brushes> {
|
||||
images.insert(im.key.clone(), blob.clone());
|
||||
}
|
||||
});
|
||||
let used: Vec<&str> = lib
|
||||
.iter()
|
||||
.map(|b| b.name.as_str())
|
||||
.chain(added.iter().map(|p| p.name.as_str()))
|
||||
.chain(pattern_names_read(&added, &renamed))
|
||||
.chain(art_names(lib.iter().flat_map(|b| b.art())))
|
||||
.collect();
|
||||
names.absorb_among(std::mem::take(&mut r.names), &used);
|
||||
Some(Brushes { brushes: lib, patterns: added, images, note: (unread > 0).then(|| brush::left_out_note(unread)) })
|
||||
}
|
||||
|
||||
@@ -393,16 +443,19 @@ pub fn brushes(data: &[u8], patterns: &[PatternDef]) -> Option<Brushes> {
|
||||
/// style library has none), as [`read`] makes them, with ids from 1, and the data's declared large
|
||||
/// canvas scale (1 when it declares none). `large_canvas`: as [`read`] takes it. The styles are
|
||||
/// those the list names before reading stops, and none when the data has no style list or lists no
|
||||
/// style this reads.
|
||||
pub fn graphic_styles(data: &[u8], large_canvas: bool) -> (Vec<GraphicStyle>, f64) {
|
||||
/// style this reads. `names` reads their names and keeps the notes on them.
|
||||
pub fn graphic_styles(data: &[u8], large_canvas: bool, names: &mut obj::Names) -> (Vec<GraphicStyle>, f64) {
|
||||
if crate::import::ai::find(data, b"BeginArtStyleList").is_none() {
|
||||
return (vec![], 1.0);
|
||||
}
|
||||
let mut r = Reader::with_names(data);
|
||||
let mut r = Reader::with_names(data, names.encoding);
|
||||
r.large_canvas = large_canvas.then_some(1.0);
|
||||
// The styles come before the art, so an error in the art leaves them read.
|
||||
let _ = r.run();
|
||||
(r.graphic_styles().0, r.canvas_scale)
|
||||
let styles = r.graphic_styles().0;
|
||||
let used: Vec<&str> = styles.iter().map(|s| s.name.as_str()).collect();
|
||||
names.absorb_among(std::mem::take(&mut r.names), &used);
|
||||
(styles, r.canvas_scale)
|
||||
}
|
||||
|
||||
/// The symbols of a `.ai` file's editing data, as [`symbols`] reads them.
|
||||
@@ -421,10 +474,10 @@ pub struct Symbols {
|
||||
/// instance of a symbol the data doesn't define, and with each object of their art that is linked
|
||||
/// to a listed graphic style linked to it by the id [`graphic_styles`] gives that style. The
|
||||
/// symbols are those defined before reading stops and before the first layer; `None` when there
|
||||
/// are none.
|
||||
pub fn symbols(data: &[u8]) -> Option<Symbols> {
|
||||
/// are none. `names` reads their names and keeps the notes on those it brings in.
|
||||
pub fn symbols(data: &[u8], names: &mut obj::Names) -> Option<Symbols> {
|
||||
crate::import::ai::find(data, b"BeginSymbol")?;
|
||||
let mut r = Reader::with_names(data);
|
||||
let mut r = Reader::with_names(data, names.encoding);
|
||||
// The symbols come before the art, so an error in the art leaves them read.
|
||||
let _ = r.run();
|
||||
r.check_symbols();
|
||||
@@ -468,14 +521,22 @@ pub fn symbols(data: &[u8]) -> Option<Symbols> {
|
||||
let reg = r.doc.symbol_registration(&s.name);
|
||||
(s, reg)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let used: Vec<&str> = symbols
|
||||
.iter()
|
||||
.map(|(s, _)| s.name.as_str())
|
||||
.chain(swatches.iter().map(|s| s.name.as_str()))
|
||||
.chain(art_names(symbols.iter().map(|(s, _)| &*s.art)))
|
||||
.collect();
|
||||
names.absorb_among(std::mem::take(&mut r.names), &used);
|
||||
Some(Symbols { symbols, images, swatches })
|
||||
}
|
||||
|
||||
/// [`artboards`] as far as reading `data` from its start gets: those read before an error, and
|
||||
/// those of a `/Document` still open when it stopped (its art can be what stopped it).
|
||||
fn artboards_read(data: &[u8]) -> (Vec<(String, Rect)>, Option<usize>) {
|
||||
fn artboards_read(data: &[u8], names: &mut obj::Names) -> (Vec<(String, Rect)>, Option<usize>) {
|
||||
let mut r = Reader::new(data);
|
||||
r.names = obj::Names::new(names.encoding);
|
||||
let _ = r.run();
|
||||
let open: Vec<Obj> = r.frames.iter().filter_map(|f| if let Kind::Obj(o) = &f.kind { Some((**o).clone()) } else { None }).collect();
|
||||
for o in &open {
|
||||
@@ -484,6 +545,8 @@ fn artboards_read(data: &[u8]) -> (Vec<(String, Rect)>, Option<usize>) {
|
||||
}
|
||||
}
|
||||
let active = r.active_board.filter(|i| *i < r.artboards.len());
|
||||
let used: Vec<&str> = r.artboards.iter().map(|b| b.name.as_str()).collect();
|
||||
names.absorb_among(std::mem::take(&mut r.names), &used);
|
||||
(r.artboards.into_iter().map(|b| (b.name, b.rect)).collect(), active)
|
||||
}
|
||||
|
||||
@@ -535,20 +598,27 @@ impl VariableRead {
|
||||
}
|
||||
|
||||
/// The variable library of the editing data `data` ([`VariableRead`]), for a file whose layers
|
||||
/// [`read`] can't read. Data without a `variableSets` element isn't read.
|
||||
pub fn variables(data: &[u8]) -> VariableRead {
|
||||
/// [`read`] can't read. Data without a `variableSets` element isn't read. `names` reads the
|
||||
/// library's names and keeps the notes on them.
|
||||
pub fn variables(data: &[u8], names: &mut obj::Names) -> VariableRead {
|
||||
if crate::import::ai::find(data, b"variableSets").is_none() {
|
||||
return VariableRead::default();
|
||||
}
|
||||
let mut r = Reader::new(data);
|
||||
r.names = obj::Names::new(names.encoding);
|
||||
let _ = r.run();
|
||||
if r.variables.present {
|
||||
absorb_library_names(&r.variables, r.names, names);
|
||||
return r.variables;
|
||||
}
|
||||
// A `/Document` still open when reading stopped.
|
||||
let open: Vec<Obj> = r.frames.iter().filter_map(|f| if let Kind::Obj(o) = &f.kind { Some((**o).clone()) } else { None }).collect();
|
||||
if let Some(found) = open.iter().filter(|o| o.ty == "Document").map(variable_library).find(|v| v.present) {
|
||||
return found;
|
||||
for o in open.iter().filter(|o| o.ty == "Document") {
|
||||
let found = variable_library(o, &mut r.names);
|
||||
if found.present {
|
||||
absorb_library_names(&found, r.names, names);
|
||||
return found;
|
||||
}
|
||||
}
|
||||
// Reading can stop before the library: read its node on its own.
|
||||
variable_sets_node(data).map_or(r.variables, |node| {
|
||||
@@ -556,11 +626,20 @@ pub fn variables(data: &[u8]) -> VariableRead {
|
||||
alone.extend_from_slice(node);
|
||||
alone.extend_from_slice(b"\n%_; (xmlnode-children) ,\n%_; /Recorded ,\n%_;\n");
|
||||
let mut r = Reader::new(&alone);
|
||||
r.names = obj::Names::new(names.encoding);
|
||||
let _ = r.run();
|
||||
absorb_library_names(&r.variables, r.names, names);
|
||||
r.variables
|
||||
})
|
||||
}
|
||||
|
||||
/// Take into `names` the notes of `read` on the names of the variables and data sets of `library`.
|
||||
fn absorb_library_names(library: &VariableRead, read: obj::Names, names: &mut obj::Names) {
|
||||
let used: Vec<&str> =
|
||||
library.variables.variables.iter().map(|v| v.name.as_str()).chain(library.variables.datasets.iter().map(|d| d.name.as_str())).collect();
|
||||
names.absorb_among(read, &used);
|
||||
}
|
||||
|
||||
impl<'a> Reader<'a> {
|
||||
/// Take the author and custom colors that the header of a program gives (`outer`, from
|
||||
/// [`Self::header_of`]), where the editing data's own header gives none: the program of an EPS
|
||||
@@ -569,6 +648,7 @@ impl<'a> Reader<'a> {
|
||||
if self.author.is_none() {
|
||||
self.author = outer.author;
|
||||
}
|
||||
self.names.absorb(outer.names);
|
||||
for n in outer.custom_colors {
|
||||
if self.custom_colors.len() < super::directives::MAX_CUSTOM_COLORS && !self.custom_colors.iter().any(|c| c.name == n.name) {
|
||||
self.custom_colors.push(n);
|
||||
@@ -577,8 +657,8 @@ impl<'a> Reader<'a> {
|
||||
}
|
||||
|
||||
/// A reader that has read the header of the program `ps` (its comment lines up to
|
||||
/// `%%EndComments`).
|
||||
pub(super) fn header_of(ps: &[u8]) -> Reader<'_> {
|
||||
/// `%%EndComments`), its names that aren't UTF-8 read in `names`.
|
||||
pub(super) fn header_of(ps: &[u8], names: NameEncoding) -> Reader<'_> {
|
||||
let mut end = 0;
|
||||
for line in ps.split_inclusive(|&b| b == b'\n' || b == b'\r') {
|
||||
if !line.starts_with(b"%") && !line.trim_ascii().is_empty() {
|
||||
@@ -590,6 +670,7 @@ impl<'a> Reader<'a> {
|
||||
}
|
||||
}
|
||||
let mut outer = Reader::new(ps.get(..end).unwrap_or_default());
|
||||
outer.names = obj::Names::new(names);
|
||||
let _ = outer.run();
|
||||
outer
|
||||
}
|
||||
@@ -732,10 +813,10 @@ impl<'a> Reader<'a> {
|
||||
{
|
||||
super::remember_xml_id(&mut self.xml_ids, &mut self.xml_id_bytes, uid, id);
|
||||
}
|
||||
let name = match o.text("AIArtName") {
|
||||
let name = match self.names.entry(o, "AIArtName") {
|
||||
Some(name) => name,
|
||||
None => match o.obj("AI10_ArtUID").and_then(Obj::content_text) {
|
||||
Some(id) => obj::xml_name(&id),
|
||||
None => match o.obj("AI10_ArtUID").and_then(|id| self.names.xml_id_name(id)) {
|
||||
Some(name) => name,
|
||||
None => return,
|
||||
},
|
||||
};
|
||||
@@ -753,7 +834,7 @@ impl<'a> Reader<'a> {
|
||||
/// Effects Settings, its variable library (the first one read), and its Objects on Path records.
|
||||
pub(super) fn document(&mut self, o: &Obj) {
|
||||
if !self.variables.present {
|
||||
self.variables = variable_library(o);
|
||||
self.variables = variable_library(o, &mut self.names);
|
||||
}
|
||||
self.constraint_data(o);
|
||||
if let Some(r) = find_entry(o, "AI Auto Rasterize", 0) {
|
||||
@@ -769,7 +850,7 @@ impl<'a> Reader<'a> {
|
||||
if !sane(r) || r.area() <= 0.0 {
|
||||
continue;
|
||||
}
|
||||
let name = ab.text("Name").unwrap_or_else(|| format!("Artboard {}", i + 1));
|
||||
let name = self.names.entry(ab, "Name").unwrap_or_else(|| format!("Artboard {}", i + 1));
|
||||
let mut board = AiArtboard::new(name, r);
|
||||
display_options(ab, &mut board);
|
||||
if active == Some(i as f64) {
|
||||
@@ -1057,7 +1138,7 @@ impl<'a> Reader<'a> {
|
||||
let mut styles: Vec<GraphicStyle> = vec![];
|
||||
let mut ids = HashMap::new();
|
||||
for raw in &self.style_list {
|
||||
let name = obj::text(raw);
|
||||
let name = self.names.quiet(raw);
|
||||
if name.is_empty() || ids.contains_key(&name) {
|
||||
continue;
|
||||
}
|
||||
@@ -1242,6 +1323,7 @@ impl<'a> Reader<'a> {
|
||||
if !doc.symbols.is_empty() {
|
||||
doc.limit_depth_noting(&mut warnings);
|
||||
}
|
||||
warnings.extend(self.names.notes());
|
||||
Ok(Structure {
|
||||
doc,
|
||||
to_doc,
|
||||
@@ -1399,9 +1481,57 @@ const MAX_LIBRARY_BYTES: usize = 8 << 20;
|
||||
/// variable holds its value: `p` elements of text, one paragraph each; a `/Bool` text, whether its
|
||||
/// objects show; a linked file's URL (`file://`) or path. Graph values aren't read. What is
|
||||
/// malformed, repeated or past the caps (a declaration, a data set, a value, a setting, a second
|
||||
/// `variableSet`) is left out and counted; a library past [`MAX_LIBRARY_NODES`] isn't read.
|
||||
fn variable_library(o: &Obj) -> VariableRead {
|
||||
find_variable_sets(o, 0).map_or_else(VariableRead::default, read_variable_sets)
|
||||
/// `variableSet`) is left out and counted; a library past [`MAX_LIBRARY_NODES`] isn't read. Text
|
||||
/// that isn't UTF-8 is read in the encoding of `names`, which gets a note on each such name of a
|
||||
/// variable or a data set.
|
||||
fn variable_library(o: &Obj, names: &mut obj::Names) -> VariableRead {
|
||||
let Some(sets) = find_variable_sets(o, 0) else { return VariableRead::default() };
|
||||
let mut legacy = HashMap::new();
|
||||
let read = read_variable_sets(&library_in_utf8(sets, names.encoding, &mut legacy, 0));
|
||||
for name in read.variables.variables.iter().map(|v| &v.name).chain(read.variables.datasets.iter().map(|d| &d.name)) {
|
||||
if let Some(replaced) = legacy.get(name) {
|
||||
names.note(name, *replaced);
|
||||
}
|
||||
}
|
||||
read
|
||||
}
|
||||
|
||||
/// The XML nodes of a variable library with their text (a `/String` or `/UnicodeString` entry, whose
|
||||
/// strings a long one is written across are joined first: a string may end inside a character) in
|
||||
/// UTF-8, so that an element named after a variable and that variable's name are alike whatever
|
||||
/// the encoding. `legacy` gets the text that wasn't UTF-8, trimmed as [`library_name`] trims it, and
|
||||
/// whether parts of it weren't valid in the encoding either.
|
||||
fn library_in_utf8(o: &Obj, encoding: NameEncoding, legacy: &mut HashMap<String, bool>, depth: usize) -> Obj {
|
||||
let mut out = o.clone();
|
||||
if depth > MAX_DEPTH {
|
||||
return out;
|
||||
}
|
||||
for (_, values) in &mut out.entries {
|
||||
match values.split_last_mut() {
|
||||
Some((V::Name(ty), strings)) if matches!(ty.as_str(), "String" | "UnicodeString") && strings.iter().all(|v| matches!(v, V::Str(_))) => {
|
||||
let bytes: Vec<u8> = strings.iter().flat_map(|v| if let V::Str(s) = v { s.as_slice() } else { &[] }).copied().collect();
|
||||
let (text, not_utf8, replaced) = encoding.decoded(&bytes);
|
||||
if not_utf8 {
|
||||
legacy.insert(text.trim().to_string(), replaced);
|
||||
}
|
||||
let ty = V::Name(ty.clone());
|
||||
*values = vec![V::Str(text.into_bytes()), ty];
|
||||
}
|
||||
_ => {
|
||||
for v in values.iter_mut() {
|
||||
if let V::Obj(child) = v {
|
||||
*child = std::rc::Rc::new(library_in_utf8(child, encoding, legacy, depth + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for v in &mut out.content {
|
||||
if let V::Obj(child) = v {
|
||||
*child = std::rc::Rc::new(library_in_utf8(child, encoding, legacy, depth + 1));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The `variableSets` XML node in `o` or the dictionaries it holds.
|
||||
|
||||
@@ -169,7 +169,7 @@ impl<'a> Reader<'a> {
|
||||
}
|
||||
if let Some(d) = self.gradient_def.as_mut() {
|
||||
match w {
|
||||
"Bs" => d.stop(&vals, &mut self.stop_spots),
|
||||
"Bs" => d.stop(&vals, &mut self.stop_spots, &mut self.names),
|
||||
"BD" => {
|
||||
if let Some((name, g)) = self.gradient_def.take().and_then(GradientDef::finish) {
|
||||
self.global_names.define(Global::Gradient, &name);
|
||||
@@ -227,7 +227,7 @@ impl<'a> Reader<'a> {
|
||||
"Lb" => self.layer_attrs(&vals),
|
||||
"Ln" => {
|
||||
if let Some(Frame { kind: Kind::Layer(a), .. }) = self.frames.last_mut() {
|
||||
a.name = vals.iter().rev().find_map(V::text).unwrap_or_default();
|
||||
a.name = vals.iter().rev().find_map(|v| self.names.text(v)).unwrap_or_default();
|
||||
}
|
||||
}
|
||||
"LB" => self.layer_end()?,
|
||||
@@ -319,12 +319,12 @@ impl<'a> Reader<'a> {
|
||||
"A" => self.gs.locked = Self::nums(&vals).last() == Some(&1.0),
|
||||
"XW" => self.state_marker(&vals, hidden),
|
||||
// Gradients.
|
||||
"Bd" => self.gradient_def = GradientDef::begin(&vals),
|
||||
"Bd" => self.gradient_def = GradientDef::begin(&vals, &mut self.names),
|
||||
"Bs" | "BD" => {}
|
||||
"Bb" => self.instance = Some(Instance::begin(&vals)),
|
||||
"Bg" => {
|
||||
if let Some(i) = self.instance.as_mut() {
|
||||
i.bg(&vals);
|
||||
i.bg(&vals, &mut self.names);
|
||||
}
|
||||
}
|
||||
"Bm" => {
|
||||
@@ -479,7 +479,7 @@ impl<'a> Reader<'a> {
|
||||
if self.frames.is_empty() {
|
||||
return;
|
||||
}
|
||||
let name = vals.iter().find_map(|v| if let V::Str(_) = v { v.text() } else { None });
|
||||
let name = vals.iter().find(|v| matches!(v, V::Str(_))).and_then(|v| self.names.text(v));
|
||||
let Some(tile) = name.as_deref().and_then(|n| self.pattern_tiles.get(n)).copied() else {
|
||||
self.unread_pattern(w);
|
||||
return;
|
||||
@@ -523,7 +523,7 @@ impl<'a> Reader<'a> {
|
||||
}
|
||||
|
||||
fn color(&mut self, w: &str, vals: &[V]) {
|
||||
let Some((p, named)) = paint::color_op(w, vals) else { return };
|
||||
let Some((p, named)) = paint::color_op_in(w, vals, &mut self.names) else { return };
|
||||
// Registration (`Xs`, `Xz`) says nothing of the document's colour model.
|
||||
let registration = matches!(w, "Xs" | "XS" | "Xz" | "XZ") || p.is_registration();
|
||||
match p.color().filter(|_| !registration) {
|
||||
@@ -706,7 +706,7 @@ impl<'a> Reader<'a> {
|
||||
/// follows an object.
|
||||
fn style_marker(&mut self, vals: &[V], hidden: bool) {
|
||||
let code = Self::nums(vals).last().copied().unwrap_or(0.0);
|
||||
let style = vals.iter().rev().find_map(V::text).unwrap_or_default();
|
||||
let style = vals.iter().rev().find_map(|v| self.names.text(v)).unwrap_or_default();
|
||||
let after = std::mem::take(&mut self.after_object);
|
||||
// An object's own state block ends `6 () XW` (a layer's `7 () XW`): an `Xy` before it isn't the layer's.
|
||||
if code == 6.0 {
|
||||
|
||||
@@ -60,7 +60,7 @@ use vectorcraft_effects::is_pathfinder;
|
||||
|
||||
use super::brush::PathBrush;
|
||||
use super::lex::{Lexer, Tok};
|
||||
use super::obj::{self, V};
|
||||
use super::obj::{self, Names, V};
|
||||
use super::paint;
|
||||
|
||||
const GLOW: &str = "Adobe Outer Glow"; // brand-ok: the filter's name in the files
|
||||
@@ -386,8 +386,14 @@ fn closes(data: &[u8]) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// The styles of the section `data` (between its markers), by name.
|
||||
/// [`art_styles_in`], names read in the default encoding.
|
||||
pub(super) fn art_styles(data: &[u8]) -> HashMap<String, ArtStyle> {
|
||||
art_styles_in(data, &mut Names::default())
|
||||
}
|
||||
|
||||
/// The styles of the section `data` (between its markers), by name: the names of the styles and of
|
||||
/// the colours, gradients and patterns they paint with read by `names`.
|
||||
pub(super) fn art_styles_in(data: &[u8], names: &mut Names) -> HashMap<String, ArtStyle> {
|
||||
let mut styles = HashMap::new();
|
||||
let mut name: Option<String> = None;
|
||||
let mut filters: Vec<Filter> = vec![];
|
||||
@@ -443,7 +449,7 @@ pub(super) fn art_styles(data: &[u8]) -> HashMap<String, ArtStyle> {
|
||||
}
|
||||
b"FillStyle" => style_entry = Some(Kind::Fill),
|
||||
b"StrokeStyle" | b"BlendStyle" => style_entry = Some(Kind::Other),
|
||||
b"Name" if name.is_none() && filters.is_empty() => name = operands.iter().rev().find_map(V::text),
|
||||
b"Name" if name.is_none() && filters.is_empty() => name = operands.iter().rev().find_map(|v| names.text(v)),
|
||||
b"All" | b"[Registration]" | b"Registration" => operands.push(V::Name(obj::text(n))),
|
||||
b"CompoundFilter" => pending = Some(true),
|
||||
b"BasicFilter" => pending = Some(false),
|
||||
@@ -470,7 +476,7 @@ pub(super) fn art_styles(data: &[u8]) -> HashMap<String, ArtStyle> {
|
||||
}
|
||||
b"Array" => dict_array = Some(vec![]),
|
||||
b"PluginObject" if in_basic => {
|
||||
let mut texts = operands.iter().rev().filter_map(V::text);
|
||||
let mut texts = operands.iter().rev().filter_map(|v| names.text(v));
|
||||
if let (Some(plugin), Some(name), Some(f)) = (texts.next(), texts.next(), filters.last_mut()) {
|
||||
f.plugin_object = Some((name, plugin));
|
||||
}
|
||||
@@ -541,7 +547,7 @@ pub(super) fn art_styles(data: &[u8]) -> HashMap<String, ArtStyle> {
|
||||
}
|
||||
}
|
||||
if let Some(f) = filters.last_mut() {
|
||||
paint_op(f, op, &operands);
|
||||
paint_op(f, op, &operands, names);
|
||||
}
|
||||
if op == "," || op == ";" || op.starts_with('X') || op.starts_with('B') || op.len() <= 2 {
|
||||
operands.clear();
|
||||
@@ -614,13 +620,13 @@ fn block_data(lex: &mut Lexer, encoded: &[u8]) -> Option<Vec<u8>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// A paint operator of a fill's or stroke's style.
|
||||
fn paint_op(f: &mut Filter, op: &str, vals: &[V]) {
|
||||
/// A paint operator of a fill's or stroke's style, the names it gives read by `names`.
|
||||
fn paint_op(f: &mut Filter, op: &str, vals: &[V], names: &mut Names) {
|
||||
let last = vals.iter().rev().find_map(V::num);
|
||||
match op {
|
||||
"Xa" | "k" | "g" | "x" | "Xx" | "Xk" | "Xs" | "Xz" | "XA" | "K" | "G" | "X" | "XX" | "XK" | "XS" | "XZ" | "xa" | "xx" | "xk" | "xs"
|
||||
| "xz" => {
|
||||
let Some((p, _)) = paint::color_op(op, vals) else { return };
|
||||
let Some((p, _)) = paint::color_op_in(op, vals, names) else { return };
|
||||
if op.ends_with(|c: char| c.is_ascii_lowercase()) {
|
||||
f.fill = Some(p);
|
||||
} else {
|
||||
@@ -681,13 +687,13 @@ fn paint_op(f: &mut Filter, op: &str, vals: &[V]) {
|
||||
"Bg" => {
|
||||
f.gradient = true;
|
||||
let at = vals.iter().rposition(|v| matches!(v, V::Str(_)));
|
||||
let name = at.and_then(|i| vals.get(i)).and_then(V::text);
|
||||
let name = at.and_then(|i| vals.get(i)).and_then(|v| names.text(v));
|
||||
let n: Vec<f64> = at.map_or(&[][..], |i| vals.get(i + 1..).unwrap_or_default()).iter().filter_map(V::num).collect();
|
||||
let angle = n.get(2).copied().filter(|a| a.is_finite()).unwrap_or(0.0);
|
||||
f.gradient_of = Some((name, angle));
|
||||
}
|
||||
"p" => {
|
||||
let name = vals.iter().find_map(|v| if let V::Str(_) = v { v.text() } else { None });
|
||||
let name = vals.iter().find(|v| matches!(v, V::Str(_))).and_then(|v| names.text(v));
|
||||
let matrix = vals.iter().rev().find_map(|v| match v {
|
||||
V::Arr(a) => {
|
||||
let n: Vec<f64> = a.iter().filter_map(V::num).collect();
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
use super::*;
|
||||
use vectorcraft_color::Color;
|
||||
|
||||
fn paint_op(f: &mut Filter, op: &str, vals: &[V]) {
|
||||
super::paint_op(f, op, vals, &mut Names::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_variable_width_stroke_keeps_its_profile() {
|
||||
let data = b"/KnownStyle :\n(Tapered) /Name ,\n/ActiveStyle :\n/CompoundFilter :\n(Chain Style Filter) 0 0 /Filter ,\n1 /Visible ,\n\
|
||||
|
||||
@@ -783,7 +783,7 @@ fn pattern_names_are_shown_up_to_their_newline() {
|
||||
// Nor the name of a custom color the program of an EPS gives, or None's.
|
||||
let ps = b"%!PS-Adobe-3.0\n%%CMYKCustomColor: 0 0 1 0 (Outer Ink)\n%%EndComments\n";
|
||||
let data = stream(&format!("{}{}{}", def("Outer Ink\\n1", 8), def("[None]\\n1", 8), layer(&filled("Outer Ink\\n1"))));
|
||||
let doc = super::read_beside(data.as_bytes(), true, ps, false).unwrap().doc;
|
||||
let doc = super::read_beside(data.as_bytes(), true, ps, false, NameEncoding::default()).unwrap().doc;
|
||||
assert_eq!(doc.patterns.iter().map(|p| p.name.as_str()).collect::<Vec<_>>(), ["Outer Ink 2", "[None] 2"]);
|
||||
assert!(matches!(doc.swatch("Outer Ink").unwrap().paint, Paint::Solid { .. }));
|
||||
assert!(matches!(fill(&art(&doc)[0]), Paint::Pattern { pattern, .. } if pattern == "Outer Ink 2"));
|
||||
@@ -2510,6 +2510,7 @@ fn ai_variable_library_without_the_layers() {
|
||||
let library = variable_library_data(&sample_variable_sets("variableAndTypes", &[]));
|
||||
let unread = stream(&format!("{library}{}", layer("1 Zz\n")));
|
||||
assert!(read(unread.as_bytes()).is_err());
|
||||
let variables = |data: &[u8]| variables(data, &mut Names::default());
|
||||
let found = variables(unread.as_bytes());
|
||||
assert!(found.present && found.variables.locked && found.skipped == 0);
|
||||
assert_eq!((found.variables.variables.len(), found.variables.datasets.len()), (5, 3));
|
||||
@@ -5724,7 +5725,7 @@ fn artboards_after_what_stops_the_reading() {
|
||||
let array = format!("%_/Array :\n{}{}%_; (ArtboardArray) ,\n", board("one", 0), board("two", 200));
|
||||
// Art in the document's own data that the reader can't follow comes before the artboards.
|
||||
let data = format!("%_/Document :\n%_/Dictionary :\n%_/Array :\n%_/Dictionary :\nLB\n{array}%_; /NotRecorded ,\n%_;\n");
|
||||
let boards: Vec<_> = super::artboards(data.as_bytes()).0.into_iter().map(|(n, r)| (n, r.x0)).collect();
|
||||
let boards: Vec<_> = super::artboards(data.as_bytes(), &mut Names::default()).0.into_iter().map(|(n, r)| (n, r.x0)).collect();
|
||||
assert_eq!(boards, [("one".to_string(), 0.0), ("two".to_string(), 200.0)]);
|
||||
}
|
||||
|
||||
@@ -6348,7 +6349,7 @@ fn a_symbol_library_without_layers_gives_its_symbols() {
|
||||
);
|
||||
let list = "%AI24_BeginSymbolList\n(Tile)\n(Pair)\n(Lost)\n(Dot)\n%AI24_EndSymbolList\n";
|
||||
let body = format!("%AI3_TemplateBox: 100.5 50.5 100.5 50.5\n{styles}{defs}{list}");
|
||||
let read = super::symbols(stream(&body).as_bytes()).expect("the library's symbols");
|
||||
let read = super::symbols(stream(&body).as_bytes(), &mut Names::default()).expect("the library's symbols");
|
||||
let names: Vec<&str> = read.symbols.iter().map(|(s, _)| s.name.as_str()).collect();
|
||||
assert_eq!(names, ["Tile", "Pair", "Dot", "Pic"]);
|
||||
let registrations: Vec<u8> = read.symbols.iter().map(|(_, r)| r.0).collect();
|
||||
@@ -6365,7 +6366,7 @@ fn a_symbol_library_without_layers_gives_its_symbols() {
|
||||
assert_eq!(keys.len(), 1);
|
||||
assert_eq!(read.images.keys().cloned().collect::<Vec<_>>(), keys);
|
||||
// Without symbols there are none to give.
|
||||
assert!(super::symbols(stream(&styles).as_bytes()).is_none());
|
||||
assert!(super::symbols(stream(&styles).as_bytes(), &mut Names::default()).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -10228,3 +10229,258 @@ fn copies_of_a_multi_layer_mask_count_toward_the_limit() {
|
||||
let e = read(mask_stream7(&filled).as_bytes()).unwrap_err();
|
||||
assert!(e.contains("objects"), "{e}");
|
||||
}
|
||||
|
||||
// ---- names that aren't UTF-8 ----------------------------------------------------------------
|
||||
|
||||
/// `body` read with its names that aren't UTF-8 in `encoding`.
|
||||
fn read_names(body: &str, encoding: &str) -> Structure {
|
||||
let encoding = NameEncoding::from_label(encoding).unwrap();
|
||||
match super::read_in(stream(body).as_bytes(), true, encoding) {
|
||||
Ok(s) => s,
|
||||
Err(e) => panic!("{e}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The notes on names that weren't UTF-8.
|
||||
fn name_notes(s: &Structure) -> Vec<&str> {
|
||||
s.warnings.iter().map(String::as_str).filter(|w| w.contains("isn't UTF-8") || w.contains("aren't UTF-8")).collect()
|
||||
}
|
||||
|
||||
/// A layer's name in a legacy code page (`(name) Ln`, the bytes as octal escapes) is read in the
|
||||
/// encoding picked, with a note that names it and the encoding; one in UTF-8 is read as it is in
|
||||
/// every encoding, without a note.
|
||||
#[test]
|
||||
fn layer_names_are_read_in_the_legacy_encoding_picked() {
|
||||
let layer_named = |name: &str| {
|
||||
format!(
|
||||
"%AI5_BeginLayer\n1 1 1 1 0 0 1 0 79 128 255 0 50 0 Lb\n({name}) Ln\n{RED}{}f\nLB\n%AI5_EndLayer--\n",
|
||||
rect_path(0.0, 0.0, 10.0, 10.0)
|
||||
)
|
||||
};
|
||||
for (encoding, bytes, want) in [
|
||||
("windows-949", r"\267\271\300\314\276\356 1", "레이어 1"),
|
||||
("shift_jis", r"\203\214\203C\203\204\201[ 1", "レイヤー 1"),
|
||||
("gbk", r"\315\274\262\343 1", "图层 1"),
|
||||
("big5", r"\271\317\274h 1", "圖層 1"),
|
||||
("macintosh", r"Caf\216", "Café"),
|
||||
("windows-1252", r"Caf\351", "Café"),
|
||||
] {
|
||||
let s = read_names(&layer_named(bytes), encoding);
|
||||
assert_eq!(s.doc.layers[0].name.as_deref(), Some(want), "{encoding}");
|
||||
assert_eq!(
|
||||
name_notes(&s),
|
||||
[format!("the name `{want}` isn't UTF-8 and was read as {encoding}: if it looks wrong, open the file with another legacyNameEncoding")],
|
||||
"{encoding}"
|
||||
);
|
||||
let utf8 = read_names(&layer_named(r"\353\240\210\354\235\264\354\226\264 1"), encoding);
|
||||
assert_eq!(utf8.doc.layers[0].name.as_deref(), Some("레이어 1"), "{encoding}");
|
||||
assert!(name_notes(&utf8).is_empty(), "{encoding}: {:?}", utf8.warnings);
|
||||
}
|
||||
// By default the Korean bytes come in as Windows-1252, as before, now with the note. A comment
|
||||
// in UTF-8 doesn't change how the names are read.
|
||||
let s = read_names(&format!("%%Title: 레이어\n{}", layer_named(r"\267\271\300\314\276\356 1")), "windows-1252");
|
||||
assert_eq!(s.doc.layers[0].name.as_deref(), Some("·¹À̾î 1"));
|
||||
assert_eq!(
|
||||
name_notes(&s),
|
||||
["the name `·¹À̾î 1` isn't UTF-8 and was read as windows-1252: if it looks wrong, open the file with another legacyNameEncoding"]
|
||||
);
|
||||
// Bytes the encoding doesn't define come in as U+FFFD, and the note says so.
|
||||
let s = read_names(&layer_named(r"\267\271\300 1"), "windows-949");
|
||||
assert_eq!(s.doc.layers[0].name.as_deref(), Some("레\u{fffd} 1"));
|
||||
assert_eq!(
|
||||
name_notes(&s),
|
||||
["the name `레\u{fffd} 1` isn't UTF-8, and parts of it aren't valid windows-949 either: open the file with another legacyNameEncoding"]
|
||||
);
|
||||
}
|
||||
|
||||
/// An object's name, an artboard's, a spot colour's and a pattern's are read in the encoding
|
||||
/// picked too, and a fill names the pattern as its definition does, whichever encoding is picked.
|
||||
#[test]
|
||||
fn object_artboard_colour_and_pattern_names_are_read_in_the_encoding_picked() {
|
||||
// 그라 (a pattern and a group), 빨강 (an artboard and a spot colour), 레이어 1 (the layer).
|
||||
let (pattern, red, layer_name) = (r"\261\327\266\363", r"\273\241\260\255", r"\267\271\300\314\276\356 1");
|
||||
let boards = format!(
|
||||
"%_/Document :\n%_/Dictionary :\n%_/Array :\n\
|
||||
%_/Dictionary :\n%_0 100 /RealPointRelToROrigin\n%_ (PositionPoint1) ,\n%_200 0 /RealPointRelToROrigin\n%_ (PositionPoint2) ,\n%_({red}) /UnicodeString (Name) ,\n%_; ,\n\
|
||||
%_; (ArtboardArray) ,\n%_; /NotRecorded ,\n%_;\n"
|
||||
);
|
||||
let tile = DOTS.replace("(Dots)", &format!("({pattern})"));
|
||||
let art_ = format!(
|
||||
"0 Ae\nu\n0 1 1 0 ({red}) 0 x\n{}f\n({pattern}) 0 0 1 1 0 0 0 0 0 [1 0 0 1 0 0] p\n{}f\nU\n%_/ArtDictionary :\n%_({pattern}) /String (AIArtName) ,\n%_;\n9 () XW\n",
|
||||
rect_path(0.0, 0.0, 10.0, 10.0),
|
||||
rect_path(20.0, 0.0, 30.0, 10.0),
|
||||
);
|
||||
let body = format!("{boards}{tile}%AI5_BeginLayer\n1 1 1 1 0 0 1 0 79 128 255 0 50 0 Lb\n({layer_name}) Ln\n{art_}LB\n%AI5_EndLayer--\n");
|
||||
for (encoding, [pattern, red, layer_name]) in [("windows-949", ["그라", "빨강", "레이어 1"]), ("windows-1252", ["±×¶ó", "»¡°\u{ad}", "·¹À̾î 1"])]
|
||||
{
|
||||
let s = read_names(&body, encoding);
|
||||
let doc = &s.doc;
|
||||
assert_eq!(doc.layers[0].name.as_deref(), Some(layer_name), "{encoding}");
|
||||
assert_eq!(doc.artboards.first().map(|a| a.name.as_str()), Some(red), "{encoding}");
|
||||
let group = &art(doc)[0];
|
||||
assert_eq!(group.name.as_deref(), Some(pattern), "{encoding}");
|
||||
let kids = group.children().unwrap();
|
||||
assert!(matches!(fill(&kids[0]), Paint::Solid { swatch: Some(s), .. } if s == red), "{encoding}: {:?}", fill(&kids[0]));
|
||||
assert!(doc.swatch(red).is_some_and(|s| s.spot), "{encoding}");
|
||||
assert!(matches!(fill(&kids[1]), Paint::Pattern { pattern: p, .. } if p == pattern), "{encoding}: {:?}", fill(&kids[1]));
|
||||
assert!(doc.pattern(pattern).is_some(), "{encoding}");
|
||||
assert!(s.unread.is_empty(), "{encoding}: {:?}", s.unread);
|
||||
assert_eq!(name_notes(&s).len(), 3, "{encoding}: {:?}", s.warnings);
|
||||
}
|
||||
}
|
||||
|
||||
/// Past three names, the notes count the others in one.
|
||||
#[test]
|
||||
fn notes_on_names_that_arent_utf8_are_capped() {
|
||||
let layers: String = (0..6)
|
||||
.map(|i| {
|
||||
format!(
|
||||
"%AI5_BeginLayer\n1 1 1 1 0 0 1 0 79 128 255 0 50 0 Lb\n(L{i} Caf\\216) Ln\n{RED}{}f\nLB\n%AI5_EndLayer--\n",
|
||||
rect_path(0.0, 0.0, 10.0, 10.0)
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let s = read_names(&layers, "macintosh");
|
||||
let names: Vec<_> = s.doc.layers.iter().map(|l| l.name.clone().unwrap_or_default()).collect();
|
||||
assert!(names.iter().all(|n| n.ends_with(" Café")), "{names:?}");
|
||||
let notes = name_notes(&s);
|
||||
assert_eq!(notes.len(), 4, "{notes:?}");
|
||||
assert_eq!(notes[3], "more names that aren't UTF-8 were read as macintosh (3)");
|
||||
}
|
||||
|
||||
/// 빨강 and 그라 in code page 949, as octal escapes.
|
||||
const KO_RED: &str = r"\273\241\260\255";
|
||||
const KO_GRA: &str = r"\261\327\266\363";
|
||||
|
||||
/// A brush's name, the art it names and the brush manager's order are read in the encoding picked:
|
||||
/// the brush finds its art and the order finds the brush, with a note on the brush and on its art.
|
||||
#[test]
|
||||
fn brush_names_are_read_in_the_encoding_picked() {
|
||||
let params = SPRAY.replace("Dot art", KO_GRA);
|
||||
let scatter = format!("%AI8_BeginPluginObject\n({SCATTER})\n({KO_RED})\n({params}) .\n%AI8_EndPluginObject\n");
|
||||
let manager = brush::MANAGER;
|
||||
let order = format!("%AI8_BeginPluginObject\n({manager})\n({manager})\n( {SCATTER}/ {KO_RED}/) .\n%AI8_EndPluginObject\n");
|
||||
let body = format!("{}{order}{scatter}{}", brush_art(KO_GRA, 4.0), layer(""));
|
||||
for (encoding, name) in [("windows-949", "빨강"), ("windows-1252", "»¡°\u{ad}")] {
|
||||
let s = read_names(&body, encoding);
|
||||
let lib = vectorcraft_brush::library(&s.doc);
|
||||
assert_eq!(lib.iter().map(|b| b.name.as_str()).collect::<Vec<_>>(), [name], "{encoding}: {:?}", s.warnings);
|
||||
assert!(matches!(brush_named(&lib, name), vectorcraft_brush::BrushKind::Scatter(_)), "{encoding}");
|
||||
assert_eq!(name_notes(&s).len(), 2, "{encoding}: {:?}", s.warnings);
|
||||
}
|
||||
}
|
||||
|
||||
/// A symbol's name, the instances that name it and the symbol list are read in the encoding
|
||||
/// picked, with a note on each symbol.
|
||||
#[test]
|
||||
fn symbol_names_are_read_in_the_encoding_picked() {
|
||||
let list = format!("%AI24_BeginSymbolList\n({KO_GRA})\n({KO_RED})\n%AI24_EndSymbolList\n");
|
||||
let defs = symbols(&format!("{}{}{list}", symbol(KO_RED, &dot(), 5), symbol(KO_GRA, &dot(), 5)));
|
||||
let s = read_names(&(defs + &layer(&instance(KO_RED, [1.0, 0.0, 0.0, -1.0, 20.0, 50.0]))), "windows-949");
|
||||
let names: Vec<&str> = s.doc.symbols.iter().map(|d| d.name.as_str()).collect();
|
||||
assert_eq!(names, ["그라", "빨강"], "{:?}", s.warnings);
|
||||
assert!(matches!(&art(&s.doc)[0].kind, NodeKind::SymbolInstance { symbol, .. } if symbol == "빨강"), "{:?}", art(&s.doc)[0].kind);
|
||||
assert_eq!(name_notes(&s).len(), 2, "{:?}", s.warnings);
|
||||
}
|
||||
|
||||
/// A symbol library read without its layers has notes on the names of the objects in its art.
|
||||
#[test]
|
||||
fn a_symbol_librarys_art_has_notes_on_its_object_names() {
|
||||
let inner = format!("{}{}", dot(), vectorcraft_testkit::ai::named(KO_GRA));
|
||||
let data = stream(&symbols(&symbol(KO_RED, &inner, 5)));
|
||||
let mut names = obj::Names::new(NameEncoding::Korean);
|
||||
assert!(super::symbols(data.as_bytes(), &mut names).is_some());
|
||||
let notes = names.notes();
|
||||
assert_eq!(notes.len(), 2, "{notes:?}");
|
||||
assert!(notes.iter().any(|n| n.contains("`그라`")), "{notes:?}");
|
||||
}
|
||||
|
||||
/// An object without a name of its own takes the one its XML id gives it, read in the encoding
|
||||
/// picked, with a note on that name.
|
||||
#[test]
|
||||
fn an_object_named_by_its_xml_id_is_read_in_the_encoding_picked() {
|
||||
let square = format!("{RED}{}f\n{}", rect_path(0.0, 0.0, 10.0, 10.0), vectorcraft_testkit::ai::named(&format!("{KO_RED}_1")));
|
||||
let s = read_names(&layer(&square), "windows-949");
|
||||
assert_eq!(art(&s.doc)[0].name.as_deref(), Some("빨강 1"), "{:?}", s.warnings);
|
||||
let notes = name_notes(&s);
|
||||
assert_eq!(notes.len(), 1, "{notes:?}");
|
||||
assert!(notes[0].contains("`빨강 1`"), "{notes:?}");
|
||||
}
|
||||
|
||||
/// The strings of a plug-in object that isn't a brush, and the name of a brush that isn't read,
|
||||
/// have no notes.
|
||||
#[test]
|
||||
fn plug_in_objects_that_are_not_read_have_no_name_notes() {
|
||||
let other = format!("%AI8_BeginPluginObject\n(Other Tool)\n({KO_RED})\n(x) .\n%AI8_EndPluginObject\n");
|
||||
let broken = format!("%AI8_BeginPluginObject\n({SCATTER})\n({KO_GRA})\n(not a brush) .\n%AI8_EndPluginObject\n");
|
||||
let s = read_names(&format!("{other}{broken}{}", layer("")), "windows-949");
|
||||
assert!(name_notes(&s).is_empty(), "{:?}", s.warnings);
|
||||
}
|
||||
|
||||
/// A graphic style's name, in the art styles and in the style list, and an object's link to it are
|
||||
/// read in the encoding picked, with a note on the style.
|
||||
#[test]
|
||||
fn graphic_style_names_are_read_in_the_encoding_picked() {
|
||||
let defs = [fill_style(KO_RED, "0 0 0 0 1 0 0 Xa\n")];
|
||||
let s = read_names(&format!("{}{}", styles_and_list(&defs, &[KO_RED]), layer(&styled_square(KO_RED))), "windows-949");
|
||||
assert_eq!(style_names(&s.doc), [("빨강".to_string(), 1)], "{:?}", s.warnings);
|
||||
assert_eq!(art(&s.doc)[0].extras().graphic_style, Some(1), "{:?}", s.warnings);
|
||||
assert_eq!(name_notes(&s).len(), 1, "{:?}", s.warnings);
|
||||
}
|
||||
|
||||
/// A variable's and a data set's names are read in the encoding picked, each with a note, a name
|
||||
/// written across two strings that end inside a character included. The element named after the
|
||||
/// variable still names it, and the data set's text is read in the encoding too, without a note.
|
||||
#[test]
|
||||
fn variable_and_data_set_names_are_read_in_the_encoding_picked() {
|
||||
let split_red = "\\273)\n%_(\\241\\260\\255";
|
||||
let library = vectorcraft_testkit::ai::variable_library(&["QVARQ"], &["QSETQ"]).replace("QVARQ", split_red).replace("QSETQ", KO_GRA);
|
||||
let s = read_names(&format!("{library}{}", layer(&format!("{RED}{}f\n", rect_path(0.0, 0.0, 10.0, 10.0)))), "windows-949");
|
||||
let vars = &s.doc.variables;
|
||||
assert_eq!(vars.variables.iter().map(|v| v.name.as_str()).collect::<Vec<_>>(), ["빨강"], "{:?}", s.warnings);
|
||||
assert_eq!(vars.datasets.iter().map(|d| d.name.as_str()).collect::<Vec<_>>(), ["그라"], "{:?}", s.warnings);
|
||||
assert_eq!(vars.dataset("그라").and_then(|d| d.values.get("빨강")), Some(&vectorcraft_doc::DataValue::Text("그라 빨강".into())));
|
||||
assert_eq!(name_notes(&s).len(), 2, "{:?}", s.warnings);
|
||||
}
|
||||
|
||||
/// A binding names its variable by the name read in the encoding picked.
|
||||
#[test]
|
||||
fn a_bound_variables_name_is_read_in_the_encoding_picked() {
|
||||
use vectorcraft_testkit::ai::{XmlValue, named, variable_library_data, xml_element, xml_node};
|
||||
let attributes =
|
||||
[("trait", XmlValue::Str("textcontent")), ("varName", XmlValue::Unicode("QVARQ")), ("docRef", XmlValue::Raw("/XMLUIDREF : (one) ;"))];
|
||||
let variable = xml_node(1, "variable", XmlValue::Str(""), &attributes, &[]);
|
||||
let set = xml_element("variableSet", &[("locked", "none")], &[xml_element("variables", &[], &[variable])]);
|
||||
let library = variable_library_data(&xml_element("variableSets", &[], &[set])).replace("QVARQ", KO_RED);
|
||||
let square = layer(&format!("{RED}{}f\n{}", rect_path(0.0, 0.0, 10.0, 10.0), named("one")));
|
||||
let s = read_names(&format!("{library}{square}"), "windows-949");
|
||||
assert_eq!(s.bindings, [BindingRef { variable: "빨강".into(), target: Some("one".into()) }], "{:?}", s.warnings);
|
||||
assert_eq!(s.doc.variables.variables.iter().map(|v| v.name.as_str()).collect::<Vec<_>>(), ["빨강"]);
|
||||
assert_eq!(name_notes(&s).len(), 1, "{:?}", s.warnings);
|
||||
}
|
||||
|
||||
/// A custom color of the header is read in the encoding picked, so it is the color an object
|
||||
/// names: one swatch comes in, with a note.
|
||||
#[test]
|
||||
fn a_custom_color_of_the_header_is_read_in_the_encoding_picked() {
|
||||
let body = format!(
|
||||
"%!PS-Adobe-3.0\n%%CMYKCustomColor: 0 1 1 0 ({KO_RED})\n%%EndComments\n{}",
|
||||
layer(&format!("0 1 1 0 ({KO_RED}) 0 x\n{}f\n", rect_path(0.0, 0.0, 10.0, 10.0)))
|
||||
);
|
||||
let s = super::read_in(body.as_bytes(), true, NameEncoding::Korean).unwrap();
|
||||
assert_eq!(s.doc.swatches.iter().filter(|w| w.spot).map(|w| w.name.as_str()).collect::<Vec<_>>(), ["빨강"], "{:?}", s.warnings);
|
||||
assert_eq!(name_notes(&s).len(), 1, "{:?}", s.warnings);
|
||||
}
|
||||
|
||||
/// A pattern's name in the version 7 form is read in the encoding picked, with a note, and a fill
|
||||
/// that names it finds it.
|
||||
#[test]
|
||||
fn a_version_7_pattern_name_is_read_in_the_encoding_picked() {
|
||||
let layers = "(0 g) @ (2 2 m 9 2 L 9 9 L f) &\n";
|
||||
let fill_it = format!("({KO_RED}) 0 0 1 1 0 0 0 0 0 [1 0 0 1 0 0] p\n{}f\n", rect_path(0.0, 0.0, 10.0, 10.0));
|
||||
let stream = pattern_stream7(&pattern7(KO_RED, layers), &pattern_layer7("Art", &fill_it));
|
||||
let s = super::read_in(stream.as_bytes(), true, NameEncoding::Korean).unwrap();
|
||||
assert!(s.doc.pattern("빨강").is_some(), "{:?}", s.doc.patterns.iter().map(|p| &p.name).collect::<Vec<_>>());
|
||||
assert!(matches!(fill(&art(&s.doc)[0]), Paint::Pattern { pattern, .. } if pattern == "빨강"), "{:?}", s.warnings);
|
||||
assert_eq!(name_notes(&s).len(), 1, "{:?}", s.warnings);
|
||||
}
|
||||
+322
-61
@@ -25,7 +25,10 @@ use std::collections::BTreeMap;
|
||||
|
||||
use kurbo::{BezPath, CubicBez, ParamCurve, ParamCurveArclen};
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
use vectorcraft_doc::{CharStyle, Justify, Node, NodeId, NodeKind, ParaDirection, ParaStyle, PathAlign, PathEffect, TextKind, TextObject, TextRun};
|
||||
use vectorcraft_doc::{
|
||||
CharStyle, HyphenationOptions, JustificationOptions, Justify, Node, NodeId, NodeKind, ParaDirection, ParaStyle, PathAlign, PathEffect, TabAlign,
|
||||
TabStop, TextKind, TextObject, TextRun,
|
||||
};
|
||||
use vectorcraft_geom::{Affine, PathData, Point, Rect};
|
||||
|
||||
/// Longest story read (bytes).
|
||||
@@ -383,8 +386,33 @@ struct Para {
|
||||
space_before: f64,
|
||||
space_after: f64,
|
||||
hyphenate: bool,
|
||||
/// Key 7: the share of its type size a line takes as its auto leading (1.2: 120%, the default;
|
||||
/// Justification… sets 0 to 500%:
|
||||
/// https://helpx.adobe.com/illustrator/using/line-character-spacing.html). `None`: the default.
|
||||
auto_leading: Option<f64>,
|
||||
/// Keys 10 to 15, in the order of Paragraph panel menu › Hyphenation…: Words Longer Than,
|
||||
/// After First, Before Last, Hyphen Limit, Hyphenation Zone (pt) and Hyphenate Capitalized
|
||||
/// Words. A value that can't be read, or is out of its range, keeps the default.
|
||||
hyphenation: HyphenationOptions,
|
||||
/// Key 30, its list (key 0): the tab stops, each its position from the frame's left edge (key
|
||||
/// 0) and alignment (key 1: 0 left, the default, 1 center, 2 right, 3 decimal, in the order of
|
||||
/// the Tabs panel's buttons), sorted. A stop that can't be read is left out, and so are those
|
||||
/// past the first [`MAX_TABS`]. Leaders aren't read.
|
||||
tabs: Vec<TabStop>,
|
||||
/// The paragraph has more than [`MAX_TABS`] stops: those past them were left out.
|
||||
tabs_truncated: bool,
|
||||
}
|
||||
|
||||
/// Most tab stops read for one paragraph.
|
||||
const MAX_TABS: usize = 1024;
|
||||
/// Largest tab stop position read (in the text document's units), as `text.tabs.set` takes it.
|
||||
const MAX_TAB_POSITION: f64 = 100_000.0;
|
||||
/// Most tab stops a story's paragraphs take in all: a paragraph style's stops are copied into
|
||||
/// every paragraph that has them. The paragraphs past it take the default stops, with a warning.
|
||||
const MAX_STORY_TABS: usize = 1 << 20;
|
||||
/// The warning when [`MAX_STORY_TABS`] leaves tab stops out.
|
||||
pub(crate) const TABS_LEFT_OUT: &str = "tab stops past VectorCraft's limits were left out";
|
||||
|
||||
/// The text of one story, in the units of the text document.
|
||||
#[derive(Debug)]
|
||||
pub(super) struct Story {
|
||||
@@ -405,6 +433,20 @@ pub(super) struct Story {
|
||||
/// Vertical type (Type › Type Orientation › Vertical): its lines are columns, from right to
|
||||
/// left. Its layout's lines run down from the anchor, each column further left.
|
||||
vertical: bool,
|
||||
/// Tab stops past [`MAX_STORY_TABS`] were left out of its paragraphs.
|
||||
tabs_left_out: std::cell::Cell<bool>,
|
||||
}
|
||||
|
||||
/// Spend `budget` on the tab stops `tabs`: when there aren't enough left, they're left out (the
|
||||
/// default stops apply). Whether they were.
|
||||
fn spend_tabs(tabs: &mut Vec<TabStop>, budget: &mut usize) -> bool {
|
||||
if tabs.len() <= *budget {
|
||||
*budget -= tabs.len();
|
||||
false
|
||||
} else {
|
||||
tabs.clear();
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -607,7 +649,12 @@ impl Texts {
|
||||
if runs.is_empty() {
|
||||
runs.push((text.chars().count(), self.style(None)));
|
||||
}
|
||||
Some(Story { text, anchor, lines, frames, paras, runs, path_spacing, vertical })
|
||||
let mut budget = MAX_STORY_TABS;
|
||||
let mut tabs_left_out = false;
|
||||
for (_, p) in &mut paras {
|
||||
tabs_left_out |= p.tabs_truncated | spend_tabs(&mut p.tabs, &mut budget);
|
||||
}
|
||||
Some(Story { text, anchor, lines, frames, paras, runs, path_spacing, vertical, tabs_left_out: tabs_left_out.into() })
|
||||
}
|
||||
|
||||
/// A paragraph's attributes (`run`: its attributes, key 5, and the paragraph style it is based
|
||||
@@ -633,6 +680,46 @@ impl Texts {
|
||||
space_before: num("4"),
|
||||
space_after: num("5"),
|
||||
hyphenate: !matches!(pick("9"), Some(Val::Bool(false))),
|
||||
auto_leading: pick("7").and_then(Val::num).filter(|v| v.is_finite() && *v > 0.0 && *v <= 5.0),
|
||||
hyphenation: {
|
||||
let d = HyphenationOptions::default();
|
||||
let count = |k: &str, lo: f64, hi: f64, or: u32| {
|
||||
pick(k).and_then(Val::num).filter(|v| v.is_finite() && v.fract() == 0.0 && (lo..=hi).contains(v)).map_or(or, |v| v as u32)
|
||||
};
|
||||
HyphenationOptions {
|
||||
words_longer_than: count("10", 1.0, 25.0, d.words_longer_than),
|
||||
after_first: count("11", 1.0, 15.0, d.after_first),
|
||||
before_last: count("12", 1.0, 15.0, d.before_last),
|
||||
hyphen_limit: count("13", 0.0, 25.0, d.hyphen_limit),
|
||||
zone: pick("14").and_then(Val::num).filter(|v| v.is_finite() && (0.0..=1296.0).contains(v)).unwrap_or(d.zone),
|
||||
capitalized: match pick("15") {
|
||||
Some(Val::Bool(b)) => *b,
|
||||
_ => d.capitalized,
|
||||
},
|
||||
}
|
||||
},
|
||||
tabs_truncated: pick("30").and_then(|t| t.get("0")).map(Val::list).is_some_and(|list| list.len() > MAX_TABS),
|
||||
tabs: {
|
||||
let list = pick("30").and_then(|t| t.get("0")).map(Val::list).unwrap_or_default();
|
||||
let mut tabs: Vec<TabStop> = list
|
||||
.iter()
|
||||
.take(MAX_TABS)
|
||||
.filter_map(|t| {
|
||||
let position = t.get("0").and_then(Val::num).filter(|p| (0.0..=MAX_TAB_POSITION).contains(p))?;
|
||||
let align = match t.get("1").map(Val::num) {
|
||||
None | Some(Some(0.0)) => TabAlign::Left,
|
||||
Some(Some(1.0)) => TabAlign::Center,
|
||||
Some(Some(2.0)) => TabAlign::Right,
|
||||
Some(Some(3.0)) => TabAlign::Decimal,
|
||||
_ => return None,
|
||||
};
|
||||
Some(TabStop { position, align, leader: String::new(), align_on: '.' })
|
||||
})
|
||||
.collect();
|
||||
tabs.sort_by(|a, b| a.position.total_cmp(&b.position));
|
||||
tabs.dedup_by(|a, b| (a.position - b.position).abs() < 1e-6);
|
||||
tabs
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1001,7 +1088,6 @@ impl Story {
|
||||
// The text document measures in the art's units too: the document's scale carries its
|
||||
// sizes and spacings onto the page (a Large Canvas copy is written at 1:10; #2031).
|
||||
let scale = scale * art_scale(to_doc);
|
||||
let leading = self.line_leading(scale);
|
||||
let chars: Vec<char> = text.chars().collect();
|
||||
let mut runs = vec![];
|
||||
let mut from = 0usize;
|
||||
@@ -1012,13 +1098,13 @@ impl Story {
|
||||
if piece.is_empty() {
|
||||
continue;
|
||||
}
|
||||
runs.push(TextRun::new(piece, char_style(st, scale, leading)));
|
||||
runs.push(TextRun::new(piece, char_style(st, scale)));
|
||||
}
|
||||
if from < chars.len() {
|
||||
let last = self.runs.last().map(|r| &r.1)?;
|
||||
runs.push(TextRun::new(chars.get(from..).unwrap_or_default().iter().collect::<String>(), char_style(last, scale, leading)));
|
||||
runs.push(TextRun::new(chars.get(from..).unwrap_or_default().iter().collect::<String>(), char_style(last, scale)));
|
||||
}
|
||||
let first = self.runs.first().map(|r| char_style(&r.1, scale, leading))?;
|
||||
let first = self.runs.first().map(|r| char_style(&r.1, scale))?;
|
||||
let mut t = TextObject::point(Point::ZERO, "", first);
|
||||
if !runs.is_empty() {
|
||||
t.runs = runs;
|
||||
@@ -1065,6 +1151,21 @@ impl Story {
|
||||
!self.lines.is_empty() && vectorcraft_text::fit_first_line(vectorcraft_text::FontDb::global(), t)
|
||||
}
|
||||
|
||||
/// Area type of one frame that the file lays more lines out in than fit here: in the fallback
|
||||
/// font, or a last line whose descent the file lets pass the frame's bottom. The frame is made
|
||||
/// taller from its bottom (`vectorcraft_text::fit_source_lines`) so the file's lines show.
|
||||
/// Whether it was.
|
||||
pub(super) fn fit_last_lines(&self, t: &mut TextObject) -> bool {
|
||||
matches!(self.frames.as_slice(), [FrameKind::Area(..)])
|
||||
&& vectorcraft_text::fit_source_lines(vectorcraft_text::FontDb::global(), t, self.lines.len())
|
||||
}
|
||||
|
||||
/// Were tab stops past [`MAX_STORY_TABS`] left out of its paragraphs (so far: making its text
|
||||
/// object counts them again)?
|
||||
pub(super) fn tabs_left_out(&self) -> bool {
|
||||
self.tabs_left_out.get()
|
||||
}
|
||||
|
||||
/// Area type (`node`, the story's first frame as [`Self::node`] makes it with `template` and
|
||||
/// `to_doc`) whose first line the file lays out higher or lower than it is laid out here, as its
|
||||
/// page draws it: its first baseline is fixed where the file has it. The font's ascent below the
|
||||
@@ -1103,38 +1204,6 @@ impl Story {
|
||||
true
|
||||
}
|
||||
|
||||
/// The leading the file's own line positions imply: the distance from one line to the next, less
|
||||
/// the space between paragraphs that is part of it (a paragraph's space after and the next one's
|
||||
/// space before; a layout's lines are where that space has put them, and the text object adds it
|
||||
/// again).
|
||||
fn line_leading(&self, scale: f64) -> Option<f64> {
|
||||
let para_at = |c: usize| {
|
||||
let mut end = 0usize;
|
||||
for (n, p) in &self.paras {
|
||||
end = end.saturating_add(*n);
|
||||
if c < end {
|
||||
return Some(p);
|
||||
}
|
||||
}
|
||||
self.paras.last().map(|(_, p)| p)
|
||||
};
|
||||
let chars: Vec<char> = self.text.chars().collect();
|
||||
let breaks: Vec<usize> = chars.iter().enumerate().filter(|(_, c)| matches!(c, '\r' | '\x03')).map(|(i, _)| i).collect();
|
||||
// More lines than breaks: area type wraps, and which break ends which line is unknown.
|
||||
let wraps = self.lines.len() > breaks.len() + 1;
|
||||
self.lines.windows(2).enumerate().find_map(|(i, w)| {
|
||||
let pitch = w[1].1 - w[0].1;
|
||||
let between = match breaks.get(i) {
|
||||
Some(&at) if !wraps && chars.get(at) == Some(&'\r') => {
|
||||
para_at(at).map_or(0.0, |p| p.space_after) + para_at(at + 1).map_or(0.0, |p| p.space_before)
|
||||
}
|
||||
_ => 0.0,
|
||||
};
|
||||
let l = (pitch - between) * scale;
|
||||
(l.is_finite() && l > 0.0).then_some(l)
|
||||
})
|
||||
}
|
||||
|
||||
/// The style of each paragraph of `text` (paragraphs split at `\n`).
|
||||
fn paragraph_styles(&self, text: &str, scale: f64) -> Vec<ParaStyle> {
|
||||
let count = text.split('\n').count();
|
||||
@@ -1142,9 +1211,13 @@ impl Story {
|
||||
let mut runs = self.paras.iter();
|
||||
let mut current = runs.next();
|
||||
let mut left = current.map_or(usize::MAX, |r| r.0);
|
||||
let mut budget = MAX_STORY_TABS;
|
||||
for p in text.split('\n') {
|
||||
let para = current.map(|r| r.1.clone()).unwrap_or_default();
|
||||
out.push(para_style(¶, scale));
|
||||
let mut style = current.map_or_else(|| para_style(&Para::default(), scale), |r| para_style(&r.1, scale));
|
||||
if spend_tabs(&mut style.tabs, &mut budget) {
|
||||
self.tabs_left_out.set(true);
|
||||
}
|
||||
out.push(style);
|
||||
// Each paragraph and its ending `\r` count.
|
||||
let mut used = p.chars().count() + 1;
|
||||
while used > 0 {
|
||||
@@ -1165,6 +1238,8 @@ impl Story {
|
||||
}
|
||||
}
|
||||
|
||||
/// The paragraph style of paragraph attributes `p`, its lengths (indents, spacing, the
|
||||
/// hyphenation zone) scaled by `scale`, as sizes are.
|
||||
fn para_style(p: &Para, scale: f64) -> ParaStyle {
|
||||
ParaStyle {
|
||||
justify: match p.justify {
|
||||
@@ -1184,21 +1259,33 @@ fn para_style(p: &Para, scale: f64) -> ParaStyle {
|
||||
space_before: p.space_before * scale,
|
||||
space_after: p.space_after * scale,
|
||||
hyphenate: p.hyphenate,
|
||||
hyphenation: HyphenationOptions { zone: p.hyphenation.zone * scale, ..p.hyphenation.clone() },
|
||||
tabs: p.tabs.iter().map(|t| TabStop { position: t.position * scale, ..t.clone() }).collect(),
|
||||
// A right-to-left paragraph lays its text out from the right whatever letters it has
|
||||
// (" 120.5 mm " reads "mm 120.5"); without the key, from its first strong letter.
|
||||
direction: p.rtl.then_some(ParaDirection::RightToLeft),
|
||||
justification: JustificationOptions {
|
||||
// Rounded, so the file's 1.2 is the default 120% exactly.
|
||||
auto_leading: p.auto_leading.map_or(JustificationOptions::default().auto_leading, |a| (a * 1e6).round() / 1e4),
|
||||
..JustificationOptions::default()
|
||||
},
|
||||
..ParaStyle::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn char_style(s: &Style, scale: f64, leading: Option<f64>) -> CharStyle {
|
||||
/// The character style of character attributes `s`: its font from the fonts the app has, its
|
||||
/// lengths (size, leading, baseline shift, stroke width) scaled by `scale`.
|
||||
fn char_style(s: &Style, scale: f64) -> CharStyle {
|
||||
let (family, style) = s.font.as_deref().map_or_else(|| (CharStyle::default().font_family, "Regular".to_string()), crate::family_style);
|
||||
let family = vectorcraft_text::FontDb::global().find_family(&family).unwrap_or(family);
|
||||
CharStyle {
|
||||
font_family: family,
|
||||
font_style: style,
|
||||
size: s.size * scale,
|
||||
leading: s.leading.map(|l| l * scale).or(leading),
|
||||
// Auto leading stays auto: the layout gives each line the paragraph's share of the largest
|
||||
// type on it, as the file's own layout does ("The largest leading value in a line of type
|
||||
// determines the leading for that line": https://helpx.adobe.com/illustrator/using/line-character-spacing.html).
|
||||
leading: s.leading.map(|l| l * scale),
|
||||
tracking: s.tracking,
|
||||
baseline_shift: s.baseline_shift * scale,
|
||||
h_scale: s.h_scale * 100.0,
|
||||
@@ -1247,6 +1334,130 @@ mod tests {
|
||||
assert_eq!(justify(b"/0 1 /33 0"), Justify::Right);
|
||||
}
|
||||
|
||||
/// Key 7 is the paragraph's auto leading, a share of the type size; one that can't be read
|
||||
/// leaves the default, 120%.
|
||||
#[test]
|
||||
fn a_paragraph_keeps_its_auto_leading() {
|
||||
let texts = Texts {
|
||||
stories: vec![],
|
||||
fonts: vec![],
|
||||
defaults: Val::Dict(BTreeMap::new()),
|
||||
para_defaults: read(b"/7 1.2").unwrap(),
|
||||
char_sheets: vec![],
|
||||
para_sheets: vec![],
|
||||
frames: vec![],
|
||||
};
|
||||
let auto = |own: &[u8]| para_style(&texts.para(Some(&read(&[b"/5 << ", own, b" >>"].concat()).unwrap())), 1.0).justification.auto_leading;
|
||||
assert_eq!(auto(b""), JustificationOptions::default().auto_leading);
|
||||
assert_eq!(auto(b"/7 1.5"), 150.0);
|
||||
assert_eq!(auto(b"/7 1.15"), 115.0);
|
||||
for unreadable in [b"/7 0".as_slice(), b"/7 -1", b"/7 1e9", b"/7 /nil"] {
|
||||
assert!((auto(unreadable) - 120.0).abs() < 1e-9, "{}", String::from_utf8_lossy(unreadable));
|
||||
}
|
||||
}
|
||||
|
||||
/// Keys 10 to 15 are the paragraph's hyphenation options; one that can't be read, or is out of
|
||||
/// its range, keeps the default. The zone is in points of the text document, scaled as sizes are.
|
||||
#[test]
|
||||
fn a_paragraph_keeps_its_hyphenation_options() {
|
||||
let texts = Texts {
|
||||
stories: vec![],
|
||||
fonts: vec![],
|
||||
defaults: Val::Dict(BTreeMap::new()),
|
||||
para_defaults: read(b"/10 6 /11 2 /12 2 /13 0 /14 36.0 /15 true").unwrap(),
|
||||
char_sheets: vec![],
|
||||
para_sheets: vec![],
|
||||
frames: vec![],
|
||||
};
|
||||
let options = |own: &[u8], scale: f64| para_style(&texts.para(Some(&read(&[b"/5 << ", own, b" >>"].concat()).unwrap())), scale).hyphenation;
|
||||
let want = HyphenationOptions { words_longer_than: 6, after_first: 2, before_last: 2, hyphen_limit: 0, zone: 36.0, capitalized: true };
|
||||
assert_eq!(options(b"", 1.0), want);
|
||||
assert_eq!(
|
||||
options(b"/10 8 /13 3 /15 false", 0.5),
|
||||
HyphenationOptions { words_longer_than: 8, hyphen_limit: 3, zone: 18.0, capitalized: false, ..want.clone() }
|
||||
);
|
||||
let d = HyphenationOptions::default();
|
||||
let bare = Texts {
|
||||
stories: vec![],
|
||||
fonts: vec![],
|
||||
defaults: Val::Dict(BTreeMap::new()),
|
||||
para_defaults: Val::Dict(BTreeMap::new()),
|
||||
char_sheets: vec![],
|
||||
para_sheets: vec![],
|
||||
frames: vec![],
|
||||
};
|
||||
let own = |own: &[u8]| para_style(&bare.para(Some(&read(&[b"/5 << ", own, b" >>"].concat()).unwrap())), 1.0).hyphenation;
|
||||
assert_eq!(own(b""), d);
|
||||
assert_eq!(own(b"/10 0 /11 99 /12 2.5 /13 -1 /14 -3 /15 1"), d);
|
||||
}
|
||||
|
||||
/// Key 30 holds the paragraph's tab stops: their positions (key 0), sorted, and alignments (key
|
||||
/// 1: 0 left, 1 center, 2 right, 3 decimal), scaled as sizes are. A stop that can't be read is
|
||||
/// left out. A user's price list keeps a right stop at 269.29 and a left one at 272.13.
|
||||
#[test]
|
||||
fn a_paragraph_keeps_its_tab_stops() {
|
||||
let texts = Texts {
|
||||
stories: vec![],
|
||||
fonts: vec![],
|
||||
defaults: Val::Dict(BTreeMap::new()),
|
||||
para_defaults: Val::Dict(BTreeMap::new()),
|
||||
char_sheets: vec![],
|
||||
para_sheets: vec![],
|
||||
frames: vec![],
|
||||
};
|
||||
let tabs = |own: &[u8], scale: f64| {
|
||||
para_style(&texts.para(Some(&read(&[b"/5 << ", own, b" >>"].concat()).unwrap())), scale)
|
||||
.tabs
|
||||
.iter()
|
||||
.map(|t| (t.position, t.align))
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(tabs(b"", 1.0), []);
|
||||
assert_eq!(
|
||||
tabs(b"/30 << /0 [ << /0 272.12598 /1 0 >> << /0 269.29135 /1 2 >> ] >>", 1.0),
|
||||
[(269.29135, TabAlign::Right), (272.12598, TabAlign::Left)]
|
||||
);
|
||||
assert_eq!(
|
||||
tabs(b"/30 << /0 [ << /0 10 /1 1 >> << /0 20 /1 3 >> << /0 30 >> ] >>", 0.5),
|
||||
[(5.0, TabAlign::Center), (10.0, TabAlign::Decimal), (15.0, TabAlign::Left)]
|
||||
);
|
||||
// Past MAX_TABS stops, the rest are left out, and the paragraph says so (the story's warning).
|
||||
let many = |n: usize| {
|
||||
let stops: String = (0..n).map(|i| format!("<< /0 {i} >> ")).collect();
|
||||
texts.para(Some(&read(format!("/5 << /30 << /0 [ {stops}] >> >>").as_bytes()).unwrap()))
|
||||
};
|
||||
let p = many(MAX_TABS + 6);
|
||||
assert!(p.tabs_truncated && p.tabs.len() == MAX_TABS);
|
||||
let p = many(MAX_TABS);
|
||||
assert!(!p.tabs_truncated && p.tabs.len() == MAX_TABS);
|
||||
// Unreadable: a position out of range or not a number, an unknown alignment.
|
||||
assert_eq!(
|
||||
tabs(b"/30 << /0 [ << /0 -1 >> << /0 1e9 >> << /0 /nil >> << /0 5 /1 7 >> << /0 6 /1 /x >> << /0 7 /1 2 >> ] >>", 1.0),
|
||||
[(7.0, TabAlign::Right)]
|
||||
);
|
||||
}
|
||||
|
||||
/// A story's paragraphs take at most [`MAX_STORY_TABS`] tab stops in all (a paragraph style's
|
||||
/// are copied into each paragraph): those past it take the default stops, and the story says so.
|
||||
#[test]
|
||||
fn a_story_s_tab_stops_are_bounded() {
|
||||
let mut budget = 3;
|
||||
let mut tabs = vec![TabStop { position: 1.0, align: TabAlign::Left, leader: String::new(), align_on: '.' }; 2];
|
||||
assert!(!spend_tabs(&mut tabs, &mut budget) && tabs.len() == 2 && budget == 1);
|
||||
assert!(spend_tabs(&mut tabs, &mut budget) && tabs.is_empty() && budget == 1);
|
||||
// Paragraphs of a style with MAX_TABS stops each, more than the story takes.
|
||||
let stop = TabStop { position: 1.0, align: TabAlign::Left, leader: String::new(), align_on: '.' };
|
||||
let para = Para { tabs: vec![stop; MAX_TABS], ..Para::default() };
|
||||
let count = MAX_STORY_TABS / MAX_TABS + 2;
|
||||
let s = story(&"a\r".repeat(count), &[0.0], ¶);
|
||||
assert!(!s.tabs_left_out());
|
||||
let styles = s.paragraph_styles(&format!("{}a", "a\n".repeat(count - 1)), 1.0);
|
||||
assert_eq!(styles.len(), count);
|
||||
assert!(s.tabs_left_out());
|
||||
assert_eq!(styles.iter().map(|p| p.tabs.len()).sum::<usize>(), MAX_STORY_TABS);
|
||||
assert!(styles.last().is_some_and(|p| p.tabs.is_empty()));
|
||||
}
|
||||
|
||||
/// Where point type lies runs along its baseline: a label turned a quarter (as a vertical
|
||||
/// dimension's is) lies in a tall box, not a wide one.
|
||||
#[test]
|
||||
@@ -1636,6 +1847,7 @@ mod tests {
|
||||
)],
|
||||
path_spacing: 0.0,
|
||||
vertical: false,
|
||||
tabs_left_out: false.into(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1882,25 +2094,54 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// The baselines of the text object `story` comes in as, laid out.
|
||||
fn baselines_of(story: &Story) -> Vec<f64> {
|
||||
let Some(node) = story.node(NodeId(1), 0, (0.0, 0.0), Affine::IDENTITY) else { return vec![] };
|
||||
let NodeKind::Text(t) = &node.kind else { return vec![] };
|
||||
vectorcraft_text::layout(vectorcraft_text::FontDb::global(), t).baselines().iter().map(|b| b.0.y).collect()
|
||||
}
|
||||
|
||||
/// Auto leading stays auto: each line takes the paragraph's share of the largest type on it, as
|
||||
/// the file's own layout does, not the distance between the first two lines for every line. A
|
||||
/// 15 pt heading over 10 pt type at 120%: 18 pt between the heading's lines, then 12 pt.
|
||||
#[test]
|
||||
fn auto_leading_follows_the_size_of_each_line() {
|
||||
let mut s = story("Big\x03Bigger\rsmall\r", &[0.0, 18.0, 30.0], &Para::default());
|
||||
let base = s.runs[0].1.clone();
|
||||
s.runs = vec![(11, Style { size: 15.0, ..base.clone() }), (6, Style { size: 10.0, ..base })];
|
||||
assert_eq!(leading_of(&s), None);
|
||||
let ys = baselines_of(&s);
|
||||
assert_eq!(ys.len(), 3, "{ys:?}");
|
||||
assert!(((ys[1] - ys[0]).abs() - 18.0).abs() < 1e-6, "{ys:?}");
|
||||
assert!(((ys[2] - ys[1]).abs() - 12.0).abs() < 1e-6, "{ys:?}");
|
||||
// At a share the paragraph sets (key 7) of 150%: 22.5 pt, then 15 pt.
|
||||
let share = Para { auto_leading: Some(1.5), ..Para::default() };
|
||||
s.paras = s.paras.iter().map(|(n, _)| (*n, share.clone())).collect();
|
||||
let ys = baselines_of(&s);
|
||||
assert!(((ys[1] - ys[0]).abs() - 22.5).abs() < 1e-6, "{ys:?}");
|
||||
assert!(((ys[2] - ys[1]).abs() - 15.0).abs() < 1e-6, "{ys:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_leaves_out_the_space_between_paragraphs_that_the_lines_already_have() {
|
||||
// Lines 10.6 apart that are three paragraphs with 5 less after each: auto leading (15.6) less 5.
|
||||
let para = Para { space_after: -5.0, ..Para::default() };
|
||||
// The text object keeps auto leading and the spacing, so its lines are where the file's are.
|
||||
let s = story("one\rtwo\rthree\r", &[0.0, 10.6, 21.2], ¶);
|
||||
assert!((s.line_leading(1.0).unwrap() - 15.6).abs() < 1e-9);
|
||||
assert!((leading_of(&s).unwrap() - 15.6).abs() < 1e-9);
|
||||
// Space after and space before both count; the scale of the frame carries onto the leading.
|
||||
assert_eq!(leading_of(&s), None);
|
||||
let ys = baselines_of(&s);
|
||||
assert!(ys.len() == 3 && ys.windows(2).all(|w| ((w[1] - w[0]).abs() - 10.6).abs() < 1e-6), "{ys:?}");
|
||||
// Space after and space before both count.
|
||||
let para = Para { space_after: 4.0, space_before: 2.0, ..Para::default() };
|
||||
let s = story("one\rtwo\r", &[0.0, 20.0], ¶);
|
||||
assert!((s.line_leading(1.0).unwrap() - 14.0).abs() < 1e-9);
|
||||
assert!((s.line_leading(0.5).unwrap() - 7.0).abs() < 1e-9);
|
||||
let ys = baselines_of(&story("one\rtwo\r", &[0.0, 21.6], ¶));
|
||||
assert!(((ys[1] - ys[0]).abs() - 21.6).abs() < 1e-6, "{ys:?}");
|
||||
}
|
||||
|
||||
/// #2031: a Large Canvas editing copy measures its text document in its art's units, a tenth
|
||||
/// of the page's: the story's size and leading reach the page through `to_doc`'s scale.
|
||||
#[test]
|
||||
fn a_story_in_a_scaled_art_space_keeps_its_size_and_leading() {
|
||||
let s = story("one\rtwo\r", &[0.0, 20.0], &Para::default());
|
||||
let s = story("one\rtwo\r", &[0.0, 15.6], &Para::default());
|
||||
// A copy written at 1:10 (see `ai::read::ensure_space`): its art's units reach the
|
||||
// document, 100 points to the page, through `to_doc`'s scale.
|
||||
let to_doc = Affine::scale(10.0) * Affine::new([1.0, 0.0, 0.0, -1.0, 0.0, 100.0]);
|
||||
@@ -1909,24 +2150,18 @@ mod tests {
|
||||
_ => panic!("not text"),
|
||||
};
|
||||
assert_eq!(t.runs[0].style.size, 130.0, "13 pt at the page's scale");
|
||||
assert_eq!(t.runs[0].style.leading, Some(200.0), "a 20-unit line pitch at the page's scale");
|
||||
assert_eq!(t.runs[0].style.leading, None, "auto leading: 120% of its size at the page's scale");
|
||||
assert_eq!(t.para.justification.auto_leading, 120.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_between_lines_of_a_paragraph_is_their_distance() {
|
||||
// A line break inside a paragraph has no paragraph spacing between its lines.
|
||||
let para = Para { space_after: -5.0, space_before: 3.0, ..Para::default() };
|
||||
let s = story("one\x03two\x03three\r", &[0.0, 15.6, 31.2], ¶);
|
||||
assert!((s.line_leading(1.0).unwrap() - 15.6).abs() < 1e-9);
|
||||
// Paragraphs without spacing: the distance as it was.
|
||||
let s = story("one\rtwo\r", &[0.0, 15.6], &Para::default());
|
||||
assert!((s.line_leading(1.0).unwrap() - 15.6).abs() < 1e-9);
|
||||
// Area type whose paragraph wraps: lines and breaks don't pair up, so nothing is taken off.
|
||||
let para = Para { space_after: -5.0, ..Para::default() };
|
||||
let s = story("one two three\rfour\r", &[0.0, 15.6, 31.2, 41.8], ¶);
|
||||
assert!((s.line_leading(1.0).unwrap() - 15.6).abs() < 1e-9);
|
||||
// One line has no distance to read.
|
||||
assert_eq!(story("one\r", &[0.0], &Para::default()).line_leading(1.0), None);
|
||||
let ys = baselines_of(&story("one\x03two\x03three\r", &[0.0, 15.6, 31.2], ¶));
|
||||
assert!(ys.len() == 3 && ys.windows(2).all(|w| ((w[1] - w[0]).abs() - 15.6).abs() < 1e-6), "{ys:?}");
|
||||
// One line.
|
||||
assert_eq!(baselines_of(&story("one\r", &[0.0], &Para::default())).len(), 1);
|
||||
}
|
||||
|
||||
/// A `\x03` ends a line inside its paragraph: it comes in as a forced line break, and the
|
||||
@@ -1970,6 +2205,32 @@ mod tests {
|
||||
assert!(!story("Heading\r", &[], &Para::default()).fit_first_line(&mut t) && height(&t).unwrap().3 == 13.0);
|
||||
}
|
||||
|
||||
/// The file sets three lines in a frame whose third line's descent passes its bottom: the frame
|
||||
/// grows from its bottom so the third shows. Only when the story's one frame is area type.
|
||||
#[test]
|
||||
fn the_last_lines_the_file_sets_in_its_frame_show() {
|
||||
let db = vectorcraft_text::FontDb::global();
|
||||
let area = |height: f64| {
|
||||
let mut t = TextObject::point(Point::ZERO, "one\ntwo\nthree", CharStyle { size: 13.0, ..CharStyle::default() });
|
||||
t.kind = TextKind::Area { frame: vectorcraft_geom::shapes::rectangle(Rect::new(10.0, 20.0, 210.0, 20.0 + height)) };
|
||||
t
|
||||
};
|
||||
let tall = vectorcraft_text::layout(db, &area(400.0));
|
||||
let third = &tall.lines[2];
|
||||
let mut t = area(third.baseline - 20.0 + third.descent / 2.0);
|
||||
assert_eq!(vectorcraft_text::layout(db, &t).lines.len(), 2);
|
||||
let mut s = story("one\rtwo\rthree\r", &[0.0, 15.6, 31.2], &Para::default());
|
||||
// A point-type frame (the helper's) isn't fitted.
|
||||
assert!(!s.fit_last_lines(&mut t));
|
||||
s.frames = vec![FrameKind::Area(vec![], AreaFrame::default())];
|
||||
assert!(s.fit_last_lines(&mut t));
|
||||
assert_eq!(vectorcraft_text::layout(db, &t).lines.len(), 3);
|
||||
// A story threaded through two frames: its lines are the first frame's alone.
|
||||
let mut t = area(third.baseline - 20.0 + third.descent / 2.0);
|
||||
s.frames.push(FrameKind::Area(vec![], AreaFrame::default()));
|
||||
assert!(!s.fit_last_lines(&mut t));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn area_type_s_first_line_goes_where_the_file_lays_it_out() {
|
||||
// GUARDS: area type's first baseline was the font's ascent below the frame's top, where the
|
||||
|
||||
@@ -54,7 +54,7 @@ use build::{Frame, MADE, prune_unseen};
|
||||
use compare::{
|
||||
MAX_DIFFERENCE, MAX_SOLID_DIFFERENCE, PageView, Shares, compare, compared, comparison_render, comparison_samples, differ, differ_in_colour,
|
||||
};
|
||||
pub use layers::{AiLayers, ai_alone, ai_alone_on_page, ai_layers_alone, ai_opened_artboard, layered_ai, layered_ai_from};
|
||||
pub use layers::{AiLayers, ai_alone, ai_alone_on_page, ai_alone_with, ai_layers_alone, ai_opened_artboard, layered_ai, layered_ai_from};
|
||||
pub(super) use layers::{layered, program_alone};
|
||||
pub(crate) use slots::MAX_TEXT;
|
||||
pub use slots::is_loss;
|
||||
|
||||
@@ -49,7 +49,7 @@ pub(super) struct Frame<'a> {
|
||||
/// (a `.ai` saved without its PDF part), its type is made from the file's text document alone and
|
||||
/// nothing is compared. `outlined`: the page's type was read as outlines, so it has none to put in
|
||||
/// the text objects. `unit`: the size in points of a unit of the page's user space (see
|
||||
/// [`layered_ai`]).
|
||||
/// [`layered_ai`]). `names`: the encoding of names that aren't UTF-8.
|
||||
pub(super) fn build(
|
||||
data: &[u8],
|
||||
visible: Option<&Document>,
|
||||
@@ -57,11 +57,12 @@ pub(super) fn build(
|
||||
outlined: bool,
|
||||
trust: bool,
|
||||
unit: f64,
|
||||
names: ai::NameEncoding,
|
||||
) -> Result<(Document, Vec<String>), String> {
|
||||
// An EPS (its page is its art) draws a Large Canvas page at full size; a `.ai` keeps its art
|
||||
// space, as its PDF part may (#2031).
|
||||
let large_canvas = matches!(page, Page::Art);
|
||||
let structure = if visible.is_some() { ai::read_over_page(data, large_canvas)? } else { ai::read(data, large_canvas)? };
|
||||
let structure = if visible.is_some() { ai::read_over_page(data, large_canvas, names)? } else { ai::read_in(data, large_canvas, names)? };
|
||||
build_from(structure, data, visible, page, outlined, trust, unit)
|
||||
}
|
||||
|
||||
@@ -69,9 +70,10 @@ pub(super) fn build(
|
||||
/// (width and height, either way round) points large in units of `unit` points: the document is
|
||||
/// drawn `unit` times as large when its first artboard, or its art's box, has the page's size in
|
||||
/// those units and not in points, as [`build_from`] decides with a page; else as many times as
|
||||
/// large as its declared large canvas scale when it has the page's size at that scale.
|
||||
pub(super) fn build_on_page(data: &[u8], page: (f64, f64), unit: f64) -> Result<(Document, Vec<String>), String> {
|
||||
let structure = ai::read(data, false)?;
|
||||
/// large as its declared large canvas scale when it has the page's size at that scale. `names`: the
|
||||
/// encoding of names that aren't UTF-8.
|
||||
pub(super) fn build_on_page(data: &[u8], page: (f64, f64), unit: f64, names: ai::NameEncoding) -> Result<(Document, Vec<String>), String> {
|
||||
let structure = ai::read_in(data, false, names)?;
|
||||
let board = structure.artboard.map(|a| structure.to_doc.transform_rect_bbox(a));
|
||||
let art = structure.bbox.map(|[a, b, c, d]| structure.to_doc.transform_rect_bbox(Rect::new(a, b, c, d)));
|
||||
let (w, h) = page;
|
||||
|
||||
@@ -11,10 +11,12 @@ use super::{Affine, Arc, Cow, Document, Imported, Node, NodeKind, PathData, Rect
|
||||
/// ([`use_symbols`]) and its variable library ([`use_variables`]) when it could be read, and with
|
||||
/// its layer tree, empty, below the page's layer when that could be read (#2033). A program in the
|
||||
/// legacy format without layers (`illustrator`, see [`program_alone`]) is read with its art on one
|
||||
/// layer; when that can't be used, the file is `visible` as it was.
|
||||
pub(in super::super) fn layered(ps: &[u8], visible: Imported, trust: bool, illustrator: bool) -> Imported {
|
||||
/// layer; when that can't be used, the file is `visible` as it was. `names`: the encoding of names
|
||||
/// that aren't UTF-8.
|
||||
pub(in super::super) fn layered(ps: &[u8], visible: Imported, trust: bool, illustrator: bool, names: ai::NameEncoding) -> Imported {
|
||||
let Some(data) = editing_copy(ps) else {
|
||||
let read = illustrator.then(|| one_layer(ps)).flatten().and_then(|p| build(&p, Some(&visible.document), Page::Art, false, trust, 1.0).ok());
|
||||
let read =
|
||||
illustrator.then(|| one_layer(ps)).flatten().and_then(|p| build(&p, Some(&visible.document), Page::Art, false, trust, 1.0, names).ok());
|
||||
return match read {
|
||||
Some((document, warnings)) => with_page_notes(document, warnings, &visible),
|
||||
None => visible,
|
||||
@@ -24,7 +26,8 @@ pub(in super::super) fn layered(ps: &[u8], visible: Imported, trust: bool, illus
|
||||
// can't be used.
|
||||
// Private data kept apart from the program: the program's own header gives the author and
|
||||
// custom colors the private data's header may lack.
|
||||
let read = |d: &[u8]| if matches!(data, Ok(Cow::Owned(_))) { ai::read_beside(d, true, ps, true) } else { ai::read_over_page(d, true) };
|
||||
let read =
|
||||
|d: &[u8]| if matches!(data, Ok(Cow::Owned(_))) { ai::read_beside(d, true, ps, true, names) } else { ai::read_over_page(d, true, names) };
|
||||
let (tree, result) = match data.as_deref() {
|
||||
Ok(d) => match read(d) {
|
||||
Ok(s) => (layer_tree(&s.doc.layers), build_from(s, d, Some(&visible.document), Page::Art, false, trust, 1.0)),
|
||||
@@ -37,12 +40,14 @@ pub(in super::super) fn layered(ps: &[u8], visible: Imported, trust: bool, illus
|
||||
Err(why) => {
|
||||
let mut v = visible;
|
||||
if let Ok(data) = &data {
|
||||
let mut read = ai::Names::new(names);
|
||||
let have = v.document.patterns.len();
|
||||
let own_palette = use_palette(data, &mut v.document);
|
||||
use_brushes(data, &mut v.document, have, &mut v.warnings);
|
||||
use_styles(data, &mut v.document, true, 1.0, None);
|
||||
use_symbols(data, &mut v.document, own_palette, &mut v.warnings);
|
||||
use_variables(data, &mut v.document, &mut v.warnings);
|
||||
let own_palette = use_palette(data, &mut v.document, &mut read);
|
||||
use_brushes(data, &mut v.document, have, &mut v.warnings, &mut read);
|
||||
use_styles(data, &mut v.document, true, 1.0, None, &mut read);
|
||||
use_symbols(data, &mut v.document, own_palette, &mut v.warnings, &mut read);
|
||||
use_variables(data, &mut v.document, &mut v.warnings, &mut read);
|
||||
add_notes(&mut v.warnings, read.notes());
|
||||
}
|
||||
if tree.is_empty() {
|
||||
v.warnings.push(format!("{LAYERS_UNREAD} ({why}): it comes in as its page, in one layer"));
|
||||
@@ -112,12 +117,13 @@ fn layer_tree(nodes: &[Arc<Node>]) -> Vec<Arc<Node>> {
|
||||
/// `unit`: the size in points of a unit of the PDF part's user space, its first page's `UserUnit`,
|
||||
/// by which its art came in scaled. Editing data whose artboard matches the page only in those
|
||||
/// units comes in `unit` times as large, and so does the artboard layout `place_pages` takes from
|
||||
/// it.
|
||||
/// it. Names that aren't UTF-8 are read as Windows-1252 ([`layered_ai_from`]).
|
||||
pub fn layered_ai(private: &[u8], visible: Document, warnings: Vec<String>, outlined: bool, trust: bool, unit: f64) -> (Document, Vec<String>, bool) {
|
||||
layered_ai_from(AiLayers::decode(private), visible, warnings, outlined, trust, unit)
|
||||
layered_ai_from(AiLayers::decode(private), visible, warnings, outlined, trust, unit, ai::NameEncoding::default())
|
||||
}
|
||||
|
||||
/// [`layered_ai`] of the editing copy `layers`, as far as it was already decoded and read.
|
||||
/// [`layered_ai`] of the editing copy `layers`, as far as it was already decoded and read, with the
|
||||
/// names that aren't UTF-8 read in `names`.
|
||||
pub fn layered_ai_from(
|
||||
layers: AiLayers,
|
||||
visible: Document,
|
||||
@@ -125,6 +131,7 @@ pub fn layered_ai_from(
|
||||
outlined: bool,
|
||||
trust: bool,
|
||||
unit: f64,
|
||||
names: ai::NameEncoding,
|
||||
) -> (Document, Vec<String>, bool) {
|
||||
let unread = |mut all: Vec<String>, why: &str| {
|
||||
all.push(format!("{LAYERS_UNREAD} from its editing data ({why}): they come from its PDF part"));
|
||||
@@ -137,34 +144,41 @@ pub fn layered_ai_from(
|
||||
};
|
||||
if !has_layers(&data) {
|
||||
let (mut visible, mut warnings) = (visible, warnings);
|
||||
let (boards, active) = ai::artboards(&data);
|
||||
let (boards, active) = ai::artboards(&data, &mut ai::Names::default());
|
||||
if board_scale(&boards, &visible, unit).is_some() {
|
||||
visible.opened_artboard = active_page(active, &visible);
|
||||
}
|
||||
let mut read = ai::Names::new(names);
|
||||
let have = visible.patterns.len();
|
||||
let own_palette = use_palette(&data, &mut visible);
|
||||
use_brushes(&data, &mut visible, have, &mut warnings);
|
||||
use_styles(&data, &mut visible, false, unit, Some(&boards));
|
||||
use_symbols(&data, &mut visible, own_palette, &mut warnings);
|
||||
use_variables(&data, &mut visible, &mut warnings);
|
||||
let own_palette = use_palette(&data, &mut visible, &mut read);
|
||||
use_brushes(&data, &mut visible, have, &mut warnings, &mut read);
|
||||
use_styles(&data, &mut visible, false, unit, Some(&boards), &mut read);
|
||||
use_symbols(&data, &mut visible, own_palette, &mut warnings, &mut read);
|
||||
use_variables(&data, &mut visible, &mut warnings, &mut read);
|
||||
add_notes(&mut warnings, read.notes());
|
||||
return (visible, warnings, false);
|
||||
}
|
||||
// The PDF part, its pages placed and named as the editing data's artboards are, when the
|
||||
// layers can't be used (`why`).
|
||||
let from_pdf_part = |mut visible: Document, mut warnings: Vec<String>, why: &str| {
|
||||
let (boards, active) = ai::artboards(&data);
|
||||
place_pages(&boards, active, &mut visible, unit);
|
||||
let mut read = ai::Names::new(names);
|
||||
let mut board_names = ai::Names::new(names);
|
||||
let (boards, active) = ai::artboards(&data, &mut board_names);
|
||||
if place_pages(&boards, active, &mut visible, unit) {
|
||||
read.absorb(board_names);
|
||||
}
|
||||
let have = visible.patterns.len();
|
||||
let own_palette = use_palette(&data, &mut visible);
|
||||
use_brushes(&data, &mut visible, have, &mut warnings);
|
||||
use_styles(&data, &mut visible, false, unit, Some(&boards));
|
||||
let own_palette = use_palette(&data, &mut visible, &mut read);
|
||||
use_brushes(&data, &mut visible, have, &mut warnings, &mut read);
|
||||
use_styles(&data, &mut visible, false, unit, Some(&boards), &mut read);
|
||||
let mut all = unread(warnings, why);
|
||||
use_symbols(&data, &mut visible, own_palette, &mut all);
|
||||
use_variables(&data, &mut visible, &mut all);
|
||||
use_symbols(&data, &mut visible, own_palette, &mut all, &mut read);
|
||||
use_variables(&data, &mut visible, &mut all, &mut read);
|
||||
add_notes(&mut all, read.notes());
|
||||
(visible, all, false)
|
||||
};
|
||||
let built = structure
|
||||
.unwrap_or_else(|| ai::read_over_page(&data, false).map(Box::new))
|
||||
.unwrap_or_else(|| ai::read_over_page(&data, false, names).map(Box::new))
|
||||
.and_then(|structure| build_from(*structure, &data, Some(&visible), Page::Artboard, outlined, trust, unit));
|
||||
match built {
|
||||
Ok((mut done, notes)) => {
|
||||
@@ -183,8 +197,8 @@ pub fn layered_ai_from(
|
||||
/// reading it, when the file's text document makes all of its type and nothing in its layers needs
|
||||
/// the PDF part (see `build_without_page`). Nothing is compared with the PDF part. Else, as the
|
||||
/// error, what was decoded and read of the editing copy, for [`layered_ai_from`] once the PDF part
|
||||
/// is imported.
|
||||
pub fn ai_layers_alone(private: &[u8], pages: &[(f64, f64)], unit: f64) -> Result<(Document, Vec<String>), AiLayers> {
|
||||
/// is imported. `names`: the encoding of names that aren't UTF-8.
|
||||
pub fn ai_layers_alone(private: &[u8], pages: &[(f64, f64)], unit: f64, names: ai::NameEncoding) -> Result<(Document, Vec<String>), AiLayers> {
|
||||
let data = match ai::decode_private(private) {
|
||||
Ok(data) => data,
|
||||
Err(why) => return Err(AiLayers { data: Err(why), structure: None }),
|
||||
@@ -193,7 +207,7 @@ pub fn ai_layers_alone(private: &[u8], pages: &[(f64, f64)], unit: f64) -> Resul
|
||||
return Err(AiLayers { data: Ok(data), structure: None });
|
||||
}
|
||||
// An image past the hard limits is read as an unread box, which the PDF part's art replaces.
|
||||
let structure = match ai::read_over_page(&data, false) {
|
||||
let structure = match ai::read_over_page(&data, false, names) {
|
||||
Ok(structure) => structure,
|
||||
Err(why) => return Err(AiLayers { data: Ok(data), structure: Some(Err(why)) }),
|
||||
};
|
||||
@@ -234,9 +248,10 @@ pub fn ai_opened_artboard(private: &[u8], doc: &Document) -> Option<u32> {
|
||||
/// sets, active data set and lock of the variable library of its editing data `data`, as [`build`]
|
||||
/// gives a document read from the layers, and the note about what of the library wasn't read
|
||||
/// added to `warnings`: its bindings aren't, as the objects they bind aren't the layers' objects.
|
||||
/// Left as it is when the editing data has no library.
|
||||
fn use_variables(data: &[u8], doc: &mut Document, warnings: &mut Vec<String>) {
|
||||
let read = ai::variables(data);
|
||||
/// Left as it is when the editing data has no library. `names` reads the library's names and keeps
|
||||
/// the notes on them.
|
||||
fn use_variables(data: &[u8], doc: &mut Document, warnings: &mut Vec<String>, names: &mut ai::Names) {
|
||||
let read = ai::variables(data, names);
|
||||
warnings.extend(read.note());
|
||||
warnings.extend(ai::bindings_note(read.bindings.len() + read.bindings_skipped));
|
||||
if read.present {
|
||||
@@ -250,9 +265,10 @@ fn use_variables(data: &[u8], doc: &mut Document, warnings: &mut Vec<String>) {
|
||||
/// palette doesn't have follow the palette's swatches. The patterns that the editing data defines come
|
||||
/// in for the palette's pattern swatches, with the images they show; one whose name a pattern of
|
||||
/// the PDF part already has takes a free variant of it ([`ai::palette`]). Left as
|
||||
/// it is when the palette is empty. Whether the palette's swatches came in.
|
||||
fn use_palette(data: &[u8], doc: &mut Document) -> bool {
|
||||
let Some(ai::PaletteSwatches { swatches, groups, patterns, images }) = ai::palette(data, &doc.patterns) else { return false };
|
||||
/// it is when the palette is empty. Whether the palette's swatches came in. `names` reads the
|
||||
/// palette's names and keeps the notes on those the swatches take.
|
||||
fn use_palette(data: &[u8], doc: &mut Document, names: &mut ai::Names) -> bool {
|
||||
let Some(ai::PaletteSwatches { swatches, groups, patterns, images }) = ai::palette(data, &doc.patterns, names) else { return false };
|
||||
for (key, blob) in images {
|
||||
doc.images.entry(key).or_insert(blob);
|
||||
}
|
||||
@@ -269,15 +285,25 @@ fn use_palette(data: &[u8], doc: &mut Document) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// `notes` added to `warnings`, those it already has left out.
|
||||
fn add_notes(warnings: &mut Vec<String>, notes: Vec<String>) {
|
||||
for n in notes {
|
||||
if !warnings.contains(&n) {
|
||||
warnings.push(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `doc` (a file read as its page or PDF part, in place of its layers) with the brushes of its
|
||||
/// editing data `data` in place of the default ones, as [`build`] gives a document read from the
|
||||
/// layers, the patterns of the editing data their art paints with (named apart from the first
|
||||
/// `have` patterns of `doc`, those of the page or PDF part, as [`use_palette`] names them, which
|
||||
/// may have added some of them already), and the note for the brushes left out added to
|
||||
/// `warnings`. Left as it is when the editing data has no brushes.
|
||||
fn use_brushes(data: &[u8], doc: &mut Document, have: usize, warnings: &mut Vec<String>) {
|
||||
/// `warnings`. Left as it is when the editing data has no brushes. `names` reads the brushes' names
|
||||
/// and keeps the notes on them.
|
||||
fn use_brushes(data: &[u8], doc: &mut Document, have: usize, warnings: &mut Vec<String>, names: &mut ai::Names) {
|
||||
let page = doc.patterns.get(..have).unwrap_or(&doc.patterns);
|
||||
let Some(ai::Brushes { brushes, patterns, images, note }) = ai::brushes(data, page) else { return };
|
||||
let Some(ai::Brushes { brushes, patterns, images, note }) = ai::brushes(data, page, names) else { return };
|
||||
for (key, blob) in images {
|
||||
doc.images.entry(key).or_insert(blob);
|
||||
}
|
||||
@@ -299,9 +325,10 @@ fn use_brushes(data: &[u8], doc: &mut Document, have: usize, warnings: &mut Vec<
|
||||
/// the size of `doc`'s pages in units of `unit` points, else as many times as large as the data's
|
||||
/// declared large canvas scale when they are the pages' size at that scale ([`board_scale`]).
|
||||
/// `boards`: the editing data's artboards when they were already read. Left as it is when the
|
||||
/// editing data has no style this reads.
|
||||
fn use_styles(data: &[u8], doc: &mut Document, large_canvas: bool, unit: f64, boards: Option<&[(String, Rect)]>) {
|
||||
let (mut styles, canvas) = ai::graphic_styles(data, large_canvas);
|
||||
/// editing data has no style this reads. `names` reads the styles' names and keeps the notes on
|
||||
/// them.
|
||||
fn use_styles(data: &[u8], doc: &mut Document, large_canvas: bool, unit: f64, boards: Option<&[(String, Rect)]>, names: &mut ai::Names) {
|
||||
let (mut styles, canvas) = ai::graphic_styles(data, large_canvas, names);
|
||||
if styles.is_empty() {
|
||||
return;
|
||||
}
|
||||
@@ -310,7 +337,7 @@ fn use_styles(data: &[u8], doc: &mut Document, large_canvas: bool, unit: f64, bo
|
||||
let boards = match boards {
|
||||
Some(b) => b,
|
||||
None => {
|
||||
read = ai::artboards(data).0;
|
||||
read = ai::artboards(data, &mut ai::Names::default()).0;
|
||||
&read
|
||||
}
|
||||
};
|
||||
@@ -336,12 +363,12 @@ fn use_styles(data: &[u8], doc: &mut Document, large_canvas: bool, unit: f64, bo
|
||||
/// symbols' art keeps the editing data's units, as in a document read from the layers: when
|
||||
/// [`use_styles`] draws the styles' strokes and effects larger (a file in larger units), linked art
|
||||
/// isn't scaled with them. Left as it is when `doc` has symbols already or the editing data has
|
||||
/// none this reads.
|
||||
fn use_symbols(data: &[u8], doc: &mut Document, own_palette: bool, warnings: &mut Vec<String>) {
|
||||
/// none this reads. `names` reads the symbols' names and keeps the notes on them.
|
||||
fn use_symbols(data: &[u8], doc: &mut Document, own_palette: bool, warnings: &mut Vec<String>, names: &mut ai::Names) {
|
||||
if !doc.symbols.is_empty() {
|
||||
return;
|
||||
}
|
||||
let Some(ai::Symbols { symbols, images, swatches }) = ai::symbols(data) else { return };
|
||||
let Some(ai::Symbols { symbols, images, swatches }) = ai::symbols(data, names) else { return };
|
||||
for (key, blob) in images {
|
||||
doc.images.entry(key).or_insert(blob);
|
||||
}
|
||||
@@ -414,14 +441,14 @@ fn board_scale(boards: &[(String, Rect)], doc: &Document, unit: f64) -> Option<f
|
||||
/// read (#1068); the page of the artboard at `active` (the active one) is the active artboard. Left
|
||||
/// as they are unless there are as many artboards as pages, each the size of its page in points,
|
||||
/// or, when `unit` is above 1, each the size of its page in units of `unit` points: then the layout
|
||||
/// is drawn `unit` times as large.
|
||||
fn place_pages(boards: &[(String, Rect)], active: Option<usize>, doc: &mut Document, unit: f64) {
|
||||
let Some(k) = board_scale(boards, doc, unit) else { return };
|
||||
/// is drawn `unit` times as large. Whether the pages took the artboards' names.
|
||||
fn place_pages(boards: &[(String, Rect)], active: Option<usize>, doc: &mut Document, unit: f64) -> bool {
|
||||
let Some(k) = board_scale(boards, doc, unit) else { return false };
|
||||
for ((name, _), a) in boards.iter().zip(&mut doc.artboards) {
|
||||
a.name.clone_from(name);
|
||||
}
|
||||
doc.opened_artboard = active_page(active, doc);
|
||||
let [(_, first), _, ..] = boards else { return };
|
||||
let [(_, first), _, ..] = boards else { return true };
|
||||
// Art space (y up) → the document, the first artboard's top left at the origin, as `read` has it,
|
||||
// `k` points a unit.
|
||||
let to_doc = Affine::new([k, 0.0, 0.0, -k, -first.x0 * k, first.y1 * k]);
|
||||
@@ -433,6 +460,7 @@ fn place_pages(boards: &[(String, Rect)], active: Option<usize>, doc: &mut Docum
|
||||
for (a, v) in doc.artboards.iter_mut().zip(&moves) {
|
||||
a.rect = a.rect + *v;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// The id of the page of `doc` (a `.ai` read as its PDF part: a page per artboard) for the artboard
|
||||
@@ -464,19 +492,25 @@ fn place_art(layer: &mut Node, pages: &[Rect], moves: &[Vec2]) {
|
||||
/// A `.ai` saved without its PDF part (its pages show only a placeholder) from its editing copy
|
||||
/// alone (`private`, the joined `AIPrivateData` streams) → the document and the import's notes.
|
||||
/// Editing data written on a large canvas comes in at its declared scale: no page holds the size.
|
||||
/// Names that aren't UTF-8 are read as Windows-1252 ([`ai_alone_with`]).
|
||||
pub fn ai_alone(private: &[u8]) -> Result<(Document, Vec<String>), String> {
|
||||
ai_alone_with(private, ai::NameEncoding::default())
|
||||
}
|
||||
|
||||
/// [`ai_alone`], with the names that aren't UTF-8 read in `names`.
|
||||
pub fn ai_alone_with(private: &[u8], names: ai::NameEncoding) -> Result<(Document, Vec<String>), String> {
|
||||
let data = ai::decode_private(private)?;
|
||||
build_from(ai::read(&data, true)?, &data, None, Page::Artboard, false, false, 1.0)
|
||||
build_from(ai::read_in(&data, true, names)?, &data, None, Page::Artboard, false, false, 1.0)
|
||||
}
|
||||
|
||||
/// [`ai_alone`] for a `.ai` whose PDF part can't be read, its first page `page` (width and height)
|
||||
/// points large in units of `unit` points (its `UserUnit`): editing data whose first artboard, or
|
||||
/// whose art's box, has the page's size in those units, and not in points, comes in `unit` times as
|
||||
/// large, as [`layered_ai`] reads it. A page turned a quarter (`/Rotate 90`) is measured either
|
||||
/// way round.
|
||||
pub fn ai_alone_on_page(private: &[u8], page: (f64, f64), unit: f64) -> Result<(Document, Vec<String>), String> {
|
||||
/// way round. `names`: the encoding of names that aren't UTF-8.
|
||||
pub fn ai_alone_on_page(private: &[u8], page: (f64, f64), unit: f64, names: ai::NameEncoding) -> Result<(Document, Vec<String>), String> {
|
||||
let data = ai::decode_private(private)?;
|
||||
build_on_page(&data, page, unit)
|
||||
build_on_page(&data, page, unit, names)
|
||||
}
|
||||
|
||||
/// Does the editing data (or a program in the legacy format) have layers?
|
||||
@@ -499,15 +533,16 @@ fn editing_copy(ps: &[u8]) -> Option<Result<Cow<'_, [u8]>, String>> {
|
||||
/// but whose program has no layers (Illustrator 3 had none; image editors still export their
|
||||
/// paths so, storytold/photocraft#6036) is read with its art on one layer. `None` when the program
|
||||
/// has no layers and isn't in the format: other PostScript isn't read as the format's operators.
|
||||
pub(in super::super) fn program_alone(ps: &[u8], illustrator: bool) -> Option<Result<(Document, Vec<String>), String>> {
|
||||
/// `names`: the encoding of names that aren't UTF-8.
|
||||
pub(in super::super) fn program_alone(ps: &[u8], illustrator: bool, names: ai::NameEncoding) -> Option<Result<(Document, Vec<String>), String>> {
|
||||
if ai::has_eps_data(ps) {
|
||||
return None;
|
||||
}
|
||||
if has_layers(ps) {
|
||||
return Some(build(ps, None, Page::Art, false, false, 1.0));
|
||||
return Some(build(ps, None, Page::Art, false, false, 1.0, names));
|
||||
}
|
||||
let program = illustrator.then(|| one_layer(ps)).flatten()?;
|
||||
Some(build(&program, None, Page::Art, false, false, 1.0))
|
||||
Some(build(&program, None, Page::Art, false, false, 1.0, names))
|
||||
}
|
||||
|
||||
/// `ps` with its art (from its `%%EndSetup` to its `%%PageTrailer`, else its `%%Trailer`, else its
|
||||
|
||||
@@ -59,7 +59,7 @@ pub(super) fn make_slots(
|
||||
to_doc: Affine,
|
||||
warn: &mut Vec<String>,
|
||||
) -> Vec<Option<Made>> {
|
||||
let mut taller = 0;
|
||||
let (mut taller, mut deeper, mut tabs_left_out) = (0, 0, false);
|
||||
let made = infos
|
||||
.iter()
|
||||
.enumerate()
|
||||
@@ -67,6 +67,7 @@ pub(super) fn make_slots(
|
||||
let t = template?;
|
||||
let story = stories.get(k)?.as_ref()?;
|
||||
let mut node = story.node(NodeId(0), info.frame, t, to_doc)?;
|
||||
tabs_left_out |= story.tabs_left_out();
|
||||
let mut region = story.region(t, to_doc);
|
||||
// The first line where the file has it, in the text document's frame (that of a
|
||||
// copied object is its original's, as its lines are).
|
||||
@@ -80,6 +81,11 @@ pub(super) fn make_slots(
|
||||
{
|
||||
taller += 1;
|
||||
}
|
||||
if let NodeKind::Text(text) = &mut node.kind
|
||||
&& story.fit_last_lines(text)
|
||||
{
|
||||
deeper += 1;
|
||||
}
|
||||
Some((Box::new(node), region))
|
||||
})
|
||||
.collect();
|
||||
@@ -88,6 +94,14 @@ pub(super) fn make_slots(
|
||||
"area type in frames too short for a line of the font it shows in got taller frames ({taller}): their type wouldn't show otherwise"
|
||||
));
|
||||
}
|
||||
if deeper > 0 {
|
||||
warn.push(format!(
|
||||
"area type whose last lines the file sets in frames too short for them here got taller frames ({deeper}): those lines wouldn't show otherwise"
|
||||
));
|
||||
}
|
||||
if tabs_left_out {
|
||||
warn.push(crate::import::ate::TABS_LEFT_OUT.into());
|
||||
}
|
||||
made
|
||||
}
|
||||
|
||||
|
||||
@@ -1411,6 +1411,89 @@ fn an_ai_file_without_layers_keeps_the_gradients_of_its_palette_unlinked() {
|
||||
assert_eq!(g.gradient.stops.len(), 2);
|
||||
}
|
||||
|
||||
/// A file that comes in as its PDF part reads the palette's names that aren't UTF-8 in the encoding
|
||||
/// picked, with the notes on them; a layer name that isn't UTF-8, in layers that aren't used, gets
|
||||
/// none.
|
||||
#[test]
|
||||
fn an_ai_file_that_comes_in_as_its_pdf_part_notes_its_palette_names_in_a_legacy_encoding() {
|
||||
let image = "%AI5_File:\n%AI5_BeginRaster\n() 1 XG\n/DeviceGray XN\n[ 1 0 0 1 0 100 ] 6000 6000 0 Xh\n\
|
||||
[ 1 0 0 1 0 100 ] 0 0 6000 6000 6000 6000 8 1 0 0 1 0 4 4 0 0\n%%BeginData: 1\rXI\n\u{0}%%EndData\r\nXH\r\n%AI5_EndRaster\r\nN";
|
||||
// 빨강 (red) in code page 949, for the group and its ink; 그라 for the layer.
|
||||
let palette = PALETTE.replace("Inks", r"\273\241\260\255").replace("Red ink", r"\273\241\260\255 ink");
|
||||
let art = native(&format!("{palette}{}", layer(r"\261\327\266\363", true, &format!("{}\n{image}", square(10, 10)))));
|
||||
// An image past 2^25 pixels isn't read here, and the page has no art of its own in its box.
|
||||
let (d, warnings, read) = crate::import::ai::with_image_limits(1 << 26, 1 << 25, 512 << 20, || {
|
||||
crate::layered_ai_from(crate::AiLayers::decode(&private(&art)), pdf_part(10.0, 86.0), vec![], false, true, 1.0, crate::NameEncoding::Korean)
|
||||
});
|
||||
assert!(!read, "the PDF part is used: {warnings:?}");
|
||||
let groups: Vec<&str> = d.swatch_groups.iter().map(|g| g.name.as_str()).collect();
|
||||
assert_eq!(groups, ["빨강"]);
|
||||
assert!(d.swatch("빨강 ink").is_some_and(|s| s.spot));
|
||||
let notes: Vec<&String> = warnings.iter().filter(|w| w.contains("isn't UTF-8")).collect();
|
||||
assert_eq!(notes.len(), 2, "{warnings:?}");
|
||||
assert!(notes.iter().all(|n| n.contains("windows-949") && !n.contains("그라")), "{notes:?}");
|
||||
}
|
||||
|
||||
/// A library without layers reads the names of its brushes, graphic styles, symbols, variables and
|
||||
/// data sets that aren't UTF-8 in the encoding picked, with a note on each name it brings in.
|
||||
#[test]
|
||||
fn an_ai_library_without_layers_reads_its_names_in_a_legacy_encoding() {
|
||||
// 빨강 and 그라 in code page 949.
|
||||
let (red, gra) = (r"\273\241\260\255", r"\261\327\266\363");
|
||||
let art = format!("%AI8_BeginBrushPattern\n({gra})\n0 0 m\n4 0 L\n4 4 L\nf\n%AI8_EndBrushPattern\n");
|
||||
let spray = format!(
|
||||
"%AI8_BeginPluginObject\n(Adobe Scatter Brush Tool)\n({red})\n(2 /{gra}/ 5 1 0 0 / 0 0.5 1.5 1 1.2 2 0 -0.25 0.25 2 -45 30 1 1 0) .\n%AI8_EndPluginObject\n"
|
||||
);
|
||||
let order = format!(
|
||||
"%AI8_BeginPluginObject\n(Adobe Brush Manager Order)\n(Adobe Brush Manager Order)\n( Adobe Scatter Brush Tool/ {red}/) .\n%AI8_EndPluginObject\n"
|
||||
);
|
||||
let styles =
|
||||
format!("%AI9_BeginArtStyles\n{}%AI9_EndArtStyles\n%AI9_BeginArtStyleList\n({red})\n%AI9_EndArtStyleList\n", stroke_art_style(red, 1.0, ""));
|
||||
let symbols = format!("%AI5_Begin_NonPrinting\n{}%AI5_End_NonPrinting--\n", symbol_def(gra, &symbol_square(-2.0, -2.0, 2.0, 2.0), 1));
|
||||
let variables = vectorcraft_testkit::ai::variable_library(&["QVARQ"], &["QSETQ"]).replace("QVARQ", red).replace("QSETQ", gra);
|
||||
let library = format!(
|
||||
"%!PS-Adobe-3.0 \n%%BoundingBox: 0 0 100 100\n%%BeginSetup\n{art}{order}{spray}{styles}{symbols}{variables}%%EndSetup\n%%PageTrailer\n%%Trailer\n"
|
||||
);
|
||||
let (d, warnings, read) = crate::layered_ai_from(
|
||||
crate::AiLayers::decode(&private(&library)),
|
||||
pdf_part(10.0, 86.0),
|
||||
vec![],
|
||||
false,
|
||||
true,
|
||||
1.0,
|
||||
crate::NameEncoding::Korean,
|
||||
);
|
||||
assert!(!read, "{warnings:?}");
|
||||
assert_eq!(vectorcraft_brush::library(&d).iter().map(|b| b.name.as_str()).collect::<Vec<_>>(), ["빨강"], "{warnings:?}");
|
||||
assert_eq!(d.graphic_styles.iter().map(|g| g.name.as_str()).collect::<Vec<_>>(), ["빨강"], "{warnings:?}");
|
||||
assert_eq!(d.symbols.iter().map(|s| s.name.as_str()).collect::<Vec<_>>(), ["그라"], "{warnings:?}");
|
||||
assert_eq!(d.variables.variables.iter().map(|v| v.name.as_str()).collect::<Vec<_>>(), ["빨강"], "{warnings:?}");
|
||||
assert_eq!(d.variables.datasets.iter().map(|s| s.name.as_str()).collect::<Vec<_>>(), ["그라"], "{warnings:?}");
|
||||
let notes: Vec<&String> = warnings.iter().filter(|w| w.contains("isn't UTF-8") || w.contains("aren't UTF-8")).collect();
|
||||
assert_eq!(notes.len(), 2, "{warnings:?}");
|
||||
assert!(notes.iter().all(|n| n.contains("windows-949")), "{notes:?}");
|
||||
}
|
||||
|
||||
/// A pattern of a file without layers that takes a free name beside a pattern of the PDF part has
|
||||
/// a note on the name it was read under.
|
||||
#[test]
|
||||
fn a_renamed_pattern_of_a_file_without_layers_has_a_note_on_its_legacy_name() {
|
||||
// 빨강 in code page 949.
|
||||
let red = r"\273\241\260\255";
|
||||
let tile = format!("%AI3_BeginPattern: ({red})\n({red}) 0 0 4 4\n%_0 0 0 1 k\n%_1 1 m\n%_3 1 L\n%_3 3 L\n%_1 3 L\n%_f\nE\n%AI3_EndPattern\n");
|
||||
let palette = format!("%AI5_BeginPalette\n0 0 Pb\n({red}) 0 0 1 1 0 0 0 0 0 [1 0 0 1 0 0] p\n(Tile)\nPc\nPB\n%AI5_EndPalette\n");
|
||||
let art = native(&format!("{tile}{palette}"));
|
||||
let mut part = pdf_part(10.0, 86.0);
|
||||
part.patterns.push(vectorcraft_doc::PatternDef::new("빨강", vec![]));
|
||||
let (d, warnings, read) =
|
||||
crate::layered_ai_from(crate::AiLayers::decode(&private(&art)), part, vec![], false, true, 1.0, crate::NameEncoding::Korean);
|
||||
assert!(!read, "{warnings:?}");
|
||||
assert!(d.pattern("빨강 2").is_some(), "{:?}", d.patterns.iter().map(|p| &p.name).collect::<Vec<_>>());
|
||||
let notes: Vec<&String> = warnings.iter().filter(|w| w.contains("isn't UTF-8")).collect();
|
||||
assert_eq!(notes.len(), 1, "{warnings:?}");
|
||||
assert!(notes[0].contains("`빨강`"), "{notes:?}");
|
||||
}
|
||||
|
||||
/// A `.ai` pattern library (a palette of pattern swatches and no layers) whose PDF part defines no
|
||||
/// pattern gets the patterns its editing data defines with the palette's pattern swatches.
|
||||
#[test]
|
||||
|
||||
@@ -44,8 +44,8 @@ mod tiff;
|
||||
|
||||
pub use ai_editing::{AiEditingOptions, AiEditingOutput, CREATOR_VERSION, export_ai_editing, private_data as ai_private_data};
|
||||
pub use import::{
|
||||
AiLayers, Imported, POSTSCRIPT_ERRORS, ai_alone, ai_alone_on_page, ai_layers_alone, ai_opened_artboard, family_style, import, import_trusting,
|
||||
import_with, is_loss, layered_ai, layered_ai_from, page,
|
||||
AiLayers, Imported, NameEncoding, POSTSCRIPT_ERRORS, ai_alone, ai_alone_on_page, ai_alone_with, ai_layers_alone, ai_opened_artboard,
|
||||
family_style, import, import_names, import_trusting, import_with, is_loss, layered_ai, layered_ai_from, page,
|
||||
};
|
||||
pub use legacy_ai::{HiddenObjects, LegacyAiOptions, LegacyAiOutput, export_legacy_ai, writes_image_mask};
|
||||
pub use print::{PrintJob, PrintPage, print};
|
||||
|
||||
@@ -173,6 +173,8 @@ impl Headless {
|
||||
UiRequest::Place(p) => {
|
||||
self.session.execute("file.place", &p).map_err(|e| e.to_string())?;
|
||||
}
|
||||
// The host keeps its view's artboard on a press, as for the presses it hands over.
|
||||
UiRequest::HeldPress { .. } => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -204,10 +206,11 @@ impl Headless {
|
||||
};
|
||||
let reqs = self.session.pointer(&ev, self.view).map_err(|e| e.to_string())?;
|
||||
self.apply_ui_requests(reqs, &mut requests)?;
|
||||
// With no frames to show the highlight in later, a hover waits for the work the tool
|
||||
// runs on another thread.
|
||||
if kind == PointerKind::Move && self.session.tool_waiting() {
|
||||
self.session.tool_poll(self.view, true).map_err(|e| e.to_string())?;
|
||||
// With no frames to show the highlight or apply an edit in later, each event waits for
|
||||
// the work the tool runs on another thread (a hover's map, a release's merge).
|
||||
if self.session.tool_waiting() {
|
||||
let reqs = self.session.tool_poll(self.view, true).map_err(|e| e.to_string())?;
|
||||
self.apply_ui_requests(reqs, &mut requests)?;
|
||||
}
|
||||
let hold = PointerEvent::json_hold(e);
|
||||
if hold > 0.0 {
|
||||
|
||||
@@ -498,6 +498,15 @@ fn headless_hover_waits_for_the_shape_builder_map() {
|
||||
assert!(!r.is_error, "{r:?}");
|
||||
assert!(!h.session.tool_waiting());
|
||||
assert!(!h.session.overlays(h.view).is_empty(), "the region under the pointer is highlighted");
|
||||
// A click's reply comes once the merge the tool computes on another thread is applied, with
|
||||
// the selection after it.
|
||||
let click = json!({"events": [{"kind": "down", "x": 115, "y": 110}, {"kind": "up", "x": 115, "y": 110}]});
|
||||
let r = crate::call_tool(&mut h, "pointer_gesture", &click);
|
||||
assert!(!r.is_error, "{r:?}");
|
||||
assert!(!h.session.tool_waiting() && !h.session.tool_editing());
|
||||
let text: String = r.content.iter().filter_map(|c| c["text"].as_str()).collect();
|
||||
let reply: Value = serde_json::from_str(&text).unwrap();
|
||||
assert_eq!(reply["selection"].as_array().map(Vec::len), Some(41), "the overlap and the 40 squares, two of them cut: {reply}");
|
||||
}
|
||||
|
||||
/// inspect_document reads back the paint type's characters show, as add_text and set_paint give it.
|
||||
|
||||
@@ -44,6 +44,38 @@ fn an_option_no_format_takes_is_an_error() {
|
||||
assert!(!r.is_error, "{r:?}");
|
||||
}
|
||||
|
||||
/// `app.save`, `file.save` and `file.exportForScreens` refuse a key no format takes before they
|
||||
/// write anything.
|
||||
#[test]
|
||||
fn a_save_or_screens_option_no_format_takes_is_an_error() {
|
||||
let dir = std::env::temp_dir().join(format!("vc-mcp-save-options-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let mut h = Headless::new();
|
||||
h.call("engine.execute", json!({"command": "file.new", "params": {"width": 50, "height": 30}})).unwrap();
|
||||
let pdf = dir.join("a.pdf").to_string_lossy().into_owned();
|
||||
for (params, named) in [
|
||||
(json!({"path": pdf, "noSuchOption": true}), "noSuchOption"),
|
||||
(json!({"path": pdf, "options": {"marks": {"useDocumentBleed": true}}}), "options.marks.useDocumentBleed"),
|
||||
] {
|
||||
let e = h.call("app.save", params.clone()).unwrap_err();
|
||||
assert!(e.contains(named), "app.save: {e}");
|
||||
let e = h.call("engine.execute", json!({"command": "file.save", "params": params})).unwrap_err();
|
||||
assert!(e.contains(named), "file.save: {e}");
|
||||
}
|
||||
let folder = dir.join("screens").to_string_lossy().into_owned();
|
||||
for (params, named) in [
|
||||
(json!({"folder": folder, "noSuchOption": true}), "noSuchOption"),
|
||||
(json!({"folder": folder, "formats": [{"format": "pdf", "marks": {"useDocumentBleed": true}}]}), "formats[0].marks.useDocumentBleed"),
|
||||
] {
|
||||
let e = h.call("engine.execute", json!({"command": "file.exportForScreens", "params": params})).unwrap_err();
|
||||
assert!(e.contains(named), "file.exportForScreens: {e}");
|
||||
}
|
||||
assert_eq!(std::fs::read_dir(&dir).unwrap().count(), 0, "nothing was written");
|
||||
h.call("app.save", json!({"path": pdf})).unwrap();
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raster_export_uses_document_resolution_unless_overridden() {
|
||||
let mut h = Headless::new();
|
||||
|
||||
@@ -39,7 +39,7 @@ use breaking::tab_advance;
|
||||
use breaking::{break_line, candidates};
|
||||
#[cfg(test)]
|
||||
pub(crate) use driver::layout_faces_per_call;
|
||||
pub use driver::{decorations, fit_first_line, layout, layout_with, scaled};
|
||||
pub use driver::{decorations, fit_first_line, fit_source_lines, layout, layout_with, scaled};
|
||||
use vertical::{TcyStyle, stands_upright, tate_chu_yoko, upright_cell, upright_centre, upright_extent, whole_character_widths};
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -62,6 +62,38 @@ pub fn fit_first_line(db: &FontDb, t: &mut TextObject) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Area type whose source lays out `lines` lines in its frame, more than fit here: a font that isn't
|
||||
/// available shows in the fallback font, whose lines may reach lower, and the source may set a last
|
||||
/// line whose descent passes the frame's bottom, which isn't drawn here. For importers: the frame is
|
||||
/// made taller, from its bottom, by its lines' deepest descent plus 0.05 pt, when that lays out
|
||||
/// more of the source's lines and no more than it has. Horizontal type only. Whether it was.
|
||||
pub fn fit_source_lines(db: &FontDb, t: &mut TextObject, lines: usize) -> bool {
|
||||
let TextKind::Area { frame } = &t.kind else { return false };
|
||||
if t.vertical {
|
||||
return false;
|
||||
}
|
||||
let Some(b) = frame.bounds().filter(|b| b.height() > 1e-6) else { return false };
|
||||
let laid = layout(db, t);
|
||||
let have = laid.lines.len();
|
||||
if !laid.overflow || have == 0 || have >= lines {
|
||||
return false;
|
||||
}
|
||||
// The deepest descent of its lines (a little more, for the rounding of the layout).
|
||||
let Some(descent) = laid.lines.iter().map(|l| l.descent).reduce(f64::max).filter(|d| d.is_finite() && *d > 0.0) else { return false };
|
||||
let by = (b.height() + descent + 0.05) / b.height();
|
||||
if !(by.is_finite() && by > 1.0) {
|
||||
return false;
|
||||
}
|
||||
let taller = frame.transformed(Affine::translate((0.0, b.y0)) * Affine::scale_non_uniform(1.0, by) * Affine::translate((0.0, -b.y0)));
|
||||
let short = std::mem::replace(&mut t.kind, TextKind::Area { frame: taller });
|
||||
let now = layout(db, t).lines.len();
|
||||
if now > have && now <= lines {
|
||||
return true;
|
||||
}
|
||||
t.kind = short;
|
||||
false
|
||||
}
|
||||
|
||||
/// The underline and strikethrough bars of `t` laid out as `layout` (#847): per run and line, a
|
||||
/// bar from the stretch's first glyph to its last one's advance, placed and sized by the font's
|
||||
/// own underline and strikeout metrics through the glyph's transform (so the size, baseline shift
|
||||
|
||||
@@ -410,6 +410,9 @@ struct LineJustification {
|
||||
start_x: f64,
|
||||
after: Vec<Option<usize>>,
|
||||
kashidas: Vec<(usize, f64)>,
|
||||
/// Right-aligned area type: the line's last tab, which takes the text after it to the right
|
||||
/// edge (the text before it sits at its stops, from the left edge).
|
||||
last_tab: Option<usize>,
|
||||
}
|
||||
|
||||
fn run_paragraph_lines(cx: &mut Ctx<'_>, pen: &mut Pen<'_>, t: &TextObject, mut paragraph: ParagraphData<'_, '_>) -> bool {
|
||||
@@ -464,6 +467,9 @@ fn run_paragraph_lines(cx: &mut Ctx<'_>, pen: &mut Pen<'_>, t: &TextObject, mut
|
||||
true
|
||||
}
|
||||
|
||||
/// The geometry of the line of `paragraph` from glyph `index`, placed at `position`: where it
|
||||
/// ends with its trailing spaces trimmed, its hyphen, its room and margins, the glyphs that hang or
|
||||
/// stay out of justification, and whether it is the paragraph's last line.
|
||||
fn prepare_line_geometry(cx: &Ctx<'_>, t: &TextObject, paragraph: &ParagraphData<'_, '_>, position: LinePosition, index: usize) -> LineGeometry {
|
||||
let para = paragraph.para;
|
||||
let sg = ¶graph.sg;
|
||||
@@ -571,7 +577,11 @@ fn prepare_line_geometry(cx: &Ctx<'_>, t: &TextObject, paragraph: &ParagraphData
|
||||
// Justification adds nothing to the list marker's glyphs.
|
||||
let mut held = held;
|
||||
held.extend(index..paragraph.marker.min(body));
|
||||
let last_of_para = position.end >= n || position.end.checked_sub(1).and_then(|i| sg.get(i)).is_some_and(|g| g.ch == '\u{2028}');
|
||||
// A line a soft return ends is justified as a wrapped one is: only the paragraph's last line
|
||||
// keeps the alignment of Justify Left, Center or Right. A paragraph that ends in a soft return
|
||||
// ends with the empty line after it (`run_paragraph_lines`).
|
||||
let soft_return = position.end > index && sg.get(position.end - 1).is_some_and(|g| g.ch == '\u{2028}');
|
||||
let last_of_para = position.end >= n && !soft_return;
|
||||
LineGeometry {
|
||||
position,
|
||||
index,
|
||||
@@ -631,6 +641,9 @@ fn flow_line_flex(glyph: usize, flex: &[Flex], held: &[usize], hung: &[usize]) -
|
||||
value
|
||||
}
|
||||
|
||||
/// How `line` of `paragraph` is aligned: where it starts, what justification adds to its spaces,
|
||||
/// gaps and glyphs, its kashidas, and, in right-aligned area type, its last tab, which takes the
|
||||
/// text after it to the right edge.
|
||||
fn justify_flow_line(cx: &Ctx<'_>, paragraph: &ParagraphData<'_, '_>, line: &LineGeometry) -> LineJustification {
|
||||
let para = paragraph.para;
|
||||
let sg = ¶graph.sg;
|
||||
@@ -718,7 +731,14 @@ fn justify_flow_line(cx: &Ctx<'_>, paragraph: &ParagraphData<'_, '_>, line: &Lin
|
||||
}
|
||||
}
|
||||
let position = &line.position;
|
||||
let start_x = if justify || pushed_in {
|
||||
// Right-aligned area type with a tab: the text before the last tab sits at its stops, from the
|
||||
// left edge, and the text after it against the right edge, as Illustrator's own layout in a
|
||||
// user's `.ai` sets a price list. Centred and justified lines are aligned as a whole.
|
||||
let last_tab = (para.justify == Justify::Right && !justify && !paragraph.rtl && paragraph.regions.is_some())
|
||||
// A tab ending the line counts: its text sits at the left edge, the tab up to the right one.
|
||||
.then(|| (line.index..line.position.end).rev().find(|&j| sg.get(j).is_some_and(|g| g.ch == '\t' && g.len > 0)))
|
||||
.flatten();
|
||||
let start_x = if justify || pushed_in || last_tab.is_some() {
|
||||
line.ax0 - line.opt_l
|
||||
} else if paragraph.regions.is_none() {
|
||||
match align {
|
||||
@@ -733,9 +753,43 @@ fn justify_flow_line(cx: &Ctx<'_>, paragraph: &ParagraphData<'_, '_>, line: &Lin
|
||||
_ => line.ax1 + line.opt_r - width,
|
||||
}
|
||||
};
|
||||
LineJustification { per_space, per_gap, per_cjk, squeeze, fit, start_x, after, kashidas }
|
||||
LineJustification { per_space, per_gap, per_cjk, squeeze, fit, start_x, after, kashidas, last_tab }
|
||||
}
|
||||
|
||||
/// The advance and leader of tab `glyph_index` of `line`, at pen position `x`: up to its stop
|
||||
/// ([`tab_advance`], measured from `tab_origin` less `tab_shift`), or, for the last tab of
|
||||
/// right-aligned area type ([`LineJustification::last_tab`]), up to where the rest of the line
|
||||
/// ends on the right edge. The tab after a list marker keeps the width `prepend_marker` gave it
|
||||
/// (`advance`).
|
||||
fn tab_glyph<'p>(
|
||||
paragraph: &'p ParagraphData<'_, '_>,
|
||||
line: &LineGeometry,
|
||||
justification: &LineJustification,
|
||||
glyph_index: usize,
|
||||
x: f64,
|
||||
(tab_origin, tab_shift): (f64, f64),
|
||||
advance: f64,
|
||||
) -> (f64, &'p str) {
|
||||
let sg = ¶graph.sg;
|
||||
// The tab of a list marker keeps the width `prepend_marker` gave it.
|
||||
if !sg.get(glyph_index).is_some_and(|g| g.len > 0) {
|
||||
return (advance, "");
|
||||
}
|
||||
let (advance, leader) = tab_advance(¶graph.para.tabs, tab_origin, x - tab_shift, sg.get(glyph_index + 1..line.trimmed).unwrap_or_default());
|
||||
if justification.last_tab != Some(glyph_index) {
|
||||
return (advance, leader);
|
||||
}
|
||||
// The width of what follows up to the line's end (nothing, when the tab ends the line), with
|
||||
// the hyphen a hyphenated line ends with.
|
||||
let after = sg.get(glyph_index + 1..line.trimmed).unwrap_or_default();
|
||||
let hyphen = line.hyphen.as_ref().map_or(0.0, |g| g.adv);
|
||||
let rest = if after.is_empty() { 0.0 } else { after.iter().map(|g| g.adv).sum::<f64>() - line.end_trim + hyphen };
|
||||
((line.ax1 + line.opt_r - rest - x).max(0.0), leader)
|
||||
}
|
||||
|
||||
/// Lay out `line` of `paragraph` as `justification` aligns it: each glyph placed along the
|
||||
/// baseline (tabs as [`tab_glyph`] sets them), its hyphen, and the line's record, then the pen
|
||||
/// moved on past it.
|
||||
fn emit_flow_line(cx: &mut Ctx<'_>, pen: &mut Pen<'_>, paragraph: &ParagraphData<'_, '_>, line: &LineGeometry, justification: &LineJustification) {
|
||||
let para = paragraph.para;
|
||||
let sg = ¶graph.sg;
|
||||
@@ -775,10 +829,7 @@ fn emit_flow_line(cx: &mut Ctx<'_>, pen: &mut Pen<'_>, paragraph: &ParagraphData
|
||||
let mut scale = 1.0;
|
||||
let mut leader = "";
|
||||
if glyph.ch == '\t' {
|
||||
// The tab of a list marker keeps the width `prepend_marker` gave it.
|
||||
if glyph.len > 0 {
|
||||
(advance, leader) = tab_advance(¶.tabs, tab_origin, x - tab_shift, &sg[glyph_index + 1..trimmed.max(glyph_index + 1)]);
|
||||
}
|
||||
(advance, leader) = tab_glyph(paragraph, line, justification, glyph_index, x, (tab_origin, tab_shift), advance);
|
||||
} else if glyph_index < body {
|
||||
let flex = flow_line_flex(glyph_index, ¶graph.flex, &line.held, &line.hung);
|
||||
if is_word_space(glyph) {
|
||||
|
||||
@@ -47,7 +47,7 @@ pub use svg_glyph::{SvgGlyphReader, set_svg_glyph_reader};
|
||||
|
||||
pub use kept::{KeptLayoutsFrame, LayoutStamp, keep_layout, take_kept_layout};
|
||||
use kurbo::{Affine, BezPath, Point, Rect, Shape, Vec2};
|
||||
pub use layout::{decorations, fit_first_line, layout, layout_with, scaled};
|
||||
pub use layout::{decorations, fit_first_line, fit_source_lines, layout, layout_with, scaled};
|
||||
pub use vectorcraft_doc::TextObject;
|
||||
|
||||
pub use vectorcraft_doc::{AreaFit, FirstBaseline, TextFlow, VerticalAlign};
|
||||
|
||||
@@ -306,6 +306,39 @@ fn area_alignment_and_justify() {
|
||||
assert!((l.lines[0].x1 - frame.x1).abs() < 1e-6);
|
||||
}
|
||||
|
||||
/// A source that sets a last line whose descent passes its frame's bottom: the frame grows from its
|
||||
/// bottom by its lines' deepest descent plus 0.05 pt, so that line shows, and only as many lines as
|
||||
/// the source has.
|
||||
#[test]
|
||||
fn fit_source_lines_keeps_the_last_lines_the_source_sets() {
|
||||
let text = "one\ntwo\nthree";
|
||||
let tall = layout(db(), &area(text, style(12.0), Rect::new(0.0, 0.0, 200.0, 400.0), Justify::Left));
|
||||
let third = &tall.lines[2];
|
||||
// The third baseline is in the frame, its descent isn't.
|
||||
let frame = Rect::new(0.0, 0.0, 200.0, third.baseline + third.descent / 2.0);
|
||||
let mut t = area(text, style(12.0), frame, Justify::Left);
|
||||
let short = layout(db(), &t);
|
||||
assert!(short.overflow && short.lines.len() == 2);
|
||||
// A source with no more lines than fit leaves the frame as it is.
|
||||
assert!(!fit_source_lines(db(), &mut t, 2));
|
||||
assert_eq!(layout(db(), &t).lines.len(), 2);
|
||||
assert!(fit_source_lines(db(), &mut t, 3));
|
||||
let fitted = layout(db(), &t);
|
||||
assert!(!fitted.overflow && fitted.lines.len() == 3);
|
||||
let TextKind::Area { frame: grown } = &t.kind else { panic!("area type") };
|
||||
let grown = grown.bounds().unwrap();
|
||||
assert!(grown.y0 == frame.y0 && grown.y1 > frame.y1 && grown.y1 <= frame.y1 + third.descent + 0.1, "{grown:?}");
|
||||
// Fitted, nothing more to do.
|
||||
assert!(!fit_source_lines(db(), &mut t, 3));
|
||||
// More than a descent short: a line the source can't have set in its frame stays out.
|
||||
let frame = Rect::new(0.0, 0.0, 200.0, tall.lines[1].baseline + tall.lines[1].descent + 1.0);
|
||||
let mut t = area(text, style(12.0), frame, Justify::Left);
|
||||
assert!(!fit_source_lines(db(), &mut t, 3));
|
||||
// Point type and vertical type aren't fitted.
|
||||
let mut p = point(text, style(12.0));
|
||||
assert!(!fit_source_lines(db(), &mut p, 9));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indents_and_paragraph_spacing() {
|
||||
let frame = Rect::new(0.0, 0.0, 200.0, 400.0);
|
||||
@@ -880,12 +913,67 @@ fn a_leading_tab_takes_its_width_in_the_line_and_the_justification() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Right-aligned area type with tabs: the text before the last tab sits at its stops, measured from
|
||||
/// the frame's left edge, and the text after the last tab against the right edge, as Illustrator's
|
||||
/// own layout in a user's `.ai` (used locally, not committed) sets a list of an item and two
|
||||
/// prices: with a right stop at 269.29 and a left one at 272.13, the item starts at 0, the first
|
||||
/// price ends at 269.29 and the second ends on the edge.
|
||||
#[test]
|
||||
fn right_aligned_area_type_sets_the_text_after_its_last_tab_against_the_edge() {
|
||||
use vectorcraft_doc::{TabAlign, TabStop};
|
||||
let stop = |position: f64, align: TabAlign| TabStop { position, align, leader: String::new(), align_on: '.' };
|
||||
let frame = Rect::new(0.0, 0.0, 336.0, 100.0);
|
||||
let mut t = area("Item\t12.50\t24.00", style(13.0), frame, Justify::Right);
|
||||
t.para.tabs = vec![stop(269.29, TabAlign::Right), stop(272.13, TabAlign::Left)];
|
||||
let lay = layout(db(), &t);
|
||||
let glyph = |byte: usize| lay.glyphs.iter().find(|g| g.byte == byte).unwrap();
|
||||
let end = |byte: usize| glyph(byte).origin.x + glyph(byte).advance;
|
||||
assert!(glyph(0).origin.x.abs() < 1e-6, "the item starts at the left edge: {}", glyph(0).origin.x);
|
||||
let first_price_end = "Item\t12.50".len() - 1;
|
||||
assert!((end(first_price_end) - 269.29).abs() < 1e-6, "the first price ends on its right stop: {}", end(first_price_end));
|
||||
let last = t.plain_text().len() - 1;
|
||||
assert!((end(last) - 336.0).abs() < 1e-6, "the last price ends on the edge: {}", end(last));
|
||||
// One tab: the text after it is against the edge, whatever its stop.
|
||||
let mut one = area("Another item\t8.00", style(13.0), frame, Justify::Right);
|
||||
one.para.tabs = t.para.tabs.clone();
|
||||
let lay = layout(db(), &one);
|
||||
let first = lay.glyphs.first().unwrap();
|
||||
let last = lay.glyphs.last().unwrap();
|
||||
assert!(
|
||||
first.origin.x.abs() < 1e-6 && (last.origin.x + last.advance - 336.0).abs() < 1e-6,
|
||||
"{} {}",
|
||||
first.origin.x,
|
||||
last.origin.x + last.advance
|
||||
);
|
||||
// A tab ending the line (a heading in the user's file): the text before it at the left edge,
|
||||
// the tab to the right edge.
|
||||
let lay = layout(db(), &area("Heading\t\nNext", style(13.0), frame, Justify::Right));
|
||||
assert!(lay.glyphs.first().unwrap().origin.x.abs() < 1e-6, "{}", lay.glyphs.first().unwrap().origin.x);
|
||||
let tab = lay.glyphs.iter().find(|g| g.byte == 7).unwrap();
|
||||
assert!((tab.origin.x + tab.advance - 336.0).abs() < 1e-6, "the tab ends at {}", tab.origin.x + tab.advance);
|
||||
// Text after the last tab that breaks with a hyphen: the hyphen ends on the edge too.
|
||||
let text = "A\tinternationalization";
|
||||
let mut hyphenated = area(text, style(13.0), Rect::new(0.0, 0.0, 100.0, 200.0), Justify::Right);
|
||||
hyphenated.para.hyphenate = true;
|
||||
hyphenated.para.composer = vectorcraft_doc::Composer::SingleLine;
|
||||
let lay = layout(db(), &hyphenated);
|
||||
let line = &lay.lines[0];
|
||||
assert!(line.end > 2 && line.end < text.len(), "the first line breaks inside the word: {line:?}");
|
||||
let last = lay.glyphs.get(line.glyph_end - 1).unwrap();
|
||||
assert!((last.origin.x + last.advance - 100.0).abs() < 1e-6, "the hyphen ends at {}", last.origin.x + last.advance);
|
||||
// Without a tab, the line is right aligned as a whole.
|
||||
let lay = layout(db(), &area("Name", style(13.0), frame, Justify::Right));
|
||||
assert!(lay.glyphs.first().unwrap().origin.x > 200.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_centred_or_right_aligned_line_sets_its_tabs_as_if_it_started_at_the_left() {
|
||||
use vectorcraft_doc::{TabAlign, TabStop};
|
||||
// "A<tab>B" with a stop at 100 pt is 100 pt plus B wide whatever the alignment: the whole line
|
||||
// moves, the gap between A and B stays 100 pt, and a right aligned line ends on the edge (#2457).
|
||||
for justify in [Justify::Center, Justify::Right, Justify::JustifyCenter, Justify::JustifyRight] {
|
||||
// (Right aligned area type sets the text after its last tab against the edge instead: see
|
||||
// `right_aligned_area_type_sets_the_text_after_its_last_tab_against_the_edge`.)
|
||||
for justify in [Justify::Center, Justify::JustifyCenter, Justify::JustifyRight] {
|
||||
let mut t = area("A\tB", style(12.0), Rect::new(0.0, 0.0, 200.0, 100.0), justify);
|
||||
t.para.tabs = vec![TabStop { position: 100.0, align: TabAlign::Left, leader: String::new(), align_on: '.' }];
|
||||
let lay = layout(db(), &t);
|
||||
|
||||
@@ -1970,14 +1970,28 @@ fn soft_return_breaks_line_without_new_paragraph() {
|
||||
assert_eq!(&t.plain_text()[l1.start..l1.end], "Line 2");
|
||||
}
|
||||
|
||||
/// A line ending in a soft return is justified as a wrapped line is: only the paragraph's last
|
||||
/// line keeps its alignment. Illustrator's own layout in a user's `.ai` (used locally, not
|
||||
/// committed) spreads such lines to the frame's edge.
|
||||
#[test]
|
||||
fn soft_return_in_justified_text_does_not_spread() {
|
||||
let text = "Short\u{2028}A much longer second line of text inside the frame.";
|
||||
let t = area(text, style(12.0), Rect::new(0.0, 0.0, 300.0, 200.0), Justify::JustifyLeft);
|
||||
let lay = layout(db(), &t);
|
||||
assert!(lay.lines.len() >= 2);
|
||||
let l0 = &lay.lines[0];
|
||||
assert!(l0.x1 - l0.x0 < 100.0, "short line ending with soft return is not justified: {}", l0.x1 - l0.x0);
|
||||
fn soft_return_in_justified_text_spreads_like_a_wrapped_line() {
|
||||
let frame = Rect::new(0.0, 0.0, 300.0, 200.0);
|
||||
let text = "A line of a few words\u{2028}and the last line.";
|
||||
for justify in [Justify::JustifyLeft, Justify::JustifyCenter, Justify::JustifyRight] {
|
||||
let lay = layout(db(), &area(text, style(12.0), frame, justify));
|
||||
assert_eq!(lay.lines.len(), 2);
|
||||
let (l0, l1) = (&lay.lines[0], &lay.lines[1]);
|
||||
assert!((l0.x0 - frame.x0).abs() < 1e-6 && (l0.x1 - frame.x1).abs() < 1e-6, "{justify:?}: {l0:?}");
|
||||
assert!(l1.x1 - l1.x0 < 200.0, "{justify:?}: the last line isn't justified: {l1:?}");
|
||||
// A soft return ending the paragraph: the empty line after it is the last one, so the line
|
||||
// it ends is justified too.
|
||||
let lay = layout(db(), &area("A line of a few words\u{2028}", style(12.0), frame, justify));
|
||||
let l0 = lay.lines.first().unwrap();
|
||||
assert!((l0.x0 - frame.x0).abs() < 1e-6 && (l0.x1 - frame.x1).abs() < 1e-6, "{justify:?}, trailing soft return: {l0:?}");
|
||||
}
|
||||
// Aligned type stays aligned.
|
||||
let lay = layout(db(), &area(text, style(12.0), frame, Justify::Left));
|
||||
assert!(lay.lines[0].x1 < frame.x1 - 100.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+261
-16
@@ -32,7 +32,7 @@ mod live_paint;
|
||||
mod lookup;
|
||||
mod map;
|
||||
|
||||
use cache::RegionCache;
|
||||
use cache::{BACKGROUND_SEGMENTS, CacheKey, RegionCache};
|
||||
#[cfg(test)]
|
||||
use live_paint::LpHover;
|
||||
use live_paint::lp_color;
|
||||
@@ -45,7 +45,10 @@ pub use lookup::{
|
||||
is_live_paint, leaf_shapes, live_paint_at, live_paint_takes, node_outline, outline_snap, path_contains, shape_builder_shapes, shapes_for,
|
||||
sources, visible_edge_near, visible_face_at,
|
||||
};
|
||||
pub use map::{BuilderMap, HATCH, HIGHLIGHT_RED, Hit, Touched, hatch, maps_built, sample_polyline, sorted_roots};
|
||||
pub use map::{
|
||||
BuilderMap, HATCH, HIGHLIGHT_RED, Hit, MergeGeometry, MergeInput, PreparedMerge, Rest, Touched, hatch, maps_built, merge_geometry, merge_inputs,
|
||||
merges_computed, sample_polyline, sorted_roots,
|
||||
};
|
||||
/// Small, Medium and Large gap lengths in points.
|
||||
pub const GAP_LENGTHS: [f64; 3] = [3.0, 6.0, 12.0];
|
||||
|
||||
@@ -169,6 +172,52 @@ pub struct ShapeBuilderTool {
|
||||
/// The pointer went more than [`CLICK_TOL_PX`] from the press during the drag, so the gesture
|
||||
/// is not a click.
|
||||
far: bool,
|
||||
/// The merge of the last gesture over a large selection, being computed on another thread.
|
||||
merging: Option<PendingMerge>,
|
||||
/// That merge once computed, for `shapeBuilder.merge` ([`Tool::shape_builder_merge`]).
|
||||
prepared: Option<Arc<PreparedMerge>>,
|
||||
/// A gesture made while the map of a large selection is being built on another thread.
|
||||
deferred: Option<Deferred>,
|
||||
}
|
||||
|
||||
/// A Shape Builder gesture made while the map of the selection was being built on another
|
||||
/// thread: the map key and the inputs it was made over, its pointer events, which [`Tool::poll`]
|
||||
/// replays once the map is there, and whether the release has come.
|
||||
struct Deferred {
|
||||
key: CacheKey,
|
||||
shapes: Vec<po::Shape>,
|
||||
events: Vec<PointerEvent>,
|
||||
released: bool,
|
||||
}
|
||||
|
||||
/// A Shape Builder merge being computed on another thread: the map key it is for (the document,
|
||||
/// its revision and the selection), the `shapeBuilder.merge` params that apply it, what it was
|
||||
/// computed from, and the channel the result arrives on.
|
||||
struct PendingMerge {
|
||||
key: CacheKey,
|
||||
params: Value,
|
||||
map: Arc<BuilderMap>,
|
||||
touched: Touched,
|
||||
gap: f64,
|
||||
inputs: Vec<MergeInput>,
|
||||
done: Receiver<MergeGeometry>,
|
||||
}
|
||||
|
||||
/// Computes [`merge_geometry`] on a new thread; None when no thread starts.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn spawn_merge(map: Arc<BuilderMap>, touched: Touched, gap: f64, inputs: Vec<MergeInput>) -> Option<Receiver<MergeGeometry>> {
|
||||
let (tx, done) = std::sync::mpsc::channel();
|
||||
let spawned = std::thread::Builder::new().name("vectorcraft-shape-builder-merge".into()).spawn(move || {
|
||||
// The tool may have dropped the receiver meanwhile (another tool, another document).
|
||||
let _ = tx.send(merge_geometry(&map, &touched, gap, &inputs));
|
||||
});
|
||||
spawned.is_ok().then_some(done)
|
||||
}
|
||||
|
||||
/// The web build has no threads: the merge runs in the command.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn spawn_merge(_map: Arc<BuilderMap>, _touched: Touched, _gap: f64, _inputs: Vec<MergeInput>) -> Option<Receiver<MergeGeometry>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// How close (screen px) the pointer must come to a line piece or an edge to delete it.
|
||||
@@ -213,6 +262,132 @@ impl ShapeBuilderTool {
|
||||
alt.then(|| cx.tol(LINE_TOL_PX))
|
||||
}
|
||||
|
||||
/// Starts computing the merge `params` describe on another thread when the map of the
|
||||
/// selection is current and has more than [`BACKGROUND_SEGMENTS`] segments; `false` when it
|
||||
/// did not (small selections, the web build), and the command computes it.
|
||||
fn start_merge(&mut self, cx: &ToolContext, params: &Value) -> bool {
|
||||
let key = RegionCache::key_for(cx, self.opts.open_filled_as_closed);
|
||||
if cfg!(target_arch = "wasm32") || params.get("splitStroke").is_some() || self.cache.key.as_ref() != Some(&key) {
|
||||
return false;
|
||||
}
|
||||
let map = Arc::clone(&self.cache.map);
|
||||
let segments: usize = map.shapes.iter().map(|s| s.path.subpaths.iter().map(|sp| sp.segment_count()).sum::<usize>()).sum();
|
||||
if segments <= BACKGROUND_SEGMENTS {
|
||||
return false;
|
||||
}
|
||||
// What the command reads from its params, read the same way.
|
||||
let num = |v: &Value| v.as_f64().unwrap_or(f64::NAN);
|
||||
let pts: Vec<Point> = params["points"].as_array().map(|a| a.iter().map(|q| Point::new(num(&q[0]), num(&q[1]))).collect()).unwrap_or_default();
|
||||
let marquee = params["rect"].as_array().filter(|r| r.len() == 4).map(|r| {
|
||||
let (x, y) = (num(&r[0]), num(&r[1]));
|
||||
(Point::new(x, y), Point::new(x + num(&r[2]), y + num(&r[3])))
|
||||
});
|
||||
let piece_tol = (params["erase"] == json!(true)).then(|| params["tolerance"].as_f64().unwrap_or(2.0).clamp(0.0, 1000.0));
|
||||
let touched = map.merge_touched(&pts, marquee, piece_tol);
|
||||
if touched.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let roots = sorted_roots(cx.doc, &cx.selection.objects);
|
||||
let (_, leaves) = shape_builder_shapes(cx.doc, &roots, self.opts.open_filled_as_closed);
|
||||
let inputs = merge_inputs(&leaves, self.opts.open_filled_as_closed);
|
||||
let gap = self.gap();
|
||||
let Some(done) = spawn_merge(Arc::clone(&map), touched.clone(), gap, inputs.clone()) else { return false };
|
||||
self.merging = Some(PendingMerge { key, params: params.clone(), map, touched, gap, inputs, done });
|
||||
true
|
||||
}
|
||||
|
||||
/// Takes the merge being computed on another thread once it has arrived, or with `wait` once
|
||||
/// it arrives: the action that applies it, while the document, the selection and its inputs are
|
||||
/// those it was computed for. When one of them changed (an edit or a selection made other than
|
||||
/// by a command, which applies the merge first), the merge is dropped at once, without waiting
|
||||
/// for the thread. A copy of the document (a save stamping its dates) and a new revision that leaves
|
||||
/// the inputs as they were keep the merge. When the thread failed, the command computes the
|
||||
/// merge and reports what went wrong.
|
||||
fn poll_merge(&mut self, cx: &ToolContext, wait: bool) -> Vec<Action> {
|
||||
let Some(mut m) = self.merging.take() else { return vec![] };
|
||||
let now = RegionCache::key_for(cx, m.key.3);
|
||||
if (now.1.0, &now.2) != (m.key.1.0, &m.key.2) {
|
||||
return vec![];
|
||||
}
|
||||
// A new revision that leaves the selection's inputs as they were (a view setting or a
|
||||
// preference that redraws the document) keeps the merge.
|
||||
if now.1 != m.key.1 {
|
||||
if !self.inputs_are(cx, m.key.3, &m.map.shapes) {
|
||||
return vec![];
|
||||
}
|
||||
m.key = now;
|
||||
}
|
||||
let got = if wait { m.done.recv().map_err(|_| TryRecvError::Disconnected) } else { m.done.try_recv() };
|
||||
let geometry = match got {
|
||||
Ok(g) => Some(g),
|
||||
Err(TryRecvError::Empty) => {
|
||||
self.merging = Some(m);
|
||||
return vec![];
|
||||
}
|
||||
Err(TryRecvError::Disconnected) => None,
|
||||
};
|
||||
self.prepared = geometry.map(|geometry| Arc::new(PreparedMerge { map: m.map, touched: m.touched, gap: m.gap, inputs: m.inputs, geometry }));
|
||||
vec![Action::Exec("shapeBuilder.merge".into(), m.params)]
|
||||
}
|
||||
|
||||
/// Is the map of the selection being built on another thread (it is not current yet)?
|
||||
fn map_building(&mut self, cx: &ToolContext) -> bool {
|
||||
self.cache.ready(cx, self.opts.open_filled_as_closed).is_none() && self.cache.pending.is_some()
|
||||
}
|
||||
|
||||
/// Are the inputs of the selection in `cx` `shapes`? The map, or the map being built, is filed
|
||||
/// under the key of `cx` first when they are its inputs ([`RegionCache::rekey`]).
|
||||
fn inputs_are(&mut self, cx: &ToolContext, open_filled_as_closed: bool, shapes: &[po::Shape]) -> bool {
|
||||
let _ = self.cache.rekey(cx, open_filled_as_closed);
|
||||
let key = RegionCache::key_for(cx, open_filled_as_closed);
|
||||
if self.cache.key.as_ref() == Some(&key) {
|
||||
return self.cache.shapes == shapes;
|
||||
}
|
||||
if let Some(p) = self.cache.pending.as_ref().filter(|p| p.key == key) {
|
||||
return p.shapes == shapes;
|
||||
}
|
||||
let roots = sorted_roots(cx.doc, &cx.selection.objects);
|
||||
shape_builder_shapes(cx.doc, &roots, open_filled_as_closed).0 == shapes
|
||||
}
|
||||
|
||||
/// Is a gesture made while the map was being built released and waiting for the map?
|
||||
fn deferred_released(&self) -> bool {
|
||||
self.deferred.as_ref().is_some_and(|d| d.released)
|
||||
}
|
||||
|
||||
/// Replays the released gesture made while the map was being built once the map is there, or
|
||||
/// with `wait` once it is built, and with `wait` also waits for the merge it starts: the
|
||||
/// actions the gesture gives. When the document, the selection or its inputs changed since the
|
||||
/// gesture, it is dropped; a new revision that leaves them as they were keeps it.
|
||||
fn replay_deferred(&mut self, cx: &ToolContext, wait: bool) -> Vec<Action> {
|
||||
if !self.deferred_released() {
|
||||
return vec![];
|
||||
}
|
||||
let ofac = self.opts.open_filled_as_closed;
|
||||
let now = RegionCache::key_for(cx, ofac);
|
||||
if let Some(mut d) = self.deferred.take() {
|
||||
if (d.key.1.0, &d.key.2) != (now.1.0, &now.2) || (d.key.1 != now.1 && !self.inputs_are(cx, ofac, &d.shapes)) {
|
||||
return vec![];
|
||||
}
|
||||
d.key = now;
|
||||
self.deferred = Some(d);
|
||||
}
|
||||
if wait {
|
||||
self.cache.get(cx, self.opts.open_filled_as_closed);
|
||||
} else if self.map_building(cx) {
|
||||
return vec![];
|
||||
}
|
||||
let Some(d) = self.deferred.take() else { return vec![] };
|
||||
let mut acts = vec![];
|
||||
for ev in &d.events {
|
||||
acts.extend(self.pointer(cx, ev));
|
||||
}
|
||||
if wait {
|
||||
acts.extend(self.poll_merge(cx, true));
|
||||
}
|
||||
acts
|
||||
}
|
||||
|
||||
/// Adds what the drag from `from` to `to` touches, picked as `shapeBuilder.merge` picks it.
|
||||
fn touch(&mut self, cx: &ToolContext, from: Option<Point>, to: Point) {
|
||||
let pts: Vec<Point> = from.into_iter().chain([to]).collect();
|
||||
@@ -274,6 +449,8 @@ impl Tool for ShapeBuilderTool {
|
||||
|
||||
fn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {
|
||||
let p = ev.pos;
|
||||
// The command has taken the merge computed for the last gesture by now.
|
||||
self.prepared = None;
|
||||
match ev.kind {
|
||||
PointerKind::Move => {
|
||||
self.alt = ev.mods.alt;
|
||||
@@ -282,7 +459,8 @@ impl Tool for ShapeBuilderTool {
|
||||
vec![]
|
||||
}
|
||||
PointerKind::Down => {
|
||||
if cx.selection.is_empty() {
|
||||
// While a merge is being computed, a press starts no gesture.
|
||||
if cx.selection.is_empty() || self.editing() {
|
||||
return vec![];
|
||||
}
|
||||
self.dragging = true;
|
||||
@@ -291,11 +469,35 @@ impl Tool for ShapeBuilderTool {
|
||||
self.points = vec![p];
|
||||
self.far = false;
|
||||
self.touched = Touched::default();
|
||||
// While the map is being built on another thread, the gesture is recorded and
|
||||
// replayed once the map is there.
|
||||
if self.map_building(cx) {
|
||||
let key = RegionCache::key_for(cx, self.opts.open_filled_as_closed);
|
||||
let shapes = match self.cache.pending.as_ref().filter(|p| p.key == key) {
|
||||
Some(p) => p.shapes.clone(),
|
||||
None => self.cache.inputs(cx, self.opts.open_filled_as_closed).0,
|
||||
};
|
||||
self.deferred = Some(Deferred { key, shapes, events: vec![*ev], released: false });
|
||||
return vec![];
|
||||
}
|
||||
self.touch(cx, None, p);
|
||||
vec![]
|
||||
}
|
||||
PointerKind::Drag if self.dragging => {
|
||||
self.at = Some(p);
|
||||
if let Some(d) = &mut self.deferred {
|
||||
// The drag's line or marquee shows meanwhile.
|
||||
d.events.push(*ev);
|
||||
if let Some((a, _)) = self.marquee {
|
||||
self.marquee = Some((a, p));
|
||||
} else if self.opts.straight_line {
|
||||
self.points.truncate(1);
|
||||
self.points.push(p);
|
||||
} else if self.points.last().is_none_or(|q| q.distance(p) >= cx.tol(1.0)) {
|
||||
self.points.push(p);
|
||||
}
|
||||
return vec![];
|
||||
}
|
||||
if self.points.first().is_some_and(|s| s.distance(p) > cx.tol(CLICK_TOL_PX)) {
|
||||
self.far = true;
|
||||
}
|
||||
@@ -316,6 +518,13 @@ impl Tool for ShapeBuilderTool {
|
||||
}
|
||||
PointerKind::Up if self.dragging => {
|
||||
self.dragging = false;
|
||||
if let Some(d) = &mut self.deferred {
|
||||
d.events.push(*ev);
|
||||
d.released = true;
|
||||
self.points.clear();
|
||||
self.marquee = None;
|
||||
return vec![];
|
||||
}
|
||||
if self.marquee.is_some() {
|
||||
self.marquee_to(cx, p);
|
||||
} else if self.opts.straight_line {
|
||||
@@ -361,6 +570,10 @@ impl Tool for ShapeBuilderTool {
|
||||
if self.opts.swatches {
|
||||
params["pickColorFrom"] = json!("swatches");
|
||||
}
|
||||
// A large selection's merge is computed on another thread; `poll` applies it.
|
||||
if self.start_merge(cx, ¶ms) {
|
||||
return vec![];
|
||||
}
|
||||
vec![Action::Exec("shapeBuilder.merge".into(), params)]
|
||||
}
|
||||
_ => vec![],
|
||||
@@ -369,10 +582,13 @@ impl Tool for ShapeBuilderTool {
|
||||
|
||||
fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
|
||||
let mut out = vec![];
|
||||
let map = &self.cache.map;
|
||||
let color = if self.alt { HIGHLIGHT_RED } else { HATCH };
|
||||
let show: Vec<Hit> = if self.dragging {
|
||||
let t = &self.touched;
|
||||
// While a merge is being computed, what its gesture touched stays highlighted.
|
||||
let map = self.merging.as_ref().map_or(&self.cache.map, |m| &m.map);
|
||||
// The mode of the gesture being merged, else the drag's or the hover's.
|
||||
let alt = self.merging.as_ref().filter(|_| !self.dragging).map_or(self.alt, |m| m.params["erase"] == json!(true));
|
||||
let color = if alt { HIGHLIGHT_RED } else { HATCH };
|
||||
let touched = if self.dragging { Some(&self.touched) } else { self.merging.as_ref().map(|m| &m.touched) };
|
||||
let show: Vec<Hit> = if let Some(t) = touched {
|
||||
let regions = t.regions.iter().map(|&i| Hit::Region(i));
|
||||
regions.chain(t.lines.iter().map(|&i| Hit::Line(i))).chain(map.erased_edges(t).into_iter().map(Hit::Edge)).collect()
|
||||
} else {
|
||||
@@ -381,7 +597,7 @@ impl Tool for ShapeBuilderTool {
|
||||
for hit in show {
|
||||
match hit {
|
||||
// Highlight Fill off: merge mode leaves the regions as they are.
|
||||
Hit::Region(_) if !self.alt && !self.opts.highlight_fill => {}
|
||||
Hit::Region(_) if !alt && !self.opts.highlight_fill => {}
|
||||
Hit::Region(i) => {
|
||||
if let Some((_, bp, _)) = map.regions.get(i) {
|
||||
out.push(Overlay::Path { path: hatch(bp, cx.tol(4.0)), color, width: 1.0, dashed: false });
|
||||
@@ -424,7 +640,10 @@ impl Tool for ShapeBuilderTool {
|
||||
fn cursor(&self, _cx: &ToolContext, _p: Point, m: Mods) -> Cursor {
|
||||
// A drag keeps the mode it started in; hovering follows the key.
|
||||
let erase = if self.dragging { self.alt } else { m.alt };
|
||||
if erase {
|
||||
if self.editing() {
|
||||
// The merge of the last gesture, or the map it waits for, is being computed.
|
||||
Cursor::Busy
|
||||
} else if erase {
|
||||
Cursor::ShapeBuilderErase
|
||||
} else if self.stroke.is_some() && !self.dragging {
|
||||
// Over a stroke a click splits.
|
||||
@@ -439,30 +658,53 @@ impl Tool for ShapeBuilderTool {
|
||||
}
|
||||
|
||||
fn waiting(&self) -> bool {
|
||||
self.cache.waiting()
|
||||
self.cache.waiting() || self.merging.is_some() || self.deferred.is_some()
|
||||
}
|
||||
|
||||
fn poll(&mut self, cx: &ToolContext, wait: bool) {
|
||||
if !self.cache.waiting() || self.dragging {
|
||||
return;
|
||||
fn editing(&self) -> bool {
|
||||
self.merging.is_some() || self.deferred_released()
|
||||
}
|
||||
|
||||
fn finish_edit(&mut self, cx: &ToolContext) -> Vec<Action> {
|
||||
let mut acts = self.replay_deferred(cx, true);
|
||||
acts.extend(self.poll_merge(cx, true));
|
||||
acts
|
||||
}
|
||||
|
||||
/// Choosing another tool or another document applies the merge being computed first.
|
||||
fn deactivate(&mut self, cx: &ToolContext) -> Vec<Action> {
|
||||
self.finish_edit(cx)
|
||||
}
|
||||
|
||||
fn poll(&mut self, cx: &ToolContext, wait: bool) -> Vec<Action> {
|
||||
let mut acts = self.poll_merge(cx, wait);
|
||||
if !acts.is_empty() || self.dragging {
|
||||
return acts;
|
||||
}
|
||||
// The map that arrives may be for an earlier revision; the hover then starts the current
|
||||
// one's, which `wait` waits for too.
|
||||
loop {
|
||||
while self.cache.waiting() {
|
||||
self.cache.settle(wait);
|
||||
if let Some(p) = self.at {
|
||||
self.hover_at(cx, p);
|
||||
}
|
||||
if !wait || !self.cache.waiting() {
|
||||
if !wait {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// A gesture made while the map was being built goes on once it is there.
|
||||
acts.extend(self.replay_deferred(cx, wait));
|
||||
acts
|
||||
}
|
||||
|
||||
fn shape_builder_map(&self) -> Option<(Arc<BuilderMap>, f64)> {
|
||||
self.cache.key.is_some().then(|| (Arc::clone(&self.cache.map), self.cache.gap))
|
||||
}
|
||||
|
||||
fn shape_builder_merge(&self) -> Option<Arc<PreparedMerge>> {
|
||||
self.prepared.clone()
|
||||
}
|
||||
|
||||
/// With Pick Color From Color Swatches, the Left and Right arrow keys pick the color swatch
|
||||
/// before or after the current fill. Escape during a drag cancels it: the release after it
|
||||
/// merges and deletes nothing.
|
||||
@@ -471,13 +713,16 @@ impl Tool for ShapeBuilderTool {
|
||||
}
|
||||
|
||||
fn key(&mut self, cx: &ToolContext, key: ToolKey, _mods: Mods) -> Vec<Action> {
|
||||
if !self.claims_key(cx, key) {
|
||||
// While a merge is being computed, the arrows leave the current fill it takes as it was.
|
||||
if !self.claims_key(cx, key) || self.editing() {
|
||||
return vec![];
|
||||
}
|
||||
if key == ToolKey::Escape {
|
||||
self.dragging = false;
|
||||
self.points.clear();
|
||||
self.touched = Touched::default();
|
||||
// A gesture recorded while the map is being built is canceled with it.
|
||||
self.deferred = None;
|
||||
(self.marquee, self.hover, self.far) = (None, None, false);
|
||||
return vec![];
|
||||
}
|
||||
|
||||
@@ -8,18 +8,21 @@ pub(super) type CacheKey = (usize, (u64, u64), Vec<NodeId>, bool);
|
||||
|
||||
/// Hovering builds the map of inputs with more segments than this on another thread
|
||||
/// ([`RegionCache::ready`]); smaller maps are built on the calling thread.
|
||||
const BACKGROUND_SEGMENTS: usize = 128;
|
||||
pub(super) const BACKGROUND_SEGMENTS: usize = 128;
|
||||
|
||||
/// A map being built on another thread: the key it is for, the drawn outlines of its inputs, and
|
||||
/// the channel it arrives on.
|
||||
struct Pending {
|
||||
key: CacheKey,
|
||||
/// A map being built on another thread: the key it is for, its inputs and their drawn outlines,
|
||||
/// and the channel it arrives on.
|
||||
pub(super) struct Pending {
|
||||
pub(super) key: CacheKey,
|
||||
pub(super) shapes: Vec<po::Shape>,
|
||||
outlines: Vec<PathData>,
|
||||
done: Receiver<BuilderMap>,
|
||||
}
|
||||
|
||||
/// The planar map of the current selection, cached by document identity, revision, selection and
|
||||
/// whether filled open paths count as closed.
|
||||
/// whether filled open paths count as closed. When only the document's identity or revision
|
||||
/// changed and the selection's inputs did not (a view setting, a preference, a copy of the
|
||||
/// document), the map is kept under the new key ([`RegionCache::rekey`]).
|
||||
#[derive(Default)]
|
||||
pub(super) struct RegionCache {
|
||||
pub(super) key: Option<CacheKey>,
|
||||
@@ -31,8 +34,12 @@ pub(super) struct RegionCache {
|
||||
pub(super) gap: f64,
|
||||
/// The outlines of the Shape Builder's inputs as they are drawn (see [`BuilderMap::stroke_at`]).
|
||||
pub(super) outlines: Vec<PathData>,
|
||||
/// The inputs the map was built from.
|
||||
pub(super) shapes: Vec<po::Shape>,
|
||||
/// The last key whose inputs [`Self::rekey`] compared with the map's.
|
||||
compared: Option<CacheKey>,
|
||||
/// The map being built on another thread, if any.
|
||||
pending: Option<Pending>,
|
||||
pub(super) pending: Option<Pending>,
|
||||
/// The key of the last map whose build on another thread failed.
|
||||
failed: Option<CacheKey>,
|
||||
/// How many times the map has been built.
|
||||
@@ -76,13 +83,13 @@ impl RegionCache {
|
||||
Self { live: true, ..Default::default() }
|
||||
}
|
||||
|
||||
fn key_for(cx: &ToolContext, open_filled_as_closed: bool) -> CacheKey {
|
||||
pub(super) fn key_for(cx: &ToolContext, open_filled_as_closed: bool) -> CacheKey {
|
||||
(cx.doc as *const Document as usize, cx.revision, cx.selection.objects.clone(), open_filled_as_closed)
|
||||
}
|
||||
|
||||
/// The inputs of the selection's map, back → front, and their drawn outlines (Shape Builder
|
||||
/// only).
|
||||
fn inputs(&self, cx: &ToolContext, open_filled_as_closed: bool) -> (Vec<po::Shape>, Vec<PathData>) {
|
||||
pub(super) fn inputs(&self, cx: &ToolContext, open_filled_as_closed: bool) -> (Vec<po::Shape>, Vec<PathData>) {
|
||||
let roots = sorted_roots(cx.doc, &cx.selection.objects);
|
||||
if self.live {
|
||||
(shapes_for(cx.doc, &roots).0, vec![])
|
||||
@@ -93,8 +100,9 @@ impl RegionCache {
|
||||
}
|
||||
}
|
||||
|
||||
fn install(&mut self, key: CacheKey, map: BuilderMap, outlines: Vec<PathData>) {
|
||||
fn install(&mut self, key: CacheKey, map: BuilderMap, shapes: Vec<po::Shape>, outlines: Vec<PathData>) {
|
||||
self.map = Arc::new(map);
|
||||
self.shapes = shapes;
|
||||
self.outlines = outlines;
|
||||
self.key = Some(key);
|
||||
#[cfg(test)]
|
||||
@@ -122,8 +130,12 @@ impl RegionCache {
|
||||
pub(super) fn get(&mut self, cx: &ToolContext, open_filled_as_closed: bool) -> &BuilderMap {
|
||||
let key = Self::key_for(cx, open_filled_as_closed);
|
||||
if self.key.as_ref() != Some(&key) {
|
||||
let built = self.pending.take().filter(|p| p.key == key).and_then(|p| Some((p.done.recv().ok()?, p.outlines)));
|
||||
let (map, outlines) = match built {
|
||||
let inputs = self.rekey(cx, open_filled_as_closed);
|
||||
if self.key.as_ref() == Some(&key) {
|
||||
return &self.map;
|
||||
}
|
||||
let built = self.pending.take().filter(|p| p.key == key).and_then(|p| Some((p.done.recv().ok()?, p.shapes, p.outlines)));
|
||||
let (map, shapes, outlines) = match built {
|
||||
Some(b) => {
|
||||
#[cfg(test)]
|
||||
{
|
||||
@@ -132,15 +144,45 @@ impl RegionCache {
|
||||
b
|
||||
}
|
||||
None => {
|
||||
let (shapes, outlines) = self.inputs(cx, open_filled_as_closed);
|
||||
(build_map(shapes, self.live, self.gap), outlines)
|
||||
let (shapes, outlines) = inputs.unwrap_or_else(|| self.inputs(cx, open_filled_as_closed));
|
||||
(build_map(shapes.clone(), self.live, self.gap), shapes, outlines)
|
||||
}
|
||||
};
|
||||
self.install(key, map, outlines);
|
||||
self.install(key, map, shapes, outlines);
|
||||
}
|
||||
&self.map
|
||||
}
|
||||
|
||||
/// When the map, or the map being built, is for the selection of `cx` but for another revision
|
||||
/// or address of the document, and the selection's inputs and their outlines are those it is
|
||||
/// made from, files it under the key of `cx`: nothing it is made from changed. Returns the
|
||||
/// inputs it computed when that did not file a map (they changed), for the caller to build
|
||||
/// from.
|
||||
pub(super) fn rekey(&mut self, cx: &ToolContext, open_filled_as_closed: bool) -> Option<(Vec<po::Shape>, Vec<PathData>)> {
|
||||
let key = Self::key_for(cx, open_filled_as_closed);
|
||||
let other = |k: &CacheKey| *k != key && (&k.2, k.3) == (&key.2, key.3);
|
||||
if self.pending.as_ref().is_some_and(|p| p.key == key) {
|
||||
return None;
|
||||
}
|
||||
let installed = self.key.as_ref().is_some_and(other);
|
||||
let building = self.pending.as_ref().is_some_and(|p| other(&p.key));
|
||||
// The inputs are compared once for each key.
|
||||
if (!installed && !building) || self.compared.as_ref() == Some(&key) {
|
||||
return None;
|
||||
}
|
||||
self.compared = Some(key.clone());
|
||||
let (shapes, outlines) = self.inputs(cx, open_filled_as_closed);
|
||||
if installed && self.shapes == shapes && self.outlines == outlines {
|
||||
self.key = Some(key);
|
||||
return None;
|
||||
}
|
||||
if let Some(p) = self.pending.as_mut().filter(|p| other(&p.key) && p.shapes == shapes && p.outlines == outlines) {
|
||||
p.key = key;
|
||||
return None;
|
||||
}
|
||||
Some((shapes, outlines))
|
||||
}
|
||||
|
||||
/// Takes the map being built on another thread once it has arrived, or with `wait` once it
|
||||
/// arrives, as the map for the key it was built for.
|
||||
pub(super) fn settle(&mut self, wait: bool) {
|
||||
@@ -152,7 +194,7 @@ impl RegionCache {
|
||||
{
|
||||
self.background += 1;
|
||||
}
|
||||
self.install(p.key, map, p.outlines);
|
||||
self.install(p.key, map, p.shapes, p.outlines);
|
||||
}
|
||||
// The build failed (a bug in the planar map): hovering does not build it again, and a
|
||||
// gesture builds it on the calling thread, which reports the failure.
|
||||
@@ -171,21 +213,25 @@ impl RegionCache {
|
||||
if self.key.as_ref() == Some(&key) {
|
||||
return Some(&self.map);
|
||||
}
|
||||
let inputs = self.rekey(cx, open_filled_as_closed);
|
||||
if self.key.as_ref() == Some(&key) {
|
||||
return Some(&self.map);
|
||||
}
|
||||
if self.pending.is_some() || self.failed.as_ref() == Some(&key) {
|
||||
return None;
|
||||
}
|
||||
let (shapes, outlines) = self.inputs(cx, open_filled_as_closed);
|
||||
let (shapes, outlines) = inputs.unwrap_or_else(|| self.inputs(cx, open_filled_as_closed));
|
||||
let segments: usize = shapes.iter().map(|s| s.path.subpaths.iter().map(|sp| sp.segment_count()).sum::<usize>()).sum();
|
||||
if segments > BACKGROUND_SEGMENTS && cfg!(not(target_arch = "wasm32")) {
|
||||
if let Some(done) = spawn_build(shapes, self.live, self.gap) {
|
||||
self.pending = Some(Pending { key, outlines, done });
|
||||
if let Some(done) = spawn_build(shapes.clone(), self.live, self.gap) {
|
||||
self.pending = Some(Pending { key, shapes, outlines, done });
|
||||
return None;
|
||||
}
|
||||
// No thread started: build here.
|
||||
return Some(self.get(cx, open_filled_as_closed));
|
||||
}
|
||||
let map = build_map(shapes, self.live, self.gap);
|
||||
self.install(key, map, outlines);
|
||||
let map = build_map(shapes.clone(), self.live, self.gap);
|
||||
self.install(key, map, shapes, outlines);
|
||||
Some(&self.map)
|
||||
}
|
||||
|
||||
|
||||
@@ -282,9 +282,9 @@ impl Tool for LivePaintBucketTool {
|
||||
self.cache.waiting()
|
||||
}
|
||||
|
||||
fn poll(&mut self, cx: &ToolContext, wait: bool) {
|
||||
fn poll(&mut self, cx: &ToolContext, wait: bool) -> Vec<Action> {
|
||||
if !self.cache.waiting() {
|
||||
return;
|
||||
return vec![];
|
||||
}
|
||||
// As the Shape Builder's: the map that arrives may be for an earlier revision. Over a part
|
||||
// of a Live Paint group the hover takes no map.
|
||||
@@ -297,6 +297,7 @@ impl Tool for LivePaintBucketTool {
|
||||
break;
|
||||
}
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -284,4 +284,6 @@ pub(super) fn faces_of(regions: Vec<po::Region>) -> Vec<Face> {
|
||||
thread_local! {
|
||||
/// The Shape Builder maps built on this thread ([`maps_built`]).
|
||||
pub(super) static MAPS_BUILT: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
/// The Shape Builder merges computed on this thread ([`merges_computed`]).
|
||||
pub(super) static MERGES_COMPUTED: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::lookup::{Face, MAPS_BUILT, faces_of, outline_snap, shape_builder_shapes};
|
||||
use super::lookup::{Face, MAPS_BUILT, MERGES_COMPUTED, faces_of, node_outline, outline_snap, shape_builder_shapes};
|
||||
use super::*;
|
||||
|
||||
/// Shape Builder hover hatch colour (neutral grey) and Live Paint highlight red.
|
||||
@@ -12,6 +12,12 @@ pub fn maps_built() -> usize {
|
||||
MAPS_BUILT.with(std::cell::Cell::get)
|
||||
}
|
||||
|
||||
/// How many Shape Builder merges ([`merge_geometry`]) this thread has computed, for tests that
|
||||
/// count them.
|
||||
pub fn merges_computed() -> usize {
|
||||
MERGES_COMPUTED.with(std::cell::Cell::get)
|
||||
}
|
||||
|
||||
/// The Shape Builder's planar map of a selection.
|
||||
#[derive(Default)]
|
||||
pub struct BuilderMap {
|
||||
@@ -345,6 +351,112 @@ impl BuilderMap {
|
||||
let bounds_one = |(e, _): &(po::Shape, Rect)| self.sides(e).iter().any(|r| r.is_some_and(|r| touched.regions.contains(&r)));
|
||||
touched.edges.iter().copied().filter(|&k| self.edges.get(k).is_some_and(|e| !bounds_one(e))).collect()
|
||||
}
|
||||
|
||||
/// What `shapeBuilder.merge` touches: the regions the marquee from `marquee.0` to `marquee.1`
|
||||
/// reaches, then what the drag along `pts` touches ([`Self::builder_hits_along`]), and the
|
||||
/// edges that deletes ([`Self::erased_edges`]).
|
||||
pub fn merge_touched(&self, pts: &[Point], marquee: Option<(Point, Point)>, piece_tol: Option<f64>) -> Touched {
|
||||
let mut touched = Touched { regions: marquee.map(|(a, b)| self.regions_in_marquee(a, b)).unwrap_or_default(), ..Default::default() };
|
||||
touched.extend(&self.builder_hits_along(pts, piece_tol));
|
||||
touched.edges = self.erased_edges(&touched);
|
||||
touched
|
||||
}
|
||||
}
|
||||
|
||||
/// What a merge needs of each input besides the map: its outline as drawn ([`node_outline`]) and
|
||||
/// whether its fill closes its open subpaths (Consider Open Filled Paths as Closed, and a fill).
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct MergeInput {
|
||||
pub outline: Option<PathData>,
|
||||
pub fill_closes: bool,
|
||||
}
|
||||
|
||||
/// The [`MergeInput`] of each of `leaves`.
|
||||
pub fn merge_inputs(leaves: &[&Node], open_filled_as_closed: bool) -> Vec<MergeInput> {
|
||||
leaves
|
||||
.iter()
|
||||
.map(|l| MergeInput { outline: node_outline(l).map(|o| o.0), fill_closes: open_filled_as_closed && !l.appearance.fill_paint().is_none() })
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// What is left of an input a merge or a delete changes: its faces not touched, united
|
||||
/// (`united`), or its own outline, with the deleted edges cut out of it.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Rest {
|
||||
pub path: PathData,
|
||||
pub united: bool,
|
||||
}
|
||||
|
||||
/// The new shapes of a Shape Builder merge or delete ([`merge_geometry`]).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct MergeGeometry {
|
||||
/// The union of the touched regions (empty when none is touched).
|
||||
pub union: PathData,
|
||||
/// For each closed input, what goes in its place when the gesture changes it.
|
||||
pub rests: Vec<Option<Rest>>,
|
||||
}
|
||||
|
||||
/// The new shapes of a gesture over `map` that touched `touched`, closing gaps up to `gap`: the
|
||||
/// union of the touched regions, and for each closed input that has a touched region or a deleted
|
||||
/// edge, what is left of it. An input a touched region covers keeps its other faces, united
|
||||
/// (they share their edges with the merged faces exactly, where subtracting the merged shape left
|
||||
/// slivers of the outline along them, #569; a sliver goes in only where the input covers it and
|
||||
/// the merged shape does not take it in); then each deleted edge is cut out of it. Inputs with
|
||||
/// pieces of open paths (`map.lines`) are left to the caller.
|
||||
pub fn merge_geometry(map: &BuilderMap, touched: &Touched, gap: f64, inputs: &[MergeInput]) -> MergeGeometry {
|
||||
MERGES_COMPUTED.with(|n| n.set(n.get() + 1));
|
||||
let cuts: Vec<&SubPath> = touched.edges.iter().filter_map(|&k| map.edges.get(k)?.0.path.subpaths.first()).collect();
|
||||
let picked: Vec<&po::Region> = touched.regions.iter().filter_map(|&i| map.regions.get(i).map(|r| &r.0)).collect();
|
||||
let faces = po::FaceMerger::with_gap(&map.shapes, gap);
|
||||
let union = if picked.is_empty() { PathData::default() } else { faces.merge(&picked) };
|
||||
let rests = map
|
||||
.shapes
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, sh)| {
|
||||
let input = inputs.get(i)?;
|
||||
let in_union = picked.iter().any(|r| r.sources.contains(&i));
|
||||
if map.lines.iter().any(|(l, _)| l.key == i as u64) || (!in_union && cuts.is_empty()) {
|
||||
return None;
|
||||
}
|
||||
let mut rest = if in_union {
|
||||
let kept: Vec<&po::Region> = map
|
||||
.regions
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(k, (r, ..))| r.sources.contains(&i) && !touched.regions.contains(k))
|
||||
.map(|(_, (r, ..))| r)
|
||||
.collect();
|
||||
if kept.is_empty() { PathData::default() } else { faces.merge_rest(i, &kept, &picked) }
|
||||
} else {
|
||||
input.outline.clone().unwrap_or_else(|| sh.path.clone())
|
||||
};
|
||||
// Edges come back from the planar map within a few hundredths of the outlines they
|
||||
// follow, whatever else is selected.
|
||||
let cut_tol = outline_snap(&sh.path);
|
||||
let mut cut = false;
|
||||
for piece in &cuts {
|
||||
if let Some(r) = po::cut_out(&rest, piece, input.fill_closes, cut_tol) {
|
||||
rest = r;
|
||||
cut = true;
|
||||
}
|
||||
}
|
||||
(in_union || cut).then_some(Rest { path: rest, united: in_union })
|
||||
})
|
||||
.collect();
|
||||
MergeGeometry { union, rests }
|
||||
}
|
||||
|
||||
/// A merge computed on another thread for a Shape Builder click or drag
|
||||
/// ([`Tool::shape_builder_merge`]): the map, what the gesture touched and the inputs it was
|
||||
/// computed from, and the result. `shapeBuilder.merge` takes the result when it would compute the
|
||||
/// same.
|
||||
pub struct PreparedMerge {
|
||||
pub map: Arc<BuilderMap>,
|
||||
pub touched: Touched,
|
||||
pub gap: f64,
|
||||
pub inputs: Vec<MergeInput>,
|
||||
pub geometry: MergeGeometry,
|
||||
}
|
||||
|
||||
/// The regions, line pieces and edges a Shape Builder gesture has touched, in the order touched.
|
||||
|
||||
@@ -132,20 +132,34 @@ fn shape_builder_builds_its_map_once_for_hover_alt_hover_and_a_merge() {
|
||||
// The merge left the document as it was (it failed, say): the map still fits it.
|
||||
t.pointer(&cx1, &ev(PointerKind::Move, 75.0, 75.0));
|
||||
assert_eq!(t.cache.builds, 1, "a hover after a merge that changed nothing");
|
||||
// A new revision of the same art (a view setting, a preference) keeps the map.
|
||||
let cx2 = ToolContext { revision: (1, 2), ..cx(&d, &s, &p) };
|
||||
t.pointer(&cx2, &ev(PointerKind::Move, 75.0, 75.0));
|
||||
assert_eq!(t.cache.builds, 2, "a hover on a new revision");
|
||||
assert_eq!(t.cache.builds, 1, "a hover on a new revision of the same art");
|
||||
assert!(matches!(t.hover, Some(Hit::Region(_))), "{:?}", t.hover);
|
||||
// The same objects, one of them moved.
|
||||
let mut moved = d.clone();
|
||||
let second = s.objects[1];
|
||||
moved.node_mut(second).unwrap().transform(vectorcraft_geom::Affine::translate((10.0, 0.0)), false);
|
||||
let cx3 = ToolContext { revision: (1, 3), ..cx(&moved, &s, &p) };
|
||||
t.pointer(&cx3, &ev(PointerKind::Move, 75.0, 75.0));
|
||||
assert_eq!(t.cache.builds, 2, "a hover on a new revision of other art");
|
||||
}
|
||||
|
||||
/// A row of `n` selected squares 20 pt wide, each overlapping the next by half: 4 segments each.
|
||||
fn square_row(n: usize) -> (Document, Selection) {
|
||||
square_row_at(n, 0.0)
|
||||
}
|
||||
|
||||
/// [`square_row`] with the squares' tops at `y`: the same objects, moved.
|
||||
fn square_row_at(n: usize, y: f64) -> (Document, Selection) {
|
||||
let mut d = Document::new(500.0, 500.0);
|
||||
let l = d.layers[0].id;
|
||||
let mut s = Selection::default();
|
||||
for k in 0..n {
|
||||
let x = k as f64 * 10.0;
|
||||
let id = d.alloc_id();
|
||||
d.insert(Some(l), k, Node::path(id, shapes::rectangle(Rect::new(x, 0.0, x + 20.0, 20.0)), Appearance::default_art())).unwrap();
|
||||
d.insert(Some(l), k, Node::path(id, shapes::rectangle(Rect::new(x, y, x + 20.0, y + 20.0)), Appearance::default_art())).unwrap();
|
||||
s.add(id);
|
||||
}
|
||||
(d, s)
|
||||
@@ -176,9 +190,10 @@ fn shape_builder_hover_builds_a_large_map_on_another_thread() {
|
||||
assert_eq!((t.cache.builds, t.cache.background), (1, 1));
|
||||
assert_eq!(t.overlays(&cx1).len(), 2, "the region's hatch and outline");
|
||||
// A new revision while the map of the one before it is being built: only the newer one's
|
||||
// map is used.
|
||||
let cx2 = ToolContext { revision: (1, 2), ..cx(&d, &s, &p) };
|
||||
let cx3 = ToolContext { revision: (1, 3), ..cx(&d, &s, &p) };
|
||||
// map is used. Each revision moves the squares down 1 pt.
|
||||
let rows: Vec<Document> = (0..7).map(|k| square_row_at(40, f64::from(k)).0).collect();
|
||||
let cx2 = ToolContext { revision: (1, 2), ..cx(&rows[2], &s, &p) };
|
||||
let cx3 = ToolContext { revision: (1, 3), ..cx(&rows[3], &s, &p) };
|
||||
t.pointer(&cx2, &hover);
|
||||
t.pointer(&cx3, &hover);
|
||||
poll_until_ready(&mut t, &cx3);
|
||||
@@ -186,29 +201,265 @@ fn shape_builder_hover_builds_a_large_map_on_another_thread() {
|
||||
assert_eq!((t.cache.builds, t.cache.background), (3, 3), "the earlier revision's map, then the newer one's");
|
||||
assert_eq!(t.cache.key.as_ref().map(|k| k.1), Some((1, 3)));
|
||||
// A host without frames waits for the map.
|
||||
let cx4 = ToolContext { revision: (1, 4), ..cx(&d, &s, &p) };
|
||||
let cx4 = ToolContext { revision: (1, 4), ..cx(&rows[4], &s, &p) };
|
||||
t.pointer(&cx4, &hover);
|
||||
assert!(t.waiting() && t.hover.is_none());
|
||||
t.poll(&cx4, true);
|
||||
assert!(!t.waiting());
|
||||
assert!(matches!(t.hover, Some(Hit::Region(_))), "{:?}", t.hover);
|
||||
assert_eq!((t.cache.builds, t.cache.background), (4, 4));
|
||||
// A press while the map is being built waits for it, and the drag merges.
|
||||
let cx5 = ToolContext { revision: (1, 5), ..cx(&d, &s, &p) };
|
||||
// A drag while the map is being built is replayed once it is there, and merges (on
|
||||
// another thread, see `shape_builder_merges_a_large_selection_on_another_thread` and
|
||||
// `shape_builder_gesture_waits_for_the_map_without_holding_the_caller`).
|
||||
let cx5 = ToolContext { revision: (1, 5), ..cx(&rows[5], &s, &p) };
|
||||
t.pointer(&cx5, &hover);
|
||||
t.pointer(&cx5, &ev(PointerKind::Down, 15.0, 10.0));
|
||||
t.pointer(&cx5, &ev(PointerKind::Drag, 35.0, 10.0));
|
||||
let acts = t.pointer(&cx5, &ev(PointerKind::Up, 35.0, 10.0));
|
||||
assert!(matches!(acts.as_slice(), [Action::Exec(id, _)] if id == "shapeBuilder.merge"), "{acts:?}");
|
||||
assert!(t.pointer(&cx5, &ev(PointerKind::Up, 35.0, 10.0)).is_empty());
|
||||
let acts = t.poll(&cx5, true);
|
||||
assert_eq!((t.cache.builds, t.cache.background), (5, 5));
|
||||
assert!(matches!(acts.as_slice(), [Action::Exec(id, _)] if id == "shapeBuilder.merge"), "{acts:?}");
|
||||
assert!(!t.waiting());
|
||||
// Changing an option forgets a map being built with the old one.
|
||||
let cx6 = ToolContext { revision: (1, 6), ..cx(&d, &s, &p) };
|
||||
let cx6 = ToolContext { revision: (1, 6), ..cx(&rows[6], &s, &p) };
|
||||
t.pointer(&cx6, &hover);
|
||||
t.set_option("gapDetection", &json!(true));
|
||||
assert!(!t.waiting());
|
||||
}
|
||||
|
||||
/// Polls `t` until it stops waiting, as the desktop app does each frame, and returns the
|
||||
/// actions the polls gave.
|
||||
fn poll_actions(t: &mut dyn Tool, cx: &ToolContext) -> Vec<Action> {
|
||||
let start = std::time::Instant::now();
|
||||
let mut acts = vec![];
|
||||
while t.waiting() {
|
||||
assert!(start.elapsed() < std::time::Duration::from_secs(60), "the tool is still waiting");
|
||||
std::thread::sleep(std::time::Duration::from_millis(2));
|
||||
acts.extend(t.poll(cx, false));
|
||||
}
|
||||
acts
|
||||
}
|
||||
|
||||
/// A Shape Builder over `square_row(40)` (160 segments) that has merged nothing, with its map,
|
||||
/// after a click at (15, 10) that started a merge on another thread.
|
||||
fn clicked_row(cx: &ToolContext) -> ShapeBuilderTool {
|
||||
let mut t = ShapeBuilderTool::default();
|
||||
t.pointer(cx, &ev(PointerKind::Move, 15.0, 10.0));
|
||||
poll_until_ready(&mut t, cx);
|
||||
t.pointer(cx, &ev(PointerKind::Down, 15.0, 10.0));
|
||||
assert!(t.pointer(cx, &ev(PointerKind::Up, 15.0, 10.0)).is_empty(), "the release returns before the merge is computed");
|
||||
assert!(t.waiting() && t.editing());
|
||||
t
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shape_builder_merges_a_large_selection_on_another_thread() {
|
||||
let (d, s) = square_row(40);
|
||||
let p = paint();
|
||||
let cx = cx(&d, &s, &p);
|
||||
let computed = merges_computed();
|
||||
let mut t = clicked_row(&cx);
|
||||
assert_eq!(t.cursor(&cx, Point::new(15.0, 10.0), Mods::default()), Cursor::Busy);
|
||||
assert_eq!(t.overlays(&cx).len(), 2, "the clicked region's hatch and outline stay");
|
||||
// A press while the merge is being computed starts no gesture.
|
||||
assert!(t.pointer(&cx, &ev(PointerKind::Down, 35.0, 10.0)).is_empty());
|
||||
assert!(!t.busy());
|
||||
assert!(t.pointer(&cx, &ev(PointerKind::Up, 35.0, 10.0)).is_empty());
|
||||
let acts = poll_actions(&mut t, &cx);
|
||||
assert_eq!(merges_computed(), computed, "the merge was computed on another thread");
|
||||
let [Action::Exec(id, params)] = acts.as_slice() else { panic!("{acts:?}") };
|
||||
assert_eq!((id.as_str(), ¶ms["points"]), ("shapeBuilder.merge", &json!([[15.0, 10.0]])));
|
||||
assert!(!t.waiting() && !t.editing());
|
||||
assert_eq!(t.cursor(&cx, Point::new(15.0, 10.0), Mods::default()), Cursor::ShapeBuilder);
|
||||
let m = t.shape_builder_merge().expect("the merge the command takes");
|
||||
assert!(Arc::ptr_eq(&m.map, &t.cache.map));
|
||||
assert_eq!((m.touched.regions.len(), m.touched.lines.len(), m.touched.edges.len()), (1, 0, 0));
|
||||
assert!(!m.geometry.union.is_empty());
|
||||
assert_eq!(m.geometry, merge_geometry(&m.map, &m.touched, m.gap, &m.inputs));
|
||||
assert_eq!(m.geometry.rests.iter().flatten().count(), 2, "the two squares over the region change");
|
||||
// The next event lets it go.
|
||||
t.pointer(&cx, &ev(PointerKind::Move, 15.0, 10.0));
|
||||
assert!(t.shape_builder_merge().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shape_builder_drops_a_merge_the_art_changed_under() {
|
||||
let (d, s) = square_row(40);
|
||||
let p = paint();
|
||||
let mut fewer = Selection::default();
|
||||
fewer.set(s.objects.iter().skip(1).copied());
|
||||
let cx1 = ToolContext { revision: (1, 1), ..cx(&d, &s, &p) };
|
||||
let (moved, _) = square_row_at(40, 5.0);
|
||||
let later = [
|
||||
// An edit or an undo: the squares moved.
|
||||
ToolContext { revision: (1, 2), ..cx(&moved, &s, &p) },
|
||||
// Another document.
|
||||
ToolContext { revision: (2, 1), ..cx(&d, &s, &p) },
|
||||
// Another selection.
|
||||
ToolContext { revision: (1, 1), ..cx(&d, &fewer, &p) },
|
||||
];
|
||||
for (k, cx2) in later.iter().enumerate() {
|
||||
let mut t = clicked_row(&cx1);
|
||||
// Dropped at the first poll, before the thread is done.
|
||||
assert!(t.poll(cx2, false).is_empty(), "change {k}: the merge is not applied");
|
||||
assert!(!t.editing() && !t.waiting() && t.shape_builder_merge().is_none(), "change {k}");
|
||||
}
|
||||
// Unchanged, the same wait applies it.
|
||||
let mut t = clicked_row(&cx1);
|
||||
assert_eq!(t.poll(&cx1, true).len(), 1);
|
||||
// A copy of the document at the same revision (a save stamps its dates on a copy), and
|
||||
// finishing the edit before a command, apply it too.
|
||||
let copy = d.clone();
|
||||
let cx3 = ToolContext { revision: (1, 1), ..cx(©, &s, &p) };
|
||||
let mut t = clicked_row(&cx1);
|
||||
assert_eq!(t.finish_edit(&cx3).len(), 1);
|
||||
assert!(!t.editing() && t.shape_builder_merge().is_some());
|
||||
// Switching away applies it.
|
||||
let mut t = clicked_row(&cx1);
|
||||
assert_eq!(t.deactivate(&cx1).len(), 1);
|
||||
assert!(!t.editing());
|
||||
}
|
||||
|
||||
/// A new revision of the document that leaves the selection's inputs as they were (a view
|
||||
/// setting or a preference that redraws it) keeps the merge being computed, the gesture made
|
||||
/// while the map is being built and the map itself: the merge applies with the map it was
|
||||
/// computed over, and no map is built again.
|
||||
#[test]
|
||||
fn shape_builder_keeps_its_work_over_a_new_revision_of_the_same_art() {
|
||||
let (d, s) = square_row(40);
|
||||
let p = paint();
|
||||
let cx1 = ToolContext { revision: (1, 1), ..cx(&d, &s, &p) };
|
||||
let cx2 = ToolContext { revision: (1, 2), ..cx(&d, &s, &p) };
|
||||
// A merge being computed.
|
||||
let computed = merges_computed();
|
||||
let mut t = clicked_row(&cx1);
|
||||
let acts = poll_actions(&mut t, &cx2);
|
||||
assert!(matches!(acts.as_slice(), [Action::Exec(id, _)] if id == "shapeBuilder.merge"), "{acts:?}");
|
||||
assert_eq!(merges_computed(), computed, "the merge computed on another thread");
|
||||
let m = t.shape_builder_merge().expect("the merge the command takes");
|
||||
assert!(Arc::ptr_eq(&m.map, &t.cache.map), "the map the merge was computed over");
|
||||
assert_eq!(t.cache.key.as_ref().map(|k| k.1), Some((1, 2)));
|
||||
assert_eq!(t.cache.builds, 1, "no map built again");
|
||||
// Finishing it before a command too.
|
||||
let mut t = clicked_row(&cx1);
|
||||
assert_eq!(t.finish_edit(&cx2).len(), 1);
|
||||
// A hover over the new revision builds no map.
|
||||
let mut t = ShapeBuilderTool::default();
|
||||
let hover = ev(PointerKind::Move, 15.0, 10.0);
|
||||
t.pointer(&cx1, &hover);
|
||||
poll_until_ready(&mut t, &cx1);
|
||||
t.pointer(&cx2, &hover);
|
||||
assert!(!t.waiting() && matches!(t.hover, Some(Hit::Region(_))), "{:?}", t.hover);
|
||||
assert_eq!(t.cache.builds, 1);
|
||||
// A map being built, and a gesture made meanwhile.
|
||||
let drag = [ev(PointerKind::Down, 15.0, 10.0), ev(PointerKind::Drag, 35.0, 10.0), ev(PointerKind::Up, 35.0, 10.0)];
|
||||
let mut ready = ShapeBuilderTool::default();
|
||||
ready.pointer(&cx1, &hover);
|
||||
poll_until_ready(&mut ready, &cx1);
|
||||
for e in &drag {
|
||||
ready.pointer(&cx1, e);
|
||||
}
|
||||
let want = poll_actions(&mut ready, &cx1);
|
||||
let mut t = ShapeBuilderTool::default();
|
||||
t.pointer(&cx1, &hover);
|
||||
for e in &drag {
|
||||
assert!(t.pointer(&cx1, e).is_empty());
|
||||
}
|
||||
assert!(t.editing() && t.cache.builds == 0, "the gesture waits for the map");
|
||||
assert_eq!(poll_actions(&mut t, &cx2), want);
|
||||
assert_eq!((t.cache.builds, t.cache.background), (1, 1), "the map built for the first revision");
|
||||
// Finishing it before a command waits for the map being built rather than building it again.
|
||||
let mut t = ShapeBuilderTool::default();
|
||||
t.pointer(&cx1, &hover);
|
||||
for e in &drag {
|
||||
t.pointer(&cx1, e);
|
||||
}
|
||||
assert_eq!(t.finish_edit(&cx2), want);
|
||||
assert_eq!((t.cache.builds, t.cache.background), (1, 1), "the map built on the other thread");
|
||||
// Another document with the same art drops the merge.
|
||||
let cx3 = ToolContext { revision: (2, 1), ..cx(&d, &s, &p) };
|
||||
let mut t = clicked_row(&cx1);
|
||||
assert!(t.poll(&cx3, false).is_empty());
|
||||
assert!(!t.editing());
|
||||
}
|
||||
|
||||
/// A press while the map of a large selection is being built on another thread does not wait
|
||||
/// for it: the gesture is recorded, each event returns at once, and the polls replay it once
|
||||
/// the map is there, giving the merge the same gesture gives over the map. Finishing the edit
|
||||
/// waits for the map and the merge; another revision of other art drops the gesture.
|
||||
#[test]
|
||||
fn shape_builder_gesture_waits_for_the_map_without_holding_the_caller() {
|
||||
let (d, s) = square_row(200);
|
||||
let p = paint();
|
||||
let cx1 = ToolContext { revision: (1, 1), ..cx(&d, &s, &p) };
|
||||
let hover = ev(PointerKind::Move, 15.0, 10.0);
|
||||
let drag = [ev(PointerKind::Down, 15.0, 10.0), ev(PointerKind::Drag, 35.0, 10.0), ev(PointerKind::Up, 35.0, 10.0)];
|
||||
let mut ready = ShapeBuilderTool::default();
|
||||
ready.pointer(&cx1, &hover);
|
||||
poll_until_ready(&mut ready, &cx1);
|
||||
for e in &drag {
|
||||
ready.pointer(&cx1, e);
|
||||
}
|
||||
let want = poll_actions(&mut ready, &cx1);
|
||||
assert!(matches!(want.as_slice(), [Action::Exec(id, _)] if id == "shapeBuilder.merge"), "{want:?}");
|
||||
let made_while_building = || {
|
||||
let mut t = ShapeBuilderTool::default();
|
||||
t.pointer(&cx1, &hover);
|
||||
for e in &drag {
|
||||
assert!(t.pointer(&cx1, e).is_empty());
|
||||
}
|
||||
assert_eq!(t.cache.builds, 0, "the gesture did not wait for the map");
|
||||
assert!(t.editing() && t.waiting());
|
||||
t
|
||||
};
|
||||
let mut t = made_while_building();
|
||||
assert_eq!(t.cursor(&cx1, Point::new(35.0, 10.0), Mods::default()), Cursor::Busy);
|
||||
// A press before the gesture is replayed starts nothing.
|
||||
assert!(t.pointer(&cx1, &ev(PointerKind::Down, 55.0, 10.0)).is_empty());
|
||||
assert!(t.pointer(&cx1, &ev(PointerKind::Up, 55.0, 10.0)).is_empty());
|
||||
assert_eq!(poll_actions(&mut t, &cx1), want);
|
||||
assert!(!t.editing() && t.shape_builder_merge().is_some());
|
||||
// Finishing the edit before a command waits for both.
|
||||
let mut t = made_while_building();
|
||||
assert_eq!(t.finish_edit(&cx1), want);
|
||||
// Another revision of other art before the map is there drops the gesture.
|
||||
let mut t = made_while_building();
|
||||
let (moved, _) = square_row_at(200, 5.0);
|
||||
let cx2 = ToolContext { revision: (1, 2), ..cx(&moved, &s, &p) };
|
||||
assert!(t.poll(&cx2, false).is_empty());
|
||||
assert!(!t.editing());
|
||||
}
|
||||
|
||||
/// Escape during a drag made while the map of a large selection is being built cancels the
|
||||
/// recorded gesture too: the release and the polls after it merge nothing, the tool stops
|
||||
/// waiting once the map is there, and the next drag merges on its own.
|
||||
#[test]
|
||||
fn shape_builder_escape_cancels_a_gesture_made_while_the_map_is_built() {
|
||||
let (d, s) = square_row(200);
|
||||
let p = paint();
|
||||
let cx1 = ToolContext { revision: (1, 1), ..cx(&d, &s, &p) };
|
||||
let mut t = ShapeBuilderTool::default();
|
||||
t.pointer(&cx1, &ev(PointerKind::Move, 15.0, 10.0));
|
||||
assert!(t.pointer(&cx1, &ev(PointerKind::Down, 15.0, 10.0)).is_empty());
|
||||
assert!(t.pointer(&cx1, &ev(PointerKind::Drag, 35.0, 10.0)).is_empty());
|
||||
assert_eq!(t.cache.builds, 0, "the gesture did not wait for the map");
|
||||
assert!(t.claims_key(&cx1, ToolKey::Escape));
|
||||
assert!(t.key(&cx1, ToolKey::Escape, Mods::default()).is_empty());
|
||||
assert!(t.pointer(&cx1, &ev(PointerKind::Up, 35.0, 10.0)).is_empty());
|
||||
assert!(poll_actions(&mut t, &cx1).is_empty(), "the canceled gesture merges nothing");
|
||||
assert!(!t.waiting() && !t.editing());
|
||||
// The next drag merges what it touches, with no event of the canceled one.
|
||||
let mut fresh = ShapeBuilderTool::default();
|
||||
fresh.pointer(&cx1, &ev(PointerKind::Move, 55.0, 10.0));
|
||||
poll_until_ready(&mut fresh, &cx1);
|
||||
let next = [ev(PointerKind::Down, 55.0, 10.0), ev(PointerKind::Drag, 75.0, 10.0), ev(PointerKind::Up, 75.0, 10.0)];
|
||||
for e in &next {
|
||||
fresh.pointer(&cx1, e);
|
||||
t.pointer(&cx1, e);
|
||||
}
|
||||
assert_eq!(poll_actions(&mut t, &cx1), poll_actions(&mut fresh, &cx1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shape_builder_hover_builds_a_small_map_at_once() {
|
||||
let (d, s) = square_row(3);
|
||||
@@ -1110,9 +1361,15 @@ fn bucket_keeps_its_map_while_the_document_is_unchanged() {
|
||||
// The fill left the document as it was: the map still fits it.
|
||||
t.pointer(&cx1, &ev(PointerKind::Move, 25.0, 50.0));
|
||||
assert_eq!(t.cache.builds, 1, "a hover after a fill that changed nothing");
|
||||
// A new revision of the same art keeps the map; one with an object moved builds it again.
|
||||
let cx2 = ToolContext { revision: (1, 2), ..cx(&d, &s, &p) };
|
||||
t.pointer(&cx2, &ev(PointerKind::Move, 25.0, 50.0));
|
||||
assert_eq!(t.cache.builds, 2, "a hover on a new revision");
|
||||
assert_eq!(t.cache.builds, 1, "a hover on a new revision of the same art");
|
||||
let mut moved = d.clone();
|
||||
moved.node_mut(b).unwrap().transform(vectorcraft_geom::Affine::translate((10.0, 0.0)), false);
|
||||
let cx3 = ToolContext { revision: (1, 3), ..cx(&moved, &s, &p) };
|
||||
t.pointer(&cx3, &ev(PointerKind::Move, 25.0, 50.0));
|
||||
assert_eq!(t.cache.builds, 2, "a hover on a new revision of other art");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+26
-6
@@ -267,21 +267,41 @@ pub trait Tool: Send {
|
||||
false
|
||||
}
|
||||
/// Is the tool waiting for work it runs on another thread (the planar map of a large selection
|
||||
/// for the Shape Builder and the Live Paint Bucket)? It highlights no region under the pointer
|
||||
/// until the work is done. While this holds, the desktop app calls [`Tool::poll`] each frame,
|
||||
/// and hosts without frames call it with `wait` after a [`PointerKind::Move`].
|
||||
/// for the Shape Builder and the Live Paint Bucket, a Shape Builder merge of one)? It
|
||||
/// highlights nothing under the pointer until a map is done. While this holds, the desktop app
|
||||
/// calls [`Tool::poll`] each frame, and hosts without frames call it with `wait` after each
|
||||
/// pointer event.
|
||||
fn waiting(&self) -> bool {
|
||||
false
|
||||
}
|
||||
/// Checks on the work [`Tool::waiting`] reports, waiting for it to finish with `wait`. Once it
|
||||
/// is done, the tool shows the highlight under the pointer where it last moved.
|
||||
fn poll(&mut self, _cx: &ToolContext, _wait: bool) {}
|
||||
/// Is the tool computing an edit on another thread, which [`Tool::poll`] applies once it is
|
||||
/// done (a Shape Builder merge of a large selection)?
|
||||
fn editing(&self) -> bool {
|
||||
false
|
||||
}
|
||||
/// Checks on the work [`Tool::waiting`] reports, waiting for it to finish with `wait`. Once a
|
||||
/// map is done, the tool shows the highlight under the pointer where it last moved; once an
|
||||
/// edit is done, the actions returned apply it.
|
||||
fn poll(&mut self, _cx: &ToolContext, _wait: bool) -> Vec<Action> {
|
||||
vec![]
|
||||
}
|
||||
/// Waits for the edit [`Tool::editing`] reports and returns the actions that apply it, before
|
||||
/// a command runs on the document; none when the document's revision or the selection changed
|
||||
/// since the gesture.
|
||||
fn finish_edit(&mut self, _cx: &ToolContext) -> Vec<Action> {
|
||||
vec![]
|
||||
}
|
||||
/// The Shape Builder's planar map of the selection, with the outline edges, and the gap it
|
||||
/// closes, when the tool has one. `shapeBuilder.merge` uses it in place of a map of its own
|
||||
/// when the map's inputs are the merge's inputs.
|
||||
fn shape_builder_map(&self) -> Option<(std::sync::Arc<builder::BuilderMap>, f64)> {
|
||||
None
|
||||
}
|
||||
/// The Shape Builder merge the tool computed on another thread for its last gesture, which
|
||||
/// `shapeBuilder.merge` takes when it would compute the same ([`builder::PreparedMerge`]).
|
||||
fn shape_builder_merge(&self) -> Option<std::sync::Arc<builder::PreparedMerge>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a tool by id. Unknown or not-yet-implemented tools fall back to a no-op tool that keeps the id.
|
||||
|
||||
@@ -110,6 +110,7 @@ impl VectorcraftApp {
|
||||
deferred_control: None,
|
||||
synthetic_dropped_before: 0,
|
||||
pending_screenshots: vec![],
|
||||
pointer_replies: vec![],
|
||||
queued_screenshots: vec![],
|
||||
screenshot_token: 0,
|
||||
screenshot_reserved: 0,
|
||||
@@ -337,8 +338,9 @@ impl VectorcraftApp {
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(100));
|
||||
}
|
||||
// The window's close button (or the system quitting the app) asks about unsaved documents,
|
||||
// once the saves running in the background are done. Not while a file dialog's sheet is on
|
||||
// the window: what asked for it runs again when it answers.
|
||||
// once the saves running in the background are done and a Shape Builder merge being
|
||||
// computed is applied. Not while a file dialog's sheet is on the window: what asked for it
|
||||
// runs again when it answers.
|
||||
if ctx.input(|i| i.viewport().close_requested()) {
|
||||
// This native viewport is going away: release its IME context. No request is
|
||||
// allocated here: the close prompt or file sheet publishes no custom descriptor, so a
|
||||
@@ -346,7 +348,7 @@ impl VectorcraftApp {
|
||||
// fresh generation on the next pass (never inherits a composition across the prompt).
|
||||
crate::ime::close_viewport(self, ctx);
|
||||
self.ime_context.end_viewport(ctx.viewport_id());
|
||||
background::wait_all(self);
|
||||
unsaved::finish_pending(self);
|
||||
if self.file_sheet_open() {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
|
||||
self.status(picks::busy());
|
||||
@@ -374,6 +376,7 @@ impl VectorcraftApp {
|
||||
crate::chrome::sync_window_title(self, ctx);
|
||||
crate::chrome::sync_fullscreen(self, ctx);
|
||||
self.drain_control(ctx);
|
||||
self.answer_pointer_replies(ctx);
|
||||
// An egui `PasteImage` with a rich system clipboard: run the paste command now, once. It
|
||||
// goes through `run`, whose `edit.paste` branch calls `adopt_system_clipboard` (which clears
|
||||
// the request) to read the formats and then pastes them. A text paste in the same UI pass
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::fonts::MAX_RECENT_FONTS;
|
||||
use super::{Value, VectorcraftApp, dialogs, fileio, io, menus, panels, picks, toolbar};
|
||||
use super::{Value, VectorcraftApp, canvas, dialogs, fileio, io, menus, panels, picks, toolbar};
|
||||
use crate::placing;
|
||||
use crate::state::ReplaceFontWarning;
|
||||
|
||||
@@ -94,6 +94,17 @@ impl VectorcraftApp {
|
||||
result
|
||||
}
|
||||
|
||||
/// A command that waits for the edit the tool computes on another thread and the input held
|
||||
/// for it waits before the app adds the view's active artboard to its params: a held press
|
||||
/// may change it. The app's own commands (its dialogs, panels and view) wait too.
|
||||
fn wait_for_tool_edit(&mut self, id: &str) {
|
||||
let ui_command = vectorcraft_engine::find_command(id).is_none();
|
||||
if (ui_command || vectorcraft_engine::waits_for_tool_edit(id)) && self.session.tool_waiting() {
|
||||
let r = self.session.finish_tool_edit();
|
||||
canvas::apply_requests(self, r);
|
||||
}
|
||||
}
|
||||
|
||||
/// [`Self::run`] it, inside what asks for file dialogs.
|
||||
fn run_now(&mut self, id: &str, params: Value) -> Result<Value, String> {
|
||||
crate::state::sync_zoom_stops_display_print_size(self.session.prefs.display_print_size);
|
||||
@@ -104,6 +115,7 @@ impl VectorcraftApp {
|
||||
if cfg!(debug_assertions) && !self.session.replaying() {
|
||||
menus::check_params(&self.session, id, ¶ms)?;
|
||||
}
|
||||
self.wait_for_tool_edit(id);
|
||||
// A `.ai` file a command writes (a save, an export, a timestamped copy, a batch's save) names
|
||||
// the view's active artboard.
|
||||
io::remember_active_artboard(self);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::{
|
||||
MAX_PENDING_SCREENSHOTS, MAX_SCREENSHOT_BYTES, MAX_SCREENSHOT_TOTAL_BYTES, PendingScreenshot, QueuedScreenshot, SCREENSHOT_TIMEOUT_MS,
|
||||
VectorcraftApp, file_access, json, now_ms,
|
||||
VectorcraftApp, canvas, file_access, json, now_ms,
|
||||
};
|
||||
use crate::control;
|
||||
|
||||
@@ -112,6 +112,9 @@ impl VectorcraftApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
control::Outcome::AfterToolEdit { from, to, document } => {
|
||||
self.pointer_replies.push(control::PendingPointerReply { from, to, document, reply });
|
||||
}
|
||||
}
|
||||
}
|
||||
if handled == control::MAX_CONTROL_REQUESTS_PER_FRAME {
|
||||
@@ -121,6 +124,38 @@ impl VectorcraftApp {
|
||||
self.control_rx = Some(rx);
|
||||
}
|
||||
|
||||
/// Sends the `ui.pointer` replies that wait for the tool's edit once their events have been
|
||||
/// made and the edit is applied. The canvas checks on the tool each frame it is drawn; this
|
||||
/// checks too, for frames without it.
|
||||
pub(crate) fn answer_pointer_replies(&mut self, ctx: &egui::Context) {
|
||||
// Those whose events the canvas's check made go first, before this check makes the input
|
||||
// held after them.
|
||||
self.send_pointer_replies();
|
||||
if self.pointer_replies.is_empty() {
|
||||
return;
|
||||
}
|
||||
if self.session.tool_editing() {
|
||||
let r = self.session.tool_poll(self.view_info(), false);
|
||||
canvas::apply_requests(self, r);
|
||||
}
|
||||
self.send_pointer_replies();
|
||||
if !self.pointer_replies.is_empty() {
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(16));
|
||||
}
|
||||
}
|
||||
|
||||
/// Sends the waiting `ui.pointer` replies whose events have been made.
|
||||
fn send_pointer_replies(&mut self) {
|
||||
for pending in std::mem::take(&mut self.pointer_replies) {
|
||||
let control::PendingPointerReply { from, to, document, reply } = pending;
|
||||
if self.session.input_applied(from, to) {
|
||||
let _ = reply.send(control::pointer_reply_for(self, document));
|
||||
} else {
|
||||
self.pointer_replies.push(control::PendingPointerReply { from, to, document, reply });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The active document's identity: its process-unique uid and revision. A capture records it
|
||||
/// at admission and issuance and refuses to answer with a different document or undo state.
|
||||
pub(super) fn document_identity(&self) -> Option<(u64, u64)> {
|
||||
|
||||
@@ -376,19 +376,29 @@ pub fn dispatch(app: &mut VectorcraftApp, ev: &PointerEvent, view: vectorcraft_e
|
||||
{
|
||||
v.artboard = i;
|
||||
}
|
||||
// A press with a selection tool inside an artboard makes it the active one (#693), as the
|
||||
// Artboard tool's does: Paste in Place and in Front or Back then paste onto it, Align to
|
||||
// Artboard aligns to it, and All on Active Artboard selects on it.
|
||||
if ev.kind == PointerKind::Down
|
||||
&& vectorcraft_tools::catalog::is_selection_tool(app.session.tool_id())
|
||||
&& let Some(i) = app.session.active().and_then(|d| d.doc.artboard_at(ev.pos))
|
||||
&& let Some(v) = app.view_mut()
|
||||
{
|
||||
v.artboard = i;
|
||||
if ev.kind == PointerKind::Down {
|
||||
pressed_with(app, app.session.active_index(), ev.pos, app.session.tool_id());
|
||||
}
|
||||
apply_requests(app, r);
|
||||
}
|
||||
|
||||
/// A press at `pos` in document `index` with tool `tool` (a selection tool) inside an artboard
|
||||
/// makes it that document's active one (#693), as the Artboard tool's does: Paste in Place and in
|
||||
/// Front or Back then paste onto it, Align to Artboard aligns to it, and All on Active Artboard
|
||||
/// selects on it.
|
||||
fn pressed_with(app: &mut VectorcraftApp, index: Option<usize>, pos: Point, tool: &str) {
|
||||
if !vectorcraft_tools::catalog::is_selection_tool(tool) {
|
||||
return;
|
||||
}
|
||||
app.sync_views();
|
||||
if let Some(i) = index
|
||||
&& let Some(board) = app.session.documents().get(i).and_then(|d| d.doc.artboard_at(pos))
|
||||
&& let Some(v) = app.views.get_mut(i)
|
||||
{
|
||||
v.artboard = board;
|
||||
}
|
||||
}
|
||||
|
||||
/// Act on what a tool event asked the UI for (dialogs, tool switches), or show its error.
|
||||
pub fn apply_requests(app: &mut VectorcraftApp, r: vectorcraft_engine::Result<Vec<vectorcraft_engine::UiRequest>>) {
|
||||
match r {
|
||||
@@ -399,6 +409,15 @@ pub fn apply_requests(app: &mut VectorcraftApp, r: vectorcraft_engine::Result<Ve
|
||||
vectorcraft_engine::UiRequest::SwitchTool(t) => app.select_tool(&t),
|
||||
vectorcraft_engine::UiRequest::Status(msg) => app.status(msg),
|
||||
vectorcraft_engine::UiRequest::Place(p) => crate::place::place_from_cursor(app, &p),
|
||||
// In the document the press was made in, which may no longer be the active one.
|
||||
vectorcraft_engine::UiRequest::HeldPress { doc, pos, tool } => {
|
||||
let index = doc.and_then(|uid| app.session.documents().iter().position(|d| d.uid == uid));
|
||||
pressed_with(app, index, pos, tool);
|
||||
// The selection tool Cmd lent has the press now, so its drag can carry art to another tab.
|
||||
if let Some(ctx) = app.ui_ctx.clone() {
|
||||
crate::document_drag::begin(app, &ctx, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,12 +147,12 @@ pub(super) fn handle_input(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Respo
|
||||
app.session.tool_hover_ended(view);
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
// The tool works on another thread (a large selection's planar map): it checks each frame
|
||||
// whether the work is done, and then shows the highlight under the pointer.
|
||||
// The tool works on another thread (a large selection's planar map or merge): it checks each
|
||||
// frame whether the work is done, and then shows the highlight under the pointer or applies
|
||||
// the edit.
|
||||
if app.session.tool_waiting() {
|
||||
if let Err(e) = app.session.tool_poll(view, false) {
|
||||
app.status(e.to_string());
|
||||
}
|
||||
let r = app.session.tool_poll(view, false);
|
||||
apply_requests(app, r);
|
||||
ui.ctx().request_repaint_after(std::time::Duration::from_millis(16));
|
||||
}
|
||||
if pointer.primary_released()
|
||||
|
||||
@@ -96,6 +96,13 @@ fn reserve_synthetic(app: &mut VectorcraftApp, additional: usize) -> Result<(),
|
||||
|
||||
pub type ControlResponse = Value;
|
||||
|
||||
pub(crate) struct PendingPointerReply {
|
||||
pub from: u64,
|
||||
pub to: u64,
|
||||
pub document: Option<u64>,
|
||||
pub reply: Sender<ControlResponse>,
|
||||
}
|
||||
|
||||
pub struct ControlRequest {
|
||||
pub method: String,
|
||||
pub params: Value,
|
||||
@@ -167,6 +174,34 @@ pub enum Outcome {
|
||||
path: Option<String>,
|
||||
data: bool,
|
||||
},
|
||||
/// A `ui.pointer` reply ([`pointer_reply`]), sent once the events numbered `from..to`
|
||||
/// ([`vectorcraft_engine::Session::input_applied`]) have been made and the edit they started
|
||||
/// on another thread is applied, so it shows the selection after the edit.
|
||||
AfterToolEdit {
|
||||
from: u64,
|
||||
to: u64,
|
||||
document: Option<u64>,
|
||||
},
|
||||
}
|
||||
|
||||
/// The reply to `ui.pointer`: the selection, the key object and the active tool.
|
||||
pub(crate) fn pointer_reply(app: &mut VectorcraftApp) -> Value {
|
||||
pointer_reply_for(app, app.session.active().map(|d| d.uid))
|
||||
}
|
||||
|
||||
pub(crate) fn pointer_reply_for(app: &VectorcraftApp, document: Option<u64>) -> Value {
|
||||
let state = document.and_then(|uid| app.session.documents().iter().find(|d| d.uid == uid));
|
||||
match state {
|
||||
Some(state) => json!({
|
||||
"ok": true,
|
||||
"result": {
|
||||
"selection": state.selection.objects.iter().map(|id| id.0).collect::<Vec<_>>(),
|
||||
"key": state.selection.key.map(|id| id.0),
|
||||
"tool": app.session.tool_id(),
|
||||
}
|
||||
}),
|
||||
None => json!({"ok": false, "error": "the gesture's document is no longer open"}),
|
||||
}
|
||||
}
|
||||
|
||||
fn ok(v: Value) -> Outcome {
|
||||
@@ -470,10 +505,9 @@ pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context, req: &ControlReques
|
||||
o.remove("wait");
|
||||
}
|
||||
let method = req.method.as_str();
|
||||
// The key check of `document.export` runs before the file is written.
|
||||
if method == "app.export"
|
||||
&& let Err(e) = crate::menus::check_params(&app.session, "document.export", &p)
|
||||
{
|
||||
// The key check of `document.export` or `document.save` runs before the file is written.
|
||||
let checked = if method == "app.export" { "document.export" } else { "document.save" };
|
||||
if let Err(e) = crate::menus::check_params(&app.session, checked, &p) {
|
||||
return err(e);
|
||||
}
|
||||
wrap(if wait { crate::background::in_foreground(app, |app| save_or_export(app, method, &p)) } else { save_or_export(app, method, &p) })
|
||||
@@ -581,6 +615,7 @@ fn pointer_events(app: &mut VectorcraftApp, ctx: &egui::Context, req: &ControlRe
|
||||
let base_mods: Mods = p.get("mods").and_then(|m| serde_json::from_value(m.clone()).ok()).unwrap_or_default();
|
||||
let view = app.view_info();
|
||||
let xf = app.canvas_rect.zip(app.view().copied()).map(|(rect, v)| Xf::new(rect, &v));
|
||||
let from = app.session.input_count();
|
||||
let held =
|
||||
PointerEvent::json_backquote(p, false).and_then(|d| events.iter().map(|e| PointerEvent::json_backquote(e, d)).collect::<Result<Vec<_>, _>>());
|
||||
let held = match held {
|
||||
@@ -621,7 +656,15 @@ fn pointer_events(app: &mut VectorcraftApp, ctx: &egui::Context, req: &ControlRe
|
||||
}
|
||||
}
|
||||
ctx.request_repaint();
|
||||
wrap(app.run("document.inspect", json!({})).map(|d| json!({"selection": d["selection"], "key": d["key"], "tool": app.session.tool_id()})))
|
||||
// A Shape Builder merge of a large selection is computed on another thread, and the
|
||||
// reply to the events that started it waits for it without holding the frames up. A
|
||||
// gesture sent while it is computed is made after it, and its reply waits until then;
|
||||
// a hover is answered at once.
|
||||
let to = app.session.input_count();
|
||||
if !app.session.input_applied(from, to) {
|
||||
return Outcome::AfterToolEdit { from, to, document: app.session.active().map(|d| d.uid) };
|
||||
}
|
||||
Outcome::Done(pointer_reply(app))
|
||||
}
|
||||
|
||||
/// `ui.click` and `ui.drag`: pointer input through egui itself.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_engine::Session;
|
||||
use vectorcraft_tools::{Mods, PointerEvent, PointerKind};
|
||||
|
||||
use super::{ControlRequest, MAX_DIALOG_FIELDS, Outcome, handle};
|
||||
use crate::state::Dialog;
|
||||
@@ -11,6 +12,27 @@ fn input_request(app: &mut VectorcraftApp, method: &str, params: Value) -> Value
|
||||
r
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deferred_pointer_reply_uses_the_gesture_document_after_file_new() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Services::default());
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
let id = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 40})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
let (reply, received) = std::sync::mpsc::channel();
|
||||
let at = app.session.input_count();
|
||||
app.pointer_replies.push(super::PendingPointerReply { from: at, to: at, document: app.session.active().map(|d| d.uid), reply });
|
||||
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.run("tool.select", json!({"tool": "rectangle"})).unwrap();
|
||||
app.answer_pointer_replies(&egui::Context::default());
|
||||
|
||||
let result = received.try_recv().unwrap();
|
||||
assert_eq!(result["ok"], true, "{result}");
|
||||
assert_eq!(result["result"]["selection"], json!([id]));
|
||||
assert_eq!(result["result"]["key"], Value::Null);
|
||||
assert_eq!(result["result"]["tool"], "rectangle");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn control_lists_and_selects_optional_addon_tools() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Services::default());
|
||||
@@ -338,6 +360,263 @@ fn pointer_replies_name_the_key_object() {
|
||||
assert_eq!(click(&mut app), Some(Value::Null), "a click on the key again lets it go");
|
||||
}
|
||||
|
||||
/// A Shape Builder click on a large selection merges on another thread: the frames go on, and
|
||||
/// the `ui.pointer` reply comes once the merge is applied, with the selection after it.
|
||||
#[test]
|
||||
fn pointer_reply_waits_for_a_merge_on_another_thread() {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let mut app = VectorcraftApp::new(Session::new(), Services::default()).with_control(rx);
|
||||
app.run("file.new", json!({"width": 800, "height": 200})).unwrap();
|
||||
for k in 0..40 {
|
||||
app.run("shape.rectangle", json!({"x": k * 10, "y": 0, "width": 20, "height": 20})).unwrap();
|
||||
}
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
app.run("tool.select", json!({"tool": "shapeBuilder"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let send = |app: &mut VectorcraftApp, events: Value| {
|
||||
let (req, reply) = ControlRequest::new("ui.pointer", json!({"events": events}));
|
||||
tx.send(req).unwrap();
|
||||
app.drain_control(&ctx);
|
||||
reply
|
||||
};
|
||||
let hover = send(&mut app, json!([{"kind": "move", "x": 15, "y": 10}]));
|
||||
assert_eq!(hover.try_recv().unwrap()["ok"], true, "a hover is answered at once");
|
||||
app.session.tool_poll(app.view_info(), true).unwrap();
|
||||
let revision = app.session.active().unwrap().revision;
|
||||
let click = send(&mut app, json!([{"kind": "down", "x": 15, "y": 10}, {"kind": "up", "x": 15, "y": 10}]));
|
||||
assert!(click.try_recv().is_err() && app.session.tool_editing(), "the click is not answered before the merge is applied");
|
||||
// A hover sent meanwhile is answered at once; a click is made after the merge, and its
|
||||
// reply waits until then.
|
||||
let hover = send(&mut app, json!([{"kind": "move", "x": 35, "y": 10}]));
|
||||
assert_eq!(hover.try_recv().map(|r| r["ok"].clone()), Ok(json!(true)), "a hover during the merge");
|
||||
let cmd = json!({"cmd": true});
|
||||
let press = send(&mut app, json!([{"kind": "down", "x": 500, "y": 150, "mods": cmd}, {"kind": "up", "x": 500, "y": 150, "mods": cmd}]));
|
||||
assert!(press.try_recv().is_err(), "a Cmd-click during the merge waits for it");
|
||||
let hover = send(&mut app, json!([{"kind": "move", "x": 45, "y": 10}]));
|
||||
assert_eq!(hover.try_recv().map(|r| r["ok"].clone()), Ok(json!(true)), "a hover after the held Cmd-click");
|
||||
let start = std::time::Instant::now();
|
||||
let reply = loop {
|
||||
if let Ok(r) = click.try_recv() {
|
||||
break r;
|
||||
}
|
||||
assert!(app.session.tool_editing(), "the merge is being computed until the reply goes");
|
||||
assert_eq!(app.session.active().unwrap().revision, revision);
|
||||
assert!(start.elapsed() < std::time::Duration::from_secs(60), "no reply");
|
||||
std::thread::sleep(std::time::Duration::from_millis(2));
|
||||
// A frame: the canvas checks on the tool, then the replies are answered.
|
||||
let r = app.session.tool_poll(app.view_info(), false);
|
||||
crate::canvas::apply_requests(&mut app, r);
|
||||
app.answer_pointer_replies(&ctx);
|
||||
};
|
||||
assert_eq!(reply["ok"], true, "{reply}");
|
||||
assert_eq!(reply["result"]["selection"].as_array().map(Vec::len), Some(41), "{reply}: the selection after the merge");
|
||||
assert_ne!(app.session.active().unwrap().revision, revision);
|
||||
let press = loop {
|
||||
if let Ok(r) = press.try_recv() {
|
||||
break r;
|
||||
}
|
||||
assert!(start.elapsed() < std::time::Duration::from_secs(60), "no reply to the Cmd-click");
|
||||
let r = app.session.tool_poll(app.view_info(), false);
|
||||
crate::canvas::apply_requests(&mut app, r);
|
||||
app.answer_pointer_replies(&ctx);
|
||||
};
|
||||
assert_eq!(press["result"]["selection"].as_array().map(Vec::len), Some(0), "{press}: the lent selection tool deselected after the merge");
|
||||
assert_eq!(press["result"]["tool"], "shapeBuilder", "{press}");
|
||||
}
|
||||
|
||||
/// A Cmd-click held while a Shape Builder merge is computed on another thread makes the artboard
|
||||
/// it lands in active once it is made, as a Cmd-click made at once does: by the frames' checks,
|
||||
/// by choosing another tool first, or before a command that acts on the active artboard takes
|
||||
/// it.
|
||||
#[test]
|
||||
fn a_held_cmd_click_makes_its_artboard_active() {
|
||||
for then in ["frames", "another tool", "All on Active Artboard", "another document"] {
|
||||
held_cmd_click(then);
|
||||
}
|
||||
}
|
||||
|
||||
fn held_cmd_click(then: &str) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Services::default());
|
||||
if then == "another document" {
|
||||
// A document with an artboard where the press is, whose view keeps its own.
|
||||
app.run("file.new", json!({"width": 1400, "height": 200})).unwrap();
|
||||
app.run("artboard.new", json!({"x": 1000, "y": 0, "width": 300, "height": 200})).unwrap();
|
||||
app.view_mut().unwrap().artboard = 0;
|
||||
}
|
||||
app.run("file.new", json!({"width": 800, "height": 200})).unwrap();
|
||||
app.run("artboard.new", json!({"x": 1000, "y": 0, "width": 300, "height": 200})).unwrap();
|
||||
for k in 0..40 {
|
||||
app.run("shape.rectangle", json!({"x": k * 10, "y": 0, "width": 20, "height": 20})).unwrap();
|
||||
}
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
app.run("tool.select", json!({"tool": "shapeBuilder"})).unwrap();
|
||||
app.view_mut().unwrap().artboard = 0;
|
||||
let view = app.view_info();
|
||||
let at = |kind, x, mods| PointerEvent { kind, pos: vectorcraft_geom::Point::new(x, 10.0), mods, pressure: 1.0, backquote: false, pen: None };
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Move, 15.0, Mods::default()), view);
|
||||
app.session.tool_poll(view, true).unwrap();
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Down, 15.0, Mods::default()), view);
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Up, 15.0, Mods::default()), view);
|
||||
let cmd = Mods { cmd: true, ..Default::default() };
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Down, 1100.0, cmd), view);
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Up, 1100.0, cmd), view);
|
||||
assert_eq!(app.view().unwrap().artboard, 0, "{then}: the Cmd-click is held");
|
||||
if then == "another tool" {
|
||||
app.select_tool("rectangle");
|
||||
assert!(!app.session.tool_editing(), "{then}");
|
||||
}
|
||||
if then == "All on Active Artboard" {
|
||||
app.run("select.allOnArtboard", json!({})).unwrap();
|
||||
assert!(app.session.doc().unwrap().selection.is_empty(), "{then}: the second artboard, which holds no art");
|
||||
}
|
||||
let doc = app.session.active_index().unwrap();
|
||||
if then == "another document" {
|
||||
// A document tab chosen.
|
||||
app.session.set_active(0);
|
||||
}
|
||||
while app.session.tool_waiting() {
|
||||
let r = app.session.tool_poll(view, true);
|
||||
crate::canvas::apply_requests(&mut app, r);
|
||||
}
|
||||
app.sync_views();
|
||||
assert_eq!(app.views[doc].artboard, 1, "{then}: the Cmd-click made the artboard it landed in active");
|
||||
if then == "another document" {
|
||||
assert_eq!(app.views[0].artboard, 0, "{then}: the other document's view keeps its artboard");
|
||||
}
|
||||
}
|
||||
|
||||
/// A dialog chosen from the menu, or with `ui.menuDialog`, while a Shape Builder merge is
|
||||
/// computed on another thread opens after the merge is applied, on the merged art. So do the
|
||||
/// app's own dialogs (Recolor Artwork), from the menu or a panel's button.
|
||||
#[test]
|
||||
fn menu_dialogs_open_after_a_merge_on_another_thread() {
|
||||
for route in ["menu", "ui.menuDialog", "app dialog from the menu", "app dialog from a panel"] {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Services::default());
|
||||
app.run("file.new", json!({"width": 800, "height": 200})).unwrap();
|
||||
for k in 0..40 {
|
||||
app.run("shape.rectangle", json!({"x": k * 10, "y": 0, "width": 20, "height": 20})).unwrap();
|
||||
}
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
app.run("tool.select", json!({"tool": "shapeBuilder"})).unwrap();
|
||||
let view = app.view_info();
|
||||
let at = |kind| PointerEvent {
|
||||
kind,
|
||||
pos: vectorcraft_geom::Point::new(15.0, 10.0),
|
||||
mods: Mods::default(),
|
||||
pressure: 1.0,
|
||||
backquote: false,
|
||||
pen: None,
|
||||
};
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Move), view);
|
||||
app.session.tool_poll(view, true).unwrap();
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Down), view);
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Up), view);
|
||||
assert!(app.session.tool_editing(), "{route}");
|
||||
match route {
|
||||
"menu" => crate::menus::invoke(&mut app, "object.move", json!({})),
|
||||
"ui.menuDialog" => {
|
||||
app.run("ui.menuDialog", json!({"command": "object.move"})).unwrap();
|
||||
}
|
||||
"app dialog from the menu" => crate::menus::invoke(&mut app, "ui.recolorDialog", json!({})),
|
||||
_ => {
|
||||
app.run("ui.recolorDialog", json!({})).unwrap();
|
||||
}
|
||||
}
|
||||
assert!(app.ui.dialog.is_some(), "{route}: the dialog is open");
|
||||
assert!(!app.session.tool_editing(), "{route}");
|
||||
let merged = app.session.doc().unwrap().history.undo.last().map(|e| e.label.clone());
|
||||
assert_eq!(merged.as_deref(), Some("Shape Builder"), "{route}");
|
||||
assert_eq!(app.session.doc().unwrap().selection.objects.len(), 41, "{route}: the dialog acts on the merged art");
|
||||
}
|
||||
}
|
||||
|
||||
/// The Separations panel's checkboxes and a preference set while a Shape Builder merge is
|
||||
/// computed on another thread give the documents new revisions: the merge is applied first,
|
||||
/// and the document keeps it.
|
||||
#[test]
|
||||
fn panels_that_redraw_apply_a_merge_on_another_thread_first() {
|
||||
let cases = [
|
||||
("view.separationsPreview", json!({"on": false})),
|
||||
("view.overprintPreview", json!({"on": false})),
|
||||
("prefs.set", json!({"values": {"gridlineEvery": 90}})),
|
||||
];
|
||||
for (id, params) in cases {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Services::default());
|
||||
app.run("file.new", json!({"width": 800, "height": 200})).unwrap();
|
||||
for k in 0..40 {
|
||||
app.run("shape.rectangle", json!({"x": k * 10, "y": 0, "width": 20, "height": 20})).unwrap();
|
||||
}
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
app.run("tool.select", json!({"tool": "shapeBuilder"})).unwrap();
|
||||
let view = app.view_info();
|
||||
let at = |kind| PointerEvent {
|
||||
kind,
|
||||
pos: vectorcraft_geom::Point::new(15.0, 10.0),
|
||||
mods: Mods::default(),
|
||||
pressure: 1.0,
|
||||
backquote: false,
|
||||
pen: None,
|
||||
};
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Move), view);
|
||||
app.session.tool_poll(view, true).unwrap();
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Down), view);
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Up), view);
|
||||
assert!(app.session.tool_editing(), "{id}");
|
||||
app.run(id, params).unwrap();
|
||||
assert!(!app.session.tool_editing(), "{id}");
|
||||
for _ in 0..3 {
|
||||
app.session.tool_poll(view, false).unwrap();
|
||||
}
|
||||
let merged = app.session.doc().unwrap().history.undo.last().map(|e| e.label.clone());
|
||||
assert_eq!(merged.as_deref(), Some("Shape Builder"), "{id}");
|
||||
assert_eq!(app.session.doc().unwrap().selection.objects.len(), 41, "{id}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Saving, exporting or closing while a Shape Builder merge is computed on another thread
|
||||
/// applies the merge first: the file holds it, and closing asks to save it.
|
||||
#[test]
|
||||
fn save_and_close_apply_a_merge_on_another_thread_first() {
|
||||
let dir = vectorcraft_testkit::temp_dir("control-merge-save");
|
||||
for then in ["file.saveAs", "file.exportAs", "file.close"] {
|
||||
let services = Services { write: Some(Box::new(|p: &str, b: &[u8]| std::fs::write(p, b).map_err(|e| e.to_string()))), ..Default::default() };
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
app.run("file.new", json!({"width": 800, "height": 200})).unwrap();
|
||||
for k in 0..40 {
|
||||
app.run("shape.rectangle", json!({"x": k * 10, "y": 0, "width": 20, "height": 20})).unwrap();
|
||||
}
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
app.run("tool.select", json!({"tool": "shapeBuilder"})).unwrap();
|
||||
// As if just saved: only the merge modifies it.
|
||||
app.session.doc_mut().unwrap().mark_saved();
|
||||
let view = app.view_info();
|
||||
let at = |kind| PointerEvent {
|
||||
kind,
|
||||
pos: vectorcraft_geom::Point::new(15.0, 10.0),
|
||||
mods: Mods::default(),
|
||||
pressure: 1.0,
|
||||
backquote: false,
|
||||
pen: None,
|
||||
};
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Move), view);
|
||||
app.session.tool_poll(view, true).unwrap();
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Down), view);
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Up), view);
|
||||
assert!(app.session.tool_editing() && !app.session.doc().unwrap().is_dirty(), "{then}");
|
||||
let path = dir.join(if then == "file.exportAs" { "a.svg" } else { "a.vectorcraft" });
|
||||
let p = if then == "file.close" { json!({}) } else { json!({"path": path.to_string_lossy()}) };
|
||||
let r = app.run(then, p).unwrap();
|
||||
assert!(!app.session.tool_editing(), "{then}");
|
||||
let merged = app.session.doc().unwrap().history.undo.last().map(|e| e.label.clone());
|
||||
assert_eq!(merged.as_deref(), Some("Shape Builder"), "{then}");
|
||||
match then {
|
||||
"file.saveAs" => assert!(!app.session.doc().unwrap().is_dirty(), "the file holds the merge"),
|
||||
"file.exportAs" => assert!(app.session.doc().unwrap().is_dirty(), "an export leaves the document modified"),
|
||||
_ => assert_eq!(r["pending"], "saveChanges", "closing asks to save the merge"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `ui.dialog.set` of a field the open dialog does not have is an error that lists its fields,
|
||||
/// and the dialog stays as it was. Fields a dialog may not hold yet are still set: `discard`
|
||||
/// with a discard button, `preview` with a live preview, `__` fields and the spec's `inputs`.
|
||||
|
||||
@@ -144,6 +144,7 @@ pub use document_setup::open as open_document_setup;
|
||||
pub use effect::open as open_effect_dialog;
|
||||
pub(crate) use effect::{FILM_GRAIN_FIELDS, PAINT_DAUB_BRUSH_TYPE_LABELS, SHADES, shown_choices};
|
||||
pub use export_as::open as open_export_as;
|
||||
pub(crate) use export_for_screens::drop_unread_screen_settings;
|
||||
pub use export_for_screens::open as open_export_for_screens;
|
||||
pub(crate) use export_for_screens::{
|
||||
KIND as EXPORT_FOR_SCREENS, PresetPick as ScreenPresetPick, export_preset as screen_export_preset, formats as screen_formats,
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Map, Value, json};
|
||||
use vectorcraft_engine::cmd::fileio::{self, ArtboardPick, ScreenSize, pdf};
|
||||
use vectorcraft_engine::cmd::params::{drop_unread_row_options, screen_formats};
|
||||
|
||||
use super::{DialogSpec, form, png_options, svg_options};
|
||||
use crate::state::Dialog;
|
||||
@@ -213,12 +214,29 @@ pub(crate) fn saved_options(app: &VectorcraftApp, saved: &Map<String, Value>, id
|
||||
options.insert("antiAlias".into(), aa.clone());
|
||||
}
|
||||
if let Some(o) = saved.get("settings").and_then(|v| v.get(id)).and_then(Value::as_object) {
|
||||
options.extend(o.iter().map(|(k, v)| (k.clone(), v.clone())));
|
||||
let mut o = o.clone();
|
||||
drop_unread_row_options(&mut o);
|
||||
options.extend(o);
|
||||
}
|
||||
options
|
||||
}
|
||||
|
||||
/// A row with its size as the text the Scale field shows (`2x`, `100w`, `100h`, `72ppi`).
|
||||
/// Export settings `settings` (as `document.exportSettings` or a preset holds them) without the
|
||||
/// keys the export no longer reads in its rows and per-format settings, and without settings for a
|
||||
/// format it doesn't write.
|
||||
pub(crate) fn drop_unread_screen_settings(settings: &mut Map<String, Value>) {
|
||||
if let Some(rows) = settings.get_mut("formats").and_then(Value::as_array_mut) {
|
||||
rows.iter_mut().filter_map(Value::as_object_mut).for_each(drop_unread_row_options);
|
||||
}
|
||||
if let Some(all) = settings.get_mut("settings").and_then(Value::as_object_mut) {
|
||||
let formats = screen_formats();
|
||||
all.retain(|id, _| formats.contains(&id.as_str()));
|
||||
all.values_mut().filter_map(Value::as_object_mut).for_each(drop_unread_row_options);
|
||||
}
|
||||
}
|
||||
|
||||
/// A row with its size as the text the Scale field shows (`2x`, `100w`, `100h`, `72ppi`), without
|
||||
/// the keys the export no longer reads.
|
||||
fn editable_row(row: &Value) -> Value {
|
||||
let num = |k: &str| row.get(k).and_then(Value::as_f64);
|
||||
let text = match (num("width"), num("height"), num("ppi"), row.get("scale")) {
|
||||
@@ -231,6 +249,7 @@ fn editable_row(row: &Value) -> Value {
|
||||
};
|
||||
let mut r = row.clone();
|
||||
if let Some(o) = r.as_object_mut() {
|
||||
drop_unread_row_options(o);
|
||||
for k in ["width", "height", "ppi"] {
|
||||
o.remove(k);
|
||||
}
|
||||
@@ -887,7 +906,11 @@ pub(super) fn apply_preset(d: &mut Dialog, preset: &Value) {
|
||||
d.fields.insert("formats".into(), json!(rows));
|
||||
d.fields.insert("preset".into(), json!(p));
|
||||
}
|
||||
if let (Some(all), Some(given)) = (d.fields.get_mut("settings").and_then(Value::as_object_mut), st["settings"].as_object()) {
|
||||
// Settings for a format the export doesn't write, and keys it no longer reads, are left out.
|
||||
let mut given = Map::from_iter([("settings".to_string(), st["settings"].clone())]);
|
||||
drop_unread_screen_settings(&mut given);
|
||||
if let (Some(all), Some(given)) = (d.fields.get_mut("settings").and_then(Value::as_object_mut), given.get("settings").and_then(Value::as_object))
|
||||
{
|
||||
for (id, o) in given {
|
||||
match (all.get_mut(id).and_then(Value::as_object_mut), o.as_object()) {
|
||||
(Some(mine), Some(o)) => mine.extend(o.iter().map(|(k, v)| (k.clone(), v.clone()))),
|
||||
|
||||
@@ -112,7 +112,8 @@ pub fn open(app: &mut VectorcraftApp, mode: Mode, path: Option<&str>) {
|
||||
/// only when saving).
|
||||
fn options(d: &Dialog) -> Value {
|
||||
let mode = Mode::of(d);
|
||||
let mut o: Map<String, Value> = d.fields.iter().filter(|(k, _)| !UI_KEYS.contains(&k.as_str())).map(|(k, v)| (k.clone(), v.clone())).collect();
|
||||
let mut o: Map<String, Value> =
|
||||
d.fields.iter().filter(|(k, _)| !UI_KEYS.contains(&k.as_str()) && !k.starts_with("__")).map(|(k, v)| (k.clone(), v.clone())).collect();
|
||||
if mode == Mode::Export {
|
||||
o.remove("preserveEditing");
|
||||
if d.bool("useArtboards") {
|
||||
@@ -379,6 +380,19 @@ mod tests {
|
||||
assert_eq!(app.ui.dialog.as_ref().unwrap().f64("decimals", 0.0), 1.0);
|
||||
}
|
||||
|
||||
/// A dialog a save panel opened carries the dialog layer's own `__` fields; the save is given
|
||||
/// only the SVG options, so it is not refused for an unknown key.
|
||||
#[test]
|
||||
fn save_as_svg_from_a_save_panel_passes_only_the_options() {
|
||||
let (mut app, written) = app("/tmp/panel.svg");
|
||||
app.run("file.saveAs", Value::Null).unwrap();
|
||||
app.ui.dialog.as_mut().unwrap().fields.insert(crate::dialogs::AFTER_PANEL.into(), json!(true));
|
||||
assert!(options(app.ui.dialog.as_ref().unwrap()).get(crate::dialogs::AFTER_PANEL).is_none());
|
||||
let d = app.ui.dialog.take().unwrap();
|
||||
confirm(&mut app, &d).unwrap_or_else(|e| panic!("{e}"));
|
||||
assert_eq!(written.borrow()[0].0, "/tmp/panel.svg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_artboards_export_one_file_each() {
|
||||
let (mut app, written) = app("/tmp/set.svg");
|
||||
|
||||
@@ -957,6 +957,34 @@ fn saving_an_applied_preset_keeps_its_bleed_and_fill() {
|
||||
assert_eq!((s.get("includeBleed"), s.get("includeArtboardFill")), (Some(&json!(true)), Some(&json!(false))));
|
||||
}
|
||||
|
||||
/// Remembered settings and a preset that hold keys the export no longer reads, in a row, in a
|
||||
/// format's settings and inside an object option, and settings for a format it doesn't write, open
|
||||
/// without them, so the dialog's export is not refused.
|
||||
#[test]
|
||||
fn saved_keys_no_longer_read_are_left_out_of_the_dialog_s_export() {
|
||||
let (mut app, _) = app(1, false);
|
||||
let stale = json!({
|
||||
"formats": [{"format": "png", "scale": "2x", "noSuchOption": 1}, {"format": "pdf", "marks": {"trim": true, "noSuchMark": 1}}],
|
||||
"settings": {"png": {"noSuchSetting": true}, "dxf": {}, "pdf": {"bleed": {"top": 1, "inner": 2}}}
|
||||
});
|
||||
let Value::Object(saved) = stale.clone() else { panic!("an object") };
|
||||
std::sync::Arc::make_mut(&mut app.session.active_mut().unwrap().doc).export_settings = saved;
|
||||
let folder = temp_folder("stale");
|
||||
let check = |app: &VectorcraftApp| {
|
||||
let p = export_for_screens::params(app, app.ui.dialog.as_ref().unwrap()).unwrap();
|
||||
app.session.check_params("document.exportForScreens", &p).unwrap_or_else(|e| panic!("{e}: {p}"));
|
||||
p
|
||||
};
|
||||
open(&mut app);
|
||||
set(&mut app, "folder", json!(folder.to_string_lossy()));
|
||||
let p = check(&app);
|
||||
assert_eq!(p["formats"][0]["scale"], json!("2x"));
|
||||
assert_eq!(p["formats"][1]["marks"]["trim"], json!(true));
|
||||
export_for_screens::apply_preset(app.ui.dialog.as_mut().unwrap(), &json!({"name": "Old", "settings": stale}));
|
||||
check(&app);
|
||||
let _ = std::fs::remove_dir_all(&folder);
|
||||
}
|
||||
|
||||
/// A preset that puts each item in its own folder (`item` or `itemFormat`, which the dialog has no
|
||||
/// control for) keeps that folder mode when it is exported or saved again from the dialog, until
|
||||
/// the sub-folder controls change (in the dialog or by `ui.dialog.set`).
|
||||
|
||||
@@ -4619,6 +4619,9 @@ axis Both И двете
|
||||
@msg its section ending with `%{end}` doesn't end разделът му, завършващ на `%{end}`, няма край
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) четките, които VectorCraft все още не може да прочете, бяха пропуснати от панела „Четки“ ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet обектите с множество запълвания или щрихове, ефекти или четки се появиха във вид на изрисувания си изглед ({_1}): тяхната поява все още не подлежи на редактиране
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding името `{name}` не е в UTF-8 и е прочетено като {label}: ако изглежда грешно, отворете файла с друго legacyNameEncoding
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding името `{name}` не е в UTF-8, а части от него не са валидни и в {label}: отворете файла с друго legacyNameEncoding
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) още имена, които не са в UTF-8, са прочетени като {label} ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it градиентът „{name}“ не е дефиниран във файла: заменен е с обикновен цвят
|
||||
@msg an image VectorCraft can't read was left out изображение, което VectorCraft не може да разчете, беше пропуснато
|
||||
@msg an image whose data is cut short was left out изображение с непълни данни беше пропуснато
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -5015,6 +5015,9 @@ imageTrace Outline Obris
|
||||
@msg its section ending with `%{end}` doesn't end njen odjeljak koji završava s `%{end}` ne završava
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) četkice koje VectorCraft još ne može pročitati izostavljene su iz panela Četkice ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet objekti s više ispuna ili poteza, efekata ili četkica stigli su kao njihov iscrtani izgled ({_1}): njihov izgled se još ne može uređivati
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding naziv `{name}` nije u UTF-8 i pročitan je kao {label}: ako izgleda pogrešno, otvorite datoteku s drugim legacyNameEncoding
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding naziv `{name}` nije u UTF-8, a dijelovi nisu ispravni ni u {label}: otvorite datoteku s drugim legacyNameEncoding
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) još naziva koji nisu u UTF-8 pročitano je kao {label} ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it gradijent „{name}” nije definisan u datoteci: umjesto njega koristi se obična boja
|
||||
@msg an image VectorCraft can't read was left out izostavljena je slika koju VectorCraft ne može pročitati
|
||||
@msg an image whose data is cut short was left out izostavljena je slika čiji su podaci skraćeni
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -5508,6 +5508,9 @@ digits Malayalam Malaiàlam
|
||||
@msg objects inside a blend, envelope, repeat or Intertwine group can't be attached to a path els objectes dins d’una fusió, un embolcall, una repetició o un grup Intertwine no es poden adjuntar a un traçat
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) els pinzells que VectorCraft encara no pot llegir s'han deixat fora del tauler Pinzells ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet els objectes amb diversos farciments o traços, efectes o pinzells han arribat amb el seu aspecte dibuixat ({_1}): la seva aparença encara no és editable
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding el nom `{name}` no és UTF-8 i s’ha llegit com a {label}: si sembla incorrecte, obriu el fitxer amb un altre legacyNameEncoding
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding el nom `{name}` no és UTF-8, i algunes parts tampoc no són {label} vàlid: obriu el fitxer amb un altre legacyNameEncoding
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) s’han llegit com a {label} més noms que no són UTF-8 ({count})
|
||||
@msg Offset Path: select paths Desplaça el traçat: selecciona traçats
|
||||
@msg Offset Path: the offset leaves nothing of the selected paths (an inset larger than the shapes) Desplaça el traçat: el desplaçament no deixa res dels traçats seleccionats (una retracció més gran que les formes)
|
||||
@msg only a dock group above or below others collapses, not one beside another només es plega un grup d’acoblament situat a sobre o a sota d’altres, no un al costat d’un altre
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -5090,6 +5090,9 @@ imageTrace Outline Obrys
|
||||
@msg its section ending with `%{end}` doesn't end jeho oddíl končící `%{end}` nemá konec
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) štětce, které VectorCraft zatím neumí načíst, byly vynechány z panelu Štětce ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet objekty s více výplněmi nebo tahy, efekty či štětci byly načteny jako vykreslený vzhled ({_1}): jejich vzhled zatím nelze upravovat
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding název `{name}` není v UTF-8 a byl načten jako {label}: pokud vypadá špatně, otevřete soubor s jiným legacyNameEncoding
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding název `{name}` není v UTF-8 a jeho části nejsou platné ani v {label}: otevřete soubor s jiným legacyNameEncoding
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) další názvy, které nejsou v UTF-8, byly načteny jako {label} ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it přechod „{name}“ není v souboru definován: zastupuje ho plná barva
|
||||
@msg an image VectorCraft can't read was left out obrázek, který VectorCraft neumí přečíst, byl vynechán
|
||||
@msg graphs come in as plain art, without their data or settings grafy se načtou jako obyčejná grafika, bez svých dat a nastavení
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4707,6 +4707,9 @@ imageTrace Outline Kontur
|
||||
@msg its section ending with `%{end}` doesn't end dens sektion, der ender med `%{end}`, ender ikke
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) pensler, som VectorCraft endnu ikke kan læse, blev udeladt af panelet Pensler ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet objekter med flere fyld eller streger, effekter eller pensler kom ind, som de er tegnet ({_1}): deres udseende er endnu ikke redigerbart
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding navnet `{name}` er ikke UTF-8 og blev læst som {label}: hvis det ser forkert ud, så åbn filen med en anden legacyNameEncoding
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding navnet `{name}` er ikke UTF-8, og dele af det er heller ikke gyldig {label}: åbn filen med en anden legacyNameEncoding
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) flere navne, der ikke er UTF-8, blev læst som {label} ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it gradienten »{name}« er ikke defineret i filen: der bruges en flad farve i stedet
|
||||
@msg an image VectorCraft can't read was left out et billede, som VectorCraft ikke kan læse, blev udeladt
|
||||
@msg an image whose data is cut short was left out et billede, hvis data er afkortet, blev udeladt
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4698,6 +4698,9 @@ theme Appearance Erscheinungsbild
|
||||
@msg its section ending with `%{end}` doesn't end sein Abschnitt, der mit `%{end}` enden soll, endet nicht
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) Pinsel, die VectorCraft noch nicht lesen kann, wurden im Bedienfeld „Pinsel“ ausgelassen ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet Objekte mit mehreren Flächen oder Konturen, Effekten oder Pinseln wurden so übernommen, wie sie gezeichnet aussehen ({_1}): Ihr Aussehen ist noch nicht bearbeitbar
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding Der Name `{name}` ist kein UTF-8 und wurde als {label} gelesen: Wenn er falsch aussieht, öffnen Sie die Datei mit einer anderen legacyNameEncoding
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding Der Name `{name}` ist kein UTF-8, und Teile davon sind auch kein gültiges {label}: Öffnen Sie die Datei mit einer anderen legacyNameEncoding
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) Weitere Namen, die kein UTF-8 sind, wurden als {label} gelesen ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it der Verlauf „{name}“ ist in der Datei nicht definiert: Eine einfache Farbe steht an seiner Stelle
|
||||
@msg an image VectorCraft can't read was left out ein Bild, das VectorCraft nicht lesen kann, wurde ausgelassen
|
||||
@msg graphs come in as plain art, without their data or settings Diagramme werden als einfache Grafik übernommen, ohne ihre Daten und Einstellungen
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4730,6 +4730,9 @@ digits Malayalam Μαλαγιάλαμ
|
||||
@msg its section ending with `%{end}` doesn't end η ενότητά του που τελειώνει σε `%{end}` δεν τερματίζεται
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) τα πινέλα που το VectorCraft δεν μπορεί ακόμη να διαβάσει παραλείφθηκαν από τον πίνακα Πινέλα ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet τα αντικείμενα με πολλαπλά γεμίσματα, περιγράμματα, εφέ ή πινέλα εισήχθησαν ως απεικονίσεις ({_1}): η εμφάνισή τους δεν είναι ακόμη επεξεργάσιμη
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding το όνομα `{name}` δεν είναι UTF-8 και διαβάστηκε ως {label}: αν φαίνεται λάθος, ανοίξτε το αρχείο με άλλο legacyNameEncoding
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding το όνομα `{name}` δεν είναι UTF-8 και τμήματά του δεν είναι έγκυρα ούτε σε {label}: ανοίξτε το αρχείο με άλλο legacyNameEncoding
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) περισσότερα ονόματα που δεν είναι UTF-8 διαβάστηκαν ως {label} ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it το ντεγκραντέ «{name}» δεν ορίζεται στο αρχείο: χρησιμοποιείται στη θέση του ένα συμπαγές χρώμα
|
||||
@msg an image VectorCraft can't read was left out παραλείφθηκε εικόνα που δεν μπορεί να διαβάσει το VectorCraft
|
||||
@msg graphs come in as plain art, without their data or settings τα γραφήματα εισάγονται ως απλή γραφική, χωρίς τα δεδομένα και τις ρυθμίσεις τους
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -4782,6 +4782,9 @@ axis Both Ambos
|
||||
@msg its section ending with `%{end}` doesn't end su sección que termina con `%{end}` no termina
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) los pinceles que VectorCraft aún no puede leer se omitieron del panel Pinceles ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet los objetos con varios rellenos o trazos, efectos o pinceles se importaron con su aspecto dibujado ({_1}): su aspecto aún no se puede editar
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding el nombre `{name}` no está en UTF-8 y se leyó como {label}: si no se ve bien, abre el archivo con otro legacyNameEncoding
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding el nombre `{name}` no está en UTF-8 y partes de él tampoco son {label} válido: abre el archivo con otro legacyNameEncoding
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) se leyeron como {label} más nombres que no están en UTF-8 ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it el degradado “{name}” no está definido en el archivo: lo sustituye un color sólido
|
||||
@msg an image VectorCraft can't read was left out se omitió una imagen que VectorCraft no puede leer
|
||||
@msg graphs come in as plain art, without their data or settings los gráficos se importan como ilustración normal, sin sus datos ni sus ajustes
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4992,6 +4992,9 @@ imageTrace Outline Ääriviiva
|
||||
@msg its section ending with `%{end}` doesn't end sen `%{end}`-merkintään päättyvä osio ei pääty
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) siveltimet, joita VectorCraft ei vielä osaa lukea, jätettiin pois Siveltimet-paneelista ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet objektit, joilla on useita täyttöjä tai viivoja, tehosteita tai siveltimiä, tuotiin piirretyn näköisinä ({_1}): niiden ulkoasua ei voi vielä muokata
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding nimi `{name}` ei ole UTF-8:aa, ja se luettiin koodauksella {label}: jos se näyttää väärältä, avaa tiedosto toisella legacyNameEncoding-arvolla
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding nimi `{name}` ei ole UTF-8:aa, eivätkä kaikki sen osat ole kelvollista {label}-koodausta: avaa tiedosto toisella legacyNameEncoding-arvolla
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) muita nimiä, jotka eivät ole UTF-8:aa, luettiin koodauksella {label} ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it liukuväriä “{name}” ei ole määritetty tiedostossa: sen tilalla on tasaväri
|
||||
@msg an image VectorCraft can't read was left out kuva, jota VectorCraft ei voi lukea, jätettiin pois
|
||||
@msg graphs come in as plain art, without their data or settings kaaviot tuodaan tavallisena grafiikkana ilman niiden tietoja ja asetuksia
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4769,6 +4769,9 @@ axis Both Les deux
|
||||
@msg its section ending with `%{end}` doesn't end leur section qui se termine par `%{end}` ne se termine pas
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) les formes que VectorCraft ne sait pas encore lire ont été omises du panneau Formes ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet les objets à plusieurs fonds ou contours, effets ou formes ont été importés tels qu’ils sont dessinés ({_1}) : leur aspect n’est pas encore modifiable
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding le nom `{name}` n’est pas en UTF-8 et a été lu en {label} : s’il semble incorrect, ouvrez le fichier avec un autre legacyNameEncoding
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding le nom `{name}` n’est pas en UTF-8, et certaines parties ne sont pas non plus du {label} valide : ouvrez le fichier avec un autre legacyNameEncoding
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) d’autres noms qui ne sont pas en UTF-8 ont été lus en {label} ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it le dégradé « {name} » n’est pas défini dans le fichier : une couleur unie le remplace
|
||||
@msg an image VectorCraft can't read was left out une image que VectorCraft ne peut pas lire a été ignorée
|
||||
@msg graphs come in as plain art, without their data or settings les graphes sont importés comme illustration ordinaire, sans leurs données ni leurs réglages
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -8074,6 +8074,9 @@ theme Appearance अपीयरेंस
|
||||
# Align to Pixel Grid
|
||||
Align to Pixel Grid पिक्सेल ग्रिड से संरेखित करें
|
||||
@msg only paths and compound paths can be aligned to the pixel grid केवल पाथ और कंपाउंड पाथ को पिक्सेल ग्रिड से संरेखित किया जा सकता है
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding नाम `{name}` UTF-8 नहीं है और इसे {label} के रूप में पढ़ा गया: यदि यह गलत दिखे, तो फ़ाइल को किसी अन्य legacyNameEncoding से खोलें
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding नाम `{name}` UTF-8 नहीं है, और इसके कुछ हिस्से {label} में भी मान्य नहीं हैं: फ़ाइल को किसी अन्य legacyNameEncoding से खोलें
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) UTF-8 में न होने वाले और नाम {label} के रूप में पढ़े गए ({count})
|
||||
Start Lists From Typed Markers टाइप किए गए चिह्नों से सूचियाँ शुरू करें
|
||||
Marquee Selection मार्की चयन
|
||||
Touching स्पर्श करते हुए
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -5170,6 +5170,9 @@ imageTrace Outline Körvonal
|
||||
@msg object {id} is not a selected top-level object az objektum nem kijelölt legfelső szintű objektum: {id}
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) a VectorCraft által még nem olvasható ecsetek kimaradtak az Ecsetek panelről ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet a több kitöltésű vagy körvonalú, effektusos vagy ecsetes objektumok a megrajzolt kinézetükkel kerültek be ({_1}): a megjelenésük még nem szerkeszthető
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding a(z) `{name}` név nem UTF-8, ezért {label} kódolással lett beolvasva: ha hibásnak tűnik, nyissa meg a fájlt másik legacyNameEncoding értékkel
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding a(z) `{name}` név nem UTF-8, és egyes részei {label} kódolásban sem érvényesek: nyissa meg a fájlt másik legacyNameEncoding értékkel
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) további nem UTF-8 nevek lettek {label} kódolással beolvasva ({count})
|
||||
@msg Offset Path: select paths Útvonal eltolása: jelölj ki útvonalakat
|
||||
@msg Offset Path: the offset leaves nothing of the selected paths (an inset larger than the shapes) Útvonal eltolása: az eltolás után semmi sem marad a kijelölt útvonalakból (a befelé eltolás nagyobb az alakzatoknál)
|
||||
@msg onto must name a floating panel az onto egy lebegő panelt kell megnevezzen
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4707,6 +4707,9 @@ imageTrace Outline Kontur
|
||||
@msg its section ending with `%{end}` doesn't end bagian yang berakhir dengan `%{end}` tidak berakhir
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) kuas yang belum dapat dibaca VectorCraft tidak dimasukkan ke panel Kuas ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet objek dengan beberapa isian atau goresan, efek, atau kuas masuk sebagai tampilan gambarnya ({_1}): penampilannya belum dapat diedit
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding nama `{name}` bukan UTF-8 dan dibaca sebagai {label}: jika terlihat salah, buka file dengan legacyNameEncoding lain
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding nama `{name}` bukan UTF-8, dan sebagiannya juga bukan {label} yang valid: buka file dengan legacyNameEncoding lain
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) nama lain yang bukan UTF-8 dibaca sebagai {label} ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it gradien “{name}” tidak didefinisikan dalam berkas: warna polos dipakai sebagai pengganti
|
||||
@msg an image VectorCraft can't read was left out gambar yang tidak dapat dibaca VectorCraft tidak disertakan
|
||||
@msg an image whose data is cut short was left out gambar yang datanya terpotong tidak disertakan
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2306 and column 5.
|
@@ -4824,6 +4824,9 @@ axis Both Entrambi
|
||||
@msg its section ending with `%{end}` doesn't end la loro sezione che termina con `%{end}` non termina
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) i pennelli che VectorCraft non sa ancora leggere sono stati esclusi dal pannello Pennelli ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet gli oggetti con più riempimenti o tratti, effetti o pennelli sono stati importati come appaiono disegnati ({_1}): il loro aspetto non è ancora modificabile
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding il nome `{name}` non è in UTF-8 ed è stato letto come {label}: se sembra errato, apri il file con un altro legacyNameEncoding
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding il nome `{name}` non è in UTF-8 e alcune sue parti non sono valide nemmeno in {label}: apri il file con un altro legacyNameEncoding
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) altri nomi non in UTF-8 sono stati letti come {label} ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it la sfumatura “{name}” non è definita nel file: la sostituisce un colore pieno
|
||||
@msg an image VectorCraft can't read was left out un'immagine che VectorCraft non può leggere è stata omessa
|
||||
@msg graphs come in as plain art, without their data or settings i grafici vengono importati come grafica semplice, senza i loro dati e le loro impostazioni
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4515,6 +4515,9 @@ swatch Bright Violet ビビッドバイオレット
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it グラデーション「{name}」はファイル内で定義されていません: 代わりに単色を使用しています
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) VectorCraft がまだ読み込めないブラシ {_1} 個はブラシパネルに追加されませんでした
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet 塗りや線が複数ある、または効果やブラシを適用したオブジェクト {_1} 個は見た目のまま読み込まれました: アピアランスはまだ編集できません
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding 名前 `{name}` は UTF-8 ではないため {label} として読み込みました: 正しくない場合は別の legacyNameEncoding でファイルを開いてください
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding 名前 `{name}` は UTF-8 ではなく、一部は {label} としても無効です: 別の legacyNameEncoding でファイルを開いてください
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) UTF-8 ではないほかの名前を {label} として読み込みました ({count})
|
||||
@msg patterns nested too deeply are filled with mid-grey 入れ子が深すぎるパターンは中間のグレーで塗りつぶされています
|
||||
@msg shadings of an unknown type were left out 種類が不明なシェーディングは除外されました
|
||||
@msg shadings whose functions are of an unknown type are filled with their middle colour 関数の種類が不明なシェーディングは中間の色で塗りつぶされています
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4516,6 +4516,9 @@ font-technology Variable ცვლადი
|
||||
@msg its section ending with `%{end}` doesn't end მისი სექცია, რომელიც `%{end}`-ით მთავრდება, არ სრულდება
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) ფუნჯები, რომლებსაც VectorCraft ჯერ ვერ კითხულობს, ფუნჯების პანელში არ დაემატა ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet რამდენიმე შევსების ან კონტურის, ეფექტის ან ფუნჯის მქონე ობიექტები შემოვიდა დახატული სახით ({_1}): მათი იერსახე ჯერ არ რედაქტირდება
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding სახელი `{name}` არ არის UTF-8 და წაკითხულია როგორც {label}: თუ არასწორად გამოიყურება, გახსენით ფაილი სხვა legacyNameEncoding-ით
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding სახელი `{name}` არ არის UTF-8 და მისი ნაწილები არც {label}-ში არის სწორი: გახსენით ფაილი სხვა legacyNameEncoding-ით
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) სხვა სახელები, რომლებიც არ არის UTF-8, წაკითხულია როგორც {label} ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it გრადიენტი „{name}“ ფაილში განსაზღვრული არ არის: მის ნაცვლად ერთგვაროვანი ფერია
|
||||
@msg an image VectorCraft can't read was left out გამოსახულება, რომელსაც VectorCraft ვერ კითხულობს, გამოტოვებულია
|
||||
@msg graphs come in as plain art, without their data or settings დიაგრამები შემოდის როგორც ჩვეულებრივი გრაფიკა, მათი მონაცემებისა და პარამეტრების გარეშე
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -4442,6 +4442,9 @@ theme Appearance 외관
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it 그레이디언트 “{name}”이(가) 파일에 정의되어 있지 않아 단색으로 대체했습니다
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) VectorCraft에서 아직 읽을 수 없는 브러시는 브러시 패널에서 제외되었습니다({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet 칠이나 선이 여러 개인 개체, 효과, 브러시가 있는 개체는 그려진 모양({_1})으로 가져왔습니다: 모양새는 아직 편집할 수 없습니다
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding 이름 `{name}`은(는) UTF-8이 아니어서 {label}(으)로 읽었습니다: 잘못 보이면 다른 legacyNameEncoding으로 파일을 여세요
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding 이름 `{name}`은(는) UTF-8이 아니고 일부는 {label}에서도 올바르지 않습니다: 다른 legacyNameEncoding으로 파일을 여세요
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) UTF-8이 아닌 다른 이름도 {label}(으)로 읽었습니다({count})
|
||||
@msg patterns nested too deeply are filled with mid-grey 너무 깊게 중첩된 패턴은 중간 회색으로 채웁니다
|
||||
@msg shadings of an unknown type were left out 알 수 없는 종류의 셰이딩은 제외했습니다
|
||||
@msg shadings whose functions are of an unknown type are filled with their middle colour 함수 종류를 알 수 없는 셰이딩은 중간 색상으로 채웁니다
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4719,6 +4719,9 @@ imageTrace Outline Contour
|
||||
@msg its section ending with `%{end}` doesn't end zijn sectie die op `%{end}` eindigt, eindigt niet
|
||||
@msg brushes VectorCraft can't read yet were left out of the Brushes panel ({_1}) penselen die VectorCraft nog niet kan lezen, zijn weggelaten uit het deelvenster Penselen ({_1})
|
||||
@msg objects with several fills or strokes, effects or brushes came in as their drawn look ({_1}): their appearance isn't editable yet objecten met meerdere vullingen of lijnen, effecten of penselen zijn als hun getekende uiterlijk binnengekomen ({_1}): hun vormgeving is nog niet bewerkbaar
|
||||
@msg the name `{name}` isn't UTF-8 and was read as {label}: if it looks wrong, open the file with another legacyNameEncoding de naam `{name}` is geen UTF-8 en is gelezen als {label}: als die er verkeerd uitziet, open het bestand dan met een andere legacyNameEncoding
|
||||
@msg the name `{name}` isn't UTF-8, and parts of it aren't valid {label} either: open the file with another legacyNameEncoding de naam `{name}` is geen UTF-8, en delen ervan zijn ook geen geldige {label}: open het bestand met een andere legacyNameEncoding
|
||||
@msg more names that aren't UTF-8 were read as {label} ({count}) meer namen die geen UTF-8 zijn, zijn gelezen als {label} ({count})
|
||||
@msg gradient “{name}” isn't defined in the file: a plain colour stands in for it verloop „{name}” is niet gedefinieerd in het bestand: er is een effen kleur voor gebruikt
|
||||
@msg an image VectorCraft can't read was left out een afbeelding die VectorCraft niet kan lezen, is weggelaten
|
||||
@msg an image whose data is cut short was left out een afbeelding waarvan de gegevens zijn afgekapt, is weggelaten
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
Loaded 100 of 130 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user