Esempio n. 1
0
    def test_suggest_name_testcase_light(self):

        fontdata = {
            'names': [
                {
                    'nameID': 1,
                    'string': 'Roboto'
                },
            ],
            'OS/2': {
                'fsSelection': 0,  # Regular
                'usWeightClass': 300,  # Light
            },
            'post': {
                'italicAngle': 0
            },
            'head': {
                'macStyle': 0,  # Regular
            },
            'CFF': {
                'Weight': 400,  # This value have to be fixed to 300
            }
        }
        fontdata = utils.fix_all_names(fontdata, 'Roboto')
        self.assertEqual(fontdata['OS/2']['usWeightClass'], 300)
        self.assertEqual(fontdata['CFF']['Weight'],
                         fontdata['OS/2']['usWeightClass'])
        self.assertEqual([[1, 'Roboto Light'], [2, 'Regular'],
                          [4, 'Roboto Light'], [6, 'Roboto-Light'],
                          [16, 'Roboto'], [17, 'Light'], [18, 'Roboto Light']],
                         [[x['nameID'], x['string']]
                          for x in fontdata['names']])
Esempio n. 2
0
 def test_suggest_name_testcase_bold_italic(self):
     fontdata = {
         'names': [
             {
                 'nameID': 1,
                 'string': 'Roboto'
             },
         ],
         'OS/2': {
             'fsSelection': 0b10001,  # Bold & Italic
             # As font is Bold this value is always 700
             'usWeightClass': 700,
         },
         'post': {
             'italicAngle': -13
         },
         'head': {
             'macStyle': 0b11,  # Bold & Italic
         },
         'CFF': {
             'Weight': 400,  # This value have to be fixed to 700
         }
     }
     fontdata = utils.fix_all_names(fontdata, 'Roboto')
     self.assertEqual(fontdata['OS/2']['usWeightClass'], 700)
     self.assertEqual(fontdata['CFF']['Weight'],
                      fontdata['OS/2']['usWeightClass'])
     self.assertEqual(
         [[1, 'Roboto'], [2, 'Bold Italic'], [4, 'Roboto Bold Italic'],
          [6, 'Roboto-BoldItalic'], [16, 'Roboto'], [17, 'Bold Italic'],
          [18, 'Roboto Bold Italic']],
         [[x['nameID'], x['string']] for x in fontdata['names']])
Esempio n. 3
0
    def test_suggest_name_testcase_black(self):

        fontdata = {
            'names': [
                {
                    'nameID': 1,
                    'string': 'Family'
                },
            ],
            'OS/2': {
                'fsSelection': 0b00000,  # Regular
                'usWeightClass': 900,  # Bold
            },
            'head': {
                'macStyle': 0b00,  # Italic
            },
            'post': {
                'italicAngle': 0
            },
            'CFF': {
                'Weight': 400,  # This value have to be fixed to 300
            }
        }
        fontdata = utils.fix_all_names(fontdata, 'Family')
        self.assertEqual(fontdata['OS/2']['usWeightClass'], 900)
        self.assertEqual(fontdata['CFF']['Weight'],
                         fontdata['OS/2']['usWeightClass'])
        self.assertEqual([[1, 'Family Black'], [2, 'Regular'],
                          [4, 'Family Black'], [6, 'Family-Black'],
                          [16, 'Family'], [17, 'Black'], [18, 'Family Black']],
                         [[x['nameID'], x['string']]
                          for x in fontdata['names']])
Esempio n. 4
0
    def test_suggest_name_testcase_light(self):

        fontdata = {
            'names': [
                {'nameID': 1, 'string': 'Roboto'},
            ],
            'OS/2': {
                'fsSelection': 0,  # Regular
                'usWeightClass': 300,  # Light
            },
            'post': {
                'italicAngle': 0
            },
            'head': {
                'macStyle': 0,  # Regular
            },
            'CFF': {
                'Weight': 400,  # This value have to be fixed to 300
            }
        }
        fontdata = utils.fix_all_names(fontdata, 'Roboto')
        self.assertEqual(fontdata['OS/2']['usWeightClass'], 300)
        self.assertEqual(fontdata['CFF']['Weight'],
                         fontdata['OS/2']['usWeightClass'])
        self.assertEqual([
            [1, 'Roboto Light'],
            [2, 'Regular'],
            [4, 'Roboto Light'],
            [6, 'Roboto-Light'],
            [16, 'Roboto'],
            [17, 'Light'],
            [18, 'Roboto Light']], [[x['nameID'], x['string']]
                                    for x in fontdata['names']])
Esempio n. 5
0
 def test_suggest_name_testcase_bold_italic(self):
     fontdata = {
         'names': [
             {'nameID': 1, 'string': 'Roboto'},
         ],
         'OS/2': {
             'fsSelection': 0b10001,  # Bold & Italic
             # As font is Bold this value is always 700
             'usWeightClass': 700,
         },
         'post': {
             'italicAngle': -13
         },
         'head': {
             'macStyle': 0b11,  # Bold & Italic
         },
         'CFF': {
             'Weight': 400,  # This value have to be fixed to 700
         }
     }
     fontdata = utils.fix_all_names(fontdata, 'Roboto')
     self.assertEqual(fontdata['OS/2']['usWeightClass'], 700)
     self.assertEqual(fontdata['CFF']['Weight'],
                      fontdata['OS/2']['usWeightClass'])
     self.assertEqual([
         [1, 'Roboto'],
         [2, 'Bold Italic'],
         [4, 'Roboto Bold Italic'],
         [6, 'Roboto-BoldItalic'],
         [16, 'Roboto'],
         [17, 'Bold Italic'],
         [18, 'Roboto Bold Italic']], [[x['nameID'], x['string']]
                                       for x in fontdata['names']])
Esempio n. 6
0
    def test_suggest_name_testcase_black(self):

        fontdata = {
            'names': [
                {'nameID': 1, 'string': 'Family'},
            ],
            'OS/2': {
                'fsSelection': 0b00000,  # Regular
                'usWeightClass': 900,  # Bold
            },
            'head': {
                'macStyle': 0b00,  # Italic
            },
            'post': {
                'italicAngle': 0
            },
            'CFF': {
                'Weight': 400,  # This value have to be fixed to 300
            }
        }
        fontdata = utils.fix_all_names(fontdata, 'Family')
        self.assertEqual(fontdata['OS/2']['usWeightClass'], 900)
        self.assertEqual(fontdata['CFF']['Weight'],
                         fontdata['OS/2']['usWeightClass'])
        self.assertEqual([
            [1, 'Family Black'],
            [2, 'Regular'],
            [4, 'Family Black'],
            [6, 'Family-Black'],
            [16, 'Family'],
            [17, 'Black'],
            [18, 'Family Black']], [[x['nameID'], x['string']]
                                    for x in fontdata['names']])
Esempio n. 7
0
    def fix(self):
        # Convert huge and complex fontTools to config python dict
        fontdata = fontTools_to_dict(self.font)

        fontdata = clean_name_values(fontdata)
        familyname = ''
        for rec in fontdata['names']:
            if rec['nameID'] == 1:
                familyname = rec['string']
                break
        fontdata = fix_all_names(fontdata, familyname)

        logger.error('```')
        logger.error(os.path.basename(self.fontpath))
        logger.error('')
        for field in fontdata['names']:
            self.getOrCreateNameRecord(field['nameID'], field['string'])
        logger.error('```')
        return True
Esempio n. 8
0
    def fix(self):
        # Convert huge and complex fontTools to config python dict
        fontdata = fontTools_to_dict(self.font)

        fontdata = clean_name_values(fontdata)
        familyname = ''
        for rec in fontdata['names']:
            if rec['nameID'] == 1:
                familyname = rec['string']
                break
        fontdata = fix_all_names(fontdata, familyname)

        logger.error('```')
        logger.error(os.path.basename(self.fontpath))
        logger.error('')
        for field in fontdata['names']:
            self.getOrCreateNameRecord(field['nameID'], field['string'])
        logger.error('```')
        return True