Sync to trunk.

This commit is contained in:
John Schember 2010-01-07 18:24:24 -05:00
commit d410872282
3 changed files with 32 additions and 6 deletions

View File

@ -8,7 +8,8 @@ import os, re, sys, shutil, pprint
from calibre.customize.conversion import OptionRecommendation, DummyReporter
from calibre.customize.ui import input_profiles, output_profiles, \
plugin_for_input_format, plugin_for_output_format, \
available_input_formats, available_output_formats
available_input_formats, available_output_formats, \
run_plugins_on_preprocess, run_plugins_on_postprocess
from calibre.ebooks.conversion.preprocess import HTMLPreProcessor
from calibre.ptempfile import PersistentTemporaryDirectory
from calibre import extract, walk
@ -470,6 +471,14 @@ OptionRecommendation(name='language',
self.log('Processing archive...')
tdir = PersistentTemporaryDirectory('_plumber')
self.input, input_fmt = self.unarchive(self.input, tdir)
if os.access(self.input, os.R_OK):
nfp = run_plugins_on_preprocess(self.input, input_fmt)
if nfp != self.input:
self.input = nfp
input_fmt = os.path.splitext(self.input)[1]
if not input_fmt:
raise ValueError('Input file must have an extension')
input_fmt = input_fmt[1:].lower()
if os.path.exists(self.output) and os.path.isdir(self.output):
output_fmt = 'oeb'
@ -842,6 +851,8 @@ OptionRecommendation(name='language',
self.output_plugin.convert(self.oeb, self.output, self.input_plugin,
self.opts, self.log)
self.ui_reporter(1.)
run_plugins_on_postprocess(self.output, self.output_fmt)
self.log(self.output_fmt.upper(), 'output written to', self.output)
self.flush()

View File

@ -12,7 +12,6 @@ from urllib import unquote
from urlparse import urlparse
from math import ceil, floor
from functools import partial
from calibre.customize.ui import run_plugins_on_postprocess
try:
from PIL import Image as PILImage
@ -1938,7 +1937,6 @@ def process_file(path, options, logger):
oname = os.path.join(os.getcwd(), name)
oname = os.path.abspath(os.path.expanduser(oname))
conv.writeto(oname, lrs=options.lrs)
run_plugins_on_postprocess(oname, 'lrf')
conv.cleanup()
return oname

View File

@ -23,6 +23,7 @@ from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace, \
OEB_RASTER_IMAGES
from calibre.ebooks.oeb.stylizer import Stylizer
from calibre.ebooks.metadata import authors_to_string
from calibre.utils.filenames import ascii_text
TAGS = {
'b': '\\b',
@ -77,6 +78,22 @@ TODO:
* Tables
* Fonts
'''
def txt2rtf(text):
if not isinstance(text, unicode):
return text
buf = cStringIO.StringIO()
for x in text:
val = ord(x)
if val <= 127:
buf.write(x)
else:
repl = ascii_text(x)
c = r'\uc{2}\u{0:d}{1}'.format(val, repl, len(repl))
buf.write(c)
return buf.getvalue()
class RTFMLizer(object):
def __init__(self, log):
@ -217,7 +234,7 @@ class RTFMLizer(object):
# Proccess tags that contain text.
if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '':
text += '%s' % elem.text
text += txt2rtf(elem.text)
for item in elem:
text += self.dump_text(item, stylizer, tag_stack)
@ -233,8 +250,8 @@ class RTFMLizer(object):
if hasattr(elem, 'tail') and elem.tail != None and elem.tail.strip() != '':
if 'block' in tag_stack:
text += '%s ' % elem.tail
text += '%s ' % txt2rtf(elem.tail)
else:
text += '{\\par \\pard \\hyphpar %s}' % elem.tail
text += '{\\par \\pard \\hyphpar %s}' % txt2rtf(elem.tail)
return text