@@ -310,6 +310,65 @@ def test_instanceworker_instantiate_ttfont_and_gen_subspace_one_axis(tmpdir):
310
310
assert "CRSV" not in axis_tags
311
311
312
312
313
+ def test_instanceworker_instantiate_ttfont_and_gen_restricted_subspace_one_axis (tmpdir ):
314
+ # When there are
315
+ outpath = str (tmpdir .join ("test.ttf" ))
316
+ font_model = get_font_model ()
317
+
318
+ axis_model = DesignAxisModel ()
319
+ axis_model .load_font (font_model )
320
+ # "wght" axis defined at restricted range of 200:400
321
+ axis_model ._data [0 ][1 ] = "1"
322
+ axis_model ._data [1 ][1 ] = "0"
323
+ axis_model ._data [2 ][1 ] = "200:400"
324
+ axis_model ._data [3 ][1 ] = "0"
325
+ axis_model ._data [4 ][1 ] = "0.5"
326
+
327
+ name_model = FontNameModel ()
328
+ name_model .load_font (font_model )
329
+
330
+ bit_model = FontBitFlagModel (
331
+ get_os2_default_dict_true (), get_head_default_dict_true ()
332
+ )
333
+
334
+ iw = InstanceWorker (
335
+ outpath ,
336
+ font_model ,
337
+ axis_model ,
338
+ name_model ,
339
+ bit_model ,
340
+ )
341
+
342
+ assert iw .ttfont is None
343
+ # the ttfont attribute is set with this method
344
+ iw .instantiate_ttfont ()
345
+ assert type (iw .ttfont ) is TTFont
346
+ # it is a variable font and should have an fvar table
347
+ assert "fvar" in iw .ttfont
348
+
349
+ # after instantiation of the partial, fvar should still be present
350
+ iw .instantiate_variable_font ()
351
+ assert "fvar" in iw .ttfont
352
+ # in the test font, the "wght" axis should still be variable
353
+ # with the variable setting that was used above
354
+ # make list of axis tags
355
+ axis_tags = [axis .axisTag for axis in iw .ttfont ["fvar" ].axes ]
356
+ # the font should include a variable MONO axis, all others
357
+ # should have been sliced
358
+ assert "MONO" not in axis_tags
359
+ assert "CASL" not in axis_tags
360
+ assert "wght" in axis_tags
361
+ assert "slnt" not in axis_tags
362
+ assert "CRSV" not in axis_tags
363
+
364
+ # get the axis data to confirm that we have a proper restricted axis range
365
+ for axis in iw .ttfont ["fvar" ].axes :
366
+ if axis .axisTag == "wght" :
367
+ assert axis .minValue == 200
368
+ assert axis .maxValue == 400
369
+ assert axis .defaultValue == 300
370
+
371
+
313
372
def test_instanceworker_instantiate_ttfont_and_gen_subspace_one_axis_woff (tmpdir ):
314
373
# When there are
315
374
outpath = str (tmpdir .join ("test.ttf" ))
@@ -364,6 +423,67 @@ def test_instanceworker_instantiate_ttfont_and_gen_subspace_one_axis_woff(tmpdir
364
423
assert "CRSV" not in axis_tags
365
424
366
425
426
+ def test_instanceworker_instantiate_ttfont_and_gen_restricted_subspace_one_axis_woff (
427
+ tmpdir ,
428
+ ):
429
+ # When there are
430
+ outpath = str (tmpdir .join ("test.ttf" ))
431
+ font_model = get_font_model_woff ()
432
+
433
+ axis_model = DesignAxisModel ()
434
+ axis_model .load_font (font_model )
435
+ # "wght" axis defined at restricted range of 200:400
436
+ axis_model ._data [0 ][1 ] = "1"
437
+ axis_model ._data [1 ][1 ] = "0"
438
+ axis_model ._data [2 ][1 ] = "200:400"
439
+ axis_model ._data [3 ][1 ] = "0"
440
+ axis_model ._data [4 ][1 ] = "0.5"
441
+
442
+ name_model = FontNameModel ()
443
+ name_model .load_font (font_model )
444
+
445
+ bit_model = FontBitFlagModel (
446
+ get_os2_default_dict_true (), get_head_default_dict_true ()
447
+ )
448
+
449
+ iw = InstanceWorker (
450
+ outpath ,
451
+ font_model ,
452
+ axis_model ,
453
+ name_model ,
454
+ bit_model ,
455
+ )
456
+
457
+ assert iw .ttfont is None
458
+ # the ttfont attribute is set with this method
459
+ iw .instantiate_ttfont ()
460
+ assert type (iw .ttfont ) is TTFont
461
+ # it is a variable font and should have an fvar table
462
+ assert "fvar" in iw .ttfont
463
+
464
+ # after instantiation of the partial, fvar should still be present
465
+ iw .instantiate_variable_font ()
466
+ assert "fvar" in iw .ttfont
467
+ # in the test font, the "wght" axis should still be variable
468
+ # with the variable setting that was used above
469
+ # make list of axis tags
470
+ axis_tags = [axis .axisTag for axis in iw .ttfont ["fvar" ].axes ]
471
+ # the font should include a variable MONO axis, all others
472
+ # should have been sliced
473
+ assert "MONO" not in axis_tags
474
+ assert "CASL" not in axis_tags
475
+ assert "wght" in axis_tags
476
+ assert "slnt" not in axis_tags
477
+ assert "CRSV" not in axis_tags
478
+
479
+ # get the axis data to confirm that we have a proper restricted axis range
480
+ for axis in iw .ttfont ["fvar" ].axes :
481
+ if axis .axisTag == "wght" :
482
+ assert axis .minValue == 200
483
+ assert axis .maxValue == 400
484
+ assert axis .defaultValue == 300
485
+
486
+
367
487
def test_instanceworker_instantiate_ttfont_and_gen_subspace_one_axis_woff2 (
368
488
tmpdir ,
369
489
):
@@ -420,6 +540,67 @@ def test_instanceworker_instantiate_ttfont_and_gen_subspace_one_axis_woff2(
420
540
assert "CRSV" not in axis_tags
421
541
422
542
543
+ def test_instanceworker_instantiate_ttfont_and_gen_restricted_subspace_one_axis_woff2 (
544
+ tmpdir ,
545
+ ):
546
+ # When there are
547
+ outpath = str (tmpdir .join ("test.ttf" ))
548
+ font_model = get_font_model_woff2 ()
549
+
550
+ axis_model = DesignAxisModel ()
551
+ axis_model .load_font (font_model )
552
+ # "wght" axis defined at restricted range of 200:400
553
+ axis_model ._data [0 ][1 ] = "1"
554
+ axis_model ._data [1 ][1 ] = "0"
555
+ axis_model ._data [2 ][1 ] = "200:400"
556
+ axis_model ._data [3 ][1 ] = "0"
557
+ axis_model ._data [4 ][1 ] = "0.5"
558
+
559
+ name_model = FontNameModel ()
560
+ name_model .load_font (font_model )
561
+
562
+ bit_model = FontBitFlagModel (
563
+ get_os2_default_dict_true (), get_head_default_dict_true ()
564
+ )
565
+
566
+ iw = InstanceWorker (
567
+ outpath ,
568
+ font_model ,
569
+ axis_model ,
570
+ name_model ,
571
+ bit_model ,
572
+ )
573
+
574
+ assert iw .ttfont is None
575
+ # the ttfont attribute is set with this method
576
+ iw .instantiate_ttfont ()
577
+ assert type (iw .ttfont ) is TTFont
578
+ # it is a variable font and should have an fvar table
579
+ assert "fvar" in iw .ttfont
580
+
581
+ # after instantiation of the partial, fvar should still be present
582
+ iw .instantiate_variable_font ()
583
+ assert "fvar" in iw .ttfont
584
+ # in the test font, the "wght" axis should still be variable
585
+ # with the variable setting that was used above
586
+ # make list of axis tags
587
+ axis_tags = [axis .axisTag for axis in iw .ttfont ["fvar" ].axes ]
588
+ # the font should include a variable MONO axis, all others
589
+ # should have been sliced
590
+ assert "MONO" not in axis_tags
591
+ assert "CASL" not in axis_tags
592
+ assert "wght" in axis_tags
593
+ assert "slnt" not in axis_tags
594
+ assert "CRSV" not in axis_tags
595
+
596
+ # get the axis data to confirm that we have a proper restricted axis range
597
+ for axis in iw .ttfont ["fvar" ].axes :
598
+ if axis .axisTag == "wght" :
599
+ assert axis .minValue == 200
600
+ assert axis .maxValue == 400
601
+ assert axis .defaultValue == 300
602
+
603
+
423
604
def test_instanceworker_instantiate_ttfont_and_gen_subspace_multi_axis (tmpdir ):
424
605
outpath = str (tmpdir .join ("test.ttf" ))
425
606
font_model = get_font_model ()
0 commit comments