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

Pavel Far?? INVALID.NOREPLY at gnu.org.ua
Wed Apr 6 18:35:03 CEST 2022


Author: pavel
Date: 2022-04-06 16:35:02 +0000 (Wed, 06 Apr 2022)
New Revision: 87

Modified:
   trunk/gentium/source/fonts/gentium-tug/type1/kerncorrection.py
Log:
refactor kerncorrection.py a little

Modified: trunk/gentium/source/fonts/gentium-tug/type1/kerncorrection.py
===================================================================
--- trunk/gentium/source/fonts/gentium-tug/type1/kerncorrection.py	2022-04-05 17:36:14 UTC (rev 86)
+++ trunk/gentium/source/fonts/gentium-tug/type1/kerncorrection.py	2022-04-06 16:35:02 UTC (rev 87)
@@ -36,6 +36,12 @@
 
 import collections
 
+SMALL_CAPS_CORRECTION = 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
+
+input_file_name = sys.argv[1]
+output_file_name = sys.argv[2]
+
 class KernReader:
     def __init__(self, filename):
         self.filename = filename
@@ -156,7 +162,7 @@
 
     kern_pairs_quotes = [
         # this is far from complete
-        # TODO: use this list also for accented small caps (using kernfactor)
+        # TODO: use this list also for accented small caps (using SMALL_CAPS_CORRECTION)
         ["A quotedblright", "A quotedblleft", "Aacute quotedblleft", "Adieresis quotedblleft"],
         ["L quotedblright", "L quotedblleft"], # Lcaron and Lacute left out (collision)
         ["A quoteright", "A quoteleft", "Aacute quoteleft", "Adieresis quoteleft"],
@@ -260,22 +266,22 @@
                 extra_kern_file.write(line)
 
 
-    def small_caps(self, fromreader, kernfactor):
+    def small_caps(self, fromreader):
         a = fromreader.getkerns("KPX [A-Z] [A-Z]")
         for s in a:
             parts = s.split()
             self.add_to_kern_lines("KPX " + parts[1].lower() + ".sc " + parts[2].lower() +
-                             ".sc " + str(int(round(kernfactor * float(parts[3])))) +
+                             ".sc " + str(int(round(SMALL_CAPS_CORRECTION * float(parts[3])))) +
                              '\n')
 
-    def initial_cap(self, fromreader, kernfactor):
+    def initial_cap(self, fromreader):
         a = fromreader.getkerns("KPX [A-Z] [A-Z]")
         for s in a:
             parts = s.split()
             self.add_to_kern_lines("KPX " + parts[1] + " " + parts[2].lower() + ".sc " +
-                             str(int(round(kernfactor * float(parts[3])))) + '\n')
+                             str(int(round(SMALL_CAPS_CORRECTION * float(parts[3])))) + '\n')
 
-    def right_punctuation(self, fromreader, kernfactor):
+    def right_punctuation(self, fromreader):
         # small cap and punctuation
         a = fromreader.getkerns("KPX [A-Z] period")
         a.extend(fromreader.getkerns("KPX [A-Z] comma"))
@@ -284,9 +290,9 @@
         for s in a:
             parts = s.split()
             self.add_to_kern_lines("KPX " + parts[1].lower() + ".sc " + parts[2] + " " +
-                             str(int(round(kernfactor * float(parts[3])))) + '\n')
+                             str(int(round(SMALL_CAPS_CORRECTION * float(parts[3])))) + '\n')
 
-    def left_punctuation(self, fromreader, kernfactor):
+    def left_punctuation(self, fromreader):
         # punctuation and small cap
         a = fromreader.getkerns("KPX quotedblleft [A-Z]")
         a.extend(fromreader.getkerns("KPX quoteleft [A-Z]"))
@@ -293,7 +299,7 @@
         for s in a:
             parts = s.split()
             self.add_to_kern_lines("KPX " + parts[1] + " " + parts[2].lower() + ".sc " +
-                             str(int(round(kernfactor * float(parts[3])))) + '\n')
+                             str(int(round(SMALL_CAPS_CORRECTION * float(parts[3])))) + '\n')
 
     def accented_capital_letters(self, fromreader):
         for x in self.kern_pairs_capital:
@@ -315,7 +321,7 @@
                 newkernline = kernline.replace(basekern, b)
                 self.add_to_kern_lines(newkernline)
 
-    def accented_small_caps(self, fromreader, kernfactor):
+    def accented_small_caps(self, fromreader):
         for x in self.kern_pairs_capital:
             basekern = x[0]
             derivedkerns = x[1:]
@@ -325,7 +331,7 @@
                 newkernline = kernline.replace(basekern, b)
                 parts = newkernline.split()
                 self.add_to_kern_lines("KPX " + parts[1].lower() + ".sc " + parts[2].lower() +
-                                 ".sc " + str(int(round(kernfactor * float(parts[3])))) +
+                                 ".sc " + str(int(round(SMALL_CAPS_CORRECTION * float(parts[3])))) +
                                  '\n')
 
     def accented_initial_cap(self, fromreader):
@@ -338,7 +344,7 @@
                 newkernline = kernline.replace(basekern, b)
                 self.add_to_kern_lines(newkernline)
 
-    def accented_initial_cap_small_cap(self, fromreader, kernfactor):
+    def accented_initial_cap_small_cap(self, fromreader):
         for x in self.kern_pairs_capital:
             basekern = x[0]
             derivedkerns = x[1:]
@@ -348,7 +354,7 @@
                 newkernline = kernline.replace(basekern, b)
                 parts = newkernline.split()
                 self.add_to_kern_lines("KPX " + parts[1] + " " + parts[2].lower() + ".sc " +
-                                 str(int(round(kernfactor * float(parts[3])))) + '\n')
+                                 str(int(round(SMALL_CAPS_CORRECTION * float(parts[3])))) + '\n')
 
     def accented_right_punctuation(self, fromreader):
         for x in self.right_punctuation_small:
@@ -408,26 +414,21 @@
                 newkernline = kernline.replace(basekern, new_kern)
                 self.add_to_kern_lines(newkernline)
 
+fin = KernReader(input_file_name)
 
-
-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])
-
 # output_generator is not a file ane more! Rename!
-output_generator = KernWriter(sys.argv[2])
+output_generator = KernWriter(output_file_name)
 # letters without accents
-output_generator.small_caps(fin, kernfactor)
-output_generator.initial_cap(fin, kernfactor)
-output_generator.right_punctuation(fin, kernfactor)
-output_generator.left_punctuation(fin, kernfactor)
+output_generator.small_caps(fin)
+output_generator.initial_cap(fin)
+output_generator.right_punctuation(fin)
+output_generator.left_punctuation(fin)
 # letters with accents
 output_generator.accented_capital_letters(fin)
 output_generator.accented_small_letters(fin)
-output_generator.accented_small_caps(fin, kernfactor)
+output_generator.accented_small_caps(fin)
 output_generator.accented_initial_cap(fin)
-output_generator.accented_initial_cap_small_cap(fin, kernfactor)
+output_generator.accented_initial_cap_small_cap(fin)
 output_generator.accented_right_punctuation(fin)
 output_generator.accented_left_punctuation(fin)
 output_generator.czech_quotes(fin)



More information about the gentium-commits mailing list.