Ejemplo n.º 1
1
 def rename_glyphs(self, names_list):
     print "renaming glyphs in space...\n"
     for ufo_path in self.ufos():
         ufo = RFont(ufo_path, showUI=False)
         print "\trenaming glyphs in %s..." % get_full_name(ufo)
         rename_glyphs_from_list(ufo, names_list, overwrite=True, mark=False, verbose=False)
         ufo.save()
     print
     print "...done.\n"
Ejemplo n.º 2
0
 def apply_callback(self, sender):
     if len(self.all_fonts) > 0:
         # get parameters
         source_font = self.all_fonts[self.w._source_value.get()]
         target_font = self.all_fonts[self.w._target_value.get()]
         # print info
         print "copying glyphs to mask...\n"
         print "\tsource font: %s (foreground)" % get_full_name(source_font)
         print "\ttarget font: %s (%s)" % (get_full_name(target_font), self.target_layer_name)
         print
         print "\t",
         # batch copy glyphs to mask
         for glyph_name in get_glyphs(source_font):
             print glyph_name,
             # prepare undo
             target_font[glyph_name].prepareUndo("copy glyphs to mask")
             # copy oulines to mask
             target_glyph_layer = target_font[glyph_name].getLayer(self.target_layer_name)
             pen = target_glyph_layer.getPointPen()
             source_font[glyph_name].drawPoints(pen)
             # update
             target_font[glyph_name].update()
             # activate undo
             target_font[glyph_name].performUndo()
         # done
         print
         target_font.update()
         print "\n...done.\n"
     # no font open
     else:
         print no_font_open
Ejemplo n.º 3
0
 def apply_callback(self, sender):
     if len(self._all_fonts) > 0:
         # get parameters
         _source_font = self._all_fonts[self.w._source_value.get()]
         _target_layer_name = self._target_layer_name
         _target_font = self._all_fonts[self.w._target_value.get()]
         # print info
         print 'copying glyphs to mask...\n'
         print '\tsource font: %s (foreground)' % get_full_name(_source_font)
         print '\ttarget font: %s (%s)' % (get_full_name(_target_font), self._target_layer_name)
         print
         print '\t',
         # batch copy glyphs to mask
         for glyph_name in get_glyphs(_source_font):
             print glyph_name,
             # prepare undo
             _target_font[glyph_name].prepareUndo('copy glyphs to mask')
             # copy oulines to mask
             _target_glyph_layer = _target_font[glyph_name].getLayer(_target_layer_name)
             pen = _target_glyph_layer.getPointPen()
             _source_font[glyph_name].drawPoints(pen)
             # update
             _target_font[glyph_name].update()
             # activate undo
             _target_font[glyph_name].performUndo()
         # done
         print
         _target_font.update()
         print '\n...done.\n'
     # no font open
     else:
         print 'please open at least one font.\n'
Ejemplo n.º 4
0
 def apply_callback(self, sender):
     # get fonts
     f1 = self.all_fonts[self.w._f1_font.get()]
     f2 = self.all_fonts[self.w._f2_font.get()]
     f3 = self.all_fonts[self.w._f3_font.get()]
     # get factors
     factor = self.factor
     # print info
     print 'condensing glyphs...\n'
     print '\tmaster 1: %s' % get_full_name(f1)
     print '\tmaster 2: %s' % get_full_name(f2)
     print '\ttarget: %s' % get_full_name(f3)
     print
     print '\tfactor: %s' % factor
     print
     print '\t',
     self.w.bar.start()
     # get stems
     f1_stems = f1.info.postscriptStemSnapH
     f2_stems = f2.info.postscriptStemSnapH
     # get glyphs
     glyph_names = f1.selection
     # condense glyphs
     if len(f1_stems) > 0 and len(f2_stems) > 0:
         condense_glyphs(f3, f1, f2, f1_stems[0], f2_stems[0], factor, glyph_names)
     else:
         print 'One or both fonts have no PS stem widths.'
     # done
     self.w.bar.stop()
     print
     print '\n...done.\n'
 def apply_callback(self, sender):
     # get fonts
     f1_name = sorted(self.all_fonts.keys())[self.w._f1_font.get()]
     f2_name = sorted(self.all_fonts.keys())[self.w._f2_font.get()]
     f3_name = sorted(self.all_fonts.keys())[self.w._f3_font.get()]
     f1 = self.all_fonts[f1_name]
     f2 = self.all_fonts[f2_name]
     f3 = self.all_fonts[f3_name]
     # get factors
     factor = float(self.w.spinner.value.get())
     # print info
     print('condensing glyphs...\n')
     print('\tmaster 1: %s' % get_full_name(f1))
     print('\tmaster 2: %s' % get_full_name(f2))
     print('\ttarget: %s' % get_full_name(f3))
     print()
     print('\tfactor: %s' % factor)
     print()
     print('\t', end=' ')
     self.w.bar.start()
     # get stems
     f1_stems = f1.info.postscriptStemSnapH
     f2_stems = f2.info.postscriptStemSnapH
     # get glyphs
     glyph_names = f1.selection
     # condense glyphs
     if len(f1_stems) > 0 and len(f2_stems) > 0:
         condense_glyphs(f3, f1, f2, f1_stems[0], f2_stems[0], factor,
                         glyph_names)
     else:
         print('One or both fonts have no PS stem widths.')
     # done
     self.w.bar.stop()
     print()
     print('\n...done.\n')
Ejemplo n.º 6
0
 def apply_callback(self, sender):
     # get source font parameters
     _source_font = self._all_fonts[self.w._source_value.get()]
     _source_mark = self.w.source_mark_checkbox.get()
     _source_mark_color = self.w.source_mark_color.get()
     _source_mark_color = (_source_mark_color.redComponent(),
                           _source_mark_color.greenComponent(),
                           _source_mark_color.blueComponent(),
                           _source_mark_color.alphaComponent())
     # get target font parameters
     _target_font = self._all_fonts[self.w._target_value.get()]
     _target_mark = self.w.target_mark_checkbox.get()
     _target_mark_color = self.w.target_mark_color.get()
     _target_mark_color = (_target_mark_color.redComponent(),
                           _target_mark_color.greenComponent(),
                           _target_mark_color.blueComponent(),
                           _target_mark_color.alphaComponent())
     # print info
     boolstring = [False, True]
     print 'transfering anchors...\n'
     print '\tsource font: %s' % get_full_name(_source_font)
     print '\tsource color: %s, %s' % (_source_mark_color,
                                       boolstring[_source_mark])
     print
     print '\ttarget font: %s' % get_full_name(_target_font)
     print '\ttarget color: %s, %s' % (_target_mark_color,
                                       boolstring[_target_mark])
     print
     print '\t',
     # batch copy glyphs to mask
     for gName in _source_font.selection:
         try:
             print gName,
             # prepare undo
             _target_font[gName].prepareUndo('transfer anchors')
             # transfer anchors
             has_anchor = transferAnchors(_source_font[gName],
                                          _target_font[gName])
             if has_anchor:
                 # mark
                 if _source_mark:
                     _source_font[gName].mark = _source_mark_color
                 if _target_mark:
                     _target_font[gName].mark = _target_mark_color
             # update
             _source_font[gName].update()
             _target_font[gName].update()
             # activate undo
             _source_font[gName].performUndo()
             _target_font[gName].performUndo()
         except:
             print '\tcannot transform %s' % gName
     # done
     print
     _target_font.update()
     _source_font.update()
     print '\n...done.\n'
Ejemplo n.º 7
0
 def apply_callback(self, sender):
     # get source font parameters
     _source_font = self._all_fonts[self.w._source_value.get()]
     _source_mark = self.w.source_mark_checkbox.get()
     _source_mark_color = self.w.source_mark_color.get()
     _source_mark_color = (_source_mark_color.redComponent(),
                           _source_mark_color.greenComponent(),
                           _source_mark_color.blueComponent(),
                           _source_mark_color.alphaComponent())
     # get target font parameters
     _target_layer_name = self._target_layer_name
     _target_font = self._all_fonts[self.w._target_value.get()]
     _target_mark = self.w.target_mark_checkbox.get()
     _target_mark_color = self.w.target_mark_color.get()
     _target_mark_color = (_target_mark_color.redComponent(),
                           _target_mark_color.greenComponent(),
                           _target_mark_color.blueComponent(),
                           _target_mark_color.alphaComponent())
     # print info
     print 'copying glyphs to mask...\n'
     print '\tsource font: %s (current layer, color: %s)' % (
         get_full_name(_source_font), _source_mark_color)
     print '\ttarget font: %s (layer: %s, color: %s)' % (get_full_name(
         _target_font), self._target_layer_name, _target_mark_color)
     print
     # batch copy glyphs to mask
     for gName in _source_font.selection:
         try:
             print '\t%s' % gName,
             # prepare undo
             _source_font[gName].prepareUndo('copy glyphs to mask')
             _target_font[gName].prepareUndo('copy glyphs to mask')
             # mark
             if _source_mark:
                 _source_font[gName].mark = _source_mark_color
             if _target_mark:
                 _target_font[gName].mark = _target_mark_color
             # copy oulines to mask
             _target_glyph_layer = _target_font[gName].getLayer(
                 _target_layer_name)
             pen = _target_glyph_layer.getPointPen()
             _source_font[gName].drawPoints(pen)
             # update
             _source_font[gName].update()
             _target_font[gName].update()
             # activate undo
             _source_font[gName].performUndo()
             _target_font[gName].performUndo()
         except:
             print '\tcannot transform %s' % gName
     # done
     print
     _target_font.update()
     _source_font.update()
     print '\n...done.\n'
Ejemplo n.º 8
0
 def apply_callback(self, sender):
     # get source font parameters
     _source_font = self._all_fonts[self.w._source_value.get()]
     _source_mark = self.w.source_mark_checkbox.get()
     _source_mark_color = self.w.source_mark_color.get()
     _source_mark_color = (_source_mark_color.redComponent(),
             _source_mark_color.greenComponent(),
             _source_mark_color.blueComponent(),
             _source_mark_color.alphaComponent())
     # get target font parameters
     _target_layer_name = self._target_layer_name
     _target_font = self._all_fonts[self.w._target_value.get()]
     _target_mark = self.w.target_mark_checkbox.get()
     _target_mark_color = self.w.target_mark_color.get()
     _target_mark_color = (_target_mark_color.redComponent(),
             _target_mark_color.greenComponent(),
             _target_mark_color.blueComponent(),
             _target_mark_color.alphaComponent())
     # print info
     print 'copying glyphs to mask...\n'
     print '\tsource font: %s (current layer, color: %s)' % (
             get_full_name(_source_font), _source_mark_color)
     print '\ttarget font: %s (layer: %s, color: %s)' % (
             get_full_name(_target_font), self._target_layer_name, _target_mark_color)
     print
     # batch copy glyphs to mask
     for gName in _source_font.selection:
         try:
             print '\t%s' % gName,
             # prepare undo
             _source_font[gName].prepareUndo('copy glyphs to mask')
             _target_font[gName].prepareUndo('copy glyphs to mask')
             # mark
             if _source_mark:
                 _source_font[gName].mark = _source_mark_color                
             if _target_mark:
                 _target_font[gName].mark = _target_mark_color
             # copy oulines to mask
             _target_glyph_layer = _target_font[gName].getLayer(_target_layer_name)
             pen = _target_glyph_layer.getPointPen()
             _source_font[gName].drawPoints(pen)
             # update
             _source_font[gName].update()
             _target_font[gName].update()
             # activate undo
             _source_font[gName].performUndo()
             _target_font[gName].performUndo()
         except:
             print '\tcannot transform %s' % gName                        
     # done
     print
     _target_font.update()
     _source_font.update()
     print '\n...done.\n'
Ejemplo n.º 9
0
 def apply_callback(self, sender):
     # get source font parameters
     _source_font = self._all_fonts[self.w._source_value.get()]
     _source_mark = self.w.source_mark_checkbox.get()
     _source_mark_color = self.w.source_mark_color.get()
     _source_mark_color = (_source_mark_color.redComponent(),
             _source_mark_color.greenComponent(),
             _source_mark_color.blueComponent(),
             _source_mark_color.alphaComponent())
     # get target font parameters
     _target_font = self._all_fonts[self.w._target_value.get()]
     _target_mark = self.w.target_mark_checkbox.get()
     _target_mark_color = self.w.target_mark_color.get()
     _target_mark_color = (_target_mark_color.redComponent(),
             _target_mark_color.greenComponent(),
             _target_mark_color.blueComponent(),
             _target_mark_color.alphaComponent())
     # print info
     boolstring = [ False, True ]
     print 'transfering anchors...\n'
     print '\tsource font: %s' % get_full_name(_source_font)
     print '\tsource color: %s, %s' % (_source_mark_color, boolstring[_source_mark])
     print
     print '\ttarget font: %s' % get_full_name(_target_font)
     print '\ttarget color: %s, %s' % (_target_mark_color, boolstring[_target_mark])
     print
     print '\t', 
     # batch copy glyphs to mask
     for gName in _source_font.selection:
         try:
             print gName,
             # prepare undo
             _target_font[gName].prepareUndo('transfer anchors')
             # transfer anchors
             has_anchor = transferAnchors(_source_font[gName], _target_font[gName])
             if has_anchor:
                 # mark
                 if _source_mark:
                     _source_font[gName].mark = _source_mark_color                
                 if _target_mark:
                     _target_font[gName].mark = _target_mark_color
             # update
             _source_font[gName].update()
             _target_font[gName].update()
             # activate undo
             _source_font[gName].performUndo()
             _target_font[gName].performUndo()
         except:
             print '\tcannot transform %s' % gName                        
     # done
     print
     _target_font.update()
     _source_font.update()
     print '\n...done.\n'
Ejemplo n.º 10
0
 def button_apply_callback(self, sender):
     print 'hello world'
     _all_fonts = AllFonts()
     if len(_all_fonts) > 0:
         # get settings
         _otfs_folder = self.w.otfs_folder_value.get()
         _decompose = self.w._decompose.get()
         _overlaps = self.w._overlaps.get()
         _autohint = self.w._autohint.get()
         _release_mode = self.w._release_mode.get()
         # print settings
         boolstring = ("False", "True")
         print 'generating .otfs for all open fonts...\n'
         print '\totfs folder: %s' % _otfs_folder
         print '\tremove overlaps: %s' % boolstring[_overlaps]
         print '\tdecompose: %s' % boolstring[_decompose]
         print '\tautohint: %s' % boolstring[_autohint]
         print '\trelease mode: %s' % boolstring[_release_mode]
         print
         # batch generate
         self.w.bar.start()
         _undo_name = 'generate all open fonts'
         for font in _all_fonts:
             if font.path is not None:
                 _font_path = font.path
                 print '\tgenerating .otf for %s...' % os.path.split(
                     get_full_name(font))[1]
                 # generate otf
                 otf_file = os.path.splitext(os.path.split(
                     font.path)[1])[0] + '.otf'
                 otf_path = os.path.join(_otfs_folder, otf_file)
                 font.generate(otf_path,
                               'otf',
                               decompose=_decompose,
                               autohint=_autohint,
                               checkOutlines=_overlaps,
                               releaseMode=_release_mode,
                               glyphOrder=[])
                 print '\t\totf path: %s' % otf_path
                 print '\t\tgeneration sucessful? %s\n' % os.path.exists(
                     otf_path)
             # skip unsaved open fonts
             else:
                 print '\tskipping "%s", please save this font to file first.\n' % os.path.split(
                     get_full_name(font))[1]
         # done all
         self.w.bar.stop()
         print '...done.\n'
     # no font open
     else:
         print 'please open at least one font before running this script.\n'
Ejemplo n.º 11
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'
Ejemplo n.º 12
0
 def apply_callback(self, sender):
     # get fonts
     try:
         f1 = self.all_fonts[self.w._f1_font.get()]
         f2 = self.all_fonts[self.w._f2_font.get()]
         f3 = self.all_fonts[self.w._f3_font.get()]
         glyph_names = get_glyphs(f1)
         if len(glyph_names) > 0:
             # get factors
             x = float(self.w._factor_x.value.get())
             y = float(self.w._factor_y.value.get())
             # print info
             print 'interpolating glyphs...\n'
             boolstring = (False, True)
             print '\tmaster 1: %s' % get_full_name(f1)
             print '\tmaster 2: %s' % get_full_name(f2)
             print '\ttarget: %s' % get_full_name(f3)
             print
             print '\tfactor x: %s' % x
             print '\tfactor y: %s' % y
             # print '\tproportional: %s' % boolstring[self.proportional]
             print
             print '\t',
             self.w.bar.start()
             # interpolate glyphs
             for glyph_name in glyph_names:
                 # check glyphs
                 if f2.has_key(glyph_name):
                     f3.newGlyph(glyph_name, clear=True)
                     # prepare undo
                     f3[glyph_name].prepareUndo('interpolate')
                     # interpolate
                     print glyph_name,
                     f3[glyph_name].interpolate((x, y), f1[glyph_name], f2[glyph_name])
                     f3[glyph_name].update()
                     # create undo
                     f3[glyph_name].performUndo()
                 else:
                     print '\tfont 2 does not have glyph %s' % glyph_name
             f3.update()
             # done
             self.w.bar.stop()
             print
             print '\n...done.\n'
         # no glyph selected
         else:
             print no_glyph_selected
     # no font open
     except:
         print no_font_open
Ejemplo n.º 13
0
 def button_apply_callback(self, sender):
     all_fonts = AllFonts()
     if len(all_fonts) > 0:
         # get settings
         _decompose = self.w._decompose.get()
         _overlaps = self.w._overlaps.get()
         _autohint = self.w._autohint.get()
         _release_mode = self.w._release_mode.get()
         # print settings
         boolstring = ("False", "True")
         print "generating .otfs for all open fonts...\n"
         print "\totfs folder: %s" % self._otfs_folder
         print "\tremove overlaps: %s" % boolstring[_overlaps]
         print "\tdecompose: %s" % boolstring[_decompose]
         print "\tautohint: %s" % boolstring[_autohint]
         print "\trelease mode: %s" % boolstring[_release_mode]
         print
         # batch generate
         self.w.bar.start()
         _undo_name = "generate all open fonts"
         for font in all_fonts:
             if font.path is not None:
                 _font_path = font.path
                 print "\tgenerating .otf for %s..." % os.path.split(get_full_name(font))[1]
                 # generate otf
                 otf_file = os.path.splitext(os.path.split(font.path)[1])[0] + ".otf"
                 otf_path = os.path.join(self._otfs_folder, otf_file)
                 font.generate(
                     otf_path,
                     "otf",
                     decompose=_decompose,
                     autohint=_autohint,
                     checkOutlines=_overlaps,
                     releaseMode=_release_mode,
                     glyphOrder=[],
                 )
                 print "\t\totf path: %s" % otf_path
                 print "\t\tgeneration sucessful? %s\n" % os.path.exists(otf_path)
             # skip unsaved open fonts
             else:
                 print '\tskipping "%s", please save this font to file first.\n' % os.path.split(
                     get_full_name(font)
                 )[1]
         # done all
         self.w.bar.stop()
         print "...done.\n"
     # no font open
     else:
         print no_font_open
Ejemplo n.º 14
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'
Ejemplo n.º 15
0
 def create_glyphs(self, gstring=None, verbose=False):
     """Create all glyphs in all fonts in space."""
     # get glyphs
     if gstring is None:
         glyph_names = self.project.all_glyphs()
     else:
         names = gstring.split(" ")
         groups = self.project.libs["groups"]["glyphs"]
         glyph_names = parse_glyphs_groups(names, groups)
     # create glyphs
     print "creating glyphs in space...\n"
     for ufo_path in self.ufos():
         ufo = RFont(ufo_path, showUI=False)
         print "\tcreating glyphs in %s..." % get_full_name(ufo)
         if verbose:
             print "\t\t",
         for glyph_name in glyph_names:
             # create glyph in font
             if ufo.has_key(glyph_name) is False:
                 if verbose:
                     print glyph_name,
                 ufo.newGlyph(glyph_name)
         # done with font
         ufo.save()
         if verbose:
             print "\n"
     # done
     print "\n...done.\n"
Ejemplo n.º 16
0
 def apply_callback(self, sender):
     ufo_paths = walk(self._ufos_folder, 'ufo')
     if len(ufo_paths) > 0:
         print 'transforming all fonts in folder...\n'
         self.w.bar.start()
         for ufo_path in ufo_paths:
             font = RFont(ufo_path, showUI=False)
             print '\ttransforming %s...' % get_full_name(font)
             if self._round:
                 print '\t\trounding points...'
                 font.round()
             if self._decompose:
                 print '\t\tdecomposing...'
                 decompose(font)
             if self._overlaps:
                 print '\t\tremoving overlaps...'
                 font.removeOverlap()
             if self._order:
                 print '\t\tauto contour order...'
                 auto_contour_order(font)
             if self._direction:
                 print '\t\tauto contour direction...'
                 auto_contour_direction(font)
             if self._extremes:
                 print '\t\tadding extreme points...'
                 add_extremes(font)
             if self._save:
                 print '\t\tsaving font...'
                 font.save()
             print '\t...done.\n'
         self.w.bar.stop()
         print '...done.\n'
     # no font open
     else:
         print 'the selected directory contains no .ufo font.\n'
Ejemplo n.º 17
0
 def scale_glyphs(self, factor, gstring=None, verbose=False):
     # get glyphs
     if gstring is None:
         glyph_names = self.project.all_glyphs()
     else:
         names = gstring.split(" ")
         groups = self.project.libs["groups"]["glyphs"]
         glyph_names = parse_glyphs_groups(names, groups)
     # scale glyphs
     print "scaling glyphs in space...\n"
     for ufo_path in self.ufos():
         ufo = RFont(ufo_path, showUI=False)
         print "\tscaling %s by %s..." % (get_full_name(ufo), factor)
         if verbose:
             print "\t\t",
         for glyph_name in glyph_names:
             if verbose:
                 print glyph_name,
             leftMargin, rightMargin = ufo[glyph_name].leftMargin, ufo[glyph_name].rightMargin
             ufo[glyph_name].scale((factor, factor))
             ufo[glyph_name].leftMargin = leftMargin * factor
             ufo[glyph_name].rightMargin = rightMargin * factor
         # done with font
         if verbose:
             print
         ufo.save()
     print "\n...done.\n"
Ejemplo n.º 18
0
 def __init__(self,):
     self.w = FloatingWindow((self._width, self._height), self._title, closable=False)
     self._all_fonts = AllFonts()
     for f in self._all_fonts:
         self._all_fonts_names.append(get_full_name(f))
     # source font
     self.w._source_label = TextBox((self._padding, self._padding_top, -self._padding, 17), "source font:")
     self.w._source_value = PopUpButton((self._padding, 35, -self._padding, 20), self._all_fonts_names)
     # mark source
     self.w.mark_source_checkbox = CheckBox((self._padding, 65, -self._padding, 20), "mark glyphs", value=True)
     self.w.mark_source_color = ColorWell(
         (120, 65, -13, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self._mark_color_source)
     )
     # dest font
     self.w._dest_label = TextBox((self._padding, 100, -self._padding, 17), "target font:")
     self.w._dest_value = PopUpButton((self._padding, 125, -self._padding, 20), self._all_fonts_names)
     # mark dest
     self.w.mark_dest_checkbox = CheckBox((self._padding, 155, -self._padding, 20), "mark glyphs", value=True)
     self.w.mark_dest_color = ColorWell(
         (120, 155, -13, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self._mark_color_dest)
     )
     self.w.line = HorizontalLine((self._padding, 200, -self._padding, 1))
     # center
     self.w.center_checkbox = CheckBox((self._padding, 215, -self._padding, 20), "center glyphs", value=False)
     self.w.line2 = HorizontalLine((self._padding, 250, -self._padding, 1))
     # buttons
     self.w.button_apply = Button(
         (self._padding, -50, self._width / 2 - 15, 0), "apply", callback=self.apply_callback
     )
     self.w.button_close = Button(
         (self._width / 2 + 5, -50, -self._padding, 0), "close", callback=self.close_callback
     )
     # open window
     self.w.open()
Ejemplo n.º 19
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'
Ejemplo n.º 20
0
 def build_accents(self, verbose=False):
     print "building accented glyphs in space...\n"
     for ufo_path in self.ufos():
         font = hFont(RFont(ufo_path, showUI=False))
         print "\tbuilding glyphs in %s..." % get_full_name(font.ufo)
         font.build_accents()
         font.ufo.save()
     print "\n...done.\n"
Ejemplo n.º 21
0
 def get_fonts(self):
     # get all fonts
     self.all_fonts = AllFonts()
     # get font names
     self.all_fonts_names = []
     if len(self.all_fonts) > 0:
         for font in self.all_fonts:
             self.all_fonts_names.append(get_full_name(font))
Ejemplo n.º 22
0
 def get_fonts(self):
     # get all fonts
     self.all_fonts = AllFonts()
     # get font names
     self.all_fonts_names = []
     if len(self.all_fonts) > 0:
         for font in self.all_fonts:
             self.all_fonts_names.append(get_full_name(font))
Ejemplo n.º 23
0
 def update_font(self):
     self.font = CurrentFont()
     if self.font is not None:
         self.w.box.text.set(get_full_name(self.font))
         self.set_defaults()
         self.restore_x()
         self.restore_y()
     else:
         print 'No font selected, please open a font and try again.\n'
Ejemplo n.º 24
0
 def update_font(self):
     self.font = CurrentFont()
     if self.font is not None:
         self.w.box.text.set(get_full_name(self.font))
         self.set_defaults()
         self.restore_x()
         self.restore_y()
     else:
         print no_font_open
Ejemplo n.º 25
0
 def apply_callback(self, sender):
     # get parameters
     _source_font = self._all_fonts[self.w._source_value.get()]
     _target_font = self._all_fonts[self.w._target_value.get()]
     # print info
     print 'copying vmetrics...\n'
     print '\tsource font: %s' % get_full_name(_source_font)
     print '\ttarget font: %s' % get_full_name(_target_font)
     # copy vmetrics
     _target_font.info.xHeight = _source_font.info.xHeight
     _target_font.info.capHeight = _source_font.info.capHeight
     _target_font.info.ascender = _source_font.info.ascender
     _target_font.info.descender = _source_font.info.descender
     _target_font.info.unitsPerEm = _source_font.info.unitsPerEm
     # done
     print
     _target_font.update()
     print '...done.\n'
 def apply_callback(self, sender):
     # get parameters
     source_font = self.all_fonts[self.w.source_value.get()]
     target_font = self.all_fonts[self.w.target_value.get()]
     # print info
     print 'copying vmetrics...\n'
     print '\tsource font: %s' % get_full_name(source_font)
     print '\ttarget font: %s' % get_full_name(target_font)
     # copy vmetrics
     target_font.info.xHeight = source_font.info.xHeight
     target_font.info.capHeight = source_font.info.capHeight
     target_font.info.ascender = source_font.info.ascender
     target_font.info.descender = source_font.info.descender
     target_font.info.unitsPerEm = source_font.info.unitsPerEm
     # done
     print
     target_font.update()
     print '...done.\n'
Ejemplo n.º 27
0
 def transfer_anchors(self, var, gstring=None, clear=True, verbose=False):
     """Transfer anchors from one variable set of fonts to another."""
     axis, src, dest_list = var
     # define source space
     for param in self.parameters.keys():
         if param == axis:
             self.parameters[param] = [src]
     self.build()
     # parse gstring
     if gstring is None:
         glyph_names = self.project.all_glyphs()
     else:
         glyph_names = self.project.parse_gstring(gstring)
     # batch copy
     print "batch transfering anchors in %s..." % self.project.name
     for src_path in self.ufos():
         font = hFont(RFont(src_path, showUI=False))
         for dest in dest_list:
             dest_parameters = font.parameters
             dest_parameters[axis] = dest
             dest_file = "%s_%s.ufo" % (font.project.name, font.name_from_parameters(separator="-"))
             dest_path = os.path.join(font.project.paths["ufos"], dest_file)
             if os.path.exists(dest_path):
                 dest_ufo = RFont(dest_path, showUI=False)
                 print
                 if clear:
                     print "\tremoving anchors in %s..." % get_full_name(dest_ufo)
                     dest_font = hFont(dest_ufo)
                     dest_font.clear_anchors(gstring)
                 print "\tcopying anchors from %s to %s..." % (get_full_name(font.ufo), get_full_name(dest_ufo))
                 if verbose:
                     print "\t\t",
                 for glyph_name in glyph_names:
                     if font.ufo.has_key(glyph_name):
                         if len(font.ufo[glyph_name].anchors) > 0:
                             if dest_ufo.has_key(glyph_name) is False:
                                 dest_ufo.newGlyph(glyph_name)
                             if verbose:
                                 print glyph_name,
                             transfer_anchors(font.ufo[glyph_name], dest_ufo[glyph_name])
                             dest_ufo.save()
                 if verbose:
                     print
     print "\n...done.\n"
Ejemplo n.º 28
0
 def __init__(self):
     if len(AllFonts()) > 0:
         # collect all fonts
         self._all_fonts = AllFonts()
         for f in self._all_fonts:
             self._all_fonts_names.append(get_full_name(f))
         self.w = FloatingWindow(
                     (self._width,
                     self._height),
                     self._title,
                     closable=True)
         # source font
         x = self._padding
         y = self._padding_top
         self.w._source_label = TextBox(
                     (x, y,
                     -self._padding,
                     self._line_height),
                     "source",
                     sizeStyle='small')
         y += self._line_height
         self.w._source_value = PopUpButton(
                     (x, y,
                     -self._padding,
                     self._line_height),
                     self._all_fonts_names,
                     sizeStyle='small')
         # target font
         y += self._line_height + self._padding_top
         self.w._target_label = TextBox(
                     (x, y,
                     -self._padding,
                     self._line_height),
                     "target",
                     sizeStyle='small')
         y += self._line_height
         self.w._target_value = PopUpButton(
                     (x, y,
                     -self._padding,
                     self._line_height),
                     self._all_fonts_names,
                     sizeStyle='small')
         # buttons
         y += self._line_height + self._padding_top + 7
         self.w.button_apply = SquareButton(
                     (x, y,
                     -self._padding,
                     self._button_height),
                     "copy",
                     sizeStyle='small',
                     callback=self.apply_callback)
         # open window
         self.w.open()
     else:
         print 'please open one or more fonts to use this dialog.\n'
Ejemplo n.º 29
0
 def __init__(self, ):
     self.w = FloatingWindow((self._width, self._height),
                             self._title,
                             closable=False)
     self._all_fonts = AllFonts()
     for f in self._all_fonts:
         self._all_fonts_names.append(get_full_name(f))
     # source font
     self.w._source_label = TextBox(
         (self._padding, self._padding_top, -self._padding, 17),
         "source font:")
     self.w._source_value = PopUpButton(
         (self._padding, 35, -self._padding, 20), self._all_fonts_names)
     # mark source
     self.w.mark_source_checkbox = CheckBox(
         (self._padding, 65, -self._padding, 20), "mark glyphs", value=True)
     self.w.mark_source_color = ColorWell(
         (120, 65, -13, 20),
         color=NSColor.colorWithCalibratedRed_green_blue_alpha_(
             *self._mark_color_source))
     # dest font
     self.w._dest_label = TextBox((self._padding, 100, -self._padding, 17),
                                  "target font:")
     self.w._dest_value = PopUpButton(
         (self._padding, 125, -self._padding, 20), self._all_fonts_names)
     # mark dest
     self.w.mark_dest_checkbox = CheckBox(
         (self._padding, 155, -self._padding, 20),
         "mark glyphs",
         value=True)
     self.w.mark_dest_color = ColorWell(
         (120, 155, -13, 20),
         color=NSColor.colorWithCalibratedRed_green_blue_alpha_(
             *self._mark_color_dest))
     self.w.line = HorizontalLine((self._padding, 200, -self._padding, 1))
     # left / right
     self.w.left_checkbox = CheckBox(
         (self._padding, 215, -self._padding, 20), "copy left", value=True)
     self.w.right_checkbox = CheckBox(
         (self._width / 2, 215, -self._padding, 20),
         "copy right",
         value=True)
     self.w.line2 = HorizontalLine((self._padding, 250, -self._padding, 1))
     # buttons
     self.w.button_apply = Button(
         (self._padding, -50, self._width / 2 - 15, 0),
         "apply",
         callback=self.apply_callback)
     self.w.button_close = Button(
         (self._width / 2 + 5, -50, -self._padding, 0),
         "close",
         callback=self.close_callback)
     # open window
     self.w.open()
Ejemplo n.º 30
0
 def apply_callback(self, sender):
     # get fonts
     f1 = self.all_fonts[self.w._f1_font.get()]
     f2 = self.all_fonts[self.w._f2_font.get()]
     f3 = self.all_fonts[self.w._f3_font.get()]
     # get factors
     x = self.factor_x
     y = self.factor_y
     # print info
     print 'interpolating glyphs...\n'
     boolstring = [False, True]
     print '\tmaster 1: %s' % get_full_name(f1)
     print '\tmaster 2: %s' % get_full_name(f2)
     print '\ttarget: %s' % get_full_name(f3)
     print
     print '\tfactor x: %s' % x
     print '\tfactor y: %s' % y
     print '\tproportional: %s' % boolstring[self.proportional]
     print
     print '\t',
     self.w.bar.start()
     # interpolate glyphs
     for glyph_name in get_glyphs(f1):
         # check glyphs
         if f2.has_key(glyph_name):
             f3.newGlyph(glyph_name, clear=True)
             # prepare undo
             f3[glyph_name].prepareUndo('interpolate')
             # interpolate
             print glyph_name,
             f3[glyph_name].interpolate((x, y), f1[glyph_name], f2[glyph_name])
             f3[glyph_name].update()
             # create undo
             f3[glyph_name].performUndo()
         else:
             print '\tfont 2 does not have glyph %s' % glyph_name
     f3.update()
     # done
     self.w.bar.stop()
     print
     print '\n...done.\n'
 def get_fonts(self):
     self.all_fonts = AllFonts()
     if len(self.all_fonts) > 0:
         self.all_fonts_names = []
         for f in self.all_fonts:
             font_name = get_full_name(f)
             self.all_fonts_names.append(font_name)
         self.w.source_value.setItems(self.all_fonts_names)
         self.w.target_value.setItems(self.all_fonts_names)
     # no font open
     else:
         print no_font_open
 def get_fonts(self):
     self.all_fonts = AllFonts()
     if len(self.all_fonts) > 0:
         self.all_fonts_names = []
         for f in self.all_fonts:
             font_name = get_full_name(f)
             self.all_fonts_names.append(font_name)
         self.w.source_value.setItems(self.all_fonts_names)
         self.w.target_value.setItems(self.all_fonts_names)
     # no font open
     else:
         print no_font_open
Ejemplo n.º 33
0
 def apply_callback(self, sender):
     if len(self.all_fonts) > 0:
         # get parameters
         source_font = self.all_fonts[self.w._source_value.get()]
         target_font = self.all_fonts[self.w._target_value.get()]
         glyph_names = get_glyphs(source_font)
         if len(glyph_names) > 0:
             # print info
             print 'copying glyphs to mask...\n'
             print '\tsource font: %s (foreground)' % get_full_name(
                 source_font)
             print '\ttarget font: %s (%s)' % (get_full_name(target_font),
                                               self.target_layer_name)
             print
             print '\t',
             # batch copy glyphs to mask
             for glyph_name in glyph_names:
                 print glyph_name,
                 # prepare undo
                 target_font[glyph_name].prepareUndo('copy glyphs to mask')
                 # copy oulines to mask
                 target_glyph_layer = target_font[glyph_name].getLayer(
                     self.target_layer_name)
                 pen = target_glyph_layer.getPointPen()
                 source_font[glyph_name].drawPoints(pen)
                 # update
                 target_font[glyph_name].update()
                 # activate undo
                 target_font[glyph_name].performUndo()
             # done
             print
             target_font.update()
             print '\n...done.\n'
         # no glyph selected
         else:
             print no_glyph_selected
     # no font open
     else:
         print no_font_open
Ejemplo n.º 34
0
 def apply_callback(self, sender):
     if len(self.all_fonts) > 0:
         # get parameters
         source_font = self.all_fonts[self.w._source_value.get()]
         target_font = self.all_fonts[self.w._target_value.get()]
         # print info
         print 'transfering anchors...\n'
         print '\tsource: %s' % get_full_name(source_font)
         print '\ttarget: %s' % get_full_name(target_font)
         print
         print '\t',
         # batch transfer anchors
         skipped = []
         for glyph_name in get_glyphs(source_font):
             if len(source_font[glyph_name].anchors) > 0:
                 if target_font.has_key(glyph_name):
                     print glyph_name,
                     # prepare undo
                     target_font[glyph_name].prepareUndo('transfer anchors')
                     # transfer anchors
                     transfer_anchors(source_font[glyph_name],
                                      target_font[glyph_name])
                     # update
                     target_font[glyph_name].update()
                     # activate undo
                     target_font[glyph_name].performUndo()
                 else:
                     skipped.append(glyph_name)
             else:
                 # glyph does not have anchors
                 pass
         # done
         print
         target_font.update()
         if len(skipped) > 0:
             print '\n\tglyphs %s not in target font.\n' % skipped
         print '...done.\n'
     else:
         print no_font_open  # 'please open at least one font.\n'
Ejemplo n.º 35
0
 def apply_callback(self, sender):
     if len(self.all_fonts) > 0:
         # get parameters
         source_font = self.all_fonts[self.w._source_value.get()]
         target_font = self.all_fonts[self.w._target_value.get()]
         # print info
         print 'transfering anchors...\n'
         print '\tsource: %s' % get_full_name(source_font)
         print '\ttarget: %s' % get_full_name(target_font)
         print
         print '\t',
         # batch transfer anchors
         skipped = []
         for glyph_name in get_glyphs(source_font):
             if len(source_font[glyph_name].anchors) > 0:
                 if target_font.has_key(glyph_name):
                     print glyph_name,
                     # prepare undo
                     target_font[glyph_name].prepareUndo('transfer anchors')
                     # transfer anchors
                     transfer_anchors(source_font[glyph_name], target_font[glyph_name])
                     # update
                     target_font[glyph_name].changed()
                     # activate undo
                     target_font[glyph_name].performUndo()
                 else:
                     skipped.append(glyph_name)
             else:
                 # glyph does not have anchors
                 pass
         # done
         print
         target_font.changed()
         if len(skipped) > 0:
             print '\n\tglyphs %s not in target font.\n' % skipped
         print '...done.\n'
     else:
         print no_font_open
Ejemplo n.º 36
0
 def apply_callback(self, sender):
     if len(self._all_fonts) > 0:
         # get parameters
         _source_font = self._all_fonts[self.w._source_value.get()]
         _target_font = self._all_fonts[self.w._target_value.get()]
         # print info
         print 'transfering anchors...\n'
         print '\tsource: %s' % get_full_name(_source_font)
         print '\ttarget: %s' % get_full_name(_target_font)
         print
         print '\t',
         # batch transfer anchors
         _skipped = []
         for glyph_name in get_glyphs(_source_font):
             if len(_source_font[glyph_name].anchors) > 0:
                 if _target_font.has_key(glyph_name):
                     print glyph_name,
                     # prepare undo
                     _target_font[glyph_name].prepareUndo('transfer anchors')
                     # transfer anchors
                     transfer_anchors(_source_font[glyph_name], _target_font[glyph_name])
                     # update
                     _target_font[glyph_name].update()
                     # activate undo
                     _target_font[glyph_name].performUndo()
                 else:
                     _skipped.append(glyph_name)
             else:
                 # glyph does not have anchors
                 pass
         # done
         print
         _target_font.update()
         if len(_skipped) > 0:
             print '\n\tglyphs %s not in target font.\n' % _skipped
         print '...done.\n'
     else:
         print 'please open at least one font.\n'
Ejemplo n.º 37
0
 def apply_callback(self, sender):
     if len(self.all_fonts) > 0:
         # get parameters
         source_font = self.all_fonts[self.w._source_value.get()]
         target_font = self.all_fonts[self.w._target_value.get()]
         glyph_names = get_glyphs(source_font)
         if len(glyph_names) > 0:
             # print info
             print 'copying glyphs to mask...\n'
             print '\tsource font: %s (%s)' % (get_full_name(source_font), self.source_layer_name)
             print '\ttarget font: %s (%s)' % (get_full_name(target_font), self.target_layer_name)
             print
             print '\t',
             # batch copy glyphs to mask
             for glyph_name in glyph_names:
                 print glyph_name,
                 # get source/target glyphs/layers
                 source_glyph = source_font[glyph_name].getLayer(self.source_layer_name)
                 target_glyph = target_font[glyph_name].getLayer(self.target_layer_name)
                 # prepare undo
                 target_glyph.prepareUndo('copy glyphs to mask')
                 # copy source to target
                 pen = target_glyph.getPen()
                 source_glyph.draw(pen)
                 # done
                 target_glyph.changed()
                 target_glyph.performUndo()
             # done
             print
             target_font.changed()
             print '\n...done.\n'
         # no glyph selected
         else:
             print no_glyph_selected
     # no font open
     else:
         print no_font_open
Ejemplo n.º 38
0
 def get_font(self):
     self.font = CurrentFont()
     if self.font is not None:
         self.w.box.font_name.set(get_full_name(self.font))
         self.w.hairspace_value.set(int(self.font.info.unitsPerEm * self.hairspace_factor))
         self.w.thickspace_value.set(int(self.font.info.unitsPerEm * self.thickspace_factor))
         self.w.thinspace_value.set(int(self.font.info.unitsPerEm * self.thinspace_factor))
         self.w.figurespace_value.set(int(self.font.info.unitsPerEm * self.figurespace_factor))
     else:
         self.w.box.font_name.set('(None)')
         self.w.hairspace_value.set('')
         self.w.thickspace_value.set('')
         self.w.thinspace_value.set('')
         self.w.figurespace_value.set('')
         print no_font_open
Ejemplo n.º 39
0
 def change_glyph_widths(self, delta, gstring=None):
     print "changing glyph widths in space...\n"
     groups = self.project.libs["groups"]["glyphs"]
     for src_path in self.ufos():
         font = hFont(RFont(src_path, showUI=False))
         if gstring is None:
             glyph_names = font.ufo.keys()
         else:
             glyph_names = parse_glyphs_groups(gstring.split(" "), groups)
         print "\tsettings widths in %s..." % get_full_name(font.ufo)
         for glyph_name in glyph_names:
             font.ufo[glyph_name].width += delta
         font.ufo.save()
     print
     print "...done.\n"
Ejemplo n.º 40
0
 def get_font(self):
     self.font = CurrentFont()
     if self.font is not None:
         self.w.box.font_name.set(get_full_name(self.font))
         self.w.hairspace_value.set(int(self.font.info.unitsPerEm * self.hairspace_factor))
         self.w.thickspace_value.set(int(self.font.info.unitsPerEm * self.thickspace_factor))
         self.w.thinspace_value.set(int(self.font.info.unitsPerEm * self.thinspace_factor))
         self.w.figurespace_value.set(int(self.font.info.unitsPerEm * self.figurespace_factor))
     else:
         self.w.box.font_name.set('(None)')
         self.w.hairspace_value.set('')
         self.w.thickspace_value.set('')
         self.w.thinspace_value.set('')
         self.w.figurespace_value.set('')
         print no_font_open
Ejemplo n.º 41
0
 def get_fonts(self):
     # get all fonts
     self.all_fonts = AllFonts()
     if len(self.all_fonts) > 0:
         # get font names
         self.all_fonts_names = []
         if len(self.all_fonts) > 0:
             for font in self.all_fonts:
                 self.all_fonts_names.append(get_full_name(font))
         self.all_fonts_names.sort()
         # update UI
         self.w.source_value.setItems(self.all_fonts_names)
         self.w.dest_value.setItems(self.all_fonts_names)
     # no font open
     else:
         print(no_font_open)
Ejemplo n.º 42
0
 def get_fonts(self):
     # get all fonts
     self.all_fonts = AllFonts()
     if len(self.all_fonts) > 0:
         # get font names
         self.all_fonts_names = []
         if len(self.all_fonts) > 0:
             for font in self.all_fonts:
                 self.all_fonts_names.append(get_full_name(font))
         self.all_fonts_names.sort()
         # update UI
         self.w.source_value.setItems(self.all_fonts_names)
         self.w.dest_value.setItems(self.all_fonts_names)
     # no font open
     else:
         print no_font_open
Ejemplo n.º 43
0
 def generate_fonts(self, options=None):
     # get options or defaults
     if options is None:
         options = {
             "decompose": True,
             "remove overlap": True,
             "autohint": False,
             "release mode": False,
             "otfs test": False,
             "woff generate": False,
             "woff upload": False,
         }
     # generate fonts
     print "generating fonts in space...\n"
     for ufo_path in self.ufos():
         ufo = RFont(ufo_path, showUI=False)
         font = hFont(ufo)
         # get otf path
         if options["otfs test"]:
             otf_path = font.otf_path(test=True)
         else:
             otf_path = font.otf_path()
         # generate otf
         print "\tgenerating %s..." % get_full_name(ufo)
         font.ufo.generate(
             otf_path,
             "otf",
             decompose=options["decompose"],
             autohint=options["autohint"],
             checkOutlines=options["remove overlap"],
             releaseMode=options["release mode"],
         )
         # generate woff
         if options["woff generate"]:
             if os.path.exists(otf_path):
                 print "\tgenerating .woff..."
                 font.generate_woff()
         # upload woff
         if options["woff upload"]:
             woff_path = font.woff_path()
             if os.path.exists(woff_path):
                 print "\tuploading .woff..."
                 font.upload_woff()
         print
     # done
     print "...done.\n"
Ejemplo n.º 44
0
 def apply_callback(self, sender):
     ufo_paths = walk(self.ufos_folder, 'ufo')
     if len(ufo_paths) > 0:
         print('transforming all fonts in folder...\n')
         self.w.bar.start()
         for ufo_path in ufo_paths:
             font = RFont(ufo_path, showUI=False)
             print('\ttransforming %s...' % get_full_name(font))
             if self.round:
                 print('\t\trounding points...')
                 font.round()
             if self.decompose:
                 print('\t\tdecomposing...')
                 decompose(font)
             if self.overlaps:
                 print('\t\tremoving overlaps...')
                 font.removeOverlap()
             if self.order:
                 print('\t\tauto contour order...')
                 auto_contour_order(font)
             if self.direction:
                 print('\t\tauto contour direction...')
                 auto_contour_direction(font)
             if self.extremes:
                 print('\t\tadding extreme points...')
                 add_extremes(font)
             if self.remove_features:
                 print('\t\tremoving all OpenType features...')
                 clear_features(font)
             if self.save:
                 print('\t\tsaving font...')
                 font.save()
             print('\t...done.\n')
         self.w.bar.stop()
         print('...done.\n')
     # no font in folder
     else:
         print(no_font_in_folder)
Ejemplo n.º 45
0
 def __init__(self):
     self._width = self._column_1 + self._field_width + (self._padding * 3)
     if CurrentFont() is not None:
         self.font = CurrentFont()
         self.w = FloatingWindow((self._width, self._height),
                                 self._title,
                                 closable=True)
         # current font
         self.w.box = Box(
             (self._padding, self._padding_top + (self._row_height * 0),
              -self._padding, 26))
         self.w.box.text = TextBox((5, 1, -10, 20),
                                   text=get_full_name(self.font),
                                   sizeStyle='small')
         # hair space
         self.w._hairspace_label = TextBox(
             (self._padding, self._padding_top +
              (self._row_height * 1) + 10, self._column_1, 20),
             "hair space")
         self.w._hairspace_value = EditText(
             (self._column_1 + (self._padding * 2), self._padding_top +
              (self._row_height * 1) + 10, self._field_width, 20),
             text=int(self.font.info.unitsPerEm * self._hairspace_factor))
         # thin space
         self.w._thinspace_label = TextBox(
             (self._padding, self._padding_top +
              (self._row_height * 2) + 10, self._column_1, 20),
             "thin space")
         self.w._thinspace_value = EditText(
             (self._column_1 + (self._padding * 2), self._padding_top +
              (self._row_height * 2) + 10, self._field_width, 20),
             text=int(self.font.info.unitsPerEm * self._thinspace_factor))
         # thick space
         self.w._thickspace_label = TextBox(
             (self._padding, self._padding_top +
              (self._row_height * 3) + 10, self._column_1, 20),
             "thick space")
         self.w._thickspace_value = EditText(
             (self._column_1 + (self._padding * 2), self._padding_top +
              (self._row_height * 3) + 10, self._field_width, 20),
             text=int(self.font.info.unitsPerEm * self._thickspace_factor))
         # figure space
         self.w._figurespace_label = TextBox(
             (self._padding, self._padding_top +
              (self._row_height * 4) + 10, self._column_1, 20),
             "figure space")
         self.w._figurespace_value = EditText(
             (self._column_1 + (self._padding * 2), self._padding_top +
              (self._row_height * 4) + 10, self._field_width, 20),
             text=int(self.font.info.unitsPerEm * self._figurespace_factor))
         # zero width space
         self.w._zerowidth_label = TextBox(
             (self._padding, self._padding_top +
              (self._row_height * 5) + 10, self._column_1, 20),
             "zero-width space")
         self.w._zerowidth_value = EditText(
             (self._column_1 + (self._padding * 2), self._padding_top +
              (self._row_height * 5) + 10, self._field_width, 20),
             text='0',
             readOnly=True)
         # division
         self.w.line_1 = HorizontalLine(
             (self._padding,
              self._padding_top + (self._row_height * 6) + 15,
              -self._padding, 1))
         # mark color
         self.w._mark_checkbox = CheckBox(
             (self._padding, self._padding_top +
              (self._row_height * 7), self._column_1, 20),
             "mark",
             value=True)
         self.w._mark_color = ColorWell(
             (self._column_1 + (self._padding * 2), self._padding_top +
              (self._row_height * 7), self._field_width, 20),
             color=NSColor.colorWithCalibratedRed_green_blue_alpha_(
                 *self._mark_color))
         # buttons
         self.w._button_apply = Button(
             (self._padding, -65, -self._padding, 20),
             "create glyphs",
             sizeStyle='small',
             callback=self.apply_callback)
         self.w._button_switch = Button(
             (self._padding, -35, -self._padding, 20),
             "switch to current font",
             sizeStyle='small',
             callback=self.update_font_callback)
         # open window
         self.w.open()
     # no font open
     else:
         print 'please open a font first.\n'
Ejemplo n.º 46
0
 def __init__(self, font):
     self.w = FloatingWindow((self._width, self._height), self._title)
     # font
     self.font = font
     self.w.box = Box((self._padding, self._padding, -self._padding, 30))
     self.w.box.text = TextBox((5, 1, -10, 20), get_full_name(font))
     # xheight
     _xheight = self.font.info.xHeight
     _xheight_min = 1
     _xheight_max = self.font.info.unitsPerEm
     self.w.xheight_label = TextBox(
         (self._padding, self._padding +
          (self._row * 1) + self._padding_top, -self._padding, 30),
         "x-height")
     self.w.xheight_slider = Slider(
         (self._column_1, self._padding + (self._row * 1) - 5 +
          self._padding_top, -(self._column_3 + (self._padding * 2)), 30),
         minValue=_xheight_min,
         maxValue=_xheight_max,
         value=_xheight,
         callback=self.xheight_slider_callback)
     self.w.xheight_text = EditText(
         (-self._column_3, self._padding +
          (self._row * 1) + self._padding_top, -self._padding, 20),
         _xheight,
         callback=self.xheight_value_callback)
     # ascender
     _ascender = self.font.info.ascender
     _ascender_min = 1
     _ascender_max = self.font.info.unitsPerEm * 1.6
     self.w.ascender_label = TextBox(
         (self._padding, self._padding +
          (self._row * 2) + self._padding_top, -self._padding, 30),
         "ascender")
     self.w.ascender_slider = Slider(
         (self._column_1, self._padding + (self._row * 2) - 5 +
          self._padding_top, -(self._column_3 + (self._padding * 2)), 30),
         minValue=_ascender_min,
         maxValue=_ascender_max,
         value=_ascender,
         callback=self.ascender_slider_callback)
     self.w.ascender_text = EditText(
         (-self._column_3, self._padding +
          (self._row * 2) + self._padding_top, -self._padding, 20),
         _ascender,
         callback=self.ascender_value_callback)
     # descender
     _descender = abs(self.font.info.descender)
     _descender_min = 1
     _descender_max = 700
     self.w.descender_label = TextBox(
         (self._padding, self._padding +
          (self._row * 3) + self._padding_top, -self._padding, 30),
         "descender")
     self.w.descender_slider = Slider(
         (self._column_1, self._padding + (self._row * 3) - 5 +
          self._padding_top, -(self._column_3 + (self._padding * 2)), 30),
         minValue=_descender_min,
         maxValue=_descender_max,
         value=_descender,
         callback=self.descender_slider_callback)
     self.w.descender_text = EditText(
         (-self._column_3, self._padding +
          (self._row * 3) + self._padding_top, -self._padding, 20),
         _descender,
         callback=self.descender_value_callback)
     # capheight
     _capheight = self.font.info.capHeight
     _capheight_min = 1
     _capheight_max = self.font.info.unitsPerEm
     self.w.capheight_label = TextBox(
         (self._padding, self._padding +
          (self._row * 4) + self._padding_top, -self._padding, 30),
         "cap-height")
     self.w.capheight_slider = Slider(
         (self._column_1, self._padding + (self._row * 4) - 5 +
          self._padding_top, -(self._column_3 + (self._padding * 2)), 30),
         minValue=_capheight_min,
         maxValue=_capheight_max,
         value=_capheight,
         callback=self.capheight_slider_callback)
     self.w.capheight_text = EditText(
         (-self._column_3, self._padding +
          (self._row * 4) + self._padding_top, -self._padding, 20),
         _capheight,
         callback=self.capheight_value_callback)
     # units per em
     _units_per_em = self.font.info.unitsPerEm
     _units_per_em_min = 10
     _units_per_em_max = self.font.info.unitsPerEm * 2
     self.w.units_per_em_label = TextBox(
         (self._padding, self._padding +
          (self._row * 5) + self._padding_top, -self._padding, 30),
         "units per em")
     self.w.units_per_em_slider = Slider(
         (self._column_1, self._padding + (self._row * 5) - 5 +
          self._padding_top, -(self._column_3 + (self._padding * 2)), 30),
         minValue=_units_per_em_min,
         maxValue=_units_per_em_max,
         value=_units_per_em,
         callback=self.units_per_em_slider_callback)
     self.w.units_per_em_text = EditText(
         (-self._column_3, self._padding +
          (self._row * 5) + self._padding_top, -self._padding, 20),
         _units_per_em,
         callback=self.units_per_em_value_callback)
     # open window
     self.w.open()
Ejemplo n.º 47
0
 def _get_fonts(self):
     self.all_fonts = {}
     for font in AllFonts():
         font_name = get_full_name(
             font)  # os.path.splitext(os.path.split(font.path)[-1])[0] #
         self.all_fonts[font_name] = font
Ejemplo n.º 48
0
 def __init__(self):
     if len(AllFonts()) > 0:
         self._all_fonts = AllFonts()
         for f in self._all_fonts:
             self._all_fonts_names.append(get_full_name(f))
         self.w = FloatingWindow((self._width, self._height),
                                 self._title,
                                 closable=False)
         # source font
         self.w._source_label = TextBox(
             (self._padding, self._padding_top +
              (self._row_height * 0), -self._padding, 17), "source font")
         self.w._source_value = PopUpButton(
             (self._padding, self._padding_top +
              (self._row_height * 1), -self._padding, 20),
             self._all_fonts_names)
         # source color
         self.w.source_mark_checkbox = CheckBox(
             (self._padding, self._padding_top +
              (self._row_height * 2) + 6, -self._padding, 20),
             "mark glyphs",
             value=True)
         self.w.source_mark_color = ColorWell(
             (self._column_1, self._padding_top +
              (self._row_height * 2) + 8, -self._padding, 20),
             color=NSColor.colorWithCalibratedRed_green_blue_alpha_(
                 *self._source_mark_color))
         # division 1
         self.w.line_1 = HorizontalLine(
             (self._padding, self._padding_top + (self._row_height * 4) - 8,
              -self._padding, 1))
         # target font
         self.w._target_label = TextBox(
             (self._padding, self._padding_top +
              (self._row_height * 4), -self._padding, 17), "target font")
         self.w._target_value = PopUpButton(
             (self._padding, self._padding_top +
              (self._row_height * 5), -self._padding, 20),
             self._all_fonts_names)
         # target color
         self.w.target_mark_checkbox = CheckBox(
             (self._padding, self._padding_top +
              (self._row_height * 6) + 6, -self._padding, 20),
             "mark glyphs",
             value=True)
         self.w.target_mark_color = ColorWell(
             (self._column_1, self._padding_top +
              (self._row_height * 6) + 8, -self._padding - 3, 20),
             color=NSColor.colorWithCalibratedRed_green_blue_alpha_(
                 *self._target_mark_color))
         # division 2
         self.w.line_2 = HorizontalLine(
             (self._padding, self._padding_top + (self._row_height * 8) - 8,
              -self._padding, 1))
         # buttons
         self.w.button_apply = Button(
             (self._padding, -45, (self._width / 2) - 15, 0),
             "apply",
             callback=self.apply_callback)
         self.w.button_close = Button(
             (self._width / 2 + 5, -45, -self._padding, 0),
             "close",
             callback=self.close_callback)
         # open window
         self.w.open()
     else:
         print 'please open one or more fonts to use this dialog.\n'
Ejemplo n.º 49
0
 def update_font_callback(self, sender):
     self.font = CurrentFont()
     self.w.box.text.set(get_full_name(self.font))
Ejemplo n.º 50
0
 def _get_fonts(self):
     self.all_fonts = AllFonts()
     if len(self.all_fonts) > 0:
         for f in self.all_fonts:
             self.all_fonts_names.append(get_full_name(f))
Ejemplo n.º 51
0
 def _get_fonts(self):
     self.all_fonts = AllFonts()
     self.all_fonts_names = []
     for font in self.all_fonts:
         self.all_fonts_names.append(get_full_name(font))
Ejemplo n.º 52
0
 def get_fonts(self):
     self.all_fonts = {}
     all_fonts = AllFonts()
     if len(all_fonts) > 0:
         for font in all_fonts:
             self.all_fonts[(get_full_name(font))] = font
Ejemplo n.º 53
0
 def _update_text_box(self):
     self.w.box_font.text.set(get_full_name(self.font))
     self.w.box_glyph.text.set(self.glyph.name)
     self.w.box_layer.text.set(self.glyph.layerName)
Ejemplo n.º 54
0
 def __init__(self):
     self.title = "vertical metrics"
     self.box_width = 60
     self.width = self.column_1 + self.column_2 + self.column_3 + (self.padding_x * 3) + (self.nudge_button * 4) + 2
     self.height = self.text_height + (self.nudge_button * 4) + (self.padding_y * 6)
     self.font = CurrentFont()
     if self.font is not None:
         self.w = FloatingWindow((self.width, self.height), self.title)
         # get font vmetrics
         units_per_em = self.font.info.unitsPerEm
         ascender = self.font.info.ascender
         capheight = self.font.info.capHeight
         xheight = self.font.info.xHeight
         descender = abs(self.font.info.descender)
         # set max vmetrics
         self.ascender_max = units_per_em
         self.capheight_max = units_per_em
         self.xheight_max = units_per_em
         self.descender_max = units_per_em
         # make button alignments
         x1 = self.padding_x
         x2 = x1 + self.column_1
         x3 = x2 + self.column_2 + 15
         x4 = x3 + self.column_3 - 1
         x5 = x4 + self.nudge_button - 1
         x6 = x5 + self.nudge_button - 1
         x7 = x6 + self.nudge_button - 1
         y = self.padding_y
         self.w.box = Box(
                     (x1, y,
                     self.column_1 + self.column_2,
                     self.text_height))
         self.w.box.text = TextBox(
                     (5, 0,
                     -self.padding_x,
                     self.text_height),
                     get_full_name(self.font),
                     sizeStyle=self.size_style)
         self.w.font_switch = SquareButton(
                     (x3, y,
                     -self.padding_x,
                     self.text_height),
                     'update',
                     sizeStyle=self.size_style,
                     callback=self.update_font_callback)
         y += self.text_height + self.padding_y
         # ascender
         self.w.ascender_label = TextBox(
                     (x1, y,
                     self.column_1,
                     self.nudge_button),
                     "ascender",
                     sizeStyle=self.size_style)
         self.w.ascender_slider = Slider(
                     (x2, y - 5,
                     self.column_2,
                     self.nudge_button),
                     minValue=self.ascender_min,
                     maxValue=self.ascender_max,
                     value=ascender,
                     callback=self.ascender_slider_callback,
                     sizeStyle=self.size_style)
         self.w.ascender_value = EditText(
                     (x3, y,
                     self.column_3,
                     self.nudge_button),
                     ascender,
                     callback=self.ascender_value_callback,
                     sizeStyle=self.size_style,
                     readOnly=self.read_only)
         self.w.ascender_minus_01 = SquareButton(
                     (x4, y,
                     self.nudge_button,
                     self.nudge_button),
                     '-',
                     sizeStyle=self.size_style,
                     callback=self.ascender_minus_01_callback)
         self.w.ascender_plus_01 = SquareButton(
                     (x5, y,
                     self.nudge_button,
                     self.nudge_button),
                     '+',
                     sizeStyle=self.size_style,
                     callback=self.ascender_plus_01_callback)
         self.w.ascender_minus_10 = SquareButton(
                     (x6, y,
                     self.nudge_button,
                     self.nudge_button),
                     '-',
                     sizeStyle=self.size_style,
                     callback=self.ascender_minus_10_callback)
         self.w.ascender_plus_10 = SquareButton(
                     (x7, y,
                     self.nudge_button,
                     self.nudge_button),
                     '+',
                     sizeStyle=self.size_style,
                     callback=self.ascender_plus_10_callback)
         y += self.nudge_button + self.padding_y
         # capheight
         self.w.capheight_label = TextBox(
                     (x1, y,
                     self.column_1,
                     self.nudge_button),
                     "cap-height",
                     sizeStyle=self.size_style)
         self.w.capheight_slider = Slider(
                     (x2, y - 5,
                     self.column_2,
                     self.nudge_button),
                     minValue=self.capheight_min,
                     maxValue=self.capheight_max,
                     value=capheight,
                     callback=self.capheight_slider_callback,
                     sizeStyle=self.size_style)
         self.w.capheight_value = EditText(
                     (x3, y,
                     self.column_3,
                     self.nudge_button),
                     capheight,
                     callback=self.capheight_value_callback,
                     sizeStyle=self.size_style,
                     readOnly=self.read_only)
         self.w.capheight_minus_01 = SquareButton(
                     (x4, y,
                     self.nudge_button,
                     self.nudge_button),
                     '-',
                     sizeStyle=self.size_style,
                     callback=self.capheight_minus_01_callback)
         self.w.capheight_plus_01 = SquareButton(
                     (x5, y,
                     self.nudge_button,
                     self.nudge_button),
                     '+',
                     sizeStyle=self.size_style,
                     callback=self.capheight_plus_01_callback)
         self.w.capheight_minus_10 = SquareButton(
                     (x6, y,
                     self.nudge_button,
                     self.nudge_button),
                     '-',
                     sizeStyle=self.size_style,
                     callback=self.capheight_minus_10_callback)
         self.w.capheight_plus_10 = SquareButton(
                     (x7, y,
                     self.nudge_button,
                     self.nudge_button),
                     '+',
                     sizeStyle=self.size_style,
                     callback=self.capheight_plus_10_callback)
         y += self.nudge_button + self.padding_y
         # xheight
         self.w.xheight_label = TextBox(
                     (x1, y,
                     self.column_1,
                     self.nudge_button),
                     "x-height",
                     sizeStyle=self.size_style)
         self.w.xheight_slider = Slider(
                     (x2, y - 5,
                     self.column_2,
                     self.nudge_button),
                     minValue=self.xheight_min,
                     maxValue=self.xheight_max,
                     value=xheight,
                     callback=self.xheight_slider_callback,
                     sizeStyle=self.size_style)
         self.w.xheight_value = EditText(
                     (x3, y,
                     self.column_3,
                     self.nudge_button),
                     xheight,
                     callback=self.xheight_value_callback,
                     sizeStyle=self.size_style,
                     readOnly=self.read_only)
         self.w.xheight_minus_01 = SquareButton(
                     (x4, y,
                     self.nudge_button,
                     self.nudge_button),
                     '-',
                     sizeStyle=self.size_style,
                     callback=self.xheight_minus_01_callback)
         self.w.xheight_plus_01 = SquareButton(
                     (x5, y,
                     self.nudge_button,
                     self.nudge_button),
                     '+',
                     sizeStyle=self.size_style,
                     callback=self.xheight_plus_01_callback)
         self.w.xheight_minus_10 = SquareButton(
                     (x6, y,
                     self.nudge_button,
                     self.nudge_button),
                     '-',
                     sizeStyle=self.size_style,
                     callback=self.xheight_minus_10_callback)
         self.w.xheight_plus_10 = SquareButton(
                     (x7, y,
                     self.nudge_button,
                     self.nudge_button),
                     '+',
                     sizeStyle=self.size_style,
                     callback=self.xheight_plus_10_callback)
         y += self.nudge_button + self.padding_y
         # descender
         self.w.descender_label = TextBox(
                     (x1, y,
                     self.column_1,
                     self.nudge_button),
                     "descender",
                     sizeStyle=self.size_style)
         self.w.descender_slider = Slider(
                     (x2, y - 5,
                     self.column_2,
                     self.nudge_button),
                     minValue=self.descender_min,
                     maxValue=self.descender_max,
                     value=descender,
                     callback=self.descender_slider_callback,
                     sizeStyle=self.size_style)
         self.w.descender_value = EditText(
                     (x3, y,
                     self.column_3,
                     self.nudge_button),
                     descender,
                     callback=self.descender_value_callback,
                     sizeStyle=self.size_style,
                     readOnly=self.read_only)
         self.w.descender_minus_01 = SquareButton(
                     (x4, y,
                     self.nudge_button,
                     self.nudge_button),
                     '-',
                     sizeStyle=self.size_style,
                     callback=self.descender_minus_01_callback)
         self.w.descender_plus_01 = SquareButton(
                     (x5, y,
                     self.nudge_button,
                     self.nudge_button),
                     '+',
                     sizeStyle=self.size_style,
                     callback=self.descender_plus_01_callback)
         self.w.descender_minus_10 = SquareButton(
                     (x6, y,
                     self.nudge_button,
                     self.nudge_button),
                     '-',
                     sizeStyle=self.size_style,
                     callback=self.descender_minus_10_callback)
         self.w.descender_plus_10 = SquareButton(
                     (x7, y,
                     self.nudge_button,
                     self.nudge_button),
                     '+',
                     sizeStyle=self.size_style,
                     callback=self.descender_plus_10_callback)
         # open window
         self.w.open()
     else:
         print(no_font_open)