diff --git a/fsck2025/__init__.py b/fsck2025/__init__.py index 8aaa563..2102589 100644 --- a/fsck2025/__init__.py +++ b/fsck2025/__init__.py @@ -3,6 +3,8 @@ from renderlib import * from schedulelib import * from easing import * +from xml.sax.saxutils import escape as xmlescape +from PIL import ImageFont # URL to Schedule-XML scheduleUrl = "https://cfp.ctbk.de/fsck-2025/schedule/export/schedule.xml" @@ -161,7 +163,37 @@ def debug(): # ) +def fit_text(string: str, max_width: int, font: ImageFont) -> list[str]: + """Break text into array of strings which fit certain a width (in pixels) for the specified font.""" + + split_line = [x.strip() for x in string.split()] + lines = [] + w = 0 + line = [] + for word in split_line: + new_line = line + [word.rstrip(":")] + w = font.getlength(" ".join(new_line)) + if w > max_width: + lines.append(" ".join(line)) + line = [] + + line.append(word.rstrip(":")) + + if word.endswith(":"): + lines.append(" ".join(line)) + line = [] + + if line: + lines.append(" ".join(line)) + + return lines + + def tasks(queue, args, idlist, skiplist): + font = ImageFont.truetype( + "../DIN1451Mittelschrift.ttf", size=74.6667, encoding="unic" + ) + # iterate over all events extracted from the schedule xml-export for event in events(scheduleUrl): # if event["room"] not in ("Medientheater", "Vortragssaal", "Blauer Salon"): @@ -179,14 +211,18 @@ def tasks(queue, args, idlist, skiplist): continue # generate a task description and put it into the queue + title_segments = fit_text(xmlescape(event["title"]), 1920, font) + title = "".join( + f'{el}' for el in title_segments + ) queue.put( Rendertask( infile=["intro.svg", "intro.flac"], outfile=str(event["id"]) + ".ts", sequence=introFrames, parameters={ - "$title": event["title"], - "$personnames": event["personnames"], + "$title": title, + "$personnames": xmlescape(event["personnames"]), }, ) ) diff --git a/fsck2025/artwork/intro.svg b/fsck2025/artwork/intro.svg index 46cd44c..403b87f 100644 --- a/fsck2025/artwork/intro.svg +++ b/fsck2025/artwork/intro.svg @@ -741,10 +741,10 @@ id="title" x="964.69553" y="793.00591" - style="font-size:74.6667px;line-height:1;font-family:'DIN 1451 Mittelschrift';-inkscape-font-specification:'DIN 1451 Mittelschrift, Normal';text-align:center;writing-mode:lr-tb;direction:ltr;white-space:pre;shape-inside:url(#rect4);display:inline;fill:#fae7e3;stroke:#e7ad52;stroke-width:5.6;stroke-linecap:round;stroke-linejoin:round;stroke:none;width:100%;text-anchor:middle">$title + style="font-size:74.6667px;line-height:1;font-family:'DIN 1451 Mittelschrift';-inkscape-font-specification:'DIN 1451 Mittelschrift, Normal';writing-mode:lr-tb;direction:ltr;white-space:pre;shape-inside:url(#rect4);display:inline;fill:#fae7e3;stroke:#e7ad52;stroke-width:5.6;stroke-linecap:round;stroke-linejoin:round;stroke:none;width:100%;text-anchor:middle;">$title $personnames \ No newline at end of file + y="1040.51959">$personnames \ No newline at end of file diff --git a/svgtemplate.py b/svgtemplate.py index 00050e1..d10db28 100644 --- a/svgtemplate.py +++ b/svgtemplate.py @@ -30,7 +30,7 @@ class SVGTemplate: def replacetext(self): for key in self.task.parameters.keys(): - self.svgstr = self.svgstr.replace(key, xmlescape(str(self.task.parameters[key]))) + self.svgstr = self.svgstr.replace(key, str(self.task.parameters[key])) def transform(self, frame): parser = etree.XMLParser(huge_tree=True)