diff --git a/resources/recipes/heraldo.recipe b/resources/recipes/heraldo.recipe new file mode 100644 index 0000000000..381e97b9ce --- /dev/null +++ b/resources/recipes/heraldo.recipe @@ -0,0 +1,50 @@ +#!/usr/bin/env python +__license__ = 'GPL v3' +__author__ = 'Lorenzo Vigentini' +__copyright__ = '2009, Lorenzo Vigentini ' +__description__ = 'Daily newspaper from Aragon' +__version__ = 'v1.01' +__date__ = '30, January 2010' + +''' +http://www.heraldo.es/ +''' + +from calibre.web.feeds.news import BasicNewsRecipe + +class heraldo(BasicNewsRecipe): + author = 'Lorenzo Vigentini' + description = 'Daily newspaper from Aragon' + + cover_url = 'http://www.heraldo.es/MODULOS/global/publico/interfaces/img/logo.gif' + title = u'Heraldo de Aragon' + publisher = 'OJD Nielsen' + category = 'News, politics, culture, economy, general interest' + + language = 'es' + timefmt = '[%a, %d %b, %Y]' + + oldest_article = 1 + max_articles_per_feed = 25 + + use_embedded_content = False + recursion = 10 + + remove_javascript = True + no_stylesheets = True + + keep_only_tags = [ + dict(name='div', attrs={'class':['titularNoticiaNN','textoGrisVerdanaContenidos']}) + ] + + feeds = [ + (u'Portadas ', u'http://www.heraldo.es/index.php/mod.portadas/mem.rss') + ] + extra_css = ''' + .articledate {color: gray;font-family: monospace;} + .articledescription {display: block;font-family: sans;font-size: 0.7em; text-indent: 0;} + .firma {color: #666;display: block;font-family: verdana, arial, helvetica;font-size: 1em;margin-bottom: 8px;} + .textoGrisVerdanaContenidos {color: #56595c;display: block;font-family: Verdana;font-size: 1.28571em;padding-bottom: 10px} + .titularNoticiaNN {display: block;padding-bottom: 10px;padding-left: 0;padding-right: 0;padding-top: 4px} + .titulo {color: #003066;font-family: Tahoma;font-size: 1.92857em;font-weight: bold;line-height: 1.2em} + ''' diff --git a/src/calibre/gui2/convert/mobi_output.py b/src/calibre/gui2/convert/mobi_output.py index 611ef96e11..b3650948f8 100644 --- a/src/calibre/gui2/convert/mobi_output.py +++ b/src/calibre/gui2/convert/mobi_output.py @@ -19,7 +19,7 @@ class PluginWidget(Widget, Ui_Form): def __init__(self, parent, get_option, get_help, db=None, book_id=None): Widget.__init__(self, parent, 'mobi_output', ['prefer_author_sort', 'rescale_images', 'toc_title', - 'dont_compress', 'no_inline_toc'] + 'dont_compress', 'no_inline_toc', 'masthead_font'] ) 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/mobi_output.ui b/src/calibre/gui2/convert/mobi_output.ui index a1bad48fb0..0b130d8369 100644 --- a/src/calibre/gui2/convert/mobi_output.ui +++ b/src/calibre/gui2/convert/mobi_output.ui @@ -41,7 +41,7 @@ - + Qt::Vertical @@ -68,6 +68,32 @@ + + + + + 75 + true + + + + Kindle-specific options + + + Qt::AlignCenter + + + + + + + Alternate masthead font: + + + + + + diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index 67e360da68..91c5a1bdb8 100644 --- a/src/calibre/library/catalog.py +++ b/src/calibre/library/catalog.py @@ -797,10 +797,11 @@ class EPUB_MOBI(CatalogPlugin): os.path.join(self.catalogPath, file[0])) # Create the custom masthead image overwriting default - try: + + if True: #try: self.generate_masthead_image(os.path.join(self.catalogPath, 'images/mastheadImage.gif')) - except: - pass +# except: +# pass def fetchBooksByTitle(self): self.updateProgressFullStep("Fetching database") @@ -1586,7 +1587,7 @@ class EPUB_MOBI(CatalogPlugin): def generateOPF(self): - self.updateProgressFullStep("Saving OPF") + self.updateProgressFullStep("Generating OPF") header = ''' @@ -2512,6 +2513,16 @@ class EPUB_MOBI(CatalogPlugin): return soup def generate_masthead_image(self, out_path): + from calibre.ebooks.conversion.config import load_defaults + recs = load_defaults('mobi_output') + font_path = recs.get('masthead_font') + default_font = P('fonts/liberation/LiberationSerif-Bold.ttf') + if not font_path or not os.access(font_path, os.R_OK): + font_path = default_font + else: + if self.opts.verbose: + self.opts.log(" Rendering catalog masthead with user-specifed font '%s'" % font_path) + MI_WIDTH = 600 MI_HEIGHT = 60 @@ -2523,7 +2534,11 @@ class EPUB_MOBI(CatalogPlugin): img = Image.new('RGB', (MI_WIDTH, MI_HEIGHT), 'white') draw = ImageDraw.Draw(img) - font = ImageFont.truetype(P('fonts/liberation/LiberationSerif-Bold.ttf'), 48) + try: + font = ImageFont.truetype(font_path, 48) + except: + self.opts.log.error(" Failed to load user-specifed font '%s'" % font_path) + font = ImageFont.truetype(default_font, 48) text = self.title.encode('utf-8') width, height = draw.textsize(text, font=font) left = max(int((MI_WIDTH - width)/2.), 0) diff --git a/src/calibre/web/feeds/news.py b/src/calibre/web/feeds/news.py index d182d856d8..125d766190 100644 --- a/src/calibre/web/feeds/news.py +++ b/src/calibre/web/feeds/news.py @@ -989,6 +989,13 @@ class BasicNewsRecipe(Recipe): MI_HEIGHT = 60 def default_masthead_image(self, out_path): + from calibre.ebooks.conversion.config import load_defaults + recs = load_defaults('mobi_output') + font_path = recs.get('masthead_font') + default-font = P('fonts/liberation/LiberationSerif-Bold.ttf') + if not font_path or not os.access(font_path, os.R_OK): + font_path = default_font + try: from PIL import Image, ImageDraw, ImageFont Image, ImageDraw, ImageFont @@ -997,7 +1004,10 @@ class BasicNewsRecipe(Recipe): img = Image.new('RGB', (self.MI_WIDTH, self.MI_HEIGHT), 'white') draw = ImageDraw.Draw(img) - font = ImageFont.truetype(P('fonts/liberation/LiberationSerif-Bold.ttf'), 48) + try: + font = ImageFont.truetype(font_path, 48) + except: + font = ImageFont.truetype(default_font, 48) text = self.get_masthead_title().encode('utf-8') width, height = draw.textsize(text, font=font) left = max(int((self.MI_WIDTH - width)/2.), 0)