touchup_for_android.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/python
  2. #
  3. # Copyright 2015 Google Inc. All Rights Reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """Post-build changes for Roboto for Android."""
  17. import sys
  18. from fontTools import ttLib
  19. from nototools import font_data
  20. import temporary_touchups
  21. def apply_android_specific_fixes(font):
  22. """Apply fixes needed for Android."""
  23. # Remove combining keycap and the arrows from the cmap table:
  24. # https://github.com/google/roboto/issues/99
  25. font_data.delete_from_cmap(font, [
  26. 0x20E3, # COMBINING ENCLOSING KEYCAP
  27. 0x2191, # UPWARDS ARROW
  28. 0x2193, # DOWNWARDS ARROW
  29. ])
  30. # Drop tables not useful on Android
  31. for table in ['LTSH', 'hdmx', 'VDMX', 'gasp']:
  32. if table in font:
  33. del font[table]
  34. # turn off round-to-grid flags in certain problem components
  35. # https://github.com/google/roboto/issues/153
  36. glyph_set = font.getGlyphSet()
  37. ellipsis = glyph_set['ellipsis']._glyph
  38. for component in ellipsis.components:
  39. component.flags &= ~(1 << 2)
  40. def correct_font(source_font_name, target_font_name):
  41. """Corrects metrics and other meta information."""
  42. font = ttLib.TTFont(source_font_name)
  43. temporary_touchups.apply_temporary_fixes(font)
  44. temporary_touchups.update_version_and_revision(font)
  45. apply_android_specific_fixes(font)
  46. font.save(target_font_name)
  47. def main(argv):
  48. """Correct the font specified in the command line."""
  49. correct_font(argv[1], argv[2])
  50. if __name__ == "__main__":
  51. main(sys.argv)