mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
RTF Input: Fix handling of text align. Fixes #3644 (Centered text is left justified after conversion)
This commit is contained in:
commit
9dc9cfb257
@ -265,9 +265,20 @@
|
|||||||
<xsl:value-of select="@line-height"/>
|
<xsl:value-of select="@line-height"/>
|
||||||
<xsl:text>pt;</xsl:text>
|
<xsl:text>pt;</xsl:text>
|
||||||
</xsl:if>
|
</xsl:if>
|
||||||
|
<xsl:if test="(@align = 'just')">
|
||||||
|
<xsl:text>text-align: justify;</xsl:text>
|
||||||
|
</xsl:if>
|
||||||
|
<xsl:if test="(@align = 'cent')">
|
||||||
|
<xsl:text>text-align: center;</xsl:text>
|
||||||
|
</xsl:if>
|
||||||
|
<xsl:if test="(@align = 'left')">
|
||||||
|
<xsl:text>text-align: left;</xsl:text>
|
||||||
|
</xsl:if>
|
||||||
|
<xsl:if test="(@align = 'right')">
|
||||||
|
<xsl:text>text-align: right;</xsl:text>
|
||||||
|
</xsl:if>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
|
|
||||||
<xsl:template match="rtf:inline">
|
<xsl:template match="rtf:inline">
|
||||||
<xsl:variable name="num-attrs" select="count(@*)"/>
|
<xsl:variable name="num-attrs" select="count(@*)"/>
|
||||||
<xsl:choose>
|
<xsl:choose>
|
||||||
|
@ -192,12 +192,18 @@ class RTFInput(InputFormatPlugin):
|
|||||||
from calibre.ebooks.rtf2xml.ParseRtf import RtfInvalidCodeException
|
from calibre.ebooks.rtf2xml.ParseRtf import RtfInvalidCodeException
|
||||||
self.log = log
|
self.log = log
|
||||||
self.log('Converting RTF to XML...')
|
self.log('Converting RTF to XML...')
|
||||||
|
#Name of the preprocesssed RTF file
|
||||||
fname = self.preprocess(stream.name)
|
fname = self.preprocess(stream.name)
|
||||||
try:
|
try:
|
||||||
xml = self.generate_xml(fname)
|
xml = self.generate_xml(fname)
|
||||||
except RtfInvalidCodeException, e:
|
except RtfInvalidCodeException, e:
|
||||||
raise ValueError(_('This RTF file has a feature calibre does not '
|
raise ValueError(_('This RTF file has a feature calibre does not '
|
||||||
'support. Convert it to HTML first and then try it.\n%s')%e)
|
'support. Convert it to HTML first and then try it.\n%s')%e)
|
||||||
|
|
||||||
|
'''dataxml = open('dataxml.xml', 'w')
|
||||||
|
dataxml.write(xml)
|
||||||
|
dataxml.close'''
|
||||||
|
|
||||||
d = glob.glob(os.path.join('*_rtf_pict_dir', 'picts.rtf'))
|
d = glob.glob(os.path.join('*_rtf_pict_dir', 'picts.rtf'))
|
||||||
if d:
|
if d:
|
||||||
imap = {}
|
imap = {}
|
||||||
@ -205,6 +211,7 @@ class RTFInput(InputFormatPlugin):
|
|||||||
imap = self.extract_images(d[0])
|
imap = self.extract_images(d[0])
|
||||||
except:
|
except:
|
||||||
self.log.exception('Failed to extract images...')
|
self.log.exception('Failed to extract images...')
|
||||||
|
|
||||||
self.log('Parsing XML...')
|
self.log('Parsing XML...')
|
||||||
parser = etree.XMLParser(recover=True, no_network=True)
|
parser = etree.XMLParser(recover=True, no_network=True)
|
||||||
doc = etree.fromstring(xml, parser=parser)
|
doc = etree.fromstring(xml, parser=parser)
|
||||||
@ -214,10 +221,10 @@ class RTFInput(InputFormatPlugin):
|
|||||||
name = imap.get(num, None)
|
name = imap.get(num, None)
|
||||||
if name is not None:
|
if name is not None:
|
||||||
pict.set('num', name)
|
pict.set('num', name)
|
||||||
|
|
||||||
self.log('Converting XML to HTML...')
|
self.log('Converting XML to HTML...')
|
||||||
inline_class = InlineClass(self.log)
|
inline_class = InlineClass(self.log)
|
||||||
styledoc = etree.fromstring(P('templates/rtf.xsl', data=True))
|
styledoc = etree.fromstring(P('templates/rtf.xsl', data=True))
|
||||||
|
|
||||||
extensions = { ('calibre', 'inline-class') : inline_class }
|
extensions = { ('calibre', 'inline-class') : inline_class }
|
||||||
transform = etree.XSLT(styledoc, extensions=extensions)
|
transform = etree.XSLT(styledoc, extensions=extensions)
|
||||||
result = transform(doc)
|
result = transform(doc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user