ccz-2 / Anki-Zoom

Zoom addon for Anki | Forked from https://github.com/krassowski/Anki-Zoom
https://ankiweb.net/shared/info/538879081
GNU General Public License v3.0
6 stars 5 forks source link

Feature request: Zoom to Fit #7

Open khonkhortisan opened 4 years ago

khonkhortisan commented 4 years ago

Where it's zoomed in until just before it would create scrollbars. word→word cards are giant, sentence cards are reasonably sized, image occlusion images fit on the screen, and cards that are too long are too small to read. This wouldn't go well with incremental reading long pages in the reviewer, unless there was a minimum zoom level.

PDFs have a defined size, so it's easy to fit-to-width, fit-to-height, or fit-to-container. HTML word-wraps when the zoom is increased, so even when the width appears to stay constant, increasing the zoom by a little bit when there's a lot of text increases the height by a lot, then zooming again by that new height can make it zoomed in less than when it started. A solution should check whether scrollbars do exist or calculate whether they would, and may benefit from a bisect algorithm. Or there may be an option to tell webkit to do all the zooming itself.

js-only attempt: var minsize=0.1; var padding=20; document.getElementsByClassName('card')[0].style.zoom=Math.max(minsize,(window.innerHeight-1)/(padding+document.getElementsByClassName('card')[0].scrollHeight+padding)); Running this multiple times mostly works, but on some cards scrollHeight returns a value lower than it actually is, and causes it to zoom in way too far.