Skip to content

Commit

Permalink
support for text wrapped around pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvorobiev committed Aug 2, 2011
1 parent a4b171a commit 6e340f9
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 5 deletions.
6 changes: 4 additions & 2 deletions dbkindle.sty
Expand Up @@ -156,7 +156,7 @@
\checkandfixthelayout

\definecolor{light-gray}{gray}{0.95}
\renewcommand*{\trimmarkscolor}{\color{light-gray}}
\newcommand*{\trimmarkscolor}{\color{light-gray}}

% font
\usepackage{dbkindle_font}
Expand Down Expand Up @@ -211,8 +211,10 @@
\setlength{\epigraphwidth}{\stockwidth * 3 / 4}
\epigraphfontsize{\footnotesize}

\usepackage{footnpag} % reset footnote counter when new page starts

\usepackage{dbkindle_unicode}
\usepackage{dbkindle_title}
\usepackage{dbkindle_verbatim}

\usepackage{dbkindle_graphics}

33 changes: 33 additions & 0 deletions dbkindle_graphics.sty
@@ -0,0 +1,33 @@
\usepackage{wrapfig}

\setlength{\intextsep}{0.25\baselineskip}

\newlength{\saveimagewidth}
\newsavebox{\saveimagebox}
\newcounter{figurecounter}

% Enclose the image in either wrapfigure of figure environment depending on its (rescaled) width
% The first parameter is treshold - multiple of textwith, the second parameter is image file name
\newcommand{\wrapifneeded}[2]{%
\savebox{\saveimagebox}{\includegraphics[width=\imgwidth,height=\imgheight,keepaspectratio=true]{#2}}
\settowidth{\saveimagewidth}{\usebox{\saveimagebox}}

\ifdim\saveimagewidth<#1\textwidth
\ifthenelse{\isodd{\value{figurecounter}}}{

\begin{wrapfigure}{R}{\saveimagewidth}
\usebox{\saveimagebox}
\end{wrapfigure}
}{
\begin{wrapfigure}{L}{\saveimagewidth}
\usebox{\saveimagebox}
\end{wrapfigure}
}
\else
\begin{figure}[h] %
\centering %
\usebox{\saveimagebox}
\end{figure}
\fi
\stepcounter{figurecounter}
}
3 changes: 1 addition & 2 deletions dbkindle_title.sty
@@ -1,5 +1,4 @@
% see documentation for memoir class

\makechapterstyle{centered}{%
\chapterstyle{default}
\setlength{\beforechapskip}{5\onelineskip}
Expand All @@ -18,7 +17,7 @@
\par\nobreak\vskip 0.5\onelineskip
% \Pisymbol{MinionPro-Extra}{110}
\Pisymbol{MinionPro-Extra}{120}
% \textxswup
% \textxswup
}
\setlength{\afterchapskip}{2.5\onelineskip}}

Expand Down
27 changes: 27 additions & 0 deletions dbkindle_title_hierog.sty
@@ -0,0 +1,27 @@
% see documentation for memoir class
\usepackage{hieroglf}
\makechapterstyle{centered}{%
\chapterstyle{default}
\setlength{\beforechapskip}{5\onelineskip}
\renewcommand*{\printchaptername}{}
\renewcommand*{\chapternamenum}{}
\renewcommand*{\chapnumfont}{\normalfont\large}
\settoheight{\midchapskip}{\chapnumfont 1}
\renewcommand*{\printchapternum}{\centering \chapnumfont
\thechapter\
}
\renewcommand*{\afterchapternum}{\par\nobreak\vskip 0.5\onelineskip}
\renewcommand*{\printchapternonum}{\centering
\vphantom{\chapnumfont 1}\afterchapternum}
\renewcommand*{\chaptitlefont}{\normalfont\Large}
\renewcommand*{\printchaptertitle}[1]{\centering \chaptitlefont ##1
\par\nobreak\vskip 0.5\onelineskip
% \Pisymbol{MinionPro-Extra}{110}
%\Pisymbol{MinionPro-Extra}{120}
\pmglyph{A:n-y-a}
% \textxswup
}
\setlength{\afterchapskip}{2.5\onelineskip}}

\chapterstyle{centered}
%\renewcommand*{\chaptitlefont}{\fontfamily{antt}\fontshape{bf}\selectfont}
5 changes: 4 additions & 1 deletion param.xsl
Expand Up @@ -8,6 +8,7 @@
<xsl:import href="xsl/lettrine.xsl"/>
<xsl:import href="xsl/poem.xsl"/>
<xsl:import href="xsl/epigraph.xsl"/>
<xsl:import href="xsl/image.xsl"/>

<!-- Options used for documentclass -->

Expand Down Expand Up @@ -74,7 +75,9 @@

<!-- Empty <literallayout> is produced by FB2's <emptyline/>-->
<xsl:template match="literallayout[.='']">
<xsl:text>\par \vspace{\baselineskip}</xsl:text>
<xsl:if test="not(preceding-sibling::node()[1][name()='mediaobject']) and not(following-sibling::node()[1][name()='mediaobject'])">
<xsl:text>\par \vspace{\baselineskip}</xsl:text>
</xsl:if>
</xsl:template>

<!-- Fancy breaks -->
Expand Down
22 changes: 22 additions & 0 deletions xsl/image.xsl
@@ -0,0 +1,22 @@
<?xml version='1.0' encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl"
version='1.0'>

<!-- Images narrower than this portion of line width will be surrounded by text -->
<xsl:param name="wrapimage.treshold">0.4</xsl:param>

<xsl:template match="mediaobject">
<xsl:call-template name="processimage">
<xsl:with-param name="image" select="./imageobject/imagedata/@fileref"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="processimage">
<xsl:param name="image" select="."/>
<xsl:text>\wrapifneeded{</xsl:text><xsl:value-of select="$wrapimage.treshold"/>
<xsl:text>}{</xsl:text><xsl:value-of select="$image"/><xsl:text>} %&#10;</xsl:text>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 6e340f9

Please sign in to comment.