mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fixed typo in pylrs.py and shifted to using non full size ImageBlocks in html2lrf
This commit is contained in:
parent
b3d7fd96f2
commit
b637f37559
@ -326,7 +326,7 @@ class HTMLConverter(object):
|
|||||||
self.current_block = TextBlock()
|
self.current_block = TextBlock()
|
||||||
self.current_para = Paragraph()
|
self.current_para = Paragraph()
|
||||||
if self.cover:
|
if self.cover:
|
||||||
self.add_image_block(self.cover)
|
self.add_image_page(self.cover)
|
||||||
self.top = self.current_block
|
self.top = self.current_block
|
||||||
|
|
||||||
self.process_children(self.soup, {})
|
self.process_children(self.soup, {})
|
||||||
@ -422,13 +422,13 @@ class HTMLConverter(object):
|
|||||||
self.current_page = Page()
|
self.current_page = Page()
|
||||||
|
|
||||||
|
|
||||||
def add_image_block(self, path):
|
def add_image_page(self, path):
|
||||||
if os.access(path, os.R_OK):
|
if os.access(path, os.R_OK):
|
||||||
self.end_page()
|
self.end_page()
|
||||||
page = ImagePage()
|
page = ImagePage()
|
||||||
if not self.images.has_key(path):
|
if not self.images.has_key(path):
|
||||||
self.images[path] = ImageStream(path)
|
self.images[path] = ImageStream(path)
|
||||||
page.append(ImageBlock(self.images[path], blockStyle=BlockStyle(blockrule='block-fixed')))
|
page.append(ImageBlock(self.images[path]))
|
||||||
self.book.append(page)
|
self.book.append(page)
|
||||||
|
|
||||||
def process_children(self, ptag, pcss):
|
def process_children(self, ptag, pcss):
|
||||||
@ -504,14 +504,43 @@ class HTMLConverter(object):
|
|||||||
path = purl[2]
|
path = purl[2]
|
||||||
if path and os.path.splitext(path)[1][1:].lower() in \
|
if path and os.path.splitext(path)[1][1:].lower() in \
|
||||||
['png', 'jpg', 'bmp', 'jpeg']:
|
['png', 'jpg', 'bmp', 'jpeg']:
|
||||||
self.add_image_block(path)
|
self.add_image_page(path)
|
||||||
else:
|
else:
|
||||||
span = _Span()
|
span = _Span()
|
||||||
self.current_para.append(span)
|
self.current_para.append(span)
|
||||||
self.links.append(HTMLConverter.Link(span, tag))
|
self.links.append(HTMLConverter.Link(span, tag))
|
||||||
elif tagname == 'img':
|
elif tagname == 'img':
|
||||||
if tag.has_key('src'):
|
if tag.has_key('src') and os.access(tag['src'], os.R_OK):
|
||||||
self.add_image_block(tag['src'])
|
width, height = 600, 800
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
im = Image.open(tag['src'])
|
||||||
|
width, height = im.size
|
||||||
|
if tag.has_key('width'):
|
||||||
|
width = int(tag['width'])
|
||||||
|
if tag.has_key('height'):
|
||||||
|
height = int(tag['height'])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.current_block.append(self.current_para)
|
||||||
|
self.current_page.append(self.current_block)
|
||||||
|
self.current_para = Paragraph()
|
||||||
|
self.current_block = TextBlock()
|
||||||
|
path = os.path.abspath(tag['src'])
|
||||||
|
print width, height
|
||||||
|
if not self.images.has_key(path):
|
||||||
|
self.images[path] = ImageStream(path)
|
||||||
|
im = ImageBlock(self.images[path], x1=width, y1=height,
|
||||||
|
xsize=width, ysize=height)
|
||||||
|
self.current_page.append(im)
|
||||||
|
else:
|
||||||
|
print >>sys.stderr, "Failed to process", tag
|
||||||
|
|
||||||
|
self.add_image_page(tag['src'])
|
||||||
elif tagname in ['style', 'link']:
|
elif tagname in ['style', 'link']:
|
||||||
if tagname == 'style':
|
if tagname == 'style':
|
||||||
for c in tag.contents:
|
for c in tag.contents:
|
||||||
|
@ -1446,7 +1446,7 @@ class Paragraph(LrsContainer):
|
|||||||
explicit .append methods to build up the text stream.
|
explicit .append methods to build up the text stream.
|
||||||
"""
|
"""
|
||||||
def __init__(self, text=None):
|
def __init__(self, text=None):
|
||||||
LrsContainer.__init__(self, [Text, CR, DrawChar, CharButton,
|
LrsContainer.__init__(self, [Text, CR, DrawChar, CharButton, Span,
|
||||||
LrsSimpleChar1, basestring])
|
LrsSimpleChar1, basestring])
|
||||||
if text is not None:
|
if text is not None:
|
||||||
self.append(text)
|
self.append(text)
|
||||||
@ -2137,7 +2137,8 @@ class ImageBlock(LrsObject, LrsContainer, LrsAttributes):
|
|||||||
defaults = dict(blockwidth="600", blockheight="800")
|
defaults = dict(blockwidth="600", blockheight="800")
|
||||||
|
|
||||||
def __init__(self, refstream, x0="0", y0="0", x1="600", y1="800",
|
def __init__(self, refstream, x0="0", y0="0", x1="600", y1="800",
|
||||||
xsize="600", ysize="800", blockStyle=None,
|
xsize="600", ysize="800",
|
||||||
|
blockStyle=BlockStyle(blockrule='block-fixed'),
|
||||||
alttext=None, **settings):
|
alttext=None, **settings):
|
||||||
LrsObject.__init__(self)
|
LrsObject.__init__(self)
|
||||||
LrsContainer.__init__(self, [])
|
LrsContainer.__init__(self, [])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user