From 780d938ad20fe8e46f828fd167afdc076c31c28c Mon Sep 17 00:00:00 2001 From: Library Admin Date: Thu, 20 Feb 2014 15:34:24 +0100 Subject: [PATCH] Local changes. --- librarian/functions.py | 30 +++++++++++ librarian/pdf.py | 14 ++++- librarian/pdf/wl.cls | 79 +++++++++++++++++++++------- librarian/pdf/wl2tex.xslt | 107 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 205 insertions(+), 25 deletions(-) diff --git a/librarian/functions.py b/librarian/functions.py index 523b3d5..4974f0d 100644 --- a/librarian/functions.py +++ b/librarian/functions.py @@ -5,6 +5,7 @@ # from lxml import etree import re +from urllib import quote from librarian.dcparser import Person @@ -104,3 +105,32 @@ def reg_texcommand(): _register_function(texcommand) +def reg_urlquote(): + def urlquote(content, text): + """ Quotes URLs """ + if isinstance(text, list): + text = ''.join(text) + return quote(text.encode('utf-8'), safe="/:") + _register_function(urlquote) + +def reg_breakurl(): + def breakurl(content, text): + """ Allows breaks in urls """ + if isinstance(text, list): + text = ''.join(text) + chunks = text.split("/") + e = etree.Element("span") + e.text = chunks[0] + ret = etree.Element("span") + ret.append(e) + for chunk in chunks[1:]: + ret.append(etree.Element("span", text="/")) + ret[-1].text = "/" + ret.append(etree.Element("cmd", {"name": "linebreak"})) + ret[-1].append(etree.Element("opt")) + ret[-1][-1].text = "1" + ret[-1].tail = chunk + return ret + #return re.sub(r'(/)([^/])', r'\1\\-\2', text) + _register_function(breakurl) + diff --git a/librarian/pdf.py b/librarian/pdf.py index 9fb92b1..da89b63 100644 --- a/librarian/pdf.py +++ b/librarian/pdf.py @@ -35,6 +35,8 @@ functions.reg_strip() functions.reg_starts_white() functions.reg_ends_white() functions.reg_texcommand() +functions.reg_urlquote() +functions.reg_breakurl() STYLESHEETS = { 'wl2tex': 'pdf/wl2tex.xslt', @@ -83,7 +85,7 @@ def substitute_hyphens(doc): insert_tags(doc, re.compile("(?<=[^-\s])-(?=[^-\s])"), "dywiz", - exclude=[DCNS("identifier.url"), DCNS("rights.license")] + exclude=[DCNS("identifier.url"), DCNS("rights.license"), 'www'] ) @@ -147,7 +149,8 @@ def parse_creator(doc): and adds *_parsed versions with forenames first. """ for person in doc.xpath("|".join('//dc:'+(tag) for tag in ( - 'creator', 'contributor.translator')), + 'creator', 'contributor.translator', + 'contributor.editor', 'contributor.technical_editor')), namespaces = {'dc': str(DCNS)})[::-1]: if not person.text: continue @@ -248,6 +251,9 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, # TeXML -> LaTeX temp = mkdtemp('-wl2pdf') + for ilustr in document.edoc.findall("//ilustr"): + shutil.copy(ilustr.get("src"), temp) + if cover: with open(os.path.join(temp, 'cover.png'), 'w') as f: bound_cover.save(f) @@ -266,6 +272,10 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, # LaTeX -> PDF shutil.copy(get_resource('pdf/wl.cls'), temp) shutil.copy(get_resource('res/wl-logo.png'), temp) + #shutil.copy(get_resource('res/prawokultury-logo.png'), temp) + #shutil.copy(get_resource('res/trust-logo.eps'), temp) + shutil.copy(get_resource('res/nowoczesnapolska.org.pl.png'), temp) + shutil.copy(get_resource('res/koedlogo.png'), temp) try: cwd = os.getcwd() diff --git a/librarian/pdf/wl.cls b/librarian/pdf/wl.cls index c387b03..65ec4fc 100644 --- a/librarian/pdf/wl.cls +++ b/librarian/pdf/wl.cls @@ -61,11 +61,13 @@ \DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}} \ProcessOptions\relax -\LoadClass[a4paper,oneside]{book} +%\LoadClass[a4paper,oneside]{book} +\LoadClass[a4paper]{book} \usepackage{trace} +\usepackage{tabularx} \usepackage[MeX]{polski} \usepackage[xetex]{graphicx} @@ -75,7 +77,9 @@ \usepackage[overload]{textcase} \usepackage{scalefnt} -\usepackage[colorlinks=true,linkcolor=black,setpagesize=false,urlcolor=black,xetex]{hyperref} +\usepackage[hyphens]{url} +%\usepackage[colorlinks=true,linkcolor=black,setpagesize=false,urlcolor=black,xetex,unicode]{hyperref} +\usepackage[colorlinks=true,linkcolor=black,setpagesize=false,urlcolor=blue,xetex,unicode]{hyperref} \ifenablewlfont \setmainfont [ @@ -149,9 +153,12 @@ Letters={SmallCaps,UppercaseSmallCaps} \fancyhf{} \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt} -\lfoot{{\footnotesize \textsc{\@author} \emph{\@title}}} +% CAUTION! Manually entered text. +%\lfoot{{\footnotesize \textsc{\@author} \emph{\@title}}} +\rfoot[{\footnotesize \thepage}]{{\footnotesize \textsc{\@author} \emph{Dlaczego nie warto blokować użycia komercyjnego\ldots}}} \cfoot{} -\rfoot{{\footnotesize \thepage}} +%\rfoot{{\footnotesize \thepage}} +\lfoot[{\footnotesize \textsc{\@author} \emph{Dlaczego nie warto blokować użycia komercyjnego\ldots}}]{{\footnotesize \thepage}} \clubpenalty=100000 \widowpenalty=100000 @@ -203,22 +210,30 @@ Letters={SmallCaps,UppercaseSmallCaps} \footnotesize \color{theme} + \noindent \begin{minipage}[t]{.65\textwidth}\vspace{0pt} + %\href{http://prawokultury.pl}{\xbox{\includegraphics[width=1in]{prawokultury-logo.png}}} + \href{http://koed.org.pl}{\xbox{\includegraphics[height=.55in]{koedlogo.png}}} + \end{minipage} \noindent \begin{minipage}[t]{.35\textwidth}\vspace{0pt} - \href{http://www.wolnelektury.pl}{\xbox{\includegraphics[width=\textwidth]{wl-logo.png}}} + \raggedright + %\xbox{\includegraphics[width=1.6in]{trust-logo.eps}} + \href{http://nowoczesnapolska.org.pl}{\xbox{\includegraphics[height=.55in]{nowoczesnapolska.org.pl.png}}} + \vspace{.5em} \end{minipage} - \begin{minipage}[t]{.65\textwidth}\vspace{0pt} + +% \begin{minipage}[t]{.45\textwidth}\vspace{0pt} \ifflaglessadvertising \else - \href{\bookurl}{Ta lektura}, podobnie jak tysiące innych, jest dostępna on-line na stronie - \href{http://www.wolnelektury.pl/}{wolnelektury.pl}. + %\noindent Ten rozdział pochodzi z książki \emph{\@title}, która zostanie opublikowana w portalu + %\href{http://prawokultury.pl/}{prawokultury.pl}. \vspace{.5em} \fi - Utwór opracowany został w ramach projektu \href{http://www.wolnelektury.pl/}{Wolne Lektury} - przez \href{http://nowoczesnapolska.org.pl}{fundację Nowoczesna Polska}. + % Utwór opracowany został w ramach projektu \href{http://www.wolnelektury.pl/}{Wolne Lektury} + % przez \href{http://nowoczesnapolska.org.pl}{fundację Nowoczesna Polska}. - \end{minipage} + % \end{minipage} \noindent \rule{\linewidth}{0.4pt} \vspace{.6em} @@ -236,9 +251,9 @@ Letters={SmallCaps,UppercaseSmallCaps} \rightsinfo \vspace{.6em} - Źródło: \href{\bookurl}{\bookurl} + %Źródło: \href{\bookurl}{\bookurl} - \vspace{.6em} + %\vspace{.6em} \sourceinfo \description @@ -272,7 +287,8 @@ Letters={Uppercase} } \newcommand{\typosection}[1]{% -{\addfontfeature{FakeStretch=0.96, LetterSpace=-4.0}\emph{\scalefont{2}#1}} +%{\addfontfeature{FakeStretch=0.96, LetterSpace=-4.0}\emph{\scalefont{2}#1}} +{\addfontfeature{FakeStretch=0.96, LetterSpace=-4.0}\emph{\scalefont{1.7}#1}} %{\addfontfeature{Scale=2.0, FakeStretch=0.98, LetterSpace=-2.0}\emph{#1}} } @@ -295,7 +311,7 @@ Letters={Uppercase} } \newcommand{\nazwautworu}[1]{% -\section*{\typosection{#1}}% +\section*{\raggedright{\typosection{#1}}}% } \newcommand{\podtytul}[1]{% @@ -329,6 +345,7 @@ Letters={Uppercase} \newcommand{\dlugicytat}[1]{% \begin{quotation}% +\raggedright% #1% \end{quotation}% } @@ -371,21 +388,24 @@ Letters={Uppercase} \subsection*{\typosubsection{#1}}% } \newcommand{\srodtytul}[1]{% -\subsection*{\typosubsection{#1}}% +\par{\typosubsubsection{#1}}% +%\subsection*{\typosubsection{#1}}% } \newcommand{\naglowekscena}[1]{% \subsubsection*{\typosubsubsection{#1}}% } \newcommand{\naglowekrozdzial}[1]{% -\subsubsection*{\typosubsubsection{#1}}% +\subsection*{\raggedright \typosubsection{#1}}% +%\subsubsection*{\typosubsubsection{#1}}% } \newcommand{\naglowekosoba}[1]{% \par{\textsc{#1}}\nopagebreak% } \newcommand{\naglowekpodrozdzial}[1]{% -\par{#1}\nopagebreak% +\subsubsection*{\typosubsubsection{#1}}% +%\par{#1}\nopagebreak% } \newcommand{\miejsceczas}[1]{% @@ -490,3 +510,26 @@ Letters={Uppercase} \fi } + +\newcommand{\www}[1]{% +%\href{#1}{#1}% +\url{#1}% +} +\newcommand{\listanum}[1]{% +\begin{enumerate}% +#1% +\end{enumerate}% +} +\newcommand{\listapunkt}[1]{% +\begin{itemize}% +#1% +\end{itemize}% +} +\newcommand{\punkt}[1]{% +\item #1% +} +\newcommand{\ilustr}[2]{% +\vspace{1em}% +\par{\noindent\includegraphics[width=\textwidth]{#1}}% +\vspace{1em}% +} diff --git a/librarian/pdf/wl2tex.xslt b/librarian/pdf/wl2tex.xslt index 909cf4b..3dc603f 100644 --- a/librarian/pdf/wl2tex.xslt +++ b/librarian/pdf/wl2tex.xslt @@ -155,16 +155,16 @@ \href{http://creativecommons.org/licenses/by-sa/3.0/}{Creative Commons Uznanie Autorstwa – Na Tych Samych Warunkach 3.0 PL}.} - \def\rightsinfo{Ten utwór jest udostepniony na licencji - \href{}{}.} + \def\rightsinfo{Ten utwór jest udostępniony na licencji\\ + \href{}{}.} \def\sourceinfo{ - Tekst opracowany na podstawie: + Tekst opracowany na podstawie: \vspace{.6em} } - \def\description{} + \def\description{\raggedright } @@ -230,6 +230,76 @@ + + + 1em + + + + + + XXXXX + + + + + XXXXX + + + + + + 1em + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -323,6 +393,13 @@ + + + + + + + @@ -377,11 +454,29 @@ - + + + Redakcja literacka: + + , + + + + + + Redakcja techniczna: + + , + + + + + @@ -416,6 +511,8 @@ + + -- 2.20.1