mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Conversion pipeline: Add an option to set the minimum line height of all elemnts as a percentage of the computed font size. By default, calibre now sets the line height to 120% of the computed font size.
This commit is contained in:
parent
429e477674
commit
9ea944ff14
@ -120,7 +120,7 @@ def add_pipeline_options(parser, plumber):
|
|||||||
[
|
[
|
||||||
'base_font_size', 'disable_font_rescaling',
|
'base_font_size', 'disable_font_rescaling',
|
||||||
'font_size_mapping',
|
'font_size_mapping',
|
||||||
'line_height',
|
'line_height', 'minimum_line_height',
|
||||||
'linearize_tables',
|
'linearize_tables',
|
||||||
'extra_css', 'smarten_punctuation',
|
'extra_css', 'smarten_punctuation',
|
||||||
'margin_top', 'margin_left', 'margin_right',
|
'margin_top', 'margin_left', 'margin_right',
|
||||||
|
@ -160,13 +160,30 @@ OptionRecommendation(name='disable_font_rescaling',
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
OptionRecommendation(name='minimum_line_height',
|
||||||
|
recommended_value=120.0, level=OptionRecommendation.LOW,
|
||||||
|
help=_(
|
||||||
|
'The minimum line height, as a percentage of the element\'s '
|
||||||
|
'calculated font size. calibre will ensure that every element '
|
||||||
|
'has a line height of at least this setting, irrespective of '
|
||||||
|
'what the input document specifies. Set to zero to disable. '
|
||||||
|
'Default is 120%. Use this setting in preference to '
|
||||||
|
'the direct line height specification, unless you know what '
|
||||||
|
'you are doing. For example, you can achieve "double spaced" '
|
||||||
|
'text by setting this to 240.'
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
OptionRecommendation(name='line_height',
|
OptionRecommendation(name='line_height',
|
||||||
recommended_value=0, level=OptionRecommendation.LOW,
|
recommended_value=0, level=OptionRecommendation.LOW,
|
||||||
help=_('The line height in pts. Controls spacing between consecutive '
|
help=_(
|
||||||
'lines of text. By default no line height manipulation is '
|
'The line height in pts. Controls spacing between consecutive '
|
||||||
'performed.'
|
'lines of text. Only applies to elements that do not define '
|
||||||
)
|
'their own line height. In most cases, the minimum line height '
|
||||||
|
'option is more useful. '
|
||||||
|
'By default no line height manipulation is performed.'
|
||||||
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
OptionRecommendation(name='linearize_tables',
|
OptionRecommendation(name='linearize_tables',
|
||||||
|
@ -633,12 +633,12 @@ class Style(object):
|
|||||||
parent = self._getparent()
|
parent = self._getparent()
|
||||||
if 'line-height' in self._style:
|
if 'line-height' in self._style:
|
||||||
lineh = self._style['line-height']
|
lineh = self._style['line-height']
|
||||||
|
if lineh == 'normal':
|
||||||
|
lineh = '1.2'
|
||||||
try:
|
try:
|
||||||
float(lineh)
|
result = float(lineh) * self.fontSize
|
||||||
except ValueError:
|
except ValueError:
|
||||||
result = self._unit_convert(lineh, base=self.fontSize)
|
result = self._unit_convert(lineh, base=self.fontSize)
|
||||||
else:
|
|
||||||
result = float(lineh) * self.fontSize
|
|
||||||
elif parent is not None:
|
elif parent is not None:
|
||||||
# TODO: proper inheritance
|
# TODO: proper inheritance
|
||||||
result = parent.lineHeight
|
result = parent.lineHeight
|
||||||
|
@ -245,6 +245,8 @@ class CSSFlattener(object):
|
|||||||
del node.attrib['bgcolor']
|
del node.attrib['bgcolor']
|
||||||
if cssdict.get('font-weight', '').lower() == 'medium':
|
if cssdict.get('font-weight', '').lower() == 'medium':
|
||||||
cssdict['font-weight'] = 'normal' # ADE chokes on font-weight medium
|
cssdict['font-weight'] = 'normal' # ADE chokes on font-weight medium
|
||||||
|
|
||||||
|
fsize = font_size
|
||||||
if not self.context.disable_font_rescaling:
|
if not self.context.disable_font_rescaling:
|
||||||
_sbase = self.sbase if self.sbase is not None else \
|
_sbase = self.sbase if self.sbase is not None else \
|
||||||
self.context.source.fbase
|
self.context.source.fbase
|
||||||
@ -258,6 +260,14 @@ class CSSFlattener(object):
|
|||||||
fsize = self.fmap[font_size]
|
fsize = self.fmap[font_size]
|
||||||
cssdict['font-size'] = "%0.5fem" % (fsize / psize)
|
cssdict['font-size'] = "%0.5fem" % (fsize / psize)
|
||||||
psize = fsize
|
psize = fsize
|
||||||
|
|
||||||
|
try:
|
||||||
|
minlh = self.context.minimum_line_height / 100.
|
||||||
|
if style['line-height'] < minlh * fsize:
|
||||||
|
cssdict['line-height'] = str(minlh)
|
||||||
|
except:
|
||||||
|
self.oeb.logger.exception('Failed to set minimum line-height')
|
||||||
|
|
||||||
if cssdict:
|
if cssdict:
|
||||||
if self.lineh and self.fbase and tag != 'body':
|
if self.lineh and self.fbase and tag != 'body':
|
||||||
self.clean_edges(cssdict, style, psize)
|
self.clean_edges(cssdict, style, psize)
|
||||||
@ -290,6 +300,7 @@ class CSSFlattener(object):
|
|||||||
lineh = self.lineh / psize
|
lineh = self.lineh / psize
|
||||||
cssdict['line-height'] = "%0.5fem" % lineh
|
cssdict['line-height'] = "%0.5fem" % lineh
|
||||||
|
|
||||||
|
|
||||||
if (self.context.remove_paragraph_spacing or
|
if (self.context.remove_paragraph_spacing or
|
||||||
self.context.insert_blank_line) and tag in ('p', 'div'):
|
self.context.insert_blank_line) and tag in ('p', 'div'):
|
||||||
if item_id != 'calibre_jacket' or self.context.output_profile.name == 'Kindle':
|
if item_id != 'calibre_jacket' or self.context.output_profile.name == 'Kindle':
|
||||||
|
@ -21,7 +21,7 @@ class LookAndFeelWidget(Widget, Ui_Form):
|
|||||||
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
||||||
Widget.__init__(self, parent,
|
Widget.__init__(self, parent,
|
||||||
['change_justification', 'extra_css', 'base_font_size',
|
['change_justification', 'extra_css', 'base_font_size',
|
||||||
'font_size_mapping', 'line_height',
|
'font_size_mapping', 'line_height', 'minimum_line_height',
|
||||||
'linearize_tables', 'smarten_punctuation',
|
'linearize_tables', 'smarten_punctuation',
|
||||||
'disable_font_rescaling', 'insert_blank_line',
|
'disable_font_rescaling', 'insert_blank_line',
|
||||||
'remove_paragraph_spacing', 'remove_paragraph_spacing_indent_size','input_encoding',
|
'remove_paragraph_spacing', 'remove_paragraph_spacing_indent_size','input_encoding',
|
||||||
|
@ -97,7 +97,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Line &height:</string>
|
<string>Line &height:</string>
|
||||||
@ -107,7 +107,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1" colspan="2">
|
<item row="4" column="1" colspan="2">
|
||||||
<widget class="QDoubleSpinBox" name="opt_line_height">
|
<widget class="QDoubleSpinBox" name="opt_line_height">
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
<string> pt</string>
|
<string> pt</string>
|
||||||
@ -117,7 +117,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0">
|
<item row="5" column="0">
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Input character &encoding:</string>
|
<string>Input character &encoding:</string>
|
||||||
@ -127,17 +127,17 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1" colspan="3">
|
<item row="5" column="1" colspan="3">
|
||||||
<widget class="QLineEdit" name="opt_input_encoding"/>
|
<widget class="QLineEdit" name="opt_input_encoding"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="0" colspan="2">
|
<item row="6" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="opt_remove_paragraph_spacing">
|
<widget class="QCheckBox" name="opt_remove_paragraph_spacing">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Remove &spacing between paragraphs</string>
|
<string>Remove &spacing between paragraphs</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="2" colspan="2">
|
<item row="6" column="2" colspan="2">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="label_4">
|
||||||
@ -164,21 +164,21 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0">
|
<item row="7" column="0">
|
||||||
<widget class="QLabel" name="label_5">
|
<widget class="QLabel" name="label_5">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Text justification:</string>
|
<string>Text justification:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0">
|
<item row="8" column="0">
|
||||||
<widget class="QCheckBox" name="opt_linearize_tables">
|
<widget class="QCheckBox" name="opt_linearize_tables">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Linearize tables</string>
|
<string>&Linearize tables</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="10" column="0" colspan="4">
|
<item row="11" column="0" colspan="4">
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Extra &CSS</string>
|
<string>Extra &CSS</string>
|
||||||
@ -190,37 +190,60 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="2" colspan="2">
|
<item row="7" column="2" colspan="2">
|
||||||
<widget class="QComboBox" name="opt_change_justification"/>
|
<widget class="QComboBox" name="opt_change_justification"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="1" colspan="3">
|
<item row="8" column="1" colspan="3">
|
||||||
<widget class="QCheckBox" name="opt_asciiize">
|
<widget class="QCheckBox" name="opt_asciiize">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Transliterate unicode characters to ASCII</string>
|
<string>&Transliterate unicode characters to ASCII</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="0">
|
<item row="9" column="0">
|
||||||
<widget class="QCheckBox" name="opt_insert_blank_line">
|
<widget class="QCheckBox" name="opt_insert_blank_line">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Insert &blank line</string>
|
<string>Insert &blank line</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="1" colspan="2">
|
<item row="9" column="1" colspan="2">
|
||||||
<widget class="QCheckBox" name="opt_keep_ligatures">
|
<widget class="QCheckBox" name="opt_keep_ligatures">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Keep &ligatures</string>
|
<string>Keep &ligatures</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="9" column="0">
|
<item row="10" column="0">
|
||||||
<widget class="QCheckBox" name="opt_smarten_punctuation">
|
<widget class="QCheckBox" name="opt_smarten_punctuation">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Smarten &punctuation</string>
|
<string>Smarten &punctuation</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="label_6">
|
||||||
|
<property name="text">
|
||||||
|
<string>Minimum &line height:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>opt_minimum_line_height</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1" colspan="2">
|
||||||
|
<widget class="QDoubleSpinBox" name="opt_minimum_line_height">
|
||||||
|
<property name="suffix">
|
||||||
|
<string> %</string>
|
||||||
|
</property>
|
||||||
|
<property name="decimals">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<double>900.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user