mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-03-18 07:29:16 -04:00
User-specified font for Kindle mastheads
This commit is contained in:
commit
8ddc5d2275
50
resources/recipes/heraldo.recipe
Normal file
50
resources/recipes/heraldo.recipe
Normal file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
__license__ = 'GPL v3'
|
||||
__author__ = 'Lorenzo Vigentini'
|
||||
__copyright__ = '2009, Lorenzo Vigentini <l.vigentini at gmail.com>'
|
||||
__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}
|
||||
'''
|
||||
@ -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)
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<item row="7" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -68,6 +68,32 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Kindle-specific options</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Alternate masthead font: </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLineEdit" name="opt_masthead_font"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
||||
@ -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 = '''
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user