repack_test.py 843 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python3
  2. import os
  3. # Parses a single repacking test file. The first line of the file is
  4. # the name of the font to use and the remaining lines define the set of
  5. # codepoints in the subset.
  6. class RepackTest:
  7. def __init__(self, test_path, definition):
  8. self.test_path = test_path
  9. self.font_name = None
  10. self.codepoints = set ()
  11. self._parse(definition)
  12. def font_path(self):
  13. return os.path.join (self._base_path (), "fonts", self.font_name)
  14. def codepoints_string (self):
  15. return ",".join (self.codepoints)
  16. def _base_path(self):
  17. return os.path.join(
  18. os.path.dirname(self.test_path),
  19. "../")
  20. def _parse(self, definition):
  21. lines = definition.splitlines ()
  22. self.font_name = lines.pop (0)
  23. for line in lines:
  24. line = line.strip()
  25. if not line:
  26. continue
  27. self.codepoints.add (line)