test_android.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. from fontbakery.callable import check
  2. from fontbakery.callable import condition
  3. from fontbakery.checkrunner import Section, PASS, FAIL, WARN
  4. from fontbakery.fonts_profile import profile_factory
  5. from tests.test_general import (
  6. include_features,
  7. font_features,
  8. com_roboto_fonts_check_italic_angle,
  9. com_roboto_fonts_check_fs_type,
  10. com_roboto_fonts_check_vendorid,
  11. com_roboto_fonts_check_digit_widths,
  12. com_roboto_fonts_check_charset_coverage,
  13. com_roboto_fonts_check_features,
  14. )
  15. from fontbakery.profiles.shared_conditions import is_italic
  16. profile = profile_factory(default_section=Section("Roboto android v3"))
  17. exclude_glyphs = frozenset([0x00A0])
  18. ROBOTO_PROFILE_CHECKS = [
  19. "com.roboto.fonts/check/vertical_metrics",
  20. "com.roboto.fonts/check/italic_angle",
  21. "com.roboto.fonts/check/fs_type",
  22. "com.roboto.fonts/check/vendorid",
  23. "com.roboto.fonts/check/digit_widths",
  24. "com.roboto.fonts/check/glyph_dont_round_to_grid",
  25. "com.roboto.fonts/check/charset_coverage",
  26. "com.roboto.fonts/check/features",
  27. ]
  28. @condition
  29. def include_glyphs():
  30. return frozenset([
  31. 0x2117, # SOUND RECORDING COPYRIGHT
  32. 0xEE01, 0xEE02, 0xF6C3] +
  33. list(range(0x0000, 0x0020)) # First 32 control characters
  34. ) # legacy PUA
  35. @condition
  36. def exclude_glyphs():
  37. return frozenset([
  38. 0x20E3, # COMBINING ENCLOSING KEYCAP
  39. 0x2191, # UPWARDS ARROW
  40. 0x2193, # DOWNWARDS ARROW
  41. 0x2072, 0x2073, 0x208F] + # unassigned characters
  42. list(range(0xE000, 0xF8FF + 1)) + list(range(0xF0000, 0x10FFFF + 1)) # other PUA
  43. ) - include_glyphs() # don't exclude legacy PUA
  44. @check(
  45. id="com.roboto.fonts/check/glyph_dont_round_to_grid",
  46. )
  47. def com_roboto_fonts_check_glyph_dont_round_to_grid(ttFont):
  48. """Test certain glyphs don't round to grid"""
  49. failed = False
  50. for name in ["ellipsis"]:
  51. glyph = ttFont["glyf"][name]
  52. for component in glyph.components:
  53. if component.flags & (1 << 2):
  54. failed = True
  55. yield FAIL, f"Round to grid flag must be disabled for '{name}' components"
  56. if not failed:
  57. yield PASS, "Glyphs do not have round to grid enabled"
  58. # test names
  59. @check(
  60. id="com.roboto.fonts/check/vertical_metrics",
  61. )
  62. def com_roboto_fonts_check_vertical_metrics(ttFont):
  63. """Check vertical metrics are correct"""
  64. failed = []
  65. expected = {
  66. # Android values come from v2.136 android fonts
  67. # https://github.com/googlefonts/roboto/releases/tag/v2.136
  68. ("head", "yMin"): -555,
  69. ("head", "yMax"): 2163,
  70. ("hhea", "descent"): -500,
  71. ("hhea", "ascent"): 1900,
  72. ("hhea", "lineGap"): 0,
  73. ("OS/2", "sTypoDescender"): -555,
  74. ("OS/2", "sTypoAscender"): 2146,
  75. ("OS/2", "sTypoLineGap"): 0,
  76. ("OS/2", "usWinDescent"): 555,
  77. ("OS/2", "usWinAscent"): 2146,
  78. }
  79. for (table, k), v in expected.items():
  80. font_val = getattr(ttFont[table], k)
  81. if font_val != v:
  82. failed.append((table, k, v, font_val))
  83. if not failed:
  84. yield PASS, "Fonts have correct vertical metrics"
  85. else:
  86. msg = "\n".join(
  87. [
  88. f"- {tbl}.{k} is {font_val} it should be {v}"
  89. for tbl, k, v, font_val in failed
  90. ]
  91. )
  92. yield FAIL, f"Fonts have incorrect vertical metrics:\n{msg}"
  93. # ligatures
  94. profile.auto_register(globals())
  95. profile.test_expected_checks(ROBOTO_PROFILE_CHECKS, exclusive=True)