mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
9e3eceec74
commit
4a2de2c905
@ -343,21 +343,25 @@ OptionRecommendation(name='remove_fake_margins',
|
|||||||
OptionRecommendation(name='margin_top',
|
OptionRecommendation(name='margin_top',
|
||||||
recommended_value=5.0, level=OptionRecommendation.LOW,
|
recommended_value=5.0, level=OptionRecommendation.LOW,
|
||||||
help=_('Set the top margin in pts. Default is %default. '
|
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')),
|
'Note: 72 pts equals 1 inch')),
|
||||||
|
|
||||||
OptionRecommendation(name='margin_bottom',
|
OptionRecommendation(name='margin_bottom',
|
||||||
recommended_value=5.0, level=OptionRecommendation.LOW,
|
recommended_value=5.0, level=OptionRecommendation.LOW,
|
||||||
help=_('Set the bottom margin in pts. Default is %default. '
|
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')),
|
'Note: 72 pts equals 1 inch')),
|
||||||
|
|
||||||
OptionRecommendation(name='margin_left',
|
OptionRecommendation(name='margin_left',
|
||||||
recommended_value=5.0, level=OptionRecommendation.LOW,
|
recommended_value=5.0, level=OptionRecommendation.LOW,
|
||||||
help=_('Set the left margin in pts. Default is %default. '
|
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')),
|
'Note: 72 pts equals 1 inch')),
|
||||||
|
|
||||||
OptionRecommendation(name='margin_right',
|
OptionRecommendation(name='margin_right',
|
||||||
recommended_value=5.0, level=OptionRecommendation.LOW,
|
recommended_value=5.0, level=OptionRecommendation.LOW,
|
||||||
help=_('Set the right margin in pts. Default is %default. '
|
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')),
|
'Note: 72 pts equals 1 inch')),
|
||||||
|
|
||||||
OptionRecommendation(name='change_justification',
|
OptionRecommendation(name='change_justification',
|
||||||
|
@ -966,7 +966,7 @@ class Manifest(object):
|
|||||||
data = data.cssText
|
data = data.cssText
|
||||||
if isinstance(data, unicode):
|
if isinstance(data, unicode):
|
||||||
data = data.encode('utf-8')
|
data = data.encode('utf-8')
|
||||||
return data
|
return data + b'\n'
|
||||||
return str(data)
|
return str(data)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
@ -157,10 +157,12 @@ class CSSFlattener(object):
|
|||||||
bs = body.get('style', '').split(';')
|
bs = body.get('style', '').split(';')
|
||||||
bs.append('margin-top: 0pt')
|
bs.append('margin-top: 0pt')
|
||||||
bs.append('margin-bottom: 0pt')
|
bs.append('margin-bottom: 0pt')
|
||||||
bs.append('margin-left : %fpt'%\
|
if float(self.context.margin_left) >= 0:
|
||||||
float(self.context.margin_left))
|
bs.append('margin-left : %gpt'%\
|
||||||
bs.append('margin-right : %fpt'%\
|
float(self.context.margin_left))
|
||||||
float(self.context.margin_right))
|
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'])
|
bs.extend(['padding-left: 0pt', 'padding-right: 0pt'])
|
||||||
if self.page_break_on_body:
|
if self.page_break_on_body:
|
||||||
bs.extend(['page-break-before: always'])
|
bs.extend(['page-break-before: always'])
|
||||||
@ -393,10 +395,11 @@ class CSSFlattener(object):
|
|||||||
l = etree.SubElement(head, XHTML('link'),
|
l = etree.SubElement(head, XHTML('link'),
|
||||||
rel='stylesheet', type=CSS_MIME, href=href)
|
rel='stylesheet', type=CSS_MIME, href=href)
|
||||||
l.tail='\n'
|
l.tail='\n'
|
||||||
href = item.relhref(global_href)
|
if global_href:
|
||||||
l = etree.SubElement(head, XHTML('link'),
|
href = item.relhref(global_href)
|
||||||
rel='stylesheet', type=CSS_MIME, href=href)
|
l = etree.SubElement(head, XHTML('link'),
|
||||||
l.tail = '\n'
|
rel='stylesheet', type=CSS_MIME, href=href)
|
||||||
|
l.tail = '\n'
|
||||||
|
|
||||||
def replace_css(self, css):
|
def replace_css(self, css):
|
||||||
manifest = self.oeb.manifest
|
manifest = self.oeb.manifest
|
||||||
@ -413,14 +416,16 @@ class CSSFlattener(object):
|
|||||||
global_css = defaultdict(list)
|
global_css = defaultdict(list)
|
||||||
for item in self.oeb.spine:
|
for item in self.oeb.spine:
|
||||||
stylizer = self.stylizers[item]
|
stylizer = self.stylizers[item]
|
||||||
stylizer.page_rule['margin-top'] = '%gpt'%\
|
if float(self.context.margin_top) >= 0:
|
||||||
float(self.context.margin_top)
|
stylizer.page_rule['margin-top'] = '%gpt'%\
|
||||||
stylizer.page_rule['margin-bottom'] = '%gpt'%\
|
float(self.context.margin_top)
|
||||||
float(self.context.margin_bottom)
|
if float(self.context.margin_bottom) >= 0:
|
||||||
|
stylizer.page_rule['margin-bottom'] = '%gpt'%\
|
||||||
|
float(self.context.margin_bottom)
|
||||||
items = stylizer.page_rule.items()
|
items = stylizer.page_rule.items()
|
||||||
items.sort()
|
items.sort()
|
||||||
css = ';\n'.join("%s: %s" % (key, val) for key, val in items)
|
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]
|
rules = [r.cssText for r in stylizer.font_face_rules]
|
||||||
raw = '\n\n'.join(rules)
|
raw = '\n\n'.join(rules)
|
||||||
css += '\n\n' + raw
|
css += '\n\n' + raw
|
||||||
@ -429,9 +434,11 @@ class CSSFlattener(object):
|
|||||||
gc_map = {}
|
gc_map = {}
|
||||||
manifest = self.oeb.manifest
|
manifest = self.oeb.manifest
|
||||||
for css in global_css:
|
for css in global_css:
|
||||||
id_, href = manifest.generate('page_css', 'page_styles.css')
|
href = None
|
||||||
manifest.add(id_, href, CSS_MIME, data=cssutils.parseString(css,
|
if css.strip():
|
||||||
validate=False))
|
id_, href = manifest.generate('page_css', 'page_styles.css')
|
||||||
|
manifest.add(id_, href, CSS_MIME, data=cssutils.parseString(css,
|
||||||
|
validate=False))
|
||||||
gc_map[css] = href
|
gc_map[css] = href
|
||||||
|
|
||||||
ans = {}
|
ans = {}
|
||||||
|
@ -109,12 +109,18 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QDoubleSpinBox" name="opt_margin_left">
|
<widget class="QDoubleSpinBox" name="opt_margin_left">
|
||||||
|
<property name="specialValueText">
|
||||||
|
<string>No margin</string>
|
||||||
|
</property>
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
<string> pt</string>
|
<string> pt</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="decimals">
|
<property name="decimals">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-1.000000000000000</double>
|
||||||
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<double>200.000000000000000</double>
|
<double>200.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
@ -132,12 +138,18 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QDoubleSpinBox" name="opt_margin_top">
|
<widget class="QDoubleSpinBox" name="opt_margin_top">
|
||||||
|
<property name="specialValueText">
|
||||||
|
<string>No margin</string>
|
||||||
|
</property>
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
<string> pt</string>
|
<string> pt</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="decimals">
|
<property name="decimals">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-1.000000000000000</double>
|
||||||
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<double>200.000000000000000</double>
|
<double>200.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
@ -155,12 +167,18 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QDoubleSpinBox" name="opt_margin_right">
|
<widget class="QDoubleSpinBox" name="opt_margin_right">
|
||||||
|
<property name="specialValueText">
|
||||||
|
<string>No margin</string>
|
||||||
|
</property>
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
<string> pt</string>
|
<string> pt</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="decimals">
|
<property name="decimals">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-1.000000000000000</double>
|
||||||
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<double>200.000000000000000</double>
|
<double>200.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
@ -178,12 +196,18 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QDoubleSpinBox" name="opt_margin_bottom">
|
<widget class="QDoubleSpinBox" name="opt_margin_bottom">
|
||||||
|
<property name="specialValueText">
|
||||||
|
<string>No margin</string>
|
||||||
|
</property>
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
<string> pt</string>
|
<string> pt</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="decimals">
|
<property name="decimals">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-1.000000000000000</double>
|
||||||
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<double>200.000000000000000</double>
|
<double>200.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user