mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Viewer: Calculate default column widths based on current font size
This commit is contained in:
parent
3d93979fdb
commit
ea7ad6fc0a
@ -119,6 +119,26 @@ def fit_images():
|
|||||||
set_elem_data(img, 'height-limited', True)
|
set_elem_data(img, 'height-limited', True)
|
||||||
|
|
||||||
|
|
||||||
|
def cps_by_em_size():
|
||||||
|
ans = cps_by_em_size.ans
|
||||||
|
fs = window.getComputedStyle(document.body).fontSize
|
||||||
|
if not ans or cps_by_em_size.at_font_size is not fs:
|
||||||
|
d = document.createElement('span')
|
||||||
|
d.style.position = 'absolute'
|
||||||
|
d.style.visibility = 'hidden'
|
||||||
|
d.style.width = '1rem'
|
||||||
|
d.style.fontSize = '1rem'
|
||||||
|
d.style.paddingTop = d.style.paddingBottom = d.style.paddingLeft = d.style.paddingRight = '0'
|
||||||
|
d.style.marginTop = d.style.marginBottom = d.style.marginLeft = d.style.marginRight = '0'
|
||||||
|
d.style.borderStyle = 'none'
|
||||||
|
document.body.appendChild(d)
|
||||||
|
w = d.clientWidth
|
||||||
|
document.body.removeChild(d)
|
||||||
|
ans = cps_by_em_size.ans = max(2, w)
|
||||||
|
cps_by_em_size.at_font_size = fs
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
def calc_columns_per_screen():
|
def calc_columns_per_screen():
|
||||||
cps = opts.columns_per_screen or {}
|
cps = opts.columns_per_screen or {}
|
||||||
cps = cps.landscape if scroll_viewport.width() > scroll_viewport.height() else cps.portrait
|
cps = cps.landscape if scroll_viewport.width() > scroll_viewport.height() else cps.portrait
|
||||||
@ -127,7 +147,7 @@ def calc_columns_per_screen():
|
|||||||
except:
|
except:
|
||||||
cps = 0
|
cps = 0
|
||||||
if not cps:
|
if not cps:
|
||||||
cps = int(Math.floor(scroll_viewport.width() / 500.0))
|
cps = int(Math.floor(scroll_viewport.width() / (35 * cps_by_em_size())))
|
||||||
cps = max(1, min(cps or 1, 20))
|
cps = max(1, min(cps or 1, 20))
|
||||||
return cps
|
return cps
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user