Skip to content

Commit

Permalink
Merge pull request #139 from googlefonts/test-data
Browse files Browse the repository at this point in the history
Move glyphsets TestDocData to this repo
  • Loading branch information
m4rc1e authored May 3, 2024
2 parents 1d20656 + a576bd0 commit a50aaae
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 2 deletions.
110 changes: 110 additions & 0 deletions src/diffenator2/data/test_strings.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
3 changes: 1 addition & 2 deletions src/diffenator2/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/diffenator2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

0 comments on commit a50aaae

Please sign in to comment.