MCPcopy Create free account
hub / github.com/PageBot/PageBot / getVarFontInstance

Function getVarFontInstance

Lib/pagebot/fonttoolbox/variablefontbuilder.py:167–193  ·  view source on GitHub ↗

The getVarFontInstance 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 in

(fontOrPath, location, styleName=None, normalize=True,
        cached=True, lazy=True)

Source from the content-addressed store, hash-verified

165 return constrainedLocation
166
167def getVarFontInstance(fontOrPath, location, styleName=None, normalize=True,
168 cached=True, lazy=True):
169 """The getVarFontInstance refers to the file of the source variable font.
170 The nLocation is dictionary axis locations of the instance with values
171 between (0, 1000), e.g. dict(wght=0, wdth=1000) or values between (0, 1),
172 e.g. dict(wght=0.2, wdth=0.6). Set normalize to False if the values in
173 location already are matching the axis min/max of the font. If there is a
174 [opsz] Optical Size value defined, then store that information in the
175 font.info.opticalSize. The optional *styleName* overwrites the
176 *font.info.styleName* of the *ttFont* or the automatic location name.
177
178 TODO: move to fonttoolbox.objects.font?
179 """
180 if isinstance(fontOrPath, str):
181 varFont = getFont(fontOrPath, lazy=lazy)
182 else:
183 varFont = fontOrPath
184 if varFont is None: # Could not read the Variable Font on that path.
185 return None
186 path = generateInstance(varFont.path, location, targetDirectory=getInstancePath(),
187 normalize=normalize, cached=cached, lazy=lazy)
188 # Answer the generated Variable Font instance. Add [opsz] value if is defined in the location, otherwise None.
189 instance = getFont(path, lazy=lazy)
190 instance.info.opticalSize = location.get('opsz')
191 instance.info.location = location
192 instance.info.varStyleName = styleName
193 return instance
194
195
196def generateInstance(variableFontPath, location, targetDirectory,

Callers 5

getInstanceMethod · 0.90
_drawGlyphMarkerMethod · 0.90
getInstanceMethod · 0.90
getVariableAxisFontsFunction · 0.85
fitVariableWidthFunction · 0.85

Calls 4

getFontFunction · 0.90
generateInstanceFunction · 0.85
getInstancePathFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected