def copy_glyphs(self, src_glyphs, dst_glyphs, parameters=None): # build space if parameters is not None: self.parameters = parameters self.build() # get glyphs groups = self.project.libs["groups"]["glyphs"] src_glyph_names = parse_glyphs_groups(src_glyphs.split(" "), groups) dst_glyph_names = parse_glyphs_groups(dst_glyphs.split(" "), groups) # batch copy glyphs print "batch copying glyphs in %s...\n" % self.project.name for font_path in self.ufos(): font = hFont(RFont(font_path, showUI=False)) print "\tcopying glyphs in font %s" % font.full_name() for i in range(len(src_glyph_names)): _src_glyph_name = src_glyph_names[i] _dst_glyph_name = dst_glyph_names[i] # copy glyph if font.ufo.has_key(_src_glyph_name): print "\t\tcopying %s to %s..." % (_src_glyph_name, _dst_glyph_name) if not font.ufo.has_key(_dst_glyph_name): font.ufo.newGlyph(_dst_glyph_name) font.ufo.insertGlyph(font.ufo[_src_glyph_name], name=_dst_glyph_name) font.ufo.save() # print '\t...done.' print # done print "...done.\n"
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"
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"
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"
def shift_y(self, dest_height, gstring, transformations, verbose=True): print "batch y-shifting glyphs in hSpace...\n" # get glyphs names = gstring.split(" ") groups = self.project.libs["groups"]["glyphs"] glyph_names = parse_glyphs_groups(names, groups) # get base height source_width = str(self.parameters["height"][0]) # batch shift glyphs in fonts for src_path in self.ufos(): font = hFont(RFont(src_path, showUI=False)) # get dest font dest_parameters = font.parameters dest_parameters["height"] = dest_height dest_file = "%s_%s.ufo" % (font.project.name, font.name_from_parameters(separator="-")) dest_path = os.path.join(font.project.paths["ufos"], dest_file) # transform font if os.path.exists(dest_path): dest_font = RFont(dest_path, showUI=False) print "\ty-shifting glyphs from %s to %s...\n" % (get_full_name(font.ufo), get_full_name(dest_font)) if verbose: print "\t\t", for glyph_name in glyph_names: if font.ufo.has_key(glyph_name): if dest_font.has_key(glyph_name) is False: dest_font.newGlyph(glyph_name) if verbose: print glyph_name, # insert glyph dest_font.insertGlyph(font.ufo[glyph_name]) # shift points for t in transformations: pos, delta, side = t deselect_points(dest_font[glyph_name]) select_points_y(dest_font[glyph_name], pos, side=side) shift_selected_points_y(dest_font[glyph_name], delta) deselect_points(dest_font[glyph_name]) # save dest_font.save() if verbose: print print "...done.\n"
def move_glyphs(self, delta, 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) # move glyphs print 'moving glyphs in space...' print for ufo_path in self.ufos(): ufo = RFont(ufo_path, showUI=False) print '\tmoving glyphs in %s by %s...' % (get_full_name(ufo), delta) if verbose: print '\t\t', for glyph_name in glyph_names: if verbose: print glyph_name, ufo[glyph_name].move(delta) # done with font ufo.save() print print '...done.\n'
def shift_x(self, dest_width, gstring, pos, delta, side, verbose=True): print 'batch x-shifting glyphs in hSpace...\n' # get glyphs names = gstring.split(' ') groups = self.project.libs['groups']['glyphs'] glyph_names = parse_glyphs_groups(names, groups) # get base width source_width = str(self.parameters['width'][0]) # batch shift glyphs in fonts for src_path in self.ufos(): font = hFont(RFont(src_path, showUI=False)) # get dest font dest_parameters = font.parameters dest_parameters['width'] = dest_width dest_file = '%s_%s.ufo' % (font.project.name, font.name_from_parameters(separator='-')) dest_path = os.path.join(font.project.paths['ufos'], dest_file) # transform font if os.path.exists(dest_path): dest_font = RFont(dest_path, showUI=False) print "\tx-shifting glyphs from %s to %s...\n" % (get_full_name(font.ufo), get_full_name(dest_font)) if verbose: print '\t\t', for glyph_name in glyph_names: if font.ufo.has_key(glyph_name): if dest_font.has_key(glyph_name) is False: dest_font.newGlyph(glyph_name) if verbose: print glyph_name, # insert glyph dest_font.insertGlyph(font.ufo[glyph_name]) # shift points deselect_points(dest_font[glyph_name]) select_points_x(dest_font[glyph_name], pos, side=side) shift_selected_points_x(dest_font[glyph_name], delta) deselect_points(dest_font[glyph_name]) # increase width dest_font[glyph_name].width += delta # done dest_font.save() if verbose: print print '...done.\n'
def transfer_glyphs(self, gstring, var, verbose=False): axis, src, dest_list = var # define source space for param in self.parameters.keys(): if param == axis: self.parameters[param] = [ src ] self.build() # get glyphs names = gstring.split(' ') groups = self.project.libs['groups']['glyphs'] glyph_names = parse_glyphs_groups(names, groups) # batch copy print "batch transfering glyphs 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 print "\tcopying glyphs 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 dest_ufo.has_key(glyph_name) is False: dest_ufo.newGlyph(glyph_name) # decompose first if len(font.ufo[glyph_name].components) > 0: font.ufo[glyph_name].decompose() if verbose: print glyph_name, # insert glyph dest_ufo.insertGlyph(font.ufo[glyph_name]) dest_ufo.save() if verbose: print print '\n...done.\n'
def transfer_glyphs(self, var, gstring, verbose=False): """Batch transfer glyphs from one set of fonts to another. ``gstring`` A string of glyph names and/or group names. ``var`` A tuple expressing the variable space for the transfer operation. The variation tuple must contain three items, representing in this order: :: (axis, source, (dest1, dest2, dest3)) 1. the name of the variation axis (the parameter) 2. the source value in this axis (from where the glyphs will be copied from) 3. a tuple with one or more destinations for the glyphs ``verbose`` A boolean to print/supress messages during execution. :: # set parameters project_name = 'Publica' gstring = '@lowercase' var = ( 'style', 'Sans', ( 'Slab', 'Serif', ) ) parameters = { 'weight' : [ 1, 5, 9 ], 'width' : [ 5 ], var[0] : [ var[1] ], } # run script s = hSpace(project_name) s.set_parameters(parameters) s.transfer_glyphs(gstring, var, verbose=False) """ axis, src, dest_list = var # define source space for param in self.parameters.keys(): if param == axis: self.parameters[param] = [src] self.build() # get glyphs names = gstring.split(" ") groups = self.project.libs["groups"]["glyphs"] glyph_names = parse_glyphs_groups(names, groups) # batch copy print "batch transfering glyphs 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 print "\tcopying glyphs 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 dest_ufo.has_key(glyph_name) is False: dest_ufo.newGlyph(glyph_name) # decompose first if len(font.ufo[glyph_name].components) > 0: font.ufo[glyph_name].decompose() if verbose: print glyph_name, # insert glyph dest_ufo.insertGlyph(font.ufo[glyph_name]) dest_ufo.save() if verbose: print print "\n...done.\n"
def parse_gstring(self, gstring): names = gstring.split(' ') glyph_names = parse_glyphs_groups(names, self.libs['groups']['glyphs']) return glyph_names
def parse_gstring(self, gstring): names = gstring.split(" ") glyph_names = parse_glyphs_groups(names, self.libs["groups"]["glyphs"]) return glyph_names