diff --git a/bin/pwnagotchi b/bin/pwnagotchi index 0b547ec..6e3ab4a 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -14,6 +14,7 @@ from pwnagotchi import plugins from pwnagotchi import log from pwnagotchi.identity import KeyPair from pwnagotchi.agent import Agent +from pwnagotchi.ui import fonts from pwnagotchi.ui.display import Display from pwnagotchi import restart from pwnagotchi import fs @@ -129,6 +130,7 @@ if __name__ == '__main__': pwnagotchi.config = config fs.setup_mounts(config) log.setup_logging(args, config) + fonts.init(config) pwnagotchi.set_name(config['main']['name']) diff --git a/builder/pwnagotchi.yml b/builder/pwnagotchi.yml index 8dd1379..b821632 100644 --- a/builder/pwnagotchi.yml +++ b/builder/pwnagotchi.yml @@ -104,6 +104,7 @@ - python3-flask - python3-flask-cors - python3-flaskext.wtf + - fonts-ipaexfont-gothic tasks: - name: change hostname diff --git a/pwnagotchi/defaults.toml b/pwnagotchi/defaults.toml index a3e058e..3b1f24b 100644 --- a/pwnagotchi/defaults.toml +++ b/pwnagotchi/defaults.toml @@ -148,6 +148,7 @@ personality.sad_num_epochs = 25 personality.bond_encounters_factor = 20000 ui.fps = 0.0 +ui.font = "DejaVuSansMono" # for japanese: fonts-japanese-gothic ui.faces.look_r = "( ⚆_⚆)" ui.faces.look_l = "(☉_☉ )" diff --git a/pwnagotchi/ui/fonts.py b/pwnagotchi/ui/fonts.py index ca616d3..9b44f92 100644 --- a/pwnagotchi/ui/fonts.py +++ b/pwnagotchi/ui/fonts.py @@ -1,18 +1,34 @@ from PIL import ImageFont -PATH = '/usr/share/fonts/truetype/dejavu/DejaVuSansMono' - -Bold = ImageFont.truetype("%s-Bold.ttf" % PATH, 10) -BoldSmall = ImageFont.truetype("%s-Bold.ttf" % PATH, 8) -BoldBig = ImageFont.truetype("%s-Bold.ttf" % PATH, 25) -Medium = ImageFont.truetype("%s.ttf" % PATH, 10) -Small = ImageFont.truetype("%s.ttf" % PATH, 9) -Huge = ImageFont.truetype("%s-Bold.ttf" % PATH, 25) +FONT_NAME = None +Bold = None +BoldSmall = None +BoldBig = None +Medium = None +Small = None +Huge = None -def setup(bold, bold_small, medium, huge): - global PATH, Bold, BoldSmall, Medium, Huge - Bold = ImageFont.truetype("%s-Bold.ttf" % PATH, bold) - BoldSmall = ImageFont.truetype("%s-Bold.ttf" % PATH, bold_small) - Medium = ImageFont.truetype("%s.ttf" % PATH, medium) - Huge = ImageFont.truetype("%s-Bold.ttf" % PATH, huge) +def init(config): + global FONT_NAME + FONT_NAME = config['ui']['font'] + setup(10, 8, 10, 25, 25, 9) + + +def setup(bold, bold_small, medium, huge, bold_big, small): + global Bold, BoldSmall, Medium, Huge, BoldBig, Small, FONT_NAME + + Small = ImageFont.truetype("%s.ttf" % FONT_NAME, small) + Medium = ImageFont.truetype("%s.ttf" % FONT_NAME, medium) + + try: + BoldSmall = ImageFont.truetype("%s-Bold.ttf" % FONT_NAME, bold_small) + Bold = ImageFont.truetype("%s-Bold.ttf" % FONT_NAME, bold) + BoldBig = ImageFont.truetype("%s-Bold.ttf" % FONT_NAME, bold_big) + Huge = ImageFont.truetype("%s-Bold.ttf" % FONT_NAME, huge) + except OSError: + BoldSmall = ImageFont.truetype("%s.ttf" % FONT_NAME, bold_small) + Bold = ImageFont.truetype("%s.ttf" % FONT_NAME, bold) + BoldBig = ImageFont.truetype("%s.ttf" % FONT_NAME, bold_big) + Huge = ImageFont.truetype("%s.ttf" % FONT_NAME, huge) + diff --git a/pwnagotchi/ui/hw/dfrobot.py b/pwnagotchi/ui/hw/dfrobot.py index b79c7fa..756e727 100644 --- a/pwnagotchi/ui/hw/dfrobot.py +++ b/pwnagotchi/ui/hw/dfrobot.py @@ -9,7 +9,7 @@ class DFRobot(DisplayImpl): self._display = None def layout(self): - fonts.setup(10, 9, 10, 35) + fonts.setup(10, 9, 10, 35, 25, 9) self._layout['width'] = 250 self._layout['height'] = 122 self._layout['face'] = (0, 40) diff --git a/pwnagotchi/ui/hw/inky.py b/pwnagotchi/ui/hw/inky.py index 7ae3327..afa6de5 100644 --- a/pwnagotchi/ui/hw/inky.py +++ b/pwnagotchi/ui/hw/inky.py @@ -10,7 +10,7 @@ class Inky(DisplayImpl): self._display = None def layout(self): - fonts.setup(10, 8, 10, 28) + fonts.setup(10, 8, 10, 28, 25, 9) self._layout['width'] = 212 self._layout['height'] = 104 self._layout['face'] = (0, 37) diff --git a/pwnagotchi/ui/hw/lcdhat.py b/pwnagotchi/ui/hw/lcdhat.py index 92e45a7..9170a2a 100644 --- a/pwnagotchi/ui/hw/lcdhat.py +++ b/pwnagotchi/ui/hw/lcdhat.py @@ -10,7 +10,7 @@ class LcdHat(DisplayImpl): self._display = None def layout(self): - fonts.setup(10, 9, 10, 35) + fonts.setup(10, 9, 10, 35, 25, 9) self._layout['width'] = 240 self._layout['height'] = 240 self._layout['face'] = (0, 40) diff --git a/pwnagotchi/ui/hw/oledhat.py b/pwnagotchi/ui/hw/oledhat.py index 3673630..6386d58 100644 --- a/pwnagotchi/ui/hw/oledhat.py +++ b/pwnagotchi/ui/hw/oledhat.py @@ -10,7 +10,7 @@ class OledHat(DisplayImpl): self._display = None def layout(self): - fonts.setup(8, 8, 8, 8) + fonts.setup(8, 8, 8, 8, 25, 9) self._layout['width'] = 128 self._layout['height'] = 64 self._layout['face'] = (0, 32) diff --git a/pwnagotchi/ui/hw/papirus.py b/pwnagotchi/ui/hw/papirus.py index 8da13be..aa3a297 100644 --- a/pwnagotchi/ui/hw/papirus.py +++ b/pwnagotchi/ui/hw/papirus.py @@ -11,7 +11,7 @@ class Papirus(DisplayImpl): self._display = None def layout(self): - fonts.setup(10, 8, 10, 23) + fonts.setup(10, 8, 10, 23, 25, 9) self._layout['width'] = 200 self._layout['height'] = 96 self._layout['face'] = (0, 24) diff --git a/pwnagotchi/ui/hw/spotpear24inch.py b/pwnagotchi/ui/hw/spotpear24inch.py index e93b071..b276d76 100644 --- a/pwnagotchi/ui/hw/spotpear24inch.py +++ b/pwnagotchi/ui/hw/spotpear24inch.py @@ -11,7 +11,7 @@ class Spotpear24inch(DisplayImpl): self._display = None def layout(self): - fonts.setup(12, 10, 12, 70) + fonts.setup(12, 10, 12, 70, 25, 9) self._layout['width'] = 320 self._layout['height'] = 240 self._layout['face'] = (35, 50) diff --git a/pwnagotchi/ui/hw/waveshare1.py b/pwnagotchi/ui/hw/waveshare1.py index 40ecc3f..ceff5cf 100644 --- a/pwnagotchi/ui/hw/waveshare1.py +++ b/pwnagotchi/ui/hw/waveshare1.py @@ -11,7 +11,7 @@ class WaveshareV1(DisplayImpl): def layout(self): if self.config['color'] == 'black': - fonts.setup(10, 9, 10, 35) + fonts.setup(10, 9, 10, 35, 25, 9) self._layout['width'] = 250 self._layout['height'] = 122 self._layout['face'] = (0, 40) @@ -31,7 +31,7 @@ class WaveshareV1(DisplayImpl): 'max': 20 } else: - fonts.setup(10, 8, 10, 25) + fonts.setup(10, 8, 10, 25, 25, 9) self._layout['width'] = 212 self._layout['height'] = 104 self._layout['face'] = (0, 26) diff --git a/pwnagotchi/ui/hw/waveshare144lcd.py b/pwnagotchi/ui/hw/waveshare144lcd.py index d1d2044..79fc888 100644 --- a/pwnagotchi/ui/hw/waveshare144lcd.py +++ b/pwnagotchi/ui/hw/waveshare144lcd.py @@ -10,7 +10,7 @@ class Waveshare144lcd(DisplayImpl): self._display = None def layout(self): - fonts.setup(10, 8, 10, 18) + fonts.setup(10, 8, 10, 18, 25, 9) self._layout['width'] = 128 self._layout['height'] = 128 self._layout['face'] = (0, 43) diff --git a/pwnagotchi/ui/hw/waveshare154inch.py b/pwnagotchi/ui/hw/waveshare154inch.py index fc9cfa7..52c48f9 100644 --- a/pwnagotchi/ui/hw/waveshare154inch.py +++ b/pwnagotchi/ui/hw/waveshare154inch.py @@ -10,7 +10,7 @@ class Waveshare154inch(DisplayImpl): self._display = None def layout(self): - fonts.setup(10, 9, 10, 35) + fonts.setup(10, 9, 10, 35, 25, 9) self._layout['width'] = 200 self._layout['height'] = 200 self._layout['face'] = (0, 40) diff --git a/pwnagotchi/ui/hw/waveshare2.py b/pwnagotchi/ui/hw/waveshare2.py index 5065f65..1b90c87 100644 --- a/pwnagotchi/ui/hw/waveshare2.py +++ b/pwnagotchi/ui/hw/waveshare2.py @@ -11,7 +11,7 @@ class WaveshareV2(DisplayImpl): def layout(self): if self.config['color'] == 'black': - fonts.setup(10, 9, 10, 35) + fonts.setup(10, 9, 10, 35, 25, 9) self._layout['width'] = 250 self._layout['height'] = 122 self._layout['face'] = (0, 40) @@ -31,7 +31,7 @@ class WaveshareV2(DisplayImpl): 'max': 20 } else: - fonts.setup(10, 8, 10, 25) + fonts.setup(10, 8, 10, 25, 25, 9) self._layout['width'] = 212 self._layout['height'] = 104 self._layout['face'] = (0, 26) diff --git a/pwnagotchi/ui/hw/waveshare213bc.py b/pwnagotchi/ui/hw/waveshare213bc.py index 70309a8..cf5a912 100644 --- a/pwnagotchi/ui/hw/waveshare213bc.py +++ b/pwnagotchi/ui/hw/waveshare213bc.py @@ -10,7 +10,7 @@ class Waveshare213bc(DisplayImpl): self._display = None def layout(self): - fonts.setup(10, 8, 10, 25) + fonts.setup(10, 8, 10, 25, 25, 9) self._layout['width'] = 212 self._layout['height'] = 104 self._layout['face'] = (0, 26) diff --git a/pwnagotchi/ui/hw/waveshare213d.py b/pwnagotchi/ui/hw/waveshare213d.py index 9aa8ff8..7171c28 100644 --- a/pwnagotchi/ui/hw/waveshare213d.py +++ b/pwnagotchi/ui/hw/waveshare213d.py @@ -10,7 +10,7 @@ class Waveshare213d(DisplayImpl): self._display = None def layout(self): - fonts.setup(10, 8, 10, 25) + fonts.setup(10, 8, 10, 25, 25, 9) self._layout['width'] = 212 self._layout['height'] = 104 self._layout['face'] = (0, 26) diff --git a/pwnagotchi/ui/hw/waveshare27inch.py b/pwnagotchi/ui/hw/waveshare27inch.py index 0cbc168..30f76f3 100644 --- a/pwnagotchi/ui/hw/waveshare27inch.py +++ b/pwnagotchi/ui/hw/waveshare27inch.py @@ -10,7 +10,7 @@ class Waveshare27inch(DisplayImpl): self._display = None def layout(self): - fonts.setup(10, 9, 10, 35) + fonts.setup(10, 9, 10, 35, 25, 9) self._layout['width'] = 264 self._layout['height'] = 176 self._layout['face'] = (66, 27) diff --git a/pwnagotchi/ui/hw/waveshare29inch.py b/pwnagotchi/ui/hw/waveshare29inch.py index cabbee9..31aac43 100644 --- a/pwnagotchi/ui/hw/waveshare29inch.py +++ b/pwnagotchi/ui/hw/waveshare29inch.py @@ -10,7 +10,7 @@ class Waveshare29inch(DisplayImpl): self._display = None def layout(self): - fonts.setup(10, 9, 10, 35) + fonts.setup(10, 9, 10, 35, 25, 9) self._layout['width'] = 296 self._layout['height'] = 128 self._layout['face'] = (0, 40)