use crate::core::canvas_entities::{
BackgroundImageInfo, BackgroundImageMutation, HobbyDirConstraint, HobbyNodeInfo,
};
use crate::core::{FontPoint, NodeId, NodeType, TransformGridAnchor};
use crate::snapping::SelectedGuideRef;
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum GuideAlignment {
#[default]
Lsb,
Center,
Rsb,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct AnchorId(pub u64);
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CanvasAnchor {
pub id: AnchorId,
pub name: String,
pub position: FontPoint,
pub selected: bool,
}
impl CanvasAnchor {
#[must_use]
pub fn new(id: AnchorId, name: impl Into<String>, position: FontPoint) -> Self {
Self {
id,
name: name.into(),
position,
selected: false,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct GlyphBaseInfo {
pub glyph_name: String,
pub bbox_x: f64,
pub bbox_y: f64,
pub bbox_w: f64,
pub bbox_h: f64,
pub lsb: f64,
pub rsb: f64,
pub advance_width: f64,
pub active_slot_kerning_left: Option<i32>,
pub kern_with_prev: Option<i32>,
pub kern_with_next: Option<i32>,
pub transform_anchor: TransformGridAnchor,
pub proportional_scale: bool,
pub contour_count: usize,
pub total_node_count: usize,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SingleOnCurveInfo {
pub node_id: NodeId,
pub x: f64,
pub y: f64,
pub node_type: NodeType,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SingleOffCurveInfo {
pub node_id: NodeId,
pub anchor_node_id: NodeId,
pub tethered_oncurve_id: NodeId,
pub x: f64,
pub y: f64,
pub delta_x: f64,
pub delta_y: f64,
pub length: f64,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MultiNodeInfo {
pub origin_anchor: TransformGridAnchor,
pub origin_x: f64,
pub origin_y: f64,
pub width: f64,
pub height: f64,
pub proportional_scale: bool,
pub selected_node_count: usize,
pub total_layer_node_count: usize,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct GuideInfo {
pub guide_ref: SelectedGuideRef,
pub x: f64,
pub y: f64,
pub angle_deg: f64,
pub alignment: GuideAlignment,
pub lock_angle: bool,
pub show_measurement: bool,
}
#[derive(Clone, Debug, PartialEq)]
pub enum SelectionInfo {
GlyphBase(GlyphBaseInfo),
SingleOnCurve(SingleOnCurveInfo),
SingleOffCurve(SingleOffCurveInfo),
MultiNode(MultiNodeInfo),
Guide(GuideInfo),
HobbyNode(HobbyNodeInfo),
BackgroundImage(BackgroundImageInfo),
GradientStop {
sublayer_index: usize,
stop_index: usize,
offset_pct: f64,
rgba: [u8; 4],
},
PostScriptHint {
hint_id: u64,
horizontal: bool,
origin_upm: f64,
width_upm: f64,
is_ghost: bool,
top_ghost: bool,
},
TrueTypeInstruction {
instruction_id: u64,
kind: crate::core::hinting_and_hoi::TrueTypeInstructionKind,
ppem: u16,
round_mode: crate::core::hinting_and_hoi::TrueTypeRoundingGrid,
stem_index: Option<u8>,
zone_index: Option<u8>,
},
HoiTiming {
c1_x: f64,
c1_y: f64,
c2_x: f64,
c2_y: f64,
},
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum SelectionInfoAction {
SetLsb(f64),
SetRsb(f64),
SetAdvanceWidth(f64),
CenterInWidth,
SetOnCurvePosition(FontPoint),
ToggleOnCurveSmooth,
SetOffCurvePosition(FontPoint),
SetOffCurveDelta {
dx: f64,
dy: f64,
},
SetHandleLength(f64),
SetMultiAnchor(TransformGridAnchor),
SetMultiProportional(bool),
SetMultiOrigin(FontPoint),
SetMultiSize {
width: Option<f64>,
height: Option<f64>,
},
SetGuideOrigin(FontPoint),
SetGuideAngle(f64),
SetGuideAlignment(GuideAlignment),
SetGuideLockAngle(bool),
SetGuideMeasurement(bool),
SetAnchorPosition(FontPoint),
SetAnchorName(String),
ResetDefaultAnchors,
SetComponentTransform(crate::core::anchors_components::Affine2D),
SetComponentLocked(bool),
SetComponentAutoAlignment(bool),
DecomposeComponents,
SetHobbyNode {
tension_in: f64,
tension_out: f64,
dir_constraint: HobbyDirConstraint,
},
MutateBackgroundImage(BackgroundImageMutation),
ResetBackgroundImageTransform,
MutateGradientStop {
offset_pct: f64,
rgba: [u8; 4],
},
MutatePostScriptHint {
origin_upm: f64,
width_upm: f64,
top_ghost: bool,
},
MutateTrueTypeInstruction {
kind: crate::core::hinting_and_hoi::TrueTypeInstructionKind,
ppem: u16,
round_mode: crate::core::hinting_and_hoi::TrueTypeRoundingGrid,
stem_index: Option<u8>,
zone_index: Option<u8>,
},
SetHoiTiming {
c1_x: f64,
c1_y: f64,
c2_x: f64,
c2_y: f64,
},
MutateHoiNode {
layer_index: usize,
contour_index: usize,
node_id: NodeId,
new_pos: FontPoint,
c1: FontPoint,
c2: FontPoint,
},
}