def getFonts_sortBy(self, attr, values): fonts = FontList() for value in values: font = self.getFont() setattr(font.info, attr, value) if attr != "familyName": font.info.familyName = "%s %s" % (attr, repr(value)) fonts.append(font) return fonts
def getFonts_sortBy(self, attr, values): fonts = FontList() for value in values: font = self.getFont() setattr(font.info, attr, value) if attr != "familyName": font.info.familyName = "%s %s" % (attr, repr(value)) fonts.append(font) return fonts
def test_sortBy_isProportional_glyphs(self): font1 = self.getFont_sortBy_monospaceGlyphs() font2 = self.getFont_sortBy_monospaceGlyphs() font3 = self.getFont_sortBy_proportionalGlyphs() font4 = self.getFont_sortBy_proportionalGlyphs() fonts = FontList() fonts.extend([font1, font2, font3, font4]) fonts.sortBy("isProportional") expected = [font3, font4, font1, font2] self.assertEqual(fonts, expected)
def test_getFontsByStyleName(self): font1 = self.getFont() font1.info.styleName = "A" font2 = self.getFont() font2.info.styleName = "B" font3 = self.getFont() font3.info.styleName = "C" font4 = self.getFont() font4.info.styleName = "A" fonts = FontList() fonts.extend([font1, font2, font3, font4]) found = fonts.getFontsByStyleName("A") self.assertEqual(found, [font1, font4])
def test_getFontsByStyleName(self): font1 = self.getFont() font1.info.styleName = "A" font2 = self.getFont() font2.info.styleName = "B" font3 = self.getFont() font3.info.styleName = "C" font4 = self.getFont() font4.info.styleName = "A" fonts = FontList() fonts.extend([font1, font2, font3, font4]) found = fonts.getFontsByStyleName("A") self.assertEqual(found, [font1, font4])
def test_sortBy_isMonospace_glyphs(self): font1 = self.getFont_sortBy_monospaceGlyphs() font2 = self.getFont_sortBy_monospaceGlyphs() font3 = self.getFont_sortBy_proportionalGlyphs() font4 = self.getFont_sortBy_proportionalGlyphs() fonts = FontList() fonts.extend([font1, font2, font3, font4]) fonts.reverse() fonts.sortBy("isMonospace") expected = [font2, font1, font4, font3] self.assertEqual(fonts, expected)
def test_sortBy_sortValueFunction(self): font1 = self.getFont_withGlyphCount(10) font2 = self.getFont_withGlyphCount(20) font3 = self.getFont_withGlyphCount(30) font4 = self.getFont_withGlyphCount(40) fonts = FontList() fonts.extend([font1, font2, font3, font4]) fonts.reverse() def glyphCountSortValue(font): return len(font) fonts.sortBy(glyphCountSortValue) expected = [font1, font2, font3, font4] self.assertEqual(fonts, expected)
def test_sortBy_sortValueFunction(self): font1 = self.getFont_withGlyphCount(10) font2 = self.getFont_withGlyphCount(20) font3 = self.getFont_withGlyphCount(30) font4 = self.getFont_withGlyphCount(40) fonts = FontList() fonts.extend([font1, font2, font3, font4]) fonts.reverse() def glyphCountSortValue(font): return len(font) fonts.sortBy(glyphCountSortValue) expected = [font1, font2, font3, font4] self.assertEqual(fonts, expected)