///| Chandra's own copy (scripts/fetch-emoji-font.sh; `just test` fetches it). let test_font : String = @emoji.font_path ///| fn open_font() -> @emoji.EmojiFont { let data = @sys.read_file_bytes(test_font) if data.length() == 0 { abort("font_test needs Noto Color Emoji at " + test_font + ": run scripts/fetch-emoji-font.sh") } @emoji.EmojiFont::parse(data) catch { e => abort("Noto Color Emoji didn't parse: " + Show::to_string(e)) } } ///| test "Noto Color Emoji: the same emoji as HarfBuzz finds" { let f = open_font() assert_eq(f.ppem, 109) // Counted with HarfBuzz (uharfbuzz) on Noto Color Emoji 2.051: of the 1923 listed emoji the // font draws 1914 (some Emoji 17/18 additions are missing), and 1650 skin tone variants. let mut base = 0 let mut tones = 0 for e in @emoji.all() { if f.has(e.text) { base = base + 1 } for t in e.tones { if f.has(t) { tones = tones + 1 } } } assert_eq(base, 1914) assert_eq(tones, 1650) // Ligatures: a family, a keycap, a flag and a skin tone are one picture each. for s in ["πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦", "#️⃣", "πŸ‡©πŸ‡ͺ", "πŸ‘πŸ½", "πŸ΄β€β˜ οΈ", "🏴󠁧󠁒󠁳󠁣󠁴󠁿"] { assert_eq(f.shape(s).length(), 1) assert_true(f.has(s)) } // Text the font can't draw as one picture. assert_false(f.has("ab")) let cracking = @emoji.all().filter(e => e.name == "cracking face")[0] assert_false(f.has(cracking.text)) // Emoji 18.0, newer than this font } ///| test "pictures are scaled to a square, centred, with transparent corners" { let f = open_font() let p = f.picture("πŸ˜€", 32).unwrap() assert_eq(p.width, 32) assert_eq(p.height, 32) // The corner is transparent, the middle of the face is opaque yellow. assert_eq(p.data[3].to_int(), 0) let o = (16 * 32 + 16) * 4 assert_eq(p.data[o + 3].to_int(), 255) assert_true(p.data[o].to_int() > 200 && p.data[o + 1].to_int() > 150 && p.data[o + 2].to_int() < 100) assert_true(f.picture("ab", 32) is None) } ///| test "a file that is not a colour emoji font is an error that says why" { let msg = try { ignore(@emoji.EmojiFont::parse(b"\x00\x01\x00\x00\x00\x00")) "parsed" } catch { e => Show::to_string(e) } assert_true(msg.contains("no cmap table")) assert_true(@emoji.missing_font_message("").contains("just install")) } ///| test "inline emoji matcher handles turtle, sequences, VS15/VS16, and BMP symbols" { assert_false(@emoji.text_may_have_emoji("Regency 215-223 WiFi")) assert_false(@emoji.text_may_have_emoji("CafΓ© β€’ … β€” Β©")) assert_true(@emoji.text_may_have_emoji("🐒")) assert_true(@emoji.text_may_have_emoji("Connected to 🐒 (72%)")) assert_true(@emoji.text_may_have_emoji("#️⃣")) assert_true(@emoji.text_may_have_emoji("©️")) let f = open_font() let all_have = fn(_cp : Int) { true } let none_have = fn(_cp : Int) { false } assert_eq(f.match_at("🐒".to_array(), 0, all_have), Some((1, "🐒"))) assert_eq(f.match_at("Connected to 🐒 (72%)".to_array(), 13, all_have), Some((14, "🐒"))) assert_eq(f.match_at("πŸ‘πŸ½!".to_array(), 0, all_have), Some((2, "πŸ‘πŸ½"))) assert_eq(f.match_at("#️⃣x".to_array(), 0, all_have), Some((3, "#️⃣"))) assert_eq(f.match_at("πŸ‡ΊπŸ‡Έx".to_array(), 0, all_have), Some((2, "πŸ‡ΊπŸ‡Έ"))) assert_eq(f.match_at("πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦x".to_array(), 0, all_have), Some((7, "πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦"))) // Bare BMP symbols stay monochrome when the UI text font has them; VS16 switches to colour, VS15 keeps text. assert_eq(f.match_at("β–Ά".to_array(), 0, all_have), None) assert_eq(f.match_at("▢️".to_array(), 0, all_have), Some((2, "▢️"))) assert_eq(f.match_at("β–Ά\u{FE0E}".to_array(), 0, all_have), None) assert_eq(f.match_at("β˜€".to_array(), 0, none_have), Some((1, "β˜€"))) // Non-emoji ASCII / CJK / unsupported Emoji 18.0 characters do not match. assert_eq(f.match_at("#1".to_array(), 0, all_have), None) assert_eq(f.match_at("ζ—₯本θͺž".to_array(), 0, none_have), None) let cracking = @emoji.all().filter(e => e.name == "cracking face")[0] assert_eq(f.match_at(cracking.text.to_array(), 0, none_have), None) // Noto Color Emoji's turtle renders olive-green opaque pixels at inline size. let p = f.picture("🐒", 16).unwrap() assert_eq((p.width, p.height), (16, 16)) let mut green = 0 for i = 0; i < p.width * p.height; i = i + 1 { let o = i * 4 let r = p.data[o].to_int() let g = p.data[o + 1].to_int() let b = p.data[o + 2].to_int() let a = p.data[o + 3].to_int() if a > 200 && g > r && g > b + 40 { green = green + 1 } } assert_true(green > 10) let src = @emoji.EmojiSource::new() assert_eq(src.match_at("🐒".to_array(), 0, all_have), Some((1, "🐒"))) }