diff --git a/resources/compiled_coffeescript.zip b/resources/compiled_coffeescript.zip index 57049c6da7..7ec0f24230 100644 Binary files a/resources/compiled_coffeescript.zip and b/resources/compiled_coffeescript.zip differ diff --git a/src/calibre/ebooks/oeb/display/paged.coffee b/src/calibre/ebooks/oeb/display/paged.coffee index 36022dc6af..3bb3461927 100644 --- a/src/calibre/ebooks/oeb/display/paged.coffee +++ b/src/calibre/ebooks/oeb/display/paged.coffee @@ -27,22 +27,48 @@ class PagedDisplay this.is_full_screen_layout = false this.max_col_width = -1 this.document_margins = null + this.use_document_margins = false read_document_margins: () -> - if false and this.document_margins is null + # Read page margins from the document. First checks for an @page rule. + # If that is not found, side margins are set to the side margins of the + # body element. + if this.document_margins is null + this.document_margins = {left:null, top:null, right:null, bottom:null} + tmp = document.createElement('div') + tmp.style.visibility = 'hidden' + tmp.style.position = 'absolute' + document.body.appendChild(tmp) for sheet in document.styleSheets for rule in sheet.rules if rule.type == CSSRule.PAGE_RULE - for prop in ['margin-top', 'margin-bottom', 'margin-left', 'margin-right'] - val = rule.style.getPropertyValue(prop) + for prop in ['left', 'top', 'bottom', 'right'] + val = rule.style.getPropertyValue('margin-'+prop) if val - log(val) + tmp.style.height = val + pxval = parseInt(window.getComputedStyle(tmp).height) + if not isNaN(pxval) + this.document_margins[prop] = pxval + document.body.removeChild(tmp) + if this.document_margins.left is null + val = parseInt(window.getComputedStyle(document.body).marginLeft) + if not isNaN(val) + this.document_margins.left = val + if this.document_margins.right is null + val = parseInt(window.getComputedStyle(document.body).marginRight) + if not isNaN(val) + this.document_margins.right = val set_geometry: (cols_per_screen=1, margin_top=20, margin_side=40, margin_bottom=20) -> - this.margin_top = margin_top - this.margin_side = margin_side - this.margin_bottom = margin_bottom this.cols_per_screen = cols_per_screen + if this.use_document_margins and this.document_margins != null + this.margin_top = this.document_margins.top or margin_top + this.margin_bottom = this.document_margins.bottom or margin_bottom + this.margin_side = this.document_margins.left or this.document_margins.right or margin_side + else + this.margin_top = margin_top + this.margin_side = margin_side + this.margin_bottom = margin_bottom layout: () -> # start_time = new Date().getTime() @@ -374,4 +400,3 @@ if window? # TODO: # Highlight on jump_to_anchor -# Handle document specified margins and allow them to be overridden diff --git a/src/calibre/gui2/viewer/config.py b/src/calibre/gui2/viewer/config.py index dccd541380..383699ff98 100644 --- a/src/calibre/gui2/viewer/config.py +++ b/src/calibre/gui2/viewer/config.py @@ -53,6 +53,11 @@ def config(defaults=None): '0 and 1.')) c.add_opt('fullscreen_clock', default=False, action='store_true', help=_('Show a clock in fullscreen mode.')) + c.add_opt('cols_per_screen', default=1) + c.add_opt('use_book_margins', default=False, action='store_true') + c.add_opt('top_margin', default=20) + c.add_opt('side_margin', default=40) + c.add_opt('bottom_margin', default=20) fonts = c.add_group('FONTS', _('Font options')) fonts('serif_family', default='Times New Roman' if iswindows else 'Liberation Serif', @@ -120,6 +125,11 @@ class ConfigDialog(QDialog, Ui_Dialog): self.hyphenate_default_lang.setVisible(False) self.hyphenate_label.setVisible(False) self.opt_fullscreen_clock.setChecked(opts.fullscreen_clock) + self.opt_cols_per_screen.setValue(opts.cols_per_screen) + self.opt_override_book_margins.setChecked(not opts.use_book_margins) + for x in ('top', 'bottom', 'side'): + getattr(self, 'opt_%s_margin'%x).setValue(getattr(opts, + x+'_margin')) def accept(self, *args): if self.shortcut_config.is_editing: @@ -152,6 +162,11 @@ class ConfigDialog(QDialog, Ui_Dialog): c.set('line_scrolling_stops_on_pagebreaks', self.opt_line_scrolling_stops_on_pagebreaks.isChecked()) c.set('fullscreen_clock', self.opt_fullscreen_clock.isChecked()) + c.set('cols_per_screen', int(self.opt_cols_per_screen.value())) + c.set('use_book_margins', not + self.opt_override_book_margins.isChecked()) + for x in ('top', 'bottom', 'side'): + c.set(x+'_margin', int(getattr(self, 'opt_%s_margin'%x).value())) return QDialog.accept(self, *args) diff --git a/src/calibre/gui2/viewer/config.ui b/src/calibre/gui2/viewer/config.ui index 546ed4ac44..a3c74681c1 100644 --- a/src/calibre/gui2/viewer/config.ui +++ b/src/calibre/gui2/viewer/config.ui @@ -18,16 +18,6 @@ :/images/config.png:/images/config.png - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - @@ -68,7 +58,7 @@ QToolBox::tab:hover { 0 0 811 - 416 + 384 @@ -212,13 +202,143 @@ QToolBox::tab:hover { + + + + 0 + 0 + 811 + 384 + + + + Text &layout in paged mode + + + + QFormLayout::ExpandingFieldsGrow + + + + + <p>These options only apply in "paged" mode, where the text is broken up into pages, as in a paper book. To get into this mode, use the button with the yellow scroll icon in the top right corner of the viewer window. + + + true + + + + + + + The number of &pages of text to show on screen + + + opt_cols_per_screen + + + + + + + page(s) + + + 1 + + + 5 + + + + + + + &Override the page margin settings specified in the book + + + true + + + + + + + &Top margin + + + opt_top_margin + + + + + + + px + + + 10 + + + 1000 + + + + + + + &Side margin + + + opt_side_margin + + + + + + + px + + + 10 + + + 1000 + + + + + + + &Bottom margin + + + opt_bottom_margin + + + + + + + px + + + 10 + + + 1000 + + + + + 0 0 811 - 416 + 384 @@ -266,7 +386,7 @@ QToolBox::tab:hover { 0 0 811 - 416 + 384 @@ -337,7 +457,7 @@ QToolBox::tab:hover { 0 0 811 - 416 + 384 @@ -430,6 +550,16 @@ QToolBox::tab:hover { + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + @@ -446,8 +576,8 @@ QToolBox::tab:hover { accept() - 252 - 569 + 258 + 623 157 @@ -462,8 +592,8 @@ QToolBox::tab:hover { reject() - 320 - 569 + 326 + 623 286 @@ -478,12 +608,60 @@ QToolBox::tab:hover { setEnabled(bool) - 83 - 279 + 89 + 226 - 349 - 312 + 332 + 259 + + + + + opt_override_book_margins + toggled(bool) + opt_top_margin + setEnabled(bool) + + + 137 + 189 + + + 367 + 218 + + + + + opt_override_book_margins + toggled(bool) + opt_side_margin + setEnabled(bool) + + + 71 + 193 + + + 347 + 253 + + + + + opt_override_book_margins + toggled(bool) + opt_bottom_margin + setEnabled(bool) + + + 513 + 196 + + + 371 + 281 diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py index 554019d2d1..76b57629cb 100644 --- a/src/calibre/gui2/viewer/documentview.py +++ b/src/calibre/gui2/viewer/documentview.py @@ -134,6 +134,10 @@ class Document(QWebPage): # {{{ # Leave some space for the scrollbar and some border self.max_fs_width = min(opts.max_fs_width, screen_width-50) self.fullscreen_clock = opts.fullscreen_clock + self.use_book_margins = opts.use_book_margins + self.cols_per_screen = opts.cols_per_screen + self.side_margin = opts.side_margin + self.top_margin, self.bottom_margin = opts.top_margin, opts.bottom_margin def fit_images(self): if self.do_fit_images and not self.in_paged_mode: @@ -216,6 +220,14 @@ class Document(QWebPage): # {{{ def switch_to_paged_mode(self, onresize=False): if onresize and not self.loaded_javascript: return + self.javascript(''' + window.paged_display.use_document_margins = %s; + window.paged_display.set_geometry(%d, %d, %d, %d); + '''%( + ('true' if self.use_book_margins else 'false'), + self.cols_per_screen, self.top_margin, self.side_margin, + self.bottom_margin + )) side_margin = self.javascript('window.paged_display.layout()', typ=int) # Setup the contents size to ensure that there is a right most margin. # Without this webkit renders the final column with no margin, as the