michal-h21 / tex4ebook

Converter from LaTeX to ebook formats (epub, mobi). Using tex4ht and texlua scripts.
310 stars 32 forks source link

Using \coverimage with an SVG results in bizarrely cropped cover image #72

Open DavidGriffith opened 4 years ago

DavidGriffith commented 4 years ago

I can't put a finger on exactly what causes this, but now that I found it, I can't seem to create a demo EPUB that results in a correctly-rendered cover. The problem is that if I do \coverimage{cover.svg}, an epub reader will render the cover strangely cropped. Sometimes it was a strip off the bottom. More recently three quarters of the SVG is removed. If I do \coverimage{cover.png}, the image appears as it should.

To recreate a misbehaving EPUB, do tex4ebook -xs -f epub3 -c badcover.cfg badcover.tex:

% badcover.tex
\documentclass[12pt]{book}
\usepackage{graphicx}
\usepackage{svg}
\usepackage{lipsum}

\title{Bad Cover}
\author{David Griffith}

\begin{document}
\coverimage{badcover.svg}
\maketitle
\tableofcontents

\chapter{Hello}
\lipsum[1]
\chapter{Goodbye}
\lipsum[1]
\chapter{Hello Again}
\lipsum[1]
\chapter{Whee!}
\lipsum[1]
\end{document}
% badcover.cfg
\Preamble{xhtml}
\Configure{UniqueIdentifier}{661.org}
\DeclareGraphicsExtensions{.svg,.png,.jpg,.gif}
\renewcommand\includesvg[2][]{\includegraphics{#2}}
\Configure{CoverMimeType}{image/svg+xml}
\begin{document}
\EndPreamble

Here's how Calibre renders the bad graphic: Screenshot at 2020-06-27 00-29-40

Here's the SVG: badcover.zip

Here's the PNG as created with convert badcover.svg badcover.png: badcover

michal-h21 commented 4 years ago

This is strange, it works correctly on my machine. This is my <img> element in badcover.html:

  <img src="badcover.svg" alt="PIC"  />

Maybe you have some additional attributes here?

DavidGriffith commented 4 years ago
<body 
>
   <div class="cover-image"> 
 <img 
src="badcover.svg" alt="PIC"  
 /></div>
michal-h21 commented 4 years ago

So this is the same. Maybe it is a bug in (or feature?) in Calibre? It seems that it crops the image only in the library view, it displays it correctly when I open the book in ebook-viewer.

DavidGriffith commented 4 years ago

Alkdiko on Android does this too.

Here's the bad epub so we can see if this renders poorly for you. badcover-epub.zip