Compare commits
No commits in common. "8dcbb67cae89b60cfa5e797f033e4180228aeb2d" and "98d09db5e87fcf5a9407049583db7f05eabb123a" have entirely different histories.
8dcbb67cae
...
98d09db5e8
4 changed files with 15 additions and 56 deletions
|
@ -15,7 +15,6 @@ class State(enum.Enum):
|
||||||
STARTED = 2
|
STARTED = 2
|
||||||
DONE = 3
|
DONE = 3
|
||||||
|
|
||||||
|
|
||||||
class Concat(dcc.doom_base.Wad):
|
class Concat(dcc.doom_base.Wad):
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super().get_parser(prog_name)
|
parser = super().get_parser(prog_name)
|
||||||
|
@ -50,11 +49,7 @@ class Concat(dcc.doom_base.Wad):
|
||||||
# Presumably fixable, but it's easier to just make one graph per video
|
# Presumably fixable, but it's easier to just make one graph per video
|
||||||
# and mux everything together at the end.
|
# and mux everything together at the end.
|
||||||
# TODO: Support UDoom in literally any way.
|
# TODO: Support UDoom in literally any way.
|
||||||
d2maps = (
|
d2maps = [str(x).zfill(2) for x in range(1,16)] + ["31","32"] + [str(x) for x in range(16,31)]
|
||||||
[str(x).zfill(2) for x in range(1, 16)]
|
|
||||||
+ ["31", "32"]
|
|
||||||
+ [str(x) for x in range(16, 31)]
|
|
||||||
)
|
|
||||||
state = State.NOT_STARTED
|
state = State.NOT_STARTED
|
||||||
for idx in d2maps:
|
for idx in d2maps:
|
||||||
if idx == parsed_args.start_map:
|
if idx == parsed_args.start_map:
|
||||||
|
|
|
@ -61,17 +61,17 @@ class ConfigBase(object):
|
||||||
return self._doom.joinpath(self._dsda)
|
return self._doom.joinpath(self._dsda)
|
||||||
|
|
||||||
|
|
||||||
def get_parser_func(toc):
|
def AddCommonArgs(parser):
|
||||||
def add_common_args(self, prog_name):
|
parser.add_argument(
|
||||||
parser = super(toc, self).get_parser(prog_name)
|
"--doom", default=pathlib.Path.home().joinpath("doom"))
|
||||||
parser.add_argument(
|
parser.add_argument("--config-name", default="config.toml")
|
||||||
"--doom", default=pathlib.Path.home().joinpath("doom"))
|
return parser
|
||||||
parser.add_argument("--config-name", default="config.toml")
|
|
||||||
return parser
|
|
||||||
return add_common_args
|
|
||||||
|
|
||||||
|
|
||||||
class Base(cliff.command.Command, ConfigBase):
|
class Base(cliff.command.Command, ConfigBase):
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
return AddCommonArgs(super().get_parser(prog_name))
|
||||||
|
|
||||||
def run(self, parsed_args):
|
def run(self, parsed_args):
|
||||||
super().init_base(parsed_args)
|
super().init_base(parsed_args)
|
||||||
super().finalize()
|
super().finalize()
|
||||||
|
@ -79,13 +79,12 @@ class Base(cliff.command.Command, ConfigBase):
|
||||||
|
|
||||||
|
|
||||||
class ListerBase(cliff.lister.Lister, ConfigBase):
|
class ListerBase(cliff.lister.Lister, ConfigBase):
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
return AddCommonArgs(super().get_parser(prog_name))
|
||||||
|
|
||||||
def run(self, parsed_args):
|
def run(self, parsed_args):
|
||||||
super().init_base(parsed_args)
|
super().init_base(parsed_args)
|
||||||
super().finalize()
|
super().finalize()
|
||||||
self.formatter = self._formatter_plugins[parsed_args.formatter].obj
|
self.formatter = self._formatter_plugins[parsed_args.formatter].obj
|
||||||
columns, data = self.take_action(parsed_args)
|
columns, data = self.take_action(parsed_args)
|
||||||
return self.produce_output(parsed_args, columns, data)
|
return self.produce_output(parsed_args, columns, data)
|
||||||
|
|
||||||
|
|
||||||
for toc in (Base, ListerBase):
|
|
||||||
toc.get_parser = get_parser_func(toc)
|
|
||||||
|
|
38
dcc/text.py
38
dcc/text.py
|
@ -1,13 +1,11 @@
|
||||||
import dcc.config
|
import dcc.config
|
||||||
import dcc.doom_base
|
import dcc.doom_base
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
|
||||||
import wand.drawing
|
import wand.drawing
|
||||||
import wand.image
|
import wand.image
|
||||||
|
|
||||||
|
|
||||||
def draw_text(self, img, text, font_size=64, wrap_dist=0.75):
|
def draw_text(self, img, text, font_size=64):
|
||||||
textlines = text.splitlines()
|
|
||||||
with wand.drawing.Drawing() as draw:
|
with wand.drawing.Drawing() as draw:
|
||||||
draw.font = self.thumbnail_font
|
draw.font = self.thumbnail_font
|
||||||
draw.font_size = font_size
|
draw.font_size = font_size
|
||||||
|
@ -15,41 +13,11 @@ def draw_text(self, img, text, font_size=64, wrap_dist=0.75):
|
||||||
draw.stroke_color = wand.color.Color(self.thumbnail_text_stroke)
|
draw.stroke_color = wand.color.Color(self.thumbnail_text_stroke)
|
||||||
draw.stroke_width = font_size * 5 / 32
|
draw.stroke_width = font_size * 5 / 32
|
||||||
draw.text_interline_spacing = -font_size / 4
|
draw.text_interline_spacing = -font_size / 4
|
||||||
|
draw.text(5, int(draw.font_size) + 5, text)
|
||||||
target_width = wrap_dist * img.width
|
|
||||||
|
|
||||||
def eval_metrics(txt):
|
|
||||||
metrics = draw.get_font_metrics(img, wrapped_text, True)
|
|
||||||
return (metrics.text_width, metrics.text_height)
|
|
||||||
|
|
||||||
for idx, wrapped_text in enumerate(textlines):
|
|
||||||
while True:
|
|
||||||
width, height = eval_metrics(wrapped_text)
|
|
||||||
if width <= target_width:
|
|
||||||
break
|
|
||||||
columns = len(wrapped_text)
|
|
||||||
while columns > 0:
|
|
||||||
columns -= 1
|
|
||||||
wrapped_text = '\n'.join(
|
|
||||||
textwrap.wrap(wrapped_text, columns)
|
|
||||||
)
|
|
||||||
wrapped_width, _ = eval_metrics(wrapped_text)
|
|
||||||
if wrapped_width <= target_width:
|
|
||||||
break
|
|
||||||
if columns == 0:
|
|
||||||
raise Exception(
|
|
||||||
"couldn't calculate text wrapping; "
|
|
||||||
+ f"final attempt was {wrapped_text}"
|
|
||||||
)
|
|
||||||
textlines[idx] = wrapped_text
|
|
||||||
|
|
||||||
wrapped_text = '\n'.join(textlines)
|
|
||||||
|
|
||||||
draw.text(5, int(draw.font_size) + 5, wrapped_text)
|
|
||||||
draw(img)
|
draw(img)
|
||||||
draw.stroke_color = wand.color.Color("none")
|
draw.stroke_color = wand.color.Color("none")
|
||||||
draw.stroke_width = 0
|
draw.stroke_width = 0
|
||||||
draw.text(5, int(draw.font_size)+5, wrapped_text)
|
draw.text(5, int(draw.font_size)+5, text)
|
||||||
draw(img)
|
draw(img)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,3 @@ dcc = "dcc.main:main"
|
||||||
|
|
||||||
[tool.poetry-pyinstaller-plugin.scripts]
|
[tool.poetry-pyinstaller-plugin.scripts]
|
||||||
dcc = { source = "dcc/main.py", type = "onefile" }
|
dcc = { source = "dcc/main.py", type = "onefile" }
|
||||||
|
|
||||||
[tool.poetry-pyinstaller-plugin.collect]
|
|
||||||
all = ["cliff"]
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue