aboutsummaryrefslogtreecommitdiff
path: root/contrib/ayatana-indicator-keyboard-icon-generator.py
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2022-01-26 17:03:32 +0100
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2022-01-27 09:24:49 +0100
commit2f4a12a03690cd090425e85711d4f928cd042d5f (patch)
treebcc2bf7bb461729f4be922da3c5cd56d9c12661d /contrib/ayatana-indicator-keyboard-icon-generator.py
parentcba5f9cb9389a9b77edc009f8e629a9b0e3fdf06 (diff)
downloadayatana-indicator-keyboard-2f4a12a03690cd090425e85711d4f928cd042d5f.tar.gz
ayatana-indicator-keyboard-2f4a12a03690cd090425e85711d4f928cd042d5f.tar.bz2
ayatana-indicator-keyboard-2f4a12a03690cd090425e85711d4f928cd042d5f.zip
Merge icon generators + add some tweakability
Diffstat (limited to 'contrib/ayatana-indicator-keyboard-icon-generator.py')
-rwxr-xr-xcontrib/ayatana-indicator-keyboard-icon-generator.py56
1 files changed, 44 insertions, 12 deletions
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 <padding> -c <colour> -f <font> -o <outdir>')
+ print('ayatana-indicator-keyboard-icon-generator -p <padding> -c <colour> -f <font> -n -o <outdir>')
print('')
print('<padding> The padding between the fill and the edges of the image')
- print(' Defaults to 0 pixels')
+ print(' Defaults to 0.8')
print('<colour> The colour of the fill')
print(' Defaults to "#ffffff"')
print('<font> 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('<outdir> 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('<?xml version="1.0" encoding="UTF-8"?><svg version="1.1" width="24" height="24"><defs><mask id="m"><rect x="0" y="0" width="24" height="24" style="fill:white"/><text x="' + str(fLayoutX) + '" y="' + str(fLayoutY) + '" style="font-family:' + sFont + ';font-weight:500;font-size:' + str(nFont) + ';fill:black">' + sLanguage + '</text></mask></defs><rect x="' + str(fIconX) + '" y="' + str(fIconY) + '" width="' + str(nSize) + '" height="' + str(nSize) + '" rx="3" mask="url(#m)" style="fill:' + sColour + '"/></svg>')
+ 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('<?xml version="1.0" encoding="UTF-8"?><svg version="1.1" width="24" height="24"><defs><mask id="m"><rect x="0" y="0" width="24" height="24" style="fill:white"/><text x="' + str(fLayoutX) + '" y="' + str(fLayoutY) + '" style="font-family:' + sFont + ';font-weight:' + str(nWeight) + ';font-size:' + str(nFont) + ';fill:black">' + sLanguage + '</text></mask></defs><rect x="' + str(fIconX) + '" y="' + str(fIconY) + '" width="' + str(fSize) + '" height="' + str(fSize) + '" rx="' + str(fRx) + '" mask="url(#m)" style="fill:' + sColour + '"/></svg>')
+
+ else:
+
+ pFile.write('<?xml version="1.0" encoding="UTF-8"?><svg version="1.1" width="24" height="24"><rect x="' + str(fIconX) + '" y="' + str(fIconY) + '" width="' + str(fSize) + '" height="' + str(fSize) + '" rx="' + str(fRx) + '" style="stroke:' + sColour + ';stroke-width:0.8;fill:none;"/><text x="' + str(fLayoutX) + '" y="' + str(fLayoutY) + '" style="font-family:' + sFont + ';font-weight:' + str(nWeight) + ';font-size:' + str(nFont) + ';fill:' + sColour + '">' + sLanguage + '</text></svg>')
+ #subprocess.run('inkscape "' + str(sOutPath) + '" --export-text-to-path --export-plain-svg --export-filename="' + str(sOutPath) + '"', shell=True, check=True);
sys.exit(0)