diff --git a/src/calibre/ebooks/pdf/writer.py b/src/calibre/ebooks/pdf/writer.py index 03519a2cbb..4ff10290c9 100644 --- a/src/calibre/ebooks/pdf/writer.py +++ b/src/calibre/ebooks/pdf/writer.py @@ -25,10 +25,6 @@ from PyQt4.QtWebKit import QWebView from pyPdf import PdfFileWriter, PdfFileReader -def get_pdf_printer(): - return QPrinter(QPrinter.HighResolution) - - def get_custom_size(opts): custom_size = None if opts.custom_size != None: @@ -42,12 +38,12 @@ def get_custom_size(opts): custom_size = None return custom_size -def setup_printer(opts, for_comic=False): +def get_pdf_printer(opts, for_comic=False): from calibre.gui2 import is_ok_to_use_qt if not is_ok_to_use_qt(): raise Exception('Not OK to use Qt') - printer = get_pdf_printer() + printer = QPrinter(QPrinter.HighResolution) custom_size = get_custom_size(opts) if opts.output_profile.short_name == 'default': @@ -61,15 +57,22 @@ def setup_printer(opts, for_comic=False): h = opts.output_profile.comic_screen_size[1] if for_comic else \ opts.output_profile.height dpi = opts.output_profile.dpi - printer.setPaperSize(QSizeF(float(w) / dpi, float(h)/dpi), QPrinter.Inch) + printer.setPaperSize(QSizeF(float(w) / dpi, float(h) / dpi), QPrinter.Inch) - printer.setPageMargins(0, 0, 0, 0, QPrinter.Point) + if for_comic: + # Comic pages typically have their own margins, or their background + # color is not white, in which case the margin looks bad + printer.setPageMargins(0, 0, 0, 0, QPrinter.Point) + else: + printer.setPageMargins(opts.margin_left, opts.margin_top, + opts.margin_right, opts.margin_bottom, QPrinter.Point) printer.setOrientation(orientation(opts.orientation)) printer.setOutputFormat(QPrinter.PdfFormat) + printer.setFullPage(True) return printer def get_printer_page_size(opts, for_comic=False): - printer = setup_printer(opts, for_comic=for_comic) + printer = get_pdf_printer(opts, for_comic=for_comic) size = printer.paperSize(QPrinter.Millimeter) return size.width() / 10., size.height() / 10. @@ -154,24 +157,11 @@ class PDFWriter(QObject): # {{{ self.view.load(QUrl.fromLocalFile(item)) - def get_printer(self, set_horz_margins=False): - printer = get_pdf_printer() - printer.setPaperSize(QSizeF(self.size[0] * 10, self.size[1] * 10), QPrinter.Millimeter) - if set_horz_margins: - printer.setPageMargins(0., self.opts.margin_top, 0., - self.opts.margin_bottom, QPrinter.Point) - else: - printer.setPageMargins(0, 0, 0, 0, QPrinter.Point) - printer.setOrientation(orientation(self.opts.orientation)) - printer.setOutputFormat(QPrinter.PdfFormat) - printer.setFullPage(not set_horz_margins) - return printer - def _render_html(self, ok): if ok: item_path = os.path.join(self.tmp_path, '%i.pdf' % len(self.combine_queue)) - self.logger.debug('\tRendering item %s as %i' % (os.path.basename(str(self.view.url().toLocalFile())), len(self.combine_queue))) - printer = self.get_printer(set_horz_margins=True) + self.logger.debug('\tRendering item %s as %i.pdf' % (os.path.basename(str(self.view.url().toLocalFile())), len(self.combine_queue))) + printer = get_pdf_printer(self.opts) printer.setOutputFileName(item_path) self.view.print_(printer) self._render_book() @@ -233,16 +223,11 @@ class ImagePDFWriter(object): os.remove(f.name) def render_images(self, outpath, mi, items): - printer = get_pdf_printer() - printer.setPaperSize(QSizeF(self.size[0] * 10, self.size[1] * 10), QPrinter.Millimeter) - printer.setPageMargins(0, 0, 0, 0, QPrinter.Point) - printer.setOrientation(orientation(self.opts.orientation)) - printer.setOutputFormat(QPrinter.PdfFormat) + printer = get_pdf_printer(self.opts, for_comic=True) printer.setOutputFileName(outpath) printer.setDocName(mi.title) printer.setCreator(u'%s [%s]'%(__appname__, __version__)) # Seems to be no way to set author - printer.setFullPage(True) painter = QPainter(printer) painter.setRenderHints(QPainter.Antialiasing|QPainter.SmoothPixmapTransform) diff --git a/src/calibre/ebooks/txt/output.py b/src/calibre/ebooks/txt/output.py index a6369b6f0b..0e077672d8 100644 --- a/src/calibre/ebooks/txt/output.py +++ b/src/calibre/ebooks/txt/output.py @@ -29,8 +29,7 @@ class TXTOutput(OutputFormatPlugin): OptionRecommendation(name='output_encoding', recommended_value='utf-8', level=OptionRecommendation.LOW, help=_('Specify the character encoding of the output document. ' \ - 'The default is utf-8. Note: This option is not honored by all ' \ - 'formats.')), + 'The default is utf-8.')), OptionRecommendation(name='inline_toc', recommended_value=False, level=OptionRecommendation.LOW, help=_('Add Table of Contents to beginning of the book.')), diff --git a/src/calibre/gui2/convert/pdb_output.py b/src/calibre/gui2/convert/pdb_output.py index 9f88656f2f..51c202cb03 100644 --- a/src/calibre/gui2/convert/pdb_output.py +++ b/src/calibre/gui2/convert/pdb_output.py @@ -19,7 +19,7 @@ class PluginWidget(Widget, Ui_Form): ICON = I('mimetypes/unknown.png') def __init__(self, parent, get_option, get_help, db=None, book_id=None): - Widget.__init__(self, parent, ['format', 'inline_toc']) + Widget.__init__(self, parent, ['format', 'inline_toc', 'output_encoding']) self.db, self.book_id = db, book_id self.initialize_options(get_option, get_help, db, book_id) diff --git a/src/calibre/gui2/convert/pdb_output.ui b/src/calibre/gui2/convert/pdb_output.ui index 772a19b79e..17bdc0a984 100644 --- a/src/calibre/gui2/convert/pdb_output.ui +++ b/src/calibre/gui2/convert/pdb_output.ui @@ -27,7 +27,7 @@ - + Qt::Vertical @@ -40,13 +40,23 @@ - + &Inline TOC + + + + Output Encoding: + + + + + + diff --git a/src/calibre/gui2/convert/pml_output.py b/src/calibre/gui2/convert/pml_output.py index 61207d3de5..f7905194ca 100644 --- a/src/calibre/gui2/convert/pml_output.py +++ b/src/calibre/gui2/convert/pml_output.py @@ -17,6 +17,7 @@ class PluginWidget(Widget, Ui_Form): ICON = I('mimetypes/unknown.png') def __init__(self, parent, get_option, get_help, db=None, book_id=None): - Widget.__init__(self, parent, ['inline_toc', 'full_image_depth']) + Widget.__init__(self, parent, ['inline_toc', 'full_image_depth', + 'output_encoding']) self.db, self.book_id = db, book_id self.initialize_options(get_option, get_help, db, book_id) diff --git a/src/calibre/gui2/convert/pmlz_output.ui b/src/calibre/gui2/convert/pmlz_output.ui index 3573e14210..9754752c8a 100644 --- a/src/calibre/gui2/convert/pmlz_output.ui +++ b/src/calibre/gui2/convert/pmlz_output.ui @@ -14,7 +14,7 @@ Form - + Qt::Vertical @@ -27,20 +27,30 @@ - + &Inline TOC - + Do not reduce image size and depth + + + + Output Encoding: + + + + + + diff --git a/src/calibre/gui2/convert/txt_output.py b/src/calibre/gui2/convert/txt_output.py index 2fafad4b43..9f30e0d83f 100644 --- a/src/calibre/gui2/convert/txt_output.py +++ b/src/calibre/gui2/convert/txt_output.py @@ -21,7 +21,8 @@ class PluginWidget(Widget, Ui_Form): def __init__(self, parent, get_option, get_help, db=None, book_id=None): Widget.__init__(self, parent, ['newline', 'max_line_length', 'force_max_line_length', - 'inline_toc', 'markdown_format', 'keep_links', 'keep_image_references']) + 'inline_toc', 'markdown_format', 'keep_links', 'keep_image_references', + 'output_encoding']) self.db, self.book_id = db, book_id self.initialize_options(get_option, get_help, db, book_id) diff --git a/src/calibre/gui2/convert/txt_output.ui b/src/calibre/gui2/convert/txt_output.ui index 19e4ec52a1..6290a096c8 100644 --- a/src/calibre/gui2/convert/txt_output.ui +++ b/src/calibre/gui2/convert/txt_output.ui @@ -27,7 +27,7 @@ - + Qt::Vertical @@ -40,7 +40,7 @@ - + &Inline TOC @@ -60,34 +60,44 @@ - + Force maximum line length - + Apply Markdown formatting to text - + Do not remove links (<a> tags) before processing - + Do not remove image references before processing + + + + Output Encoding: + + + + + +