🐛[bugfix] Model : Overlayの起動処理を修正
This commit is contained in:
@@ -58,7 +58,11 @@ class OverlayImage:
|
|||||||
font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular")
|
font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular")
|
||||||
img = Image.new("RGBA", (base_width, base_height), (0, 0, 0, 0))
|
img = Image.new("RGBA", (base_width, base_height), (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(img)
|
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)
|
text_width = draw.textlength(text, font)
|
||||||
character_width = text_width // len(text)
|
character_width = text_width // len(text)
|
||||||
character_line_num = int((base_width) // character_width) - 12
|
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))
|
img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(img)
|
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)
|
text_width = draw.textlength(text, font)
|
||||||
character_width = text_width // len(text)
|
character_width = text_width // len(text)
|
||||||
character_line_num = int(width // character_width)
|
character_line_num = int(width // character_width)
|
||||||
@@ -172,7 +179,10 @@ class OverlayImage:
|
|||||||
|
|
||||||
img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(img)
|
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_height = font_size*2
|
||||||
text_width = draw.textlength(date_time, font)
|
text_width = draw.textlength(date_time, font)
|
||||||
character_width = text_width // len(date_time)
|
character_width = text_width // len(date_time)
|
||||||
@@ -235,4 +245,13 @@ class OverlayImage:
|
|||||||
draw = ImageDraw.Draw(background)
|
draw = ImageDraw.Draw(background)
|
||||||
draw.rounded_rectangle([(0, 0), (width, height)], radius=15, fill=background_color, outline=background_outline_color, width=5)
|
draw.rounded_rectangle([(0, 0), (width, height)], radius=15, fill=background_color, outline=background_outline_color, width=5)
|
||||||
img = Image.alpha_composite(background, img)
|
img = Image.alpha_composite(background, img)
|
||||||
return img
|
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")
|
||||||
@@ -250,7 +250,7 @@ class Controller:
|
|||||||
translation = " (" + "/".join(translation) + ")"
|
translation = " (" + "/".join(translation) + ")"
|
||||||
model.logger.info(f"[SENT] {message}{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)
|
overlay_image = model.createOverlayImageLarge("send", message, translation)
|
||||||
model.updateOverlayLarge(overlay_image)
|
model.updateOverlayLarge(overlay_image)
|
||||||
|
|
||||||
@@ -289,13 +289,11 @@ class Controller:
|
|||||||
transliteration = model.convertMessageToTransliteration(message)
|
transliteration = model.convertMessageToTransliteration(message)
|
||||||
|
|
||||||
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
|
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
|
||||||
if config.OVERLAY_SMALL_LOG is True:
|
if config.OVERLAY_SMALL_LOG is True and model.overlay_small_log.initialized is True:
|
||||||
if model.overlay_small_log.initialized is True:
|
|
||||||
overlay_image = model.createOverlayImageSmall(message, translation)
|
overlay_image = model.createOverlayImageSmall(message, translation)
|
||||||
model.updateOverlaySmall(overlay_image)
|
model.updateOverlaySmall(overlay_image)
|
||||||
|
|
||||||
if config.OVERLAY_LARGE_LOG is True:
|
if config.OVERLAY_LARGE_LOG is True and model.overlay_large_log.initialized is True:
|
||||||
if model.overlay_large_log.initialized is True:
|
|
||||||
overlay_image = model.createOverlayImageLarge("receive", message, translation)
|
overlay_image = model.createOverlayImageLarge("receive", message, translation)
|
||||||
model.updateOverlayLarge(overlay_image)
|
model.updateOverlayLarge(overlay_image)
|
||||||
|
|
||||||
@@ -1364,6 +1362,10 @@ class Controller:
|
|||||||
def setEnableTranscriptionSend(self, *args, **kwargs) -> dict:
|
def setEnableTranscriptionSend(self, *args, **kwargs) -> dict:
|
||||||
self.startThreadingTranscriptionSendMessage()
|
self.startThreadingTranscriptionSendMessage()
|
||||||
config.ENABLE_TRANSCRIPTION_SEND = True
|
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}
|
return {"status":200, "result":config.ENABLE_TRANSCRIPTION_SEND}
|
||||||
|
|
||||||
def setDisableTranscriptionSend(self, *args, **kwargs) -> dict:
|
def setDisableTranscriptionSend(self, *args, **kwargs) -> dict:
|
||||||
@@ -1373,9 +1375,14 @@ class Controller:
|
|||||||
|
|
||||||
def setEnableTranscriptionReceive(self, *args, **kwargs) -> dict:
|
def setEnableTranscriptionReceive(self, *args, **kwargs) -> dict:
|
||||||
self.startThreadingTranscriptionReceiveMessage()
|
self.startThreadingTranscriptionReceiveMessage()
|
||||||
if config.OVERLAY_SMALL_LOG is True:
|
if (config.OVERLAY_SMALL_LOG is True and
|
||||||
if model.overlay_small_log.initialized is False and model.overlay_small_log.checkSteamvrRunning() is True:
|
model.overlay_small_log.initialized is False and
|
||||||
|
model.overlay_small_log.checkSteamvrRunning() is True):
|
||||||
model.startOverlaySmall()
|
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
|
config.ENABLE_TRANSCRIPTION_RECEIVE = True
|
||||||
return {"status":200, "result":config.ENABLE_TRANSCRIPTION_RECEIVE}
|
return {"status":200, "result":config.ENABLE_TRANSCRIPTION_RECEIVE}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user