diff --git a/src/diffenator2/data/test_strings.json b/src/diffenator2/data/test_strings.json new file mode 100644 index 0000000..0e15c7d --- /dev/null +++ b/src/diffenator2/data/test_strings.json @@ -0,0 +1,110 @@ +{ + "GF_Latin_Core": { + "Letter Groups": [ + { + "string": "EFHIJLTU AVWXZ KMNY", + "lang": "en" + }, + { + "string": "COQS BPRDGÞẞ", + "lang": "en" + }, + { + "string": "hmnu ceogðsß abdpqþ", + "lang": "en" + }, + { + "string": "kvwxyz fijltr", + "lang": "en" + }, + { + "string": "0123456789", + "lang": "en" + }, + { + "string": ".,:;/|?!-–—&@%([{}])°", + "lang": "en" + }, + { + "string": "+−×÷=≠><≥≤±≈~¬∞", + "lang": "en" + } + ], + "Spacing": [ + { + "string": "HHOHHOOHOO HIHOIO", + "lang": "en" + }, + { + "string": "uuonouonoo ninoioolonlniuo", + "lang": "en" + }, + { + "string": "010 080 030 020 050 060 070", + "lang": "en" + }, + { + "string": "3+4=7 5>2 2x²−(8×7)÷9≈1", + "lang": "en" + }, + { + "string": "L·L l·l", + "lang": "ca" + } + ], + "Kerning": [ + { + "string": "HHAVAHH OXOWAFAPATAUAYAÞYLYTJLVÆAVAOYO HH", + "lang": "en" + }, + { + "string": "Ti Tí Tî Tï Tì Tī Vă Tä Tü Tõ Tŭ Tř", + "lang": "en" + }, + { + "string": "HHTan oTo yTy vAv oVo oWo eYe Ly Ky Ac Ay gj", + "lang": "en" + }, + { + "string": "nin non nvn ovo oxo ayn fl fi fj ft gj ko rento", + "lang": "en" + }, + { + "string": "ďá ďu gj ľk włw yły ółr fħ ílïlîl", + "lang": "en" + }, + { + "string": "H.Y-Y.T,F.P,V:Y„V-T-A*A’A“A’A-AL–L—L-", + "lang": "en" + }, + { + "string": "n.r.r,y.y,(o)(i)(d)(j)(f)[j]{f}", + "lang": "en" + }, + { + "string": "¿o,O? w@y «n•n» n*", + "lang": "en" + }, + { + "string": "080 076 474 973 94 7078 54 24 272 679", + "lang": "en" + }, + { + "string": "P4T47A .47,9.7-»4", + "lang": "en" + }, + { + "string": "42°21′29″N 71°03′49″W", + "lang": "en" + }, + { + "string": "d² m³ 15°C/26°F", + "lang": "en" + }, + { + "string": "0/0\\0", + "lang": "en" + } + ] + } +} \ No newline at end of file diff --git a/src/diffenator2/html.py b/src/diffenator2/html.py index e25530d..814457a 100644 --- a/src/diffenator2/html.py +++ b/src/diffenator2/html.py @@ -6,8 +6,7 @@ import os import shutil from diffenator2.template_elements import CSSFontStyle, CSSFontFace -from diffenator2.utils import font_sample_text, characters_in_string -from glyphsets import GFTestData +from diffenator2.utils import font_sample_text, characters_in_string, GFTestData import re from pathlib import Path from diffenator2.shape import parse_wordlist diff --git a/src/diffenator2/utils.py b/src/diffenator2/utils.py index de153df..f9e0ef3 100644 --- a/src/diffenator2/utils.py +++ b/src/diffenator2/utils.py @@ -27,6 +27,10 @@ from zipfile import ZipFile import re import json +from glyphsets import get_glyphsets_fulfilled + + +TEST_STRINGS_DATA = os.path.join(os.path.dirname(__file__), "data", "test_strings.json") def dict_coords_to_string(coords: dict[str, float]) -> str: @@ -195,3 +199,27 @@ def re_filter_characters(font, pattern): def characters_in_string(string, characters): return all(g in characters for g in string) + + + +class _TestDocData: + def __init__( + self, + data=json.load(open(TEST_STRINGS_DATA, encoding="utf8")), + ): + self._data = data + + def test_strings_in_font(self, ttFont, threshold=0.95): + res = {} + glyphsets_in_font = get_glyphsets_fulfilled(ttFont) + for glyphset, coverage in glyphsets_in_font.items(): + if coverage["percentage"] < threshold: + continue + test_strings = self._data.get(glyphset) + if not test_strings: + continue + res[glyphset] = test_strings + return res + + +GFTestData = _TestDocData()