mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Adjust linespacing when fontsize changes.
This commit is contained in:
parent
17dfb24f7f
commit
27d228caaf
@ -33,7 +33,7 @@ You may have to adjust the GROUP and the location of the rules file to
|
|||||||
suit your distribution.
|
suit your distribution.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = "0.3.41"
|
__version__ = "0.3.42"
|
||||||
__docformat__ = "epytext"
|
__docformat__ = "epytext"
|
||||||
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||||
|
|
||||||
|
@ -209,6 +209,8 @@ class Span(_Span):
|
|||||||
if fs.lower() == 'italic':
|
if fs.lower() == 'italic':
|
||||||
src = Italic(src)
|
src = Italic(src)
|
||||||
attrs = Span.translate_attrs(css, font_delta=font_delta, memory=memory)
|
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)
|
_Span.__init__(self, text=src, **attrs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,9 +44,6 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2><a name='tables'>Tables</a></h2>
|
<h2><a name='tables'>Tables</a></h2>
|
||||||
<p>
|
|
||||||
Because I can!
|
|
||||||
</p>
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
@ -62,7 +59,7 @@
|
|||||||
</p>
|
</p>
|
||||||
<br/>
|
<br/>
|
||||||
<p>
|
<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>
|
</p>
|
||||||
<br />
|
<br />
|
||||||
<p>
|
<p>
|
||||||
|
@ -163,10 +163,9 @@ class Cell(object):
|
|||||||
ts = tb.textStyle.attrs
|
ts = tb.textStyle.attrs
|
||||||
default_font = get_font(ts['fontfacename'], self.pts_to_pixels(ts['fontsize']))
|
default_font = get_font(ts['fontfacename'], self.pts_to_pixels(ts['fontsize']))
|
||||||
parindent = self.pts_to_pixels(ts['parindent'])
|
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
|
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:
|
if left + width > maxwidth:
|
||||||
left = width + ws
|
left = width + ws
|
||||||
top += ls
|
top += ls
|
||||||
@ -178,14 +177,19 @@ class Cell(object):
|
|||||||
return left, right, top, bottom
|
return left, right, top, bottom
|
||||||
|
|
||||||
for token, attrs in tokens(tb):
|
for token, attrs in tokens(tb):
|
||||||
|
if attrs == None:
|
||||||
|
attrs = {}
|
||||||
font = default_font
|
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
|
if isinstance(token, int): # Handle para and line breaks
|
||||||
top = bottom
|
top = bottom
|
||||||
left = parindent if int == 1 else 0
|
left = parindent if int == 1 else 0
|
||||||
continue
|
continue
|
||||||
if isinstance(token, Plot):
|
if isinstance(token, Plot):
|
||||||
width, height = self.pts_to_pixels(token.xsize), self.pts_to_pixels(token.ysize)
|
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
|
continue
|
||||||
ff = attrs.get('fontfacename', ts['fontfacename'])
|
ff = attrs.get('fontfacename', ts['fontfacename'])
|
||||||
fs = attrs.get('fontsize', ts['fontsize'])
|
fs = attrs.get('fontsize', ts['fontsize'])
|
||||||
@ -193,7 +197,7 @@ class Cell(object):
|
|||||||
font = get_font(ff, self.pts_to_pixels(fs))
|
font = get_font(ff, self.pts_to_pixels(fs))
|
||||||
for word in token.split():
|
for word in token.split():
|
||||||
width, height = font.getsize(word)
|
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
|
return right+3, bottom
|
||||||
|
|
||||||
def text_block_preferred_width(self, tb, debug=False):
|
def text_block_preferred_width(self, tb, debug=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user