use super::GlyphOutlineCommand as Command;
const PLUS: &[Command] = &[
Command::Move((722.0, 250.0)),
Command::Cubic([(722.0, 261.0), (713.0, 270.0), (702.0, 270.0)]),
Command::Line((409.0, 270.0)),
Command::Line((409.0, 563.0)),
Command::Cubic([(409.0, 574.0), (400.0, 583.0), (389.0, 583.0)]),
Command::Cubic([(378.0, 583.0), (369.0, 574.0), (369.0, 563.0)]),
Command::Line((369.0, 270.0)),
Command::Line((76.0, 270.0)),
Command::Cubic([(65.0, 270.0), (56.0, 261.0), (56.0, 250.0)]),
Command::Cubic([(56.0, 239.0), (65.0, 230.0), (76.0, 230.0)]),
Command::Line((369.0, 230.0)),
Command::Line((369.0, -63.0)),
Command::Cubic([(369.0, -74.0), (378.0, -83.0), (389.0, -83.0)]),
Command::Cubic([(400.0, -83.0), (409.0, -74.0), (409.0, -63.0)]),
Command::Line((409.0, 230.0)),
Command::Line((702.0, 230.0)),
Command::Cubic([(713.0, 230.0), (722.0, 239.0), (722.0, 250.0)]),
Command::Close,
];
const MINUS: &[Command] = &[
Command::Move((722.0, 250.0)),
Command::Cubic([(722.0, 261.0), (713.0, 270.0), (702.0, 270.0)]),
Command::Line((76.0, 270.0)),
Command::Cubic([(65.0, 270.0), (56.0, 261.0), (56.0, 250.0)]),
Command::Cubic([(56.0, 239.0), (65.0, 230.0), (76.0, 230.0)]),
Command::Line((702.0, 230.0)),
Command::Cubic([(713.0, 230.0), (722.0, 239.0), (722.0, 250.0)]),
Command::Close,
];
const EQUAL: &[Command] = &[
Command::Move((722.0, 347.0)),
Command::Cubic([(722.0, 358.0), (713.0, 367.0), (702.0, 367.0)]),
Command::Line((76.0, 367.0)),
Command::Cubic([(65.0, 367.0), (56.0, 358.0), (56.0, 347.0)]),
Command::Cubic([(56.0, 336.0), (65.0, 327.0), (76.0, 327.0)]),
Command::Line((702.0, 327.0)),
Command::Cubic([(713.0, 327.0), (722.0, 336.0), (722.0, 347.0)]),
Command::Close,
Command::Move((722.0, 153.0)),
Command::Cubic([(722.0, 164.0), (713.0, 173.0), (702.0, 173.0)]),
Command::Line((76.0, 173.0)),
Command::Cubic([(65.0, 173.0), (56.0, 164.0), (56.0, 153.0)]),
Command::Cubic([(56.0, 142.0), (65.0, 133.0), (76.0, 133.0)]),
Command::Line((702.0, 133.0)),
Command::Cubic([(713.0, 133.0), (722.0, 142.0), (722.0, 153.0)]),
Command::Close,
];
pub(super) fn commands(text: &str, fs: f64, dpi: f64, baseline: f64) -> Option<Vec<Command>> {
let (outline, source, target) = match text {
"+" => (
PLUS,
(56.0, -83.0, 722.0, 583.0),
(57.0, -58.0, 738.0, 623.0),
),
"−" => (
MINUS,
(56.0, 230.0, 722.0, 270.0),
(57.0, 267.0, 718.0, 308.0),
),
"=" => (
EQUAL,
(56.0, 133.0, 722.0, 367.0),
(57.0, 164.0, 738.0, 403.0),
),
_ => return None,
};
let origin = baseline - super::negation_geometry::math_origin_shift(fs, dpi);
let map = |(x, y): (f64, f64)| {
(
fs * (target.0 + (x - source.0) * (target.2 - target.0) / (source.2 - source.0))
/ 1024.0,
origin
- fs * (target.1 + (y - source.1) * (target.3 - target.1) / (source.3 - source.1))
/ 1024.0,
)
};
Some(
outline
.iter()
.map(|command| match *command {
Command::Move(p) => Command::Move(map(p)),
Command::Line(p) => Command::Line(map(p)),
Command::Cubic(p) => Command::Cubic(p.map(map)),
Command::Close => Command::Close,
})
.collect(),
)
}