mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Switch to rtf2xml from unrtf as the RTF conversion engine.
This commit is contained in:
parent
9fe7e54bcf
commit
d6bfea6684
3
Makefile
3
Makefile
@ -6,6 +6,9 @@ clean :
|
||||
gui2 :
|
||||
cd src/libprs500/gui2 && python make.py
|
||||
|
||||
test : gui2
|
||||
cd src/libprs500/gui2 && python make.py test
|
||||
|
||||
translations :
|
||||
cd src/libprs500 && python translations/__init__.py
|
||||
|
||||
|
@ -233,8 +233,9 @@ setup(
|
||||
'argv_emulation' : True,
|
||||
'iconfile' : 'icons/library.icns',
|
||||
'frameworks': ['libusb.dylib', 'libunrar.dylib'],
|
||||
'includes' : ['sip', 'pkg_resources', 'PyQt4.QtSvg', 'mechanize', 'ClientForm'],
|
||||
'packages' : ['PIL', 'Authorization',],
|
||||
'includes' : ['sip', 'pkg_resources', 'PyQt4.QtSvg',
|
||||
'mechanize', 'ClientForm'],
|
||||
'packages' : ['PIL', 'Authorization', 'rtf2xml', 'lxml'],
|
||||
'excludes' : ['pydoc'],
|
||||
'plist' : { 'CFBundleGetInfoString' : '''libprs500, an E-book management application.'''
|
||||
''' Visit http://libprs500.kovidgoyal.net for details.''',
|
||||
|
@ -30,6 +30,15 @@ iswindows = 'win32' in sys.platform.lower()
|
||||
isosx = 'darwin' in sys.platform.lower()
|
||||
islinux = not(iswindows or isosx)
|
||||
|
||||
def osx_version():
|
||||
if isosx:
|
||||
import platform
|
||||
src = platform.mac_ver()[0]
|
||||
m = re.match(r'(\d+)\.(\d+)\.(\d+)', src)
|
||||
if m:
|
||||
return int(m.group(1)), int(m.group(2)), int(m.group(3))
|
||||
|
||||
|
||||
# Default translation is NOOP
|
||||
import __builtin__
|
||||
__builtin__.__dict__['_'] = lambda s: s
|
||||
|
@ -20,16 +20,20 @@ from libprs500.ebooks.lrf.html.convert_from import process_file as html_process_
|
||||
from libprs500.ebooks import ConversionError
|
||||
from libprs500 import isosx, setup_cli_handlers, __appname__
|
||||
from libprs500.libwand import convert, WandException
|
||||
from libprs500.ebooks.BeautifulSoup import BeautifulStoneSoup
|
||||
from libprs500.ebooks.lrf.rtf.xsl import xhtml
|
||||
|
||||
UNRTF = 'unrtf'
|
||||
if isosx and hasattr(sys, 'frameworks_dir'):
|
||||
UNRTF = os.path.join(getattr(sys, 'frameworks_dir'), UNRTF)
|
||||
|
||||
def option_parser():
|
||||
return lrf_option_parser(
|
||||
parser = lrf_option_parser(
|
||||
'''Usage: %prog [options] mybook.rtf\n\n'''
|
||||
'''%prog converts mybook.rtf to mybook.lrf'''
|
||||
)
|
||||
parser.add_option('--keep-intermediate-files', action='store_true', default=False)
|
||||
return parser
|
||||
|
||||
def convert_images(html, logger):
|
||||
wmfs = glob.glob('*.wmf') + glob.glob('*.WMF')
|
||||
@ -72,14 +76,15 @@ def generate_html(rtfpath, logger):
|
||||
def process_file(path, options, logger=None):
|
||||
if logger is None:
|
||||
level = logging.DEBUG if options.verbose else logging.INFO
|
||||
logger = logging.getLogger('pdf2lrf')
|
||||
logger = logging.getLogger('rtf2lrf')
|
||||
setup_cli_handlers(logger, level)
|
||||
rtf = os.path.abspath(os.path.expanduser(path))
|
||||
f = open(rtf, 'rb')
|
||||
mi = get_metadata(f, 'rtf')
|
||||
f.close()
|
||||
html = generate_html(rtf, logger)
|
||||
html = generate_html2(rtf, logger)
|
||||
tdir = os.path.dirname(html)
|
||||
cwd = os.getcwdu()
|
||||
try:
|
||||
if not options.output:
|
||||
ext = '.lrs' if options.lrs else '.lrf'
|
||||
@ -95,9 +100,14 @@ def process_file(path, options, logger=None):
|
||||
options.category = mi.category
|
||||
if (not options.freetext or options.freetext == 'Unknown') and mi.comments:
|
||||
options.freetext = mi.comments
|
||||
os.chdir(tdir)
|
||||
html_process_file(html, options, logger)
|
||||
finally:
|
||||
shutil.rmtree(tdir)
|
||||
os.chdir(cwd)
|
||||
if options.keep_intermediate_files:
|
||||
logger.debug('Intermediate files in '+ tdir)
|
||||
else:
|
||||
shutil.rmtree(tdir)
|
||||
|
||||
def main(args=sys.argv, logger=None):
|
||||
parser = option_parser()
|
||||
@ -110,9 +120,89 @@ def main(args=sys.argv, logger=None):
|
||||
process_file(args[1], options, logger)
|
||||
return 0
|
||||
|
||||
|
||||
def generate_xml(rtfpath):
|
||||
from rtf2xml.ParseRtf import ParseRtf
|
||||
tdir = tempfile.mkdtemp(prefix=__appname__+'_')
|
||||
ofile = os.path.join(tdir, 'index.xml')
|
||||
cwd = os.getcwdu()
|
||||
os.chdir(tdir)
|
||||
try:
|
||||
parser = ParseRtf(
|
||||
in_file = rtfpath,
|
||||
out_file = ofile,
|
||||
# Convert symbol fonts to unicode equivelents. Default
|
||||
# is 1
|
||||
convert_symbol = 1,
|
||||
|
||||
# Convert Zapf fonts to unicode equivelents. Default
|
||||
# is 1.
|
||||
convert_zapf = 1,
|
||||
|
||||
# Convert Wingding fonts to unicode equivelents.
|
||||
# Default is 1.
|
||||
convert_wingdings = 1,
|
||||
|
||||
# Convert RTF caps to real caps.
|
||||
# Default is 1.
|
||||
convert_caps = 1,
|
||||
|
||||
# Indent resulting XML.
|
||||
# Default is 0 (no indent).
|
||||
indent = 1,
|
||||
|
||||
# Form lists from RTF. Default is 1.
|
||||
form_lists = 1,
|
||||
|
||||
# Convert headings to sections. Default is 0.
|
||||
headings_to_sections = 1,
|
||||
|
||||
# Group paragraphs with the same style name. Default is 1.
|
||||
group_styles = 1,
|
||||
|
||||
# Group borders. Default is 1.
|
||||
group_borders = 1,
|
||||
|
||||
# Write or do not write paragraphs. Default is 0.
|
||||
empty_paragraphs = 0,
|
||||
)
|
||||
parser.parse_rtf()
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
return ofile
|
||||
|
||||
|
||||
def generate_html2(rtfpath, logger):
|
||||
from lxml import etree
|
||||
logger.info('Converting RTF to XML...')
|
||||
xml = generate_xml(rtfpath)
|
||||
tdir = os.path.dirname(xml)
|
||||
cwd = os.getcwdu()
|
||||
os.chdir(tdir)
|
||||
try:
|
||||
logger.info('Parsing XML...')
|
||||
parser = etree.XMLParser(recover=True, no_network=True)
|
||||
try:
|
||||
doc = etree.parse(xml, parser)
|
||||
except:
|
||||
raise
|
||||
logger.info('Parsing failed. Trying to clean up XML...')
|
||||
soup = BeautifulStoneSoup(open(xml, 'rb').read())
|
||||
doc = etree.fromstring(str(soup))
|
||||
logger.info('Converting XML to HTML...')
|
||||
styledoc = etree.fromstring(xhtml)
|
||||
|
||||
transform = etree.XSLT(styledoc)
|
||||
result = transform(doc)
|
||||
tdir = os.path.dirname(xml)
|
||||
html = os.path.join(tdir, 'index.html')
|
||||
f = open(html, 'wb')
|
||||
f.write(transform.tostring(result))
|
||||
f.close()
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
return html
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
||||
sys.exit(main())
|
||||
|
538
src/libprs500/ebooks/lrf/rtf/xsl.py
Normal file
538
src/libprs500/ebooks/lrf/rtf/xsl.py
Normal file
@ -0,0 +1,538 @@
|
||||
#########################################################################
|
||||
# #
|
||||
# #
|
||||
# copyright 2002 Paul Henry Tremblay #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
|
||||
# General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with this program; if not, write to the Free Software #
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA #
|
||||
# 02111-1307 USA #
|
||||
# #
|
||||
# #
|
||||
#########################################################################
|
||||
|
||||
xhtml = '''\
|
||||
<?xml version="1.0"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns:rtf="http://rtf2xml.sourceforge.net/"
|
||||
exclude-result-prefixes="rtf"
|
||||
>
|
||||
|
||||
<xsl:template match = "rtf:para">
|
||||
<xsl:choose>
|
||||
<xsl:when test = "parent::rtf:paragraph-definition[@name='heading 1']|
|
||||
parent::rtf:paragraph-definition[@name='heading 2']|
|
||||
parent::rtf:paragraph-definition[@name='heading 3']|
|
||||
parent::rtf:paragraph-definition[@name='heading 4']|
|
||||
parent::rtf:paragraph-definition[@name='heading 5']|
|
||||
parent::rtf:paragraph-definition[@name='heading 6']|
|
||||
parent::rtf:paragraph-definition[@name='heading 7']|
|
||||
parent::rtf:paragraph-definition[@name='heading 8']|
|
||||
parent::rtf:paragraph-definition[@name='heading 9']
|
||||
|
||||
">
|
||||
<xsl:variable name="head-number" select="substring(parent::rtf:paragraph-definition/@name, 9)"/>
|
||||
<xsl:element name="h{$head-number}">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:call-template name = "para"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:style-group">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:paragraph-definition">
|
||||
<xsl:choose>
|
||||
<xsl:when test = "parent::rtf:paragraph-definition[@name='heading 1']|
|
||||
parent::rtf:paragraph-definition[@name='heading 2']|
|
||||
parent::rtf:paragraph-definition[@name='heading 3']|
|
||||
parent::rtf:paragraph-definition[@name='heading 4']|
|
||||
parent::rtf:paragraph-definition[@name='heading 5']|
|
||||
parent::rtf:paragraph-definition[@name='heading 6']|
|
||||
parent::rtf:paragraph-definition[@name='heading 7']|
|
||||
parent::rtf:paragraph-definition[@name='heading 8']|
|
||||
parent::rtf:paragraph-definition[@name='heading 9']
|
||||
|
||||
">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:element name="div">
|
||||
<xsl:attribute name="class">
|
||||
<xsl:value-of select="@style-number"/>
|
||||
</xsl:attribute>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name = "para">
|
||||
<xsl:if test = "normalize-space(.) or child::*">
|
||||
<xsl:element name = "p">
|
||||
<xsl:call-template name = "para-content"/>
|
||||
</xsl:element>
|
||||
</xsl:if>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name = "para_off">
|
||||
<xsl:if test = "normalize-space(.) or child::*">
|
||||
<xsl:element name = "p">
|
||||
<xsl:attribute name = "class">
|
||||
<xsl:value-of select = "../@style-number"/>
|
||||
</xsl:attribute>
|
||||
<xsl:call-template name = "para-content"/>
|
||||
</xsl:element>
|
||||
</xsl:if>
|
||||
</xsl:template>
|
||||
|
||||
|
||||
<xsl:template name = "para-content">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name = "para-content_off">
|
||||
<xsl:choose>
|
||||
<xsl:when test = "@italics = 'true' ">
|
||||
<emph rend = "paragraph-emph-italics">
|
||||
<xsl:apply-templates/>
|
||||
</emph>
|
||||
</xsl:when>
|
||||
<xsl:when test = "@bold = 'true' ">
|
||||
<emph rend = "paragraph-emph-bold">
|
||||
<xsl:apply-templates/>
|
||||
</emph>
|
||||
</xsl:when>
|
||||
<xsl:when test = "@underlined">
|
||||
<emph rend = "paragraph-emph-underlined">
|
||||
<xsl:apply-templates/>
|
||||
</emph>
|
||||
</xsl:when>
|
||||
<xsl:when test = "(@strike-through = 'true')
|
||||
or (@double-strike-through = 'true')
|
||||
or (@emboss = 'true')
|
||||
or (@engrave = 'true')
|
||||
or (@small-caps = 'true')
|
||||
or (@shadow = 'true')
|
||||
or (@hidden = 'true')
|
||||
or (@outline = 'true')
|
||||
|
||||
">
|
||||
<emph rend = "paragraph-emph">
|
||||
<xsl:apply-templates/>
|
||||
</emph>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="make-header">
|
||||
<head>
|
||||
<xsl:element name="meta">
|
||||
<xsl:attribute name="name">
|
||||
<xsl:text>generator</xsl:text>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="content">
|
||||
<xsl:text>http://rtf2xml.sourceforge.net/</xsl:text>
|
||||
</xsl:attribute>
|
||||
</xsl:element>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="/rtf:doc/rtf:preamble/rtf:doc-information">
|
||||
<xsl:apply-templates select="/rtf:doc/rtf:preamble/rtf:doc-information" mode="header"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:call-template name="html-head"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</head>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:doc-information"/>
|
||||
|
||||
<xsl:template match="rtf:doc-information" mode="header">
|
||||
<link rel="stylesheet" type="text/css" href="styles.css"/>
|
||||
<xsl:if test="not(rtf:title)">
|
||||
<title>unamed</title>
|
||||
</xsl:if>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:creation-time|rtf:doc-notes|rtf:author|rtf:revision-time">
|
||||
<xsl:element name="meta">
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="name(.)"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="content">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:attribute>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:creation-time|rtf:revision-time">
|
||||
<xsl:element name="meta">
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="name(.)"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="content">
|
||||
<xsl:value-of select="@year"/>
|
||||
<xsl:text>-</xsl:text>
|
||||
<xsl:value-of select="@month"/>
|
||||
<xsl:text>-</xsl:text>
|
||||
<xsl:value-of select="@day"/>
|
||||
</xsl:attribute>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:operator|rtf:editing-time|rtf:number-of-pages|rtf:number-of-words|rtf:number-of-characters"/>
|
||||
|
||||
|
||||
<xsl:template match="rtf:title">
|
||||
<xsl:element name="title">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
|
||||
<xsl:template name="html-head">
|
||||
<title>unnamed</title>
|
||||
<link rel="stylesheet" type="text/css" href="styles.css"/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="make-css-stylesheet">
|
||||
<xsl:document href="styles.css" method="text">
|
||||
<xsl:for-each select="//rtf:paragraph-definition">
|
||||
<xsl:if test = "generate-id(.) = generate-id(key('style-types', @style-number))">
|
||||
<xsl:text>div.</xsl:text>
|
||||
<xsl:value-of select="@style-number"/>
|
||||
<xsl:text>{</xsl:text>
|
||||
<xsl:call-template name="parse-styles-attrs"/>
|
||||
<xsl:text>}
</xsl:text>
|
||||
</xsl:if>
|
||||
</xsl:for-each>
|
||||
<xsl:text>span.italic{font-style:italic}
</xsl:text>
|
||||
<xsl:text>span.no-italic{font-style:normal}
</xsl:text>
|
||||
<xsl:text>span.bold{font-weight:bold}
</xsl:text>
|
||||
<xsl:text>span.no-bold{font-weight:normal}
</xsl:text>
|
||||
<xsl:text>span.underline{text-decoration:underline}
</xsl:text>
|
||||
<xsl:text>span.no-underline{text-decoration:none}
</xsl:text>
|
||||
<xsl:text>span.italic-bold{font-style:italic;font-weight:bold}
</xsl:text>
|
||||
<xsl:text>span.italic-underline{font-style:italic;text-decoration:underline}
</xsl:text>
|
||||
<xsl:text>span.bold-underline{font-weight:bold;text-decoration:underline}
</xsl:text>
|
||||
<xsl:for-each select="//rtf:inline">
|
||||
<xsl:call-template name="parse-inline"/>
|
||||
</xsl:for-each>
|
||||
</xsl:document>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="parse-styles-attrs">
|
||||
<xsl:text>position:relative;</xsl:text>
|
||||
<xsl:if test="@space-before">
|
||||
<xsl:text>padding-top:</xsl:text>
|
||||
<xsl:value-of select="@space-before"/>
|
||||
<xsl:text>pt;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@space-after">
|
||||
<xsl:text>padding-bottom:</xsl:text>
|
||||
<xsl:value-of select="@space-after"/>
|
||||
<xsl:text>pt;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@left-indent">
|
||||
<xsl:text>padding-left:</xsl:text>
|
||||
<xsl:value-of select="@left-indent"/>
|
||||
<xsl:text>pt;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@right-indent">
|
||||
<xsl:text>padding-right:</xsl:text>
|
||||
<xsl:value-of select="@right-indent"/>
|
||||
<xsl:text>pt;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@first-line-indent">
|
||||
<xsl:text>text-indent:</xsl:text>
|
||||
<xsl:value-of select="@first-line-indent"/>
|
||||
<xsl:text>pt;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@bold='true'">
|
||||
<xsl:text>font-weight:</xsl:text>
|
||||
<xsl:value-of select="'bold'"/>
|
||||
<xsl:text>;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@italics='true'">
|
||||
<xsl:text>font-style:</xsl:text>
|
||||
<xsl:value-of select="'italic'"/>
|
||||
<xsl:text>;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@underline and @underline != 'false'">
|
||||
<xsl:text>text-decoration:underline</xsl:text>
|
||||
<xsl:text>;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@line-spacing">
|
||||
<xsl:text>line-height:</xsl:text>
|
||||
<xsl:value-of select="@line-height"/>
|
||||
<xsl:text>pt;</xsl:text>
|
||||
</xsl:if>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="parse-inline">
|
||||
<xsl:variable name="num-attrs" select="count(@*)"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$num-attrs = 1 and @italics"/>
|
||||
<xsl:when test="$num-attrs = 1 and @bold"/>
|
||||
<xsl:when test="$num-attrs = 1 and @underline"/>
|
||||
<xsl:when test="$num-attrs = 2 and @italics and @bold"/>
|
||||
<xsl:when test="$num-attrs = 2 and @italcs and @underline"/>
|
||||
<xsl:when test="$num-attrs = 2 and @bold and @underline"/>
|
||||
<xsl:otherwise>
|
||||
<xsl:text>span.</xsl:text>
|
||||
<xsl:value-of select="generate-id(.)"/>
|
||||
<xsl:text>{</xsl:text>
|
||||
<xsl:if test="@italics = 'true'">
|
||||
<xsl:text>font-style:italic;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@italics = 'false'">
|
||||
<xsl:text>font-style:normal;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@bold = 'true'">
|
||||
<xsl:text>font-weight:bold;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@bold = 'false'">
|
||||
<xsl:text>font-weight:normal;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@underline and @underline != 'false'">
|
||||
<xsl:text>text-decoration:underline;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@underline= 'false'">
|
||||
<xsl:text>text-decoration:none;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@strike-through = 'true'">
|
||||
<xsl:text>text-decoration:line-through;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@strike-through = 'false'">
|
||||
<xsl:text>text-decoration:none;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="@font-size">
|
||||
<xsl:text>font-size:</xsl:text>
|
||||
<xsl:value-of select="@font-size"/>
|
||||
<xsl:text>pt;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:text>}</xsl:text>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:inline">
|
||||
<xsl:variable name="num-attrs" select="count(@*)"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="@footnote-marker">
|
||||
<xsl:text>[</xsl:text>
|
||||
<xsl:value-of select="count(preceding::rtf:footnote) + 1"/>
|
||||
<xsl:text>]</xsl:text>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:element name="span">
|
||||
<xsl:attribute name="class">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$num-attrs=1 and @italics='true'">
|
||||
<xsl:text>italic</xsl:text>
|
||||
</xsl:when>
|
||||
<xsl:when test="$num-attrs=1 and @italics='false'">
|
||||
<xsl:text>no-italic</xsl:text>
|
||||
</xsl:when>
|
||||
<xsl:when test="$num-attrs=1 and @bold='true'">
|
||||
<xsl:text>bold</xsl:text>
|
||||
</xsl:when>
|
||||
<xsl:when test="$num-attrs=1 and @bold='true'">
|
||||
<xsl:text>bold</xsl:text>
|
||||
</xsl:when>
|
||||
<xsl:when test="$num-attrs=1 and @bold='false'">
|
||||
<xsl:text>no-bold</xsl:text>
|
||||
</xsl:when>
|
||||
<xsl:when test="$num-attrs=1 and @underlined">
|
||||
<xsl:choose>
|
||||
<xsl:when test="not(@underlined='false')">
|
||||
<xsl:text>underline</xsl:text>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:text>no-underline</xsl:text>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:when>
|
||||
<xsl:when test="$num-attrs=2 and @bold='true' and @italics='true'">
|
||||
<xsl:text>italic-bold</xsl:text>
|
||||
</xsl:when>
|
||||
<xsl:when test="$num-attrs=2 and @italics='true' and @underline and @underline != 'false'">
|
||||
<xsl:text>italic-underline</xsl:text>
|
||||
</xsl:when>
|
||||
<xsl:when test="$num-attrs=2 and @bold='true' and @underline and @underline != 'false'">
|
||||
<xsl:text>bold-underline</xsl:text>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="generate-id(.)"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:attribute>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:footnote"/>
|
||||
|
||||
<xsl:template match="rtf:footnote" mode="bottom">
|
||||
<xsl:element name="div">
|
||||
<xsl:attribute name="class">
|
||||
<xsl:text>footnote</xsl:text>
|
||||
</xsl:attribute>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:list[@list-type='unordered']">
|
||||
<xsl:element name="ul">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:list[@list-type='ordered']">
|
||||
<xsl:element name="ol">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:item">
|
||||
<xsl:element name="li">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:item/rtf:style-group/rtf:paragraph-definition/rtf:para" priority="2">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:table">
|
||||
<xsl:element name="table">
|
||||
<xsl:attribute name="id">
|
||||
<xsl:value-of select="generate-id(.)"/>
|
||||
</xsl:attribute>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:row">
|
||||
<xsl:element name="row">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:cell">
|
||||
<xsl:element name="cell">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<!--
|
||||
<xsl:include href="blocks.xsl"/>
|
||||
<xsl:include href="fields.xsl"/>
|
||||
-->
|
||||
|
||||
|
||||
|
||||
|
||||
<xsl:output method = "xml"/>
|
||||
|
||||
<xsl:key name="style-types" match="rtf:paragraph-definition" use="@style-number"/>
|
||||
|
||||
|
||||
<xsl:variable name = "delete-list-text">true</xsl:variable>
|
||||
<xsl:variable name = "delete-field-blocks">true</xsl:variable>
|
||||
<xsl:variable name = "delete-annotation">false</xsl:variable>
|
||||
|
||||
<xsl:template match="/">
|
||||
<xsl:call-template name="make-css-stylesheet"/>
|
||||
<html>
|
||||
<xsl:call-template name="make-header"/>
|
||||
<xsl:apply-templates/>
|
||||
</html>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:doc">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:preamble">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:page-break">
|
||||
<xsl:element name="br">
|
||||
<xsl:attribute name="style">page-break-after:always</xsl:attribute>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:rtf-definition|rtf:font-table|rtf:color-table|rtf:style-table|rtf:page-definition|rtf:list-table|rtf:override-table|rtf:override-list|rtf:list-text"/>
|
||||
|
||||
<xsl:template match="rtf:body">
|
||||
<xsl:element name="body">
|
||||
<xsl:apply-templates/>
|
||||
<xsl:if test = "//rtf:footnote">
|
||||
<hr/>
|
||||
</xsl:if>
|
||||
<xsl:for-each select="//rtf:footnote">
|
||||
<xsl:apply-templates select="." mode="bottom"/>
|
||||
</xsl:for-each>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:section">
|
||||
<xsl:element name="div">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match = "rtf:field-block">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match = "rtf:field[@type='hyperlink']">
|
||||
<xsl:element name ="a">
|
||||
<xsl:attribute name = "href">
|
||||
<xsl:value-of select = "@link"/>
|
||||
</xsl:attribute>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:element>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match = "rtf:field">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rtf:pict" />
|
||||
|
||||
<xsl:template match="*">
|
||||
<xsl:message>
|
||||
<xsl:text>no match for element: "</xsl:text>
|
||||
<xsl:value-of select="name(.)"/>
|
||||
<xsl:text>" 
</xsl:text>
|
||||
</xsl:message>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
'''
|
@ -25,7 +25,7 @@ from libprs500.gui2 import qstring_to_unicode, error_dialog, \
|
||||
from libprs500.gui2.widgets import FontFamilyModel
|
||||
from libprs500.ebooks.lrf import option_parser
|
||||
from libprs500.ptempfile import PersistentTemporaryFile
|
||||
from libprs500 import __appname__
|
||||
from libprs500 import __appname__, osx_version
|
||||
|
||||
font_family_model = None
|
||||
|
||||
@ -101,6 +101,16 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
|
||||
|
||||
if self.selected_format:
|
||||
self.setWindowTitle(_('Convert %s to LRF')%(self.selected_format,))
|
||||
if self.selected_format == 'RTF':
|
||||
try:
|
||||
major, minor = osx_version()[:2]
|
||||
if False and (major == 10 and minor > 4) or major > 10:
|
||||
self.selected_format = None
|
||||
d = error_dialog(self, _('RTF conversion not supported'),
|
||||
_('Conversion of RTF files is not supported on OS X Leopard and higher. This is because unrtf, the underlying program does not work. If you are willing to port unrtf to Leopard, contact me.'))
|
||||
d.exec_()
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
self.setWindowTitle(_('Set conversion defaults'))
|
||||
|
||||
|
@ -92,7 +92,7 @@ class Distribution(object):
|
||||
self.command = cmd.strip()
|
||||
if os == 'debian':
|
||||
self.command += '\n'+prefix + 'cp -R /usr/share/pycentral/fonttools/site-packages/FontTools* /usr/lib/python2.5/site-packages/'
|
||||
self.command += '\n'+prefix+'easy_install -U TTFQuery libprs500 \nlibprs500_postinstall'
|
||||
self.command += '\n'+prefix+'easy_install -U TTFQuery lxml libprs500 \n'+prefix+'easy_install -f http://sourceforge.net/project/showfiles.php?group_id=68617 rtf2xml\n'+prefix+'libprs500_postinstall'
|
||||
try:
|
||||
self.manual = Markup(self.MANUAL_MAP[os])
|
||||
except KeyError:
|
||||
|
@ -457,7 +457,8 @@ setup(
|
||||
'dist_dir' : PY2EXE_DIR,
|
||||
'includes' : ['sip', 'pkg_resources', 'PyQt4.QtSvg',
|
||||
'mechanize', 'ClientForm', 'wmi',
|
||||
'win32file', 'pythoncom'],
|
||||
'win32file', 'pythoncom', 'rtf2xml',
|
||||
'lxml', 'lxml._elementpath'],
|
||||
'packages' : ['PIL'],
|
||||
'excludes' : ["Tkconstants", "Tkinter", "tcl",
|
||||
"_imagingtk", "ImageTk", "FixTk",
|
||||
|
Loading…
x
Reference in New Issue
Block a user