diff --git a/Lib/glyphsets/__init__.py b/Lib/glyphsets/__init__.py index 8555bbb..c083dae 100644 --- a/Lib/glyphsets/__init__.py +++ b/Lib/glyphsets/__init__.py @@ -498,6 +498,52 @@ def describe_glyphset(glyph_names): return md +def compare_glyphsets(glyphsets): + """ + Compare the contents of glyphsets to each other, + with the first glyphset being the reference. + Each consecutive glyphset gets compares to each former. + """ + + if len(list(set(glyphsets))) < 2: + raise ValueError("Please provide at least two glyphsets to compare.") + + if len(list(set(glyphsets))) != len(glyphsets): + raise ValueError("Please provide unique glyphsets to compare.") + + reference_glyphset = glyphsets[0] + reference_glyphs = set(glyphs_in_glyphset(reference_glyphset)) + + print(f"{reference_glyphset}:\n{'=' * len(reference_glyphset)}\n") + print(f"Total glyphs: {len(reference_glyphs)}\n") + print(describe_glyphset(reference_glyphs)) + + for i, glyphset in enumerate(glyphsets): + if i == 0: + continue + + this_glyphs = set(glyphs_in_glyphset(glyphsets[i])) + previous_glyphs = set(glyphs_in_glyphset(glyphsets[i - 1])) + + print(f"\n{glyphset}:\n{'=' * len(glyphset)}\n") + print(f"Total glyphs: {len(this_glyphs)}\n") + + missing = previous_glyphs.difference(this_glyphs) + extra = this_glyphs.difference(previous_glyphs) + + if missing: + print( + f"{glyphset} has {len(missing)} **missing** glyphs compared to {glyphsets[i - 1]}:\n" + ) + print(describe_glyphset(missing)) + + if extra: + print( + f"{glyphset} has {len(extra)} **extra** glyphs compared to {glyphsets[i - 1]}:\n" + ) + print(describe_glyphset(extra)) + + def add_country(code): if code in regions: return f"{regions[code].name} ({code})" diff --git a/Lib/glyphsets/__main__.py b/Lib/glyphsets/__main__.py index a90a980..4597162 100644 --- a/Lib/glyphsets/__main__.py +++ b/Lib/glyphsets/__main__.py @@ -1,5 +1,5 @@ import argparse -from glyphsets import build_glyphsapp_filter_list +from glyphsets import build_glyphsapp_filter_list, compare_glyphsets def main(): @@ -28,6 +28,12 @@ def main(): filter_lists_parser.add_argument("--prod-names", action="store_true", default=False) filter_lists_parser.add_argument("-o", "--out", required=True, help="output path") + filter_lists_parser = subparsers.add_parser( + "compare", + help="Compare two or more glyhsets to each other; with later glyphsets being compared to the former.", + ) + filter_lists_parser.add_argument("glyphsets", nargs="+") + # nam_file_parser = subparsers.add_parser( # "nam-file", help="Ouput .nam file from given glyphset(s)." # ) @@ -52,6 +58,9 @@ def main(): if args.command == "filter-list": build_glyphsapp_filter_list(args.glyphsets, args.out, args.prod_names) + if args.command == "compare": + compare_glyphsets(args.glyphsets) + # elif args.command == "update-srcs": # srcs = [load_source(src) for src in args.srcs] # for src in srcs: diff --git a/README.md b/README.md index a2b82d9..c3d3b8c 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,11 @@ RESULTS: │ Glyphsets Tool ============== +> [!NOTE] +> Previously existing commands of the `glyphsets` tool are currently deactivated after the transition to the new database. These are: `update-srcs`, `nam-file`, `missing-in-font`. Please report if you need to use these. + +## Custom Filters + You can create your own Glyphs.app _Custom Filters_ using the `glyphsets` tool. Install or update the tool with pip, if you haven’t already: @@ -121,10 +126,42 @@ glyphsets filter-list -o myfilter.plist GF_Latin_Core GF_Latin_Plus ``` Add this `.plist` file next to your Glyphs file and (after restart) you would be able to see it in the filters sidebar. -> [!NOTE] -> Previously existing commands of the `glyphsets` tool are currently deactivated after the transition to the new database. These are: `update-srcs`, `nam-file`, `missing-in-font`. Please report if you need to use these. +## Compare Glyphsets + +You can compare the contents of two or more glyphsets against each other. Each consecutive glyphset will be compared to the previous one. + +This command lists the complete contents of `GF_Latin_Kernel` first, and then lists only extra (or missing) glyphs for `GF_Latin_Core` when compared to `GF_Latin_Kernel`: +``` +glyphsets compare GF_Latin_Kernel GF_Latin_Core +``` + +Output: +``` +GF_Latin_Kernel: +=============== + +Total glyphs: 116 + +Letter (52 glyphs): +`A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z` + +... + + +GF_Latin_Core: +============= +Total glyphs: 324 + +GF_Latin_Core has 208 **extra** glyphs compared to GF_Latin_Kernel: + +Letter (168 glyphs): +`ª º À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ø ù ú û ü ý þ ÿ Ā ā Ă ă Ą ą Ć ć Ċ ċ Č č Ď ď Đ đ Ē ē Ė ė Ę ę Ě ě Ğ ğ Ġ ġ Ģ ģ Ħ ħ Ī ī Į į İ ı Ķ ķ Ĺ ĺ Ļ ļ Ľ ľ Ł ł Ń ń Ņ ņ Ň ň Ő ő Œ œ Ŕ ŕ Ř ř Ś ś Ş ş Š š Ť ť Ū ū Ů ů Ű ű Ų ų Ŵ ŵ Ŷ ŷ Ÿ Ź ź Ż ż Ž ž Ș ș Ț ț ȷ Ẁ ẁ Ẃ ẃ Ẅ ẅ ẞ Ỳ ỳ /idotaccent` + +... + +``` Acknowledgements ================ diff --git a/tests/test_glyphsets.py b/tests/test_glyphsets.py index dafd247..cee5ca4 100644 --- a/tests/test_glyphsets.py +++ b/tests/test_glyphsets.py @@ -4,6 +4,7 @@ languages_per_glyphset, get_glyphsets_fulfilled, defined_glyphsets, + compare_glyphsets, ) DATA_FP = os.path.join(os.path.dirname(__file__), "data") @@ -31,3 +32,7 @@ def test_coverage(): ttFont = TTFont(FONT_PATH) assert get_glyphsets_fulfilled(ttFont)["GF_Latin_Core"]["percentage"] > 0.99 + + +def test_compare(): + compare_glyphsets(["GF_Latin_Kernel", "GF_Latin_Core", "GF_Latin_Plus"])