diff options
-rw-r--r-- | scripts/common_tests.py | 94 | ||||
-rw-r--r-- | scripts/roboto_data.py | 24 | ||||
-rwxr-xr-x | scripts/run_general_tests.py | 1 | ||||
-rwxr-xr-x | scripts/run_web_tests.py | 14 | ||||
-rw-r--r-- | scripts/temporary_touchups.py | 5 |
5 files changed, 98 insertions, 40 deletions
diff --git a/scripts/common_tests.py b/scripts/common_tests.py index 54dff86..952e794 100644 --- a/scripts/common_tests.py +++ b/scripts/common_tests.py @@ -17,11 +17,13 @@ """Common tests for different targets.""" import glob +from os import path import unittest from fontTools import ttLib from nototools import coverage from nototools import font_data +from nototools import noto_fonts import freetype @@ -86,6 +88,8 @@ class TestItalicAngle(FontTest): class TestMetaInfo(FontTest): """Test various meta information.""" + mark_heavier_as_bold = False + def setUp(self): _, self.fonts = self.loaded_fonts @@ -96,7 +100,8 @@ class TestMetaInfo(FontTest): """ for font in self.fonts: font_name = font_data.font_name(font) - bold = ('Bold' in font_name) or ('Black' in font_name) + bold = ('Bold' in font_name) or ( + self.mark_heavier_as_bold and 'Black' in font_name) italic = 'Italic' in font_name expected_mac_style = (italic << 1) | bold self.assertEqual(font['head'].macStyle, expected_mac_style) @@ -119,8 +124,8 @@ class TestMetaInfo(FontTest): def test_us_weight(self): "Tests the usWeight of the fonts to be correct.""" for font in self.fonts: - weight = roboto_data.extract_weight_name(font_data.font_name(font)) - expected_numeric_weight = roboto_data.WEIGHTS[weight] + weight = noto_fonts.parse_weight(font_data.font_name(font)) + expected_numeric_weight = noto_fonts.WEIGHTS[weight] self.assertEqual( font['OS/2'].usWeightClass, expected_numeric_weight) @@ -142,8 +147,11 @@ class TestMetaInfo(FontTest): class TestNames(FontTest): """Tests various strings in the name table.""" + mark_heavier_as_bold = False + def setUp(self): - _, self.fonts = self.loaded_fonts + font_files, self.fonts = self.loaded_fonts + self.font_files = [path.basename(f) for f in font_files] self.condensed_family_name = self.family_name + ' Condensed' self.names = [] for font in self.fonts: @@ -156,13 +164,79 @@ class TestNames(FontTest): records[0], 'Copyright 2011 Google Inc. All Rights Reserved.') + def parse_filename(self, filename): + """Parse expected name attributes from filename.""" + + name_nosp = self.family_name.replace(' ', '') + condensed_name_nosp = self.condensed_family_name.replace(' ', '') + family_names = '%s|%s' % (condensed_name_nosp, name_nosp) + + filename_match = noto_fonts.match_filename(filename, family_names) + family, _, _, _, _, weight, slope, _ = filename_match.groups() + + if family == condensed_name_nosp: + family = self.condensed_family_name + else: # family == name_nosp + family = self.family_name + if not weight: + weight = 'Regular' + return family, weight, slope + + def build_style(self, weight, slope): + """Build style (typographic subfamily) out of weight and slope.""" + + style = weight + if slope: + if style == 'Regular': + style = 'Italic' + else: + style += ' ' + slope + return style + def test_family_name(self): - """Tests the family name.""" - for records in self.names: - self.assertIn(records[1], - [self.family_name, self.condensed_family_name]) - if 16 in records: - self.assertEqual(records[16], records[1]) + """Tests the family name. + Bug: https://github.com/google/roboto/issues/37 + """ + + for font_file, records in zip(self.font_files, self.names): + + family, weight, _ = self.parse_filename(font_file) + + # check that family name includes weight, if not regular or bold + if weight not in ['Regular', 'Bold']: + self.assertEqual(records[1], '%s %s' % (family, weight)) + + # check typographic name, if present + self.assertIn(16, records) + self.assertEqual(records[16], family) + + # check that family name does not include weight, if regular or bold + else: + self.assertEqual(records[1], family) + + def test_subfamily_name(self): + """Tests the subfamily name. + Bug: https://github.com/google/roboto/issues/37 + """ + + for font_file, records in zip(self.font_files, self.names): + _, weight, slope = self.parse_filename(font_file) + subfam = records[2] + + # check that subfamily is just a combination of bold and italic + self.assertIn(subfam, ['Regular', 'Bold', 'Italic', 'Bold Italic']) + + # check that subfamily weight/slope are consistent with filename + bold = (weight == 'Bold') or ( + self.mark_heavier_as_bold and + noto_fonts.WEIGHTS[weight] > noto_fonts.WEIGHTS['Bold']) + self.assertEqual(bold, subfam.startswith('Bold')) + self.assertEqual(slope == 'Italic', subfam.endswith('Italic')) + + # check typographic name, if present + if weight not in ['Regular', 'Bold']: + self.assertIn(17, records) + self.assertEqual(records[17], self.build_style(weight, slope)) def test_postscript_name_for_spaces(self): """Tests that there are no spaces in PostScript names.""" diff --git a/scripts/roboto_data.py b/scripts/roboto_data.py index 2e4f2e9..a9a947a 100644 --- a/scripts/roboto_data.py +++ b/scripts/roboto_data.py @@ -19,30 +19,6 @@ from os import path import re -WEIGHTS = { - 'Thin': 250, - 'Light': 300, - 'Regular': 400, - 'Medium': 500, - 'Bold': 700, - 'Black': 900, -} - -_ALL_WEIGHTS_RE = re.compile( - '(' + '|'.join(WEIGHTS.keys()) + ')' -) - - -def extract_weight_name(font_name): - """Extracts the weight part of the name from a font name.""" - match = re.search(_ALL_WEIGHTS_RE, font_name) - if match is None: - assert re.match('^Roboto(Draft)?( Condensed)? Italic$', font_name) - return 'Regular' - else: - return match.group(1) - - def get_build_number(): """Returns the build number as a five-digit string.""" build_number_txt = path.join( diff --git a/scripts/run_general_tests.py b/scripts/run_general_tests.py index 297c37c..7ec8fcc 100755 --- a/scripts/run_general_tests.py +++ b/scripts/run_general_tests.py @@ -42,6 +42,7 @@ class TestItalicAngle(common_tests.TestItalicAngle): class TestMetaInfo(common_tests.TestMetaInfo): loaded_fonts = FONTS + mark_heavier_as_bold = True test_us_weight = None test_version_numbers = None diff --git a/scripts/run_web_tests.py b/scripts/run_web_tests.py index 3ff483a..f201114 100755 --- a/scripts/run_web_tests.py +++ b/scripts/run_web_tests.py @@ -32,6 +32,7 @@ class TestItalicAngle(common_tests.TestItalicAngle): class TestMetaInfo(common_tests.TestMetaInfo): loaded_fonts = FONTS + mark_heavier_as_bold = True # Since different font files are hinted at different times, the actual # outlines differ slightly. So we are keeping the version numbers as a hint. test_version_numbers = None @@ -40,19 +41,24 @@ class TestMetaInfo(common_tests.TestMetaInfo): class TestNames(common_tests.TestNames): loaded_fonts = FONTS family_name = 'Roboto' + mark_heavier_as_bold = True def test_unique_identifier_and_full_name(self): """Tests the unique identifier and full name.""" - for records in self.names: - expected_name = records[1] + ' ' + records[2] + for font_file, records in zip(self.font_files, self.names): + family, weight, slope = self.parse_filename(font_file) + style = self.build_style(weight, slope) + expected_name = family + ' ' + style self.assertEqual(records[3], expected_name) self.assertEqual(records[4], expected_name) self.assertFalse(records.has_key(18)) def test_postscript_name(self): """Tests the postscript name.""" - for records in self.names: - expected_name = (records[1] + '-' + records[2]).replace(' ', '') + for font_file, records in zip(self.font_files, self.names): + family, weight, slope = self.parse_filename(font_file) + style = self.build_style(weight, slope) + expected_name = (family + '-' + style).replace(' ', '') self.assertEqual(records[6], expected_name) diff --git a/scripts/temporary_touchups.py b/scripts/temporary_touchups.py index 9997adc..8953b64 100644 --- a/scripts/temporary_touchups.py +++ b/scripts/temporary_touchups.py @@ -16,6 +16,7 @@ from datetime import date from nototools import font_data +from nototools import noto_fonts import roboto_data @@ -23,8 +24,8 @@ def apply_temporary_fixes(font): """Apply some temporary fixes.""" # Fix usWeight: font_name = font_data.font_name(font) - weight = roboto_data.extract_weight_name(font_name) - weight_number = roboto_data.WEIGHTS[weight] + weight = noto_fonts.parse_weight(font_name) + weight_number = noto_fonts.WEIGHTS[weight] font['OS/2'].usWeightClass = weight_number # Set ascent, descent, and lineGap values to Android K values |