readium / readium-css

šŸŒˆ A set of reference stylesheets for EPUB Reading Systems, starting with Readium Mobile
https://readium.org/readium-css/
BSD 3-Clause "New" or "Revised" License
90 stars 20 forks source link

Document-global text size #34

Open danielweck opened 6 years ago

danielweck commented 6 years ago

Hello @JayPanoz what do you think about CSS text-size-adjust? https://developer.mozilla.org/en-US/docs/Web/CSS/text-size-adjust

I am asking following the discussion in this issue: https://github.com/readium/readium-js-viewer/issues/686

Thanks!

JayPanoz commented 6 years ago

Ah, tbh this is a strange beast, but weā€™re indeed using it in ReadiumCSS for iOS (see pagination module).

Since youā€™re managing the font-size setting in JS, you should be safe ā€“ it is worth noting that it would break the native zoom feature of the iOSā€™ UIWebView though (and maybe the WKWebView but I canā€™t confirm for this one).

danielweck commented 6 years ago

The problem is that in Readium1, changing font-size (and proportional line-height) at the DOM "leaf" level doesn't adequately scale the "gutters" in the sample EPUB provided by the issue reporter. So, could you please test the provided EPUB with Readium2 's font scaling method, to see if it works? Many thanks!

JayPanoz commented 6 years ago

Yeah sure, will do ASAP.

Quick notes:

Iā€™ll take a closer look and come back to you but from the ā€œsource codeā€, to be completely frank, the markup+styling is asking for this type of problems.

danielweck commented 6 years ago

Thanks!

JayPanoz commented 6 years ago

So the good news is that the number isnā€™t truncated in my tests.

The bad news is that itā€™s even worse:

cap1

cap2

Which can be explained by the following

css

As you can see, theyā€™re using a different unit (em instead of rem) for list items with double digits.

What this means is that em is computed against their bodyā€™s font-size, which is 0.7em or 11.2px while rem is computed against 100% or 16px.

In our normalize, we currently map everything to 1rem (16px) as we have samples whose font-sizes are set in pt or px for body and it breaks the cascade for relative units.

The stylesheet has been designed for iBooks only ā€“ theyā€™re now even applying an iTunes DRM so that you canā€™t use another app to read the guides they publish. Now, iBooks is using the font-size API (UIWebview on iOS, Webview on MacOS) so this problem doesnā€™t apply (it even takes care of margins in px if Iā€™m not mistaken), but we donā€™t have that in web browsers and thatā€™s why weā€™ve been using this normalize, and youā€™ve been using JS in R1ā€¦

I was failing to see how -webkit-text-size-adjust makes a difference there, as I didnā€™t notice any during my testsā€¦ until I found this link.

It indeed worksā€¦

text-size-adjust-mobile

Problem is there may be differences in behaviors as it is non-standard, and isnā€™t supported in some browsers (including Safari Desktop) so this wonā€™t have any effect on desktop

text-size-adjust-desktop

Mind you, Iā€™ll be happy to get rid of the normalize to prevent such edge cases, but it exists (and the JS solution too) because we donā€™t have anything cross-platform which does the job.

As for truncation, I guess itā€™s because, as any negative text-indent larger than the margin|padding-left, the risk is the first line overflowing on the left (+ rounding errors, especially as different units are used in this case).

Does this answer makes sense?

JayPanoz commented 6 years ago

Also, the ReadiumCSS gutter doesnā€™t increase with font-size neither, as this would make the container narrower in larger font sizes, and make the document unreadable.

JayPanoz commented 6 years ago

Out of curiosity, I took a quick look at -webkit-text-size-adjust (and text-size-adjust) on Chrome, with a non-basic support (as the MDN page is saying).

Hereā€™s on desktop, with a value of 200% (no effect)

desktop-fail

Hereā€™s on mobile, same value (no effect)

phone-fail

So it probably supports only none or auto.

On a related note, if you have access to anything like ā€œChanging the text sizeā€ as in the MacOS Webview for instance, it will probably be a lot easier to manage edge cases.

JayPanoz commented 6 years ago

After further testing, -webkit-text-size-adjust can only be used on iOS (canā€™t be used to increase/decrease font-size on MacOS, Windows, Linux or Android as % values are not supported, even by WebKit).

photo 30-04-2018 16 34 30

Here you can see a test document with a 200% value on an iPad, it works beautifully and reliably, for all units, even the absolute ones (pt, px, keywords). Increasing/decreasing font-size is as simple as changing this percentage.

screenshot_20180430-163627

Here you can (maybe) see it doesnā€™t work on Android ā€“ itā€™s hard to tell at first sight but I can confirm this is font-size @ 100%.

Itā€™s worth noting -webkit-text-size-adjust appears to be developersā€™ preferred method when it comes to changing the font-size in an iOS WebView, probably because itā€™s simple and work reliably.

Android alternative could be native, i.e. setTextZoom() but Iā€™m really not sure about that. People have been using getTextZoom though.

JayPanoz commented 6 years ago

And Electron: Could setZoomFactor/setZoomLevel be a more reliable alternative, @danielweck? See https://electronjs.org/docs/all#contentssetzoomfactorfactor

I canā€™t tell how the zoom is behaving (changing the font-size + reflowing or simply zooming).

danielweck commented 6 years ago

Yes, the Electron "web contents" API (also accessible via "web frame" proxy https://github.com/electron/electron/blob/master/docs/api/web-frame.md#methods ) provides methods to control zoom "level" ( https://github.com/electron/electron/blob/master/docs/api/web-contents.md#contentssetzoomlevellevel ) and "factor" ( https://github.com/electron/electron/blob/master/docs/api/web-contents.md#contentssetzoomfactorfactor ), which are two different ways (metric scales) to alter layout and visuals "zooming". This is potentially useful not only for publication documents, but also for the application UI itself (both of which are implemented with HTML/CSS)

For example, webPreferences.zoomFactor can be configured directly in the constructor of any BrowserWindow ( https://github.com/electron/electron/blob/master/docs/api/browser-window.md#new-browserwindowoptions ), which in the case of readium-desktop are the top-level window containers for the library view (bookshelf) and the reader view(s). This gives us an opportunity to easily implement a very useful feature for visually-impaired / low-vision / large-print users: "magnify" the entire application UI (own chrome as well as webview-rendered publication documents).

That being said, the original discussion topic here is specifically about "scaling" publication documents, including font size and other rendered objects (images, etc.). Personally I have not tried the Electron API yet, there might be undesirable side effects with CSS columns layout, scrollbar rendering, etc. (to be determined)