use super::{LayoutBox, LayoutKind};
pub(super) fn layout_command(text: &str, fs: f64, dpi: f64) -> Option<LayoutBox> {
if text != "△" {
return None;
}
let em = super::source_roman_advance::em_advance(fs, dpi).unwrap_or(fs);
Some(LayoutBox {
font_size: fs,
x: 0.0,
y: 0.0,
width: super::source_font_text::logical_advance(1024, em, dpi),
height: fs,
baseline: fs * 0.8,
kind: LayoutKind::FontGlyph {
text: "∆".to_string(),
font_family: "Haansoft Batang, 한컴바탕, Batang, 바탕, serif",
paint: None,
outline: None,
},
})
}
pub(super) fn operator_metrics(text: &str, fs: f64, dpi: f64) -> Option<(f64, f64)> {
let (advance, padding) = match text {
"+" => (795, 0.14),
"-" | "−" => (774, 0.14),
"=" => (795, 0.21),
":" => (283, 0.21),
"<" | ">" => (864, 0.21),
"≤" | "≥" => (1024, 0.21),
"≠" => (1024, 0.15),
"×" => (831, 0.14),
"±" => (831, 0.14),
"∓" => (1024, 0.14),
"∙" => (1024, 0.14),
"⋅" => (1024, 0.0),
"/" => (512, 0.0),
"%" => (853, 0.0),
_ => return None,
};
let advance_size = super::source_roman_advance::em_advance(fs, dpi).unwrap_or(fs);
Some((
super::source_font_text::logical_advance(advance, advance_size, dpi),
fs * padding,
))
}
pub(super) fn layout(text: &str, fs: f64, dpi: f64) -> Option<LayoutBox> {
if matches!(text, "←" | "→") {
let em = super::source_roman_advance::em_advance(fs, dpi).unwrap_or(fs);
return Some(LayoutBox {
font_size: fs,
x: 0.0,
y: 0.0,
width: super::source_font_text::logical_advance(1024, em, dpi),
height: fs,
baseline: fs * 0.8,
kind: LayoutKind::MathSymbol(text.to_owned()),
});
}
if matches!(text, "{" | "}") {
return Some(LayoutBox {
font_size: fs,
x: 0.0,
y: 0.0,
width: super::source_font_text::logical_advance(594, fs, dpi),
height: fs,
baseline: fs * 0.8,
kind: LayoutKind::FontGlyph {
text: text.to_string(),
font_family: "HYhwpEQ, Latin Modern Math, STIX Two Math, serif",
paint: None,
outline: Some(super::super::brace_outline::commands(
fs,
dpi,
fs * 0.8,
text == "}",
)),
},
});
}
if text == "%" {
let (width, _) = operator_metrics(text, fs, dpi)?;
return Some(LayoutBox {
font_size: fs,
x: 0.0,
y: 0.0,
width,
height: fs,
baseline: fs * 0.8,
kind: LayoutKind::FontGlyph {
text: "\u{e042}".to_string(),
font_family: "HYhwpEQ, Latin Modern Math, STIX Two Math, serif",
paint: None,
outline: None,
},
});
}
if matches!(text, "±" | "∓" | "∙" | "⋅") {
let (width, _) = operator_metrics(text, fs, dpi)?;
return Some(LayoutBox {
font_size: fs,
x: 0.0,
y: 0.0,
width,
height: fs,
baseline: fs * 0.8,
kind: LayoutKind::FontGlyph {
text: text.to_string(),
font_family: "HYhwpEQ, Latin Modern Math, STIX Two Math, serif",
paint: None,
outline: super::super::dot_geometry::commands(text, fs, dpi, fs * 0.8),
},
});
}
if matches!(text, "×" | "≠") {
let (width, _) = operator_metrics(text, fs, dpi)?;
let baseline = fs * 0.8;
return Some(LayoutBox {
font_size: fs,
x: 0.0,
y: 0.0,
width,
height: fs,
baseline,
kind: LayoutKind::FontGlyph {
text: text.to_string(),
font_family: "Latin Modern Math, STIX Two Math, serif",
paint: None,
outline: Some(if text == "×" {
super::super::multiplication_outline::commands(fs, width, baseline)
} else {
super::super::not_equal_geometry::commands(fs, baseline)
}),
},
});
}
if !matches!(text, "'" | "′") {
return None;
}
Some(LayoutBox {
font_size: fs,
x: 0.0,
y: 0.0,
width: super::source_font_advance::measured(fs, dpi, 2).unwrap_or(fs * 276.0 / 1024.0),
height: fs,
baseline: fs * 0.8,
kind: LayoutKind::FontGlyph {
text: "′".to_string(),
font_family: "Haansoft Batang, 한컴바탕, Batang, 바탕, serif",
paint: None,
outline: None,
},
})
}
pub(super) fn layout_operator_outline(text: &str, fs: f64, dpi: f64) -> Option<LayoutBox> {
let display = if text == "-" { "−" } else { text };
let baseline = fs * 0.8;
let commands = super::super::operator_outline::commands(display, fs, dpi, baseline)
.or_else(|| super::super::relation_outline::commands(display, fs, dpi, baseline))?;
let (width, _) = operator_metrics(display, fs, dpi)?;
Some(LayoutBox {
font_size: fs,
x: 0.0,
y: 0.0,
width,
height: fs,
baseline,
kind: LayoutKind::FontGlyph {
text: display.to_string(),
font_family: "Latin Modern Math, STIX Two Math, serif",
paint: None,
outline: Some(commands),
},
})
}