| 1 |
from fontTools.ttLib import TTFont |
| 2 |
from fontTools.misc.testTools import getXML |
| 3 |
from axisregistry import ( |
| 4 |
build_name_table, |
| 5 |
build_filename, |
| 6 |
build_fvar_instances, |
| 7 |
build_stat, |
| 8 |
build_variations_ps_name, |
| 9 |
_fvar_dflts, |
| 10 |
_fvar_instance_collisions, |
| 11 |
) |
| 12 |
import pytest |
| 13 |
import os |
| 14 |
|
| 15 |
CWD = os.path.dirname(__file__) |
| 16 |
DATA_DIR = os.path.join(CWD, "data") |
| 17 |
|
| 18 |
roboto_flex_fp = os.path.join( |
| 19 |
DATA_DIR, |
| 20 |
"RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf", |
| 21 |
) |
| 22 |
mavenpro_fp = os.path.join(DATA_DIR, "MavenPro-Regular.ttf") |
| 23 |
opensans_roman_fp = os.path.join(DATA_DIR, "OpenSans[wdth,wght].ttf") |
| 24 |
opensans_italic_fp = os.path.join(DATA_DIR, "OpenSans-Italic[wdth,wght].ttf") |
| 25 |
opensans_cond_roman_fp = os.path.join(DATA_DIR, "OpenSansCondensed[wght].ttf") |
| 26 |
opensans_cond_italic_fp = os.path.join(DATA_DIR, "OpenSansCondensed-Italic[wght].ttf") |
| 27 |
wonky_fp = os.path.join(DATA_DIR, "Wonky[wdth,wght].ttf") |
| 28 |
playfair_fp = os.path.join(DATA_DIR, "Playfair[opsz,wdth,wght].ttf") |
| 29 |
wavefont_fp = os.path.join(DATA_DIR, "Wavefont[ROND,YALN,wght].ttf") |
| 30 |
|
| 31 |
|
| 32 |
@pytest.fixture |
| 33 |
def static_font(): |
| 34 |
return TTFont(mavenpro_fp) |
| 35 |
|
| 36 |
|
| 37 |
def _test_names(ttFont, expected): |
| 38 |
name_table = ttFont["name"] |
| 39 |
for k, v in expected.items(): |
| 40 |
record = name_table.getName(*k) |
| 41 |
if not record: |
| 42 |
assert record == v, f"{k} record is incorrect, expected {v} got {record}" |
| 43 |
else: |
| 44 |
record_string = record.toUnicode() |
| 45 |
assert ( |
| 46 |
record_string == v |
| 47 |
), f"{k} record is incorrect, expected {v} got {record}" |
| 48 |
|
| 49 |
|
| 50 |
@pytest.mark.parametrize( |
| 51 |
"fp, family_name, style_name, siblings, expected", |
| 52 |
[ |
| 53 |
# Maven Pro Regular |
| 54 |
( |
| 55 |
mavenpro_fp, |
| 56 |
"Maven Pro", |
| 57 |
"Regular", |
| 58 |
[], |
| 59 |
{ |
| 60 |
(1, 3, 1, 0x409): "Maven Pro", |
| 61 |
(2, 3, 1, 0x409): "Regular", |
| 62 |
(3, 3, 1, 0x409): "2.003;NONE;MavenPro-Regular", |
| 63 |
(4, 3, 1, 0x409): "Maven Pro Regular", |
| 64 |
(6, 3, 1, 0x409): "MavenPro-Regular", |
| 65 |
(16, 3, 1, 0x409): None, |
| 66 |
(17, 3, 1, 0x409): None, |
| 67 |
}, |
| 68 |
), |
| 69 |
# Maven Pro Italic |
| 70 |
( |
| 71 |
mavenpro_fp, |
| 72 |
"Maven Pro", |
| 73 |
"Italic", |
| 74 |
[], |
| 75 |
{ |
| 76 |
(1, 3, 1, 0x409): "Maven Pro", |
| 77 |
(2, 3, 1, 0x409): "Italic", |
| 78 |
(3, 3, 1, 0x409): "2.003;NONE;MavenPro-Italic", |
| 79 |
(4, 3, 1, 0x409): "Maven Pro Italic", |
| 80 |
(6, 3, 1, 0x409): "MavenPro-Italic", |
| 81 |
(16, 3, 1, 0x409): None, |
| 82 |
(17, 3, 1, 0x409): None, |
| 83 |
}, |
| 84 |
), |
| 85 |
# Maven Pro Bold |
| 86 |
( |
| 87 |
mavenpro_fp, |
| 88 |
"Maven Pro", |
| 89 |
"Bold", |
| 90 |
[], |
| 91 |
{ |
| 92 |
(1, 3, 1, 0x409): "Maven Pro", |
| 93 |
(2, 3, 1, 0x409): "Bold", |
| 94 |
(3, 3, 1, 0x409): "2.003;NONE;MavenPro-Bold", |
| 95 |
(4, 3, 1, 0x409): "Maven Pro Bold", |
| 96 |
(6, 3, 1, 0x409): "MavenPro-Bold", |
| 97 |
(16, 3, 1, 0x409): None, |
| 98 |
(17, 3, 1, 0x409): None, |
| 99 |
}, |
| 100 |
), |
| 101 |
# Maven Pro Bold Italic |
| 102 |
( |
| 103 |
mavenpro_fp, |
| 104 |
"Maven Pro", |
| 105 |
"Bold Italic", |
| 106 |
[], |
| 107 |
{ |
| 108 |
(1, 3, 1, 0x409): "Maven Pro", |
| 109 |
(2, 3, 1, 0x409): "Bold Italic", |
| 110 |
(3, 3, 1, 0x409): "2.003;NONE;MavenPro-BoldItalic", |
| 111 |
(4, 3, 1, 0x409): "Maven Pro Bold Italic", |
| 112 |
(6, 3, 1, 0x409): "MavenPro-BoldItalic", |
| 113 |
(16, 3, 1, 0x409): None, |
| 114 |
(17, 3, 1, 0x409): None, |
| 115 |
}, |
| 116 |
), |
| 117 |
# Maven Pro Black |
| 118 |
( |
| 119 |
mavenpro_fp, |
| 120 |
"Maven Pro", |
| 121 |
"Black", |
| 122 |
[], |
| 123 |
{ |
| 124 |
(1, 3, 1, 0x409): "Maven Pro Black", |
| 125 |
(2, 3, 1, 0x409): "Regular", |
| 126 |
(3, 3, 1, 0x409): "2.003;NONE;MavenPro-Black", |
| 127 |
(4, 3, 1, 0x409): "Maven Pro Black", |
| 128 |
(6, 3, 1, 0x409): "MavenPro-Black", |
| 129 |
(16, 3, 1, 0x409): "Maven Pro", |
| 130 |
(17, 3, 1, 0x409): "Black", |
| 131 |
}, |
| 132 |
), |
| 133 |
# Maven Pro Black Italic |
| 134 |
( |
| 135 |
mavenpro_fp, |
| 136 |
"Maven Pro", |
| 137 |
"Black Italic", |
| 138 |
[], |
| 139 |
{ |
| 140 |
(1, 3, 1, 0x409): "Maven Pro Black", |
| 141 |
(2, 3, 1, 0x409): "Italic", |
| 142 |
(3, 3, 1, 0x409): "2.003;NONE;MavenPro-BlackItalic", |
| 143 |
(4, 3, 1, 0x409): "Maven Pro Black Italic", |
| 144 |
(6, 3, 1, 0x409): "MavenPro-BlackItalic", |
| 145 |
(16, 3, 1, 0x409): "Maven Pro", |
| 146 |
(17, 3, 1, 0x409): "Black Italic", |
| 147 |
}, |
| 148 |
), |
| 149 |
# Maven Pro ExtraLight Italic |
| 150 |
( |
| 151 |
mavenpro_fp, |
| 152 |
"Maven Pro", |
| 153 |
"ExtraLight Italic", |
| 154 |
[], |
| 155 |
{ |
| 156 |
(1, 3, 1, 0x409): "Maven Pro ExtraLight", |
| 157 |
(2, 3, 1, 0x409): "Italic", |
| 158 |
(3, 3, 1, 0x409): "2.003;NONE;MavenPro-ExtraLightItalic", |
| 159 |
(4, 3, 1, 0x409): "Maven Pro ExtraLight Italic", |
| 160 |
(6, 3, 1, 0x409): "MavenPro-ExtraLightItalic", |
| 161 |
(16, 3, 1, 0x409): "Maven Pro", |
| 162 |
(17, 3, 1, 0x409): "ExtraLight Italic", |
| 163 |
}, |
| 164 |
), |
| 165 |
# check non-weight styles get appended to family name |
| 166 |
# Maven Pro UltraExpanded Regular |
| 167 |
( |
| 168 |
mavenpro_fp, |
| 169 |
"Maven Pro", |
| 170 |
"UltraExpanded Regular", |
| 171 |
[], |
| 172 |
{ |
| 173 |
(1, 3, 1, 0x409): "Maven Pro UltraExpanded", |
| 174 |
(2, 3, 1, 0x409): "Regular", |
| 175 |
(3, 3, 1, 0x409): "2.003;NONE;MavenProUltraExpanded-Regular", |
| 176 |
(4, 3, 1, 0x409): "Maven Pro UltraExpanded Regular", |
| 177 |
(6, 3, 1, 0x409): "MavenProUltraExpanded-Regular", |
| 178 |
(16, 3, 1, 0x409): None, |
| 179 |
(17, 3, 1, 0x409): None, |
| 180 |
}, |
| 181 |
), |
| 182 |
# Maven Pro Condensed ExtraLight Italic |
| 183 |
( |
| 184 |
mavenpro_fp, |
| 185 |
"Maven Pro", |
| 186 |
"Condensed ExtraLight Italic", |
| 187 |
[], |
| 188 |
{ |
| 189 |
(1, 3, 1, 0x409): "Maven Pro Condensed ExtraLight", |
| 190 |
(2, 3, 1, 0x409): "Italic", |
| 191 |
(3, 3, 1, 0x409): "2.003;NONE;MavenProCondensed-ExtraLightItalic", |
| 192 |
(4, 3, 1, 0x409): "Maven Pro Condensed ExtraLight Italic", |
| 193 |
(6, 3, 1, 0x409): "MavenProCondensed-ExtraLightItalic", |
| 194 |
(16, 3, 1, 0x409): "Maven Pro Condensed", |
| 195 |
(17, 3, 1, 0x409): "ExtraLight Italic", |
| 196 |
}, |
| 197 |
), |
| 198 |
## VFs |
| 199 |
# Open Sans Roman |
| 200 |
( |
| 201 |
opensans_roman_fp, |
| 202 |
"Open Sans", |
| 203 |
None, |
| 204 |
[opensans_italic_fp, opensans_cond_roman_fp, opensans_cond_italic_fp], |
| 205 |
{ |
| 206 |
(1, 3, 1, 0x409): "Open Sans", |
| 207 |
(2, 3, 1, 0x409): "Regular", |
| 208 |
(3, 3, 1, 0x409): "3.000;GOOG;OpenSans-Regular", |
| 209 |
(4, 3, 1, 0x409): "Open Sans Regular", |
| 210 |
(6, 3, 1, 0x409): "OpenSans-Regular", |
| 211 |
(16, 3, 1, 0x409): None, |
| 212 |
(17, 3, 1, 0x409): None, |
| 213 |
(25, 3, 1, 0x409): "OpenSans", |
| 214 |
}, |
| 215 |
), |
| 216 |
# Open Sans Italic |
| 217 |
( |
| 218 |
opensans_italic_fp, |
| 219 |
"Open Sans", |
| 220 |
None, |
| 221 |
[opensans_roman_fp, opensans_cond_roman_fp, opensans_cond_italic_fp], |
| 222 |
{ |
| 223 |
(1, 3, 1, 0x409): "Open Sans", |
| 224 |
(2, 3, 1, 0x409): "Italic", |
| 225 |
(3, 3, 1, 0x409): "3.000;GOOG;OpenSans-Italic", |
| 226 |
(4, 3, 1, 0x409): "Open Sans Italic", |
| 227 |
(6, 3, 1, 0x409): "OpenSans-Italic", |
| 228 |
(16, 3, 1, 0x409): None, |
| 229 |
(17, 3, 1, 0x409): None, |
| 230 |
(25, 3, 1, 0x409): "OpenSansItalic", |
| 231 |
}, |
| 232 |
), |
| 233 |
# Open Sans Cond Roman |
| 234 |
( |
| 235 |
opensans_cond_roman_fp, |
| 236 |
"Open Sans Condensed", |
| 237 |
None, |
| 238 |
[opensans_roman_fp, opensans_italic_fp, opensans_cond_italic_fp], |
| 239 |
{ |
| 240 |
(1, 3, 1, 0x409): "Open Sans Condensed", |
| 241 |
(2, 3, 1, 0x409): "Regular", |
| 242 |
(3, 3, 1, 0x409): "3.000;GOOG;OpenSansCondensed-Regular", |
| 243 |
(4, 3, 1, 0x409): "Open Sans Condensed Regular", |
| 244 |
(6, 3, 1, 0x409): "OpenSansCondensed-Regular", |
| 245 |
(16, 3, 1, 0x409): None, |
| 246 |
(17, 3, 1, 0x409): None, |
| 247 |
(25, 3, 1, 0x409): "OpenSansCondensed", |
| 248 |
}, |
| 249 |
), |
| 250 |
# Open Sans Cond Italic |
| 251 |
( |
| 252 |
opensans_cond_italic_fp, |
| 253 |
"Open Sans Condensed", |
| 254 |
None, |
| 255 |
[opensans_roman_fp, opensans_italic_fp, opensans_cond_roman_fp], |
| 256 |
{ |
| 257 |
(1, 3, 1, 0x409): "Open Sans Condensed", |
| 258 |
(2, 3, 1, 0x409): "Italic", |
| 259 |
(3, 3, 1, 0x409): "3.000;GOOG;OpenSansCondensed-Italic", |
| 260 |
(4, 3, 1, 0x409): "Open Sans Condensed Italic", |
| 261 |
(6, 3, 1, 0x409): "OpenSansCondensed-Italic", |
| 262 |
(16, 3, 1, 0x409): None, |
| 263 |
(17, 3, 1, 0x409): None, |
| 264 |
(25, 3, 1, 0x409): "OpenSansCondensedItalic", |
| 265 |
}, |
| 266 |
), |
| 267 |
# Bad names |
| 268 |
( |
| 269 |
mavenpro_fp, |
| 270 |
"Maven Pro", |
| 271 |
"Fat", # this should get appended to the family name |
| 272 |
[], |
| 273 |
{ |
| 274 |
(1, 3, 1, 0x409): "Maven Pro Fat", |
| 275 |
(2, 3, 1, 0x409): "Regular", |
| 276 |
(3, 3, 1, 0x409): "2.003;NONE;MavenProFat-Regular", |
| 277 |
(4, 3, 1, 0x409): "Maven Pro Fat Regular", |
| 278 |
(6, 3, 1, 0x409): "MavenProFat-Regular", |
| 279 |
(16, 3, 1, 0x409): None, |
| 280 |
(17, 3, 1, 0x409): None, |
| 281 |
}, |
| 282 |
), |
| 283 |
( |
| 284 |
wonky_fp, |
| 285 |
"Wonky", # name exists in axis reg! |
| 286 |
None, |
| 287 |
[], |
| 288 |
{ |
| 289 |
(1, 3, 1, 0x409): "Wonky", |
| 290 |
(2, 3, 1, 0x409): "Regular", |
| 291 |
(3, 3, 1, 0x409): "3.000;GOOG;Wonky-Regular", |
| 292 |
(4, 3, 1, 0x409): "Wonky Regular", |
| 293 |
(6, 3, 1, 0x409): "Wonky-Regular", |
| 294 |
(16, 3, 1, 0x409): None, |
| 295 |
(17, 3, 1, 0x409): None, |
| 296 |
}, |
| 297 |
), |
| 298 |
# Test opsz particle is kept. |
| 299 |
# Fixes https://github.com/googlefonts/axisregistry/issues/130 |
| 300 |
( |
| 301 |
playfair_fp, |
| 302 |
"Playfair", |
| 303 |
None, |
| 304 |
[], |
| 305 |
{ |
| 306 |
(1, 3, 1, 0x409): "Playfair SemiExpanded Light", |
| 307 |
(2, 3, 1, 0x409): "Regular", |
| 308 |
(3, 3, 1, 0x409): "2.000;FTH;Playfair-SemiExpandedLight", |
| 309 |
(4, 3, 1, 0x409): "Playfair SemiExpanded Light", |
| 310 |
(6, 3, 1, 0x409): "Playfair-SemiExpandedLight", |
| 311 |
(16, 3, 1, 0x409): "Playfair", |
| 312 |
(17, 3, 1, 0x409): "SemiExpanded Light", |
| 313 |
}, |
| 314 |
), |
| 315 |
], |
| 316 |
) |
| 317 |
def test_name_table(fp, family_name, style_name, siblings, expected): |
| 318 |
font = TTFont(fp) |
| 319 |
siblings = [TTFont(fp) for fp in siblings] |
| 320 |
build_name_table(font, family_name, style_name, siblings) |
| 321 |
_test_names(font, expected) |
| 322 |
|
| 323 |
|
| 324 |
def test_name_table_aggression(): |
| 325 |
font = TTFont(mavenpro_fp) |
| 326 |
build_name_table(font, "Raven Am", "Regular", aggressive=True) |
| 327 |
_test_names( |
| 328 |
font, |
| 329 |
{ |
| 330 |
( |
| 331 |
0, |
| 332 |
3, |
| 333 |
1, |
| 334 |
0x409, |
| 335 |
): 'Copyright 2011 The Raven Am Project Authors (http://www.vissol.co.uk/mavenpro/), with Reserved Font Name "Raven Am".', |
| 336 |
(4, 3, 1, 0x409): "Raven Am Regular", |
| 337 |
}, |
| 338 |
) |
| 339 |
font = TTFont(mavenpro_fp) |
| 340 |
build_name_table(font, "Raven Am", "Regular", aggressive=False) |
| 341 |
_test_names( |
| 342 |
font, |
| 343 |
{ |
| 344 |
( |
| 345 |
0, |
| 346 |
3, |
| 347 |
1, |
| 348 |
0x409, |
| 349 |
): 'Copyright 2011 The Maven Pro Project Authors (http://www.vissol.co.uk/mavenpro/), with Reserved Font Name "Maven Pro".', |
| 350 |
(4, 3, 1, 0x409): "Raven Am Regular", |
| 351 |
}, |
| 352 |
) |
| 353 |
|
| 354 |
|
| 355 |
@pytest.mark.parametrize( |
| 356 |
"font_fp, dflt_coords, expected", |
| 357 |
[ |
| 358 |
# Condensed variants |
| 359 |
( |
| 360 |
opensans_cond_roman_fp, |
| 361 |
{}, |
| 362 |
[ |
| 363 |
("Thin", {"wght": 100.0}), |
| 364 |
("ExtraLight", {"wght": 200.0}), |
| 365 |
("Light", {"wght": 300.0}), |
| 366 |
("Regular", {"wght": 400.0}), |
| 367 |
("Medium", {"wght": 500.0}), |
| 368 |
("SemiBold", {"wght": 600.0}), |
| 369 |
("Bold", {"wght": 700.0}), |
| 370 |
("ExtraBold", {"wght": 800.0}), |
| 371 |
], |
| 372 |
), |
| 373 |
( |
| 374 |
opensans_cond_italic_fp, |
| 375 |
{}, |
| 376 |
[ |
| 377 |
("Thin Italic", {"wght": 100.0}), |
| 378 |
("ExtraLight Italic", {"wght": 200.0}), |
| 379 |
("Light Italic", {"wght": 300.0}), |
| 380 |
("Italic", {"wght": 400.0}), |
| 381 |
("Medium Italic", {"wght": 500.0}), |
| 382 |
("SemiBold Italic", {"wght": 600.0}), |
| 383 |
("Bold Italic", {"wght": 700.0}), |
| 384 |
("ExtraBold Italic", {"wght": 800.0}), |
| 385 |
], |
| 386 |
), |
| 387 |
# Multi axis + roman & ital with dflt coords |
| 388 |
( |
| 389 |
roboto_flex_fp, |
| 390 |
{}, |
| 391 |
[ |
| 392 |
("Thin", {"wght": 100.0}), |
| 393 |
("ExtraLight", {"wght": 200.0}), |
| 394 |
("Light", {"wght": 300.0}), |
| 395 |
("Regular", {"wght": 400.0}), |
| 396 |
("Medium", {"wght": 500.0}), |
| 397 |
("SemiBold", {"wght": 600.0}), |
| 398 |
("Bold", {"wght": 700.0}), |
| 399 |
("ExtraBold", {"wght": 800.0}), |
| 400 |
("Black", {"wght": 900.0}), |
| 401 |
("Thin Italic", {"wght": 100.0, "slnt": -10}), |
| 402 |
("ExtraLight Italic", {"wght": 200.0, "slnt": -10}), |
| 403 |
("Light Italic", {"wght": 300.0, "slnt": -10}), |
| 404 |
("Italic", {"wght": 400.0, "slnt": -10}), |
| 405 |
("Medium Italic", {"wght": 500.0, "slnt": -10}), |
| 406 |
("SemiBold Italic", {"wght": 600.0, "slnt": -10}), |
| 407 |
("Bold Italic", {"wght": 700.0, "slnt": -10}), |
| 408 |
("ExtraBold Italic", {"wght": 800.0, "slnt": -10}), |
| 409 |
("Black Italic", {"wght": 900.0, "slnt": -10}), |
| 410 |
], |
| 411 |
), |
| 412 |
# multi axis with METADATA.pb registry_default_overrides |
| 413 |
# https://github.com/google/fonts/blob/main/ofl/robotoflex/METADATA.pb |
| 414 |
( |
| 415 |
roboto_flex_fp, |
| 416 |
{ |
| 417 |
"XOPQ": 96.0, |
| 418 |
"XTRA": 468.0, |
| 419 |
"YOPQ": 79.0, |
| 420 |
"YTDE": -203.0, |
| 421 |
"YTFI": 738.0, |
| 422 |
"YTLC": 514.0, |
| 423 |
"YTUC": 712.0, |
| 424 |
}, |
| 425 |
[ |
| 426 |
("Thin", {"wght": 100.0}), |
| 427 |
("ExtraLight", {"wght": 200.0}), |
| 428 |
("Light", {"wght": 300.0}), |
| 429 |
("Regular", {"wght": 400.0}), |
| 430 |
("Medium", {"wght": 500.0}), |
| 431 |
("SemiBold", {"wght": 600.0}), |
| 432 |
("Bold", {"wght": 700.0}), |
| 433 |
("ExtraBold", {"wght": 800.0}), |
| 434 |
("Black", {"wght": 900.0}), |
| 435 |
("Thin Italic", {"wght": 100.0, "slnt": -10}), |
| 436 |
("ExtraLight Italic", {"wght": 200.0, "slnt": -10}), |
| 437 |
("Light Italic", {"wght": 300.0, "slnt": -10}), |
| 438 |
("Italic", {"wght": 400.0, "slnt": -10}), |
| 439 |
("Medium Italic", {"wght": 500.0, "slnt": -10}), |
| 440 |
("SemiBold Italic", {"wght": 600.0, "slnt": -10}), |
| 441 |
("Bold Italic", {"wght": 700.0, "slnt": -10}), |
| 442 |
("ExtraBold Italic", {"wght": 800.0, "slnt": -10}), |
| 443 |
("Black Italic", {"wght": 900.0, "slnt": -10}), |
| 444 |
], |
| 445 |
), |
| 446 |
], |
| 447 |
) |
| 448 |
def test_fvar_instances(font_fp, dflt_coords, expected): |
| 449 |
font = TTFont(font_fp) |
| 450 |
builder = build_fvar_instances(font, dflt_coords) |
| 451 |
fvar = font["fvar"] |
| 452 |
wght_axis = next((a for a in fvar.axes if a.axisTag == "wght"), None) |
| 453 |
wght_min = wght_axis.minValue |
| 454 |
wght_max = wght_axis.maxValue |
| 455 |
instances = fvar.instances |
| 456 |
if not dflt_coords: |
| 457 |
dflt_coords = {k: v["value"] for k, v in _fvar_dflts(font).items()} |
| 458 |
|
| 459 |
assert len(instances) == len(expected) |
| 460 |
for inst, (expected_name, coords) in zip(instances, expected): |
| 461 |
inst_name = font["name"].getName(inst.subfamilyNameID, 3, 1, 0x409).toUnicode() |
| 462 |
assert inst_name == expected_name |
| 463 |
for tag, val in coords.items(): |
| 464 |
dflt_coords[tag] = val |
| 465 |
assert inst.coordinates == dflt_coords |
| 466 |
|
| 467 |
|
| 468 |
def dump(table, ttFont=None): |
| 469 |
return "\n".join(getXML(table.toXML, ttFont)) |
| 470 |
|
| 471 |
|
| 472 |
@pytest.mark.parametrize( |
| 473 |
"fp, sibling_fps", |
| 474 |
[ |
| 475 |
(roboto_flex_fp, []), |
| 476 |
( |
| 477 |
opensans_roman_fp, |
| 478 |
[opensans_italic_fp, opensans_cond_roman_fp, opensans_cond_italic_fp], |
| 479 |
), |
| 480 |
( |
| 481 |
opensans_italic_fp, |
| 482 |
[opensans_roman_fp, opensans_cond_roman_fp, opensans_cond_italic_fp], |
| 483 |
), |
| 484 |
( |
| 485 |
opensans_cond_roman_fp, |
| 486 |
[opensans_roman_fp, opensans_italic_fp, opensans_cond_italic_fp], |
| 487 |
), |
| 488 |
( |
| 489 |
opensans_cond_italic_fp, |
| 490 |
[opensans_roman_fp, opensans_italic_fp, opensans_cond_roman_fp], |
| 491 |
), |
| 492 |
(wonky_fp, []), |
| 493 |
# don't add a linkedValue for Regular to Bold since Bold doesn't exist |
| 494 |
# Fixes https://github.com/googlefonts/axisregistry/issues/104 |
| 495 |
(wavefont_fp, []), |
| 496 |
], |
| 497 |
) |
| 498 |
def test_stat(fp, sibling_fps): |
| 499 |
font = TTFont(fp) |
| 500 |
siblings = [TTFont(f) for f in sibling_fps] |
| 501 |
build_stat(font, siblings) |
| 502 |
stat_fp = fp.replace(".ttf", "_STAT.ttx") |
| 503 |
|
| 504 |
## output good files |
| 505 |
# with open(stat_fp, "w") as doc: |
| 506 |
# got = dump(font["STAT"], font) |
| 507 |
# doc.write(got) |
| 508 |
|
| 509 |
with open(stat_fp) as doc: |
| 510 |
expected = doc.read() |
| 511 |
got = dump(font["STAT"], font) |
| 512 |
assert got == expected |
| 513 |
|
| 514 |
|
| 515 |
@pytest.mark.parametrize( |
| 516 |
"fp, expected", |
| 517 |
[ |
| 518 |
(mavenpro_fp, "MavenPro-Regular.ttf"), |
| 519 |
(opensans_roman_fp, "OpenSans[wdth,wght].ttf"), |
| 520 |
(opensans_italic_fp, "OpenSans-Italic[wdth,wght].ttf"), |
| 521 |
(opensans_cond_roman_fp, "OpenSansCondensed[wght].ttf"), |
| 522 |
(opensans_cond_italic_fp, "OpenSansCondensed-Italic[wght].ttf"), |
| 523 |
], |
| 524 |
) |
| 525 |
def test_filename(fp, expected): |
| 526 |
font = TTFont(fp) |
| 527 |
assert build_filename(font) == expected |
| 528 |
|
| 529 |
|
| 530 |
@pytest.mark.parametrize( |
| 531 |
"fp, sibling_fps, result", |
| 532 |
[ |
| 533 |
(roboto_flex_fp, [], False), |
| 534 |
( |
| 535 |
opensans_roman_fp, |
| 536 |
[opensans_italic_fp, opensans_cond_roman_fp, opensans_cond_italic_fp], |
| 537 |
True, |
| 538 |
), |
| 539 |
( |
| 540 |
opensans_italic_fp, |
| 541 |
[opensans_roman_fp, opensans_cond_roman_fp, opensans_cond_italic_fp], |
| 542 |
True, |
| 543 |
), |
| 544 |
( |
| 545 |
opensans_cond_roman_fp, |
| 546 |
[opensans_roman_fp, opensans_italic_fp, opensans_cond_italic_fp], |
| 547 |
True, |
| 548 |
), |
| 549 |
( |
| 550 |
opensans_cond_italic_fp, |
| 551 |
[opensans_roman_fp, opensans_italic_fp, opensans_cond_roman_fp], |
| 552 |
True, |
| 553 |
), |
| 554 |
(opensans_roman_fp, [opensans_cond_roman_fp], True), |
| 555 |
(opensans_roman_fp, [opensans_italic_fp], False), |
| 556 |
(wonky_fp, [], False), |
| 557 |
], |
| 558 |
) |
| 559 |
def test_fvar_instance_collisions(fp, sibling_fps, result): |
| 560 |
ttFont = TTFont(fp) |
| 561 |
siblings = [TTFont(fp) for fp in sibling_fps] |
| 562 |
assert _fvar_instance_collisions(ttFont, siblings) == result |
| 563 |
|
| 564 |
|
| 565 |
@pytest.mark.parametrize( |
| 566 |
"fp, result", |
| 567 |
[ |
| 568 |
(roboto_flex_fp, "RobotoFlex"), |
| 569 |
(opensans_roman_fp, "OpenSans"), |
| 570 |
(opensans_italic_fp, "OpenSansItalic"), |
| 571 |
(opensans_cond_roman_fp, "OpenSansCondensed"), |
| 572 |
(opensans_cond_italic_fp, "OpenSansCondensedItalic"), |
| 573 |
(wonky_fp, "Wonky"), |
| 574 |
], |
| 575 |
) |
| 576 |
def test_build_variations_ps_name(fp, result): |
| 577 |
ttFont = TTFont(fp) |
| 578 |
build_variations_ps_name(ttFont) |
| 579 |
variation_ps_name = ttFont["name"].getName(25, 3, 1, 0x409).toUnicode() |
| 580 |
assert variation_ps_name == result |
| 581 |
|
| 582 |
|
| 583 |
@pytest.mark.parametrize( |
| 584 |
"fp, style_name, result", |
| 585 |
[ |
| 586 |
(mavenpro_fp, "Regular", 400), |
| 587 |
(mavenpro_fp, "Italic", 400), |
| 588 |
(mavenpro_fp, "Black Italic", 900), |
| 589 |
(mavenpro_fp, "ExtraBold Italic", 800), |
| 590 |
(mavenpro_fp, "ExtraBold", 800), |
| 591 |
(mavenpro_fp, "Bold", 700), |
| 592 |
(mavenpro_fp, "Bold Italic", 700), |
| 593 |
(mavenpro_fp, "Thin Italic", 100), |
| 594 |
(mavenpro_fp, "Thin", 100), |
| 595 |
], |
| 596 |
) |
| 597 |
def test_us_weight_class(fp, style_name, result): |
| 598 |
ttFont = TTFont(fp) |
| 599 |
build_name_table(ttFont, style_name=style_name) |
| 600 |
assert ttFont["OS/2"].usWeightClass == result |