Example #1
0
def show_stylenames(fontpath):
    from bakery_cli.ttfont import Font
    try:
        font = Font(fontpath)
    except TTLibError, ex:
        print("ERROR: %s" % ex)
        return
Example #2
0
def reset_fstype(fontpath):
    from bakery_cli.ttfont import Font
    try:
        font = Font(fontpath)
    except TTLibError, ex:
        print >> sys.stderr, "ERROR: %s" % ex
        return
Example #3
0
def metricfix(fonts):
    from bakery_cli.ttfont import Font
    ymin = 0
    ymax = 0

    for f in fonts:
        metrics = Font(f)
        font_ymin, font_ymax = metrics.get_bounding()
        ymin = min(font_ymin, ymin)
        ymax = max(font_ymax, ymax)

    for f in fonts:
        metrics = Font(f)
        metrics.ascents.set(ymax)
        metrics.descents.set(ymin)
        metrics.linegaps.set(0)
        metrics.save(f + '.fix')
Example #4
0
def show_stylenames(fontpath):
    from bakery_cli.ttfont import Font
    try:
        font = Font(fontpath)
    except TTLibError as ex:
        print("ERROR: %s" % ex)
        return
    print(font['name'].names[2].string)
Example #5
0
def reset_fstype(fontpath):
    from bakery_cli.ttfont import Font
    try:
        font = Font(fontpath)
    except TTLibError as ex:
        print("ERROR: %s" % ex, file=sys.stderr)
        return
    font['OS/2'].fsType = 0
    font.save(fontpath + '.fix')
Example #6
0
def fix_style_names(fontpath):
    from bakery_cli.ttfont import Font
    try:
        font = Font(fontpath)
    except TTLibError as ex:
        print("ERROR: %s" % ex)
        return
    # font['name'].fsType = 0
    font.save(fontpath + '.fix')
Example #7
0
def metricview(fonts):
    from bakery_cli.ttfont import Font
    view = TextMetricsView()
    for f in fonts:
        try:
            metrics = Font(f)
        except TTLibError, ex:
            print("ERROR: %s" % ex)
            continue
        view.add_metric(os.path.basename(f), metrics)
Example #8
0
def fix_name_table(fontfile):
    try:
        font = Font(fontfile)
    except TTLibError:
        print("Unable to open {}".format(os.path.basename(fontfile)),
              file=sys.stderr)
        return

    for name in font['name'].names:
        title = Font.bin2unistring(name)
        title = normalizestr(title)
        if name.platformID == 3:
            name.string = title.encode('utf-16-be')
        else:
            name.string = title

    font.save(fontfile + '.fix')
Example #9
0
    def apply(self, override_origin=False):
        from bakery_cli.ttfont import Font
        ymin = 0
        ymax = 0

        for f in self.fonts:
            metrics = Font(f)
            font_ymin, font_ymax = metrics.get_bounding()
            ymin = min(font_ymin, ymin)
            ymax = max(font_ymax, ymax)

        for f in self.fonts:
            fixer = VmetFixer(self.testcase, f)
            fixer.apply(ymin, ymax, override_origin=override_origin)

        command = "$ {0} {1}".format(Vmet.SCRIPTPATH, ' '.join(self.fonts))

        logger.debug(command)

        import StringIO
        for l in StringIO.StringIO(metricview(self.fonts)):
            logger.debug(l)
Example #10
0
def fix_name_table(fontfile):
    try:
        font = Font(fontfile)
    except TTLibError, ex:
        print >> sys.stderr, "ERROR: %s" % ex
        return
Example #11
0
# See the License for the specific language governing permissions and
# limitations under the License.
#
# See AUTHORS.txt for the list of Authors and LICENSE.txt for the License.
import argparse
import os
import sys

from bakery_cli.ttfont import Font
from bakery_cli.scripts.fstype import reset_fstype

from fontTools.ttLib import TTLibError

parser = argparse.ArgumentParser()
parser.add_argument('filename', help="Font file in OpenType (TTF/OTF) format")
parser.add_argument('--autofix',
                    action="store_true",
                    help="Autofix font metrics")

args = parser.parse_args()
assert os.path.exists(args.filename)
if args.autofix:
    reset_fstype(args.filename)
else:
    try:
        font = Font(args.filename)
    except TTLibError, ex:
        print >> sys.stderr, "ERROR: %s" % ex
        exit(1)
    print(font.fstype)
                    nargs='+',
                    metavar='ttf_font',
                    help="Font file in OpenType (TTF/OTF) format")

options = parser.parse_args()

fonts = options.ttf_font

if (options.ascents or options.descents or options.linegaps
        or options.ascents_hhea or options.ascents_typo or options.ascents_win
        or options.descents_hhea or options.descents_typo
        or options.descents_win or options.linegaps_hhea
        or options.linegaps_typo):
    for f in fonts:
        try:
            metrics = Font(f)
        except TTLibError as ex:
            print('Error: {0}: {1}'.format(f, ex))
            continue

        # set ascents, descents and linegaps. FontVerticalMetrics will
        # not set those values if None, and overwrite them if concrete
        # argument has been passed
        metrics.ascents.set(options.ascents)
        metrics.descents.set(options.descents)
        metrics.linegaps.set(options.linegaps)

        metrics.ascents.hhea = options.ascents_hhea
        metrics.ascents.os2typo = options.ascents_typo
        metrics.ascents.os2win = options.ascents_win
Example #13
0
from bakery_cli.ttfont import Font
from bakery_cli.scripts.fstype import reset_fstype

from fontTools.ttLib import TTLibError

description = 'Fixes TTF fsType to 0'

parser = argparse.ArgumentParser(description=description)
parser.add_argument('ttf_font',
                    nargs='+',
                    help="Font in OpenType (TTF/OTF) format")
parser.add_argument('--autofix',
                    action="store_true",
                    help="Autofix font metrics")

args = parser.parse_args()

for path in args.ttf_font:
    if not os.path.exists(path):
        continue

    if args.autofix:
        reset_fstype(path)
    else:
        try:
            font = Font(path)
        except TTLibError as ex:
            print("ERROR: {0}: {1}".format(path, ex), file=sys.stderr)
            continue
        print('{0}: {1}'.format(path, font.OS2_fsType))