touchup_for_cros.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/python
  2. #
  3. # Copyright 2016 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 to deploy on Google Chrome/Chromium OS"""
  17. import sys
  18. from fontTools import ttLib
  19. from nototools import font_data
  20. from touchup_for_web import apply_web_cros_common_fixes
  21. import temporary_touchups
  22. def drop_non_windows_name_records(font):
  23. """Drop name records whose (PID,EID,Lang) != (3,1,0x409)"""
  24. names = font['name'].names
  25. records_to_drop = set()
  26. for record_number, record in enumerate(names):
  27. name_ids = (record.platformID, record.platEncID, record.langID)
  28. if name_ids != (3, 1, 0x409):
  29. records_to_drop.add(record_number)
  30. # Taken from nototools/font_data.py
  31. if records_to_drop:
  32. font['name'].names = [
  33. record for record_number, record in enumerate(names)
  34. if record_number not in records_to_drop]
  35. def correct_font(source_name, unhinted_name, target_font_name, family_name):
  36. """Corrects metrics and other meta information."""
  37. font = ttLib.TTFont(source_name)
  38. unhinted = ttLib.TTFont(unhinted_name)
  39. apply_web_cros_common_fixes(font, unhinted, family_name)
  40. temporary_touchups.apply_temporary_fixes(font, is_for_cros=True)
  41. temporary_touchups.update_version_and_revision(font)
  42. drop_non_windows_name_records(font)
  43. font.save(target_font_name)
  44. def main(argv):
  45. """Correct the font specified in the command line."""
  46. correct_font(*argv[1:])
  47. if __name__ == "__main__":
  48. main(sys.argv)