Initial text support implementation, pt. I.
@ -43,7 +43,7 @@ class ENNToolApp(object):
|
||||
print(" -R WxH....: set MiRCART cube resolution; defaults to 0.1x0.2", file=sys.stderr)
|
||||
print(" -s pname..: input script pathname", file=sys.stderr)
|
||||
print(" -S........: select scrolling mode", file=sys.stderr)
|
||||
print(" -t pname..: set MiRCART texture pathname; defaults to texture.png", file=sys.stderr)
|
||||
print(" -t pname..: set MiRCART texture pathname; defaults to {}".format(os.path.join("assets", "texture.png")), file=sys.stderr)
|
||||
print(" -v........: be verbose", file=sys.stderr)
|
||||
try:
|
||||
optlist, argv = getopt(argv[1:], "Af:ho:pr:R:s:St:v")
|
||||
@ -63,7 +63,7 @@ class ENNToolApp(object):
|
||||
if not "-R" in optdict:
|
||||
optdict["-R"] = "0.1x0.2"
|
||||
if not "-t" in optdict:
|
||||
optdict["-t"] = "texture.png"
|
||||
optdict["-t"] = os.path.join("assets", "texture.png")
|
||||
|
||||
if "-r" in optdict:
|
||||
optdict["-r"] = [int(r) for r in optdict["-r"].split("x")][0:2]
|
||||
|
@ -5,7 +5,32 @@
|
||||
# This project is licensed under the terms of the MIT license.
|
||||
#
|
||||
|
||||
#
|
||||
# MiRCARTColours: mIRC colour number to RGBA map given none of ^[BFV_] (bold, italic, reverse, underline],
|
||||
#
|
||||
ENNToolMiRCARTColours = [
|
||||
[255, 255, 255], # White
|
||||
[0, 0, 0], # Black
|
||||
[0, 0, 187], # Blue
|
||||
[0, 187, 0], # Green
|
||||
[255, 85, 85], # Light Red
|
||||
[187, 0, 0], # Red
|
||||
[187, 0, 187], # Purple
|
||||
[187, 187, 0], # Yellow
|
||||
[255, 255, 85], # Light Yellow
|
||||
[85, 255, 85], # Light Green
|
||||
[0, 187, 187], # Cyan
|
||||
[85, 255, 255], # Light Cyan
|
||||
[85, 85, 255], # Light Blue
|
||||
[255, 85, 255], # Pink
|
||||
[85, 85, 85], # Grey
|
||||
[187, 187, 187], # Light Grey
|
||||
]
|
||||
|
||||
#
|
||||
# MiRCARTColours: mIRC colour number to RGBA float map given none of ^[BFV_] (bold, italic, reverse, underline],
|
||||
#
|
||||
ENNToolMiRCARTColoursFloat = [
|
||||
[1.00, 1.00, 1.00], # White
|
||||
[0.00, 0.00, 0.00], # Black
|
||||
[0.00, 0.00, 0.73], # Blue
|
||||
|
92
ENNToolTTFExporter.py
Executable file
@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# ENNTool -- mIRC art animation tool (for EFnet #MiRCART) (WIP)
|
||||
# Copyright (c) 2018 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
||||
# This project is licensed under the terms of the MIT license.
|
||||
#
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
import os, string, yaml, sys
|
||||
|
||||
from ENNToolMiRCARTColours import ENNToolMiRCARTColours
|
||||
from ENNToolMiRCARTImporter import ENNToolMiRCARTImporter
|
||||
|
||||
#
|
||||
# Entry point
|
||||
def main(*argv):
|
||||
fontNormalPathName = os.path.join("assets", "DejaVuSansMono.ttf")
|
||||
fontBoldPathName = os.path.join("assets", "DejaVuSansMono-Bold.ttf")
|
||||
fontSize = int("11")
|
||||
outInfoFileName = os.path.join("assets", "textures.yaml")
|
||||
outPathName = os.path.join("assets", "textures")
|
||||
if not os.path.exists(os.path.dirname(outInfoFileName)):
|
||||
os.makedirs(os.path.dirname(outInfoFileName))
|
||||
if not os.path.exists(outPathName):
|
||||
os.makedirs(outPathName)
|
||||
|
||||
pilFontNormal = ImageFont.truetype(fontNormalPathName, fontSize)
|
||||
pilFontBold = ImageFont.truetype(fontBoldPathName, fontSize)
|
||||
pilFontSize = list(pilFontNormal.getsize(" "))
|
||||
pilFontSize[0] += (8 - (pilFontSize[0] % 8))
|
||||
pilFontSize[1] = pilFontSize[0] * 2
|
||||
pilImageSize = (pilFontSize[0] * 128, pilFontSize[1])
|
||||
print("font size: {}, image size: {}".format(pilFontSize, pilImageSize))
|
||||
|
||||
charMap = {}
|
||||
for fontAttrs in [[ENNToolMiRCARTImporter._CellState.CS_NONE],
|
||||
[ENNToolMiRCARTImporter._CellState.CS_BOLD],
|
||||
[ENNToolMiRCARTImporter._CellState.CS_UNDERLINE],
|
||||
[ENNToolMiRCARTImporter._CellState.CS_BOLD, ENNToolMiRCARTImporter._CellState.CS_UNDERLINE]]:
|
||||
for fontColour in range(16):
|
||||
curPos = [0, 0]
|
||||
pilImage = Image.new("RGBA", pilImageSize, (0, 0, 0, 0))
|
||||
pilImageDraw = ImageDraw.Draw(pilImage)
|
||||
for fontChar in [chr(n) for n in range(128)]:
|
||||
pilFont, underLine = None, False
|
||||
for fontAttr in fontAttrs:
|
||||
if fontAttr == ENNToolMiRCARTImporter._CellState.CS_NONE:
|
||||
pilFont = pilFontNormal
|
||||
elif fontAttr == ENNToolMiRCARTImporter._CellState.CS_BOLD:
|
||||
pilFont = pilFontBold
|
||||
elif fontAttr == ENNToolMiRCARTImporter._CellState.CS_UNDERLINE:
|
||||
underLine = True
|
||||
else:
|
||||
raise ValueError
|
||||
if fontChar in string.printable:
|
||||
pilImageDraw.text(curPos, fontChar,
|
||||
(*ENNToolMiRCARTColours[fontColour], 255), pilFont)
|
||||
if underLine:
|
||||
pilImageDraw.line(
|
||||
xy=(curPos[0], curPos[1] + (pilFontSize[1] - 2),
|
||||
curPos[0] + pilFontSize[0], curPos[1] + (pilFontSize[1] - 2)),
|
||||
fill=(*ENNToolMiRCARTColours[fontColour], 255))
|
||||
if not fontChar in charMap:
|
||||
charMap[fontChar] = {}
|
||||
if not fontColour in charMap[fontChar]:
|
||||
charMap[fontChar][fontColour] = []
|
||||
charMap[fontChar][fontColour] \
|
||||
+= [{"attrs":fontAttrs,
|
||||
"bl":[float((curPos[0])/pilImageSize[0]), float((curPos[1])/pilImageSize[1])],
|
||||
"br":[float((curPos[0] + pilFontSize[0])/pilImageSize[0]), float((curPos[1])/pilImageSize[1])],
|
||||
"tl":[float((curPos[0])/pilImageSize[0]), float((curPos[1] + pilFontSize[1])/pilImageSize[1])],
|
||||
"tr":[float((curPos[0] + pilFontSize[0])/pilImageSize[0]), float((curPos[1] + pilFontSize[1])/pilImageSize[1])]}]
|
||||
curPos[0] += pilFontSize[0]
|
||||
fontAttrName = ""
|
||||
for fontAttr in fontAttrs:
|
||||
if fontAttr == ENNToolMiRCARTImporter._CellState.CS_NONE:
|
||||
fontAttrName += "Normal"
|
||||
elif fontAttr == ENNToolMiRCARTImporter._CellState.CS_BOLD:
|
||||
fontAttrName += "Bold"
|
||||
elif fontAttr == ENNToolMiRCARTImporter._CellState.CS_UNDERLINE:
|
||||
fontAttrName += "Underline"
|
||||
else:
|
||||
raise ValueError
|
||||
pilImage.save(os.path.join(outPathName, "{}Fg{:02d}.png".format(fontAttrName, fontColour)))
|
||||
|
||||
with open(outInfoFileName, "w") as fileObject:
|
||||
yaml.dump(charMap, fileObject)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(*sys.argv)
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
@ -2,4 +2,4 @@
|
||||
Copyright (c) 2018 Lucio Andrés Illanes Albornoz <<lucio@lucioillanes.de>>
|
||||
This project is licensed under the terms of the MIT licence.
|
||||
* Prerequisites on Windows: install Python v3.5.x and script dependencies w/ the following elevated command prompt command line:
|
||||
`pip install chardet numpy opencv-python Pillow PyOpenGL wxPython`
|
||||
`pip install chardet numpy opencv-python Pillow PyOpenGL PyYAML wxPython`
|
||||
|
BIN
assets/DejaVuSansMono-Bold.ttf
Normal file
Before Width: | Height: | Size: 270 B After Width: | Height: | Size: 270 B |
33702
assets/textures.yaml
Normal file
BIN
assets/textures/BoldFg00.png
Normal file
After Width: | Height: | Size: 7.0 KiB |
BIN
assets/textures/BoldFg01.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/textures/BoldFg02.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
assets/textures/BoldFg03.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
assets/textures/BoldFg04.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
assets/textures/BoldFg05.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
assets/textures/BoldFg06.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
assets/textures/BoldFg07.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
assets/textures/BoldFg08.png
Normal file
After Width: | Height: | Size: 7.9 KiB |
BIN
assets/textures/BoldFg09.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
assets/textures/BoldFg10.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
assets/textures/BoldFg11.png
Normal file
After Width: | Height: | Size: 7.7 KiB |
BIN
assets/textures/BoldFg12.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
assets/textures/BoldFg13.png
Normal file
After Width: | Height: | Size: 7.8 KiB |
BIN
assets/textures/BoldFg14.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
assets/textures/BoldFg15.png
Normal file
After Width: | Height: | Size: 8.6 KiB |
BIN
assets/textures/BoldUnderlineFg00.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
assets/textures/BoldUnderlineFg01.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/textures/BoldUnderlineFg02.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
assets/textures/BoldUnderlineFg03.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
assets/textures/BoldUnderlineFg04.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
assets/textures/BoldUnderlineFg05.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
assets/textures/BoldUnderlineFg06.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
assets/textures/BoldUnderlineFg07.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
assets/textures/BoldUnderlineFg08.png
Normal file
After Width: | Height: | Size: 7.9 KiB |
BIN
assets/textures/BoldUnderlineFg09.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
assets/textures/BoldUnderlineFg10.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
assets/textures/BoldUnderlineFg11.png
Normal file
After Width: | Height: | Size: 7.8 KiB |
BIN
assets/textures/BoldUnderlineFg12.png
Normal file
After Width: | Height: | Size: 8.4 KiB |
BIN
assets/textures/BoldUnderlineFg13.png
Normal file
After Width: | Height: | Size: 7.8 KiB |
BIN
assets/textures/BoldUnderlineFg14.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
assets/textures/BoldUnderlineFg15.png
Normal file
After Width: | Height: | Size: 8.6 KiB |
BIN
assets/textures/NormalFg00.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
assets/textures/NormalFg01.png
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/textures/NormalFg02.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
assets/textures/NormalFg03.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
assets/textures/NormalFg04.png
Normal file
After Width: | Height: | Size: 8.4 KiB |
BIN
assets/textures/NormalFg05.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
assets/textures/NormalFg06.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
assets/textures/NormalFg07.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
assets/textures/NormalFg08.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
assets/textures/NormalFg09.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
assets/textures/NormalFg10.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
assets/textures/NormalFg11.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
assets/textures/NormalFg12.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
assets/textures/NormalFg13.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
assets/textures/NormalFg14.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
assets/textures/NormalFg15.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
assets/textures/UnderlineFg00.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg01.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg02.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg03.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg04.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg05.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg06.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg07.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg08.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg09.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg10.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg11.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg12.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg13.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg14.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/textures/UnderlineFg15.png
Normal file
After Width: | Height: | Size: 1.3 KiB |