summaryrefslogtreecommitdiff
path: root/fonts/gentium-tug/source/type1/greekcorrection.py
diff options
context:
space:
mode:
Diffstat (limited to 'fonts/gentium-tug/source/type1/greekcorrection.py')
-rwxr-xr-xfonts/gentium-tug/source/type1/greekcorrection.py173
1 files changed, 93 insertions, 80 deletions
diff --git a/fonts/gentium-tug/source/type1/greekcorrection.py b/fonts/gentium-tug/source/type1/greekcorrection.py
index 16b328f590..aebe686af4 100755
--- a/fonts/gentium-tug/source/type1/greekcorrection.py
+++ b/fonts/gentium-tug/source/type1/greekcorrection.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
# This file is part of the Gentium package for TeX.
# It is licensed under the Expat License, see doc//README for details.
# author: Pavel Farar, pavel.farar@centrum.cz
@@ -37,7 +37,7 @@ import sys
# 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 @@ LigatureTable.append(['tonos', 'Omega', 'Omegatonos'])
# 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 @@ farray = f.readlines()
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']
-
- # 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
+ 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']
+
+ # 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)
-
- return FirstMove + SecondMove - int(AccentWidth[LigatureTable[LetterIndex][0]])
-
-
-
-
-KernTable = {}
+ # 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)
+
+ 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()