run_general_tests.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/usr/bin/python
  2. # coding=UTF-8
  3. #
  4. # Copyright 2015 Google Inc. All Rights Reserved.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. """Test general health of the fonts."""
  18. import unittest
  19. from robofab.world import OpenFont
  20. from nototools.unittests import font_tests
  21. import roboto_data
  22. FONTS = font_tests.load_fonts(
  23. ['out/RobotoTTF/*.ttf', 'out/RobotoCondensedTTF/*.ttf'],
  24. expected_count=20)
  25. UFO_MASTERS = font_tests.load_fonts(
  26. ['src/v2/*.ufo'],
  27. expected_count=3,
  28. font_class=OpenFont)
  29. class TestItalicAngle(font_tests.TestItalicAngle):
  30. loaded_fonts = FONTS
  31. expected_italic_angle = -12.0
  32. class TestMetaInfo(font_tests.TestMetaInfo):
  33. """Bugs:
  34. https://github.com/google/roboto/issues/142
  35. https://code.google.com/a/google.com/p/roboto/issues/detail?id=8
  36. https://code.google.com/a/google.com/p/roboto/issues/detail?id=29
  37. """
  38. loaded_fonts = FONTS
  39. mark_heavier_as_bold = False
  40. mark_italic_as_oblique = True
  41. test_us_weight = None
  42. expected_version = roboto_data.get_version_number()
  43. # fsType of 0 marks the font free for installation, embedding, etc.
  44. expected_os2_fsType = 0
  45. expected_os2_achVendID = 'GOOG'
  46. class TestNames(font_tests.TestNames):
  47. """Bugs:
  48. https://github.com/google/roboto/issues/37
  49. """
  50. loaded_fonts = FONTS
  51. family_name = 'Roboto'
  52. mark_heavier_as_bold = False
  53. expected_copyright = 'Copyright 2011 Google Inc. All Rights Reserved.'
  54. def expected_unique_id(self, family, style):
  55. return 'Google:%s %s:2016' % (family, style)
  56. class TestDigitWidths(font_tests.TestDigitWidths):
  57. loaded_fonts = FONTS
  58. class TestCharacterCoverage(font_tests.TestCharacterCoverage):
  59. loaded_fonts = FONTS
  60. include = frozenset([
  61. 0x2117, # SOUND RECORDING COPYRIGHT
  62. 0xEE01, 0xEE02, 0xF6C3]) # legacy PUA
  63. exclude = frozenset([
  64. 0x2072, 0x2073, 0x208F] + # unassigned characters
  65. range(0xE000, 0xF8FF + 1) + range(0xF0000, 0x10FFFF + 1) # other PUA
  66. ) - include # don't exclude legacy PUA
  67. class TestLigatures(font_tests.TestLigatures):
  68. loaded_fonts = FONTS
  69. active = (
  70. (None, ('fi', 'fl', 'ffi', 'ffl')),
  71. ('--language=FRA', ('fi', 'fl', 'ffi', 'ffl')),
  72. ('--language=TRK', ('fl', 'ffl')),
  73. ('--features=dlig', ('ff', 'st', u'ſt')),
  74. )
  75. inactive = (
  76. (None, ('ff', 'st', u'ſt')),
  77. ('--language=TRK', ('fi', 'ffi')),
  78. ('--script=arab', ('fi', 'fl', 'ffi', 'ffl')),
  79. )
  80. class TestFeatures(font_tests.TestFeatures):
  81. loaded_fonts = FONTS
  82. smcp_reqs_path = 'res/smcp_requirements.txt'
  83. c2sc_reqs_path = 'res/c2sc_requirements.txt'
  84. unic_reqs_path = 'res/unic_requirements.txt'
  85. class TestVerticalMetrics(font_tests.TestVerticalMetrics):
  86. loaded_fonts = FONTS
  87. test_ymin_ymax = None
  88. test_hhea_table_metrics = None
  89. test_os2_metrics = None
  90. # tests yMin and yMax to be equal to Roboto v1 values
  91. # android requires this, and web fonts expect this
  92. expected_head_yMin = -555
  93. expected_head_yMax = 2163
  94. class TestGlyphBounds(font_tests.TestGlyphBounds):
  95. loaded_fonts = FONTS
  96. should_exceed = (
  97. (('chi',), (None, 0, None, None), 0, 'is it an alias of x?'),
  98. )
  99. should_not_exceed = (
  100. (('Epsilontonos', 'Etatonos', 'Iotatonos', 'Upsilontonos'),
  101. (-150, None, None, None), 0.4,
  102. 'may be susceptible to aggressive clipping'),
  103. (('uni1F1B', 'uni1F2B', 'uni1F3B', 'uni1F5B', 'uni1F9B'),
  104. (-550, None, None, None), 0.1,
  105. 'may be susceptible to aggressive clipping'),
  106. )
  107. class TestGlyphAreas(font_tests.TestGlyphAreas):
  108. master_weights_to_test = ['Thin', 'Bold']
  109. instance_weights_to_test = ['Thin', 'Regular', 'Bold']
  110. exclude = ['Condensed', 'Italic']
  111. master_glyph_sets = [
  112. f.replace('_', '-') for f in UFO_MASTERS[0]], UFO_MASTERS[1]
  113. instance_glyph_sets = FONTS[0], [f.getGlyphSet() for f in FONTS[1]]
  114. master_glyphs_to_test = UFO_MASTERS[1][0].keys()
  115. instance_glyphs_to_test = FONTS[1][0].getGlyphOrder()
  116. #TODO maybe fix masters so that whitelisting isn't necessary
  117. whitelist = [
  118. 'uni0488', # offset 20 units b/w masters, interpolated points are off
  119. 'uni2050' # has flipped component, so contour is backwards in master
  120. ]
  121. if __name__ == '__main__':
  122. unittest.main()