The getInstance function refers to the file of the source variable font. The nLocation is dictionary axis locations of the instance with values between (0, 1000), e.g. dict(wght=0, wdth=1000) or values between (0, 1), e.g. dict(wght=0.2, wdth=0.6). Set normalize to False if the values i
(pathOrFont, location, dstPath=None, styleName=None,
opticalSize=None, normalize=True, cached=True, lazy=True,
kerning=None)
| 348 | return instance |
| 349 | |
| 350 | def getInstance(pathOrFont, location, dstPath=None, styleName=None, |
| 351 | opticalSize=None, normalize=True, cached=True, lazy=True, |
| 352 | kerning=None): |
| 353 | """The getInstance function refers to the file of the source variable font. |
| 354 | The nLocation is dictionary axis locations of the instance with values |
| 355 | between (0, 1000), e.g. dict(wght=0, wdth=1000) or values between (0, 1), |
| 356 | e.g. dict(wght=0.2, wdth=0.6). Set normalize to False if the values in |
| 357 | location already are matching the axis min/max of the font. If there is a |
| 358 | [opsz] Optical Size value defined, then store that information in the |
| 359 | font.info.opticalSize. |
| 360 | |
| 361 | The optional *styleName* overwrites the *font.info.styleName* of the |
| 362 | *ttFont* or the automatic location name. |
| 363 | |
| 364 | |
| 365 | >>> vf = findFont('Amstelvar-Roman-VF') |
| 366 | >>> instance = getInstance(vf, location={}, opticalSize=8) |
| 367 | >>> instance |
| 368 | <Font Amstelvar-Roman-VF-opsz8> |
| 369 | """ |
| 370 | """ |
| 371 | >>> instance.location |
| 372 | {'opsz': 8} |
| 373 | >>> instance['H'].width |
| 374 | 1740 |
| 375 | >>> instance = getInstance(vf, location=dict(wght=300), cached=False, opticalSize=150) |
| 376 | >>> instance.location |
| 377 | {'wght': 300, 'opsz': 150} |
| 378 | >>> instance['H'].width |
| 379 | 1740 |
| 380 | >>> instance = getInstance(vf, path='/tmp/TestVariableFontInstance.ttf', opticalSize=8) |
| 381 | >>> instance |
| 382 | <Font Amstelvar-Roman-VF-wght300> |
| 383 | """ |
| 384 | # If forcing flag is undefined, then get info from location. |
| 385 | if opticalSize is None: |
| 386 | opticalSize = location.get('opsz') |
| 387 | else: |
| 388 | location['opsz'] = opticalSize |
| 389 | |
| 390 | instance = makeInstance(pathOrFont, location, dstPath=None, normalize=normalize, cached=cached, |
| 391 | lazy=lazy, kerning=kerning) |
| 392 | |
| 393 | # Answers the generated Variable Font instance. Add [opsz] value if is |
| 394 | # defined in the location, otherwise None. |
| 395 | instance.info.opticalSize = opticalSize |
| 396 | instance.info.location = location |
| 397 | instance.info.varStyleName = styleName |
| 398 | return instance |
| 399 | |
| 400 | def makeInstance(pathOrVarFont, location, dstPath=None, normalize=True, cached=True, |
| 401 | lazy=True, kerning=None): |
no test coverage detected