Adjust linespacing when fontsize changes.

This commit is contained in:
Kovid Goyal 2007-05-26 16:07:41 +00:00
parent 17dfb24f7f
commit 27d228caaf
4 changed files with 12 additions and 9 deletions

View file

@ -33,7 +33,7 @@
suit your distribution.
"""
__version__ = "0.3.41"
__version__ = "0.3.42"
__docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"

View file

@ -209,6 +209,8 @@ def __init__(self, ns, css, memory, font_delta=0):
if fs.lower() == 'italic':
src = Italic(src)
attrs = Span.translate_attrs(css, font_delta=font_delta, memory=memory)
if 'fontsize' in attrs.keys():
attrs['baselineskip'] = int(attrs['fontsize']) + 20
_Span.__init__(self, text=src, **attrs)

View file

@ -44,9 +44,6 @@
</p>
<h2><a name='tables'>Tables</a></h2>
<p>
Because I can!
</p>
<br/>
<table>
@ -62,7 +59,7 @@
</p>
<br/>
<p>
Not that if you have custom fonts on your reader, the table may not be properly aligned. Also html2lrf does not support nested tables.
Note that if you have custom fonts on your reader, the table may not be properly aligned. Also html2lrf does not support nested tables.
</p>
<br />
<p>

View file

@ -163,10 +163,9 @@ def text_block_size(self, tb, maxwidth=sys.maxint, debug=False):
ts = tb.textStyle.attrs
default_font = get_font(ts['fontfacename'], self.pts_to_pixels(ts['fontsize']))
parindent = self.pts_to_pixels(ts['parindent'])
ls, ws = self.pts_to_pixels(ts['baselineskip']) + self.pts_to_pixels(ts['linespace']), self.pts_to_pixels(ts['wordspace'])
top, bottom, left, right = 0, 0, parindent, parindent
def add_word(width, height, left, right, top, bottom):
def add_word(width, height, left, right, top, bottom, ls, ws):
if left + width > maxwidth:
left = width + ws
top += ls
@ -178,14 +177,19 @@ def add_word(width, height, left, right, top, bottom):
return left, right, top, bottom
for token, attrs in tokens(tb):
if attrs == None:
attrs = {}
font = default_font
ls = self.pts_to_pixels(attrs.get('baselineskip', ts['baselineskip']))+\
self.pts_to_pixels(attrs.get('linespace', ts['linespace']))
ws = self.pts_to_pixels(attrs.get('wordspace', ts['wordspace']))
if isinstance(token, int): # Handle para and line breaks
top = bottom
left = parindent if int == 1 else 0
continue
if isinstance(token, Plot):
width, height = self.pts_to_pixels(token.xsize), self.pts_to_pixels(token.ysize)
left, right, top, bottom = add_word(width, height, left, right, top, bottom)
left, right, top, bottom = add_word(width, height, left, right, top, bottom, ls, ws)
continue
ff = attrs.get('fontfacename', ts['fontfacename'])
fs = attrs.get('fontsize', ts['fontsize'])
@ -193,7 +197,7 @@ def add_word(width, height, left, right, top, bottom):
font = get_font(ff, self.pts_to_pixels(fs))
for word in token.split():
width, height = font.getsize(word)
left, right, top, bottom = add_word(width, height, left, right, top, bottom)
left, right, top, bottom = add_word(width, height, left, right, top, bottom, ls, ws)
return right+3, bottom
def text_block_preferred_width(self, tb, debug=False):