From 2f4a12a03690cd090425e85711d4f928cd042d5f Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 26 Jan 2022 17:03:32 +0100 Subject: Merge icon generators + add some tweakability --- ...ana-indicator-keyboard-icon-generator-lomiri.py | 277 --------------------- .../ayatana-indicator-keyboard-icon-generator.py | 56 ++++- 2 files changed, 44 insertions(+), 289 deletions(-) delete mode 100755 contrib/ayatana-indicator-keyboard-icon-generator-lomiri.py (limited to 'contrib') diff --git a/contrib/ayatana-indicator-keyboard-icon-generator-lomiri.py b/contrib/ayatana-indicator-keyboard-icon-generator-lomiri.py deleted file mode 100755 index 6d69fa5c..00000000 --- a/contrib/ayatana-indicator-keyboard-icon-generator-lomiri.py +++ /dev/null @@ -1,277 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -import gi - -gi.require_version('PangoFT2', '1.0') - -from gi.repository import PangoFT2, Pango -from pathlib import Path -import sys -import getopt -import subprocess - -m_lLanguages = [ -'Ap', #APL -'Fa', #Afghani -'Ak', #Akan -'Sq', #Albanian -'Am', #Amharic -'Ar', #Arabic -'Hy', #Armenian -'As', #Asturian -'At', #Atsina -'Av', #Avatime -'Ae', #Avestan -'Az', #Azerbaijani -'Bm', #Bambara -'Bn', #Bangla -'Ba', #Bashkirian -'Be', #Belarusian -'Bl', #Belgian -'Bb', #Berber -'Bs', #Bosnian -'Bi', #Braille -'Bg', #Bulgarian -'By', #Burmese -'Zg', #Zawgyi -'Cm', #Cameroon -'Cn', #Canadian -'Ca', #Catalan -'Ck', #Cherokee -'Zh', #Chinese -'Cu', #Church Slavonic -'Cv', #Chuvash -'Cl', #CloGaelach -'Sx', #Coeur d'Alene Salish -'Cp', #Coptic -'Tt', #Tatar -'Hr', #Croatian -'Cs', #Czech -'Da', #Danish -'Dv', #Dhivehi -'Dl', #Dutch -'Dz', #Dzongkha -'Ed', #Elfdalian -'En', #English -'Eo', #Esperanto -'Et', #Estonian -'Ek', #EurKEY -'Ee', #Ewe -'Fo', #Faroese -'Ph', #Filipino -'Fi', #Finnish -'Fr', #French -'Fu', #Friulian -'Ff', #Fula -'Gh', #Ga -'Ka', #Georgian -'De', #German -'Gr', #Greek -'Gu', #Gujarati -'Hp', #Hanyu Pinyin -'Ha', #Hausa -'Hw', #Hawaiian -'He', #Hebrew -'Hi', #Hindi -'Hu', #Hungarian -'Is', #Icelandic -'Ig', #Igbo -'Il', #Indian -'Ip', #Indic -'Id', #Indonesian -'Ix', #International Phonetic Alphabet -'Iu', #Inuktitut -'Iq', #Iraqi -'Ga', #Irish -'It', #Italian -'Ja', #Japanese -'Kb', #Kabyle -'Kx', #Kalmyk -'Kn', #Kannada -'Kp', #Kashubian -'Kk', #Kazakh -'Km', #Khmer -'Ki', #Kikuyu -'Kv', #Komi -'Ko', #Korean -'Ku', #Kurdish -'Kt', #Kutenai -'Ky', #Kyrgyz -'Lo', #Lao -'Lv', #Latvian -'Lt', #Lithuanian -'Sb', #Lower Sorbian -'Mk', #Macedonian -'Ms', #Malay -'Ml', #Malayalam -'Mt', #Maltese -'Ma', #Manipuri -'Mi', #Maori -'Mr', #Marathi -'Mx', #Mari -'Mu', #Mmuock -'Md', #Modi -'Ro', #Moldavian -'Mn', #Mongolian -'Me', #Montenegrin -'Mb', #Multilingual -'Nk', #N'Ko -'Ne', #Nepali -'Ns', #Saami -'No', #Norwegian -'Oc', #Occitan -'Og', #Ogham -'Ol', #Ol Chiki -'Or', #Oriya -'Os', #Ossetian -'Rs', #Rusyn -'Ps', #Pashto -'Fa', #Persian -'Pl', #Polish -'Pt', #Portuguese -'Pa', #Punjabi -'Ro', #Romanian -'Ru', #Russian -'Sy', #Saisiyat -'Sf', #Samogitian -'Sa', #Sanskrit -'Sp', #Secwepemctsin -'Sr', #Serbian -'Hs', #Serbo-Croatian -'Sj', #Sicilian -'Sj', #Silesian -'Sd', #Sindhi -'Si', #Sinhala -'Sk', #Slovak -'Sl', #Slovenian -'Es', #Spanish -'Sw', #Swahili -'Sv', #Swedish -'Ls', #Syriac -'Tw', #Taiwanese -'Tg', #Tajik -'Ta', #Tamil -'Tt', #Tatar -'Te', #Telugu -'Th', #Thai -'Bo', #Tibetan -'Tn', #Tswana -'Tr', #Turkish -'Tk', #Turkmen -'Ud', #Udmurt -'Ua', #Ugaritic -'Uk', #Ukrainian -'Ur', #Urdu -'Ug', #Uyghur -'Uz', #Uzbek -'Vi', #Vietnamese -'Wo', #Wolof -'Ya', #Yakut -'Yo', #Yoruba -'emoji', #Emoji -'custom', #Custom -'00' #Unknown -] - -def printHelp(): - - print('') - print('Usage:') - print('') - print('ayatana-indicator-keyboard-icon-generator-lomiri -b -c -f -o ') - print('') - print(' The width of the border around the image') - print(' Defaults to 1') - print(' The colour of the image') - print(' Defaults to "#707070"') - print(' The font family') - print(' Defaults to "Ubuntu"') - print(' The output directory') - print(' Defaults to the current directory') - print('') - -if __name__ == '__main__': - - nBorder = 1 - sColour = '#707070' - sFont = "Ubuntu" - pOutDir = Path.cwd() - nFont = 15 - lOpts = [] - - try: - - lOpts = getopt.getopt(sys.argv[1:], 'hp:c:f:o:')[0] - - except getopt.GetoptError: - - printHelp() - sys.exit(1) - - for sOpt, sArg in lOpts: - - if sOpt == '-h': - - printHelp() - sys.exit(0) - - elif sOpt == '-b': - - nBorder = int(sArg) - - elif sOpt == '-c': - - sColour = sArg - - elif sOpt == '-f': - - sFont = sArg - - elif sOpt == '-o': - - pOutDir = Path(sArg) - - pOutDir.mkdir(parents=True, exist_ok=True) - - nSize = 24 - nBorder - fIconX = (24 - nSize) / 2 - fIconY = (24 - nSize) / 2 - pFontMap = PangoFT2.FontMap.new() - pContext = Pango.FontMap.create_context(pFontMap) - pFontDescription = Pango.FontDescription.new() - pFontDescription.set_family(sFont) - pFontDescription.set_weight(300) - pFontDescription.set_size(nFont * Pango.SCALE) - pLayout = Pango.Layout.new(pContext) - pLayout.set_font_description(pFontDescription) - - for sLanguage in m_lLanguages: - - sOutPath = pOutDir.joinpath('ayatana-indicator-keyboard-' + sLanguage + '.svg') - sLanguageText = sLanguage - - if sLanguage == '00': - - sLanguageText = '?' - - elif sLanguage == 'emoji': - - sLanguageText = '😐' - - elif sLanguage == 'custom': - - sLanguageText = '#' - - with open(sOutPath, 'w') as pFile: - - pLayout.set_text(sLanguageText, -1) - nLayoutWidth, nLayoutHeight = pLayout.get_size() - nBaseline = pLayout.get_baseline() - fLayoutX = (24.0 - (nLayoutWidth / Pango.SCALE)) / 2 - fLayoutY = (24.0 - (nLayoutHeight / Pango.SCALE)) / 2 + (nBaseline / Pango.SCALE) - pFile.write('' + sLanguageText + '') - - subprocess.run('inkscape "' + str(sOutPath) + '" --export-text-to-path --export-plain-svg --export-filename="' + str(sOutPath) + '"', shell=True, check=True); - - sys.exit(0) diff --git a/contrib/ayatana-indicator-keyboard-icon-generator.py b/contrib/ayatana-indicator-keyboard-icon-generator.py index 586c8229..5d631d33 100755 --- a/contrib/ayatana-indicator-keyboard-icon-generator.py +++ b/contrib/ayatana-indicator-keyboard-icon-generator.py @@ -9,6 +9,7 @@ from gi.repository import PangoFT2, Pango from pathlib import Path import sys import getopt +#import subprocess m_lLanguages = [ 'Ap', #APL @@ -178,30 +179,34 @@ def printHelp(): print('') print('Usage:') print('') - print('ayatana-indicator-keyboard-icon-generator -p -c -f -o ') + print('ayatana-indicator-keyboard-icon-generator -p -c -f -n -o ') print('') print(' The padding between the fill and the edges of the image') - print(' Defaults to 0 pixels') + print(' Defaults to 0.8') print(' The colour of the fill') print(' Defaults to "#ffffff"') print(' The font family') print(' Defaults to "Sans Regular"') + print('-n Do not fill the icon, draw the border only') + print(' Not used by default') print(' The output directory') print(' Defaults to the current directory') print('') if __name__ == '__main__': - nPadding = 0 + fBorder = 0.8 sColour = '#ffffff' sFont = "Sans Regular" pOutDir = Path.cwd() nFont = 15 + nWeight = 500 + bNoFill = False lOpts = [] try: - lOpts = getopt.getopt(sys.argv[1:], 'hp:c:f:o:')[0] + lOpts = getopt.getopt(sys.argv[1:], 'hp:c:f:no:')[0] except getopt.GetoptError: @@ -217,7 +222,7 @@ if __name__ == '__main__': elif sOpt == '-p': - nPadding = int(sArg) + fBorder = float(sArg) elif sOpt == '-c': @@ -227,20 +232,39 @@ if __name__ == '__main__': sFont = sArg + elif sOpt == '-n': + + bNoFill = True + elif sOpt == '-o': pOutDir = Path(sArg) pOutDir.mkdir(parents=True, exist_ok=True) - nSize = 24 - (2 * nPadding) - fIconX = (24 - nSize) / 2 - fIconY = (24 - nSize) / 2 + fRx = 2.4 + + if fRx == 0: + + fRx = 3.0 + + fSize = 24.0 - (fBorder * 2) + fIconX = (24.0 - fSize) / 2 + fIconY = (24.0 - fSize) / 2 + + if bNoFill == True: + + nWeight = 300 + nFont = 13 + fSize -= 0.8 + fIconX = fBorder + 0.4 + fIconY = fBorder + 0.4 + pFontMap = PangoFT2.FontMap.new() pContext = Pango.FontMap.create_context(pFontMap) pFontDescription = Pango.FontDescription.new() pFontDescription.set_family(sFont) - pFontDescription.set_weight(500) + pFontDescription.set_weight(nWeight) pFontDescription.set_size(nFont * Pango.SCALE) pLayout = Pango.Layout.new(pContext) pLayout.set_font_description(pFontDescription) @@ -266,8 +290,16 @@ if __name__ == '__main__': pLayout.set_text(sLanguage, -1) nLayoutWidth, nLayoutHeight = pLayout.get_size() nBaseline = pLayout.get_baseline() - fLayoutX = (24.0 - (nLayoutWidth / Pango.SCALE)) / 2 - fLayoutY = (24.0 - (nLayoutHeight / Pango.SCALE)) / 2 + (nBaseline / Pango.SCALE) - pFile.write('' + sLanguage + '') + fLayoutX = (24.0 - (nLayoutWidth / Pango.SCALE)) / 2 + (fBorder * 0.1) + fLayoutY = (24.0 - (nLayoutHeight / Pango.SCALE)) / 2 + (nBaseline / Pango.SCALE) + (fBorder * 0.1) + + if bNoFill == False: + + pFile.write('' + sLanguage + '') + + else: + + pFile.write('' + sLanguage + '') + #subprocess.run('inkscape "' + str(sOutPath) + '" --export-text-to-path --export-plain-svg --export-filename="' + str(sOutPath) + '"', shell=True, check=True); sys.exit(0) -- cgit v1.2.3