From cdbe426d1a903e5cc966409e90a70f95a8d7f6a6 Mon Sep 17 00:00:00 2001 From: Kalapi Gajjar Date: Wed, 29 May 2024 12:19:23 -0700 Subject: [PATCH] Adds renaming script --- .../UT_renameGlyphsFromDatabase.py | 65 ++++++++++++ scripts/_glyphsScripts/bangla_glyph_names.py | 100 ++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 scripts/_glyphsScripts/UT_renameGlyphsFromDatabase.py create mode 100644 scripts/_glyphsScripts/bangla_glyph_names.py diff --git a/scripts/_glyphsScripts/UT_renameGlyphsFromDatabase.py b/scripts/_glyphsScripts/UT_renameGlyphsFromDatabase.py new file mode 100644 index 00000000..58c43aa4 --- /dev/null +++ b/scripts/_glyphsScripts/UT_renameGlyphsFromDatabase.py @@ -0,0 +1,65 @@ +#MenuTitle: [UT] Rename Glyphs from DataBase +# -*- coding: utf-8 -*- +from __future__ import division, print_function, unicode_literals +from bangla_glyph_names import glyph_names as name_dict +__doc__=""" +Does what it says on the tin! + +The script takes a dictionary of before/after glyph-names and renames glyphs if they're found in the font. + +TODO: + +- Update prefixes +- Update classes +- Update features +- [DONE] Update glyphOrder + +""" +Glyphs.clearLog() + +this_font = Glyphs.font + +def renameGlyphs(font, data): + """docstring for renameGlyphs""" + for names in data: + if names in font.glyphs: + font.glyphs[names].name = data[names] + else: + print("Glyph \'{}\' not found in source!".format(names)) + +def updateGlyphOrder(font, data): + if font.customParameters["glyphOrder"]: + for names in data.keys(): + if names in font.customParameters["glyphOrder"]: +# print(font.glyphOrder().index(n)) + glyph_index = font.customParameters["glyphOrder"].index(names) + font.customParameters["glyphOrder"][glyph_index] = data[names] + +# update prefixes +#if len(this_font.featurePrefixes) > 1: +# # Do stuff +# print(this_font.featurePrefixes) +#else: +# pass + +# update classes +#if len(this_font.classes) > 0: +# # Do stuff +# print(this_font.classes) +#else: +# pass + +# update features + + +#if len(this_font.features) > 0: +# # Do stuff +# print(this_font.features[0].code) +#else: +# pass + +this_font.disableUpdateInterface() +glyph_name_data = name_dict +renameGlyphs(this_font, glyph_name_data) +updateGlyphOrder(this_font, glyph_name_data) +this_font.enableUpdateInterface() diff --git a/scripts/_glyphsScripts/bangla_glyph_names.py b/scripts/_glyphsScripts/bangla_glyph_names.py new file mode 100644 index 00000000..f224b980 --- /dev/null +++ b/scripts/_glyphsScripts/bangla_glyph_names.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- + +glyph_names = { +"uni0980": "anji-beng", +"anusvarabeng": "anusvara-beng", +"visargabeng": "visarga-beng", +"abeng": "a-beng", +"aabeng": "aa-beng", +"ibeng": "i-beng", +"iibeng": "ii-beng", +"ubeng": "u-beng", +"uubeng": "uu-beng", +"rvocalicbeng": "rVocalic-beng", +"lvocalicbeng": "lVocalic-beng", +"ebeng": "e-beng", +"aibeng": "ai-beng", +"obeng": "o-beng", +"aubeng": "au-beng", +"kabeng": "ka-beng", +"khabeng": "kha-beng", +"gabeng": "ga-beng", +"ghabeng": "gha-beng", +"ngabeng": "nga-beng", +"cabeng": "ca-beng", +"chabeng": "cha-beng", +"jabeng": "ja-beng", +"jhabeng": "jha-beng", +"nyabeng": "nya-beng", +"ttabeng": "tta-beng", +"tthabeng": "ttha-beng", +"ddabeng": "dda-beng", +"ddhabeng": "ddha-beng", +"nnabeng": "nna-beng", +"tabeng": "ta-beng", +"thabeng": "tha-beng", +"dabeng": "da-beng", +"dhabeng": "dha-beng", +"nabeng": "na-beng", +"pabeng": "pa-beng", +"phabeng": "pha-beng", +"babeng": "ba-beng", +"bhabeng": "bha-beng", +"mabeng": "ma-beng", +"yabeng": "ya-beng", +"rabeng": "ra-beng", +"labeng": "la-beng", +"shabeng": "sha-beng", +"ssabeng": "ssa-beng", +"sabeng": "sa-beng", +"habeng": "ha-beng", +"nuktabeng": "nukta-beng", +"avagrahabeng": "avagraha-beng", +"aavowelsignbeng": "aaMatra-beng", +"ivowelsignbeng": "iMatra-beng", +"iivowelsignbeng": "iiMatra-beng", +"uvowelsignbeng": "uMatra-beng", +"uuvowelsignbeng": "uuMatra-beng", +"rvocalicvowelsignbeng": "rVocalicMatra-beng", +"rrvocalicvowelsignbeng": "rrVocalicMatra-beng", +"evowelsignbeng": "eMatra-beng", +"aivowelsignbeng": "aiMatra-beng", +"ovowelsignbeng": "oMatra-beng", +"auvowelsignbeng": "auMatra-beng", +"viramabeng": "halant-beng", +"khandatabeng": "taKhanda-beng", +"aulengthmarkbeng": "auLength-beng", +"rrabeng": "rra-beng", +"rhabeng": "rha-beng", +"yyabeng": "yya-beng", +"rrvocalicbeng": "rrVocalic-beng", +"llvocalicbeng": "llVocalic-beng", +"lvocalicvowelsignbeng": "lVocalicMatra-beng", +"llvocalicvowelsignbeng": "llVocalicMatra-beng", +"zerobeng": "zero-beng", +"onebeng": "one-beng", +"twobeng": "two-beng", +"threebeng": "three-beng", +"fourbeng": "four-beng", +"fivebeng": "five-beng", +"sixbeng": "six-beng", +"sevenbeng": "seven-beng", +"eightbeng": "eight-beng", +"ninebeng": "nine-beng", +"ra1beng": "ramiddlediagonal-beng", +"wabeng": "ralowerdiagonal-beng", +"rupeemarkbeng": "rupeeMark-beng", +"rupeesignbeng": "rupeeSign-beng", +"uni09F4": "oneNumr-beng", +"uni09F5": "twoNumr-beng", +"uni09F6": "threeNumr-beng", +"uni09F7": "fourNumr-beng", +"uni09F8": "oneLessNumr-beng", +"uni09F9": "sixteenDnom-beng", +"issharbeng": "isshar-beng", +"uni09FB": "ganda-beng", +"uni09FC": "vedicAnusvara-beng", +"uni09FD": "abbreviation-beng", +"uni09FE": "sandhi-beng" +} +