root/trunk/Documentation/TypoTechnica 2005/scripts Folder/Paulus - batch/batch export glyphs rtf.py

Revision 1, 2.1 kB (checked in by erik, 3 years ago)

initial import

  • Property svn:executable set to
Line 
1 #FLM: Batch export glyphs to rtf
2
3 #       Paul van der Laan, 2004/11/02
4
5
6 from robofab.interface.all.dialogs import GetFolder, ProgressBar
7 from robofab.world import RFont, OpenFont
8 import os
9
10 mySize = 16
11 myLeading = 22
12
13
14 # Een functie om een map met files door te zoeken op vfb files
15 def collectSources(root):
16         files = []
17         ext = ['.vfb']
18         names = os.listdir(root)
19         for n in names:
20                 if os.path.splitext(n)[1] in ext:
21                         files.append(os.path.join(root, n))
22         return files
23
24 # main loop
25 mySource = GetFolder()
26 if mySource is not None:
27         myPath = mySource + ":glyph overview.rtf"
28         myrtfFile = open(myPath, "w")
29         myrtfFile.write("{\\rtf1\\mac\\ansicpg1252" + chr(13))
30         myPagebreak = ""
31        
32         myFiles = collectSources(mySource)
33         for myFile in myFiles:
34                 myFont = None
35                 try:
36                         myFont = OpenFont(myFile)
37                         myflFont = fl.font
38                         myEncoding = myflFont.encoding
39                         myFontfam = myFont.info.familyName
40                         myFontstyle = myFont.info.styleName
41                         myList = [""] * len(myEncoding)
42                        
43                         for myGlyph in myFont:
44                                 myGlyphname = myGlyph.name
45                                 myIndex = myEncoding.FindName(myGlyphname)
46                                 if myIndex is not -1:
47                                         myList[myIndex] = myGlyph.unicode
48                        
49                         if myFont.info.designer is None:
50                                 myFont.info.designer = "-"
51                         if myFont.info.year is None:
52                                 myFont.info.year = "1452"
53                        
54                         myBar = ProgressBar('Exporting glyphs...', len(myList))
55                         myLine = myPagebreak + "{\\fonttbl\\f0\\fnil\\cpg819 " + myFontfam + "-" + myFontstyle + ";}" + chr(13) + "\\f0\\sl-" + str(myLeading*20) + "\\fs" + str(mySize*2) + chr(13) + "\\par "
56                         myrtfFile.write(myLine)
57                         for myItem in range (0, len(myList)):
58                                 if myList[myItem]:
59                                         myHex = hex(myItem)[-2:]
60                                         myHex = myHex.replace("x", "0")
61                                         myWord = "\u" + str(myList[myItem]) + "\\'" + myHex + " "
62                                         myrtfFile.write(myWord)
63                                 myBar.tick()
64                         myPagebreak = "\page" + chr(13)
65                         myBar.close()
66                 finally:
67                         if myFont is not None:
68                                 myFont.close(False)
69                 print "Generated glyph overview for", myFontfam + "-" + myFontstyle
70         myrtfFile.write(chr(13) + "}")
71         myrtfFile.close()
72 print "Done"
73
74
75
76 # \f0\fnil\fcharset77 AndaleMono;
77 # \f1\fswiss\fcharset77 Helvetica;
78 # \f2\fnil\fcharset77 Georgia;
Note: See TracBrowser for help on using the browser.