class TestClosureTaker(unittest.TestCase):

  def setUp(self):
    """Loads font and initializes ClosureTaker
    """
    self.font = TTFont('test_data/NotoSans-Regular_subset.ttf')
    self.closureTaker = ClosureTaker(self.font)

  def test_c(self):
    """Takes closure of character 'c' Expected result is array: [3]
    """
    self.closureTaker.clear()
    self.closureTaker.add_glyph_names(['c'])
    gids = self.closureTaker.closure()
    self.assertTrue(gids == [3], 'Closure of c is [c]')

  def test_clear(self):
    """Takes closure of cleared input lists Expected result is array: []
    """
    self.closureTaker.clear()
    gids = self.closureTaker.closure()
    self.assertTrue(gids == [], 'Closure of empty is []')

  def tearDown(self):
    """Closes font
    """
    self.font.close()
示例#2
0
class TestClosureTaker(unittest.TestCase):
    def setUp(self):
        """Loads font and initializes ClosureTaker
    """
        self.font = TTFont('test_data/NotoSans-Regular_subset.ttf')
        self.closureTaker = ClosureTaker(self.font)

    def test_c(self):
        """Takes closure of character 'c' Expected result is array: [3]
    """
        self.closureTaker.clear()
        self.closureTaker.add_glyph_names(['c'])
        gids = self.closureTaker.closure()
        self.assertTrue(gids == [3], 'Closure of c is [c]')

    def test_clear(self):
        """Takes closure of cleared input lists Expected result is array: []
    """
        self.closureTaker.clear()
        gids = self.closureTaker.closure()
        self.assertTrue(gids == [], 'Closure of empty is []')

    def tearDown(self):
        """Closes font
    """
        self.font.close()
示例#3
0
def dump_closure_map(fontfile, outputfolder):
    """Takes closure of each glyph in the font and dump them into the two seperate files.

  Index file used to locate a glyph in data file.
  Data file contains closure lists
  """

    font = TTFont(fontfile)
    closurer = ClosureTaker(font)

    glyph_metadata = Dumper(outputfolder + "/closure_idx")
    glyph_data = Dumper(outputfolder + "/closure_data")
    bigEndian = ">"
    fmt_offset = ">l"  # offset - length
    fmt_size = ">H"
    fmt_elem = "H"
    elem_size = struct.calcsize(fmt_elem)
    offset = 0
    for g in font.getGlyphOrder():
        closurer.clear()
        closurer.add_glyph_names([g])
        glyphsClosure = closurer.closure()
        id = closurer.glyph_name_to_id[g]
        if len(glyphsClosure) == 1 and id in glyphsClosure:
            # recording not needed
            glyph_metadata.dump_fmt(-1, fmt_offset)
            glyph_metadata.dump_fmt(0, fmt_size)
        else:
            size = elem_size * len(glyphsClosure)
            glyph_data.dump_array(glyphsClosure, fmt_elem, bigEndian)
            glyph_metadata.dump_fmt(offset, fmt_offset)
            glyph_metadata.dump_fmt(size, fmt_size)
            # print id, g, glyphsClosure
            offset += size

    font.close()
    glyph_data.close()
    glyph_metadata.close()
示例#4
0
def dump_closure_map(fontfile, outputfolder):
    """Takes closure of each glyph in the font and dump them into the two seperate files.

  Index file used to locate a glyph in data file.
  Data file contains closure lists
  """

    font = TTFont(fontfile)
    closurer = ClosureTaker(font)

    glyph_metadata = Dumper(outputfolder + '/closure_idx')
    glyph_data = Dumper(outputfolder + '/closure_data')
    bigEndian = '>'
    fmt_offset = '>l'  # offset - length
    fmt_size = '>H'
    fmt_elem = 'H'
    elem_size = struct.calcsize(fmt_elem)
    offset = 0
    for g in font.getGlyphOrder():
        closurer.clear()
        closurer.add_glyph_names([g])
        glyphsClosure = closurer.closure()
        id = closurer.glyph_name_to_id[g]
        if len(glyphsClosure) == 1 and id in glyphsClosure:
            # recording not needed
            glyph_metadata.dump_fmt(-1, fmt_offset)
            glyph_metadata.dump_fmt(0, fmt_size)
        else:
            size = elem_size * len(glyphsClosure)
            glyph_data.dump_array(glyphsClosure, fmt_elem, bigEndian)
            glyph_metadata.dump_fmt(offset, fmt_offset)
            glyph_metadata.dump_fmt(size, fmt_size)
            #print id, g, glyphsClosure
            offset += size

    font.close()
    glyph_data.close()
    glyph_metadata.close()