CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-mutator-math

Python library for piecewise linear interpolation in multiple dimensions with multiple, arbitrarily placed, masters.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

ufo-tools.mddocs/

UFO Tools

Specialized tools for font interpolation using UFO (Unified Font Object) data with designspace document processing. These tools provide font-specific functionality built on top of the core MutatorMath objects.

Capabilities

Designspace Builder

Convenience function for processing designspace documents and generating UFO instances.

def build(documentPath, outputUFOFormatVersion=2, roundGeometry=True, 
          verbose=True, logPath=None, progressFunc=None) -> list:
    """
    Simple builder for UFO designspaces.
    
    Parameters:
    - documentPath: str, filepath to .designspace document or directory
    - outputUFOFormatVersion: int, UFO format version for output (default 2)
    - roundGeometry: bool, whether to round geometry coordinates (default True)
    - verbose: bool, enable verbose output (default True)
    - logPath: str, optional filepath to log file
    - progressFunc: callable, optional progress callback function
    
    Returns:
    - list: Processing results from designspace execution
    """

Progress Callback Function

def tokenProgressFunc(state="update", action=None, text=None, tick=0):
    """
    Token progress callback function for designspace processing.
    
    Parameters:
    - state: str, processing state ("update", "reading sources", "wrapping up")
    - action: str, action type ("stop", "start")
    - text: str, additional information (e.g., UFO name)
    - tick: float, progress value between 0 and 1
    """

Build Usage Examples

from mutatorMath.ufo import build

# Process single designspace document
results = build("MyFont.designspace", 
                outputUFOFormatVersion=3,
                verbose=True)

# Process all designspace files in directory
results = build("/path/to/designspaces/", 
                roundGeometry=False,
                logPath="build.log")

# With custom progress callback
def my_progress(state, action, text, tick):
    print(f"Progress: {state} - {text} ({tick*100:.1f}%)")

results = build("MyFont.designspace", progressFunc=my_progress)

DesignSpace Document Writer

Writer for creating designspace XML documents that describe interpolation spaces and masters.

class DesignSpaceDocumentWriter(object):
    """
    Writer for designspace XML documents.
    """
    def __init__(self, path, toolVersion=3, verbose=False):
        """
        Create designspace document writer.
        
        Parameters:
        - path: str, output path for designspace document
        - toolVersion: int, tool version for format compatibility
        - verbose: bool, enable verbose logging
        """
        
    def save(self, pretty=True):
        """
        Save the designspace XML document.
        
        Parameters:
        - pretty: bool, format XML with indentation
        """
        
    def addAxis(self, tag, name, minimum, maximum, default, warpMap=None):
        """
        Add axis definition to designspace.
        
        Parameters:
        - tag: str, 4-character axis tag
        - name: str, axis name
        - minimum: float, minimum axis value
        - maximum: float, maximum axis value
        - default: float, default axis value
        - warpMap: list, optional warp map for non-linear axis
        """
        
    def addSource(self, fileName, location, copyLib=False, copyGroups=False, 
                  copyInfo=False, muteKerning=False, muteInfo=False, 
                  muteFeatures=True, name=None, familyName=None, styleName=None):
        """
        Add source/master to designspace.
        
        Parameters:
        - fileName: str, path to UFO source file
        - location: Location object with axis coordinates
        - copyLib: bool, copy lib data from source
        - copyGroups: bool, copy groups from source
        - copyInfo: bool, copy info from source
        - muteKerning: bool, mute kerning for this source
        - muteInfo: bool, mute info for this source
        - muteFeatures: bool, mute features for this source
        - name: str, optional source name
        - familyName: str, optional family name
        - styleName: str, optional style name
        """
        
    def startInstance(self, name=None, familyName=None, styleName=None, 
                     fileName=None, postScriptFontName=None, styleMapFamilyName=None,
                     styleMapStyleName=None):
        """
        Start defining an instance in the designspace.
        
        Parameters:
        - name: str, optional instance name
        - familyName: str, optional family name
        - styleName: str, optional style name
        - fileName: str, optional output UFO path
        - postScriptFontName: str, optional PostScript font name
        - styleMapFamilyName: str, optional style map family name
        - styleMapStyleName: str, optional style map style name
        """
        
    def endInstance(self):
        """End current instance definition."""
        
    def writeGlyph(self, glyphName, location=None, unicodes=None, masters=None):
        """
        Write glyph definition to current instance.
        
        Parameters:
        - glyphName: str, glyph name
        - location: Location object, optional location for glyph
        - unicodes: list, optional unicode values
        - masters: list, optional master configurations
        """
        
    def writeInfo(self, location=None, masters=None):
        """
        Write info definition to current instance.
        
        Parameters:
        - location: Location object, optional location
        - masters: list, optional master configurations
        """
        
    def writeKerning(self, location=None, masters=None):
        """
        Write kerning definition to current instance.
        
        Parameters:
        - location: Location object, optional location
        - masters: list, optional master configurations
        """
        
    def writeWarp(self, warpDict):
        """
        Write warp/bending transformations to designspace.
        
        Parameters:
        - warpDict: dict, warp transformation definitions
        """

DesignSpace Document Reader

Reader and processor for designspace XML documents that generates UFO instances.

class DesignSpaceDocumentReader(object):
    """
    Reader and processor for designspace XML documents.
    """
    def __init__(self, path, ufoVersion=2, roundGeometry=True, 
                 verbose=True, logPath=None, progressFunc=None):
        """
        Create designspace document reader.
        
        Parameters:
        - path: str, path to designspace document
        - ufoVersion: int, UFO format version for output
        - roundGeometry: bool, round geometry coordinates
        - verbose: bool, enable verbose output
        - logPath: str, optional log file path
        - progressFunc: callable, optional progress callback
        """
        
    def process(self):
        """
        Process the designspace document and generate instances.
        Populates self.results with processing outcomes.
        """
        
    @property
    def results(self) -> list:
        """Get processing results after calling process()."""

DesignSpace Usage Examples

from mutatorMath.ufo.document import DesignSpaceDocumentWriter, DesignSpaceDocumentReader
from mutatorMath.objects.location import Location

# Create designspace document
writer = DesignSpaceDocumentWriter("MyFont.designspace")

# Define weight axis
writer.startAxis("weight", 100, 400, 900, "wght")
writer.endAxis()

# Add master sources
writer.startSource("Light.ufo", familyName="MyFont", styleName="Light")
writer.writeLocation(Location(weight=100))
writer.endSource()

writer.startSource("Bold.ufo", familyName="MyFont", styleName="Bold")  
writer.writeLocation(Location(weight=900))
writer.endSource()

# Add instances
writer.startInstance(familyName="MyFont", styleName="Regular", fileName="Regular.ufo")
writer.writeLocation(Location(weight=400))
writer.endInstance()

writer.save()

# Process designspace to generate instances
reader = DesignSpaceDocumentReader("MyFont.designspace", 
                                   ufoVersion=3,
                                   verbose=True)
reader.process()
print(reader.results)

Instance Writer

Object for building UFO instances from interpolation data.

class InstanceWriter(object):
    """
    Simple object to build a UFO instance.
    Collects interpolation data and generates UFO as efficiently as possible.
    """
    def __init__(self, path, ufoVersion=1, roundGeometry=False, 
                 axes=None, verbose=False, logger=None):
        """
        Create instance writer.
        
        Parameters:
        - path: str, output path for UFO instance
        - ufoVersion: int, UFO format version
        - roundGeometry: bool, round coordinate values
        - axes: dict, optional axis definitions for bending
        - verbose: bool, enable verbose output
        - logger: logging.Logger, optional logger instance
        """
        
    def save(self):
        """Save the UFO instance to disk."""
        
    def writeGlyph(self, glyphName, glyph):
        """
        Write glyph data to instance.
        
        Parameters:
        - glyphName: str, glyph name
        - glyph: glyph object with outline data
        """
        
    def writeInfo(self, info):
        """
        Write font info to instance.
        
        Parameters:
        - info: font info object
        """
        
    def writeKerning(self, kerning):
        """
        Write kerning data to instance.
        
        Parameters:
        - kerning: kerning data object
        """
        
    def writeLib(self, lib):
        """
        Write lib data to instance.
        
        Parameters:
        - lib: lib data dict
        """

Instance Writer Usage Examples

from mutatorMath.ufo.instance import InstanceWriter

# Create instance writer
writer = InstanceWriter("output/Regular.ufo", 
                       ufoVersion=3,
                       roundGeometry=True,
                       verbose=True)

# Write interpolated data (typically done by DesignSpaceDocumentReader)
# writer.writeGlyph("A", interpolated_glyph_A)
# writer.writeInfo(interpolated_info)
# writer.writeKerning(interpolated_kerning)

# Save UFO to disk
writer.save()

Helper Functions

Utility functions for designspace processing.

def initializeLogger(proposedLogPath):
    """
    Initialize logging for designspace processing.
    
    Parameters:
    - proposedLogPath: str, path for log file
    """

Install with Tessl CLI

npx tessl i tessl/pypi-mutator-math

docs

core-objects.md

index.md

ufo-tools.md

tile.json