summaryrefslogtreecommitdiff
path: root/fonts/gentium-tug/source/type1/ff-gentium.pe
blob: 55b6ec5c00035a3d4f3d46b6a566fe269c6e548b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env fontforge
# $Id: ff-gentium.pe 116 2022-05-11 00:51:36Z karl $
# This file is part of the Gentium package for TeX.
# It is licensed under the Expat License, see doc//README for details.

# It is heavily based on the work by Clea F. Rees (ff-gentium-vgx.pe),
# with some modifications and additions by Pavel Farar.
# 
# The script is dirty now. It relies on the order in which the fonts are
# processed and maybe on some other things. I will see if it will be
# easier for me to do clean up or rewrite it to Python. I would prefer
# the latter, because the syntax is more familiar to me.

# You can set the desired copyright text in the following variable
FONT_COPYRIGHT='Copyright (c) SIL International, 2003-2022. TeX conversion additions copyright (c) 2013-2022 TeX Users Group. Released under the OFL, https://scripts.sil.org/OFL.'

TTF_PATH='../../../../fonts/truetype/public/gentium-tug/'
FONT_VERSION_PLUS='gentiumps-1.101 (from Gentium Plus 6.101; 2022; Maintenance release)'
FONT_VERSION_BOOK='gentiumps-1.101 (from Gentium Book Plus 6.101; 2022; Maintenance release)'

LoadNamelist("vgx.nam")

i = 1

while ( i < $argc )

	Print("* ----------------------------------------")
	Print("* Converting font " + $argv[i] + " to Type 1")
	Print("* Reading TrueType")
	Open(TTF_PATH + $argv[i])
	
	# attempt to follow Hirwen's instructions:
	Print("* Scaling")
	ScaleToEm(1000)
	Print("* Generating OpenType")
	Generate($argv[i]:r + ".otf","",-1) # is the OpenType really needed?
	Close()
	
	Print("* Reading OpenType")
	Open($argv[i]:r + ".otf")

	# TODO: Move following commands before generating OpenType
	SetFontOrder(3)	# just to be sure
	SelectAll()
	Print("* Simplifying")
	Simplify()
	Simplify(104,5)
	Print("* Adding extrema")
	AddExtrema()

	# Moving autohinting after guessing blue values makes no difference.
	Print("* Autohinting")
	AutoHint()
	# ps private
	Print("* Guessing blue values")
	PrivateGuess("BlueValues")
	PrivateGuess("OtherBlues")
	PrivateGuess("BlueScale")
	PrivateGuess("BlueShift")
	# Hirwen doesn't include this though LM has it (and also FalseBold set as false - even for bold!)
	PrivateGuess("BlueFuzz")
	PrivateGuess("StdHW")
	PrivateGuess("StdVW")
	PrivateGuess("StemSnapH")
	PrivateGuess("StemSnapV")
	PrivateGuess("ExpansionFactor")

	# Family blue values
	# Adobe says that FamilyBlues and FamilyOtherBlues should be set for
	# non-regular styles and that the values should be taken from
	# BlueValues and OtherBlues for regular style. Unfortunately, it is
	# impossible to use the values from the regular style for bold and
	# bold italic styles--t1lint complained (too big difference). Therefore,
	# family blues for the italic style are taken from the regular style and
	# values for the bold italic style are taken from the bold style.
	# It makes sense from another point of view: two fonts from  GentiumPlus 
	# make one family, two fonts from GentiumBasic make other family.
	# TODO: clean-up of the following code

	# GentiumPlus family
	if ( $argv[i] == "GentiumPlus-Regular.ttf" )
		BlueValuesRegular = GetPrivateEntry("BlueValues")
		OtherBluesRegular = GetPrivateEntry("OtherBlues")
	endif
	if ( $argv[i] == "GentiumPlus-Italic.ttf" )
		ChangePrivateEntry("FamilyBlues", BlueValuesRegular)
		ChangePrivateEntry("FamilyOtherBlues", OtherBluesRegular)
	endif
	if ( $argv[i] == "GentiumPlus-Bold.ttf" )
		BlueValuesBold = GetPrivateEntry("BlueValues")
		OtherBluesBold = GetPrivateEntry("OtherBlues")
	endif
	if ( $argv[i] == "GentiumPlus-BoldItalic.ttf" )
		ChangePrivateEntry("FamilyBlues", BlueValuesBold)
		ChangePrivateEntry("FamilyOtherBlues", OtherBluesBold)
	endif

	# GentiumBookPlus family
	if ( $argv[i] == "GentiumBookPlus-Regular.ttf" )
		BlueValuesBookRegular = GetPrivateEntry("BlueValues")
		OtherBluesBookRegular = GetPrivateEntry("OtherBlues")
	endif
	if ( $argv[i] == "GentiumBookPlus-Italic.ttf" )
		ChangePrivateEntry("FamilyBlues", BlueValuesBookRegular)
		ChangePrivateEntry("FamilyOtherBlues", OtherBluesBookRegular)
	endif
	if ( $argv[i] == "GentiumBookPlus-Bold.ttf" )
		BlueValuesBookBold = GetPrivateEntry("BlueValues")
		OtherBluesBookBold = GetPrivateEntry("OtherBlues")
	endif
	if ( $argv[i] == "GentiumBookPlus-BoldItalic.ttf" )
		ChangePrivateEntry("FamilyBlues", BlueValuesBookBold)
		ChangePrivateEntry("FamilyOtherBlues", OtherBluesBookBold)
	endif

	# Hirwen says add forcebold and write true if font is bold (or bold italic).
	# Adobe strongly advises to set ForceBold explicitly (true or false).
	if ( $argv[i] == "GentiumPlus-Regular.ttf" || $argv[i] == "GentiumPlus-Italic.ttf" || \
	     $argv[i] == "GentiumBookPlus-Regular.ttf" || $argv[i] == "GentiumBookPlus-Italic.ttf" )
		ChangePrivateEntry("ForceBold", "false")
	else
		ChangePrivateEntry("ForceBold", "true")
	endif

	# Hirwen says to repeat with the os/2 and panose panels but these already seem to be filled out...
	# os/2
	#SetOS2Value(field-name,field-value)
	# Usually the second argument is an integer but VendorID takes a 4 character ASCII string, and Panose takes a 10 element integer array. 
	#Weight, Width, FSType, IBMFamily, VendorID, Panose, WinAscent, WinAscentIsOffset, WinDescent, WinDescentIsOffset, TypoAscent, TypoAscentIsOffset, TypoDescent, TypoDescentIsOffset, HHeadAscent, HHeadAscentIsOffset, HHeadDescent, HHeadDescentIsOffset, TypoLineGap, HHeadLineGap, VHeadLineGap, SubXSize, SubYSize, SubXOffset, SubYOffset, SupXSize, SupYSize, SupXOffset, SupYOffset, StrikeOutSize, StrikeOutPos 

	Save($argv[i]:r + ".sfd") # Is it really needed?

	# Reencoding to Adobe Standard Encoding introduced many slots with ".notdef".
	# These slots can be either cleared (if you uncomment the following
	# commands) or the reencoding can be switched off (if the following commands
	# are commented out)
#	Print("* Reencoding")
#	Reencode("AdobeStandardEncoding")
#	Select(".notdef")
#	Clear()

#	RenameGlyphs("vgx")	# currently switched off, file vgx not present;

	Print("* Setting font names")
#	SetFontNames(fontname[,family[,fullname[,weight[,copyright-notice[,fontversion]]]]])
	# Note that this is not at all robust. If it doesn't work, comment out all the lines in the next block except for the single line between the "else" and the "endif". This will produce names which may be less than ideal from an aesthetic point of view but should at least work.	
	hyphened=Strrstr($fontname,"-")
	spaced=Strrstr($fullname," ")
	if ( Strcasestr($argv[i], "GentiumPlus") == 0 )
		FONT_VERSION=FONT_VERSION_PLUS
	else
		FONT_VERSION=FONT_VERSION_BOOK
	endif
	if ( hyphened > 0 )
		fontnamecyntaf=Strsub($fontname,0,hyphened)
		fontnameail=Strsub($fontname,hyphened)
		fullnamecyntaf=Strsub($fullname,0,spaced)
		fullnameail=Strsub($fullname,spaced)
		SetFontNames(fontnamecyntaf + "PS" + fontnameail,$familyname + " PS", fullnamecyntaf + " PS" + fullnameail, $weight, FONT_COPYRIGHT, FONT_VERSION)
	else
		SetFontNames($fontname + "PS",$familyname + " PS", $fullname + " PS", $weight, FONT_COPYRIGHT, FONT_VERSION)
	endif
	

	# Corrections for Greek (automatically generated values) and additional kerns
	# TODO: Don't use hard-coded names, check the existence of extra kernings instead
	if ( $argv[i] == "GentiumPlus-Regular.ttf" )
		Print("* Correction for Greek and additional kerning pairs")
		MergeFeature("GentiumPlus-Regular-extra.afm")
	endif
	if ( $argv[i] == "GentiumPlus-Italic.ttf" )
		Print("* Correction for Greek and additional kerning pairs")
		MergeFeature("GentiumPlus-Italic-extra.afm")
	endif
	if ( $argv[i] == "GentiumPlus-Bold.ttf" )
		Print("* Correction for Greek and additional kerning pairs")
		MergeFeature("GentiumPlus-Bold-extra.afm")
	endif
	if ( $argv[i] == "GentiumPlus-BoldItalic.ttf" )
		Print("* Correction for Greek and additional kerning pairs")
		MergeFeature("GentiumPlus-BoldItalic-extra.afm")
	endif
	if ( $argv[i] == "GentiumBookPlus-Regular.ttf" )
		Print("* Correction for Greek and additional kerning pairs")
		MergeFeature("GentiumBookPlus-Regular-extra.afm")
	endif
	if ( $argv[i] == "GentiumBookPlus-Italic.ttf" )
		Print("* Correction for Greek and additional kerning pairs")
		MergeFeature("GentiumBookPlus-Italic-extra.afm")
	endif
	if ( $argv[i] == "GentiumBookPlus-Bold.ttf" )
		Print("* Correction for Greek and additional kerning pairs")
		MergeFeature("GentiumBookPlus-Bold-extra.afm")
	endif
	if ( $argv[i] == "GentiumBookPlus-BoldItalic.ttf" )
		Print("* Correction for Greek and additional kerning pairs")
		MergeFeature("GentiumBookPlus-BoldItalic-extra.afm")
	endif


	# Correction of the kern between D and V in "GentiumPlus-Regular.ttf" and some other
	# All these fonts had 20 and it will be changed to -20.
	if ( \
	    $argv[i] == "GentiumPlus-Regular.ttf" || \
	    $argv[i] == "GentiumPlus-Bold.ttf" || \
	    $argv[i] == "GentiumBookPlus-Regular.ttf" || \
	    $argv[i] == "GentiumBookPlus-Bold.ttf" \
	)
		Print("* Correction of kern between D and V")
		Select("D")
		SetKern("V", -20)
	endif

	Print("* Generating Type 1")
	Generate($argv[i]:r + ".pfb","",-1)
	i = i+1

endloop