test_android.py 3.3 KB

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