mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
inline blocked images respect the text-align property.
This commit is contained in:
parent
9d3be321e7
commit
e383232fe9
@ -570,20 +570,11 @@ class HTMLConverter(object):
|
|||||||
elif isinstance(c, NavigableString):
|
elif isinstance(c, NavigableString):
|
||||||
self.add_text(c, pcss)
|
self.add_text(c, pcss)
|
||||||
|
|
||||||
def add_text(self, tag, css):
|
def process_alignment(self, css):
|
||||||
'''
|
'''
|
||||||
Add text to the current paragraph taking CSS into account.
|
Create a new TextBlock only if necessary as indicated by css
|
||||||
@param tag: Either a BeautifulSoup tag or a string
|
@type css: dict
|
||||||
@param css:
|
|
||||||
@type css:
|
|
||||||
'''
|
'''
|
||||||
src = tag.string if hasattr(tag, 'string') else tag
|
|
||||||
if self.lstrip_toggle:
|
|
||||||
src = src.lstrip()
|
|
||||||
self.lstrip_toggle = False
|
|
||||||
if not src.strip():
|
|
||||||
self.current_para.append(' ')
|
|
||||||
else:
|
|
||||||
align = 'head'
|
align = 'head'
|
||||||
if css.has_key('text-align'):
|
if css.has_key('text-align'):
|
||||||
val = css['text-align']
|
val = css['text-align']
|
||||||
@ -601,6 +592,22 @@ class HTMLConverter(object):
|
|||||||
blockStyle=self.current_block.blockStyle,
|
blockStyle=self.current_block.blockStyle,
|
||||||
textStyle=ts)
|
textStyle=ts)
|
||||||
self.current_para = Paragraph()
|
self.current_para = Paragraph()
|
||||||
|
|
||||||
|
def add_text(self, tag, css):
|
||||||
|
'''
|
||||||
|
Add text to the current paragraph taking CSS into account.
|
||||||
|
@param tag: Either a BeautifulSoup tag or a string
|
||||||
|
@param css:
|
||||||
|
@type css:
|
||||||
|
'''
|
||||||
|
src = tag.string if hasattr(tag, 'string') else tag
|
||||||
|
if self.lstrip_toggle:
|
||||||
|
src = src.lstrip()
|
||||||
|
self.lstrip_toggle = False
|
||||||
|
if not src.strip():
|
||||||
|
self.current_para.append(' ')
|
||||||
|
else:
|
||||||
|
self.process_alignment(css)
|
||||||
try:
|
try:
|
||||||
self.current_para.append(Span(src, self.sanctify_css(css), self.memory,\
|
self.current_para.append(Span(src, self.sanctify_css(css), self.memory,\
|
||||||
font_delta=self.font_delta))
|
font_delta=self.font_delta))
|
||||||
@ -761,13 +768,18 @@ class HTMLConverter(object):
|
|||||||
self.current_para.append(Plot(im, xsize=ceil(width*factor),
|
self.current_para.append(Plot(im, xsize=ceil(width*factor),
|
||||||
ysize=ceil(height*factor)))
|
ysize=ceil(height*factor)))
|
||||||
elif height <= self.page_height/1.5:
|
elif height <= self.page_height/1.5:
|
||||||
|
pb = self.current_block
|
||||||
self.end_current_para()
|
self.end_current_para()
|
||||||
|
self.process_alignment(tag_css)
|
||||||
im = Image(self.images[path], x0=0, y0=0, x1=width, y1=height,\
|
im = Image(self.images[path], x0=0, y0=0, x1=width, y1=height,\
|
||||||
xsize=width, ysize=height)
|
xsize=width, ysize=height)
|
||||||
self.current_para.append(Plot(im, xsize=width*factor,
|
self.current_para.append(Plot(im, xsize=width*factor,
|
||||||
ysize=height*factor))
|
ysize=height*factor))
|
||||||
self.current_block.append(self.current_para)
|
self.current_block.append(self.current_para)
|
||||||
self.current_block.append(CR())
|
self.current_page.append(self.current_block)
|
||||||
|
self.current_block = self.book.create_text_block(
|
||||||
|
textStyle=pb.textStyle,
|
||||||
|
blockStyle=pb.blockStyle)
|
||||||
self.current_para = Paragraph()
|
self.current_para = Paragraph()
|
||||||
else:
|
else:
|
||||||
self.current_block.append(self.current_para)
|
self.current_block.append(self.current_para)
|
||||||
@ -832,13 +844,6 @@ class HTMLConverter(object):
|
|||||||
self.process_children(tag, tag_css)
|
self.process_children(tag, tag_css)
|
||||||
if self.in_ol:
|
if self.in_ol:
|
||||||
self.in_ol += 1
|
self.in_ol += 1
|
||||||
elif False and tagname in ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']:
|
|
||||||
self.end_current_para()
|
|
||||||
if self.current_block.contents:
|
|
||||||
self.current_block.append(CR())
|
|
||||||
self.process_children(tag, tag_css)
|
|
||||||
self.end_current_para()
|
|
||||||
self.current_block.append(CR())
|
|
||||||
elif tagname == 'blockquote':
|
elif tagname == 'blockquote':
|
||||||
self.current_para.append_to(self.current_block)
|
self.current_para.append_to(self.current_block)
|
||||||
self.current_block.append_to(self.current_page)
|
self.current_block.append_to(self.current_page)
|
||||||
@ -863,6 +868,8 @@ class HTMLConverter(object):
|
|||||||
if tag_css.has_key('text-indent'):
|
if tag_css.has_key('text-indent'):
|
||||||
indent = Span.unit_convert(tag_css['text-indent'])
|
indent = Span.unit_convert(tag_css['text-indent'])
|
||||||
tag_css.pop('text-indent')
|
tag_css.pop('text-indent')
|
||||||
|
if not indent:
|
||||||
|
indent=0
|
||||||
else:
|
else:
|
||||||
indent = self.book.defaultTextStyle.attrs['parindent']
|
indent = self.book.defaultTextStyle.attrs['parindent']
|
||||||
if indent != self.current_block.textStyle.attrs['parindent']:
|
if indent != self.current_block.textStyle.attrs['parindent']:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user