[gentium-commits] [SCM] gentium updated: r26 - trunk/gentium/source/fonts/gentium-tug/type1

Pavel Far?? INVALID.NOREPLY at gnu.org.ua
Tue Mar 15 20:59:24 CET 2022


Author: pavel
Date: 2022-03-15 19:59:24 +0000 (Tue, 15 Mar 2022)
New Revision: 26

Modified:
   trunk/gentium/source/fonts/gentium-tug/type1/afmcreator.py
   trunk/gentium/source/fonts/gentium-tug/type1/greekcorrection.py
   trunk/gentium/source/fonts/gentium-tug/type1/kerncorrection.py
Log:
fix whitespace in font conversion scripts

Modified: trunk/gentium/source/fonts/gentium-tug/type1/afmcreator.py
===================================================================
--- trunk/gentium/source/fonts/gentium-tug/type1/afmcreator.py	2022-03-15 18:25:18 UTC (rev 25)
+++ trunk/gentium/source/fonts/gentium-tug/type1/afmcreator.py	2022-03-15 19:59:24 UTC (rev 26)
@@ -2,7 +2,8 @@
 # This file is part of the Gentium package for TeX.
 # It is licensed under the Expat License, see doc//README for details.
 
-import os, sys
+import os
+import sys
 
 creatortext = "Comment Creator: TeX Users Group\n"
 
@@ -11,11 +12,12 @@
 fin = open(sys.argv[1], "r")
 fout = open(tempname, "w")
 while True:
-  s = fin.readline()
-  if s == "": break	# end of file
-  fout.write(s)
-  if s.find("Comment Creation Date") == 0 :
-    fout.write(creatortext) # Creator after Creation Date
+    s = fin.readline()
+    if s == "":
+        break  # end of file
+    fout.write(s)
+    if s.find("Comment Creation Date") == 0:
+        fout.write(creatortext)  # Creator after Creation Date
 fin.close()
 fout.close()
 

Modified: trunk/gentium/source/fonts/gentium-tug/type1/greekcorrection.py
===================================================================
--- trunk/gentium/source/fonts/gentium-tug/type1/greekcorrection.py	2022-03-15 18:25:18 UTC (rev 25)
+++ trunk/gentium/source/fonts/gentium-tug/type1/greekcorrection.py	2022-03-15 19:59:24 UTC (rev 26)
@@ -37,7 +37,7 @@
 # from the LIGKERN commands for the precomposed small Greek
 # accented letters in the encoding LGR. Then I did uppercasing
 # using information from Unicode and looked if there is
-# some accented letter missing. Therefore I call it 
+# some accented letter missing. Therefore I call it
 # LigatureTable and this file uses one line for every
 # capital Greek letter. I did it in such a way to avoid
 # random errors.
@@ -109,30 +109,32 @@
 
 
 # Set with Greek accents
-GreekAccents = set()	# empty set
+GreekAccents = set()  # empty set
 for i in range(len(LigatureTable)):
-  GreekAccents.add(LigatureTable[i][0])
+    GreekAccents.add(LigatureTable[i][0])
 
 # Set with Greek letters
-GreekLetters = set()	# empty set
+GreekLetters = set()  # empty set
 for i in range(len(LigatureTable)):
-  GreekLetters.add(LigatureTable[i][1])
+    GreekLetters.add(LigatureTable[i][1])
 
 # Set with precomposed Greek letters
-PrecomposedGreekLetters = set()	# empty set
+PrecomposedGreekLetters = set()  # empty set
 for i in range(len(LigatureTable)):
-  PrecomposedGreekLetters.add(LigatureTable[i][2])
+    PrecomposedGreekLetters.add(LigatureTable[i][2])
 
 
 def UnicodeValue(s):
-  # The unicode value is the second number after "Encoding:"
-  if s.find('Encoding:') != 0: sys.exit('UnicodeValue error')
-  return s.split()[2]	# The third item
+    # The unicode value is the second number after "Encoding:"
+    if s.find('Encoding:') != 0:
+        sys.exit('UnicodeValue error')
+    return s.split()[2]  # The third item
 
 
 def WidthValue(s):
-  if s.find('Width:') != 0: sys.exit('WidthValue error')
-  return s.split()[1]	# The second item
+    if s.find('Width:') != 0:
+        sys.exit('WidthValue error')
+    return s.split()[1]  # The second item
 
 
 # Dictionaries (all values are strings, not numbers!)
@@ -147,87 +149,98 @@
 f.close()
 findex = -1
 while True:
-  findex = findex + 1
-  if findex >= len(farray): break	# end of file
-  s = farray[findex]
-  if s.find('StartChar: ') == 0 :
-    CharacterName = s[11:-1]
-    if CharacterName in GreekLetters:
-      findex = findex + 1
-      s = farray[findex]
-      LetterUnicode[CharacterName] = UnicodeValue(s)
-    if CharacterName in GreekAccents:
-      findex = findex + 1
-      s = farray[findex]
-      AccentUnicode[CharacterName] = UnicodeValue(s)
-      findex = findex + 1
-      s = farray[findex]
-      AccentWidth[CharacterName] = WidthValue(s)
+    findex = findex + 1
+    if findex >= len(farray):
+        break  # end of file
+    s = farray[findex]
+    if s.find('StartChar: ') == 0:
+        CharacterName = s[11:-1]
+        if CharacterName in GreekLetters:
+            findex = findex + 1
+            s = farray[findex]
+            LetterUnicode[CharacterName] = UnicodeValue(s)
+        if CharacterName in GreekAccents:
+            findex = findex + 1
+            s = farray[findex]
+            AccentUnicode[CharacterName] = UnicodeValue(s)
+            findex = findex + 1
+            s = farray[findex]
+            AccentWidth[CharacterName] = WidthValue(s)
 
 
 def MoveValue(ss, lindex):
-  sarray = ss.split()
-  if sarray[0] != 'Refer:': sys.exit('No Refer:')
-  x = int(sarray[8])	# the value of move
-  
-  # dirty hack to make Omega work in both Gentium and GentiumPlus
-  # This script without the following hack would work well for Gentium, but not for
-  # GentiumPlus. The problem with GentiumPlus is that the accented letters with Omega
-  # uses as a base letter that with the unicode value 937 (which should be Omega), but
-  # this letter has PostScript name uni03A9, not Omega. Omega has a different value.
-  if sarray[2] == '937': # the standard unicode value for Omega = problems in GentiumPlus
-    sarray[2] = LetterUnicode['Omega']
+    sarray = ss.split()
+    if sarray[0] != 'Refer:':
+        sys.exit('No Refer:')
+    x = int(sarray[8])  # the value of move
 
-  # is it accent or letter?
-  # unicode is the second number (third value)
-  if sarray[2] == AccentUnicode[LigatureTable[lindex][0]]: # accent
-    x = -x	# the move of accent is taken negatively
-  elif sarray[2] == LetterUnicode[LigatureTable[lindex][1]]: # letter
-    x = +x	# the move of letter is taken positively
-  else:
-    sys.exit('Bad unicode of component')
-    
-  return x
+    # dirty hack to make Omega work in both Gentium and GentiumPlus
+    # This script without the following hack would work well for Gentium, but not for
+    # GentiumPlus. The problem with GentiumPlus is that the accented letters with Omega
+    # uses as a base letter that with the unicode value 937 (which should be Omega), but
+    # this letter has PostScript name uni03A9, not Omega. Omega has a different value.
+    if (
+        sarray[2] == '937'
+    ):  # the standard unicode value for Omega = problems in GentiumPlus
+        sarray[2] = LetterUnicode['Omega']
 
+    # is it accent or letter?
+    # unicode is the second number (third value)
+    if sarray[2] == AccentUnicode[LigatureTable[lindex][0]]:  # accent
+        x = -x  # the move of accent is taken negatively
+    elif sarray[2] == LetterUnicode[LigatureTable[lindex][1]]:  # letter
+        x = +x  # the move of letter is taken positively
+    else:
+        sys.exit('Bad unicode of component')
 
+    return x
+
+
 def KernValue(letter, s1, s2):
-  # letter	- the name of the precomposed letter
-  # s1		- Refer to the accent (expected to be first)
-  # s2		- Refer to the letter
-  for i in range(len(LigatureTable)):
-    if LigatureTable[i][2] == letter: LetterIndex = i
-  
-  FirstMove = MoveValue(s1, LetterIndex)  
-  SecondMove = MoveValue(s2, LetterIndex)  
+    # letter	- the name of the precomposed letter
+    # s1		- Refer to the accent (expected to be first)
+    # s2		- Refer to the letter
+    for i in range(len(LigatureTable)):
+        if LigatureTable[i][2] == letter:
+            LetterIndex = i
 
-  return FirstMove + SecondMove - int(AccentWidth[LigatureTable[LetterIndex][0]])
-  
-  
-  
+    FirstMove = MoveValue(s1, LetterIndex)
+    SecondMove = MoveValue(s2, LetterIndex)
 
-KernTable = {} 
+    return FirstMove + SecondMove - int(AccentWidth[LigatureTable[LetterIndex][0]])
 
+
+KernTable = {}
+
 # Process the precomposed letters
 # The sfd file is still in "farray"
 findex = -1
 while True:
-  findex = findex + 1
-  if findex >= len(farray): break	# end of file
-  s = farray[findex]
-  if s.find('StartChar: ') == 0 :
-    CharacterName = s[11:-1]
-    if CharacterName in PrecomposedGreekLetters:
-      while s.find('Refer: ') != 0 :
-        findex = findex + 1
-        s = farray[findex]
-      KernTable[CharacterName] = KernValue(CharacterName, s, farray[findex + 1])
+    findex = findex + 1
+    if findex >= len(farray):
+        break  # end of file
+    s = farray[findex]
+    if s.find('StartChar: ') == 0:
+        CharacterName = s[11:-1]
+        if CharacterName in PrecomposedGreekLetters:
+            while s.find('Refer: ') != 0:
+                findex = findex + 1
+                s = farray[findex]
+            KernTable[CharacterName] = KernValue(CharacterName, s, farray[findex + 1])
 
 
 # Write the kerning table
 fafm = open(sys.argv[1][:-4] + '-extra.afm', 'w')
 for i in range(len(LigatureTable)):
-  sourceKern = KernTable[LigatureTable[i][2]]
-  if sourceKern != 0: # remove zero kerns
-    fafm.write('KPX ' + LigatureTable[i][0] + ' ' + LigatureTable[i][1] + ' ' +
-      str(int(round(1000.0 / 2048.0 * sourceKern))) + '\n')
+    sourceKern = KernTable[LigatureTable[i][2]]
+    if sourceKern != 0:  # remove zero kerns
+        fafm.write(
+            'KPX '
+            + LigatureTable[i][0]
+            + ' '
+            + LigatureTable[i][1]
+            + ' '
+            + str(int(round(1000.0 / 2048.0 * sourceKern)))
+            + '\n'
+        )
 fafm.close()

Modified: trunk/gentium/source/fonts/gentium-tug/type1/kerncorrection.py
===================================================================
--- trunk/gentium/source/fonts/gentium-tug/type1/kerncorrection.py	2022-03-15 18:25:18 UTC (rev 25)
+++ trunk/gentium/source/fonts/gentium-tug/type1/kerncorrection.py	2022-03-15 19:59:24 UTC (rev 26)
@@ -6,15 +6,18 @@
 
 import os, sys, re
 
+
 class KernReader:
     def __init__(self, filename):
         self.filename = filename
+
     def getkerns(self, regex):
         a = []
         f = open(self.filename, "r")
         while True:
             s = f.readline()
-            if s == "": break # end of file
+            if s == "":
+                break  # end of file
             if re.match(regex, s):
                 a.append(s)
         f.close()
@@ -134,8 +137,10 @@
         ["y period", "yacute period", "ydieresis period"]
         # nothing to be derived from "f quoteright" and "f quotedblright"
     ]
+
     def __init__(self, filename):
-        self.f = open(filename, "a") # append
+        self.f = open(filename, "a")  # append
+
     def writetofile(self, s):
         # This method writes one extra kerning pair to the output file.
         # It also makes correction for small cap Tcommaaccent and Tcedilla.
@@ -145,6 +150,7 @@
         # in the unicode value, but also in the case, because method lower() is
         # used).
         self.f.write(s.replace("uni021a.SC", "uni021B.SC").replace("uni0162.SC", "uni0163.SC"))
+
     def smallcaps(self, fromreader, kernfactor):
         a = fromreader.getkerns("KPX [A-Z] [A-Z]")
         for s in a:
@@ -152,6 +158,7 @@
             self.writetofile("KPX " + parts[1].lower() + ".SC " + parts[2].lower() +
                              ".SC " + str(int(round(kernfactor * float(parts[3])))) +
                              '\n')
+
     def initialcap(self, fromreader, kernfactor):
         a = fromreader.getkerns("KPX [A-Z] [A-Z]")
         for s in a:
@@ -158,9 +165,10 @@
             parts = s.split()
             self.writetofile("KPX " + parts[1] + " " + parts[2].lower() + ".SC " +
                              str(int(round(kernfactor * float(parts[3])))) + '\n')
+
     def rightpunctuation(self, fromreader, kernfactor):
         # small cap and punctuation
-        a =      fromreader.getkerns("KPX [A-Z] period")
+        a = fromreader.getkerns("KPX [A-Z] period")
         a.extend(fromreader.getkerns("KPX [A-Z] comma"))
         a.extend(fromreader.getkerns("KPX [A-Z] quotedblright"))
         a.extend(fromreader.getkerns("KPX [A-Z] quoteright"))
@@ -168,14 +176,16 @@
             parts = s.split()
             self.writetofile("KPX " + parts[1].lower() + ".SC " + parts[2] + " " +
                              str(int(round(kernfactor * float(parts[3])))) + '\n')
+
     def leftpunctuation(self, fromreader, kernfactor):
         # punctuation and small cap
-        a =      fromreader.getkerns("KPX quotedblleft [A-Z]")
+        a = fromreader.getkerns("KPX quotedblleft [A-Z]")
         a.extend(fromreader.getkerns("KPX quoteleft [A-Z]"))
         for s in a:
             parts = s.split()
             self.writetofile("KPX " + parts[1] + " " + parts[2].lower() + ".SC " +
                              str(int(round(kernfactor * float(parts[3])))) + '\n')
+
     def accentedcapitalletters(self, fromreader):
         for x in self.kernpairscapital:
             basekern = x[0]
@@ -185,6 +195,7 @@
             for b in derivedkerns:
                 newkernline = kernline.replace(basekern, b)
                 self.writetofile(newkernline)
+
     def accentedsmallletters(self, fromreader):
         for x in self.kernpairssmall:
             basekern = x[0]
@@ -194,6 +205,7 @@
             for b in derivedkerns:
                 newkernline = kernline.replace(basekern, b)
                 self.writetofile(newkernline)
+
     def accentedsmallcaps(self, fromreader, kernfactor):
         for x in self.kernpairscapital:
             basekern = x[0]
@@ -206,6 +218,7 @@
                 self.writetofile("KPX " + parts[1].lower() + ".SC " + parts[2].lower() +
                                  ".SC " + str(int(round(kernfactor * float(parts[3])))) +
                                  '\n')
+
     def accentedinitialcap(self, fromreader):
         for x in self.kernpairsinitialcap:
             basekern = x[0]
@@ -215,6 +228,7 @@
             for b in derivedkerns:
                 newkernline = kernline.replace(basekern, b)
                 self.writetofile(newkernline)
+
     def accentedinitialcapsmallcap(self, fromreader, kernfactor):
         for x in self.kernpairscapital:
             basekern = x[0]
@@ -226,6 +240,7 @@
                 parts = newkernline.split()
                 self.writetofile("KPX " + parts[1] + " " + parts[2].lower() + ".SC " +
                                  str(int(round(kernfactor * float(parts[3])))) + '\n')
+
     def accentedrightpunctuation(self, fromreader):
         for x in self.rightpunctuationsmall:
             basekern = x[0]
@@ -235,9 +250,11 @@
             for b in derivedkerns:
                 newkernline = kernline.replace(basekern, b)
                 self.writetofile(newkernline)
+
     def accentedleftpunctuation(self, fromreader):
         # nothing to be done
         pass
+
     def czechquotes(self, fromreader):
         for x in self.kernpairsquotes:
             basekern = x[0]
@@ -247,12 +264,13 @@
             for b in derivedkerns:
                 newkernline = kernline.replace(basekern, b)
                 self.writetofile(newkernline)
+
     def close(self):
         self.f.close()
 
 
-kernfactor = 0.94 # width of small caps / width of capital letters; tested for
-    # letters A, L, T, V, W and Y, all had nearly the same ratio
+kernfactor = 0.94  # width of small caps / width of capital letters; tested for
+                   # letters A, L, T, V, W and Y, all had nearly the same ratio
 
 fin = KernReader(sys.argv[1])
 



More information about the gentium-commits mailing list.