• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from fontTools.misc.py23 import *
2from fontTools import ttLib
3from fontTools.merge import *
4import unittest
5
6
7class MergeIntegrationTest(unittest.TestCase):
8	# TODO
9	pass
10
11class gaspMergeUnitTest(unittest.TestCase):
12	def setUp(self):
13		self.merger = Merger()
14
15		self.table1 = ttLib.newTable('gasp')
16		self.table1.version = 1
17		self.table1.gaspRange = {
18			0x8: 0xA ,
19			0x10: 0x5,
20		}
21
22		self.table2 = ttLib.newTable('gasp')
23		self.table2.version = 1
24		self.table2.gaspRange = {
25			0x6: 0xB ,
26			0xFF: 0x4,
27		}
28
29		self.result = ttLib.newTable('gasp')
30
31	def test_gasp_merge_basic(self):
32		result = self.result.merge(self.merger, [self.table1, self.table2])
33		self.assertEqual(result, self.table1)
34
35		result = self.result.merge(self.merger, [self.table2, self.table1])
36		self.assertEqual(result, self.table2)
37
38	def test_gasp_merge_notImplemented(self):
39		result = self.result.merge(self.merger, [NotImplemented, self.table1])
40		self.assertEqual(result, NotImplemented)
41
42		result = self.result.merge(self.merger, [self.table1, NotImplemented])
43		self.assertEqual(result, self.table1)
44
45
46class CmapMergeUnitTest(unittest.TestCase):
47	def setUp(self):
48		self.merger = Merger()
49		self.table1 = ttLib.newTable('cmap')
50		self.table2 = ttLib.newTable('cmap')
51		self.mergedTable = ttLib.newTable('cmap')
52		pass
53
54	def tearDown(self):
55		pass
56
57
58	def makeSubtable(self, format, platformID, platEncID, cmap):
59		module = ttLib.getTableModule('cmap')
60		subtable = module.cmap_classes[format](format)
61		(subtable.platformID,
62			subtable.platEncID,
63			subtable.language,
64			subtable.cmap) = (platformID, platEncID, 0, cmap)
65		return subtable
66
67	# 4-3-1 table merged with 12-3-10 table with no dupes with codepoints outside BMP
68	def test_cmap_merge_no_dupes(self):
69		table1 = self.table1
70		table2 = self.table2
71		mergedTable = self.mergedTable
72
73		cmap1 = {0x2603: 'SNOWMAN'}
74		table1.tables = [self.makeSubtable(4,3,1, cmap1)]
75
76		cmap2 = {0x26C4: 'SNOWMAN WITHOUT SNOW'}
77		cmap2Extended = {0x1F93C: 'WRESTLERS'}
78		cmap2Extended.update(cmap2)
79		table2.tables = [self.makeSubtable(4,3,1, cmap2), self.makeSubtable(12,3,10, cmap2Extended)]
80
81		self.merger.alternateGlyphsPerFont = [{},{}]
82		mergedTable.merge(self.merger, [table1, table2])
83
84		expectedCmap = cmap2.copy()
85		expectedCmap.update(cmap1)
86		expectedCmapExtended = cmap2Extended.copy()
87		expectedCmapExtended.update(cmap1)
88		self.assertEqual(mergedTable.numSubTables, 2)
89		self.assertEqual([(table.format, table.platformID, table.platEncID, table.language) for table in mergedTable.tables],
90			[(4,3,1,0),(12,3,10,0)])
91		self.assertEqual(mergedTable.tables[0].cmap, expectedCmap)
92		self.assertEqual(mergedTable.tables[1].cmap, expectedCmapExtended)
93
94	# Tests Issue #322
95	def test_cmap_merge_three_dupes(self):
96		table1 = self.table1
97		table2 = self.table2
98		mergedTable = self.mergedTable
99
100		cmap1 = {0x20: 'space#0', 0xA0: 'space#0'}
101		table1.tables = [self.makeSubtable(4,3,1,cmap1)]
102		cmap2 = {0x20: 'space#1', 0xA0: 'uni00A0#1'}
103		table2.tables = [self.makeSubtable(4,3,1,cmap2)]
104
105		self.merger.duplicateGlyphsPerFont = [{},{}]
106		mergedTable.merge(self.merger, [table1, table2])
107
108		expectedCmap = cmap1.copy()
109		self.assertEqual(mergedTable.numSubTables, 1)
110		table = mergedTable.tables[0]
111		self.assertEqual((table.format, table.platformID, table.platEncID, table.language), (4,3,1,0))
112		self.assertEqual(table.cmap, expectedCmap)
113		self.assertEqual(self.merger.duplicateGlyphsPerFont, [{}, {'space#0': 'space#1'}])
114
115
116if __name__ == "__main__":
117	import sys
118	sys.exit(unittest.main())
119