use super::{FontMetric, LatinRange};
#[path = "font_metric_konghan_hft.rs"]
mod konghan;
#[path = "font_metric_system_hft.rs"]
mod system;
static ASCII_0: [u16; 95] = [
400, 500, 400, 660, 660, 1000, 1000, 400, 500, 500, 500, 1000, 400, 500, 400, 500, 660, 660,
660, 660, 660, 660, 660, 660, 660, 660, 500, 500, 500, 1000, 500, 660, 1000, 782, 713, 764,
771, 761, 730, 819, 771, 340, 585, 710, 689, 872, 769, 818, 719, 819, 767, 712, 746, 771, 726,
988, 683, 716, 742, 500, 500, 500, 500, 500, 400, 662, 622, 565, 622, 618, 480, 620, 628, 294,
294, 562, 294, 896, 627, 621, 623, 622, 467, 574, 456, 627, 567, 783, 573, 559, 649, 500, 500,
500, 1000,
];
static RANGES_0: [LatinRange; 1] = [LatinRange {
start: 0x0020,
end: 0x007e,
widths: &ASCII_0,
}];
static ASCII_1: [u16; 95] = [
400, 500, 400, 620, 620, 1000, 1000, 400, 500, 500, 500, 1000, 400, 500, 400, 500, 620, 620,
620, 620, 620, 620, 620, 620, 620, 620, 500, 500, 500, 1000, 500, 620, 1000, 779, 696, 756,
759, 694, 663, 811, 755, 299, 558, 698, 619, 867, 752, 812, 719, 808, 758, 698, 656, 754, 725,
1010, 720, 710, 641, 500, 500, 500, 500, 500, 400, 571, 619, 521, 619, 575, 400, 573, 578, 244,
243, 519, 243, 860, 578, 574, 577, 577, 363, 528, 315, 577, 524, 747, 550, 502, 511, 500, 500,
500, 1000,
];
static RANGES_1: [LatinRange; 1] = [LatinRange {
start: 0x0020,
end: 0x007e,
widths: &ASCII_1,
}];
static ASCII_2: [u16; 95] = [
1000, 325, 423, 450, 602, 920, 814, 386, 395, 374, 524, 567, 235, 572, 244, 390, 500, 500, 500,
500, 500, 500, 500, 500, 500, 500, 276, 292, 729, 570, 734, 511, 920, 794, 704, 690, 749, 677,
654, 742, 784, 337, 450, 792, 645, 959, 777, 748, 629, 755, 703, 648, 774, 773, 780, 1037, 754,
769, 599, 362, 397, 352, 429, 500, 382, 509, 556, 485, 543, 482, 352, 588, 560, 277, 314, 557,
274, 858, 564, 516, 534, 548, 405, 486, 351, 562, 581, 840, 590, 574, 474, 418, 280, 421, 500,
];
static SQUARE_ROOT_2: [u16; 1] = [1000];
static BULLET_2: [u16; 1] = [1000];
static EN_DASH_2: [u16; 1] = [1000];
static RANGES_2: [LatinRange; 4] = [
LatinRange {
start: 0x0020,
end: 0x007e,
widths: &ASCII_2,
},
LatinRange {
start: 0x2013,
end: 0x2013,
widths: &EN_DASH_2,
},
LatinRange {
start: 0x2022,
end: 0x2022,
widths: &BULLET_2,
},
LatinRange {
start: 0x221a,
end: 0x221a,
widths: &SQUARE_ROOT_2,
},
];
static ASCII_3: [u16; 95] = [
1000, 248, 420, 535, 529, 867, 643, 240, 288, 281, 369, 518, 246, 518, 245, 263, 500, 500, 500,
500, 500, 500, 500, 500, 500, 500, 247, 245, 583, 519, 582, 524, 999, 632, 629, 699, 693, 649,
594, 751, 689, 246, 470, 631, 539, 803, 692, 749, 637, 754, 692, 636, 584, 688, 632, 904, 619,
619, 585, 253, 283, 253, 448, 500, 256, 534, 527, 483, 531, 532, 255, 529, 529, 195, 196, 473,
195, 809, 529, 539, 535, 531, 310, 480, 255, 531, 479, 697, 470, 466, 485, 310, 237, 306, 500,
];
static RANGES_3: [LatinRange; 19] = [
LatinRange {
start: 0x0020,
end: 0x007e,
widths: &ASCII_3,
},
single(0x00b7, &[381]),
single(0x2015, &[1000]),
LatinRange {
start: 0x2018,
end: 0x2019,
widths: &[225, 225],
},
LatinRange {
start: 0x201c,
end: 0x201d,
widths: &[375, 375],
},
LatinRange {
start: 0x2026,
end: 0x2027,
widths: &[1000, 500],
},
single(0x203b, &[1000]),
single(0x2192, &[1000]),
single(0x25a1, &[1000]),
single(0x25cb, &[1000]),
single(0x3000, &[1000]),
LatinRange {
start: 0x3004,
end: 0x3005,
widths: &[1000, 1000],
},
LatinRange {
start: 0x3007,
end: 0x3011,
widths: &[1000; 11],
},
LatinRange {
start: 0x3014,
end: 0x3015,
widths: &[1000, 1000],
},
LatinRange {
start: 0x301a,
end: 0x301c,
widths: &[1000, 1000, 1000],
},
single(0x302b, &[1000]),
single(0x338f, &[1000]),
single(0x339c, &[1000]),
single(0x33a1, &[1000]),
];
static ASCII_4: [u16; 95] = [
400, 500, 400, 680, 680, 1000, 1000, 400, 500, 500, 500, 1000, 400, 500, 400, 500, 680, 680,
680, 680, 680, 680, 680, 680, 680, 680, 500, 500, 500, 1000, 500, 680, 1000, 816, 772, 775,
785, 714, 678, 889, 831, 319, 653, 786, 653, 1066, 895, 888, 714, 854, 775, 769, 719, 889, 779,
1149, 847, 731, 697, 500, 500, 500, 500, 500, 400, 644, 694, 584, 696, 643, 457, 699, 703, 323,
322, 598, 323, 1050, 700, 697, 693, 694, 458, 583, 382, 705, 634, 929, 651, 635, 527, 500, 500,
500, 1000,
];
static RANGES_4: [LatinRange; 5] = [
LatinRange {
start: 0x0020,
end: 0x007e,
widths: &ASCII_4,
},
single(0x00b7, &[381]),
LatinRange {
start: 0x2018,
end: 0x2019,
widths: &[200, 200],
},
LatinRange {
start: 0x201c,
end: 0x201d,
widths: &[300, 300],
},
single(0x3005, &[1000]),
];
static ASCII_5: [u16; 95] = [
400, 500, 400, 600, 600, 1000, 1000, 400, 500, 500, 500, 1000, 400, 500, 400, 500, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 500, 500, 500, 1000, 500, 600, 1000, 725, 798, 788,
846, 771, 692, 850, 847, 374, 654, 769, 646, 961, 792, 845, 659, 854, 753, 711, 671, 834, 742,
969, 768, 689, 683, 500, 500, 500, 500, 500, 400, 648, 705, 607, 708, 605, 389, 620, 745, 372,
371, 703, 372, 1027, 748, 644, 706, 663, 500, 607, 451, 768, 607, 859, 644, 698, 563, 500, 500,
500, 1000,
];
static RANGES_5: [LatinRange; 4] = [
LatinRange {
start: 0x0020,
end: 0x007e,
widths: &ASCII_5,
},
single(0x00b7, &[384]),
LatinRange {
start: 0x2018,
end: 0x2019,
widths: &[200, 200],
},
LatinRange {
start: 0x201c,
end: 0x201d,
widths: &[400, 400],
},
];
const fn single(code: u32, widths: &'static [u16]) -> LatinRange {
LatinRange {
start: code,
end: code,
widths,
}
}
pub(super) static METRICS: [FontMetric; 8] = [
FontMetric {
name: "신명 디나루 (HFT)",
bold: false,
italic: false,
em_size: 1000,
latin_ranges: &RANGES_0,
hangul: None,
},
FontMetric {
name: "신명 신그래픽 (HFT)",
bold: false,
italic: false,
em_size: 1000,
latin_ranges: &RANGES_1,
hangul: None,
},
FontMetric {
name: "한양신명조 (HFT)",
bold: false,
italic: false,
em_size: 1000,
latin_ranges: &RANGES_2,
hangul: None,
},
FontMetric {
name: "한양중고딕 (HFT)",
bold: false,
italic: false,
em_size: 1000,
latin_ranges: &RANGES_3,
hangul: None,
},
FontMetric {
name: "신명 중고딕 (HFT)",
bold: false,
italic: false,
em_size: 1000,
latin_ranges: &RANGES_4,
hangul: None,
},
FontMetric {
name: "신명 순명조 (HFT)",
bold: false,
italic: false,
em_size: 1000,
latin_ranges: &RANGES_5,
hangul: None,
},
konghan::METRIC,
system::METRIC,
];
pub(crate) fn metric_face_name(requested: &str) -> Option<&'static str> {
match requested {
"한양신명조" | "HanyangSinMyeongJo" => Some("한양신명조 (HFT)"),
"한양중고딕" | "HanyangJungGothic" => Some("한양중고딕 (HFT)"),
"신명 디나루" => Some("신명 디나루 (HFT)"),
"신명 신그래픽" => Some("신명 신그래픽 (HFT)"),
"신명 중고딕" => Some("신명 중고딕 (HFT)"),
"신명 순명조" => Some("신명 순명조 (HFT)"),
"중간공한" | "Konghan Normal" => Some("중간공한 (HFT)"),
"시스템" => Some("시스템 (HFT)"),
_ => None,
}
}
pub(crate) fn is_metric_face(name: &str) -> bool {
METRICS.iter().any(|metric| metric.name == name)
}
fn owns_regular_bar(face: &str, character: char) -> bool {
let source = metric_face_name(face).unwrap_or(face);
character == '\u{2013}' && source == "한양신명조 (HFT)"
}
pub(crate) fn rejects_regular_bar_style(
face: &str,
bold: bool,
italic: bool,
character: char,
) -> bool {
owns_regular_bar(face, character) && (bold || italic)
}
pub(crate) fn centered_bar_advance_em(
face: &str,
bold: bool,
italic: bool,
character: char,
) -> Option<f64> {
if !owns_regular_bar(face, character)
|| rejects_regular_bar_style(face, bold, italic, character)
{
return None;
}
let source = metric_face_name(face).unwrap_or(face);
let metric = METRICS.iter().find(|metric| metric.name == source)?;
Some(f64::from(metric.get_width(character)?) / f64::from(metric.em_size))
}