From: Radek Czajka Date: Wed, 10 Apr 2024 11:03:46 +0000 (+0200) Subject: Fundraising in PDF. X-Git-Tag: 24.4~1 X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/102460ac788a7307391852115d8f142e6e5c3cdd?hp=b13f09caed970090efa8a6c7205d71cc82ff6c97 Fundraising in PDF. --- diff --git a/src/librarian/pdf.py b/src/librarian/pdf.py index 94d14cf..e5cf5bd 100644 --- a/src/librarian/pdf.py +++ b/src/librarian/pdf.py @@ -188,6 +188,29 @@ def hack_motifs(doc): break +def add_fundraising(doc, fundraising): + # Before each naglowek_rozdzial and naglowek_scena and in the end + spots = [] + for naglowek in doc.xpath('//naglowek_czesc|//naglowek_akt'): + spot = etree.Element('f_spot') + naglowek.addprevious(spot) + spots.append(spot) + spot = etree.Element('f_spot') + doc.getroot()[-1][-1].append(spot) + spots.append(spot) + e = len(spots) + nfunds = len(fundraising) + if e > 4 * nfunds: + nfunds *= 2 + for f in range(nfunds): + spot_index = int(f / nfunds * e) + spots[spot_index].set('active', 'true') + elem = etree.fromstring('' + fundraising[f % len(fundraising)] + '') + spots[spot_index].text = elem.text + for c in elem: + spots[spot_index].append(c) + + def parse_creator(doc): """Generates readable versions of creator and translator tags. @@ -242,7 +265,7 @@ def package_available(package, args='', verbose=False): def transform(wldoc, verbose=False, save_tex=None, morefloats=None, cover=None, flags=None, customizations=None, base_url='file://./', - latex_dir=False): + latex_dir=False, fundraising=None): """ produces a PDF file with XeLaTeX wldoc: a WLDocument @@ -305,6 +328,8 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, root.set('thanks', document.book_info.thanks) # hack the tree + if fundraising: + add_fundraising(document.edoc, fundraising) move_motifs_inside(document.edoc) hack_motifs(document.edoc) parse_creator(document.edoc) diff --git a/src/librarian/pdf/wl.cls b/src/librarian/pdf/wl.cls index aa6abc2..d2eac63 100644 --- a/src/librarian/pdf/wl.cls +++ b/src/librarian/pdf/wl.cls @@ -722,6 +722,7 @@ Letters={Uppercase} \par{\emph{#1}}% } +\usepackage{framed} \usepackage{intcalc} \usepackage{color} \definecolor{gray}{RGB}{200,200,200} diff --git a/src/librarian/pdf/wl2tex.xslt b/src/librarian/pdf/wl2tex.xslt index bb61d10..ab189e0 100644 --- a/src/librarian/pdf/wl2tex.xslt +++ b/src/librarian/pdf/wl2tex.xslt @@ -678,4 +678,39 @@ + + + + + empty + + + + 2em + + + + 2em + + + + + + + + \\ + + + + + + + \href{}{} + + + + + + +