diff --git a/src-python/models/overlay/overlay_image.py b/src-python/models/overlay/overlay_image.py index df6e303f..e14ccacd 100644 --- a/src-python/models/overlay/overlay_image.py +++ b/src-python/models/overlay/overlay_image.py @@ -58,7 +58,11 @@ class OverlayImage: font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular") img = Image.new("RGBA", (base_width, base_height), (0, 0, 0, 0)) draw = ImageDraw.Draw(img) - font = ImageFont.truetype(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf"), font_size) + try: + font = ImageFont.truetype(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf"), font_size) + except Exception: + font = ImageFont.truetype(os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf"), font_size) + text_width = draw.textlength(text, font) character_width = text_width // len(text) character_line_num = int((base_width) // character_width) - 12 @@ -142,7 +146,10 @@ class OverlayImage: img = Image.new("RGBA", (0, 0), (0, 0, 0, 0)) draw = ImageDraw.Draw(img) - font = ImageFont.truetype(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf"), font_size) + try: + font = ImageFont.truetype(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf"), font_size) + except Exception: + font = ImageFont.truetype(os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf"), font_size) text_width = draw.textlength(text, font) character_width = text_width // len(text) character_line_num = int(width // character_width) @@ -172,7 +179,10 @@ class OverlayImage: img = Image.new("RGBA", (0, 0), (0, 0, 0, 0)) draw = ImageDraw.Draw(img) - font = ImageFont.truetype(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", "NotoSansJP-Regular.ttf"), font_size) + try: + font = ImageFont.truetype(os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", "NotoSansJP-Regular.ttf"), font_size) + except Exception: + font = ImageFont.truetype(os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", "NotoSansJP-Regular.ttf"), font_size) text_height = font_size*2 text_width = draw.textlength(date_time, font) character_width = text_width // len(date_time) @@ -235,4 +245,13 @@ class OverlayImage: draw = ImageDraw.Draw(background) draw.rounded_rectangle([(0, 0), (width, height)], radius=15, fill=background_color, outline=background_outline_color, width=5) img = Image.alpha_composite(background, img) - return img \ No newline at end of file + return img + +if __name__ == "__main__": + overlay = OverlayImage() + img = overlay.createOverlayImageSmall("Hello, World!", "English", "こんにちは、世界!", "Japanese") + img.save("overlay_small.png") + img = overlay.createOverlayImageLarge("send", "Hello, World!", "English", "こんにちは、世界!", "Japanese") + img.save("overlay_large0.png") + img = overlay.createOverlayImageLarge("receive", "こんにちは、世界!", "Japanese", "Hello, World!", "English") + img.save("overlay_large1.png") \ No newline at end of file diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index 405617b8..c505a295 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -250,7 +250,7 @@ class Controller: translation = " (" + "/".join(translation) + ")" model.logger.info(f"[SENT] {message}{translation}") - if config.OVERLAY_LARGE_LOG is True: + if config.OVERLAY_LARGE_LOG is True and model.overlay_large_log.initialized is True: overlay_image = model.createOverlayImageLarge("send", message, translation) model.updateOverlayLarge(overlay_image) @@ -289,13 +289,11 @@ class Controller: transliteration = model.convertMessageToTransliteration(message) if config.ENABLE_TRANSCRIPTION_RECEIVE is True: - if config.OVERLAY_SMALL_LOG is True: - if model.overlay_small_log.initialized is True: + if config.OVERLAY_SMALL_LOG is True and model.overlay_small_log.initialized is True: overlay_image = model.createOverlayImageSmall(message, translation) model.updateOverlaySmall(overlay_image) - if config.OVERLAY_LARGE_LOG is True: - if model.overlay_large_log.initialized is True: + if config.OVERLAY_LARGE_LOG is True and model.overlay_large_log.initialized is True: overlay_image = model.createOverlayImageLarge("receive", message, translation) model.updateOverlayLarge(overlay_image) @@ -1364,6 +1362,10 @@ class Controller: def setEnableTranscriptionSend(self, *args, **kwargs) -> dict: self.startThreadingTranscriptionSendMessage() config.ENABLE_TRANSCRIPTION_SEND = True + if (config.OVERLAY_LARGE_LOG is True and + model.overlay_large_log.initialized is False and + model.overlay_large_log.checkSteamvrRunning() is True): + model.startOverlayLarge() return {"status":200, "result":config.ENABLE_TRANSCRIPTION_SEND} def setDisableTranscriptionSend(self, *args, **kwargs) -> dict: @@ -1373,9 +1375,14 @@ class Controller: def setEnableTranscriptionReceive(self, *args, **kwargs) -> dict: self.startThreadingTranscriptionReceiveMessage() - if config.OVERLAY_SMALL_LOG is True: - if model.overlay_small_log.initialized is False and model.overlay_small_log.checkSteamvrRunning() is True: + if (config.OVERLAY_SMALL_LOG is True and + model.overlay_small_log.initialized is False and + model.overlay_small_log.checkSteamvrRunning() is True): model.startOverlaySmall() + if (config.OVERLAY_LARGE_LOG is True and + model.overlay_large_log.initialized is False and + model.overlay_large_log.checkSteamvrRunning() is True): + model.startOverlayLarge() config.ENABLE_TRANSCRIPTION_RECEIVE = True return {"status":200, "result":config.ENABLE_TRANSCRIPTION_RECEIVE}