mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
RTF Output: Metadata and more render tweaks.
This commit is contained in:
parent
9f5e16cc12
commit
3d4ae1920a
@ -17,23 +17,22 @@ import cStringIO
|
|||||||
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace, \
|
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace, \
|
||||||
OEB_IMAGES
|
OEB_IMAGES
|
||||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||||
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
|
|
||||||
TAGS = {
|
TAGS = {
|
||||||
'b': '\\b',
|
'b': '\\b',
|
||||||
'del': '\\deleted',
|
'del': '\\deleted',
|
||||||
'h1': '\\b \\par \\pard \\hyphpar \\keep',
|
'h1': '\\b \\par \\pard \\hyphpar',
|
||||||
'h2': '\\b \\par \\pard \\hyphpar \\keep',
|
'h2': '\\b \\par \\pard \\hyphpar',
|
||||||
'h3': '\\b \\par \\pard \\hyphpar \\keep',
|
'h3': '\\b \\par \\pard \\hyphpar',
|
||||||
'h4': '\\b \\par \\pard \\hyphpar \\keep',
|
'h4': '\\b \\par \\pard \\hyphpar',
|
||||||
'h5': '\\b \\par \\pard \\hyphpar \\keep',
|
'h5': '\\b \\par \\pard \\hyphpar',
|
||||||
'h6': '\\b \\par \\pard \\hyphpar \\keep',
|
'h6': '\\b \\par \\pard \\hyphpar',
|
||||||
'li': '\\par \\pard \\hyphpar \\keep \t',
|
'li': '\\par \\pard \\hyphpar \t',
|
||||||
'p': '\\par \\pard \\hyphpar \\keep \t',
|
'p': '\\par \\pard \\hyphpar \t',
|
||||||
#'ol': '\\pn \\pnrestart \\pnlvlblt',
|
|
||||||
'sub': '\\sub',
|
'sub': '\\sub',
|
||||||
'sup': '\\super',
|
'sup': '\\super',
|
||||||
'u': '\\ul',
|
'u': '\\ul',
|
||||||
#'ul': '\\pn \\pnrestart \\pndec',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SINGLE_TAGS = {
|
SINGLE_TAGS = {
|
||||||
@ -46,7 +45,7 @@ SINGLE_TAGS_END = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
STYLES = [
|
STYLES = [
|
||||||
('display', {'block': '\\par \\pard \\hyphpar \\keep'}),
|
('display', {'block': '\\par \\pard \\hyphpar'}),
|
||||||
('font-weight', {'bold': '\\b', 'bolder': '\\b'}),
|
('font-weight', {'bold': '\\b', 'bolder': '\\b'}),
|
||||||
('font-style', {'italic': '\\i'}),
|
('font-style', {'italic': '\\i'}),
|
||||||
('text-align', {'center': '\\qc', 'left': '\\ql', 'right': '\\qr'}),
|
('text-align', {'center': '\\qc', 'left': '\\ql', 'right': '\\qr'}),
|
||||||
@ -96,7 +95,7 @@ class RTFMLizer(object):
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
def header(self):
|
def header(self):
|
||||||
return u'{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033'
|
return u'{\\rtf1{\\info{\\title %s}{\\author %s}}\\ansi\\ansicpg1252\\deff0\\deflang1033' % (self.oeb_book.metadata.title[0].value, authors_to_string([x.value for x in self.oeb_book.metadata.creator]))
|
||||||
|
|
||||||
def footer(self):
|
def footer(self):
|
||||||
return ' }'
|
return ' }'
|
||||||
@ -145,7 +144,7 @@ class RTFMLizer(object):
|
|||||||
text = re.sub('[ ]{2,}', ' ', text)
|
text = re.sub('[ ]{2,}', ' ', text)
|
||||||
|
|
||||||
text = re.sub(r'(\{\\line \}\s*){3,}', r'{\\line }{\\line }', text)
|
text = re.sub(r'(\{\\line \}\s*){3,}', r'{\\line }{\\line }', text)
|
||||||
text = re.sub(r'(\{\\line \}\s*)+\{\\par', r'{\\par', text)
|
#text = re.compile(r'(\{\\line \}\s*)+(?P<brackets>}*)\s*\{\\par').sub(lambda mo: r'%s{\\par' % mo.group('brackets'), text)
|
||||||
|
|
||||||
# Remove non-breaking spaces
|
# Remove non-breaking spaces
|
||||||
text = text.replace(u'\xa0', ' ')
|
text = text.replace(u'\xa0', ' ')
|
||||||
@ -180,7 +179,7 @@ class RTFMLizer(object):
|
|||||||
block_start = ''
|
block_start = ''
|
||||||
block_end = ''
|
block_end = ''
|
||||||
if 'block' not in tag_stack:
|
if 'block' not in tag_stack:
|
||||||
block_start = '{\\par \\pard \\hyphpar \\keep '
|
block_start = '{\\par \\pard \\hyphpar '
|
||||||
block_end = '}'
|
block_end = '}'
|
||||||
text += '%s SPECIAL_IMAGE-%s-REPLACE_ME %s' % (block_start, src, block_end)
|
text += '%s SPECIAL_IMAGE-%s-REPLACE_ME %s' % (block_start, src, block_end)
|
||||||
|
|
||||||
@ -222,6 +221,6 @@ class RTFMLizer(object):
|
|||||||
if 'block' in tag_stack:
|
if 'block' in tag_stack:
|
||||||
text += '%s ' % elem.tail
|
text += '%s ' % elem.tail
|
||||||
else:
|
else:
|
||||||
text += '{\\par \\pard \\hyphpar \\keep %s}' % elem.tail
|
text += '{\\par \\pard \\hyphpar %s}' % elem.tail
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user