From b7dfad3f187305da4ca001a00da40525205d633f Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 22 Apr 2012 20:55:50 -0400 Subject: [PATCH 1/4] PDF Output: Set engine on OS X based upon paper size as stanard sizes are fixed with Qt 4.8.1. Custom sizes are still broken. --- src/calibre/ebooks/pdf/writer.py | 41 ++++++++++++++------------------ 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/calibre/ebooks/pdf/writer.py b/src/calibre/ebooks/pdf/writer.py index a680d61188..ea23a9c248 100644 --- a/src/calibre/ebooks/pdf/writer.py +++ b/src/calibre/ebooks/pdf/writer.py @@ -45,29 +45,24 @@ def get_pdf_printer(opts, for_comic=False, output_file_name=None): if not is_ok_to_use_qt(): raise Exception('Not OK to use Qt') + custom_size = False printer = QPrinter(QPrinter.HighResolution) custom_size = get_custom_size(opts) - if isosx and not for_comic: - # On OSX, the native engine can only produce a single page size - # (usually A4). The Qt engine on the other hand produces image based - # PDFs. If we set a custom page size using QSizeF the native engine - # produces unreadable output, so we just ignore the custom size - # settings. - printer.setPaperSize(paper_size(opts.paper_size)) - else: - if opts.output_profile.short_name == 'default' or \ - opts.output_profile.width > 9999: - if custom_size is None: - printer.setPaperSize(paper_size(opts.paper_size)) - else: - printer.setPaperSize(QSizeF(custom_size[0], custom_size[1]), unit(opts.unit)) + if opts.output_profile.short_name == 'default' or \ + opts.output_profile.width > 9999: + if custom_size is None: + printer.setPaperSize(paper_size(opts.paper_size)) else: - w = opts.output_profile.comic_screen_size[0] if for_comic else \ - opts.output_profile.width - 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) + custom_size = True + printer.setPaperSize(QSizeF(custom_size[0], custom_size[1]), unit(opts.unit)) + else: + custom_size = True + w = opts.output_profile.comic_screen_size[0] if for_comic else \ + opts.output_profile.width + 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) if for_comic: # Comic pages typically have their own margins, or their background @@ -77,13 +72,13 @@ def get_pdf_printer(opts, for_comic=False, output_file_name=None): 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(for_comic) if output_file_name: printer.setOutputFileName(output_file_name) - if isosx and not for_comic: - # Ensure we are not generating enormous image based PDFs + if isosx and not custom_size: printer.setOutputFormat(QPrinter.NativeFormat) + else: + printer.setOutputFormat(QPrinter.PdfFormat) return printer From e9a9ccba9f77664d2bbb6bf6eb78399b579581b4 Mon Sep 17 00:00:00 2001 From: Alex Stanev Date: Fri, 27 Apr 2012 13:14:30 +0300 Subject: [PATCH 2/4] add biblio.bg store --- src/calibre/customize/builtins.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 2908444665..fa736068b5 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1254,6 +1254,15 @@ class StoreBeWriteStore(StoreBase): headquarters = 'US' formats = ['EPUB', 'MOBI', 'PDF'] +class StoreBiblioStore(StoreBase): + name = 'Biblio' + author = 'Alex Stanev' + description = u'Електронна книжарница за книги и списания във формати ePUB и PDF. Част от заглавията са с активна DRM защита.' + actual_plugin = 'calibre.gui2.store.stores.biblio_plugin:BiblioStore' + + headquarters = 'BG' + formats = ['EPUB, PDF'] + class StoreBookotekaStore(StoreBase): name = 'Bookoteka' author = u'Tomasz Długosz' @@ -1605,6 +1614,7 @@ plugins += [ StoreBNStore, StoreBeamEBooksDEStore, StoreBeWriteStore, + StoreBiblioStore, StoreBookotekaStore, StoreChitankaStore, StoreDieselEbooksStore, From cfad95d0ea8cdadf2daec7b0e7108041d16dda33 Mon Sep 17 00:00:00 2001 From: Alex Stanev Date: Fri, 27 Apr 2012 14:05:45 +0300 Subject: [PATCH 3/4] add biblio.bg plugin --- .../gui2/store/stores/biblio_plugin.py | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/calibre/gui2/store/stores/biblio_plugin.py diff --git a/src/calibre/gui2/store/stores/biblio_plugin.py b/src/calibre/gui2/store/stores/biblio_plugin.py new file mode 100644 index 0000000000..5a40ec57cc --- /dev/null +++ b/src/calibre/gui2/store/stores/biblio_plugin.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) + +__license__ = 'GPL 3' +__copyright__ = '2012, Alex Stanev ' +__docformat__ = 'restructuredtext en' + +import re + +from calibre.gui2.store.basic_config import BasicStoreConfig +from calibre.gui2.store.opensearch_store import OpenSearchOPDSStore +from calibre.gui2.store.search_result import SearchResult + +class BiblioStore(BasicStoreConfig, OpenSearchOPDSStore): + + open_search_url = 'http://biblio.bg/feed.opds.php' + web_url = 'http://biblio.bg/' + + def search(self, query, max_results=10, timeout=60): + # check for cyrillic symbols before performing search + uquery = unicode(query.strip(), 'utf-8') + reObj = re.search(u'^[а-яА-Я\\d\\s]{3,}$', uquery) + if not reObj: + return + + for s in OpenSearchOPDSStore.search(self, query, max_results, timeout): + yield s + + def get_details(self, search_result, timeout): + # get format and DRM status + from calibre import browser + from contextlib import closing + from lxml import html + + br = browser() + with closing(br.open(search_result.detail_item, timeout=timeout)) as nf: + idata = html.fromstring(nf.read()) + search_result.formats = '' + if idata.xpath('.//span[@class="format epub"]'): + search_result.formats = 'EPUB' + + if idata.xpath('.//span[@class="format pdf"]'): + if search_result.formats == '': + search_result.formats = 'PDF' + else: + search_result.formats.join(', PDF') + + if idata.xpath('.//span[@class="format nodrm-icon"]'): + search_result.drm = SearchResult.DRM_UNLOCKED + else: + search_result.drm = SearchResult.DRM_LOCKED + + return True From 2c2f0c272ba11906457d6a0b8f2ac74eaa8bd1ee Mon Sep 17 00:00:00 2001 From: Alex Stanev Date: Tue, 1 May 2012 20:44:32 +0300 Subject: [PATCH 4/4] Change store name --- src/calibre/customize/builtins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 0309a72041..23059bcce2 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1254,7 +1254,7 @@ class StoreBeWriteStore(StoreBase): formats = ['EPUB', 'MOBI', 'PDF'] class StoreBiblioStore(StoreBase): - name = 'Biblio' + name = u'Библио.бг' author = 'Alex Stanev' description = u'Електронна книжарница за книги и списания във формати ePUB и PDF. Част от заглавията са с активна DRM защита.' actual_plugin = 'calibre.gui2.store.stores.biblio_plugin:BiblioStore'