Initial text support implementation, pt. I.

This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-06-27 19:13:20 +02:00
parent 74bdd88766
commit f5dee0bf20
73 changed files with 33822 additions and 3 deletions

View File

@ -43,7 +43,7 @@ class ENNToolApp(object):
print(" -R WxH....: set MiRCART cube resolution; defaults to 0.1x0.2", file=sys.stderr) 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 pname..: input script pathname", file=sys.stderr)
print(" -S........: select scrolling mode", 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) print(" -v........: be verbose", file=sys.stderr)
try: try:
optlist, argv = getopt(argv[1:], "Af:ho:pr:R:s:St:v") optlist, argv = getopt(argv[1:], "Af:ho:pr:R:s:St:v")
@ -63,7 +63,7 @@ class ENNToolApp(object):
if not "-R" in optdict: if not "-R" in optdict:
optdict["-R"] = "0.1x0.2" optdict["-R"] = "0.1x0.2"
if not "-t" in optdict: if not "-t" in optdict:
optdict["-t"] = "texture.png" optdict["-t"] = os.path.join("assets", "texture.png")
if "-r" in optdict: if "-r" in optdict:
optdict["-r"] = [int(r) for r in optdict["-r"].split("x")][0:2] optdict["-r"] = [int(r) for r in optdict["-r"].split("x")][0:2]

View File

@ -5,7 +5,32 @@
# This project is licensed under the terms of the MIT license. # 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 = [ 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 [1.00, 1.00, 1.00], # White
[0.00, 0.00, 0.00], # Black [0.00, 0.00, 0.00], # Black
[0.00, 0.00, 0.73], # Blue [0.00, 0.00, 0.73], # Blue

92
ENNToolTTFExporter.py Executable file
View 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

View File

@ -2,4 +2,4 @@
Copyright (c) 2018 Lucio Andrés Illanes Albornoz <<lucio@lucioillanes.de>> Copyright (c) 2018 Lucio Andrés Illanes Albornoz <<lucio@lucioillanes.de>>
This project is licensed under the terms of the MIT licence. 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: * 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`

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 270 B

After

Width:  |  Height:  |  Size: 270 B

33702
assets/textures.yaml Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB