コード例 #1
0
ファイル: webfonts.py プロジェクト: gferreira/hTools2
def ttf2eot(ttf_path, eot_path):
    '''
    Generate .eot font file from a .ttf font.

    Needs ``ttf2eot`` installed on your system.

    '''
    eot_command = ['ttf2eot', '<', ttf_path, '>', eot_path]
    executeCommand(eot_command, shell=True)
    return os.path.exists(eot_path)
コード例 #2
0
def ttf2eot(ttf_path, eot_path):
    '''
    Generate .eot font file from a .ttf font.

    Needs ``ttf2eot`` installed on your system.

    '''
    eot_command = ['ttf2eot', '<', ttf_path, '>', eot_path]
    executeCommand(eot_command, shell=True)
    return os.path.exists(eot_path)
コード例 #3
0
def woff2_compress(otf_path, woff_path=None):
    '''
    Generate a .woff2 file from an .otf or .ttf font.

    Requires ``woff2_compress`` installed on your system.

    '''
    command = ['woff2_compress', "%s" % otf_path]
    executeCommand(command, shell=True)
    woff_path_temp = '%s.woff2' % os.path.splitext(otf_path)[0]
    if woff_path is not None and os.path.exists(woff_path_temp):
        shutil.move(woff_path_temp, woff_path)
コード例 #4
0
def sfnt2woff(otf_path, woff_path=None):
    """
    Generate a .woff file from an .otf or .ttf font.

    Requires ``sfnt2woff`` installed on your system.

    """
    command = ['sfnt2woff', "%s" % otf_path]
    executeCommand(command, shell=True)
    woff_path_temp = '%s.woff' % os.path.splitext(otf_path)[0]
    if woff_path is not None and os.path.exists(woff_path_temp):
        shutil.move(woff_path_temp, woff_path)
コード例 #5
0
ファイル: webfonts.py プロジェクト: gferreira/hTools2
def woff2_compress(otf_path, woff_path=None):
    '''
    Generate a .woff2 file from an .otf or .ttf font.

    Requires ``woff2_compress`` installed on your system.

    '''
    command = ['woff2_compress', "%s" % otf_path]
    executeCommand(command, shell=True)
    woff_path_temp = '%s.woff2' % os.path.splitext(otf_path)[0]
    if woff_path is not None and os.path.exists(woff_path_temp):
        shutil.move(woff_path_temp, woff_path)
コード例 #6
0
def autohint_ttf(ttf_path, ttfautohinted_path):
    '''
    Autohint a .ttf font.

    Requires ``ttfautohint`` installed on your system.

    '''
    # if hasTTFAutoHint() is False:
    #     message('ERROR: ttfautohint is not installed.')
    #     return
    ttfautohint_options = []
    ttfautohint_command = ['ttfautohint'] + \
        ttfautohint_options + [ttf_path, ttfautohinted_path]
    executeCommand(ttfautohint_command, shell=True)
    return os.path.exists(ttfautohinted_path)
コード例 #7
0
ファイル: webfonts.py プロジェクト: gferreira/hTools2
def autohint_ttf(ttf_path, ttfautohinted_path):
    '''
    Autohint a .ttf font.

    Requires ``ttfautohint`` installed on your system.

    '''
    # if hasTTFAutoHint() is False:
    #     message('ERROR: ttfautohint is not installed.')
    #     return
    ttfautohint_options = []
    ttfautohint_command = ['ttfautohint'] + \
        ttfautohint_options + [ttf_path, ttfautohinted_path]
    executeCommand(ttfautohint_command, shell=True)
    return os.path.exists(ttfautohinted_path)
コード例 #8
0
 def convertButtonCallback(self, sender):
     if self.chosenMode == 'Single File':
         inputPath = getFile('Choose the file to convert')[0]
         if inputPath.endswith('.vfb') or inputPath.endswith('.ufo'):
             executeCommand(['vfb2ufo', '-fo', inputPath], shell=True)
         else:
             message('input file path is not correct')
     else:
         inputFolder = getFolder('Choose a folder with files to convert')[0]
         if inputFolder:
             for eachPath in catchFilesAndFolders(inputFolder,
                                                  self.chosenSuffix):
                 executeCommand(['vfb2ufo', '-fo', eachPath], shell=True)
         else:
             message('input folder path is not correct')
コード例 #9
0
def ShowProfile(func, *args, **kwargs):
    """
    +------------------------------+
    |        function name         |
    | total time % ( self time % ) |
    |         total calls          |
    +------------------------------+

                total time %
                  calls
    parent --------------------> children
    """
    statsPath = tempfile.mkstemp(suffix=".stats")[1]
    dotPath = tempfile.mkstemp(suffix=".dot")[1]
    svgPath = tempfile.mkstemp(suffix=".svg")[1]

    pro = cProfile.Profile()
    pro.runcall(func, *args, **kwargs)
    pro.print_stats(sort=1)
    pro.dump_stats(statsPath)

    gprof2dot = os.path.join(os.path.dirname(__file__), "gprof2dot.py")

    cmds = [python, gprof2dot, "-o", dotPath, "--node-thres", "0", "--edge-thres", "1", "-f", "pstats", statsPath]
    stdout, stderr = executeCommand(cmds, shell=True)

    cmds = ["dot", dotPath, "-Tsvg", "-o", svgPath]
    stdout, stderr = executeCommand(cmds, shell=True)

    f = open(svgPath, "r", encoding="utf-8")
    data = f.read()
    f.close()

    HelpWindow(htmlString=data, title="Profiling: %s" % func.__name__)

    os.remove(statsPath)
    os.remove(dotPath)
    os.remove(svgPath)
コード例 #10
0
def generateWOFF(source, dest, metaData=None, version=None):
    cmds = [sfnt2woff]
    if version is not None:
        cmds.append("-v")
        cmds.append(version)
    if metaData is not None:
        cmds.append("-m")
        cmds.append(metaData)
    cmds.append(source)

    result = executeCommand(cmds)
    resultWoff = os.path.splitext(source)[0] + ".woff"
    shutil.move(resultWoff, dest)
    return result
コード例 #11
0
def TTFAutohint(sourcePath, destinationPath, options=dict()):
    """
    Options:
          --debug                print debugging information
      -f, --latin-fallback       set fallback script to latin
      -G, --hinting-limit=N      switch off hinting above this PPEM value
                                 (default: 200); value 0 means no limit
      -h, --help                 display this help and exit
      -i, --ignore-restrictions  override font license restrictions
      -l, --hinting-range-min=N  the minimum PPEM value for hint sets
                                 (default: 8)
      -n  --no-info              don't add ttfautohint info
                                 to the version string(s) in the `name' table
      -p, --pre-hinting          apply original hints in advance
      -r, --hinting-range-max=N  the maximum PPEM value for hint sets
                                 (default: 50)
      -s, --symbol               input is symbol font
      -v, --verbose              show progress information
      -V, --version              print version information and exit
      -w, --strong-stem-width=S  use strong stem width routine for modes S,
                                 where S is a string of up to three letters
                                 with possible values `g' for grayscale,
                                 `G' for GDI ClearType, and `D' for
                                 DirectWrite ClearType (default: G)
      -x, --increase-x-height=N  increase x height for sizes in the range
                                 6<=PPEM<=N; value 0 switches off this feature
                                 (default: 14)
      -X, --x-height-snapping-exceptions=STRING
                                 specify a comma-separated list of
                                 x-height snapping exceptions

    """
    updateWithDefaultValues(options, defaultOptions)

    hintRangeMinimum = str(options["hintRangeMinimum"])
    hintRangeMaximum = str(options["hintRangeMaximum"])
    fallbackScript = options["fallbackScript"]
    hintingLimit = options["hintingLimit"]
    noHintingLimit = options["noHintingLimit"]
    if noHintingLimit:
        hintingLimit = 0
    hintingLimit = str(hintingLimit)

    xHeightIncreaseLimit = options["xHeightIncreaseLimit"]
    noXHeightIncreaseLimit = options["noXHeightIncreaseLimit"]
    if noXHeightIncreaseLimit:
        xHeightIncreaseLimit = 0
    xHeightIncreaseLimit = str(xHeightIncreaseLimit)

    preHinting = options["preHinting"]
    symbolFont = options["symbolFont"]
    if not symbolFont:
        f = TTFont(sourcePath)
        symbolFont = "o" not in f.getGlyphOrder()
        f.close()

    addTTFAutoHintInfo = options["addTTFAutoHintInfo"]
    overRideFontLicense = options["overRideFontLicense"]

    grayScale = options["grayScale"]
    if grayScale:
        grayScale = "g"
    else:
        grayScale = ""

    gdiClearType = options["gdiClearType"]
    if gdiClearType:
        gdiClearType = "G"
    else:
        gdiClearType = ""

    dwClearType = options["dwClearType"]
    if dwClearType:
        dwClearType = "D"
    else:
        dwClearType = ""

    cmd = [ttfautohint]
    cmd.extend(["-G", hintingLimit])
    cmd.extend(["-l", hintRangeMinimum])
    cmd.extend(["-r", hintRangeMaximum])
    cmd.extend(["-x", xHeightIncreaseLimit])

    if fallbackScript:
        cmd.append("-f")
    if not addTTFAutoHintInfo:
        cmd.append("-n")
    if preHinting:
        cmd.append("-p")
    if symbolFont:
        cmd.append("-s")
    if not overRideFontLicense:
        cmd.append("-i")

    cmd.extend(["-w", grayScale + gdiClearType + dwClearType])
    cmd.extend([sourcePath, destinationPath])
    result = executeCommand(cmd)
    return result
コード例 #12
0
def TTFAutohint(sourcePath, destinationPath, options=dict()):
    """
    Options:
          --debug                print debugging information
      -f, --latin-fallback       set fallback script to latin
      -G, --hinting-limit=N      switch off hinting above this PPEM value
                                 (default: 200); value 0 means no limit
      -h, --help                 display this help and exit
      -i, --ignore-restrictions  override font license restrictions
      -l, --hinting-range-min=N  the minimum PPEM value for hint sets
                                 (default: 8)
      -n  --no-info              don't add ttfautohint info
                                 to the version string(s) in the `name' table
      -p, --pre-hinting          apply original hints in advance
      -r, --hinting-range-max=N  the maximum PPEM value for hint sets
                                 (default: 50)
      -s, --symbol               input is symbol font
      -v, --verbose              show progress information
      -V, --version              print version information and exit
      -w, --strong-stem-width=S  use strong stem width routine for modes S,
                                 where S is a string of up to three letters
                                 with possible values `g' for grayscale,
                                 `G' for GDI ClearType, and `D' for
                                 DirectWrite ClearType (default: G)
      -x, --increase-x-height=N  increase x height for sizes in the range
                                 6<=PPEM<=N; value 0 switches off this feature
                                 (default: 14)
      -X, --x-height-snapping-exceptions=STRING
                                 specify a comma-separated list of
                                 x-height snapping exceptions

    """
    updateWithDefaultValues(options, defaultOptions)

    hintRangeMinimum = str(options["hintRangeMinimum"])
    hintRangeMaximum = str(options["hintRangeMaximum"])
    fallbackScript = options["fallbackScript"]
    hintingLimit = options["hintingLimit"]
    noHintingLimit = options["noHintingLimit"]
    if noHintingLimit:
        hintingLimit = 0
    hintingLimit = str(hintingLimit)

    xHeightIncreaseLimit = options["xHeightIncreaseLimit"]
    noXHeightIncreaseLimit = options["noXHeightIncreaseLimit"]
    if noXHeightIncreaseLimit:
        xHeightIncreaseLimit = 0
    xHeightIncreaseLimit = str(xHeightIncreaseLimit)

    preHinting = options["preHinting"]
    symbolFont = options["symbolFont"]
    if not symbolFont:
        f = TTFont(sourcePath)
        symbolFont = "o" not in f.getGlyphOrder()
        f.close()

    addTTFAutoHintInfo = options["addTTFAutoHintInfo"]
    overRideFontLicense = options["overRideFontLicense"]

    grayScale = options["grayScale"]
    if grayScale:
        grayScale = "g"
    else:
        grayScale = ""

    gdiClearType = options["gdiClearType"]
    if gdiClearType:
        gdiClearType = "G"
    else:
        gdiClearType = ""

    dwClearType = options["dwClearType"]
    if dwClearType:
        dwClearType = "D"
    else:
        dwClearType = ""

    cmd = [ttfautohint]
    cmd.extend(["-G", hintingLimit])
    cmd.extend(["-l", hintRangeMinimum])
    cmd.extend(["-r", hintRangeMaximum])
    cmd.extend(["-x", xHeightIncreaseLimit])

    if fallbackScript:
        cmd.append("-f")
    if not addTTFAutoHintInfo:
        cmd.append("-n")
    if preHinting:
        cmd.append("-p")
    if symbolFont:
        cmd.append("-s")
    if not overRideFontLicense:
        cmd.append("-i")

    cmd.extend(["-w", grayScale + gdiClearType + dwClearType])
    cmd.extend([sourcePath, destinationPath])
    result = executeCommand(cmd)
    return result
コード例 #13
0
def generateWOFF2(source, dest):
    cmds = [woff2_compress, source]
    result = executeCommand(cmds)
    resultWoff = os.path.splitext(source)[0] + ".woff2"
    shutil.move(resultWoff, dest)
    return result
コード例 #14
0
def generateWOFF2(source, dest):
    cmds = [woff2_compress, source]
    result = executeCommand(cmds)
    resultWoff = os.path.splitext(source)[0] + ".woff2"
    shutil.move(resultWoff, dest)
    return result
コード例 #15
0
def traceImage(glyph,
               destGlyph=None,
               threshold=.2,
               blur=None,
               invert=False,
               turdsize=2,
               opttolerance=0.2,
               neededForPreview=False):
    if destGlyph is None:
        destGlyph = glyph
    if glyph is None:
        return
    image = glyph.image
    if image is None:
        return
    bounds = image.bounds
    if bounds is None:
        return
    x, y, maxx, maxy = image.bounds
    w = maxx - x
    h = maxy - y

    imagePath = tempfile.mktemp(".bmp")
    bitmapPath = tempfile.mktemp(".pgm")
    svgPath = tempfile.mktemp(".svg")

    saveImageAsBitmap(image, imagePath)

    cmds = [mkbitmap, "-x", "-t", str(threshold)]
    if blur:
        cmds.extend(["-b", str(blur)])
    if invert:
        cmds.extend(["-i"])
    cmds.extend([
        # "-g",
        # "-1",
        "-o",
        bitmapPath,
        imagePath
    ])
    log = executeCommand(cmds, shell=True)
    if log != ('', ''):
        print(log)

    cmds = [potrace, "-s"]
    cmds.extend(["-t", str(turdsize)])
    cmds.extend(["-O", str(opttolerance)])
    cmds.extend(["-o", svgPath, bitmapPath])

    log = executeCommand(cmds, shell=False)
    if log != ('', ''):
        print(log)

    glyph.prepareUndo("Tracing")
    importSVGWithPen(svgPath, destGlyph.getPen(), (x, y, w, h))
    glyph.performUndo()

    os.remove(imagePath)
    os.remove(svgPath)

    if not neededForPreview:
        os.remove(bitmapPath)
    else:
        return bitmapPath