FontLab Forum
2012-05-23, 23:46:40 *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to the FontLab forum, read how to use it! Update: Archives from old MSN forums are now available on our forum.
 
   Home   Help Search Calendar Downloads Tags Login Register  
Del.icio.us Digg FURL FaceBook Stumble Upon Reddit SlashDot

Pages: [1]
  Print  
Author Topic: Creating an Encoding to sort font by  (Read 828 times)
Jens
Beta: FontLab Studio Mac
Hero Member
***

Karma: +0/-0
Germany Germany

Posts: 24


WWW
« on: 2012-02-05, 16:03:53 »

I'm trying to write a macro that will sort the glyphs of a font. Is there any way to do that without creating an encoding file on disk first?

This works:

Code:
from jkFontTools import sortedGlyphListFromFont
encodingPath = r".../sortEncoding.enc"
myGlyphOrder = sortedGlyphListFromFont(fl.font)
f = open(encodingPath, "w")
f.write("%%FONTLAB ENCODING: 3001976; Temp. Sort Encoding\n")
for i in range(len(myGlyphOrder)):
f.write(myGlyphOrder[i].name+"\n")
f.close()

fl.font.encoding.Load(encodingPath)
fl.CallCommand(fl_cmd.FontModeNames)
fl.CallCommand(fl_cmd.FontSortByCodepage)
fl.UpdateFont()

But I'm trying to do something like this ...

Code:
from jkFontTools import sortedGlyphListFromFont
myGlyphOrder = sortedGlyphListFromFont(fl.font)

e = Encoding()
for i in range(len(myGlyphOrder)):
er = EncodingRecord()
er.name = myGlyphOrder[i].name
e.append(er)

fl.font.encoding = e
fl.CallCommand(fl_cmd.FontModeNames)
fl.CallCommand(fl_cmd.FontSortByCodepage)
fl.UpdateFont()

... which doesn't work because fl.font.encoding is read-only.
Logged
malcolm
Hero Member
*****

Karma: +0/-0
Posts: 29


Email
« Reply #1 on: 2012-02-16, 21:41:52 »

You could try duplicating all the glyphs and appending them into the font in the correct order, giving them a unique identifier (say 'N.' prefix). Then delete the existing glyphs and rename by removing the prefix.
You may need to handle composites as well.
Logged
Tags:
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!