Beispiel #1
0
 def generate_instance(self, instance_name, verbose=False, folder=None):
     """Generate a ``.ufo`` instance with name ``instance_name``, using data from the project's interpol lib."""
     _masters = self.masters()
     if self.libs["interpol"].has_key(instance_name):
         # get instance info
         master_1, master_2, interpol_factor = self.libs["interpol"][instance_name]
         # make file names
         master_1_filename = "%s_%s.ufo" % (self.name, master_1)
         master_2_filename = "%s_%s.ufo" % (self.name, master_2)
         # master masters
         master_1_path = os.path.join(self.paths["ufos"], master_1_filename)
         master_2_path = os.path.join(self.paths["ufos"], master_2_filename)
         # instance masters
         if master_1_path not in _masters:
             master_1_path = os.path.join(self.paths["instances"], master_1_filename)
         if master_2_path not in _masters:
             master_2_path = os.path.join(self.paths["instances"], master_2_filename)
         # generate instance
         if os.path.exists(master_1_path) and os.path.exists(master_2_path):
             if verbose:
                 print "generating %s %s (factor: %s, %s)..." % (
                     self.name,
                     instance_name,
                     interpol_factor[0],
                     interpol_factor[1],
                 ),
             instance_filename = "%s_%s.ufo" % (self.name, instance_name)
             if folder is None:
                 instance_path = os.path.join(self.paths["instances"], instance_filename)
             else:
                 instance_path = os.path.join(folder, instance_filename)
             # open/create fonts
             f1 = RFont(master_1_path, showUI=False)
             f2 = RFont(master_2_path, showUI=False)
             f3 = NewFont(showUI=False)
             # interpolate
             f3.interpolate((interpol_factor[0], interpol_factor[1]), f1, f2)
             f3.update()
             f1.close()
             f2.close()
             f3.save(instance_path)
             f3.close()
             if verbose:
                 print "done.\n"
     # instance not in lib
     else:
         if verbose:
             print "%s is not an instance.\n" % instance_name
Beispiel #2
0
 def generate_instance(self, instance_name, verbose=False, folder=None):
     '''Generate a .ufo instance with name `instance_name`, using data from the project's interpol lib.'''
     if self.libs['interpol'].has_key(instance_name):
         # master 1
         master_1 = self.libs['interpol'][instance_name][0]
         master_1_filename = '%s_%s.ufo' % (self.name, master_1)
         master_1_path = os.path.join(self.paths['ufos'], master_1_filename)
         # master 2
         master_2 = self.libs['interpol'][instance_name][1]
         master_2_filename = '%s_%s.ufo' % (self.name, master_2)
         master_2_path = os.path.join(self.paths['ufos'], master_2_filename)
         # interpolation factor
         interpol_factor = self.libs['interpol'][instance_name][2]
         # if both masters exist, generate instance
         if os.path.exists(master_1_path) and os.path.exists(master_2_path):
             if verbose:
                 print 'generating %s %s (factor: %s, %s)...' % (self.name, instance_name,
                         interpol_factor[0], interpol_factor[1]),
             instance_filename = '%s_%s.ufo' % (self.name, instance_name)
             if folder is None:
                 instance_path = os.path.join(self.paths['instances'], instance_filename)
             else:
                 instance_path = os.path.join(folder, instance_filename)
             # open/create fonts
             f1 = RFont(master_1_path, showUI=False)
             f2 = RFont(master_2_path, showUI=False)
             f3 = NewFont(showUI=False)
             # interpolate
             f3.interpolate((interpol_factor[0], interpol_factor[1]), f2, f1)
             f3.update()
             f1.close()
             f2.close()
             f3.save(instance_path)
             f3.close()
             if verbose:
                 print 'done.\n'
     # instance not in lib
     else:
         if verbose:
             print '%s is not an instance.\n' % instance_name