Export .enc files as .txt?

Max Phillips
Max Phillips Posts: 474
edited August 2012 in Technique and Theory
Is it possible to export the encoding file of a particular vfb as a separate text file, and not as part of a generated font? (I did try to RTFM, by the way, but couldn't find what I needed.) Can you do this in FL, or does it require some other utility? I'd like to capture the glyph complement of a family I'm working on and edit the encoding to put the glyphs in a more sensible order.

Comments

  • James Puckett
    James Puckett Posts: 1,993
    Select all the glyphs and hit copy. Then paste into a text editor, which will dump all the names with slashes in front of them. Then find/replace all of the slashes with line breaks in Indesign, Textwrangler, etc. After that add a header and you’re done.
  • Dude! Now that's what I call cutting the Gordian Knot. Thanks, James.

    The glyphs won't be numbered, of course. Is it necessary to add a glyph number after each glyph name, as I've seen done? It does make it cumbersome to change the order of the glyphs, since you've then got to redo the numbering as well.
  • Matthew Butterick
    Matthew Butterick Posts: 143
    edited August 2012
    This Robofab script will save an encoding file to the Mac desktop in with the glyphname and index on each line. Robofab doesn't deal with encodings directly so you have to access the FL encoding object directly, which is called font.naked().encoding. The encoding object is an iterable list of records that have fields called name and unicode.
    import os, robofab.world
    
    font = robofab.world.CurrentFont()
    
    encoding_out = []
    for index, encodingRecord in enumerate(font.naked().encoding):
        encoding_out.append("%s %s" % (encodingRecord.name, index))
    encoding_out = "\n".join(encoding_out)
    
    path = os.path.join(os.path.expanduser("~"), "Desktop", "encoding_out.enc")
    file_object = open(path, 'w') 
    file_object.write(encoding_out) 
    file_object.close()
  • You can also press the little button in FontLab called "Save Encoding".
  • The user and all related content has been deleted.
  • Thanks, Matthew!
  • The user and all related content has been deleted.
  • BTW you can import an encoding like this, where path is the path to the encoding on disk.
    font = robofab.world.CurrentFont()
    font.naked().encoding.Load(path)
    font.update()
    Yes, a script is overkill for one font. But I find that Fontlab has a habit of "forgetting" the encoding at inopportune times. So I build this into other scripts that do things that rely on the encoding (e.g., generate a font).
  • @ James M: How do you rearrange glyphs in Index mode? I've never been able to manage it. And where is Save the Encoding File? Or, as Göran calls it, the little button?

  • Mark Simonson
    Mark Simonson Posts: 1,734
    In Index mode, you can drag the glyphs around and rearrange them. Once you have an ordering you like, choose Glyph > Glyph Names > Save Encoding. (This is only available in Index mode.)
  • Mark Simonson
    Mark Simonson Posts: 1,734
    By the way, if you want to start with a particular existing encoding before you start rearranging glyphs, switch to Names mode, select the encoding, then choose Glyph > Sort Glyphs > By Encoding. When you go to Index mode, the glyphs will be arranged in this order.
  • The user and all related content has been deleted.
  • The "little button" is here:

    image

    After that you can open up the encoding end edit it, rename to something you like.
  • OK, I was grabbing the glyphs wrong, clicking the on cell instead of the cell header. That's why they didn't move. Now everything's lovely.

    Thanks, Göran, Mark, and James.
  • Mark Simonson
    Mark Simonson Posts: 1,734
    edited August 2012
    Oh, that button. I was wondering what you meant. I normally have my font windows with the tool bar at the bottom, which provides a slightly wider range of functions and takes up less space. The "save encoding" button is absent with that option.