Files
texrra-engine/crates/texrra-tex-core/src/cmr10.rs
T

69 lines
2.2 KiB
Rust

// Computer Modern Roman 10pt character widths, extracted from cmr10.tfm
// with tftopl. Values are scaled points at 10pt design size.
#[derive(Clone, Debug)]
pub struct Cmr10Metrics {}
impl Default for Cmr10Metrics {
fn default() -> Self {
Self::new()
}
}
impl Cmr10Metrics {
pub const fn new() -> Self {
Self {}
}
pub fn width(&self, character: char) -> i64 {
self.widths()
.get(character as usize)
.copied()
.unwrap_or(327_680)
}
pub fn space(&self) -> i64 {
218_454
}
pub fn stretch(&self) -> i64 {
109_227
}
pub fn shrink(&self) -> i64 {
72_818
}
fn widths(&self) -> &'static [i64; 128] {
&CMR10_WIDTHS
}
}
const CMR10_WIDTHS: [i64; 128] = [
409601, 546135, 509727, 455112, 436908, 491521, 473317, 509727, 473317, 509727, 473317, 382295,
364090, 364090, 546135, 546135, 182045, 200250, 327681, 327681, 327681, 327681, 327681, 491521,
291272, 327682, 473317, 509727, 327681, 591647, 664464, 509727, 182045, 182045, 327681, 546135,
327681, 546135, 509727, 182045, 254863, 254863, 327681, 509727, 182045, 218454, 182045, 327681,
327681, 327681, 327681, 327681, 327681, 327681, 327681, 327681, 327681, 327681, 182045, 182045,
182045, 509727, 309477, 309477, 509727, 491521, 464215, 473317, 500624, 446010, 427807, 514277,
491521, 236658, 336783, 509727, 409601, 600748, 491521, 509727, 446010, 509727, 482419, 364090,
473317, 491521, 491521, 673567, 491521, 491521, 400499, 182045, 327681, 182045, 327681, 182045,
182045, 327681, 364090, 291272, 364090, 291272, 200250, 327681, 364090, 182045, 200250, 345887,
182045, 546135, 364090, 327681, 364090, 345885, 256684, 258503, 254863, 364090, 345887, 473317,
345887, 345887, 291272, 327681, 655362, 327681, 327681, 327681,
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn reads_cmr10_widths() {
let font = Cmr10Metrics::new();
assert!(font.width('A') > 450_000);
assert!((font.width('a') - 327_681).abs() <= 2);
assert!((font.space() - 218_454).abs() <= 2);
assert!(font.stretch() > 0);
assert!(font.shrink() > 0);
}
}