Example #1
0
def paint_groups(f, crop=False):
    """Paint the glyphs in the font according to their groups.

    If a ``groups_order`` lib is available, it is used to set the order of the glyphs in the font.

    """
    font = CurrentFont()
    if len(f.groups) > 0:
        clear_colors(f)
        count = 0
        _order = []
        if f.lib.has_key("groups_order"):
            groups = f.lib["groups_order"]
        else:
            groups = f.groups.keys()
        for group in groups:
            color_step = 1.0 / len(f.groups)
            color = color_step * count
            R, G, B = hls_to_rgb(color, 0.5, 1.0)
            for glyph_name in f.groups[group]:
                if f.has_key(glyph_name) is not True:
                    f.newGlyph(glyph_name)
                _order.append(glyph_name)
                f[glyph_name].mark = (R, G, B, 0.5)
                f[glyph_name].update()
            count += 1
        f.glyphOrder = _order
        f.update()
        if crop:
            crop_glyphset(f, _order)
    else:
        print "font has no groups.\n"
def paint_groups(font, crop=False):
    """Paint the glyphs in the font according to their groups.

    If a ``groups_order`` lib is available, it is used to set the order of the glyphs in the font.

    :param RFont font: The font as an RFont object.

    """
    if len(font.groups) > 0:
        clear_colors(font)
        count = 0
        _order = []
        if font.lib.has_key('groups_order'):
            groups = font.lib['groups_order']
        else:
            groups = font.groups.keys()
        for group in groups:
            color_step = 1.0 / len(font.groups)
            color = color_step * count
            R, G, B = hls_to_rgb(color, 0.5, 1.0)
            for glyph_name in font.groups[group]:
                if font.has_key(glyph_name) is not True:
                    font.newGlyph(glyph_name)
                _order.append(glyph_name)
                font[glyph_name].mark = (R, G, B, 0.3)
                font[glyph_name].update()
            count += 1
        font.glyphOrder = _order
        font.update()
        if crop:
            crop_glyphset(font, _order)
    else:
        print 'font has no groups.\n'
Example #3
0
def find_lost_anchors(font):
    """Find anchors which are lost outside of the bounding box."""
    clear_colors(font)
    c = random_color()
    lost_anchors = []
    for g in font:
        if len(g.anchors) > 0:
            for a in g.anchors:
                if a.position[1] > f.info.unitsPerEm:
                    lost_anchors.append((g.name, a.name, a.position))
                    g.mark = c
    return lost_anchors
Example #4
0
def find_lost_anchors(font):
    '''Find anchors which are lost outside of the bounding box.'''
    clear_colors(font)
    c = random_color()
    lost_anchors = []
    for g in font:
        if len(g.anchors) > 0:
            for a in g.anchors:
                if a.position[1] > f.info.unitsPerEm:
                    lost_anchors.append((g.name, a.name, a.position))
                    g.mark = c
    return lost_anchors
Example #5
0
def find_lost_anchors(font):
    '''Find anchors which are lost outside of the glyph box.'''
    clear_colors(font)
    c = random_color()
    lost_anchors = []
    for g in font:
        if len(g.anchors) > 0:
            for a in g.anchors:
                if a.y > f.info.unitsPerEm:
                    lost_anchors.append((g.name, a.name, (a.x, a.y) ))
                    g.mark = c
    return lost_anchors
Example #6
0
def check_compatibility(f1, f2, names=None, report=True):
    '''
    Checks if glyphs in ``f1`` and ``f2`` are compatible for interpolation.

    If ``names=None``, all glyphs in ``f1`` will be checked - otherwise, only the ones in the list ``names``.

    Glyph compatibility is indicated by colors in ``f1``:

    - ``green`` -> glyphs are compatible
    - ``red``   -> glyphs are not compatible
    - ``blue``  -> glyph does not exist in ``f2``

    If ``report=True``, the check results will be printed to the output window.

    '''
    # glyph names
    if names != None:
        gNames = names
    else:
        gNames = f1.keys()
    # colors
    clear_colors(f1)
    green = named_colors['green']
    red   = named_colors['red']
    blue  = named_colors['blue']
    # check glyphs
    if report == True:
        print 'checking compatibility between %s and %s...\n' % (get_full_name(f1), get_full_name(f2))
    for name in gNames:
        if f2.has_key(name):
            clear_color(f2[name])
            # if not compatible
            if not f1[name].isCompatible(f2[name]):
                f2[name].markColor = red
                if report == True:
                    print "\t### %s is not compatible" % name
            # if compatible
            else:
                f2[name].markColor = green
                if report == True:
                    print "\t%s is compatible" % name
        # if glyphs not in f2
        else:
            f1[name].markColor = blue
            if report == True:
                print "\t### %s is not in font 2" % name
    # update fonts
    f2.changed()
    f1.changed()
    if report == True:
        print '\n...done.\n'
Example #7
0
def check_compatibility(f1, f2, names=None, report=True):
    """
    Checks if glyphs in ``f1`` and ``f2`` are compatible for interpolation.

    If ``names=None``, all glyphs in ``f1`` will be checked - otherwise, only the ones in the list ``names``.

    Glyph compatibility is indicated by colors in ``f1``: glyphs marked with ``green`` are compatible, glyphs marked with ``red`` are not compatible (because contours and/or amount of points do not match), and glyphs marked with ``blue`` do not exist in ``f2``.

    If ``report=True``, the check results will be printed to the output window.

    """
    # glyph names
    if names != None:
        gNames = names
    else:
        gNames = f1.keys()
    # colors
    clear_colors(f1)
    green = named_colors['green']
    red = named_colors['red']
    blue = named_colors['blue']
    # check glyphs
    if report == True:
        print 'checking compatibility between %s and %s...\n' % (
            get_full_name(f1), get_full_name(f2))
    for name in gNames:
        if f2.has_key(name):
            clear_color(f2[name])
            # if not compatible
            if f1[name].isCompatible(f2[name], False) is not True:
                f2[name].mark = red
                if report == True:
                    print "\t### %s is not compatible" % name
            # if compatible
            else:
                f2[name].mark = green
                if report == True:
                    print "\t%s is compatible" % name
        # if glyphs not in f2
        else:
            f1[name].mark = blue
            if report == True:
                print "\t### %s is not in font 2" % name
    # update fonts
    f2.update()
    f1.update()
    if report == True:
        print '\n...done.\n'
Example #8
0
def check_compatibility(f1, f2, names=None, report=True):
    """
    Checks if glyphs in ``f1`` and ``f2`` are compatible for interpolation.

    If ``names=None``, all glyphs in ``f1`` will be checked - otherwise, only the ones in the list ``names``.

    Glyph compatibility is indicated by colors in ``f1``: glyphs marked with ``green`` are compatible, glyphs marked with ``red`` are not compatible (because contours and/or amount of points do not match), and glyphs marked with ``blue`` do not exist in ``f2``.

    If ``report=True``, the check results will be printed to the output window.

    """
    # glyph names
    if names != None:
        gNames = names
    else:
        gNames = f1.keys()
    # colors
    clear_colors(f1)
    green = named_colors['green']
    red = named_colors['red']
    blue = named_colors['blue']
    # check glyphs
    if report == True:
        print 'checking compatibility between %s and %s...\n' % (get_full_name(f1), get_full_name(f2))
    for name in gNames:
        if f2.has_key(name):
            clear_color(f2[name])
            # if not compatible
            if f1[name].isCompatible(f2[name], False) is not True:
                f2[name].mark = red
                if report == True:
                    print "\t### %s is not compatible" % name
            # if compatible
            else:
                f2[name].mark = green
                if report == True:
                    print "\t%s is compatible" % name
        # if glyphs not in f2
        else:
            f1[name].mark = blue
            if report == True:
                print "\t### %s is not in font 2" % name
    # update fonts
    f2.update()
    f1.update()
    if report == True:
        print '\n...done.\n'
Example #9
0
 def paint_spacing_groups(self, side, verbose=False):
     """Paint left or right spacing groups."""
     # collect groups & glyphs to paint
     _groups_dict = get_spacing_groups(self.ufo)
     if side == 'left':
         _groups = _groups_dict['left']
     else:
         _groups = _groups_dict['right']
     # paint
     if len(_groups) > 0:
         if verbose:
             print 'painting spacing groups...'
         print
         _group_names = _groups.keys()
         clear_colors(self.ufo)
         color_step = 1.0 / len(_group_names)
         count = 0
         for group in _group_names:
             if verbose:
                 print '\tpainting group %s...' % group
             color = color_step * count
             R, G, B = hls_to_rgb(color, 0.5, 1.0)
             for glyph_name in _groups[group]:
                 if self.ufo.has_key(glyph_name):
                     self.ufo[glyph_name].mark = (R, G, B, .5)
                     self.ufo[glyph_name].update()
                 else:
                     if verbose:
                         print '\t\t%s not in font' % glyph_name
             count += 1
         self.ufo.update()
         if verbose:
             print
             print '...done.\n'
     else:
         if verbose:
             print 'there are no spacing groups to paint.\n'
Example #10
0
def paint_groups(font, crop=False, order=None):
    '''
    Paint glyphs in the font according to their groups.

    If a ``groups_order`` font lib is available, it is used to set the order of the glyphs in the font.

    font: The font as an RFont object.

    '''
    if len(font.groups) > 0:
        clear_colors(font)
        count = 0
        _order = []
        if order is not None:
            groups = order
        elif font.lib.has_key('groups_order'):
            groups = font.lib['groups_order']
        else:
            groups = font.groups.keys()
        for group in groups:
            color_step = 1.0 / len(font.groups)
            color = color_step * count
            R, G, B = hls_to_rgb(color, 0.5, 1.0)
            for glyph_name in font.groups[group]:
                if font.has_key(glyph_name) is not True:
                    font.newGlyph(glyph_name)
                _order.append(glyph_name)
                font[glyph_name].mark = (R, G, B, 0.3)
                font[glyph_name].update()
            count += 1
        # print _order
        font.glyphOrder = _order
        font.update()
        if crop:
            crop_glyphset(font, _order)
    else:
        print 'font has no groups.\n'
Example #11
0
# [h] clear colors

'''Clear colors of all glyphs in font.'''

# import

from hTools2.modules.color import clear_colors

# run

f = CurrentFont()
clear_colors(f)
Example #12
0
# [h] clear colors

try:
    from mojo.roboFont import CurrentFont
except ImportError:
    from fontParts.world import CurrentFont

from hTools2.modules.color import clear_colors
from hTools2.modules.messages import no_font_open

f = CurrentFont()

if f is not None:
    clear_colors(f)

else:
    print(no_font_open)