Local changes.
authorLibrary Admin <librarian@szo.nowoczesnapolska.org.pl>
Thu, 20 Feb 2014 14:34:24 +0000 (15:34 +0100)
committerLibrary Admin <librarian@szo.nowoczesnapolska.org.pl>
Thu, 20 Feb 2014 14:34:24 +0000 (15:34 +0100)
librarian/functions.py
librarian/pdf.py
librarian/pdf/wl.cls
librarian/pdf/wl2tex.xslt

index 523b3d5..4974f0d 100644 (file)
@@ -5,6 +5,7 @@
 #
 from lxml import etree
 import re
 #
 from lxml import etree
 import re
+from urllib import quote
 
 from librarian.dcparser import Person
 
 
 from librarian.dcparser import Person
 
@@ -104,3 +105,32 @@ def reg_texcommand():
     _register_function(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)
+
index 9fb92b1..da89b63 100644 (file)
@@ -35,6 +35,8 @@ functions.reg_strip()
 functions.reg_starts_white()
 functions.reg_ends_white()
 functions.reg_texcommand()
 functions.reg_starts_white()
 functions.reg_ends_white()
 functions.reg_texcommand()
+functions.reg_urlquote()
+functions.reg_breakurl()
 
 STYLESHEETS = {
     'wl2tex': 'pdf/wl2tex.xslt',
 
 STYLESHEETS = {
     'wl2tex': 'pdf/wl2tex.xslt',
@@ -83,7 +85,7 @@ def substitute_hyphens(doc):
     insert_tags(doc,
                 re.compile("(?<=[^-\s])-(?=[^-\s])"),
                 "dywiz",
     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 (
     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
                     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')
 
         # 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)
         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)
         # 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()
 
         try:
             cwd = os.getcwd()
index c387b03..65ec4fc 100644 (file)
 
 \DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
 \ProcessOptions\relax
 
 \DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
 \ProcessOptions\relax
-\LoadClass[a4paper,oneside]{book}
+%\LoadClass[a4paper,oneside]{book}
+\LoadClass[a4paper]{book}
 
 
 \usepackage{trace}
 
 
 
 \usepackage{trace}
 
+\usepackage{tabularx}
 \usepackage[MeX]{polski}
 
 \usepackage[xetex]{graphicx}
 \usepackage[MeX]{polski}
 
 \usepackage[xetex]{graphicx}
@@ -75,7 +77,9 @@
 
 \usepackage[overload]{textcase}
 \usepackage{scalefnt}
 
 \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 [
 
 \ifenablewlfont
 \setmainfont [
@@ -149,9 +153,12 @@ Letters={SmallCaps,UppercaseSmallCaps}
 \fancyhf{}
 \renewcommand{\headrulewidth}{0pt}
 \renewcommand{\footrulewidth}{0pt}
 \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{}
 \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
 
 \clubpenalty=100000
 \widowpenalty=100000
@@ -203,22 +210,30 @@ Letters={SmallCaps,UppercaseSmallCaps}
     \footnotesize
     \color{theme}
 
     \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}
     \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}
     \end{minipage}
-    \begin{minipage}[t]{.65\textwidth}\vspace{0pt}
+
+%    \begin{minipage}[t]{.45\textwidth}\vspace{0pt}
 
     \ifflaglessadvertising
     \else
 
     \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
 
         \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}
     \noindent \rule{\linewidth}{0.4pt}
 
     \vspace{.6em}
@@ -236,9 +251,9 @@ Letters={SmallCaps,UppercaseSmallCaps}
     \rightsinfo
     \vspace{.6em}
 
     \rightsinfo
     \vspace{.6em}
 
-    Źródło: \href{\bookurl}{\bookurl}
+    %Źródło: \href{\bookurl}{\bookurl}
 
 
-    \vspace{.6em}
+    %\vspace{.6em}
     \sourceinfo
 
     \description
     \sourceinfo
 
     \description
@@ -272,7 +287,8 @@ Letters={Uppercase}
 }
 
 \newcommand{\typosection}[1]{%
 }
 
 \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}}
 }
 
 %{\addfontfeature{Scale=2.0, FakeStretch=0.98, LetterSpace=-2.0}\emph{#1}}
 }
 
@@ -295,7 +311,7 @@ Letters={Uppercase}
 }
 
 \newcommand{\nazwautworu}[1]{%
 }
 
 \newcommand{\nazwautworu}[1]{%
-\section*{\typosection{#1}}%
+\section*{\raggedright{\typosection{#1}}}%
 }
 
 \newcommand{\podtytul}[1]{%
 }
 
 \newcommand{\podtytul}[1]{%
@@ -329,6 +345,7 @@ Letters={Uppercase}
 
 \newcommand{\dlugicytat}[1]{%
 \begin{quotation}%
 
 \newcommand{\dlugicytat}[1]{%
 \begin{quotation}%
+\raggedright%
 #1%
 \end{quotation}%
 }
 #1%
 \end{quotation}%
 }
@@ -371,21 +388,24 @@ Letters={Uppercase}
 \subsection*{\typosubsection{#1}}%
 }
 \newcommand{\srodtytul}[1]{%
 \subsection*{\typosubsection{#1}}%
 }
 \newcommand{\srodtytul}[1]{%
-\subsection*{\typosubsection{#1}}%
+\par{\typosubsubsection{#1}}%
+%\subsection*{\typosubsection{#1}}%
 }
 
 \newcommand{\naglowekscena}[1]{%
 \subsubsection*{\typosubsubsection{#1}}%
 }
 \newcommand{\naglowekrozdzial}[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]{%
 }
 
 \newcommand{\naglowekosoba}[1]{%
 \par{\textsc{#1}}\nopagebreak%
 }
 \newcommand{\naglowekpodrozdzial}[1]{%
-\par{#1}\nopagebreak%
+\subsubsection*{\typosubsubsection{#1}}%
+%\par{#1}\nopagebreak%
 }
 
 \newcommand{\miejsceczas}[1]{%
 }
 
 \newcommand{\miejsceczas}[1]{%
@@ -490,3 +510,26 @@ Letters={Uppercase}
 \fi
 }
 
 \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}%
+}
index 909cf4b..3dc603f 100644 (file)
             \href{http://creativecommons.org/licenses/by-sa/3.0/}{Creative Commons
             Uznanie Autorstwa – Na Tych Samych Warunkach 3.0 PL}.}
         <xsl:if test=".//dc:rights.license">
             \href{http://creativecommons.org/licenses/by-sa/3.0/}{Creative Commons
             Uznanie Autorstwa – Na Tych Samych Warunkach 3.0 PL}.}
         <xsl:if test=".//dc:rights.license">
-            \def\rightsinfo{Ten utwór jest udostepniony na licencji
-            \href{<xsl:value-of select=".//dc:rights.license" />}{<xsl:value-of select=".//dc:rights" />}.}
+            \def\rightsinfo{Ten utwór jest udostępniony na licencji\\
+            \href{<xsl:value-of select=".//dc:rights.license" />}{<TeXML escape="1"><xsl:apply-templates select=".//dc:rights" mode="inline" /></TeXML>}.}
         </xsl:if>
 
         \def\sourceinfo{
             <xsl:if test=".//dc:source">
         </xsl:if>
 
         \def\sourceinfo{
             <xsl:if test=".//dc:source">
-                Tekst opracowany na podstawie: <xsl:apply-templates select=".//dc:source" mode="inline" />
+                Tekst opracowany na podstawie: <TeXML escape="1"><xsl:apply-templates select=".//dc:source" mode="inline" /></TeXML>
                 \vspace{.6em}
             </xsl:if>}
                 \vspace{.6em}
             </xsl:if>}
-        \def\description{<xsl:apply-templates select=".//dc:description" mode="inline" />}
+        \def\description{\raggedright <TeXML escape="1"><xsl:apply-templates select=".//dc:description" mode="inline" /></TeXML>}
     </TeXML>
 </xsl:template>
 
     </TeXML>
 </xsl:template>
 
 </xsl:template>
 
 
 </xsl:template>
 
 
+<xsl:template match="tabela|tabelka">
+    <cmd name="par" />
+    <cmd name="vspace"><parm>1em</parm></cmd>
+    <group><cmd name="raggedright" />
+    <env name="tabularx">
+      <parm><cmd name="textwidth"/></parm>
+        <xsl:choose>
+        <xsl:when test="@ramka='1' or @ramki='1'">
+        <parm><spec cat="vert"/>X<spec cat="vert"/>X<spec cat="vert"/>X<spec cat="vert"/>X<spec cat="vert"/>X<spec cat="vert"/></parm>
+        <cmd name="hline" />
+        <xsl:apply-templates mode="wiersze-ramki"/>
+        </xsl:when>
+        <xsl:otherwise>
+        <parm>XXXXX</parm>
+        <xsl:apply-templates/>
+        </xsl:otherwise>
+        </xsl:choose>
+    </env>
+    </group>
+    <cmd name="vspace"><parm>1em</parm></cmd>
+</xsl:template>
+<xsl:template match="wiersz" mode="wiersze-ramki">
+    <xsl:apply-templates />
+    <spec cat="esc"/><spec cat="esc"/>
+    <cmd name="hline" gr="0" />
+</xsl:template>
+<xsl:template match="wiersz">
+    <xsl:apply-templates />
+    <spec cat="esc"/><spec cat="esc"/>
+</xsl:template>
+
+<xsl:template match="kol">
+    <xsl:apply-templates mode="inline"/>
+    <xsl:if test="position() &lt; last()">
+    <spec cat="align"/>
+    </xsl:if>
+</xsl:template>
+
+<xsl:template match="punkt">
+    <cmd name="punkt"><parm>
+        <xsl:choose>
+        <xsl:when test=".//akap">
+            <xsl:apply-templates />
+        </xsl:when>
+        <xsl:otherwise>
+            <xsl:apply-templates mode="inline"/>
+        </xsl:otherwise>
+        </xsl:choose>
+    </parm></cmd>
+</xsl:template>
+<xsl:template match="lista">
+    <xsl:if test="@typ='num'">
+        <cmd name="listanum">
+            <parm><xsl:apply-templates /></parm>
+        </cmd>
+    </xsl:if>
+    <xsl:if test="@typ='punkt'">
+        <cmd name="listapunkt">
+            <parm><xsl:apply-templates /></parm>
+        </cmd>
+    </xsl:if>
+</xsl:template>
+
+<xsl:template match="ilustr">
+    <cmd name="ilustr">
+        <parm><xsl:value-of select="@src" /></parm>
+        <parm><xsl:value-of select="@alt" /></parm>
+    </cmd>
+</xsl:template>
+
 <!-- ========================================== -->
 <!-- = PARAGRAPH TAGS                         = -->
 <!-- = (can contain inline and special tags)  = -->
 <!-- ========================================== -->
 <!-- = PARAGRAPH TAGS                         = -->
 <!-- = (can contain inline and special tags)  = -->
     </cmd>
 </xsl:template>
 
     </cmd>
 </xsl:template>
 
+<xsl:template match="www" mode="inline">
+    <cmd name="href">
+        <parm><xsl:value-of select="wl:urlquote(text())" /></parm>
+        <parm><cmd name="url"><parm><xsl:value-of select="text()" /></parm></cmd></parm>
+    </cmd>
+</xsl:template>
+
 
 
 <xsl:template match="tytul_dziela" mode="inline">
 
 
 <xsl:template match="tytul_dziela" mode="inline">
 </xsl:template>
 
 <xsl:template name="editors">
 </xsl:template>
 
 <xsl:template name="editors">
-    <xsl:if test="@editors">
+    <!--xsl:if test="@editors">
         <xsl:text>Opracowanie redakcyjne i przypisy: </xsl:text>
         <xsl:value-of select="@editors" />
         <xsl:text>.</xsl:text>
         <xsl:text>Opracowanie redakcyjne i przypisy: </xsl:text>
         <xsl:value-of select="@editors" />
         <xsl:text>.</xsl:text>
+    </xsl:if-->
+    <xsl:if test=".//dc:contributor.editor_parsed">
+    <cmd name="par"><parm>Redakcja literacka:
+    <xsl:for-each select=".//dc:contributor.editor_parsed">
+        <xsl:if test="position() != 1">, </xsl:if>
+        <xsl:apply-templates mode="inline" />
+    </xsl:for-each>
+    </parm></cmd>
+    </xsl:if>
+    <xsl:if test=".//dc:contributor.technical_editor_parsed">
+    <cmd name="par"><parm>Redakcja techniczna:
+    <xsl:for-each select=".//dc:contributor.technical_editor_parsed">
+        <xsl:if test="position() != 1">, </xsl:if>
+        <xsl:apply-templates mode="inline" />
+    </xsl:for-each>
+    </parm></cmd>
     </xsl:if>
     </xsl:if>
+
+
 </xsl:template>
 
 <xsl:template name="translators">
 </xsl:template>
 
 <xsl:template name="translators">
     </group>
 </xsl:template>
 
     </group>
 </xsl:template>
 
+
+
 <!-- ================ -->
 <!-- = IGNORED TAGS = -->
 <!-- ================ -->
 <!-- ================ -->
 <!-- = IGNORED TAGS = -->
 <!-- ================ -->