temporary_touchups.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright 2015 Google Inc. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Temporary post-build changes for Roboto."""
  15. from datetime import date
  16. from nototools import font_data
  17. from nototools import noto_fonts
  18. import roboto_data
  19. def apply_temporary_fixes(font, is_for_cros=False, is_for_web=False):
  20. """Apply some temporary fixes."""
  21. # Fix usWeight:
  22. font_name = font_data.font_name(font)
  23. weight = noto_fonts.parse_weight(font_name)
  24. weight_number = noto_fonts.WEIGHTS[weight]
  25. # Chrome OS wants Thin to have usWeightClass=100
  26. if is_for_cros and weight == 'Thin':
  27. weight_number = 100
  28. font['OS/2'].usWeightClass = weight_number
  29. # Set bold bits for Black (macStyle bit 0, fsSelection bit 5)
  30. if is_for_web is False:
  31. name_records = font_data.get_name_records(font)
  32. family_name = name_records[1]
  33. if family_name.endswith('Black'):
  34. font['head'].macStyle |= (1 << 0)
  35. font['OS/2'].fsSelection |= (1 << 5)
  36. font['OS/2'].fsSelection &= ~(1 << 6)
  37. def update_version_and_revision(font):
  38. """Update version and revision numbers."""
  39. version_number = roboto_data.get_version_number()
  40. version_record = 'Version %s; %d' % (version_number, date.today().year)
  41. font_data.set_name_record(font, 5, version_record)
  42. font['head'].fontRevision = float(version_number)