Bug 435535 - Okular EPUB backend renders black background with black text
Summary: Okular EPUB backend renders black background with black text
Status: REOPENED
Alias: None
Product: okular
Classification: Applications
Component: EPub backend (show other bugs)
Version: 20.12.2
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: Okular developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-09 08:07 UTC by Bernie Innocenti
Modified: 2024-09-03 09:22 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
CSS file found inside the EPUB (117.51 KB, text/css)
2021-04-09 08:08 UTC, Bernie Innocenti
Details
Cut-down EPUB file to demonstrate the bug (1.48 MB, application/epub+zip)
2021-04-09 11:21 UTC, Bernie Innocenti
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bernie Innocenti 2021-04-09 08:07:26 UTC
SUMMARY

I have an 800-page EPUB book which I cannot re-share.

Okular renders a black background for this, while another ebook reader (http://epubreader.1bestlink.net/) renders it correctly.

SOFTWARE/OS VERSIONS
KDE Plasma Version: 5.21.4
KDE Frameworks Version: 5.80.0
Qt Version: 5.15.2

ADDITIONAL INFORMATION

I tested with Okular built from git, got same result.
Comment 1 Bernie Innocenti 2021-04-09 08:08:34 UTC
Created attachment 137446 [details]
CSS file found inside the EPUB
Comment 2 Bernie Innocenti 2021-04-09 08:10:20 UTC
I tried deleting all the occurrences of "color: #000000;" and "background: transparent;" from the CSS and then repack the EPUB, but it still renders black over black.
Comment 3 Yuri Chornoivan 2021-04-09 08:29:23 UTC
Can you replace all the text of your restricted book with "Lorem ipsum" or something similar using Sigil or Calibre editor and attach the file (if it's reproducible) to this bug report?

Thanks in advance for your answer.

P.S. I cannot reproduce the bug with the CSS attached and calibre-crafted book.
Comment 4 Bernie Innocenti 2021-04-09 11:21:37 UTC
Created attachment 137450 [details]
Cut-down EPUB file to demonstrate the bug
Comment 5 Yuri Chornoivan 2021-04-09 11:25:39 UTC
Confirmed. Calibre viewer shows the white background and Okular shows black.
Comment 6 Bernie Innocenti 2021-04-09 11:26:14 UTC
Thank you for analyzing this bug, Yuri!

Calibre also renders black text on a dark background when using the default system theme, but it is possible to fix it by either switching to a light theme, or by selecting "Override all book colors... in dark mode".
Comment 7 Yuri Chornoivan 2021-04-09 16:17:57 UTC
There is

<body style="background-color:black;">

in cover.xhtml. With style="background-color:black;" removed, everything works as expected. So I think it's not a bug.
Comment 8 Bernie Innocenti 2021-04-11 17:29:42 UTC
Do you think I could file a feature request for an option similar to Calibre?

   Override all book colors:
   ( ) Never
   (o) In dark mode
   ( ) Always
Comment 9 Yuri Chornoivan 2021-04-11 17:32:55 UTC
(In reply to bernie from comment #8)
> Do you think I could file a feature request for an option similar to Calibre?
> 
>    Override all book colors:
>    ( ) Never
>    (o) In dark mode
>    ( ) Always

I might be wrong, but isn't it already here (one of the options on the "Accessibility" page)?

https://docs.kde.org/trunk5/en/okular/okular/configaccessibility.html
Comment 10 Bernie Innocenti 2021-04-11 17:57:50 UTC
> I might be wrong, but isn't it already here
> (one of the options on the "Accessibility" page)?

I tried a few of them, and...

 - "Change Paper Color" has no effect on this book
 - "Invert Colors" renders white background with white text (so it's still unreadable)
 - "Change Dark & Light Colors" renders both page and text in the dark color
 - "Convert to Black & White" leaves text & page to black
 - "Invert..." and "Shift..." also have no effect.
Comment 11 Bernie Innocenti 2021-04-11 17:58:25 UTC
On second thought, it seems Calibre is ignoring the "background-color:black" in <body>, because the background is painted in the Breeze-dark window background color.
Similarly, http://epubreader.1bestlink.net/ renders page backgrounds in white.

Perhaps Okular is ignoring those "background: transparent" attributes in the css file? I'm not sure in what order they should be applied...
Comment 12 Bernie Innocenti 2021-04-11 18:09:18 UTC
Oh, I see now: only cover.xhtml has style="background-color:black;". The following sections don't specify the background-color for <body>, but Okular keeps on using black throughout the entire book.

Reopening the bug.
Comment 13 Yuri Chornoivan 2021-04-11 18:16:04 UTC
Ok. Here's oneliner that will be never accepted (but tested to work). ;)


diff --git a/generators/epub/converter.cpp b/generators/epub/converter.cpp
index 291b9caed..2f79dbc9b 100644
--- a/generators/epub/converter.cpp
+++ b/generators/epub/converter.cpp
@@ -217,6 +217,7 @@ QTextDocument *Converter::convert(const QString &fileName)
         // as QTextCharFormat::anchorNames() ignores sections, replace it with <p>
         htmlContent.replace(QRegExp(QStringLiteral("< *section")), QStringLiteral("<p"));
         htmlContent.replace(QRegExp(QStringLiteral("< */ *section")), QStringLiteral("</p"));
+        htmlContent.replace(QStringLiteral("background-color:black;"), QStringLiteral(""));
 
         // convert svg tags to img
         const int maxHeight = mTextDocument->maxContentHeight();
Comment 14 Phos 2022-01-07 18:05:32 UTC
Any update on this? I also have the exact same issue and it makes it impossible to read epubs with Okular