Exemple #1
0
 def __init__(self, name, width, path):
     self.name = name
     if self.RE_HEX.match(name):
         if 2 <= len(name) < 4:
             self.uname = "u" + "0" * (4 - len(name)) + name
         else:
             self.uname = "u" + name
     else:
         self.uname = name
     self.width = int(width)
     # workaround for using cygwin fontforge
     if CYGWINFLG and CYGPATHFLG and os.path.isabs(path):
         self.path = util.cygpathconv(util.escapepath(path))
     else:
         self.path = util.escapepath(path)
 def __init__(self, name, width, path):
     self.name = name
     if self.RE_HEX.match(name):
         if 2 <= len(name) < 4:
             self.uname = "u" + "0" * (4 - len(name)) + name
         else:
             self.uname = "u" + name
     else:
         self.uname = name
     self.width = int(width)
     # workaround for using cygwin fontforge
     if CYGWINFLG and CYGPATHFLG and os.path.isabs(path):
         self.path = util.cygpathconv(util.escapepath(path))
     else:
         self.path = util.escapepath(path)
Exemple #3
0
def generateffscript(dest, metadata, lstglf, codepoints):
    script = '#!/usr/bin/env fontforge -script\n\n'

    script += 'New();\n\n'

    script += 'ScaleToEm({ascent},{descent})\n\n'.format(
        ascent=metadata.ascent, descent=metadata.descent)

    script += '# make .notdef\n'
    script += 'Select(0x0000);\n'
    script += 'SetWidth(1000);\n'
    script += 'SetGlyphName(".notdef");\n\n'

    script += '# use Unicode encoding\n'
    script += 'Reencode("unicode");\n\n'

    # import svg here
    script += '# import SVG files\n'
    script += 'Print("importing svg files...");\n'

    # define U+0020 space if not defined
    if 0x20 not in codepoints:
        script += 'Select(0u0020);\n'
        script += 'SetWidth(500);\n'

    # define U+3000 Ideographic Space if not defined
    if 0x3000 not in codepoints:
        script += 'Select(0u3000);\n'
        script += 'SetWidth(1000);\n'

    for glf in lstglf:
        #script += 'Print("{name}");\n'.format(name=glf.name)
        script += 'Select("{uname}");\n'.format(uname=glf.uname)
        script += 'Import("{path}", 0);\n'.format(path=glf.path)
        script += 'SetWidth({width});\n'.format(width=glf.width)

    # WAVE DASH <-> FULLWIDTH TILDE conversion
    if 0x301c in codepoints and 0xff5e not in codepoints:
        script += 'Select(0u301c);\n'
        script += 'Copy();\n'
        script += 'Select(0uff5e);\n'
        script += 'Paste();\n'
    elif 0x301c not in codepoints and 0xff5e in codepoints:
        script += 'Select(0uff5e);\n'
        script += 'Copy();\n'
        script += 'Select(0u301c);\n'
        script += 'Paste();\n'

    script += '\n'
    script += '# Auto Hinting off\n'
    script += 'SelectAll();\n'
    script += 'DontAutoHint();\n\n'

    script += '# round to integer values\n'
    script += 'RoundToInt();\n\n'

    script += '# set font info\n'
    # SetFontNames(fontname[,family[,fullname[,weight[,copyright-notice[,fontversion]]]]])
    script += 'SetFontNames("{fontname}",\\\n'.format(
        fontname=metadata.fontname)
    script += '             "{family}",\\\n'.format(family=metadata.family)
    script += '             "{fullname}",\\\n'.format(
        fullname=metadata.fullname)
    script += '             "{weight}",\\\n'.format(weight=metadata.weight)
    script += '             "{copyright}",\\\n'.format(
        copyright=metadata.copyrightnotice)
    script += '             "{fontversion}");\n\n'.format(
        fontversion=metadata.fontversion)

    # SetTTFName(lang,nameid,utf8-string)
    # see https://www.microsoft.com/typography/otspec/name.htm
    script += 'SetTTFName(0x411, 1, "{familyJP}");\n'.format(
        familyJP=metadata.familyJP)
    script += 'SetTTFName(0x411, 4, "{fullnameJP}");\n\n'.format(
        fullnameJP=metadata.fullnameJP)

    # workaround for cygwin fontforge
    if CYGWINFLG and CYGPATHFLG and os.path.isabs(dest):
        dest = util.cygpathconv(util.escapepath(dest))

    script += '# generate OTF file\n'
    script += 'Generate("{destfile}", "", 0x94);\n'.format(destfile=dest)
    script += 'Print("generated: {destfile}");\n\n'.format(destfile=dest)

    script += 'Close();\n'
    script += 'Quit();\n'

    return script
def generateffscript(dest, metadata, lstglf, codepoints):
    script = "#!/usr/bin/env fontforge -script\n\n"

    script += "New();\n\n"

    script += "ScaleToEm({ascent},{descent})\n\n".format(ascent=metadata.ascent, descent=metadata.descent)

    script += "# make .notdef\n"
    script += "Select(0x0000);\n"
    script += "SetWidth(1000);\n"
    script += 'SetGlyphName(".notdef");\n\n'

    script += "# use Unicode encoding\n"
    script += 'Reencode("unicode");\n\n'

    # import svg here
    script += "# import SVG files\n"
    script += 'Print("importing svg files...");\n'

    # define U+0020 space if not defined
    if 0x20 not in codepoints:
        script += "Select(0u0020);\n"
        script += "SetWidth(500);\n"

    # define U+3000 Ideographic Space if not defined
    if 0x3000 not in codepoints:
        script += "Select(0u3000);\n"
        script += "SetWidth(1000);\n"

    for glf in lstglf:
        # script += 'Print("{name}");\n'.format(name=glf.name)
        script += 'Select("{uname}");\n'.format(uname=glf.uname)
        script += 'Import("{path}", 0);\n'.format(path=glf.path)
        script += "SetWidth({width});\n".format(width=glf.width)

    # WAVE DASH <-> FULLWIDTH TILDE conversion
    if 0x301C in codepoints and 0xFF5E not in codepoints:
        script += "Select(0u301c);\n"
        script += "Copy();\n"
        script += "Select(0uff5e);\n"
        script += "Paste();\n"
    elif 0x301C not in codepoints and 0xFF5E in codepoints:
        script += "Select(0uff5e);\n"
        script += "Copy();\n"
        script += "Select(0u301c);\n"
        script += "Paste();\n"

    script += "\n"
    script += "# Auto Hinting off\n"
    script += "SelectAll();\n"
    script += "DontAutoHint();\n\n"

    script += "# round to integer values\n"
    script += "RoundToInt();\n\n"

    script += "# set font info\n"
    # SetFontNames(fontname[,family[,fullname[,weight[,copyright-notice[,fontversion]]]]])
    script += 'SetFontNames("{fontname}",\\\n'.format(fontname=metadata.fontname)
    script += '             "{family}",\\\n'.format(family=metadata.family)
    script += '             "{fullname}",\\\n'.format(fullname=metadata.fullname)
    script += '             "{weight}",\\\n'.format(weight=metadata.weight)
    script += '             "{copyright}",\\\n'.format(copyright=metadata.copyrightnotice)
    script += '             "{fontversion}");\n\n'.format(fontversion=metadata.fontversion)

    # SetTTFName(lang,nameid,utf8-string)
    # see https://www.microsoft.com/typography/otspec/name.htm
    script += 'SetTTFName(0x411, 1, "{familyJP}");\n'.format(familyJP=metadata.familyJP)
    script += 'SetTTFName(0x411, 4, "{fullnameJP}");\n\n'.format(fullnameJP=metadata.fullnameJP)

    # workaround for cygwin fontforge
    if CYGWINFLG and CYGPATHFLG and os.path.isabs(dest):
        dest = util.cygpathconv(util.escapepath(dest))

    script += "# generate OTF file\n"
    script += 'Generate("{destfile}", "", 0x94);\n'.format(destfile=dest)
    script += 'Print("generated: {destfile}");\n\n'.format(destfile=dest)

    script += "Close();\n"
    script += "Quit();\n"

    return script