Implement epubReadingSystem for the in browser viewer

This commit is contained in:
Kovid Goyal 2017-04-07 10:17:39 +05:30
parent d97e1ce707
commit 195b083c3a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 32 additions and 1 deletions

View File

@ -215,7 +215,10 @@ def compile_srv():
base = P('content-server', allow_user_override=False) base = P('content-server', allow_user_override=False)
fname = os.path.join(rapydscript_dir, 'srv.pyj') fname = os.path.join(rapydscript_dir, 'srv.pyj')
with lopen(fname, 'rb') as f: with lopen(fname, 'rb') as f:
js = compile_fast(f.read(), fname).replace('__RENDER_VERSION__', rv, 1).replace('__MATHJAX_VERSION__', mathjax_version, 1).encode('utf-8') js = compile_fast(f.read(), fname).replace(
'__RENDER_VERSION__', rv, 1).replace(
'__MATHJAX_VERSION__', mathjax_version, 1).replace(
'__CALIBRE_VERSION__', __version__, 1).encode('utf-8')
with lopen(os.path.join(base, 'index.html'), 'rb') as f: with lopen(os.path.join(base, 'index.html'), 'rb') as f:
html = f.read().replace(b'RESET_STYLES', reset, 1).replace(b'ICONS', icons, 1).replace(b'MAIN_JS', js, 1) html = f.read().replace(b'RESET_STYLES', reset, 1).replace(b'ICONS', icons, 1).replace(b'MAIN_JS', js, 1)

View File

@ -28,10 +28,38 @@ from read_book.touch import create_handlers as create_touch_handlers
from utils import debounce from utils import debounce
FORCE_FLOW_MODE = False FORCE_FLOW_MODE = False
CALIBRE_VERSION = '__CALIBRE_VERSION__'
ERS_SUPPORTED_FEATURES = {'dom-manipulation', 'layout-changes', 'touch-events', 'mouse-events', 'keyboard-events', 'spine-scripting'}
class EPUBReadingSystem:
@property
def name(self):
return 'calibre'
@property
def version(self):
return CALIBRE_VERSION
@property
def layoutStyle(self):
return 'scrolling' if current_layout_mode() is 'flow' else 'paginated'
def hasFeature(self, feature, version):
return feature in ERS_SUPPORTED_FEATURES
def __repr__(self):
return f'{{name:{self.name}, version:{self.version}, layoutStyle:{self.layoutStyle}}}'
def __str__(self):
return self.__repr__()
class IframeBoss: class IframeBoss:
def __init__(self): def __init__(self):
window.navigator.epubReadingSystem = EPUBReadingSystem()
self.ready_sent = False self.ready_sent = False
self.last_cfi = None self.last_cfi = None
self.replace_history_on_next_cfi_update = True self.replace_history_on_next_cfi_update = True