summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-01-22 13:16:03 +0100
committerLaurenz <laurmaedje@gmail.com>2023-01-22 13:16:03 +0100
commiteabbbf7eae04a4a8044d83acde84d8634f095b50 (patch)
tree74682b60a8fdff575233afb59356bfa4803749d2
parent85f95f75b749bb7c160ba92d9f6008031f02c882 (diff)
Name handling for New Computer Modern Math
-rw-r--r--library/src/math/mod.rs22
-rw-r--r--src/font/book.rs8
-rw-r--r--tests/typ/text/font.typ2
-rw-r--r--tests/typ/text/symbol.typ2
4 files changed, 19 insertions, 15 deletions
diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs
index ce70f1de..785e027a 100644
--- a/library/src/math/mod.rs
+++ b/library/src/math/mod.rs
@@ -102,24 +102,24 @@ impl MathNode {
}
impl Show for MathNode {
- fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> SourceResult<Content> {
- let mut map = StyleMap::new();
- map.set_family(FontFamily::new("NewComputerModernMath"), styles);
-
- let mut realized = self
- .clone()
- .pack()
- .guarded(Guard::Base(NodeId::of::<Self>()))
- .styled_with_map(map);
-
+ fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> SourceResult<Content> {
+ let mut realized = self.clone().pack().guarded(Guard::Base(NodeId::of::<Self>()));
if self.block {
realized = realized.aligned(Axes::with_x(Some(Align::Center.into())))
}
-
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 {
fn layout(
&self,
diff --git a/src/font/book.rs b/src/font/book.rs
index dfc6140c..25b1fc85 100644
--- a/src/font/book.rs
+++ b/src/font/book.rs
@@ -299,7 +299,7 @@ fn decode_mac_roman(coded: &[u8]) -> String {
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 {
// Separators between names, modifiers and styles.
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.
diff --git a/tests/typ/text/font.typ b/tests/typ/text/font.typ
index 170703c7..0889a0f3 100644
--- a/tests/typ/text/font.typ
+++ b/tests/typ/text/font.typ
@@ -31,7 +31,7 @@ Emoji: 🐪, 🌋, 🏞
]
// Disable font fallback beyond the user-specified list.
-// Without disabling, NewComputerModernMath would come to the rescue.
+// Without disabling, New Computer Modern Math would come to the rescue.
#set text("PT Sans", "Twitter Color Emoji", fallback: false)
2π = 𝛼 + 𝛽. ✅
diff --git a/tests/typ/text/symbol.typ b/tests/typ/text/symbol.typ
index 4dcef58b..f758c779 100644
--- a/tests/typ/text/symbol.typ
+++ b/tests/typ/text/symbol.typ
@@ -6,7 +6,7 @@
:woman:old:
:turtle:
-#set text("NewComputerModernMath")
+#set text("New Computer Modern Math")
:arrow:
:arrow:l:
:arrow:r:squiggly: