render_video/src/iotro.rs

115 lines
2.5 KiB
Rust

//! A module for writing intros and outros
use crate::{
time::{format_date_long, Date},
Resolution
};
use svgwriter::{
tags::{Group, Rect, TagWithPresentationAttributes, Text},
Graphic
};
#[repr(u16)]
enum FontSize {
Huge = 72,
Large = 56,
Big = 44
}
#[repr(u16)]
enum FontWeight {
Normal = 400,
SemiBold = 500,
Bold = 700
}
struct Iotro {
res: Resolution,
g: Group
}
impl Iotro {
fn new(res: Resolution) -> Self {
Self {
res,
g: Group::new()
.with_fill("white")
.with_text_anchor("middle")
.with_dominant_baseline("hanging")
.with_font_family("Noto Sans")
}
}
fn add_text<T: Into<String>>(
&mut self,
font_size: FontSize,
font_weight: FontWeight,
y_top: usize,
content: T
) {
let mut text = Text::new()
.with_x(960)
.with_y(y_top)
.with_font_size(font_size as u16)
.with_font_weight(font_weight as u16);
text.push(content.into());
self.g.push(text);
}
fn finish(self) -> Graphic {
let mut svg = Graphic::new();
svg.set_width(self.res.width());
svg.set_height(self.res.height());
svg.set_view_box("0 0 1920 1080");
svg.push(
Rect::new()
.with_fill("black")
.with_x(0)
.with_y(0)
.with_width(1920)
.with_height(1080)
);
svg.push(self.g);
svg
}
}
pub(crate) fn intro(res: Resolution, date: Date) -> Graphic {
use self::{FontSize::*, FontWeight::*};
let mut intro = Iotro::new(res);
intro.add_text(Huge, Bold, 110, "Mathematische Logik II");
intro.add_text(Huge, SemiBold, 250, "Prof. E. Grädel");
intro.add_text(
Huge,
SemiBold,
460,
format!("Vorlesung vom {}", format_date_long(date))
);
intro.add_text(
Big,
Normal,
870,
"Video erstellt von der Video AG, Fachschaft I/1"
);
intro.add_text(Big, Normal, 930, "https://video.fsmpi.rwth-aachen.de");
intro.add_text(Big, Normal, 990, "video@fsmpi.rwth-aachen.de");
intro.finish()
}
pub(crate) fn outro(res: Resolution) -> Graphic {
use self::{FontSize::*, FontWeight::*};
let mut outro = Iotro::new(res);
outro.add_text(Large, SemiBold, 50, "Video erstellt von der");
outro.add_text(Huge, Bold, 210, "Video AG, Fachschaft I/1");
outro.add_text(Large, Normal, 360, "Website der Fachschaft:");
outro.add_text(Large, Normal, 430, "https://www.fsmpi.rwth-aachen.de");
outro.add_text(Large, Normal, 570, "Videos herunterladen:");
outro.add_text(Large, Normal, 640, "https://video.fsmpi.rwth-aachen.de");
outro.add_text(Large, Normal, 780, "Fragen, Vorschläge und Feedback:");
outro.add_text(Large, Normal, 850, "video@fsmpi.rwth-aachen.de");
outro.finish()
}