From 3f05c912486a3e811ad0265f953194dd3eac489d Mon Sep 17 00:00:00 2001 From: Marc Foley Date: Fri, 12 Jan 2024 15:54:31 +0000 Subject: [PATCH] tags: get main group values --- Lib/gftools/tags.py | 490 +++++++++++++++++++++++--------------------- 1 file changed, 254 insertions(+), 236 deletions(-) diff --git a/Lib/gftools/tags.py b/Lib/gftools/tags.py index 691fd8ae0..ceb7d4a67 100644 --- a/Lib/gftools/tags.py +++ b/Lib/gftools/tags.py @@ -14,7 +14,8 @@ from functools import lru_cache -class SheetStructureChange(Exception): pass +class SheetStructureChange(Exception): + pass class GFTags(object): @@ -95,7 +96,7 @@ class GFTags(object): "Loud", "Awkward", "Innovative", - "Artistic" + "Artistic", ], "Youthful": [ "Playful", @@ -106,7 +107,7 @@ class GFTags(object): "Loud", "Rugged", "Vintage", - "Stiff" + "Stiff", ], "Flow": [ "Rugged", @@ -117,8 +118,8 @@ class GFTags(object): "Cute", "Sophisticated", "Fancy", - "Artistic" - ] + "Artistic", + ], } def __init__(self): @@ -137,6 +138,7 @@ def _parse_csv(self): ]""" columns = [] res = [] + seen_group_result = set() for row_idx, row in enumerate(self.data): if row_idx == 1: columns = row @@ -154,11 +156,27 @@ def _parse_csv(self): # ,Humanist,Grotesk, ,Garalde,Didone # # ["Sans/Humanist", "Sans/Grotesk", "Serif/Garalde", "Serif/Didone"] - group = next( - self.data[0][i] + group_idx, group = next( + (i, self.data[0][i]) for i in range(col_idx, 0, -1) if self.data[0][i] != "" ) + # Some groups such as Sans and Serif also have values for each family e.g + # Sans <--- Both families have values for Sans + # Modern Traditional + # Abel 20 30 + # Wave 90 90 + if group not in seen_group_result and self.data[1][group_idx] == "": + if self.data[row_idx][group_idx] == "": + continue + res.append( + { + "Family": row[0], + "Group/Tag": f"/{group}/{group}", + "Weight": int(self.data[row_idx][group_idx]), + } + ) + seen_group_result.add(group) if group not in self.CATEGORIES: raise ValueError( f"{group} isn't a know category, {self.CATEGORIES.keys()}" @@ -194,240 +212,240 @@ def check_structure(self): # know git or install other tools. # Please don't cry about all the empty columns below ;-). columns_0 = [ - 'Family', - 'Family Dir', - 'Existing Category', - 'Sample Image', - '', + "Family", + "Family Dir", + "Existing Category", + "Sample Image", + "", "Eli's Quality Score", "Eben's Quality Score", "UT's Quality Score", - ' Type \n Categories', - 'Serif', - '', - '', - '', - '', - '', - '', - '', - '', - 'Sans', - '', - '', - '', - '', - '', - '', - '', - '', - 'Slab', - '', - '', - '', - '', - 'Script', - '', - '', - '', - '', - '', - 'Display', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - 'Arabic', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - 'Hebrew', - '', - '', - '', - '', - '', - 'South East Asian (Thai, Khmer, Lao)', - '', - '', - '', - '', - '', - 'Sinhala', - '', - '', - '', - '', - 'Indic', - '', - '', - '', - '', - '', - ' Expressive\n Categories', - 'Simplicity', - '', - '', - '', - '', - '', - '', - '', - 'Youthful', - '', - '', - '', - '', - '', - '', - '', - '', - 'Flow', - '', - '', - '', - '', - '', - '', - '', - '' + " Type \n Categories", + "Serif", + "", + "", + "", + "", + "", + "", + "", + "", + "Sans", + "", + "", + "", + "", + "", + "", + "", + "", + "Slab", + "", + "", + "", + "", + "Script", + "", + "", + "", + "", + "", + "Display", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "Arabic", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "Hebrew", + "", + "", + "", + "", + "", + "South East Asian (Thai, Khmer, Lao)", + "", + "", + "", + "", + "", + "Sinhala", + "", + "", + "", + "", + "Indic", + "", + "", + "", + "", + "", + " Expressive\n Categories", + "Simplicity", + "", + "", + "", + "", + "", + "", + "", + "Youthful", + "", + "", + "", + "", + "", + "", + "", + "", + "Flow", + "", + "", + "", + "", + "", + "", + "", + "", ] columns_1 = [ - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - 'Humanist Venetian', - 'Old Style Garalde', - 'Transitional', - 'Modern', - 'Scotch', - 'Didone', - 'Fat Face', - '', - '', - 'Humanist', - 'Grotesque', - 'Neo Grotesque', - 'Geometric', - 'Rounded', - 'Superelipse', - 'Glyphic', - '', - '', - 'Geometric', - 'Humanist', - 'Clarendon', - '', - '', - 'Formal', - 'Informal', - 'Handwritten', - 'Upright Script', - '', - '', - 'Blackletter', - 'Wacky', - 'Blobby', - 'Woodtype', - 'Stencil', - 'Inline', - 'Distressed', - 'Shaded', - 'Techno', - 'Art Nouveau', - 'Tuscan', - 'Art Deco', - 'Medieval', - 'Brush/Marker', - '', - '', - 'Kufi', - 'Naskh', - 'Nastaliq', - 'Maghribi', - 'Ruqah', - 'Diwani', - 'Bihari', - 'Warsh', - 'Sudani', - 'West African', - '', - '', - 'Normal', - 'Ashurit', - 'Cursive', - 'Rashi', - '', - '', - 'Looped', - 'Loopless', - 'Moul (Khmer)', - 'Chrieng (Khmer)', - '', - '', - 'Traditional/High contrast', - 'Contemporary/High contrast', - 'Low contrast', - '', - '', - 'Traditional/High contrast', - 'Contemporary/High contrast', - 'Low contrast', - 'Sign Painting/vernacular', - 'Reverse-contrast', - '', - 'Calm/simple', - 'Competent', - 'Business', - 'Sincere', - 'Loud', - 'Awkward', - 'Innovative', - 'Artistic', - 'Playful', - 'Excited', - 'Cute', - 'Happy', - 'Childlike', - 'Loud', - 'Rugged', - 'Vintage', - 'Stiff', - 'Rugged', - 'Futuristic', - 'Calm', - 'Childlike', - 'Active', - 'Cute', - 'Sophisticated', - 'Fancy', - 'Artistic' + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "Humanist Venetian", + "Old Style Garalde", + "Transitional", + "Modern", + "Scotch", + "Didone", + "Fat Face", + "", + "", + "Humanist", + "Grotesque", + "Neo Grotesque", + "Geometric", + "Rounded", + "Superelipse", + "Glyphic", + "", + "", + "Geometric", + "Humanist", + "Clarendon", + "", + "", + "Formal", + "Informal", + "Handwritten", + "Upright Script", + "", + "", + "Blackletter", + "Wacky", + "Blobby", + "Woodtype", + "Stencil", + "Inline", + "Distressed", + "Shaded", + "Techno", + "Art Nouveau", + "Tuscan", + "Art Deco", + "Medieval", + "Brush/Marker", + "", + "", + "Kufi", + "Naskh", + "Nastaliq", + "Maghribi", + "Ruqah", + "Diwani", + "Bihari", + "Warsh", + "Sudani", + "West African", + "", + "", + "Normal", + "Ashurit", + "Cursive", + "Rashi", + "", + "", + "Looped", + "Loopless", + "Moul (Khmer)", + "Chrieng (Khmer)", + "", + "", + "Traditional/High contrast", + "Contemporary/High contrast", + "Low contrast", + "", + "", + "Traditional/High contrast", + "Contemporary/High contrast", + "Low contrast", + "Sign Painting/vernacular", + "Reverse-contrast", + "", + "Calm/simple", + "Competent", + "Business", + "Sincere", + "Loud", + "Awkward", + "Innovative", + "Artistic", + "Playful", + "Excited", + "Cute", + "Happy", + "Childlike", + "Loud", + "Rugged", + "Vintage", + "Stiff", + "Rugged", + "Futuristic", + "Calm", + "Childlike", + "Active", + "Cute", + "Sophisticated", + "Fancy", + "Artistic", ] if self.data[0] != columns_0: raise SheetStructureChange(