Conversion: Allow setting negative page margins. A negative page margin means that calibre will not specify any page margin in the output document (for formats that support this)

This commit is contained in:
Kovid Goyal 2012-05-13 08:40:57 +05:30
parent 9e3eceec74
commit 4a2de2c905
4 changed files with 52 additions and 17 deletions

View File

@ -343,21 +343,25 @@ OptionRecommendation(name='remove_fake_margins',
OptionRecommendation(name='margin_top',
recommended_value=5.0, level=OptionRecommendation.LOW,
help=_('Set the top margin in pts. Default is %default. '
'Setting this to less than zero will cause no margin to be set. '
'Note: 72 pts equals 1 inch')),
OptionRecommendation(name='margin_bottom',
recommended_value=5.0, level=OptionRecommendation.LOW,
help=_('Set the bottom margin in pts. Default is %default. '
'Setting this to less than zero will cause no margin to be set. '
'Note: 72 pts equals 1 inch')),
OptionRecommendation(name='margin_left',
recommended_value=5.0, level=OptionRecommendation.LOW,
help=_('Set the left margin in pts. Default is %default. '
'Setting this to less than zero will cause no margin to be set. '
'Note: 72 pts equals 1 inch')),
OptionRecommendation(name='margin_right',
recommended_value=5.0, level=OptionRecommendation.LOW,
help=_('Set the right margin in pts. Default is %default. '
'Setting this to less than zero will cause no margin to be set. '
'Note: 72 pts equals 1 inch')),
OptionRecommendation(name='change_justification',

View File

@ -966,7 +966,7 @@ class Manifest(object):
data = data.cssText
if isinstance(data, unicode):
data = data.encode('utf-8')
return data
return data + b'\n'
return str(data)
def __unicode__(self):

View File

@ -157,9 +157,11 @@ class CSSFlattener(object):
bs = body.get('style', '').split(';')
bs.append('margin-top: 0pt')
bs.append('margin-bottom: 0pt')
bs.append('margin-left : %fpt'%\
if float(self.context.margin_left) >= 0:
bs.append('margin-left : %gpt'%\
float(self.context.margin_left))
bs.append('margin-right : %fpt'%\
if float(self.context.margin_right) >= 0:
bs.append('margin-right : %gpt'%\
float(self.context.margin_right))
bs.extend(['padding-left: 0pt', 'padding-right: 0pt'])
if self.page_break_on_body:
@ -393,6 +395,7 @@ class CSSFlattener(object):
l = etree.SubElement(head, XHTML('link'),
rel='stylesheet', type=CSS_MIME, href=href)
l.tail='\n'
if global_href:
href = item.relhref(global_href)
l = etree.SubElement(head, XHTML('link'),
rel='stylesheet', type=CSS_MIME, href=href)
@ -413,14 +416,16 @@ class CSSFlattener(object):
global_css = defaultdict(list)
for item in self.oeb.spine:
stylizer = self.stylizers[item]
if float(self.context.margin_top) >= 0:
stylizer.page_rule['margin-top'] = '%gpt'%\
float(self.context.margin_top)
if float(self.context.margin_bottom) >= 0:
stylizer.page_rule['margin-bottom'] = '%gpt'%\
float(self.context.margin_bottom)
items = stylizer.page_rule.items()
items.sort()
css = ';\n'.join("%s: %s" % (key, val) for key, val in items)
css = '@page {\n%s\n}\n'%css
css = ('@page {\n%s\n}\n'%css) if items else ''
rules = [r.cssText for r in stylizer.font_face_rules]
raw = '\n\n'.join(rules)
css += '\n\n' + raw
@ -429,6 +434,8 @@ class CSSFlattener(object):
gc_map = {}
manifest = self.oeb.manifest
for css in global_css:
href = None
if css.strip():
id_, href = manifest.generate('page_css', 'page_styles.css')
manifest.add(id_, href, CSS_MIME, data=cssutils.parseString(css,
validate=False))

View File

@ -109,12 +109,18 @@
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="opt_margin_left">
<property name="specialValueText">
<string>No margin</string>
</property>
<property name="suffix">
<string> pt</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-1.000000000000000</double>
</property>
<property name="maximum">
<double>200.000000000000000</double>
</property>
@ -132,12 +138,18 @@
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="opt_margin_top">
<property name="specialValueText">
<string>No margin</string>
</property>
<property name="suffix">
<string> pt</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-1.000000000000000</double>
</property>
<property name="maximum">
<double>200.000000000000000</double>
</property>
@ -155,12 +167,18 @@
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="opt_margin_right">
<property name="specialValueText">
<string>No margin</string>
</property>
<property name="suffix">
<string> pt</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-1.000000000000000</double>
</property>
<property name="maximum">
<double>200.000000000000000</double>
</property>
@ -178,12 +196,18 @@
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="opt_margin_bottom">
<property name="specialValueText">
<string>No margin</string>
</property>
<property name="suffix">
<string> pt</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-1.000000000000000</double>
</property>
<property name="maximum">
<double>200.000000000000000</double>
</property>