mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Remove IM from calibre_cover()
This commit is contained in:
parent
0e282c10fc
commit
955a83a320
@ -202,12 +202,12 @@ class Pocket(BasicNewsRecipe):
|
|||||||
This override adds time to the cover
|
This override adds time to the cover
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from calibre.ebooks import calibre_cover
|
from calibre.ebooks.covers import calibre_cover2
|
||||||
title = self.title if isinstance(self.title, unicode) else \
|
title = self.title if isinstance(self.title, unicode) else \
|
||||||
self.title.decode('utf-8', 'replace')
|
self.title.decode('utf-8', 'replace')
|
||||||
date = strftime(self.timefmt)
|
date = strftime(self.timefmt)
|
||||||
time = strftime('[%I:%M %p]')
|
time = strftime('[%I:%M %p]')
|
||||||
img_data = calibre_cover(title, date, time)
|
img_data = calibre_cover2(title, date, time)
|
||||||
cover_file.write(img_data)
|
cover_file.write(img_data)
|
||||||
cover_file.flush()
|
cover_file.flush()
|
||||||
except:
|
except:
|
||||||
|
@ -106,13 +106,13 @@ class ALEX(N516):
|
|||||||
return os.path.join(base, 'covers', name)
|
return os.path.join(base, 'covers', name)
|
||||||
|
|
||||||
def upload_cover(self, path, filename, metadata, filepath):
|
def upload_cover(self, path, filename, metadata, filepath):
|
||||||
from calibre.ebooks import calibre_cover
|
from calibre.ebooks.covers import calibre_cover2
|
||||||
from calibre.utils.img import scale_image
|
from calibre.utils.img import scale_image
|
||||||
coverdata = getattr(metadata, 'thumbnail', None)
|
coverdata = getattr(metadata, 'thumbnail', None)
|
||||||
if coverdata and coverdata[2]:
|
if coverdata and coverdata[2]:
|
||||||
cover = coverdata[2]
|
cover = coverdata[2]
|
||||||
else:
|
else:
|
||||||
cover = calibre_cover(metadata.get('title', _('Unknown')),
|
cover = calibre_cover2(metadata.get('title', _('Unknown')),
|
||||||
metadata.get('authors', _('Unknown')))
|
metadata.get('authors', _('Unknown')))
|
||||||
|
|
||||||
cover = scale_image(cover, width=self.THUMBNAIL_HEIGHT,
|
cover = scale_image(cover, width=self.THUMBNAIL_HEIGHT,
|
||||||
|
@ -207,37 +207,10 @@ def calibre_cover(title, author_string, series_string=None,
|
|||||||
title = normalize(title)
|
title = normalize(title)
|
||||||
author_string = normalize(author_string)
|
author_string = normalize(author_string)
|
||||||
series_string = normalize(series_string)
|
series_string = normalize(series_string)
|
||||||
from calibre.utils.magick.draw import create_cover_page, TextLine
|
from calibre.ebooks.covers import calibre_cover2
|
||||||
import regex
|
from calibre.utils.img import image_to_data
|
||||||
pat = regex.compile(ur'\p{Cf}+', flags=regex.VERSION1) # remove non-printing chars like the soft hyphen
|
ans = calibre_cover2(title, author_string or '', series_string or '', logo_path=logo_path, as_qimage=True)
|
||||||
text = pat.sub(u'', title + author_string + (series_string or u''))
|
return image_to_data(ans, fmt=output_format)
|
||||||
font_path = P('fonts/liberation/LiberationSerif-Bold.ttf')
|
|
||||||
|
|
||||||
from calibre.utils.fonts.utils import get_font_for_text
|
|
||||||
font = open(font_path, 'rb').read()
|
|
||||||
c = get_font_for_text(text, font)
|
|
||||||
cleanup = False
|
|
||||||
if c is not None and c != font:
|
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
|
||||||
pt = PersistentTemporaryFile('.ttf')
|
|
||||||
pt.write(c)
|
|
||||||
pt.close()
|
|
||||||
font_path = pt.name
|
|
||||||
cleanup = True
|
|
||||||
|
|
||||||
lines = [TextLine(pat.sub(u'', title), title_size, font_path=font_path),
|
|
||||||
TextLine(pat.sub(u'', author_string), author_size, font_path=font_path)]
|
|
||||||
if series_string:
|
|
||||||
lines.append(TextLine(pat.sub(u'', series_string), author_size, font_path=font_path))
|
|
||||||
if logo_path is None:
|
|
||||||
logo_path = I('library.png')
|
|
||||||
try:
|
|
||||||
return create_cover_page(lines, logo_path, output_format='jpg',
|
|
||||||
texture_opacity=0.3, texture_data=I('cover_texture.png',
|
|
||||||
data=True))
|
|
||||||
finally:
|
|
||||||
if cleanup:
|
|
||||||
os.remove(font_path)
|
|
||||||
|
|
||||||
UNIT_RE = re.compile(r'^(-*[0-9]*[.]?[0-9]*)\s*(%|em|ex|en|px|mm|cm|in|pt|pc|rem|q)$')
|
UNIT_RE = re.compile(r'^(-*[0-9]*[.]?[0-9]*)\s*(%|em|ex|en|px|mm|cm|in|pt|pc|rem|q)$')
|
||||||
|
|
||||||
|
@ -164,14 +164,13 @@ class RTFInput(InputFormatPlugin):
|
|||||||
if self.opts.ignore_wmf:
|
if self.opts.ignore_wmf:
|
||||||
os.remove(name)
|
os.remove(name)
|
||||||
return '__REMOVE_ME__'
|
return '__REMOVE_ME__'
|
||||||
from calibre.ebooks import calibre_cover
|
from calibre.ebooks.covers import message_image
|
||||||
if self.default_img is None:
|
if self.default_img is None:
|
||||||
self.default_img = calibre_cover('Conversion of WMF images is not supported',
|
self.default_img = message_image('Conversion of WMF images is not supported.',
|
||||||
'Use Microsoft Word or OpenOffice to save this RTF file'
|
' Use Microsoft Word or OpenOffice to save this RTF file'
|
||||||
' as HTML and convert that in calibre.', title_size=36,
|
' as HTML and convert that in calibre.')
|
||||||
author_size=20)
|
|
||||||
name = name.replace('.wmf', '.jpg')
|
name = name.replace('.wmf', '.jpg')
|
||||||
with open(name, 'wb') as f:
|
with lopen(name, 'wb') as f:
|
||||||
f.write(self.default_img)
|
f.write(self.default_img)
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
@ -535,7 +535,7 @@ def create_cover(title, authors, series=None, series_index=1, prefs=None, as_qim
|
|||||||
prefs or cprefs, title_template=d['title_template'], subtitle_template=d['subtitle_template'], footer_template=d['footer_template'])
|
prefs or cprefs, title_template=d['title_template'], subtitle_template=d['subtitle_template'], footer_template=d['footer_template'])
|
||||||
return generate_cover(mi, prefs=prefs, as_qimage=as_qimage)
|
return generate_cover(mi, prefs=prefs, as_qimage=as_qimage)
|
||||||
|
|
||||||
def calibre_cover2(title, author_string='', series_string='', prefs=None, as_qimage=False):
|
def calibre_cover2(title, author_string='', series_string='', prefs=None, as_qimage=False, logo_path=None):
|
||||||
init_environment()
|
init_environment()
|
||||||
title, subtitle, footer = '<b>' + escape_formatting(title), '<i>' + escape_formatting(series_string), '<b>' + escape_formatting(author_string)
|
title, subtitle, footer = '<b>' + escape_formatting(title), '<i>' + escape_formatting(series_string), '<b>' + escape_formatting(author_string)
|
||||||
prefs = prefs or cprefs
|
prefs = prefs or cprefs
|
||||||
@ -555,7 +555,7 @@ def calibre_cover2(title, author_string='', series_string='', prefs=None, as_qim
|
|||||||
height = title_block.height + subtitle_block.height + extra_spacing + title_block.leading
|
height = title_block.height + subtitle_block.height + extra_spacing + title_block.leading
|
||||||
top += height + 25
|
top += height + 25
|
||||||
bottom = footer_block.position.y - 50
|
bottom = footer_block.position.y - 50
|
||||||
logo = QImage(I('library.png'))
|
logo = QImage(logo_path or I('library.png'))
|
||||||
pwidth, pheight = rect.width(), bottom - top
|
pwidth, pheight = rect.width(), bottom - top
|
||||||
scaled, width, height = fit_image(logo.width(), logo.height(), pwidth, pheight)
|
scaled, width, height = fit_image(logo.width(), logo.height(), pwidth, pheight)
|
||||||
x, y = (pwidth - width) // 2, (pheight - height) // 2
|
x, y = (pwidth - width) // 2, (pheight - height) // 2
|
||||||
@ -578,6 +578,19 @@ def calibre_cover2(title, author_string='', series_string='', prefs=None, as_qim
|
|||||||
return img
|
return img
|
||||||
return pixmap_to_data(img)
|
return pixmap_to_data(img)
|
||||||
|
|
||||||
|
def message_image(text, width=500, height=400, font_size=20):
|
||||||
|
init_environment()
|
||||||
|
img = QImage(width, height, QImage.Format_ARGB32)
|
||||||
|
img.fill(Qt.white)
|
||||||
|
p = QPainter(img)
|
||||||
|
f = QFont()
|
||||||
|
f.setPixelSize(font_size)
|
||||||
|
p.setFont(f)
|
||||||
|
r = img.rect().adjusted(10, 10, -10, -10)
|
||||||
|
p.drawText(r, Qt.AlignJustify | Qt.AlignVCenter | Qt.TextWordWrap, text)
|
||||||
|
p.end()
|
||||||
|
return pixmap_to_data(img)
|
||||||
|
|
||||||
def scale_cover(prefs, scale):
|
def scale_cover(prefs, scale):
|
||||||
for x in ('cover_width', 'cover_height', 'title_font_size', 'subtitle_font_size', 'footer_font_size'):
|
for x in ('cover_width', 'cover_height', 'title_font_size', 'subtitle_font_size', 'footer_font_size'):
|
||||||
prefs[x] = int(scale * prefs[x])
|
prefs[x] = int(scale * prefs[x])
|
||||||
|
@ -90,20 +90,20 @@ def get_gui():
|
|||||||
|
|
||||||
def add_quick_start_guide(library_view, refresh_cover_browser=None):
|
def add_quick_start_guide(library_view, refresh_cover_browser=None):
|
||||||
from calibre.ebooks.metadata.meta import get_metadata
|
from calibre.ebooks.metadata.meta import get_metadata
|
||||||
from calibre.ebooks import calibre_cover
|
from calibre.ebooks.covers import calibre_cover2
|
||||||
from calibre.utils.zipfile import safe_replace
|
from calibre.utils.zipfile import safe_replace
|
||||||
from calibre.utils.localization import get_lang, canonicalize_lang
|
from calibre.utils.localization import get_lang, canonicalize_lang
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
l = canonicalize_lang(get_lang()) or 'eng'
|
l = canonicalize_lang(get_lang()) or 'eng'
|
||||||
gprefs['quick_start_guide_added'] = True
|
gprefs['quick_start_guide_added'] = True
|
||||||
imgbuf = BytesIO(calibre_cover(_('Quick Start Guide'), '', author_size=8))
|
imgbuf = BytesIO(calibre_cover2(_('Quick Start Guide'), ''))
|
||||||
try:
|
try:
|
||||||
with open(P('quick_start/%s.epub' % l), 'rb') as src:
|
with lopen(P('quick_start/%s.epub' % l), 'rb') as src:
|
||||||
buf = BytesIO(src.read())
|
buf = BytesIO(src.read())
|
||||||
except EnvironmentError as err:
|
except EnvironmentError as err:
|
||||||
if err.errno != errno.ENOENT:
|
if err.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
with open(P('quick_start/eng.epub'), 'rb') as src:
|
with lopen(P('quick_start/eng.epub'), 'rb') as src:
|
||||||
buf = BytesIO(src.read())
|
buf = BytesIO(src.read())
|
||||||
safe_replace(buf, 'images/cover.jpg', imgbuf)
|
safe_replace(buf, 'images/cover.jpg', imgbuf)
|
||||||
buf.seek(0)
|
buf.seek(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user