mirror of
https://github.com/MarcZierle/photo-log-backend.git
synced 2024-12-29 10:57:58 +00:00
56 lines
3.6 KiB
Python
Executable File
56 lines
3.6 KiB
Python
Executable File
from datetime import datetime
|
|
from django.conf import settings
|
|
|
|
import os
|
|
|
|
|
|
def generate_tex(title, date, render_date, start_slide_image, slides, id_to_name, work_dir):
|
|
log_start = "% !TEX program = xelatex\n\\documentclass[aspectratio=169]{beamer}\n\\usepackage{graphicx}\n\\usepackage{tikz}\n\\usepackage[absolute,overlay]{textpos}\n\\definecolor{gray1}{rgb}{0.85,0.85,0.85}\n\\definecolor{gray2}{rgb}{0.95,0.95,0.95}\n\\setbeamertemplate{background canvas}{%\n\\begin{tikzpicture}[remember picture,overlay]\n\\begin{scope}[xshift=0.55\\textwidth, yshift=-4.5cm]\n\\fill[even odd rule,inner color=gray2,outer color=gray1] (0,0) circle (10);\n\\node[inner sep=0pt] at (0.26,-4.02) {\\includegraphics[width=1.16\\textwidth]{wood_floor}};\n\\end{scope}\n\\end{tikzpicture}%\n}\n\\setbeamertemplate{navigation symbols}{}\n\\vfuzz=1000pt\n\\hfuzz=1000pt\n\\usepackage{fontspec}\n\\newfontfamily{\\gill} [ Path = "+str(settings.CELERY_WORK_DIR)+"/photolog_assets/,UprightFont = * Medium,BoldFont = * Bold] {Gill Sans MT}\n\\definecolor{title_line_red}{rgb}{0.8,0.2,0.2}\n\\makeatletter\n\\let\\old@rule\\@rule\n\\def\\@rule[#1]#2#3{\\textcolor{title_line_red}{\\old@rule[#1]{#2}{#3}}}\n\\makeatother\n\\title{Fotoprotokoll}\n\\author{Antje Zierle-Kohlmorgen}\n\\institute{Zierle-Training}\n\\date{2022}\n\\begin{document}\n\\gill"
|
|
log_end = "\\begin{frame}\n\\begin{columns}\n\\begin{column}{0.6\\textwidth}\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{smile}\n\\end{center}\n\\end{column}\n\\begin{column}{0.4\\textwidth}\n\\Huge{Viel Erfolg!}\n\\end{column}\n\\end{columns}\n\\end{frame}\n\\end{document}"
|
|
|
|
title_slide_start = "\\begin{frame}\n\\begin{textblock*}{13.0cm}(3cm,1.75cm)\n\\huge{"
|
|
title_slide_end_w_photo = "}\\\\[-0.25cm]\n\\rule{14cm}{0.05cm}\n\\begin{tikzpicture}[remember picture, overlay]\n\\node[xshift=0.8\\textwidth,yshift=-0.5cm]{\\includegraphics[height=4.5cm]{%s}};\n\\end{tikzpicture}\n\\end{textblock*}\n\\end{frame}"
|
|
title_slide_end_wo_photo = "}\\\\[-0.25cm]\n\\rule{14cm}{0.05cm}\n\n\\end{textblock*}\n\\end{frame}"
|
|
|
|
slide_start = "\\begin{frame}\n\\begin{columns}"
|
|
slide_end = "\\end{columns}\n\\hfill\\\\[1.5cm]\n\\end{frame}"
|
|
|
|
photo_start = "\\begin{column}{%.3f\\textwidth}\n\\begin{center}\n\\includegraphics[height=6.5cm]{"
|
|
photo_end = "}\\end{center}\n\\end{column}"
|
|
|
|
assets_path = "{%s}" % (os.path.abspath(os.path.join(work_dir, '..', 'photolog_assets')))
|
|
photos_path = "{%s}" % (str(work_dir))
|
|
include_paths = "\\graphicspath{"+assets_path+","+photos_path+"}\n"
|
|
|
|
tex_file_content = log_start
|
|
tex_file_content += include_paths
|
|
|
|
tex_file_content += title_slide_start + title
|
|
if date and render_date:
|
|
date = datetime.strptime(date, '%Y-%m-%dT%H:%M:%S')
|
|
tex_file_content += "\\\\" + date.strftime("%d.%m.%Y")
|
|
|
|
if start_slide_image:
|
|
tex_file_content += title_slide_end_w_photo % (id_to_name[str(start_slide_image)])
|
|
else:
|
|
tex_file_content += title_slide_end_wo_photo
|
|
|
|
for slide in slides:
|
|
tex_file_content += slide_start
|
|
num_none_photos = sum([1 for p in slide if p==None])
|
|
|
|
for photo_id in slide:
|
|
if not photo_id:
|
|
continue
|
|
if num_none_photos == 2: # slides are saved as [2, None, None] for only 1 image
|
|
tex_file_content += photo_start % (3.0/len(slide))
|
|
else:
|
|
tex_file_content += photo_start % (1.0/len(slide))
|
|
tex_file_content += id_to_name[str(photo_id)]
|
|
tex_file_content += photo_end
|
|
tex_file_content += slide_end
|
|
|
|
tex_file_content += log_end
|
|
|
|
return tex_file_content
|