root/trunk/Documentation/TypoTechnica 2005/scripts Folder/Paulus - batch/batch win rename flex.py

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

initial import

  • Property svn:executable set to
Line 
1 #FLM: Batch win rename Flex
2
3 #       Paul van der Laan, 2004/09/13
4
5
6
7 from robofab.interface.all.dialogs import GetFolder
8 from robofab.world import RFont, OpenFont, CurrentFont
9 import os
10
11
12 # Een functie om een map met files door te zoeken op vfb files
13 def collectSources(root):
14         files = []
15         ext = ['.vfb']
16         names = os.listdir(root)
17         for n in names:
18                 if os.path.splitext(n)[1] in ext:
19                         files.append(os.path.join(root, n))
20         return files
21
22
23
24 # Rename
25 def renameFont(f, myDest):
26         if f.info.fontName:
27
28                 f.info.fontStyle=64
29                
30                 myStylename = f.info.styleName
31                 if "Italic" in myStylename:
32                         myStylename = myStylename.replace("Italic", "")
33                         f.info.fontstyle = 1
34                
35                 myFamilyname = f.info.familyName +
36                
37                 myStylename = "Regular"
38                 if f.info.fontStyle == 1: myStylename = "Italic"
39                
40                 f.info.familyName = myFamilyname
41                 # f.info.fontStyle = myFontstyle
42                 f.info.styleName = myStylename
43                 f.info.fontName = myFamilyname + "-" + myStylename
44                 f.info.fullName = myFamilyname + " " + myStylename
45                 f.info.menuName = myFamilyname
46                 f.info.fondName = myFamilyname
47                
48                 font = fl.font
49                 font.weight = "Regular"
50                 font.weight_code = 400
51                 font.width = "Medium (normal)"
52                
53                 f.update()
54                
55                 myPath = myDest + ":" + myFamilyname + "-" + myStylename + ".vfb"
56                 fl.font.Save(myPath)
57                 print myFamilyname + "-" + myStylename
58
59
60        
61 # main loop
62 mySource = GetFolder()
63 myDest = GetFolder()
64
65 if mySource is not None:
66         myFiles = collectSources(mySource)
67        
68         for myFile in myFiles:
69                 myFont = None
70                 try:
71                         myFont = OpenFont(myFile)
72                         renameFont(myFont, myDest)
73                        
74                 finally:
75                         if myFont is not None:
76                                 myFont.close(False)
77
78 print "Done"
Note: See TracBrowser for help on using the browser.