示例#1
0
 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"
示例#2
0
 def set_vmetrics(self):
     print "setting vertical metrics in space..."
     print
     for ufo_path in self.ufos():
         ufo = RFont(ufo_path, showUI=False)
         font = hFont(ufo)
         # get vmetrics data
         if font.parameters.has_key("size"):
             size = font.parameters["size"]
         else:
             size = font.parameters["height"]
         vmetrics = self.project.libs["project"]["vmetrics"][str(size)]
         _gridsize = self.project.libs["project"]["grid"]
         # clear vmetrics
         clear_opentype_os2(font.ufo)
         clear_opentype_hhea(font.ufo)
         clear_opentype_vhea(font.ufo)
         # set vmetrics
         print "\tsetting vmetrics in %s..." % font.full_name()
         set_vmetrics(
             font.ufo,
             vmetrics["xheight"],
             vmetrics["capheight"],
             vmetrics["ascender"],
             vmetrics["descender"],
             int(size),
             gridsize=_gridsize,
         )
         font.ufo.save()
         # print_generic_dimension(font.ufo)
     print "\n...done.\n"
示例#3
0
 def remove_overlap(self):
     print "removing overlaps in fonts...\n"
     for ufo_path in self.ufos():
         ufo = RFont(ufo_path, showUI=False)
         font = hFont(ufo)
         font.remove_overlap()
         font.ufo.save()
     print "\n...done.\n"
示例#4
0
 def decompose(self):
     print "decomposing fonts...\n"
     for ufo_path in self.ufos():
         ufo = RFont(ufo_path, showUI=False)
         font = hFont(ufo)
         print "\tdecomposing glyphs in %s..." % font.full_name()
         font.decompose()
         font.ufo.save()
     print "\n...done.\n"
示例#5
0
 def round_to_grid(self, gridsize, gstring=None):
     print "rounding points and widths to grid...\n"
     for ufo_path in self.ufos():
         ufo = RFont(ufo_path, showUI=False)
         font = hFont(ufo)
         print "\trounding points and widths in %s..." % font.full_name()
         font.round_to_grid(gridsize, gstring)
         font.ufo.save()
     print "\n...done.\n"
示例#6
0
 def set_info(self):
     print "setting font info in space...\n"
     for ufo_path in self.ufos():
         ufo = RFont(ufo_path, showUI=False)
         font = hFont(ufo)
         font.set_info()
         print "\tsetting font info for %s..." % font.full_name()
         font.ufo.save()
     print "\n...done.\n"
示例#7
0
 def build_accents(self, verbose=False):
     """Build all accents in all fonts in space."""
     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"
示例#8
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"
示例#9
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"
示例#10
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"
示例#11
0
 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"
示例#12
0
    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"
示例#13
0
 def clear_anchors(self):
     """Remove anchors in all fonts in space."""
     print "deleting all anchors in space..."
     for ufo_path in self.ufos():
         font = hFont(RFont(ufo_path, showUI=False))
         font.clear_anchors()