summaryrefslogtreecommitdiff
path: root/misc/pylib/robofab/test/testSupport.py
blob: f7f96c9ff5efcfd0c01cd37a8ca34ec81c088922 (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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
"""Miscellaneous helpers for our test suite."""


import sys
import os
import types
import unittest


def getDemoFontPath():
	"""Return the path to Data/DemoFont.ufo/."""
	import robofab
	root = os.path.dirname(os.path.dirname(os.path.dirname(robofab.__file__)))
	return os.path.join(root, "Data", "DemoFont.ufo")


def getDemoFontGlyphSetPath():
	"""Return the path to Data/DemoFont.ufo/glyphs/."""
	return os.path.join(getDemoFontPath(), "glyphs")


def _gatherTestCasesFromCallerByMagic():
	# UGLY magic: fetch TestClass subclasses from the globals of our
	# caller's caller.
	frame = sys._getframe(2)
	return _gatherTestCasesFromDict(frame.f_globals)


def _gatherTestCasesFromDict(d):
	testCases = []
	for ob in d.values():
		if isinstance(ob, type) and issubclass(ob, unittest.TestCase):
			testCases.append(ob)
	return testCases

	
def runTests(testCases=None, verbosity=1):
	"""Run a series of tests."""
	if testCases is None:
		testCases = _gatherTestCasesFromCallerByMagic()
	loader = unittest.TestLoader()
	suites = []
	for testCase in testCases:
		suites.append(loader.loadTestsFromTestCase(testCase))

	testRunner = unittest.TextTestRunner(verbosity=verbosity)
	testSuite = unittest.TestSuite(suites)
	testRunner.run(testSuite)

# font info values used by several tests

fontInfoVersion1 = {
	"familyName"   : "Some Font (Family Name)",
	"styleName"	   : "Regular (Style Name)",
	"fullName"	   : "Some Font-Regular (Postscript Full Name)",
	"fontName"	   : "SomeFont-Regular (Postscript Font Name)",
	"menuName"	   : "Some Font Regular (Style Map Family Name)",
	"fontStyle"	   : 64,
	"note"		   : "A note.",
	"versionMajor" : 1,
	"versionMinor" : 0,
	"year"		   : 2008,
	"copyright"	   : "Copyright Some Foundry.",
	"notice"	   : "Some Font by Some Designer for Some Foundry.",
	"trademark"	   : "Trademark Some Foundry",
	"license"	   : "License info for Some Foundry.",
	"licenseURL"   : "http://somefoundry.com/license",
	"createdBy"	   : "Some Foundry",
	"designer"	   : "Some Designer",
	"designerURL"  : "http://somedesigner.com",
	"vendorURL"	   : "http://somefoundry.com",
	"unitsPerEm"   : 1000,
	"ascender"	   : 750,
	"descender"	   : -250,
	"capHeight"	   : 750,
	"xHeight"	   : 500,
	"defaultWidth" : 400,
	"slantAngle"   : -12.5,
	"italicAngle"  : -12.5,
	"widthName"	   : "Medium (normal)",
	"weightName"   : "Medium",
	"weightValue"  : 500,
	"fondName"	   : "SomeFont Regular (FOND Name)",
	"otFamilyName" : "Some Font (Preferred Family Name)",
	"otStyleName"  : "Regular (Preferred Subfamily Name)",
	"otMacName"	   : "Some Font Regular (Compatible Full Name)",
	"msCharSet"	   : 0,
	"fondID"	   : 15000,
	"uniqueID"	   : 4000000,
	"ttVendor"	   : "SOME",
	"ttUniqueID"   : "OpenType name Table Unique ID",
	"ttVersion"	   : "OpenType name Table Version",
}

fontInfoVersion2 = {
	"familyName"						 : "Some Font (Family Name)",
	"styleName"							 : "Regular (Style Name)",
	"styleMapFamilyName"				 : "Some Font Regular (Style Map Family Name)",
	"styleMapStyleName"					 : "regular",
	"versionMajor"						 : 1,
	"versionMinor"						 : 0,
	"year"								 : 2008,
	"copyright"							 : "Copyright Some Foundry.",
	"trademark"							 : "Trademark Some Foundry",
	"unitsPerEm"						 : 1000,
	"descender"							 : -250,
	"xHeight"							 : 500,
	"capHeight"							 : 750,
	"ascender"							 : 750,
	"italicAngle"						 : -12.5,
	"note"								 : "A note.",
	"openTypeHeadCreated"				 : "2000/01/01 00:00:00",
	"openTypeHeadLowestRecPPEM"			 : 10,
	"openTypeHeadFlags"					 : [0, 1],
	"openTypeHheaAscender"				 : 750,
	"openTypeHheaDescender"				 : -250,
	"openTypeHheaLineGap"				 : 200,
	"openTypeHheaCaretSlopeRise"		 : 1,
	"openTypeHheaCaretSlopeRun"			 : 0,
	"openTypeHheaCaretOffset"			 : 0,
	"openTypeNameDesigner"				 : "Some Designer",
	"openTypeNameDesignerURL"			 : "http://somedesigner.com",
	"openTypeNameManufacturer"			 : "Some Foundry",
	"openTypeNameManufacturerURL"		 : "http://somefoundry.com",
	"openTypeNameLicense"				 : "License info for Some Foundry.",
	"openTypeNameLicenseURL"			 : "http://somefoundry.com/license",
	"openTypeNameVersion"				 : "OpenType name Table Version",
	"openTypeNameUniqueID"				 : "OpenType name Table Unique ID",
	"openTypeNameDescription"			 : "Some Font by Some Designer for Some Foundry.",
	"openTypeNamePreferredFamilyName"	 : "Some Font (Preferred Family Name)",
	"openTypeNamePreferredSubfamilyName" : "Regular (Preferred Subfamily Name)",
	"openTypeNameCompatibleFullName"	 : "Some Font Regular (Compatible Full Name)",
	"openTypeNameSampleText"			 : "Sample Text for Some Font.",
	"openTypeNameWWSFamilyName"			 : "Some Font (WWS Family Name)",
	"openTypeNameWWSSubfamilyName"		 : "Regular (WWS Subfamily Name)",
	"openTypeOS2WidthClass"				 : 5,
	"openTypeOS2WeightClass"			 : 500,
	"openTypeOS2Selection"				 : [3],
	"openTypeOS2VendorID"				 : "SOME",
	"openTypeOS2Panose"					 : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
	"openTypeOS2FamilyClass"			 : [1, 1],
	"openTypeOS2UnicodeRanges"			 : [0, 1],
	"openTypeOS2CodePageRanges"			 : [0, 1],
	"openTypeOS2TypoAscender"			 : 750,
	"openTypeOS2TypoDescender"			 : -250,
	"openTypeOS2TypoLineGap"			 : 200,
	"openTypeOS2WinAscent"				 : 750,
	"openTypeOS2WinDescent"				 : -250,
	"openTypeOS2Type"					 : [],
	"openTypeOS2SubscriptXSize"			 : 200,
	"openTypeOS2SubscriptYSize"			 : 400,
	"openTypeOS2SubscriptXOffset"		 : 0,
	"openTypeOS2SubscriptYOffset"		 : -100,
	"openTypeOS2SuperscriptXSize"		 : 200,
	"openTypeOS2SuperscriptYSize"		 : 400,
	"openTypeOS2SuperscriptXOffset"		 : 0,
	"openTypeOS2SuperscriptYOffset"		 : 200,
	"openTypeOS2StrikeoutSize"			 : 20,
	"openTypeOS2StrikeoutPosition"		 : 300,
	"openTypeVheaVertTypoAscender"		 : 750,
	"openTypeVheaVertTypoDescender"		 : -250,
	"openTypeVheaVertTypoLineGap"		 : 200,
	"openTypeVheaCaretSlopeRise"		 : 0,
	"openTypeVheaCaretSlopeRun"			 : 1,
	"openTypeVheaCaretOffset"			 : 0,
	"postscriptFontName"				 : "SomeFont-Regular (Postscript Font Name)",
	"postscriptFullName"				 : "Some Font-Regular (Postscript Full Name)",
	"postscriptSlantAngle"				 : -12.5,
	"postscriptUniqueID"				 : 4000000,
	"postscriptUnderlineThickness"		 : 20,
	"postscriptUnderlinePosition"		 : -200,
	"postscriptIsFixedPitch"			 : False,
	"postscriptBlueValues"				 : [500, 510],
	"postscriptOtherBlues"				 : [-250, -260],
	"postscriptFamilyBlues"				 : [500, 510],
	"postscriptFamilyOtherBlues"		 : [-250, -260],
	"postscriptStemSnapH"				 : [100, 120],
	"postscriptStemSnapV"				 : [80, 90],
	"postscriptBlueFuzz"				 : 1,
	"postscriptBlueShift"				 : 7,
	"postscriptBlueScale"				 : 0.039625,
	"postscriptForceBold"				 : True,
	"postscriptDefaultWidthX"			 : 400,
	"postscriptNominalWidthX"			 : 400,
	"postscriptWeightName"				 : "Medium",
	"postscriptDefaultCharacter"		 : ".notdef",
	"postscriptWindowsCharacterSet"		 : 1,
	"macintoshFONDFamilyID"				 : 15000,
	"macintoshFONDName"					 : "SomeFont Regular (FOND Name)",
}

expectedFontInfo1To2Conversion = {
	"familyName"						: "Some Font (Family Name)",
	"styleMapFamilyName"				: "Some Font Regular (Style Map Family Name)",
	"styleMapStyleName"					: "regular",
	"styleName"							: "Regular (Style Name)",
	"unitsPerEm"						: 1000,
	"ascender"							: 750,
	"capHeight"							: 750,
	"xHeight"							: 500,
	"descender"							: -250,
	"italicAngle"						: -12.5,
	"versionMajor"						: 1,
	"versionMinor"						: 0,
	"year"								: 2008,
	"copyright"							: "Copyright Some Foundry.",
	"trademark"							: "Trademark Some Foundry",
	"note"								: "A note.",
	"macintoshFONDFamilyID"				: 15000,
	"macintoshFONDName"					: "SomeFont Regular (FOND Name)",
	"openTypeNameCompatibleFullName"	: "Some Font Regular (Compatible Full Name)",
	"openTypeNameDescription"			: "Some Font by Some Designer for Some Foundry.",
	"openTypeNameDesigner"				: "Some Designer",
	"openTypeNameDesignerURL"			: "http://somedesigner.com",
	"openTypeNameLicense"				: "License info for Some Foundry.",
	"openTypeNameLicenseURL"			: "http://somefoundry.com/license",
	"openTypeNameManufacturer"			: "Some Foundry",
	"openTypeNameManufacturerURL"		: "http://somefoundry.com",
	"openTypeNamePreferredFamilyName"	: "Some Font (Preferred Family Name)",
	"openTypeNamePreferredSubfamilyName": "Regular (Preferred Subfamily Name)",
	"openTypeNameCompatibleFullName"	: "Some Font Regular (Compatible Full Name)",
	"openTypeNameUniqueID"				: "OpenType name Table Unique ID",
	"openTypeNameVersion"				: "OpenType name Table Version",
	"openTypeOS2VendorID"				: "SOME",
	"openTypeOS2WeightClass"			: 500,
	"openTypeOS2WidthClass"				: 5,
	"postscriptDefaultWidthX"			: 400,
	"postscriptFontName"				: "SomeFont-Regular (Postscript Font Name)",
	"postscriptFullName"				: "Some Font-Regular (Postscript Full Name)",
	"postscriptSlantAngle"				: -12.5,
	"postscriptUniqueID"				: 4000000,
	"postscriptWeightName"				: "Medium",
	"postscriptWindowsCharacterSet"		: 1
}

expectedFontInfo2To1Conversion = {
	"familyName"  	: "Some Font (Family Name)",
	"menuName"	  	: "Some Font Regular (Style Map Family Name)",
	"fontStyle"	  	: 64,
	"styleName"	  	: "Regular (Style Name)",
	"unitsPerEm"  	: 1000,
	"ascender"	  	: 750,
	"capHeight"	  	: 750,
	"xHeight"	  	: 500,
	"descender"	  	: -250,
	"italicAngle" 	: -12.5,
	"versionMajor"	: 1,
	"versionMinor"	: 0,
	"copyright"	  	: "Copyright Some Foundry.",
	"trademark"	  	: "Trademark Some Foundry",
	"note"		  	: "A note.",
	"fondID"	  	: 15000,
	"fondName"	  	: "SomeFont Regular (FOND Name)",
	"fullName"	  	: "Some Font Regular (Compatible Full Name)",
	"notice"	  	: "Some Font by Some Designer for Some Foundry.",
	"designer"	  	: "Some Designer",
	"designerURL" 	: "http://somedesigner.com",
	"license"	  	: "License info for Some Foundry.",
	"licenseURL"  	: "http://somefoundry.com/license",
	"createdBy"	  	: "Some Foundry",
	"vendorURL"	  	: "http://somefoundry.com",
	"otFamilyName"	: "Some Font (Preferred Family Name)",
	"otStyleName" 	: "Regular (Preferred Subfamily Name)",
	"otMacName"	  	: "Some Font Regular (Compatible Full Name)",
	"ttUniqueID"  	: "OpenType name Table Unique ID",
	"ttVersion"	  	: "OpenType name Table Version",
	"ttVendor"	  	: "SOME",
	"weightValue" 	: 500,
	"widthName"	  	: "Medium (normal)",
	"defaultWidth"	: 400,
	"fontName"	  	: "SomeFont-Regular (Postscript Font Name)",
	"fullName"	  	: "Some Font-Regular (Postscript Full Name)",
	"slantAngle"  	: -12.5,
	"uniqueID"	  	: 4000000,
	"weightName"  	: "Medium",
	"msCharSet"	  	: 0,
	"year"			: 2008
}