GitCorner

Code

ossartcraftvectorcraft🌐
2bc41aeb8602
use super::{Color, EyedropperOptions, PathfinderOptions, Value, cmd};

/// Where new art goes (Illustrator's drawing modes, Shift+D cycles).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum DrawMode {
    #[default]
    Normal,
    Behind,
    Inside,
}

/// Plug-ins & Scratch Disks › Plug-in Instruction Budget: the instructions an object filter's run
/// may use ([`vectorcraft_plugins::Plugin::large_limits`]).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize)]
#[serde(rename_all = "lowercase")]
pub enum PluginBudget {
    /// The plug-in's own limits.
    #[default]
    Normal,
    /// At least [`vectorcraft_plugins::LARGE_FUEL`] instructions besides those for each byte of
    /// input; the time budget is unchanged.
    Large,
}

/// A saved Plug-in Instruction Budget: any value but `large`, of any type, reads as Normal, and the
/// other preferences are read as they are.
fn plugin_budget<'de, D: serde::Deserializer<'de>>(d: D) -> std::result::Result<PluginBudget, D::Error> {
    let saved = <Value as serde::Deserialize>::deserialize(d)?;
    Ok(if saved.as_str() == Some("large") { PluginBudget::Large } else { PluginBudget::Normal })
}

/// A saved Default Language as its tag: older preferences hold the language's name, and one the list
/// no longer has reads as the default.
fn language_tag<'de, D: serde::Deserializer<'de>>(d: D) -> std::result::Result<String, D::Error> {
    let saved = <String as serde::Deserialize>::deserialize(d)?;
    let tag = vectorcraft_doc::setup::char_language(&saved).ok().flatten();
    Ok(tag.or_else(|| vectorcraft_doc::setup::LANGUAGES.first().map(|(_, t, _)| *t)).unwrap_or_default().to_string())
}

/// Application preferences (Edit → Preferences). Every field is reachable through `prefs.get` /
/// `prefs.set {key, value}` (camelCase keys, validated against [`cmd::prefscmds::PREF_SPECS`]).
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Prefs {
    // General
    /// Arrow-key nudge distance (General → Keyboard Increment), points.
    pub keyboard_increment: f64,
    pub constrain_angle: f64,
    pub corner_radius: f64,
    pub disable_auto_add_delete: bool,
    /// General › Interpolate Control Points When Moving Anchors: the default of the `interpolate`
    /// param of the commands that move direct-selected anchors (a Direct Selection drag, the arrow
    /// keys, Move, Transform Again). On, the handles of each segment with one moved end are
    /// re-mapped by the turn, scale and move that take its old ends to its new ends. Off (the
    /// default), the handles of a moved anchor move with it and the other handles stay.
    pub interpolate_control_points: bool,
    pub use_precise_cursors: bool,
    pub show_tool_tips: bool,
    /// General › Show Tool Cards: with tool tips on, a tool button's tool tip is a card with what the
    /// tool does and its keys, for tools that have a description.
    pub show_tool_cards: bool,
    /// Other Script… warns before it runs a chosen script.
    pub show_external_script_warning: bool,
    pub anti_aliased_artwork: bool,
    pub select_same_tint_percent: bool,
    pub show_home_screen: bool,
    pub use_preview_bounds: bool,
    /// Align panel menu › Align to Glyph Bounds › Point Text: Align and Distribute measure point
    /// type by the ink of its glyphs instead of its em box.
    pub align_glyph_bounds_point: bool,
    /// Align panel menu › Align to Glyph Bounds › Area Text: the same for area type, instead of
    /// its frame.
    pub align_glyph_bounds_area: bool,
    /// Preferences › Type › Glyph Bounds › Measure Type by Glyph Bounds (also in the Transform
    /// panel menu): the bounding box, the Transform panel's, Control bar's and Properties panel's X,
    /// Y, W and H, and `object.setBounds` measure each point type object selected as an object (not
    /// inside a selected group) by the ink of its glyphs instead of its em box
    /// ([`crate::Session::bounds_measure`]).
    pub type_glyph_bounds: bool,
    /// Artboard Options › Fade Region Outside Artboard: while the Artboard tool is active, the
    /// canvas draws everything outside the artboards darker, the pasteboard and the art on it.
    pub fade_region_outside_artboard: bool,
    /// Artboard Options › Update While Dragging: the area outside the artboards stays darker while
    /// the Artboard tool moves or resizes an artboard; off, it draws as usual until the drag ends.
    pub artboard_update_while_dragging: bool,
    pub display_print_size: bool,
    pub double_click_to_isolate: bool,
    pub transform_pattern_tiles: bool,
    pub scale_corners: bool,
    /// Scale Strokes & Effects.
    pub scale_strokes: bool,
    pub zoom_with_mouse_wheel: bool,
    /// While Zoom with Mouse Wheel is off, Cmd/Ctrl-wheel scrolls sideways instead of zooming.
    pub ctrl_wheel_scrolls_sideways: bool,
    /// A horizontal drag on a numeric field or its label steps its value (#400).
    pub scrub_numeric_fields: bool,
    /// A two-finger rotation on a Mac trackpad turns the view about the pointer once it reaches 5°.
    pub trackpad_rotate_view: bool,
    /// A single-key tool shortcut held down chooses its tool until the key is let go, and then the
    /// tool active before comes back; a quick press chooses the tool for good.
    pub hold_tool_keys: bool,
    /// Hold shortcuts act (Edit › Keyboard Shortcuts › Hold Shortcuts, off by default): a key with a
    /// hold shortcut runs it when held for [`Self::key_hold_delay`], and its own shortcut when let go
    /// sooner. Off, every key runs on its press and the dialog shows no Hold column.
    pub hold_shortcuts: bool,
    /// Seconds a key with a hold shortcut must stay down before the hold shortcut runs (Hold
    /// Shortcut Delay, 0.2 to 1.0). VectorCraft's own default, 0.35.
    pub key_hold_delay: f64,
    /// With View › Show Bounding Box on, the bounding box stays visible while a drag moves the
    /// selection, and the shape tools that show it draw it around the shape being drawn. Off (the
    /// default), it hides during a move and while a shape is drawn, except that a Selection tool
    /// move with Real-time Drawing off still moves the box.
    pub bounding_box_while_moving_and_drawing: bool,
    /// Offset for Paste / duplicate (Illustrator pastes to the view centre; we offset by this).
    pub paste_offset: f64,
    // Selection & Anchor Display
    pub selection_tolerance: f64,
    /// Selection-tool marquee: touching (default), enclosed, or screen drag direction.
    pub marquee_selection: String,
    pub object_selection_by_path_only: bool,
    pub snap_to_point_tolerance: f64,
    pub ctrl_click_selects_behind: bool,
    pub zoom_to_selection: bool,
    pub move_locked_with_artboard: bool,
    pub anchor_size: u32,
    pub handle_style: String,
    pub highlight_anchors_on_hover: bool,
    pub show_handles_multiple_anchors: bool,
    pub hide_corner_widget_above: f64,
    pub pen_rubber_band: bool,
    pub curvature_rubber_band: bool,
    // Type
    pub type_size_increment: f64,
    pub tracking_increment: f64,
    pub baseline_shift_increment: f64,
    pub show_east_asian_options: bool,
    pub show_indic_options: bool,
    pub type_selection_by_path_only: bool,
    pub font_names_in_english: bool,
    pub auto_size_area_type: bool,
    pub font_preview: bool,
    /// Type › Show samples on white: the font menus draw each family's sample in dark type on a
    /// white area in every brightness (off by default).
    pub font_samples_on_white: bool,
    pub font_preview_size: String,
    pub recent_fonts_count: u32,
    pub missing_glyph_protection: bool,
    pub highlight_alternate_glyphs: bool,
    /// Type › Show Character Alternates: with a Type tool and one character selected, the canvas
    /// shows that character's alternate glyphs beside it (on by default).
    pub show_character_alternates: bool,
    /// Type › Highlight Substituted Fonts: on screen, text drawn in a substitute for a missing
    /// font is highlighted, in every document (on by default).
    pub highlight_substituted_fonts: bool,
    pub placeholder_text: bool,
    /// Type › Start Lists From Typed Markers: a list marker and a space typed at the start of a
    /// paragraph start a list (on by default). Off, they stay as typed text.
    pub typed_lists: bool,
    // Units
    pub units_general: String,
    pub units_stroke: String,
    pub units_type: String,
    pub units_asian_type: String,
    /// Numbers Without Units Are Points: a number typed with no unit into a length field in picas
    /// is read in points (on by default; the reference app dims it unless a unit is Picas).
    pub numbers_without_units_are_points: bool,
    pub identify_objects_by: String,
    // Guides & Grid
    pub guide_color: String,
    pub guide_style: String,
    /// Lock Guides by Default: the app starts with View › Guides › Lock Guides on.
    pub lock_guides_by_default: bool,
    /// Artboard Guides with Cmd/Ctrl + Ruler Drag: Cmd/Ctrl held when a guide is dragged out of a
    /// ruler makes it a guide of the active artboard, or with the Artboard tool a canvas guide.
    pub cmd_ruler_drag_artboard_guides: bool,
    pub grid_color: String,
    pub grid_style: String,
    pub gridline_every: f64,
    pub grid_subdivisions: u32,
    pub grids_in_back: bool,
    pub show_pixel_grid: bool,
    // Smart Guides
    pub smart_guide_color: String,
    pub alignment_guides: bool,
    pub object_highlighting: bool,
    pub transform_tools_guides: bool,
    pub construction_guides: bool,
    pub construction_angles: String,
    pub anchor_path_labels: bool,
    pub measurement_labels: bool,
    pub spacing_guides: bool,
    pub distance_guides: bool,
    pub snap_to_last_location: bool,
    pub snapping_tolerance: f64,
    pub snap_tangent: bool,
    pub snap_perpendicular: bool,
    // Slices
    pub show_slice_numbers: bool,
    pub slice_line_color: String,
    // Hyphenation
    /// Default Language: the BCP 47 tag of the language new type takes when its document's language
    /// is the default ([`vectorcraft_doc::setup::LANGUAGES`]).
    #[serde(deserialize_with = "language_tag")]
    pub hyphenation_language: String,
    pub hyphenation_exceptions: String,
    /// Type › Options › Additional Fonts Folder: a folder (read with its subfolders) whose fonts
    /// are listed and used as if installed (#683); empty for none.
    pub fonts_folder: String,
    // Plug-ins & Scratch Disks
    pub plugins_folder: String,
    /// Plug-in Instruction Budget: the instructions each object filter run gets, from
    /// `plugin.run`, a plug-in command and the app alike. Live effects, exporters and importers
    /// keep their own budgets.
    #[serde(deserialize_with = "plugin_budget")]
    pub plugin_instruction_budget: PluginBudget,
    pub scratch_primary: String,
    pub scratch_secondary: String,
    // User Interface
    pub ui_brightness: String,
    /// User Interface › Accent Color: the colour of what is on, chosen or focused.
    pub ui_accent: String,
    /// User Interface › Color Scheme: "modern" (with the accent above) or "classic" (neutral
    /// greys and a blue accent).
    pub ui_color_scheme: String,
    pub canvas_color: String,
    pub auto_collapse_icon_panels: bool,
    /// User Interface › Show Tool Group Labels: the toolbar's group names (Select, Shapes, Draw…);
    /// off (as it ships, #1736), the tools run on from group to group with nothing between them.
    pub tool_group_labels: bool,
    pub open_documents_as_tabs: bool,
    pub large_tabs: bool,
    pub ui_scaling: f64,
    pub scale_cursor_with_ui: bool,
    /// UI language: `auto` (follow the system locale) or a language code such as `en`, `zh-hant`.
    /// The list of languages belongs to the shell (`ui-egui` i18n); an unknown code reads as `auto`.
    pub interface_language: String,
    /// Windows and Linux: use the system's title bar and window buttons instead of the app bar
    /// acting as the title bar (tiling window managers, desktops that draw their own decorations).
    /// Read when the app starts. macOS always uses the system's.
    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` set to `app`, `system` or `desktop` take precedence over it.
    pub app_title_bar: bool,
    // Performance
    pub gpu_performance: bool,
    pub animated_zoom: bool,
    /// Which graphics processor the desktop app asks for at startup (it takes effect after a
    /// restart): `automatic`, `lowPower` (the integrated GPU on hybrid-graphics machines) or
    /// `highPerformance` (the discrete one). The canvas is rasterized on the CPU and only
    /// composited on the GPU, so the integrated GPU is plenty; presenting from the discrete GPU
    /// through the integrated one made some hybrid laptops flicker (#306). Automatic is power
    /// saving on Windows and macOS and the system's default GPU elsewhere, the one the desktop
    /// runs on: a Wayland compositor may not show frames from another GPU (#502). Single-GPU
    /// machines are unaffected.
    pub gpu_preference: String,
    /// The desktop app's window presents without vsync, with frames capped at 240 a second (#6013).
    /// Read at startup (it takes effect after a restart); `--present-mode` and
    /// `VECTORCRAFT_PRESENT_MODE` take precedence over it.
    pub low_latency_drawing: bool,
    pub history_states: u32,
    pub real_time_drawing: bool,
    /// Rasterizer worker threads; -1 = automatic.
    pub render_threads: i32,
    /// Linux: `automatic` opens the window on the session's display server, or through XWayland on
    /// a Wayland session when a pen is attached (#4967); `x11` opens it through XWayland on a
    /// Wayland session, where dropped files arrive (#1151); `x11WithPen` opens it through XWayland
    /// only when a pen is attached (#2028). Read when the app starts.
    pub linux_display_server: String,
    /// The desktop canvas converts its sRGB into the ICC profile of the display that shows the
    /// window, where the system doesn't (Windows without Advanced Color, X11). Display only: it
    /// changes no document, proof or export.
    pub monitor_profile_display: bool,
    // File Handling
    pub background_save: bool,
    pub background_export: bool,
    pub autosave_recovery: bool,
    pub autosave_interval: u32,
    pub recovery_folder: String,
    pub recovery_off_for_complex: bool,
    pub recent_files_count: u32,
    pub low_res_proxy_eps: bool,
    pub anti_aliased_bitmaps: bool,
    pub update_links: String,
    // Clipboard Handling
    pub copy_as_svg: bool,
    pub copy_as_pdf: bool,
    pub copy_aicb: bool,
    pub aicb_mode: String,
    pub paste_text_formatting: String,
    // Appearance of Black
    pub black_on_screen: String,
    pub black_output: String,
    // Devices
    pub touch_workspace: bool,
    pub touch_gestures: bool,
    // Graphic Styles panel
    /// Override Character Color: a graphic style applied to type replaces its characters' fill
    /// and stroke with the style's fills and strokes.
    pub override_char_color: bool,
    // Pattern editing
    /// Object → Pattern → Tile Edge Color (`#rrggbb`): the tile edge and swatch bounds in pattern
    /// editing mode.
    pub pattern_tile_edge_color: String,
    /// Eyedropper Options (`eyedropper.setOptions`; a preference group, see
    /// [`cmd::prefscmds::PREF_GROUPS`]).
    pub eyedropper: EyedropperOptions,
    /// Pathfinder panel › Pathfinder Options (`object.pathfinder.options`; a preference group, see
    /// [`cmd::prefscmds::PREF_GROUPS`]).
    pub pathfinder: PathfinderOptions,
    /// Character panel › Show Snap to Glyph Options: which guides View › Snap to Glyph gives
    /// (`view.snapToGlyph.options`; a preference group, see [`cmd::prefscmds::PREF_GROUPS`]).
    pub glyph_snap: vectorcraft_tools::GlyphSnap,
    /// Pixel Snapping Options: whether View › Snap to Pixel snaps drawing, moving and scaling
    /// (`view.snapToPixel.options`; a preference group, see [`cmd::prefscmds::PREF_GROUPS`]).
    pub pixel_snap: vectorcraft_tools::PixelSnap,
    /// Edit → Transparency Flattener Presets: the user's presets (the built-in ones aren't stored).
    /// Not a `prefs.set` key or group (resetting the preferences keeps them): `flattener.presets.*`
    /// edit it.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub flattener_presets: Vec<cmd::FlattenerPreset>,
    /// Image Trace panel › Manage Presets: the user's tracing presets (the built-in ones aren't
    /// stored). Not a `prefs.set` key or group (resetting the preferences keeps them):
    /// `imageTrace.presets.*` edit it.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub trace_presets: Vec<cmd::TracePreset>,
    /// Gradient panel › Presets: the user's saved gradients (the built-in presets aren't stored).
    /// A local library, not a Preferences dialog field: resetting the preferences keeps it;
    /// `gradient.presets.*` edit it.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub gradient_presets: Vec<cmd::GradientPreset>,
    /// Width profiles saved to the Stroke panel's Profile list (`stroke.widthProfile.*`). Not a
    /// Preferences dialog field, so it has no [`cmd::prefscmds::PREF_SPECS`] row.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub width_profiles: Vec<vectorcraft_doc::SavedProfile>,
    /// General → Use Japanese Crop Marks: the style of Create Trim Marks and Effect → Crop Marks.
    pub japanese_crop_marks: bool,
    /// Appearance panel → New Art Has Basic Appearance (on): new art takes one fill and stroke;
    /// off, the whole appearance of the last selection (`appearance.setNewArtBasic`).
    pub new_art_basic: bool,
    /// The Color Themes panel's saved themes (`colorTheme.*`): a local library, not a Preferences
    /// dialog field, so it has no [`cmd::prefscmds::PREF_SPECS`] row and resetting keeps it.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub color_themes: Vec<cmd::colortheme::ColorTheme>,
    /// New Document → Saved: the user's document presets (`file.newPresets.save`). A local
    /// library, not a Preferences dialog field: resetting the preferences keeps it.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub new_doc_presets: Vec<cmd::newdoc::DocSettings>,
    /// New Document → Recent: the settings of the last documents made (newest first).
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub recent_new_docs: Vec<cmd::newdoc::DocSettings>,
    /// Edit → PDF Presets: the user's presets (the built-in ones aren't stored). A local library,
    /// not a Preferences dialog field: resetting the preferences keeps it; `pdf.preset.*` edit it.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub pdf_presets: Vec<vectorcraft_pdf::PdfPreset>,
    /// File → Export for Screens: the user's batch export presets (`document.exportPresets.*`;
    /// the built-in ones aren't stored). A local library, not a Preferences dialog field.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub screen_export_presets: Vec<cmd::fileio::ScreenExportPreset>,
    // File Handling (continued)
    /// Where Save as Template and New from Template start ("" = `Documents/VectorCraft Templates`).
    pub templates_folder: String,
    /// File Handling → Use System Defaults for Edit Original (#5236): Links panel › Edit Original
    /// opens a linked file in the system's default app for it; off, in the app that made it
    /// (PhotoCraft for a raster image, where it is installed; the system's app otherwise).
    pub edit_original_system_defaults: bool,
    /// Open older native files as "<name> [Converted]" so Save asks for a new name.
    pub append_converted: bool,
    /// File Handling → Use Compression: native saves are gzip-compressed (`document.save
    /// {compress}` overrides it).
    pub use_compression: bool,
    /// Save for Web: the user's presets (the built-in ones aren't stored). A local library, not a
    /// Preferences dialog field: resetting the preferences keeps it; `webExport.presets.*` edit it.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub web_export_presets: Vec<cmd::webexport::WebPreset>,
    /// The VectorCraft Options a native Save or Save As used last (Preview, Embed ICC Profiles,
    /// Create PDF-Compatible File…; not the artboards it picked, nor Use Compression, which its
    /// preference decides): `file.formatOptions` offers them for a document not yet saved as a
    /// native file. Not a Preferences dialog field.
    #[serde(skip_serializing_if = "serde_json::Map::is_empty")]
    pub native_save_options: serde_json::Map<String, serde_json::Value>,
    /// Save for Web: the settings the dialog opens on (`webExport.settings`); none until set.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub web_export_settings: Option<cmd::webexport::WebSettings>,
    /// Edit → Print Presets: the user's presets ([Default] isn't stored). A local library, not a
    /// Preferences dialog field: resetting the preferences keeps it; `print.presets.*` edit it.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub print_presets: Vec<cmd::printpresets::PrintPreset>,
    /// Constrain Width and Height Proportions: the link between W and H in the Transform panel,
    /// the Properties panel and the Control bar (their size fields pass `proportional` to
    /// `object.setBounds`).
    pub constrain_proportions: bool,
    /// One Corner Radius field sets every corner of a live rectangle (off: a field per corner).
    pub single_corner_radius: bool,
    /// The Transform panel menu's Transform Object Only / Transform Pattern Only / Transform Both
    /// (`object`, `pattern`, `both`): what the panel's fields, flips and menu flips transform
    /// (they pass `objects` and `patterns` to the transform commands). `default` (and any other
    /// value), until one is chosen: they pass neither, so patterns follow General › Transform
    /// Pattern Tiles (`transformPatternTiles`), as before the menu acted.
    pub transform_panel_patterns: String,
    /// The Transform panel menu's Use Registration Point for Symbol: with one symbol instance
    /// selected, the panel and the Properties panel's Transform section measure and transform it
    /// from its symbol's registration point instead of the reference point.
    pub use_registration_point_for_symbol: bool,
    /// The Transform panel menu's Show on Shape Creation: drawing a shape with the Rectangle,
    /// Rounded Rectangle, Ellipse, Polygon, Star or Line Segment tool (a drag or OK in the tool's
    /// dialog, also on the active perspective plane), a shape the Shaper tool recognizes, or running
    /// one of [`crate::DRAWS_SHAPE`], shows the Transform panel.
    pub show_on_shape_creation: bool,
    /// The tools' persistent options by store (a tool id, or a store a family shares: `liquify`
    /// holds the Liquify tools' Global Brush Dimensions), see [`vectorcraft_tools::settings`]:
    /// kept across tool switches and saved with the preferences. Not a Preferences dialog field:
    /// resetting the preferences keeps them; `tool.setOption` edits them.
    #[serde(skip_serializing_if = "std::collections::BTreeMap::is_empty")]
    pub tool_settings: std::collections::BTreeMap<String, serde_json::Map<String, Value>>,
    /// View → Perspective Grid presets: the user's (the built-in ones aren't stored). A local
    /// library, not a Preferences dialog field: resetting the preferences keeps it;
    /// `perspective.presets.*` edit it.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub perspective_presets: Vec<vectorcraft_tools::distort::perspective::GridDefinition>,
    /// Blend Options set with no blend selected: what new blends start with
    /// (`object.blend.options`; none: Smooth Color, Align to Page). A tool setting, not a
    /// Preferences dialog field: it has no [`cmd::prefscmds::PREF_SPECS`] row and resetting the
    /// preferences keeps it.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub blend_options: Option<vectorcraft_doc::live::BlendDefaults>,
    /// Perspective Grid Options (double-click the Perspective Grid tool): whether the Plane
    /// Switching Widget shows and where (`perspective.widget.options`).
    pub perspective_widget: vectorcraft_tools::distort::perspective::widget::WidgetOptions,
    /// What names and codes in other apps' shortcut sets stand for, as the user confirmed them on
    /// import (`importMatches.*`). A local library, not a Preferences dialog field: resetting the
    /// preferences keeps it.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub import_matches: Vec<cmd::importmatches::ImportMatch>,
}

/// The default Hold Shortcut Delay, in seconds (VectorCraft's own value).
pub const KEY_HOLD_DELAY: f64 = 0.35;
/// The range of the Hold Shortcut Delay, in seconds.
pub const KEY_HOLD_DELAY_RANGE: (f64, f64) = (0.2, 1.0);

impl Prefs {
    /// The Hold Shortcut Delay in seconds, inside its range. A restored settings file is not
    /// checked against the range, so a value outside it is brought inside, and one that is not a
    /// number gives the default.
    pub fn key_hold_delay(&self) -> f64 {
        let (min, max) = KEY_HOLD_DELAY_RANGE;
        if self.key_hold_delay.is_finite() { self.key_hold_delay.clamp(min, max) } else { KEY_HOLD_DELAY }
    }
}

impl Default for Prefs {
    fn default() -> Self {
        let s = |v: &str| v.to_string();
        Self {
            keyboard_increment: 1.0,
            constrain_angle: 0.0,
            corner_radius: 12.0,
            disable_auto_add_delete: false,
            interpolate_control_points: false,
            use_precise_cursors: false,
            show_tool_tips: true,
            show_tool_cards: false,
            show_external_script_warning: true,
            anti_aliased_artwork: true,
            select_same_tint_percent: false,
            show_home_screen: true,
            use_preview_bounds: false,
            align_glyph_bounds_point: false,
            align_glyph_bounds_area: false,
            type_glyph_bounds: false,
            fade_region_outside_artboard: true,
            artboard_update_while_dragging: true,
            display_print_size: false,
            double_click_to_isolate: true,
            transform_pattern_tiles: false,
            scale_corners: false,
            scale_strokes: false,
            zoom_with_mouse_wheel: false,
            ctrl_wheel_scrolls_sideways: true,
            scrub_numeric_fields: true,
            trackpad_rotate_view: true,
            hold_tool_keys: true,
            hold_shortcuts: false,
            key_hold_delay: KEY_HOLD_DELAY,
            bounding_box_while_moving_and_drawing: false,
            paste_offset: 10.0,
            selection_tolerance: 3.0,
            marquee_selection: "touching".into(),
            object_selection_by_path_only: false,
            snap_to_point_tolerance: 2.0,
            ctrl_click_selects_behind: true,
            zoom_to_selection: true,
            move_locked_with_artboard: false,
            anchor_size: 3,
            handle_style: s("solid"),
            highlight_anchors_on_hover: true,
            show_handles_multiple_anchors: true,
            hide_corner_widget_above: 177.0,
            pen_rubber_band: true,
            curvature_rubber_band: true,
            type_size_increment: 2.0,
            tracking_increment: 20.0,
            baseline_shift_increment: 2.0,
            show_east_asian_options: false,
            show_indic_options: false,
            type_selection_by_path_only: false,
            font_names_in_english: true,
            auto_size_area_type: false,
            font_preview: true,
            font_samples_on_white: false,
            font_preview_size: s("medium"),
            recent_fonts_count: 10,
            missing_glyph_protection: true,
            highlight_alternate_glyphs: false,
            show_character_alternates: true,
            highlight_substituted_fonts: true,
            placeholder_text: true,
            typed_lists: true,
            units_general: s("points"),
            units_stroke: s("points"),
            units_type: s("points"),
            units_asian_type: s("points"),
            numbers_without_units_are_points: true,
            identify_objects_by: s("objectName"),
            guide_color: s("#4affff"),
            guide_style: s("lines"),
            lock_guides_by_default: false,
            cmd_ruler_drag_artboard_guides: false,
            grid_color: s("#c8c8c8"),
            grid_style: s("lines"),
            gridline_every: 72.0,
            grid_subdivisions: 8,
            grids_in_back: true,
            show_pixel_grid: true,
            smart_guide_color: s("#ff3dfc"),
            alignment_guides: true,
            object_highlighting: true,
            transform_tools_guides: true,
            construction_guides: true,
            construction_angles: s(vectorcraft_tools::guides::DEFAULT_CONSTRUCTION_ANGLES),
            anchor_path_labels: true,
            measurement_labels: true,
            spacing_guides: true,
            distance_guides: true,
            snap_to_last_location: false,
            snapping_tolerance: 4.0,
            snap_tangent: true,
            snap_perpendicular: true,
            show_slice_numbers: true,
            slice_line_color: s("#ff3f3f"),
            hyphenation_language: s("en-US"),
            hyphenation_exceptions: String::new(),
            fonts_folder: String::new(),
            plugins_folder: String::new(),
            plugin_instruction_budget: PluginBudget::Normal,
            scratch_primary: s("Startup"),
            scratch_secondary: s("None"),
            ui_brightness: s("mediumDark"),
            ui_accent: s("coral"),
            ui_color_scheme: s("modern"),
            canvas_color: s("matchUi"),
            auto_collapse_icon_panels: false,
            tool_group_labels: false,
            open_documents_as_tabs: true,
            large_tabs: false,
            ui_scaling: 1.0,
            scale_cursor_with_ui: false,
            interface_language: s("auto"),
            system_title_bar: false,
            app_title_bar: false,
            gpu_performance: true,
            animated_zoom: true,
            gpu_preference: s("automatic"),
            low_latency_drawing: false,
            history_states: 500,
            real_time_drawing: true,
            render_threads: -1,
            linux_display_server: s("automatic"),
            monitor_profile_display: true,
            background_save: true,
            background_export: true,
            autosave_recovery: true,
            autosave_interval: 2,
            recovery_folder: String::new(),
            recovery_off_for_complex: false,
            recent_files_count: 20,
            low_res_proxy_eps: false,
            anti_aliased_bitmaps: false,
            update_links: s("askWhenModified"),
            copy_as_svg: true,
            copy_as_pdf: false,
            copy_aicb: false,
            aicb_mode: s("preserveAppearance"),
            paste_text_formatting: s("keep"),
            black_on_screen: s("accurate"),
            black_output: s("accurate"),
            touch_workspace: true,
            touch_gestures: true,
            override_char_color: true,
            pattern_tile_edge_color: {
                let [r, g, b] = vectorcraft_doc::LAYER_COLORS[0].1;
                Color::rgb8(r, g, b).to_hex()
            },
            eyedropper: Default::default(),
            pathfinder: Default::default(),
            glyph_snap: Default::default(),
            pixel_snap: Default::default(),
            flattener_presets: vec![],
            trace_presets: vec![],
            gradient_presets: vec![],
            width_profiles: vec![],
            japanese_crop_marks: false,
            new_art_basic: true,
            color_themes: vec![],
            new_doc_presets: vec![],
            recent_new_docs: vec![],
            pdf_presets: vec![],
            screen_export_presets: vec![],
            templates_folder: String::new(),
            edit_original_system_defaults: true,
            append_converted: true,
            use_compression: false,
            web_export_presets: vec![],
            native_save_options: serde_json::Map::new(),
            web_export_settings: None,
            print_presets: vec![],
            constrain_proportions: false,
            single_corner_radius: true,
            transform_panel_patterns: "default".to_string(),
            use_registration_point_for_symbol: false,
            show_on_shape_creation: false,
            tool_settings: Default::default(),
            perspective_presets: vec![],
            blend_options: None,
            perspective_widget: Default::default(),
            import_matches: vec![],
        }
    }
}