[ttLib] adding a test for cmap format 14 (unicode variation sequences) (#1436)
Adding a test for cmap format 14 (unicode variation sequences), in preparation for #1435
This commit is contained in:
parent
b920b3b36f
commit
855378477f
@ -1,9 +1,22 @@
|
|||||||
from __future__ import print_function, division, absolute_import, unicode_literals
|
from __future__ import print_function, division, absolute_import, unicode_literals
|
||||||
|
import io
|
||||||
|
import os
|
||||||
|
import re
|
||||||
from fontTools.misc.py23 import *
|
from fontTools.misc.py23 import *
|
||||||
from fontTools import ttLib
|
from fontTools import ttLib
|
||||||
|
from fontTools.fontBuilder import FontBuilder
|
||||||
import unittest
|
import unittest
|
||||||
from fontTools.ttLib.tables._c_m_a_p import CmapSubtable, table__c_m_a_p
|
from fontTools.ttLib.tables._c_m_a_p import CmapSubtable, table__c_m_a_p
|
||||||
|
|
||||||
|
CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
DATA_DIR = os.path.join(CURR_DIR, 'data')
|
||||||
|
CMAP_FORMAT_14_TTX = os.path.join(DATA_DIR, "_c_m_a_p_format_14.ttx")
|
||||||
|
|
||||||
|
def strip_VariableItems(string):
|
||||||
|
# ttlib changes with the fontTools version
|
||||||
|
string = re.sub(' ttLibVersion=".*"', '', string)
|
||||||
|
return string
|
||||||
|
|
||||||
class CmapSubtableTest(unittest.TestCase):
|
class CmapSubtableTest(unittest.TestCase):
|
||||||
|
|
||||||
def makeSubtable(self, cmapFormat, platformID, platEncID, langID):
|
def makeSubtable(self, cmapFormat, platformID, platEncID, langID):
|
||||||
@ -82,6 +95,34 @@ class CmapSubtableTest(unittest.TestCase):
|
|||||||
self.assertEqual(font.getBestCmap(cmapPreferences=[(3, 1)]), {0x0041:'A', 0x0391:'A'})
|
self.assertEqual(font.getBestCmap(cmapPreferences=[(3, 1)]), {0x0041:'A', 0x0391:'A'})
|
||||||
self.assertEqual(font.getBestCmap(cmapPreferences=[(0, 4)]), None)
|
self.assertEqual(font.getBestCmap(cmapPreferences=[(0, 4)]), None)
|
||||||
|
|
||||||
|
def test_format_14(self):
|
||||||
|
subtable = self.makeSubtable(14, 0, 5, 0)
|
||||||
|
subtable.cmap = {} # dummy
|
||||||
|
subtable.uvsDict = {
|
||||||
|
0xFE00: [[0x0030, "zero.slash"]],
|
||||||
|
0xFE01: [(0x0030, None)], # yes, tuple here, list above, to match decompile
|
||||||
|
}
|
||||||
|
fb = FontBuilder(1024, isTTF=True)
|
||||||
|
font = fb.font
|
||||||
|
fb.setupGlyphOrder([".notdef", "zero.slash"])
|
||||||
|
fb.setupMaxp()
|
||||||
|
fb.setupPost()
|
||||||
|
cmap = table__c_m_a_p()
|
||||||
|
cmap.tableVersion = 0
|
||||||
|
cmap.tables = [subtable]
|
||||||
|
font["cmap"] = cmap
|
||||||
|
f = io.BytesIO()
|
||||||
|
font.save(f)
|
||||||
|
f.seek(0)
|
||||||
|
font = ttLib.TTFont(f)
|
||||||
|
self.assertEqual(font["cmap"].getcmap(0, 5).uvsDict, subtable.uvsDict)
|
||||||
|
f = io.StringIO(newline=None)
|
||||||
|
font.saveXML(f, tables=["cmap"])
|
||||||
|
ttx = strip_VariableItems(f.getvalue())
|
||||||
|
with open(CMAP_FORMAT_14_TTX) as f:
|
||||||
|
expected = strip_VariableItems(f.read())
|
||||||
|
self.assertEqual(ttx, expected)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
|
12
Tests/ttLib/tables/data/_c_m_a_p_format_14.ttx
Normal file
12
Tests/ttLib/tables/data/_c_m_a_p_format_14.ttx
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.35">
|
||||||
|
|
||||||
|
<cmap>
|
||||||
|
<tableVersion version="0"/>
|
||||||
|
<cmap_format_14 platformID="0" platEncID="5" format="14" length="49" numVarSelectorRecords="2">
|
||||||
|
<map uvs="0xfe00" uv="0x30" name="zero.slash"/>
|
||||||
|
<map uvs="0xfe01" uv="0x30" name="None"/>
|
||||||
|
</cmap_format_14>
|
||||||
|
</cmap>
|
||||||
|
|
||||||
|
</ttFont>
|
Loading…
x
Reference in New Issue
Block a user