Blame Tests/cffLib/cffLib_test.py

rpm-build 6a2e4c
from __future__ import print_function, division, absolute_import
rpm-build 6a2e4c
from fontTools.cffLib import TopDict, PrivateDict, CharStrings
rpm-build 6a2e4c
from fontTools.misc.testTools import parseXML, DataFilesHandler
rpm-build 6a2e4c
from fontTools.ttLib import TTFont
rpm-build 6a2e4c
import sys
rpm-build 6a2e4c
import unittest
rpm-build 6a2e4c
rpm-build 6a2e4c
rpm-build 6a2e4c
class CffLibTest(DataFilesHandler):
rpm-build 6a2e4c
rpm-build 6a2e4c
    def test_topDict_recalcFontBBox(self):
rpm-build 6a2e4c
        topDict = TopDict()
rpm-build 6a2e4c
        topDict.CharStrings = CharStrings(None, None, None, PrivateDict(), None, None)
rpm-build 6a2e4c
        topDict.CharStrings.fromXML(None, None, parseXML("""
rpm-build 6a2e4c
            <CharString name=".notdef">
rpm-build 6a2e4c
              endchar
rpm-build 6a2e4c
            </CharString>
rpm-build 6a2e4c
            <CharString name="foo">
rpm-build 6a2e4c
              100 -100 rmoveto 200 hlineto 200 vlineto -200 hlineto endchar
rpm-build 6a2e4c
            </CharString>
rpm-build 6a2e4c
            <CharString name="bar">
rpm-build 6a2e4c
              0 0 rmoveto 200 hlineto 200 vlineto -200 hlineto endchar
rpm-build 6a2e4c
            </CharString>
rpm-build 6a2e4c
            <CharString name="baz">
rpm-build 6a2e4c
              -55.1 -55.1 rmoveto 110.2 hlineto 110.2 vlineto -110.2 hlineto endchar
rpm-build 6a2e4c
            </CharString>
rpm-build 6a2e4c
        """))
rpm-build 6a2e4c
rpm-build 6a2e4c
        topDict.recalcFontBBox()
rpm-build 6a2e4c
        self.assertEqual(topDict.FontBBox, [-56, -100, 300, 200])
rpm-build 6a2e4c
rpm-build 6a2e4c
    def test_topDict_recalcFontBBox_empty(self):
rpm-build 6a2e4c
        topDict = TopDict()
rpm-build 6a2e4c
        topDict.CharStrings = CharStrings(None, None, None, PrivateDict(), None, None)
rpm-build 6a2e4c
        topDict.CharStrings.fromXML(None, None, parseXML("""
rpm-build 6a2e4c
            <CharString name=".notdef">
rpm-build 6a2e4c
              endchar
rpm-build 6a2e4c
            </CharString>
rpm-build 6a2e4c
            <CharString name="space">
rpm-build 6a2e4c
              123 endchar
rpm-build 6a2e4c
            </CharString>
rpm-build 6a2e4c
        """))
rpm-build 6a2e4c
rpm-build 6a2e4c
        topDict.recalcFontBBox()
rpm-build 6a2e4c
        self.assertEqual(topDict.FontBBox, [0, 0, 0, 0])
rpm-build 6a2e4c
rpm-build 6a2e4c
    def test_topDict_set_Encoding(self):
rpm-build 6a2e4c
        file_name = 'TestOTF.otf'
rpm-build 6a2e4c
        font_path = self.getpath(file_name)
rpm-build 6a2e4c
        temp_path = self.temp_font(font_path, file_name)
rpm-build 6a2e4c
        save_path = temp_path[:-4] + '2.otf'
rpm-build 6a2e4c
        font = TTFont(temp_path)
rpm-build 6a2e4c
        topDict = font["CFF "].cff.topDictIndex[0]
rpm-build 6a2e4c
        encoding = [".notdef"] * 256
rpm-build 6a2e4c
        encoding[0x20] = "space"
rpm-build 6a2e4c
        topDict.Encoding = encoding
rpm-build 6a2e4c
        font.save(save_path)
rpm-build 6a2e4c
        font2 = TTFont(save_path)
rpm-build 6a2e4c
        topDict2 = font2["CFF "].cff.topDictIndex[0]
rpm-build 6a2e4c
        self.assertEqual(topDict2.Encoding[32], "space")
rpm-build 6a2e4c
rpm-build 6a2e4c
rpm-build 6a2e4c
if __name__ == "__main__":
rpm-build 6a2e4c
    sys.exit(unittest.main())