

def renderToFile(self, filepath, margin, height, maxWidth):
    margin = round(margin)
    height = round(height)
    maxWidth = round(maxWidth)
    minmax = None
    for item in self.items:
        if (minmax is None):
            minmax = item.minmax()
        else:
            minmax = minmaxMerge(minmax, item.minmax())
    scalingY = ((height - (2 * margin)) / (minmax.maxY - minmax.minY))
    scalingX = ((maxWidth - (2 * margin)) / (minmax.maxX - minmax.minX))
    scaling = min(scalingX, scalingY)
    contentWidth = math.ceil(((minmax.maxX - minmax.minX) * scaling))
    contentHeight = math.ceil(((minmax.maxY - minmax.minY) * scaling))
    width = (contentWidth + (2 * margin))
    svg_document = svgwrite.Drawing(filename=filepath, size=(formatSvgPixels(width), formatSvgPixels(height)))
    if (self.backgroundColor is not None):
        fillSvgRect(svg_document, 0, 0, width, height, self.backgroundColor)
    for item in self.items:
        item.resetRenderState()
        item.translate(TFSPoint((- minmax.minX), (- minmax.minY)))
        item.scale(scaling)
        item.translate(TFSPoint(margin, math.floor(((height - contentHeight) / 2))))
        item.render(svg_document)
    if (self.borderColor is not None):
        drawSvgRect(svg_document, 0, 0, width, height, self.borderColor)
    svg_document.save()

dataset/ETHPy150Open charlesmchen/typefacet-robofont/extension/TypeFacet-RoboFont.roboFontExt/lib/tfs/common/TFSSvg.py TFSSvg.renderToFile/original