johnfactotum / foliate

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

[GTK4] Navigation and rendering issues with fixed-layout documents with `page-spread-center` #1072

Closed initramfs closed 1 year ago

initramfs commented 1 year ago

Note: Most of the problems below probably stem from foliate-js, which does seem to have a disclaimer claiming the FXL renderer is unfinished. At the very least this bug report can serve as implementation tests/milestones to complete the renderer.


For EPUB 3 fixed-layout documents with a page progression direction of rtl (right to left) several rendering and navigation issues occur, as described below:

  1. On opening the EPUB document, instead of the cover page being shown, a small white box is presented: Opening screenshot from this screen, neither the forward or backward navigation keys work to move the reader past this initial white box, only navigation directly via clicking the links in the navigation document work.
    Advancing past this page (via clicking a link in the navigation document/TOC allows forward/backward navigation to work again) but it is possible to hit "previous" on the cover page, which will land back on this initial white box and break navigation again.

  2. Rendering of true spreads results in a center gap between the two pages: True spread gap screenshot While section 8.2.2.4 of the EPUB 3.3 specification doesn't specify that a gap cannot be present, I believe the expected behaviour is for gapless rendering (as seen on other EPUB renderers like Thorium).

  3. Rendering of synthetic spreads with a 'gap' in the spread properties (e.g. rendition:page-spread-right followed by rendition:page-spread-center, or rendition:page-spread-center followed by rendition:page-spread-left [in RTL mode]) results in a small white box for the unpopulated viewport along with the inability to navigate past that viewport: Right spread left unpopulated screenshot In the above screenshot, the left viewport is left unpopulated by having page 3 (P-03) declared as rendition:page-spread-right and having page 4 (P-04, not shown above) declared as rendition:page-spread-center in the spine itemref. Attempt to navigate forward/next past the unpopulated viewport is broken (i.e. does not advance viewer) but navigating back/previous works as expected.
    Left spread right unpopulated screenshot The same is true for an unpopulated right viewport with the same symptoms as the previous example but with an inability to navigate back/previous, but navigating forward/next works.

  4. Center spread does not use the entire renderer's dimensions, resulting in an overly small spread: Center spread screenshot The viewport dimensions for a center spread seems to be limited to that of a single 'side' (i.e. left/right) spread, resulting in a landscape page (typical of pages marked with rendition:page-spread-center) to be rendered overly small.

  5. Cannot open books from the library that are fixed-layout RTL: Library screenshot All books that are fixed-layout RTL show up as blanks in the library that fail to open: Book cannot open screenshot The only way to get them opened in the first place is to directly open the EPUB with the application. The example book does have a correctly tagged cover page that does correctly show up in the "About this book" dialog box (in the renderer).

To Reproduce Steps to reproduce the behavior:

  1. Download FXL-Test.zip
  2. Extract and open FXL-Test.epub from the archive.

Note: The provided EPUB document does contain a few additional metadata and language tag tests (that trip up other readers like Thorium) but passes epubcheck with 0 warnings or errors. If an absolute minimal EPUB file that triggers all the bugs denoted here without the additional (unrelated) tests is desired, one can be provided. An example of a language-tag rendering issue in Thorium is shown here.

Expected behavior The following screenshots represent the hypothetical correct rendering of the test EPUB document exhibited above:

Pages 01-02 screenshot Page 03 screenshot Page 04 screenshot Page 05 screenshot Pages 06-07 screenshot

Version:

Additional information: epub.js has significant issues with rendering RTL fixed-layout document that cause much more severe rendering issues than what is described here (with appropriate bug reports opened for them), hence this bug report targeting the GTK4 branch and foliate-js, since the codebase for that renderer should be under this project's control.

johnfactotum commented 1 year ago

Fixed with https://github.com/johnfactotum/foliate-js/commit/99e246ecb854a1b3c5116c21b1faacd1342ff030 and https://github.com/johnfactotum/foliate-js/commit/0cebcb93c43bab53013c75823bebe69b1d531766.

center gap between the two pages

I think this is due to the default margin on the body element, which can be fixed with body { margin: 0; }.

initramfs commented 1 year ago

This might be an extremely minor nitpick but even with margin: 0; padding: 0 on the html and body elements there still exists a 1 pixel gap between the spreads: CSS spread gap screenshot

Thorium renders both variants (stylesheet-less and with stylesheet) as truly gapless: Thorium spread gap screenshot


Relevant EPUBs here (contains original EPUB + EPUB with stylesheet): FXL-Test.zip

On another note: I'm not well versed with any specifications of default values for CSS properties besides what is shown here (I'm not sure if this is normative), but should the body margin be set to 0 px for FXL content?

johnfactotum commented 1 year ago

A slight gap is visible in your Thorium screenshot as well. I think it's an antialiasing artifact (antialiasing being applied to the individual pages which causes the gap to appear). As far as I know it's not really something that can be fixed as the antialiasing is controlled by the browser engine. It works for me, though, when using 200% HiDPI scaling:

Screenshot from 2023-09-10 17-31-43

Regarding the default user agent stylesheet, as far as I can tell, there aren't any special requirements for fixed layout. For EPUB in general, the reading system spec says

a reading system's user agent style sheet SHOULD support the [html] suggested default rendering.

initramfs commented 1 year ago

Okay, I can reproduce the gapless rendering with 200% scale as well, also noticed Thorium's gapless rendering might have a bug as well (where the pages are actually overlapped by 1 or 2 pixels, producing the AA artifacts), though that's hard to confirm (increasing zoom level causes pages to definitively overlap on my system though).

In any case, thanks for fixing this bug, seems to be the only FOSS epub renderer right now that can actually render FXL RTL correctly.