johnfactotum / foliate

Read e-books in style
https://johnfactotum.github.io/foliate/
GNU General Public License v3.0
6.33k stars 290 forks source link

Add option to override publisher font #1113

Closed elmagio closed 10 months ago

elmagio commented 11 months ago

Describe the bug When a EPUB book has specific fonts designated by a style.css or similar file, Foliate 3.0 will not apply user chosen default fonts. I'm marking this as a bug as Foliate 2.6.4 used to automatically apply the user chosen font to all books regardless of style sheets, however if this is the desired behavior this can serve as a feature request for an optional "Force user fonts" setting. MOBI files made by converting the problematic EPUBs in Calibre do not exhibit the issue.

To Reproduce Steps to reproduce the behavior:

  1. Open a .epub book that has a style.css designated font (I've included an user-generated one, but I've experienced it with copyrighted books which I can't share here as well)
  2. Go to Fonts & Layout settings
  3. Alternate between Serif and Sans-serif as the default or change the specific font family for either
  4. Foliate will not apply the desired font

Expected behavior The selected font or font category (Serif/Sans-serif) should be applied

Version:

Additional context I had to zip up an example epub to share it, as Github would not let me upload an .epub file as is: Example.zip

johnfactotum commented 11 months ago

It's indeed by design, and that's why it's called "Default Font", i.e. the default if the book doesn't specify any. But it does need an option to override publisher fonts.

As a workaround, you can add the following to user-stylesheet.css:

* {
    font-family: inherit !important;
    line-height: inherit !important;
}
elmagio commented 11 months ago

Thanks for the workaround !

johnfactotum commented 11 months ago

It just occurred to me that using inherit will break elements like pre, code, samp, etc. So one should probably use revert instead.

* {
    font-family: revert !important;
}
distefam commented 11 months ago

Thank you for this workaround, however, applying it to a book with code blocks that are ordinarily rendered in a monospaced font makes those blocks also render with the default font, even when I've specified a monospaced font in Foliate's preferences.

johnfactotum commented 11 months ago

revert works for code blocks, which is usually marked up with <pre>, which is styled by the user agent (i.e. WebKit) with the default monospace font.

You can use the inspector (F12) to see what's happening.