Fix font in embedded iframe different from rest of interface

This commit is contained in:
Kovid Goyal 2017-05-19 07:23:53 +05:30
parent c4fce3eee9
commit d09f7605f1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 9 additions and 6 deletions

View File

@ -14,7 +14,7 @@ from utils import safe_set_inner_html
from book_list.constants import book_list_container_id, read_book_container_id, INIT_ENDPOINT
from book_list.library_data import fetch_init_data, update_library_data, url_books_query
from book_list.theme import get_color
from book_list.theme import get_color, get_font_family
from book_list.router import update_window_title, set_default_mode_handler, apply_url, set_mode_handler, on_pop_state
from book_list.globals import get_db, set_session_data, get_read_ui
from book_list.ui import apply_url_state as book_list_mode_handler
@ -47,6 +47,7 @@ def onerror(msg, script_url, line_number, column_number, error_object):
def init_ui():
document.body.style.fontFamily = get_font_family()
install_event_filters()
set_default_mode_handler(book_list_mode_handler)
window.onerror = onerror

View File

@ -21,7 +21,7 @@ from read_book.prefs.font_size import change_font_size_by
from read_book.touch import set_left_margin_handler, set_right_margin_handler
from read_book.toc import update_visible_toc_nodes
from read_book.goto import get_next_section
from book_list.theme import get_color
from book_list.theme import get_color, get_font_family
from utils import parse_url_params, username_key
LOADING_DOC = '''
@ -34,8 +34,8 @@ LOADING_DOC = '''
__SCRIPT__
end_script
</head>
<body>
<div style="font-family: sans-serif; font-size:larger; font-weight: bold; margin-top:48vh; text-align:center">
<body style="font-family: __FONT__">
<div style="font-size:larger; font-weight: bold; margin-top:48vh; text-align:center">
__BS__
</div>
</body>
@ -214,7 +214,8 @@ class View:
main_js(None)
self.src_doc = LOADING_DOC.replace(
'__BS__', _('Bootstrapping book reader...')).replace(
'__SCRIPT__', iframe_script)
'__SCRIPT__', iframe_script).replace(
'__FONT__', get_font_family().replace('"', '&quot;'))
def init_iframe(self, iframe_script):
self.encrypted_communications = False

View File

@ -4,6 +4,7 @@ from __python__ import hash_literals
from ajax import encode_query
from encodings import hexlify
from book_list.theme import get_font_family
def debounce(func, wait, immediate=False):
# Returns a function, that, as long as it continues to be invoked, will not
@ -228,7 +229,7 @@ def sandboxed_html(html, style, sandbox):
ans.setAttribute('seamless', '')
ans.style.width = '100%'
html = html or ''
css = 'html, body { margin: 0; padding: 0; } p:first-child { margin-top: 0; padding-top: 0; -webkit-margin-before: 0 }'
css = 'html, body { margin: 0; padding: 0; font-family: __FONT__ } p:first-child { margin-top: 0; padding-top: 0; -webkit-margin-before: 0 }'.replace('__FONT__', get_font_family())
css += style or ''
ans.srcdoc = f'<html><head><style>{css}</style></head><body>{html}</body></html>'
return ans