New to Typophile? Accounts are free, and easy to set up.
I've reached the exaspiration point so I'm hoping someone can weigh in on this for me.
I have a python script that dumps out all the character names and unicodes but I'm getting an error using the isdigit() command.
I couldn't get the indents I have in the code to show here so I've used backslashes for each indent.
This smaller script works fine, in the line "unistr = str(f.glyphs[1].unicode)" if I change the "1" to a "0" I get the correct result:
#FLM: Testing Macro
f = fl.font
gcount = len(f)
unistr = str(f.glyphs[1].unicode)
isnumeric=unistr.isdigit()
if isnumeric:
-print "It is!"
else:
-print "It isn't!"
However, doing nearly the same darn thing I'm getting an invalid syntax error. I'm at a loss.
Many thanks,
Ken
#FLM: Writes marked glyph unicode numbers and names to a file
f = fl.font
fname=f.font_name
finame=str("C:\Program Files\FontLab\Studio5\Macros\UnicodeAndNamesMarked_") + fname + str(".txt")
TheFile = open(finame, "w")
TheFile.write(f.family_name + " marked glyphs" + chr(10))
if f != None:
-gcount = len(f)
-for i in range(gcount):
--if f.glyphs[i].mark:
---unistr = str(f.glyphs[i].unicode)
---isnumeric=unistr.isdigit()
---if isnumeric:
----TheFile.write(hex(unistr) + chr(9) + f.glyphs[i].name + chr(10))
---else:
----TheFile.write(unistr + chr(9) + f.glyphs[i].name + chr(10))
else:
-print "There are no fonts opened"
TheFile.close()
print "Filename: " + finame
28 Aug 2011 — 9:14am
Oy, got it. It had something to do with the indents in the code. I must have had a space somehwere instead of a tab. Once I retyped them all everything worked fine.
28 Aug 2011 — 9:37am
Hello,
I think this prints what you want:
if len(fl) > 0: for glyph in fl.font.glyphs: if glyph.mark: if glyph.unicode is None: print 'None\t%s' % glyph.name else: print '0x%04X\t%s' % (glyph.unicode, glyph.name)Redirecting the output to a file is up to you ;-)
Best
Eigi
1 Sep 2011 — 12:53am
Eigi:
all the code does for me is the list of glyphs and "none" unicode for all of them, no matter they have unicode or not.
Ken:
Could I have the code, I just need it for generating unicode for many glyphs, and your script will make it a cakewalk, thanks.
1 Sep 2011 — 10:23am
Hello Bahman,
Hm - this confuses me!? This is what I get if I mark standard figures (with unicode) and old Style figures (without unicode)
Are you running FontLab on Mac or Win?
1 Sep 2011 — 10:35am
Stil confused. Just checked FontLab 5.0.4 Win and 5.0.2 Mac - same output!?
1 Sep 2011 — 10:13pm
Hi Eigi
I got it, it wasn't the code, the problem was that I had too many glyphs (about 800) and output window is not enough for it, so it just leaves out the glyphs which had unicode. I made the ken code to work but there is a problem, hex function is not working in it. without hex function it works but it's useless for me. what should I do?
Thanks,
Code:
#FLM: Writes marked glyph unicode numbers and names to a file f = fl.font fname=f.font_name finame=str("C:\Program Files\FontLab\Studio5\Macros\UnicodeAndNamesMarked_") + fname + str(".txt") TheFile = open(finame, "w") TheFile.write(f.family_name + " marked glyphs" + chr(10)) if f != None: gcount = len(f) for i in range(gcount): if f.glyphs[i].mark: unistr = str(f.glyphs[i].unicode) isnumeric = unistr.isdigit() if isnumeric: TheFile.write(hex(unistr) + chr(9) + f.glyphs[i].name + chr(10)) else: TheFile.write(unistr + chr(9) + f.glyphs[i].name + chr(10)) else: print "There are no fonts opened" TheFile.close() print "Filename: " + finame2 Sep 2011 — 12:04am
Hello Bahman,
The hex() function takes an integer as parameter not a string. See http://docs.python.org/library/functions.html#hex
I prefer the string formatting operations to get a hex representation of an integer (as shown above). See http://docs.python.org/library/stdtypes.html#string-formatting-operations
Best
Eigi
5 Sep 2011 — 1:21am
Thanks :)