diff --git a/resources/images/embed-fonts.png b/resources/images/embed-fonts.png new file mode 100644 index 0000000000..fac5b5022d Binary files /dev/null and b/resources/images/embed-fonts.png differ diff --git a/resources/images/smarten-punctuation.png b/resources/images/smarten-punctuation.png new file mode 100644 index 0000000000..6f3cb92ed7 Binary files /dev/null and b/resources/images/smarten-punctuation.png differ diff --git a/resources/images/subset-fonts.png b/resources/images/subset-fonts.png new file mode 100644 index 0000000000..449f204158 Binary files /dev/null and b/resources/images/subset-fonts.png differ diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index e92e596801..a749e65f54 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -11,12 +11,12 @@ from functools import partial from PyQt4.Qt import ( QObject, QApplication, QDialog, QGridLayout, QLabel, QSize, Qt, - QDialogButtonBox, QIcon, QTimer, QPixmap) + QDialogButtonBox, QIcon, QTimer, QPixmap, QTextBrowser, QVBoxLayout) from calibre import prints from calibre.ptempfile import PersistentTemporaryDirectory from calibre.ebooks.oeb.base import urlnormalize -from calibre.ebooks.oeb.polish.main import SUPPORTED +from calibre.ebooks.oeb.polish.main import SUPPORTED, tweak_polish from calibre.ebooks.oeb.polish.container import get_container as _gc, clone_container, guess_type from calibre.ebooks.oeb.polish.replace import rename_files from calibre.gui2 import error_dialog, choose_files, question_dialog, info_dialog @@ -156,12 +156,37 @@ class Boss(QObject): if not self.check_dirtied(): return self.add_savepoint(_('Edit Table of Contents')) - d = TOCEditor(parent=self.gui) + d = TOCEditor(title=self.current_metadata.title, parent=self.gui) if d.exec_() != d.Accepted: self.rewind_savepoint() return self.update_editors_from_container() + def polish(self, action, name): + if not self.check_dirtied(): + return + self.add_savepoint(name) + try: + report = tweak_polish(current_container(), {action:True}) + except: + self.rewind_savepoint() + raise + self.apply_container_update_to_gui() + from calibre.ebooks.markdown import markdown + report = markdown('# %s\n\n'%self.current_metadata.title + '\n\n'.join(report), output_format='html4') + d = QDialog(self.gui) + d.l = QVBoxLayout() + d.setLayout(d.l) + d.e = QTextBrowser(d) + d.l.addWidget(d.e) + d.e.setHtml(report) + d.bb = QDialogButtonBox(QDialogButtonBox.Close) + d.l.addWidget(d.bb) + d.bb.rejected.connect(d.reject) + d.bb.accepted.connect(d.accept) + d.resize(600, 400) + d.exec_() + # Renaming {{{ def rename_requested(self, oldname, newname): if not self.check_dirtied(): diff --git a/src/calibre/gui2/tweak_book/ui.py b/src/calibre/gui2/tweak_book/ui.py index b808c9b9d3..6c80c1d434 100644 --- a/src/calibre/gui2/tweak_book/ui.py +++ b/src/calibre/gui2/tweak_book/ui.py @@ -6,6 +6,8 @@ from __future__ import (unicode_literals, division, absolute_import, __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' +from functools import partial + from PyQt4.Qt import ( QDockWidget, Qt, QLabel, QIcon, QAction, QApplication, QWidget, QVBoxLayout, QStackedWidget, QTabWidget, QImage, QPixmap, pyqtSignal) @@ -179,6 +181,18 @@ class Main(MainWindow): group = _('Tools') self.action_toc = reg('toc.png', _('&Edit Table of Contents'), self.boss.edit_toc, 'edit-toc', (), _('Edit Table of Contents')) + # Polish actions + group = _('Polish') + self.action_subset_fonts = reg( + 'subset-fonts.png', _('&Subset embedded fonts'), partial( + self.boss.polish, 'subset', _('Subset fonts')), 'subset-fonts', (), _('Subset embedded fonts')) + self.action_embed_fonts = reg( + 'embed-fonts.png', _('&Embed referenced fonts'), partial( + self.boss.polish, 'embed', _('Embed fonts')), 'embed-fonts', (), _('Embed referenced fonts')) + self.action_smarten_punctuation = reg( + 'smarten-punctuation.png', _('&Smarten punctuation'), partial( + self.boss.polish, 'smarten_punctuation', _('Smarten punstuation')), 'smarten-punctuation', (), _('Smarten punctuation')) + def create_menubar(self): b = self.menuBar() @@ -200,6 +214,9 @@ class Main(MainWindow): e = b.addMenu(_('&Tools')) e.addAction(self.action_toc) + e.addAction(self.action_embed_fonts) + e.addAction(self.action_subset_fonts) + e.addAction(self.action_smarten_punctuation) def create_toolbar(self): self.global_bar = b = self.addToolBar(_('Book tool bar')) @@ -210,6 +227,12 @@ class Main(MainWindow): b.addAction(self.action_save) b.addAction(self.action_toc) + self.polish_bar = b = self.addToolBar(_('Polish book tool bar')) + b.setObjectName('polish_bar') # Needed for saveState + b.addAction(self.action_embed_fonts) + b.addAction(self.action_subset_fonts) + b.addAction(self.action_smarten_punctuation) + def create_docks(self): self.file_list_dock = d = QDockWidget(_('&Files Browser'), self) d.setObjectName('file_list_dock') # Needed for saveState