FontLab Forum
2012-02-08, 20:15:20 *
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] 2
  Print  
Author Topic: Additional OpenType names  (Read 8163 times)
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 Germany

Posts: 55



WWW
« Reply #3 on: 2009-05-11, 12:51:53 »

Hello,

this should work:

Code:
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 Germany

Posts: 55



WWW
« Reply #5 on: 2009-05-12, 13:01:17 »

Hello Uwe,

The dir() command helps to discover such things:

Code:
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.
 Wink
Logged
Arno Enslin
Hero Member
*****

Karma: +8/-0
Germany Germany

Posts: 98



« Reply #7 on: 2010-11-11, 02:32:04 »

Hello,

this should work:

Code:
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.

Code:
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 Germany

Posts: 55



WWW
« Reply #8 on: 2010-11-11, 04:24:52 »

Hello,

you can remove name records by index:
Code:
assert isinstance(index, int)
del fl.font.fontnames[index]

Eigi
Logged
Arno Enslin
Hero Member
*****

Karma: +8/-0
Germany Germany

Posts: 98



« Reply #9 on: 2010-11-11, 05:34:19 »

@ Eigi

Quote
Code:
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 Germany

Posts: 55



WWW
« 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:
Code:
# 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 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:
Code:
# 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:

Quote
(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 …

Code:
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:
Quote
(Python)

Traceback (most recent call last):
  File "<string>", line 2, in ?
IndexError: List index is out of range

But …

Quote
# 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 Germany

Posts: 55



WWW
« 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:
Code:
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 Germany

Posts: 98



« Reply #13 on: 2010-11-11, 15:26:11 »

That works fine, Eigi.

But how can I solve this more elegant?:

Code:
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 Germany

Posts: 55



WWW
« Reply #14 on: 2010-11-11, 17:41:42 »

This is not much better:
Code:
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
Tags: FontLab 
Pages: [1] 2
  Print  
 
Jump to:  

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