]> git.scottworley.com Git - tablify/commitdiff
Explicitly specify a font for tally marks
authorScott Worley <scottworley@scottworley.com>
Sun, 12 Jul 2026 02:53:13 +0000 (19:53 -0700)
committerScott Worley <scottworley@scottworley.com>
Sun, 12 Jul 2026 02:54:07 +0000 (19:54 -0700)
Changelog
src/lib.rs

index 7fd5cc8015f481d4d60a90273d37622948c5b4f5..9a64d5add01912fea0695f4a6eb672ef88286541 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,5 @@
 ## [Unreleased]
 ## [Unreleased]
+- Explicitly specify a font for tally marks
 
 ## [0.6.1] - 2025-07-16
 - Minor cleanups
 
 ## [0.6.1] - 2025-07-16
 - Minor cleanups
index 1807333a3608f9a3202b241cdeebef79bf612130..bfcfdec72aa9d9186cb017c6cba14b6a75bfcf62 100644 (file)
@@ -4,12 +4,15 @@ use std::fmt::Write;
 use std::io::BufRead;
 use std::iter::Iterator;
 
 use std::io::BufRead;
 use std::iter::Iterator;
 
+const TALLY_FONT: &str = "BabelStone Han";
+
 fn tally_marks(n: usize, mark: Option<&str>) -> HTML {
     HTML(match mark {
         None => {
             let fives = { 0..n / 5 }.map(|_| '𝍸');
             let ones = { 0..n % 5 }.map(|_| '𝍷');
 fn tally_marks(n: usize, mark: Option<&str>) -> HTML {
     HTML(match mark {
         None => {
             let fives = { 0..n / 5 }.map(|_| '𝍸');
             let ones = { 0..n % 5 }.map(|_| '𝍷');
-            fives.chain(ones).collect()
+            let marks: String = fives.chain(ones).collect();
+            format!("<span style=\"font-family: '{TALLY_FONT}'\">{marks}</span>")
         }
         Some(m) => { 0..n }.map(|_| m).collect(),
     })
         }
         Some(m) => { 0..n }.map(|_| m).collect(),
     })
@@ -504,17 +507,72 @@ mod tests {
 
     #[test]
     fn test_tally_marks() {
 
     #[test]
     fn test_tally_marks() {
-        assert_eq!(tally_marks(1, None), "𝍷".into());
-        assert_eq!(tally_marks(2, None), "𝍷𝍷".into());
-        assert_eq!(tally_marks(3, None), "𝍷𝍷𝍷".into());
-        assert_eq!(tally_marks(4, None), "𝍷𝍷𝍷𝍷".into());
-        assert_eq!(tally_marks(5, None), "𝍸".into());
-        assert_eq!(tally_marks(6, None), "𝍸𝍷".into());
-        assert_eq!(tally_marks(7, None), "𝍸𝍷𝍷".into());
-        assert_eq!(tally_marks(8, None), "𝍸𝍷𝍷𝍷".into());
-        assert_eq!(tally_marks(9, None), "𝍸𝍷𝍷𝍷𝍷".into());
-        assert_eq!(tally_marks(10, None), "𝍸𝍸".into());
-        assert_eq!(tally_marks(11, None), "𝍸𝍸𝍷".into());
+        assert_eq!(
+            tally_marks(1, None),
+            HTML(format!(
+                "<span style=\"font-family: '{TALLY_FONT}'\">𝍷</span>"
+            ))
+        );
+        assert_eq!(
+            tally_marks(2, None),
+            HTML(format!(
+                "<span style=\"font-family: '{TALLY_FONT}'\">𝍷𝍷</span>"
+            ))
+        );
+        assert_eq!(
+            tally_marks(3, None),
+            HTML(format!(
+                "<span style=\"font-family: '{TALLY_FONT}'\">𝍷𝍷𝍷</span>"
+            ))
+        );
+        assert_eq!(
+            tally_marks(4, None),
+            HTML(format!(
+                "<span style=\"font-family: '{TALLY_FONT}'\">𝍷𝍷𝍷𝍷</span>"
+            ))
+        );
+        assert_eq!(
+            tally_marks(5, None),
+            HTML(format!(
+                "<span style=\"font-family: '{TALLY_FONT}'\">𝍸</span>"
+            ))
+        );
+        assert_eq!(
+            tally_marks(6, None),
+            HTML(format!(
+                "<span style=\"font-family: '{TALLY_FONT}'\">𝍸𝍷</span>"
+            ))
+        );
+        assert_eq!(
+            tally_marks(7, None),
+            HTML(format!(
+                "<span style=\"font-family: '{TALLY_FONT}'\">𝍸𝍷𝍷</span>"
+            ))
+        );
+        assert_eq!(
+            tally_marks(8, None),
+            HTML(format!(
+                "<span style=\"font-family: '{TALLY_FONT}'\">𝍸𝍷𝍷𝍷</span>"
+            ))
+        );
+        assert_eq!(
+            tally_marks(9, None),
+            HTML(format!(
+                "<span style=\"font-family: '{TALLY_FONT}'\">𝍸𝍷𝍷𝍷𝍷</span>"
+            ))
+        );
+        assert_eq!(
+            tally_marks(10, None),
+            HTML(format!(
+                "<span style=\"font-family: '{TALLY_FONT}'\">𝍸𝍸</span>"
+            ))
+        );
+        assert_eq!(
+            tally_marks(11, None),
+            HTML(format!(
+                "<span style=\"font-family: '{TALLY_FONT}'\">𝍸𝍸𝍷</span>"
+            ))
+        );
         assert_eq!(tally_marks(1, Some("x")), "x".into());
         assert_eq!(tally_marks(4, Some("x")), "xxxx".into());
         assert_eq!(tally_marks(5, Some("x")), "xxxxx".into());
         assert_eq!(tally_marks(1, Some("x")), "x".into());
         assert_eq!(tally_marks(4, Some("x")), "xxxx".into());
         assert_eq!(tally_marks(5, Some("x")), "xxxxx".into());
@@ -760,7 +818,7 @@ mod tests {
                 }
             ),
             HTML::from(
                 }
             ),
             HTML::from(
-                r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">𝍷</td>"#
+                r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"><span style="font-family: 'BabelStone Han'">𝍷</span></td>"#
             )
         );
         assert_eq!(
             )
         );
         assert_eq!(
@@ -773,7 +831,7 @@ mod tests {
                 }
             ),
             HTML::from(
                 }
             ),
             HTML::from(
-                r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">𝍷𝍷</td>"#
+                r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"><span style="font-family: 'BabelStone Han'">𝍷𝍷</span></td>"#
             )
         );
         assert_eq!(
             )
         );
         assert_eq!(
@@ -802,7 +860,7 @@ mod tests {
                 }
             ),
             HTML::from(
                 }
             ),
             HTML::from(
-                r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">5 π·</td>"#
+                r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">5 <span style="font-family: 'BabelStone Han'">𝍷</span></td>"#
             )
         );
         assert_eq!(
             )
         );
         assert_eq!(
@@ -841,7 +899,7 @@ mod tests {
                 }
             ),
             HTML::from(
                 }
             ),
             HTML::from(
-                r#"<td class="yes" onmouseover="h2('bob&#39;s','foo')" onmouseout="ch2('bob&#39;s','foo')">𝍷</td>"#
+                r#"<td class="yes" onmouseover="h2('bob&#39;s','foo')" onmouseout="ch2('bob&#39;s','foo')"><span style="font-family: 'BabelStone Han'">𝍷</span></td>"#
             )
         );
         assert_eq!(
             )
         );
         assert_eq!(
@@ -916,7 +974,7 @@ mod tests {
                     ]),
                 }
             ),
                     ]),
                 }
             ),
-            HTML::from("bar: π·π·, foo")
+            HTML::from(r#"bar: <span style="font-family: 'BabelStone Han'">𝍷𝍷</span>, foo"#)
         );
         assert_eq!(
             render_all_leftovers(
         );
         assert_eq!(
             render_all_leftovers(
@@ -1071,7 +1129,7 @@ mod tests {
                 })
             ),
             HTML::from(
                 })
             ),
             HTML::from(
-                r#"<tr><th id="nope">nope</th><td class="yes" onmouseover="h2('nope','bar')" onmouseout="ch2('nope','bar')">𝍷</td><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>
+                r#"<tr><th id="nope">nope</th><td class="yes" onmouseover="h2('nope','bar')" onmouseout="ch2('nope','bar')"><span style="font-family: 'BabelStone Han'">𝍷</span></td><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>
 "#
             )
         );
 "#
             )
         );