Name handling for New Computer Modern Math

This commit is contained in:
Laurenz 2023-01-22 13:16:03 +01:00
parent 85f95f75b7
commit eabbbf7eae
4 changed files with 19 additions and 15 deletions

View File

@ -102,24 +102,24 @@ impl MathNode {
} }
impl Show for MathNode { impl Show for MathNode {
fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> SourceResult<Content> { fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> SourceResult<Content> {
let mut map = StyleMap::new(); let mut realized = self.clone().pack().guarded(Guard::Base(NodeId::of::<Self>()));
map.set_family(FontFamily::new("NewComputerModernMath"), styles);
let mut realized = self
.clone()
.pack()
.guarded(Guard::Base(NodeId::of::<Self>()))
.styled_with_map(map);
if self.block { if self.block {
realized = realized.aligned(Axes::with_x(Some(Align::Center.into()))) realized = realized.aligned(Axes::with_x(Some(Align::Center.into())))
} }
Ok(realized) Ok(realized)
} }
} }
impl Finalize for MathNode {
fn finalize(&self, realized: Content) -> Content {
realized.styled(
TextNode::FAMILY,
FallbackList(vec![FontFamily::new("New Computer Modern Math")]),
)
}
}
impl Layout for MathNode { impl Layout for MathNode {
fn layout( fn layout(
&self, &self,

View File

@ -299,7 +299,7 @@ fn decode_mac_roman(coded: &[u8]) -> String {
coded.iter().copied().map(char_from_mac_roman).collect() coded.iter().copied().map(char_from_mac_roman).collect()
} }
/// Trim style naming from a family name. /// Trim style naming from a family name and fix bad names.
fn typographic_family(mut family: &str) -> &str { fn typographic_family(mut family: &str) -> &str {
// Separators between names, modifiers and styles. // Separators between names, modifiers and styles.
const SEPARATORS: [char; 3] = [' ', '-', '_']; const SEPARATORS: [char; 3] = [' ', '-', '_'];
@ -349,7 +349,11 @@ fn typographic_family(mut family: &str) -> &str {
} }
} }
&family[..len] // Fix bad names.
match &family[..len] {
"NewComputerModernMath" => "New Computer Modern Math",
other => other,
}
} }
/// How many words the two strings share in their prefix. /// How many words the two strings share in their prefix.