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 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"