Example #1
0
def fixMissingComponent(filePath):
    report = []  # Collect errors and warnings in this list

    font = openFont(filePath)
    if TESTING and 'Agrave' in font:  # Introduce an error, so we test the script
        for component in font['Agrave'].components:
            if component.baseGlyph == 'A':
                component.baseGlyph = 'HHH'  # Does not exist
                break

    # Display the font as header of the errors/warning with a marker line.
    report.append('-' * 80)
    report.append('Checking %s missing component references' % font.path)

    # Report if glyph.width < 0, then set it to DEFAULT_WIDTH
    for g in font:  # For all glyphs in the font
        if g.components:
            for component in g.components:
                #print(g.name, component)
                if component.baseGlyph not in font:
                    if REPLACE:
                        report.append(
                            'Fixed: Component in glyph "%s" baseGlyph "%s" changed to "%s"'
                            % (g.name, component.baseGlyph, REPLACE_BY))
                        ccomponent.baseGlyph = REPLACE_BY
                    else:
                        report.append(
                            'Warning: Component in glyph "%s" baseGlyph "%s" should change to "%s"'
                            % (g.name, component.baseGlyph, REPLACE_BY))

    if not TESTING:
        font.save()
    font.close()  # Does not do+anything in this script.
    return report
Example #2
0
def fixNegativeWidths(filePath):
    report = []  # Collect errors and warnings in this list
    font = openFont(
        filePath)  # Open the font as instance (not opening a window)

    if TESTING:  # Introduce an error, so we test the script
        font['H'].width = -200
        font['O'].width = -500

    # Display the font as header of the errors/warning with a marker line.
    report.append('-' * 80)
    report.append('Checking %s Groups %d Kerning %d' %
                  (font.path, len(font.groups), len(font.kerning)))

    # Report if glyph.width < 0, then set it to DEFAULT_WIDTH
    for g in font:  # For all glyphs in the font
        if g.width < 0:
            report.append('Error: Glyph %s has negative width (%d)' %
                          (g.name, g.width))
            g.width = DEFAULT_WIDTH
        elif g.width == DEFAULT_WIDTH:
            report.append('Warning: Glyph %s has DEFAULT_WIDTH (%d)' %
                          (g.name, g.width))

    report.append('Saving font')
    font.save()
    font.close()  # Does not do+anything in this script.
    return report
Example #3
0
def fixTabWidths(fontPath):
    report = []
    #print('Family:', font.info.familyName, 'Style:', font.info.styleName, 'Path:', font.path)
    font = openFont(fontPath)
    report.append('Checking %s' % font.path)
    for g in font: # Runs through the glyph, instead of glyph names
        if 'tab' in g.name:
            if abs(g.width - TAB_WIDTH) > 1:
                diff = TAB_WIDTH - g.width
                report.append('Set tab width', g, TAB_WIDTH, '-->', g.width)
                g.leftMargin += diff/2 # First set the margin
                g.width = TAB_WIDTH # Then set the width
                g.update() 

    font.save()
    font.close() # Does not do+anything in this script.
    return report
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import sys
if __name__ == "__main__":
    sys.path.insert(0, "../")
from pagebotnano_025 import openFont

font = openFont("../masters/Upgrade_CJK_Try-Regular82.ufo")


def g(f, groupName, group):
    f.groups[groupName] = group


g(font, "TC1.I",
  ('I', 'Iacute', 'Ibreve', 'Icircumflex', 'Idieresis', 'Idotaccent', 'Igrave',
   'Imacron', 'Iogonek', 'Iota', 'Itilde'))
g(font, "TC1.comma", ('colon', 'ellipsis', 'period'))
g(font, "TC1.eight_dnom",
  ('eight.dnom', 'eight.numr', 'eight.sinf', 'eight.sups'))
g(font, "TC1.exclam", ('exclam', 'exclamdown'))
g(font, "TC1.five_dnom",
  ('five.dnom', 'five.numr', 'five.sinf', 'five.sups', 'fiveeighths'))
g(font, "TC1.four_dnom", ('four.dnom', 'four.numr', 'four.sinf', 'four.sups'))
g(font, "TC1.i", ('dotlessi', 'i', 'iacute', 'ibreve', 'icircumflex',
                  'idieresis', 'igrave', 'imacron', 'iogonek', 'itilde'))
g(font, "TC1.nine_dnom", ('nine.dnom', 'nine.numr', 'nine.sinf', 'nine.sups'))
g(font, "TC1.one_dnom",
  ('one.dnom', 'one.numr', 'one.sinf', 'one.sups', 'oneeighth', 'onefifth',
   'onehalf', 'onequarter', 'onesuperior', 'onethird'))
g(font, "TC1.seven_dnom",
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import sys
if __name__ == "__main__":
   sys.path.insert(0, "../")
from pagebotnano_025 import openFont

font = openFont("../masters/Upgrade_CJK_Try-Thin.ufo") 

def k(f, pair, value):
   f.kerning[pair] = value


font.save()
font.close()
#
import os, codecs
# Include the openFont function here, instead of the import, in case this
# script is not running inside the current folder.
from pagebotnano_025 import openFont

TESTING = False
PATH = 'masters/'  # Check all .ufo in this local folder
REPORT_PATH = 'reports/'  # Create folder if not exists, export report file there.

report = []  # Collect errors and warnings in this list

for fileName in os.listdir(PATH):  # For all the files in the masters/ folder
    if not fileName.endswith('.ufo'):
        continue  # Skip anything that is not a ufo file.
    font = openFont(
        PATH + fileName)  # Open the font as instance (not opening a window)

    if TESTING:  # Insert error to test on
        font['A'].unicode = 61
        font['B'].unicode = 61

    # Display the font as header of the errors/warning with a marker line.
    report.append('-' * 80)
    report.append('Checking %s Groups %d Kerning %d' %
                  (font.path, len(font.groups), len(font.kerning)))

    unicode2Name = {}
    for g in font:
        if g.unicode is None or not g.unicodes:  # Only test if there is a unicode set.
            continue
        for u in g.unicodes:
Example #7
0
#   Generate tab figures from figures if they don't exists.
#   Check on equal tab spacing if they do exist.
#
import os
# Include the openFont and copyGlyph function here, instead of the import, 
# in case this script is not running inside the current folder.
from pagebotnano_025 import openFont, copyGlyph

TAB_WIDTH = 630 # Standard tab width for all masters
FIGURES = ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'zero')
PATH = 'masters/'

for fileName in os.listdir(PATH): # For all .ufo files in the masters/ folder
    if fileName.startswith('.'):
        continue # Skip anything that is not a ufo file
    font = openFont(PATH+fileName) # Open then font without opening a FontWindow
    print('Checking', font.path)
    for gName in FIGURES: # Just doing from original figures
        if gName in font: # Only figure does exist already
            g = font[gName] # Get the figure glyph
            tabName = gName + '.tab' # Make the new figure.tab name
            if not tabName in font: # Only if it does not exists 
                copyGlyph(font, gName, font, tabName) # Copy the original to the .tab
                diff = TAB_WIDTH - g.width # Calculate the difference in width
                tabGlyph = font[tabName] # Set the tab width and center the figure
                tabGlyph.leftMargin += diff/2 # First set the margin
                tabGlyph.width = TAB_WIDTH # Then set the width
                print('Creating tab figure', tabName, 'on width', TAB_WIDTH)
    font.save()
    font.close() # Does not do anything in this script.
Example #8
0
# Kerning pair (glyph1, glyph2)
#
TAB_WIDTH = 630

PATH = 'masters/'
REPORT_PATH = 'reports/'

report = []
fixed = []

fonts = []

for fileName in os.listdir(PATH):
    if fileName.startswith('.') or not fileName.endswith('.ufo'):
        continue
    font = openFont(PATH + fileName)
    fonts.append(font)

    report.append('Checking %s Groups %d Kerning %d' %
                  (font.path, len(font.groups), len(font.kerning)))

    # Check on kerning pairs only (group1, group2)
    # Kerning with value 0
    # Glyphs of group1 can only be there once, same with glyphs of group2
    # All glyphs in groups exist
    # Different of groups between all fonts

    # Kerning with value 0
    if 1:
        for pair, value in font.kerning.items():
            if value == 0:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import sys
if __name__ == "__main__":
    sys.path.insert(0, "../")
from pagebotnano_025 import openFont

font = openFont("../masters/Upgrade_CJK_Try-Bold.ufo")


def g(f, groupName, group):
    f.groups[groupName] = group


g(font, "TC1.I",
  ('H', 'I', 'Iacute', 'IbreveIcircumflex', 'Idieresis', 'Idotaccent',
   'Igrave', 'Imacron', 'Iogonek', 'Iota', 'Itilde'))
g(font, "TC1.comma", ('colon', 'ellipsis', 'period'))
g(font, "TC1.eight_dnom",
  ('eight.dnom', 'eight.numr', 'eight.sinf', 'eight.sups'))
g(font, "TC1.exclam", ('exclam', 'exclamdown'))
g(font, "TC1.five_dnom",
  ('five.dnom', 'five.numr', 'five.sinf', 'five.sups', 'fiveeighths'))
g(font, "TC1.four_dnom", ('four.dnom', 'four.numr', 'four.sinf', 'four.sups'))
g(font, "TC1.i", ('dotlessi', 'i', 'iacute', 'ibreve', 'icircumflex',
                  'idieresis', 'igrave', 'imacron', 'iogonek', 'itilde'))
g(font, "TC1.nine_dnom", ('nine.dnom', 'nine.numr', 'nine.sinf', 'nine.sups'))
g(font, "TC1.one_dnom",
  ('one.dnom', 'one.numr', 'one.sinf', 'one.sups', 'oneeighth', 'onefifth',
   'onehalf', 'onequarter', 'onesuperior', 'onethird'))
g(font, "TC1.seven_dnom",