ufuehrmann
Sr. Member
  
Karma: +0/-0
Posts: 7
|
 |
« on: 2009-04-22, 13:15:08 » |
|
Hi all,
Does anybody know if it is possible to fill in the additonal OpenType tables via a Python Script?
Tia and best regards,
Uwe
|
|
|
|
|
Logged
|
|
|
|
ufuehrmann
Sr. Member
  
Karma: +0/-0
Posts: 7
|
 |
« Reply #1 on: 2009-04-22, 13:55:41 » |
|
Solution found (sometimes one is routine blinded): "NameRecords" provides all tools for filling out the table!
|
|
|
|
|
Logged
|
|
|
|
ufuehrmann
Sr. Member
  
Karma: +0/-0
Posts: 7
|
 |
« Reply #2 on: 2009-05-05, 09:33:08 » |
|
But it does not work as described! Any idea or advice? This the code I'm using (FL5, WinXP):
font = fl.font if font == None: print "No font opened!" exit NameRecord() #create an empty record NameRecord("Test") #create default-language record with Test as name value fl.UpdateFont(fl.ifont)
NO changes in the tables. Tanks in advance
Uwe
|
|
|
|
« Last Edit: 2009-05-07, 05:08:59 by ufuehrmann »
|
Logged
|
|
|
|
Eigi
Beta: FontLab Studio Mac
Hero Member
 
Karma: +7/-0
 Germany
Posts: 55
|
 |
« Reply #3 on: 2009-05-11, 12:51:53 » |
|
Hello, this should work: nid = 1 # Font Family name pid = 3 # Windows eid = 1 # Unicode lid = 0 # English name = 'Myfamily' rec = NameRecord(nid, pid, eid, lid, name) fl.font.fontnames.clean() fl.font.fontnames.append(rec) fl.UpdateFont(fl.ifont)
Regards Eigi
|
|
|
|
|
Logged
|
|
|
|
ufuehrmann
Sr. Member
  
Karma: +0/-0
Posts: 7
|
 |
« Reply #4 on: 2009-05-12, 07:39:30 » |
|
Hi Eigi, Many thanks, it works!. Where did you find the method .clean()? It is not mentioned in API Reference.
Best regards,
Uwe
|
|
|
|
|
Logged
|
|
|
|
Eigi
Beta: FontLab Studio Mac
Hero Member
 
Karma: +7/-0
 Germany
Posts: 55
|
 |
« Reply #5 on: 2009-05-12, 13:01:17 » |
|
Hello Uwe, The dir() command helps to discover such things: print dir(fl.font.fontnames)
lists the available methods for the fontnames attribute: ['append', 'clean', 'insert'] Eigi
|
|
|
|
|
Logged
|
|
|
|
|
jingle33
Guest
|
 |
« Reply #6 on: 2009-08-21, 04:30:17 » |
|
Howdy. I am a Newbie.just stopped to say hello!Are you guys rocking? good keep it up. 
|
|
|
|
|
Logged
|
|
|
|
Arno Enslin
Hero Member
   
Karma: +8/-0
 Germany
Posts: 98
|
 |
« Reply #7 on: 2010-11-11, 02:32:04 » |
|
Hello, this should work: nid = 1 # Font Family name pid = 3 # Windows eid = 1 # Unicode lid = 0 # English name = 'Myfamily' rec = NameRecord(nid, pid, eid, lid, name) fl.font.fontnames.clean() fl.font.fontnames.append(rec) fl.UpdateFont(fl.ifont)
Regards Eigi Is it also possible to clean one namerecord, defined by nid, pid eid and lid (but not name) only? I want to replace one namerecord by another. fl.font.fontnames.clean(rec) does not work. More to the point, it also cleans all namerecords.
|
|
|
|
|
Logged
|
|
|
|
Eigi
Beta: FontLab Studio Mac
Hero Member
 
Karma: +7/-0
 Germany
Posts: 55
|
 |
« Reply #8 on: 2010-11-11, 04:24:52 » |
|
Hello, you can remove name records by index: assert isinstance(index, int) del fl.font.fontnames[index] Eigi
|
|
|
|
|
Logged
|
|
|
|
Arno Enslin
Hero Member
   
Karma: +8/-0
 Germany
Posts: 98
|
 |
« Reply #9 on: 2010-11-11, 05:34:19 » |
|
@ Eigi assert isinstance(index, int) del fl.font.fontnames[index] Would you give me an example, please? I don’t know, what I have to insert there. Or better, because otherwise I always have to ask those beginner questions again: If I know almost nothing about programming and Python, how can I make out, what the code, that you have posted, means? I would like to get orientation in this, but I don’t know, where to start and where to look up. It is easier for me, if I have a concrete example, which I can try to comprehend, than making an example from abstract code. Can you recommend a German book about Python for a person, who primary wants to use Python in FontLab? I mean, I am better motivated, if I can program something, that is useful for me. I don’t know why, but it was much easier to find an entrance in HTML and CSS. My problem is not the missing talent for logical thinking, but finding a practice orientated learning strategy. (The best would be a book about FontLab related Python scripts, but probably there is not a market for such a book.)
|
|
|
|
|
Logged
|
|
|
|
Eigi
Beta: FontLab Studio Mac
Hero Member
 
Karma: +7/-0
 Germany
Posts: 55
|
 |
« Reply #10 on: 2010-11-11, 06:50:44 » |
|
Hello, Let's say you want to remove all License Info URL records (name ID = 14) from the name table: # start from the end to avoid change of indexes # of remaining name records for index in reversed(range(len(fl.font.fontnames))): if fl.font.fontnames[index].nid == 14: del fl.font.fontnames[index] does this help?
|
|
|
|
« Last Edit: 2010-11-11, 09:49:04 by Eigi »
|
Logged
|
|
|
|
Arno Enslin
Hero Member
   
Karma: +8/-0
 Germany
Posts: 98
|
 |
« Reply #11 on: 2010-11-11, 12:29:11 » |
|
Hello, Let's say you want to remove all License Info URL records (name ID = 14) from the name table: # start from the end to avoid change of indexes # of remaining name records for index in reversed(range(len(fl.font.fontnames))): if fl.font.fontnames[index].nid == 14: del fl.font.fontnames[index] does this help? I get the following error: (Python)
Traceback (most recent call last): File "<string>", line 1, in ? NameError: name 'reversed' is not defined Probably because I am using Python 2.3 and reversed was introduced in version 2.4, as far as I was able to make out. And without reversed … for index in range(len(fl.font.fontnames)): if fl.font.fontnames[index].nid == 14: del fl.font.fontnames[index] … I get the following error, if there are name IDs greater than 14: (Python)
Traceback (most recent call last): File "<string>", line 2, in ? IndexError: List index is out of range But … # start from the end to avoid change of indexes # of remaining name records … in my test the index of the nid greater than 14 was not changed. So I am not sure, what the comment means.
|
|
|
|
« Last Edit: 2010-11-11, 12:31:49 by Arno Enslin »
|
Logged
|
|
|
|
Eigi
Beta: FontLab Studio Mac
Hero Member
 
Karma: +7/-0
 Germany
Posts: 55
|
 |
« Reply #12 on: 2010-11-11, 14:31:51 » |
|
Hello, Yes - reversed() was indrouced in Python 2.4. If you use a older version you get a name Error. The range() function creates a list of integers, one number for each name record. If you iterate over this list and delete one of the name records, the list of name records becomes shorter than the list you are iterating over - and you get an index Error. To avoid this in py2.3 you can do someting like this: indexList = range(len(fl.font.fontnames)): # start from the end to avoid change of indexes # of remaining name records indexList.reverse() for index in indexList: if fl.font.fontnames[index].nid == 14: del fl.font.fontnames[index]
E
|
|
|
|
|
Logged
|
|
|
|
Arno Enslin
Hero Member
   
Karma: +8/-0
 Germany
Posts: 98
|
 |
« Reply #13 on: 2010-11-11, 15:26:11 » |
|
That works fine, Eigi. But how can I solve this more elegant?: indexList = range(len(fl.font.fontnames)) # start from the end to avoid change of indexes # of remaining name records indexList.reverse() for index in indexList: if fl.font.fontnames[index].nid == 1: if fl.font.fontnames[index].pid == 3: if fl.font.fontnames[index].eid == 1: if fl.font.fontnames[index].lid == 0: if fl.font.fontnames[index].name == 'Myfamily': del fl.font.fontnames[index]
|
|
|
|
« Last Edit: 2010-11-11, 18:26:38 by Arno Enslin »
|
Logged
|
|
|
|
Eigi
Beta: FontLab Studio Mac
Hero Member
 
Karma: +7/-0
 Germany
Posts: 55
|
 |
« Reply #14 on: 2010-11-11, 17:41:42 » |
|
This is not much better: indexList = range(len(fl.font.fontnames) -1, -1, -1): for index in indexList: r = fl.font.fontnames[index] if r.nid == 1 and r.pid == 3 and r.eid == 1 and r.lid == 0 and r.name == 'Myfamily': del fl.font.fontnames[index]
|
|
|
|
|
Logged
|
|
|
|
|