mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
This commit is contained in:
commit
d72d615e5c
@ -64,4 +64,6 @@ class COOL_ER(EB600):
|
|||||||
VENDOR_NAME = 'COOL-ER'
|
VENDOR_NAME = 'COOL-ER'
|
||||||
WINDOWS_MAIN_MEM = 'EREADER'
|
WINDOWS_MAIN_MEM = 'EREADER'
|
||||||
|
|
||||||
|
OSX_MAIN_MEM = 'COOL-ER eReader Media'
|
||||||
|
|
||||||
EBOOK_DIR_MAIN = 'my docs'
|
EBOOK_DIR_MAIN = 'my docs'
|
||||||
|
@ -17,15 +17,20 @@ from calibre import prepare_string_for_xml
|
|||||||
from calibre.constants import __appname__, __version__
|
from calibre.constants import __appname__, __version__
|
||||||
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace
|
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace
|
||||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||||
from calibre.ebooks.oeb.base import OEB_IMAGES
|
from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES
|
||||||
|
|
||||||
TAG_MAP = {
|
TAG_MAP = {
|
||||||
'b' : 'strong',
|
'b' : 'strong',
|
||||||
'i' : 'emphasis',
|
'i' : 'emphasis',
|
||||||
'p' : 'p',
|
'p' : 'p',
|
||||||
'li' : 'p'
|
'li' : 'p',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TAG_SPACE = [
|
||||||
|
'div',
|
||||||
|
'br',
|
||||||
|
]
|
||||||
|
|
||||||
STYLES = [
|
STYLES = [
|
||||||
('font-weight', {'bold' : 'strong', 'bolder' : 'strong'}),
|
('font-weight', {'bold' : 'strong', 'bolder' : 'strong'}),
|
||||||
('font-style', {'italic' : 'emphasis'}),
|
('font-style', {'italic' : 'emphasis'}),
|
||||||
@ -60,12 +65,32 @@ class FB2MLizer(object):
|
|||||||
return u'<?xml version="1.0" encoding="UTF-8"?>\n%s' % etree.tostring(etree.fromstring(output), encoding=unicode, pretty_print=True)
|
return u'<?xml version="1.0" encoding="UTF-8"?>\n%s' % etree.tostring(etree.fromstring(output), encoding=unicode, pretty_print=True)
|
||||||
|
|
||||||
def fb2_header(self):
|
def fb2_header(self):
|
||||||
|
author_first = u''
|
||||||
|
author_middle = u''
|
||||||
|
author_last = u''
|
||||||
|
author_parts = self.oeb_book.metadata.creator[0].value.split(' ')
|
||||||
|
|
||||||
|
if len(author_parts) == 1:
|
||||||
|
author_last = author_parts[0]
|
||||||
|
elif len(author_parts == 2):
|
||||||
|
author_first = author_parts[0]
|
||||||
|
author_last = author_parts[1]
|
||||||
|
else:
|
||||||
|
author_first = author_parts[0]
|
||||||
|
author_middle = ' '.join(author_parts[1:-2])
|
||||||
|
author_last = author_parts[-1]
|
||||||
|
|
||||||
return u'<FictionBook xmlns:xlink="http://www.w3.org/1999/xlink" ' \
|
return u'<FictionBook xmlns:xlink="http://www.w3.org/1999/xlink" ' \
|
||||||
'xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">\n' \
|
'xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">\n' \
|
||||||
'<description>\n<title-info><book-title>%s</book-title> ' \
|
'<description>\n<title-info>\n ' \
|
||||||
|
'<author>\n<first-name>%s</first-name>\n<middle-name>%s' \
|
||||||
|
'</middle-name>\n<last-name>%s</last-name>\n</author>\n' \
|
||||||
|
'<book-title>%s</book-title> ' \
|
||||||
'</title-info><document-info> ' \
|
'</title-info><document-info> ' \
|
||||||
'<program-used>%s - %s</program-used></document-info>\n' \
|
'<program-used>%s - %s</program-used></document-info>\n' \
|
||||||
'</description>\n<body>\n<section>' % (self.oeb_book.metadata.title[0].value, __appname__, __version__)
|
'</description>\n<body>\n<section>' % (author_first, author_middle,
|
||||||
|
author_last, self.oeb_book.metadata.title[0].value,
|
||||||
|
__appname__, __version__)
|
||||||
|
|
||||||
def fb2_body_footer(self):
|
def fb2_body_footer(self):
|
||||||
return u'\n</section>\n</body>'
|
return u'\n</section>\n</body>'
|
||||||
@ -76,7 +101,7 @@ class FB2MLizer(object):
|
|||||||
def fb2mlize_images(self):
|
def fb2mlize_images(self):
|
||||||
images = u''
|
images = u''
|
||||||
for item in self.oeb_book.manifest:
|
for item in self.oeb_book.manifest:
|
||||||
if item.media_type in OEB_IMAGES:
|
if item.media_type in OEB_RASTER_IMAGES:
|
||||||
raw_data = b64encode(item.data)
|
raw_data = b64encode(item.data)
|
||||||
# Don't put the encoded image on a single line.
|
# Don't put the encoded image on a single line.
|
||||||
data = ''
|
data = ''
|
||||||
@ -108,14 +133,12 @@ class FB2MLizer(object):
|
|||||||
if tag == 'img':
|
if tag == 'img':
|
||||||
fb2_text += '<image xlink:href="#%s" />' % os.path.basename(elem.attrib['src'])
|
fb2_text += '<image xlink:href="#%s" />' % os.path.basename(elem.attrib['src'])
|
||||||
|
|
||||||
|
|
||||||
fb2_tag = TAG_MAP.get(tag, None)
|
fb2_tag = TAG_MAP.get(tag, None)
|
||||||
if fb2_tag and fb2_tag not in tag_stack:
|
if fb2_tag and fb2_tag not in tag_stack:
|
||||||
tag_count += 1
|
tag_count += 1
|
||||||
fb2_text += '<%s>' % fb2_tag
|
fb2_text += '<%s>' % fb2_tag
|
||||||
tag_stack.append(fb2_tag)
|
tag_stack.append(fb2_tag)
|
||||||
|
|
||||||
|
|
||||||
# Processes style information
|
# Processes style information
|
||||||
for s in STYLES:
|
for s in STYLES:
|
||||||
style_tag = s[1].get(style[s[0]], None)
|
style_tag = s[1].get(style[s[0]], None)
|
||||||
@ -124,7 +147,11 @@ class FB2MLizer(object):
|
|||||||
fb2_text += '<%s>' % style_tag
|
fb2_text += '<%s>' % style_tag
|
||||||
tag_stack.append(style_tag)
|
tag_stack.append(style_tag)
|
||||||
|
|
||||||
if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '':
|
if tag in TAG_SPACE:
|
||||||
|
if not fb2_text or fb2_text[-1] != ' ':
|
||||||
|
fb2_text += ' '
|
||||||
|
|
||||||
|
if hasattr(elem, 'text') and elem.text != None:
|
||||||
fb2_text += prepare_string_for_xml(elem.text)
|
fb2_text += prepare_string_for_xml(elem.text)
|
||||||
|
|
||||||
for item in elem:
|
for item in elem:
|
||||||
@ -135,12 +162,12 @@ class FB2MLizer(object):
|
|||||||
close_tag_list.insert(0, tag_stack.pop())
|
close_tag_list.insert(0, tag_stack.pop())
|
||||||
fb2_text += self.close_tags(close_tag_list)
|
fb2_text += self.close_tags(close_tag_list)
|
||||||
|
|
||||||
if hasattr(elem, 'tail') and elem.tail != None and elem.tail.strip() != '':
|
if hasattr(elem, 'tail') and elem.tail != None:
|
||||||
if 'p' not in tag_stack:
|
if 'p' not in tag_stack:
|
||||||
fb2_text += '<p>%s</p>' % prepare_string_for_xml(elem.tail)
|
fb2_text += '<p>%s</p>' % prepare_string_for_xml(elem.tail)
|
||||||
else:
|
else:
|
||||||
fb2_text += prepare_string_for_xml(elem.tail)
|
fb2_text += prepare_string_for_xml(elem.tail)
|
||||||
|
|
||||||
return fb2_text
|
return fb2_text
|
||||||
|
|
||||||
def close_tags(self, tags):
|
def close_tags(self, tags):
|
||||||
|
@ -20,7 +20,7 @@ except ImportError:
|
|||||||
import cStringIO
|
import cStringIO
|
||||||
|
|
||||||
from calibre.ebooks.pdb.formatwriter import FormatWriter
|
from calibre.ebooks.pdb.formatwriter import FormatWriter
|
||||||
from calibre.ebooks.oeb.base import OEB_IMAGES
|
from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES
|
||||||
from calibre.ebooks.pdb.header import PdbHeaderBuilder
|
from calibre.ebooks.pdb.header import PdbHeaderBuilder
|
||||||
from calibre.ebooks.pdb.ereader import image_name
|
from calibre.ebooks.pdb.ereader import image_name
|
||||||
from calibre.ebooks.pml.pmlml import PMLMLizer
|
from calibre.ebooks.pml.pmlml import PMLMLizer
|
||||||
@ -72,21 +72,24 @@ class Writer(FormatWriter):
|
|||||||
images = []
|
images = []
|
||||||
|
|
||||||
for item in manifest:
|
for item in manifest:
|
||||||
if item.media_type in OEB_IMAGES:
|
if item.media_type in OEB_RASTER_IMAGES:
|
||||||
header = 'PNG '
|
try:
|
||||||
|
im = Image.open(cStringIO.StringIO(item.data)).convert('P')
|
||||||
|
im.thumbnail((300,300), Image.ANTIALIAS)
|
||||||
|
|
||||||
header += image_name(item.href)
|
data = cStringIO.StringIO()
|
||||||
header = header.ljust(62, '\x00')
|
im.save(data, 'PNG')
|
||||||
|
data = data.getvalue()
|
||||||
|
|
||||||
im = Image.open(cStringIO.StringIO(item.data)).convert('P')
|
header = 'PNG '
|
||||||
im.thumbnail((300,300), Image.ANTIALIAS)
|
header += image_name(item.href)
|
||||||
|
header = header.ljust(62, '\x00')
|
||||||
|
|
||||||
data = cStringIO.StringIO()
|
if len(data) + len(header) < 65505:
|
||||||
im.save(data, 'PNG')
|
images.append((header, data))
|
||||||
data = data.getvalue()
|
except Exception as e:
|
||||||
|
self.log.error('Error: Could not include file %s becuase ' \
|
||||||
if len(data) + len(header) < 65505:
|
'%s.' % (item.href, e))
|
||||||
images.append((header, data))
|
|
||||||
|
|
||||||
return images
|
return images
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import cStringIO
|
|||||||
from calibre.ebooks.rb.rbml import RBMLizer
|
from calibre.ebooks.rb.rbml import RBMLizer
|
||||||
from calibre.ebooks.rb import HEADER
|
from calibre.ebooks.rb import HEADER
|
||||||
from calibre.ebooks.rb import unique_name
|
from calibre.ebooks.rb import unique_name
|
||||||
from calibre.ebooks.oeb.base import OEB_IMAGES
|
from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES
|
||||||
from calibre.constants import __appname__, __version__
|
from calibre.constants import __appname__, __version__
|
||||||
|
|
||||||
TEXT_RECORD_SIZE = 4096
|
TEXT_RECORD_SIZE = 4096
|
||||||
@ -116,20 +116,24 @@ class RBWriter(object):
|
|||||||
used_names = []
|
used_names = []
|
||||||
|
|
||||||
for item in manifest:
|
for item in manifest:
|
||||||
if item.media_type in OEB_IMAGES:
|
if item.media_type in OEB_RASTER_IMAGES:
|
||||||
data = ''
|
try:
|
||||||
|
data = ''
|
||||||
|
|
||||||
im = Image.open(cStringIO.StringIO(item.data)).convert('L')
|
im = Image.open(cStringIO.StringIO(item.data)).convert('L')
|
||||||
data = cStringIO.StringIO()
|
data = cStringIO.StringIO()
|
||||||
im.save(data, 'PNG')
|
im.save(data, 'PNG')
|
||||||
data = data.getvalue()
|
data = data.getvalue()
|
||||||
|
|
||||||
name = '%s.png' % os.path.splitext(os.path.basename(item.href))[0]
|
name = '%s.png' % os.path.splitext(os.path.basename(item.href))[0]
|
||||||
name = unique_name(name, used_names)
|
name = unique_name(name, used_names)
|
||||||
used_names.append(name)
|
used_names.append(name)
|
||||||
self.name_map[os.path.basename(item.href)] = name
|
self.name_map[os.path.basename(item.href)] = name
|
||||||
|
|
||||||
images.append((name, data))
|
images.append((name, data))
|
||||||
|
except Exception as e:
|
||||||
|
self.log.error('Error: Could not include file %s becuase ' \
|
||||||
|
'%s.' % (item.href, e))
|
||||||
|
|
||||||
return images
|
return images
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ except ImportError:
|
|||||||
import cStringIO
|
import cStringIO
|
||||||
|
|
||||||
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace, \
|
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace, \
|
||||||
OEB_IMAGES
|
OEB_RASTER_IMAGES
|
||||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||||
from calibre.ebooks.metadata import authors_to_string
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ class RTFMLizer(object):
|
|||||||
|
|
||||||
def insert_images(self, text):
|
def insert_images(self, text):
|
||||||
for item in self.oeb_book.manifest:
|
for item in self.oeb_book.manifest:
|
||||||
if item.media_type in OEB_IMAGES:
|
if item.media_type in OEB_RASTER_IMAGES:
|
||||||
src = os.path.basename(item.href)
|
src = os.path.basename(item.href)
|
||||||
data, width, height = self.image_to_hexstring(item.data)
|
data, width, height = self.image_to_hexstring(item.data)
|
||||||
text = text.replace('SPECIAL_IMAGE-%s-REPLACE_ME' % src, '\n\n{\\*\\shppict{\\pict\\picw%i\\pich%i\\jpegblip \n%s\n}}\n\n' % (width, height, data))
|
text = text.replace('SPECIAL_IMAGE-%s-REPLACE_ME' % src, '\n\n{\\*\\shppict{\\pict\\picw%i\\pich%i\\jpegblip \n%s\n}}\n\n' % (width, height, data))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user