use std::collections::HashMap;
use std::sync::OnceLock;
use crate::renderer::font_rule_layout_metric_projection::find_font_rule_layout_metric;
#[path = "font_metrics_vertical.rs"]
mod vertical;
pub(crate) use vertical::win_descent_em;
#[path = "font_metric_han_santteut.rs"]
mod han_santteut;
#[path = "font_metric_legacy_hft.rs"]
mod legacy_hft;
#[path = "font_metric_hci_poppy.rs"]
mod hci_poppy;
#[path = "font_metric_hci_tulip.rs"]
mod hci_tulip;
#[path = "font_metric_math_alphabet.rs"]
mod math_alphabet;
#[path = "font_metric_math_symbols.rs"]
mod math_symbols;
#[path = "font_metric_cjk_punctuation.rs"]
mod cjk_punctuation;
#[path = "font_metric_supplementary_pictographs.rs"]
mod supplementary_pictographs;
#[path = "font_metric_contextual_scripts.rs"]
mod contextual_scripts;
#[path = "font_metric_math_symbol_blocks.rs"]
mod math_symbol_blocks;
#[path = "font_metric_hangul_jamo.rs"]
mod hangul_jamo;
pub(crate) fn uses_hangul_jamo_overlay(metric: &FontMetric, character: char) -> bool {
hangul_jamo::width(metric, character).is_some()
}
#[path = "font_metric_symbol_slot_chars.rs"]
mod symbol_slot_chars;
#[path = "font_metric_nimbus_roman.rs"]
mod nimbus_roman;
pub(crate) use legacy_hft::{
centered_bar_advance_em as original_hft_centered_bar_advance_em,
is_metric_face as is_legacy_hft_metric_face, metric_face_name as legacy_hft_metric_face,
};
pub(crate) fn is_verified_original_hft_advance(metric: &FontMetric) -> bool {
hci_poppy::METRICS
.iter()
.any(|source| std::ptr::eq(source, metric))
}
#[derive(Debug)]
pub struct HangulMetric {
pub cho_groups: u8,
pub jung_groups: u8,
pub jong_groups: u8,
pub cho_map: &'static [u8],
pub jung_map: &'static [u8],
pub jong_map: &'static [u8],
pub widths: &'static [u16],
}
#[derive(Debug)]
pub struct FontMetric {
pub name: &'static str,
pub bold: bool,
pub italic: bool,
pub em_size: u16,
pub latin_ranges: &'static [LatinRange],
pub hangul: Option<&'static HangulMetric>,
}
pub(crate) fn source_descent_em(name: &str, bold: bool, italic: bool) -> Option<f64> {
let metric = find_metric(name, bold, italic)?.metric;
match metric.name {
"Gulim" | "GulimChe" | "Dotum" | "DotumChe" => Some(145.0 / 1024.0),
_ => None,
}
}
#[derive(Debug)]
pub struct LatinRange {
pub start: u32,
pub end: u32,
pub widths: &'static [u16],
}
impl FontMetric {
pub fn get_width(&self, ch: char) -> Option<u16> {
let code = ch as u32;
if let Some(width) = hangul_jamo::width(self, ch) {
return Some(width);
}
if code >= 0xAC00 && code <= 0xD7A3 {
if let Some(h) = self.hangul {
let idx = code - 0xAC00;
let cho = (idx / (21 * 28)) as usize;
let jung = ((idx % (21 * 28)) / 28) as usize;
let jong = (idx % 28) as usize;
let gi = h.cho_map[cho] as usize * h.jung_groups as usize * h.jong_groups as usize
+ h.jung_map[jung] as usize * h.jong_groups as usize
+ h.jong_map[jong] as usize;
return h.widths.get(gi).copied();
}
return None;
}
for range in self.latin_ranges {
if code < range.start || code > range.end {
continue;
}
let idx = (code - range.start) as usize;
let Some(&w) = range.widths.get(idx) else {
continue;
};
return if w > 0 {
Some(w)
} else {
supplementary_pictographs::width(self, ch)
.or_else(|| contextual_scripts::width(self, ch))
};
}
verified_technical_symbol_width(self, ch)
.or_else(|| math_symbols::width(self, ch))
.or_else(|| math_alphabet::width(self, ch))
.or_else(|| math_symbol_blocks::width(self, ch))
.or_else(|| supplementary_pictographs::width(self, ch))
.or_else(|| contextual_scripts::width(self, ch))
.or_else(|| symbol_slot_chars::width(self, ch))
}
}
include!("font_metrics_technical_symbols.rs");
pub(crate) fn verified_metric_has_glyph(metric: &FontMetric, ch: char) -> Option<bool> {
if nimbus_roman_metric_source(metric).is_some() {
return Some(metric.get_width(ch).is_some());
}
verified_program_has_glyph(metric, ch)
.or_else(|| math_symbols::has_glyph(metric, ch))
.or_else(|| math_alphabet::entry(metric, ch).map(|(present, _)| present))
.or_else(|| cjk_punctuation::primary_has_glyph(metric.name, metric.bold, metric.italic, ch))
.or_else(|| math_symbol_blocks::entry(metric, ch).map(|(present, _)| present))
.or_else(|| supplementary_pictographs::entry(metric, ch).map(|(present, _)| present))
.or_else(|| contextual_scripts::entry(metric, ch).map(|(present, _)| present))
.or_else(|| symbol_slot_chars::entry(metric, ch).map(|(present, _)| present))
}
pub(crate) fn verified_named_program_has_glyph(
family: &str,
bold: bool,
italic: bool,
ch: char,
) -> Option<bool> {
math_alphabet::primary_has_glyph(family, bold, italic, ch)
.or_else(|| cjk_punctuation::primary_has_glyph(family, bold, italic, ch))
.or_else(|| supplementary_pictographs::primary_has_glyph(family, bold, italic, ch))
.or_else(|| contextual_scripts::primary_has_glyph(family, bold, italic, ch))
}
pub(crate) fn verified_program_glyph_fallback_families(face: &str) -> &'static [&'static str] {
match find_metric(face, false, false).map(|found| found.metric.name) {
Some("HumanMyeongJo" | "DotumChe" | "HYSinMyeongJo-Medium" | "HYHeadLine-Medium") => {
&["Haansoft Batang"]
}
Some("Gulim" | "Dotum") => &["Haansoft Dotum"],
_ => &[],
}
}
pub(crate) fn verified_missing_glyph_supplier(
metric: &FontMetric,
ch: char,
) -> Option<&'static str> {
match (metric.name, metric.em_size, metric.bold, metric.italic, ch) {
("Arial", 2048, false, false, '\u{2024}' | '\u{2027}') => Some("Haansoft Batang"),
("DotumChe", 1024, false, false, '\u{2024}') => Some("Haansoft Batang"),
("GulimChe", 1024, false, false, '\u{2024}') => Some("Haansoft Batang"),
("Batang", 1024, false, false, '\u{2024}') => Some("Haansoft Batang"),
("Gulim", 1024, false, false, '\u{2024}' | '\u{2027}') => Some("Haansoft Dotum"),
("Dotum", 1024, false, false, '\u{2024}') => Some("Haansoft Dotum"),
("HYSinMyeongJo-Medium", 1024, false, false, '\u{2024}' | '\u{2027}') => {
Some("Haansoft Batang")
}
("HYHeadLine-Medium", 1024, false, false, '\u{2024}') => Some("Haansoft Batang"),
_ => None,
}
}
pub struct MetricMatch {
pub metric: &'static FontMetric,
pub bold_fallback: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum MetricMatchKind {
Exact,
BoldOnly,
NameFirst,
}
impl MetricMatchKind {
pub(crate) const fn as_str(self) -> &'static str {
match self {
Self::Exact => "exact",
Self::BoldOnly => "boldOnly",
Self::NameFirst => "nameFirst",
}
}
}
#[derive(Debug, Clone, Copy)]
struct MetricSelection {
metric: &'static FontMetric,
bold_fallback: bool,
match_kind: MetricMatchKind,
entry_index: usize,
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct MetricLookupDecision<'a> {
pub(crate) requested_name: &'a str,
pub(crate) alias_resolved_name: &'a str,
pub(crate) alias_rule_id: Option<&'static str>,
pub(crate) metric: &'static FontMetric,
pub(crate) bold_fallback: bool,
pub(crate) match_kind: MetricMatchKind,
pub(crate) entry_index: usize,
}
fn resolve_projected_metric_alias(name: &str) -> (&str, Option<&'static str>) {
match find_font_rule_layout_metric(name) {
Some(rule) => (rule.target_face_or_policy, Some(rule.rule_id)),
None if name == "양재난초체M" => ("Yj NANCHO Medium", None),
None => (name, None),
}
}
fn strip_postscript_weight_suffix(name: &str) -> Option<(&str, bool)> {
let (family, weight) = name.rsplit_once('-')?;
match weight {
"Regular" | "Medium" => Some((family, false)),
"Bold" => Some((family, true)),
_ => None,
}
}
fn metric_slot_index(bold: bool, italic: bool) -> usize {
((bold as usize) << 1) | (italic as usize)
}
static METRIC_INDEX: OnceLock<HashMap<&'static str, [MetricSelection; 4]>> = OnceLock::new();
fn metric_index() -> &'static HashMap<&'static str, [MetricSelection; 4]> {
METRIC_INDEX.get_or_init(|| {
struct FirstSeen {
exact: [Option<(&'static FontMetric, usize)>; 4],
first: (&'static FontMetric, usize),
}
let mut seen: HashMap<&'static str, FirstSeen> = HashMap::new();
for (entry_index, m) in FONT_METRICS.iter().enumerate() {
let entry = seen.entry(m.name).or_insert(FirstSeen {
exact: [None; 4],
first: (m, entry_index),
});
let idx = metric_slot_index(m.bold, m.italic);
if entry.exact[idx].is_none() {
entry.exact[idx] = Some((m, entry_index));
}
}
seen.into_iter()
.map(|(name, fs)| {
let mut slots = [MetricSelection {
metric: fs.first.0,
bold_fallback: false,
match_kind: MetricMatchKind::NameFirst,
entry_index: fs.first.1,
}; 4];
for bold in [false, true] {
for italic in [false, true] {
slots[metric_slot_index(bold, italic)] =
if let Some((metric, entry_index)) =
fs.exact[metric_slot_index(bold, italic)]
{
MetricSelection {
metric,
bold_fallback: false,
match_kind: MetricMatchKind::Exact,
entry_index,
}
} else if let Some((metric, entry_index)) =
fs.exact[metric_slot_index(bold, false)]
{
MetricSelection {
metric,
bold_fallback: false,
match_kind: MetricMatchKind::BoldOnly,
entry_index,
}
} else {
MetricSelection {
metric: fs.first.0,
bold_fallback: bold,
match_kind: MetricMatchKind::NameFirst,
entry_index: fs.first.1,
}
};
}
}
(name, slots)
})
.collect()
})
}
pub fn find_metric(name: &str, bold: bool, italic: bool) -> Option<MetricMatch> {
let decision = find_metric_decision(name, bold, italic)?;
Some(MetricMatch {
metric: decision.metric,
bold_fallback: decision.bold_fallback,
})
}
#[derive(Clone, Copy)]
struct MetricNameResolution {
alias: Option<&'static str>,
alias_rule_id: Option<&'static str>,
slots: Option<&'static [MetricSelection; 4]>,
}
fn resolve_metric_name(name: &str) -> MetricNameResolution {
const RECENT: usize = 8;
thread_local! {
static RECENT_NAMES: std::cell::RefCell<Vec<(Box<str>, MetricNameResolution)>> =
const { std::cell::RefCell::new(Vec::new()) };
}
RECENT_NAMES.with(|recent| {
let mut recent = recent.borrow_mut();
if let Some((_, resolution)) = recent.iter().find(|(cached, _)| **cached == *name) {
return *resolution;
}
let (alias_resolved_name, alias_rule_id) = resolve_projected_metric_alias(name);
let resolution = MetricNameResolution {
alias: static_metric_alias(name),
alias_rule_id,
slots: metric_index().get(alias_resolved_name),
};
if recent.len() >= RECENT {
recent.remove(0);
}
recent.push((name.into(), resolution));
resolution
})
}
fn static_metric_alias(name: &str) -> Option<&'static str> {
match find_font_rule_layout_metric(name) {
Some(rule) => Some(rule.target_face_or_policy),
None if name == "양재난초체M" => Some("Yj NANCHO Medium"),
None => None,
}
}
pub(crate) fn find_metric_decision<'a>(
name: &'a str,
bold: bool,
italic: bool,
) -> Option<MetricLookupDecision<'a>> {
let mut resolution = resolve_metric_name(name);
let mut lookup_name = name;
let mut bold = bold;
if resolution.slots.is_none() {
let (family, suffix_bold) = strip_postscript_weight_suffix(name)?;
lookup_name = family;
resolution = resolve_metric_name(family);
bold |= suffix_bold;
}
let alias_resolved_name = resolution.alias.unwrap_or(lookup_name);
let alias_rule_id = resolution.alias_rule_id;
let slots = resolution.slots?;
let selected = slots[metric_slot_index(bold, italic)];
Some(MetricLookupDecision {
requested_name: name,
alias_resolved_name,
alias_rule_id,
metric: selected.metric,
bold_fallback: selected.bold_fallback,
match_kind: selected.match_kind,
entry_index: selected.entry_index,
})
}
pub(crate) fn regular_advance_metric(bold_metric: &FontMetric) -> Option<&'static FontMetric> {
if !bold_metric.bold {
return None;
}
let slots = metric_index().get(bold_metric.name)?;
let regular = slots[metric_slot_index(false, bold_metric.italic)];
(regular.match_kind == MetricMatchKind::Exact
&& !regular.metric.bold
&& regular.metric.italic == bold_metric.italic
&& regular.metric.em_size == bold_metric.em_size)
.then_some(regular.metric)
}
pub(crate) fn find_metric_decision_for_character<'a>(
name: &'a str,
bold: bool,
italic: bool,
character: char,
) -> Option<MetricLookupDecision<'a>> {
let mut decision = find_metric_decision(name, bold, italic)?;
if legacy_hft::is_metric_face(decision.metric.name)
&& legacy_hft::rejects_regular_bar_style(decision.metric.name, bold, italic, character)
{
return None;
}
if character.is_whitespace() {
return Some(decision);
}
let Some((source_slot, source)) = hci_poppy::METRICS.iter().enumerate().find(|(_, source)| {
decision.alias_resolved_name == source.name
&& bold == source.bold
&& italic == source.italic
&& source.get_width(character).is_some()
}) else {
return Some(decision);
};
static SOURCE_INDICES: OnceLock<Vec<Option<usize>>> = OnceLock::new();
let indices = SOURCE_INDICES.get_or_init(|| {
hci_poppy::METRICS
.iter()
.map(|source| {
FONT_METRICS
.iter()
.position(|entry| std::ptr::eq(entry, source))
})
.collect()
});
if let Some(index) = indices[source_slot] {
decision.metric = source;
decision.entry_index = index;
decision.match_kind = MetricMatchKind::Exact;
decision.bold_fallback = false;
}
Some(decision)
}
pub fn layout_metric_face_name(font_family: &str, bold: bool, italic: bool) -> Option<String> {
let primary = font_family
.split(',')
.next()
.unwrap_or(font_family)
.trim()
.trim_matches('\'');
let lower = primary.to_lowercase().replace(' ', "");
if primary.contains("KoPub돋움체")
|| primary.contains("KoPubWorld돋움체")
|| lower.contains("kopubdotum")
|| lower.contains("kopubworlddotum")
|| primary.contains("KoPub바탕체")
|| primary.contains("KoPubWorld바탕체")
|| lower.contains("kopubbatang")
|| lower.contains("kopubworldbatang")
{
return Some(primary.to_string());
}
find_metric(primary, bold, italic).map(|m| m.metric.name.to_string())
}
#[cfg(test)]
fn legacy_find_metric(name: &str, bold: bool, italic: bool) -> Option<MetricMatch> {
let (name, _) = resolve_projected_metric_alias(name);
if let Some(m) = FONT_METRICS
.iter()
.find(|m| m.name == name && m.bold == bold && m.italic == italic)
{
return Some(MetricMatch {
metric: m,
bold_fallback: false,
});
}
if let Some(m) = FONT_METRICS
.iter()
.find(|m| m.name == name && m.bold == bold && !m.italic)
{
return Some(MetricMatch {
metric: m,
bold_fallback: false,
});
}
FONT_METRICS
.iter()
.find(|m| m.name == name)
.map(|m| MetricMatch {
metric: m,
bold_fallback: bold,
})
}
include!("font_metrics_generated.rs");
include!("font_metrics_overlays.rs");
include!("font_metrics_core14.rs");
pub(crate) fn core14_metric_source(metric: &FontMetric) -> Option<(&'static str, &'static str)> {
if !CORE14_FONT_METRICS
.iter()
.any(|entry| std::ptr::eq(entry, metric))
{
return None;
}
Some(match (metric.bold, metric.italic) {
(false, false) => (
"data/font-metrics/adobe-core14/Helvetica.afm",
"CORE14_0_RANGES",
),
(true, false) => (
"data/font-metrics/adobe-core14/Helvetica-Bold.afm",
"CORE14_1_RANGES",
),
(false, true) => (
"data/font-metrics/adobe-core14/Helvetica-Oblique.afm",
"CORE14_2_RANGES",
),
(true, true) => (
"data/font-metrics/adobe-core14/Helvetica-BoldOblique.afm",
"CORE14_3_RANGES",
),
})
}
pub(crate) fn nimbus_roman_metric_source(metric: &FontMetric) -> Option<&'static str> {
if !metric.name.starts_with("Nimbus") {
return None;
}
nimbus_roman::METRICS
.iter()
.any(|entry| std::ptr::eq(entry, metric))
.then_some("data/font-metrics/nimbus-roman/source.json")
}
struct FontMetrics;
static FONT_METRICS: FontMetrics = FontMetrics;
impl FontMetrics {
fn iter(&self) -> impl Iterator<Item = &'static FontMetric> {
GENERATED_FONT_METRICS
.iter()
.chain(MEASURED_FONT_METRIC_OVERLAYS.iter())
.chain(CORE14_FONT_METRICS.iter())
.chain(han_santteut::METRICS.iter())
.chain(legacy_hft::METRICS.iter())
.chain(hci_poppy::METRICS.iter())
.chain(hci_tulip::METRICS.iter())
.chain(nimbus_roman::METRICS.iter())
}
}
#[cfg(test)]
mod tests {
use super::*;
use sha2::{Digest, Sha256};
const NOTO_SANS_KR_REGULAR: &[u8] =
include_bytes!("../../ttfs/opensource/NotoSansKR-Regular.ttf");
#[test]
fn issue_4442_noto_sans_kr_ascii_advances_match_tracked_font() {
let digest = Sha256::digest(NOTO_SANS_KR_REGULAR);
assert_eq!(
&digest[..],
&[
0x6e, 0x06, 0xa7, 0xfe, 0x5d, 0x69, 0x6c, 0xa7, 0x19, 0x89, 0x4a, 0x23, 0xf3, 0x6b,
0xb2, 0xb1, 0xbe, 0x8c, 0x81, 0x6a, 0x59, 0x37, 0xcd, 0x4a, 0xd0, 0xf2, 0x3c, 0xa6,
0x77, 0x80, 0xdd, 0x74,
]
);
let face = ttf_parser::Face::parse(NOTO_SANS_KR_REGULAR, 0)
.expect("tracked bundled font must parse");
let metric = find_metric("Noto Sans KR", false, false).expect("shared regular metric");
assert_eq!(metric.metric.em_size, face.units_per_em());
for ch in ' '..='~' {
let glyph = face.glyph_index(ch).expect("printable ASCII glyph");
let advance = face
.glyph_hor_advance(glyph)
.expect("printable ASCII horizontal advance");
assert_eq!(
metric.metric.get_width(ch),
Some(advance),
"shared advance for {ch:?}"
);
}
}
#[test]
fn hy_gothic_medium_maps_correctly() {
let m = find_metric("HY중고딕", false, false);
assert!(m.is_some(), "HY중고딕 매핑 실패");
assert_eq!(m.unwrap().metric.name, "HYGothic-Medium");
}
#[test]
fn hy_family_all_map() {
for (korean, expected_english) in &[
("HY중고딕", "HYGothic-Medium"),
("HY견고딕", "HYGothic-Extra"),
("HY헤드라인M", "HYHeadLine-Medium"),
("HY견명조", "HYMyeongJo-Extra"),
("HY신명조", "HYSinMyeongJo-Medium"),
("HY그래픽", "HYGraphic-Medium"),
("HY궁서", "HYGungSo-Bold"),
("한컴 윤고딕 230", "Haan YGodic 230"),
] {
let m = find_metric(korean, false, false);
assert!(m.is_some(), "{} 매핑 실패", korean);
assert_eq!(
m.unwrap().metric.name,
*expected_english,
"{} 이 {} 에 매핑되지 않음",
korean,
expected_english
);
}
}
#[test]
fn source_han_sans_family_maps_to_pretendard() {
for name in &[
"본한글",
"본한글vf",
"본한글 Medium",
"본한글M",
"본고딕",
"본고딕vf",
"Source Han Sans",
"Source Han Sans K",
"Source Han Sans KR",
"SourceHanSans",
"SourceHanSansKR",
"SourceHanSansK",
"Noto Sans CJK KR",
] {
let m = find_metric(name, false, false);
assert!(m.is_some(), "{} 매핑 실패 (Pretendard 기대)", name);
assert_eq!(m.unwrap().metric.name, "Pretendard");
}
}
#[test]
fn source_han_serif_family_maps_to_noto_serif_kr() {
for name in &[
"본명조",
"본명조vf",
"본명조M",
"Source Han Serif",
"Source Han Serif K",
"Source Han Serif KR",
"SourceHanSerif",
"SourceHanSerifKR",
"SourceHanSerifK",
"Noto Serif CJK KR",
] {
let m = find_metric(name, false, false);
assert!(m.is_some(), "{} 매핑 실패 (Noto Serif KR 기대)", name);
assert_eq!(m.unwrap().metric.name, "Noto Serif KR");
}
}
#[test]
fn hy_family_bold_fallback() {
let m = find_metric("HY중고딕", true, false);
assert!(m.is_some(), "HY중고딕 bold 폴백 실패");
let mm = m.unwrap();
assert_eq!(mm.metric.name, "HYGothic-Medium");
assert!(
mm.bold_fallback,
"HY중고딕 bold 요청 시 bold_fallback=true 여야 함"
);
}
#[test]
fn task885_hy_extra_aliases_resolve() {
for (korean, expected_english) in &[
("HY수평선B", "HYsupB"),
("HY수평선M", "HYsupM"),
("HY울릉도B", "HYwulB"),
("HY울릉도M", "HYwulM"),
("HY태백B", "HYtbrB"),
("HY동녘B", "HYdnkB"),
("HY동녘M", "HYdnkM"),
("HY각헤드라인M", "HYHeadLine-Medium"),
] {
let m = find_metric(korean, false, false);
assert!(m.is_some(), "{} 별칭 매핑 실패", korean);
assert_eq!(
m.unwrap().metric.name,
*expected_english,
"{} 이 {} 에 매핑되지 않음",
korean,
expected_english
);
}
}
#[test]
fn non_korean_font_unchanged() {
let m = find_metric("함초롬바탕", false, false);
assert!(m.is_some(), "함초롬바탕 기존 매핑 회귀");
assert_eq!(m.unwrap().metric.name, "HCR Batang");
}
#[test]
fn index_matches_legacy_linear_scan_exhaustively() {
let mut names: Vec<&str> = FONT_METRICS.iter().map(|m| m.name).collect();
names.extend([
"함초롬돋움",
"한컴돋움",
"돋움",
"함초롬바탕",
"한컴바탕",
"바탕",
"맑은 고딕",
"나눔고딕",
"나눔명조",
"바탕체",
"굴림",
"궁서",
"굴림체",
"돋움체",
"궁서체",
"D2Coding",
"D2 Coding",
"고운바탕",
"Gowun Batang",
"고운돋움",
"Gowun Dodum",
"Pretendard",
"프리텐다드",
"HY중고딕",
"HY견고딕",
"HY헤드라인M",
"HY견명조",
"HY신명조",
"HY그래픽",
"HY궁서",
"한양신명조",
"한양중고딕",
"한양견명조",
"한양견고딕",
"휴먼명조",
"신명조",
"HY수평선B",
"HY수평선M",
"HY울릉도B",
"HY울릉도M",
"HY태백B",
"HY동녘B",
"HY동녘M",
"HY각헤드라인M",
"본한글",
"본한글vf",
"본한글 Medium",
"본한글M",
"본고딕",
"본고딕vf",
"Source Han Sans",
"Source Han Sans K",
"Source Han Sans KR",
"SourceHanSans",
"SourceHanSansKR",
"SourceHanSansK",
"Noto Sans CJK KR",
"본명조",
"본명조vf",
"본명조M",
"Source Han Serif",
"Source Han Serif K",
"Source Han Serif KR",
"SourceHanSerif",
"SourceHanSerifKR",
"SourceHanSerifK",
"Noto Serif CJK KR",
]);
names.extend([
"NoSuchFont-Regular",
"가상의사용자폰트",
"Comic Sans MS",
"",
]);
for name in names {
for bold in [false, true] {
for italic in [false, true] {
let new = find_metric(name, bold, italic);
let old = legacy_find_metric(name, bold, italic);
match (new, old) {
(None, None) => {}
(Some(n), Some(o)) => {
assert!(
std::ptr::eq(n.metric, o.metric),
"metric 불일치: {name:?} bold={bold} italic={italic} \
(new={}/b{}/i{}, old={}/b{}/i{})",
n.metric.name,
n.metric.bold,
n.metric.italic,
o.metric.name,
o.metric.bold,
o.metric.italic,
);
assert_eq!(
n.bold_fallback, o.bold_fallback,
"bold_fallback 불일치: {name:?} bold={bold} italic={italic}"
);
}
(n, o) => panic!(
"Some/None 불일치: {name:?} bold={bold} italic={italic} \
new={} old={}",
n.is_some(),
o.is_some()
),
}
}
}
}
}
}