-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mismatch between CSS and device pixels on Android #97
Comments
Hmmm what’s sure at first sight is that it will be very difficult to solve this one through ReadiumCSS since it is fed the computed (hence rounded) values by the rendering engine. We’re using percentage or viewport units in the pagination module so it sounds kinda hopeless/like a black hole to try to hack our way out of this there. I thought maybe it could be columns but at this size, Do you know what happens if you apply exactly I’ll try to take a look at the Chromium issue tracker as I’m pretty sure this already popped up there. |
How would you do this? I tried injecting
I tried again the test with the red div, setting a width of |
Given how columns work, the readium-css/css/src/modules/ReadiumCSS-pagination.css Lines 56 to 58 in 5830114
It’s kinda clear I’ll have to create a custom property/variable for that as it is highly likely that it impacts Chrome (browser) too but in the interval, you can do something like:
Getting a rounded value for [edit] and obviously it has to be documented since you also have to keep track of orientation, resize, etc. changes. |
That worked! I could reach the end of the chapter without any noticeable offset. After checking a screenshot the last page was 2 or 3 pixels off, probably because 392.72px is not precise enough (392.727272727...), I wonder if we could use
Agreed, this smells like a rendering engine bug to me.
That would be super helpful. Do you think you would be able to implement this soonish since this issue is critical for Android?
Yeah, we probably need a JS snippet to handle this. I'll check if we can get the real viewport width from JS. I think that the pixel ratio is available with |
Resolves #97 but doesn’t fix the overarching issue in Chromium. Also needs docs before being pushed into main.
@mickael-menu Just pushed the |
Great, thanks again! |
It's pixel perfect with setProperty("--RS__viewportWidth", "calc(" + nativeViewportWidth + "px / " + window.devicePixelRatio + ")"); I still have some other related issues to fix before sending a PR. I think they are caused by the existing code being tuned to the faulty web view behavior. |
Thanks for reporting the JS snippet back! |
I opened a PR on the Kotlin navigator: readium/r2-navigator-kotlin#178 Considering that we can't really do much more at our level, feel free to close the issue when you want Jiminy. Thanks for your help! |
I'm submitting a bug report.
Short description of the issue/suggestion:
Pages are misaligned on large resources if the device has a fractional pixel density. See this related issue on Android: readium/kotlin-toolkit#166
Steps to reproduce the issue/enhancement:
What is the expected behaviour?
We should see only the current page on the screen.
What is the current behaviour?
Do you know which CSS modules (stylesheets) are impacted?
Probably the pagination one.
Please tell us about your environment:
Other information (e.g. related issues, suggestions how to fix, links for us to have context)
I'm not 100% sure it is a Readium CSS issue but I'm opening a discussion on the subject, because I'm in a pickle to fix this Android issue.
First, here are some information about the Pixel 3a:
On the Kotlin EPUB navigator, scrolling through pages is done using Kotlin code and Android APIs. We're using the device's resolution width for all calculation, so in the case of the Pixel 3a, a page is 1080px large.
Unfortunately there's a mismatch with the page width we get in the web view, which has a viewport of 393px. But
1080 / 2.75 = 392.72
. This small difference adds up to huge offsets in large resources.What makes me think that the issue is more related to Readium CSS is some tests I did in the web inspector.
First, a weird thing is that although a CSS page should be 393px,
document.scrollingElement.scrollWidth
was100631
which is not a multiple of 393 (nor1080 / 1.75
). So we can see pages getting shifted by doing either:Then, I created an absolute-positioned
div
withwidth: 100%
(I also triedwidth: 393px
which gives the same result). While it appears to be the size of a page, I can see a really thin portion of it after turning the page. Whether I'm doing it from Kotlin, or by executing directlydocument.scrollingElement.scrollLeft = 393
.Next page:
The text was updated successfully, but these errors were encountered: