From d12cb90ef6246aa506a825519492464ba92f1660 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Mon, 4 Nov 2024 14:21:24 +0000 Subject: [PATCH] Emoji modifier test from #195, for all platforms. --- tests/test_font.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_font.py b/tests/test_font.py index 2a220f98..8fd8a656 100644 --- a/tests/test_font.py +++ b/tests/test_font.py @@ -1,3 +1,5 @@ +import os +import sys import skia import pytest @@ -643,3 +645,42 @@ def test_FontMetrics_hasStrikeoutThickness(fontmetrics): def test_FontMetrics_hasStrikeoutPosition(fontmetrics): position = 0. assert isinstance(fontmetrics.hasStrikeoutPosition(position), bool) + + +@pytest.fixture +def color_emoji_run(): + if sys.platform.startswith("linux"): + typeface = skia.Typeface("Noto Color Emoji") + if sys.platform.startswith("darwin"): + typeface = skia.Typeface("Apple Color Emoji") + if sys.platform.startswith("win"): + typeface = skia.Typeface("Segoe UI Emoji") # COLRv0 + text = "✌✌🏻" + font = skia.Font(typeface,109) + blob = skia.TextBlob.MakeFromShapedText(text, font) + run = [x for x in blob] + return run[0] + +def test_emoji_count(color_emoji_run): + assert (color_emoji_run.fGlyphCount == 2) + +def test_emoji_typeface(color_emoji_run): + assert ((color_emoji_run.fTypeface.getFamilyName() == "Noto Color Emoji") + or (color_emoji_run.fTypeface.getFamilyName() == "Apple Color Emoji") + or (color_emoji_run.fTypeface.getFamilyName() == "Segoe UI Emoji")) + +# The numbers are hardcoded for three specific version of fonts, +# and will change if the hosts are upgraded. +def test_emoji_glyph1(color_emoji_run): + if (os.getenv("GITHUB_ACTION") == True): + assert ((color_emoji_run.fGlyphIndices[0] == 148) + or (color_emoji_run.fGlyphIndices[0] == 247) + or (color_emoji_run.fGlyphIndices[0] == 1567)) + +# The numbers are hardcoded for three specific version of fonts, +# and will change if the hosts are upgraded. +def test_emoji_glyph2(color_emoji_run): + if (os.getenv("GITHUB_ACTION") == True): + assert ((color_emoji_run.fGlyphIndices[1] == 1512) + or (color_emoji_run.fGlyphIndices[1] == 248) + or (color_emoji_run.fGlyphIndices[1] == 1571))