mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Sync to trunk.
This commit is contained in:
commit
d410872282
@ -8,7 +8,8 @@ import os, re, sys, shutil, pprint
|
|||||||
from calibre.customize.conversion import OptionRecommendation, DummyReporter
|
from calibre.customize.conversion import OptionRecommendation, DummyReporter
|
||||||
from calibre.customize.ui import input_profiles, output_profiles, \
|
from calibre.customize.ui import input_profiles, output_profiles, \
|
||||||
plugin_for_input_format, plugin_for_output_format, \
|
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.ebooks.conversion.preprocess import HTMLPreProcessor
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
from calibre.ptempfile import PersistentTemporaryDirectory
|
||||||
from calibre import extract, walk
|
from calibre import extract, walk
|
||||||
@ -470,6 +471,14 @@ OptionRecommendation(name='language',
|
|||||||
self.log('Processing archive...')
|
self.log('Processing archive...')
|
||||||
tdir = PersistentTemporaryDirectory('_plumber')
|
tdir = PersistentTemporaryDirectory('_plumber')
|
||||||
self.input, input_fmt = self.unarchive(self.input, tdir)
|
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):
|
if os.path.exists(self.output) and os.path.isdir(self.output):
|
||||||
output_fmt = 'oeb'
|
output_fmt = 'oeb'
|
||||||
@ -842,6 +851,8 @@ OptionRecommendation(name='language',
|
|||||||
self.output_plugin.convert(self.oeb, self.output, self.input_plugin,
|
self.output_plugin.convert(self.oeb, self.output, self.input_plugin,
|
||||||
self.opts, self.log)
|
self.opts, self.log)
|
||||||
self.ui_reporter(1.)
|
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.log(self.output_fmt.upper(), 'output written to', self.output)
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ from urllib import unquote
|
|||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from math import ceil, floor
|
from math import ceil, floor
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from calibre.customize.ui import run_plugins_on_postprocess
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PIL import Image as PILImage
|
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.join(os.getcwd(), name)
|
||||||
oname = os.path.abspath(os.path.expanduser(oname))
|
oname = os.path.abspath(os.path.expanduser(oname))
|
||||||
conv.writeto(oname, lrs=options.lrs)
|
conv.writeto(oname, lrs=options.lrs)
|
||||||
run_plugins_on_postprocess(oname, 'lrf')
|
|
||||||
conv.cleanup()
|
conv.cleanup()
|
||||||
return oname
|
return oname
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace, \
|
|||||||
OEB_RASTER_IMAGES
|
OEB_RASTER_IMAGES
|
||||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||||
from calibre.ebooks.metadata import authors_to_string
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
|
from calibre.utils.filenames import ascii_text
|
||||||
|
|
||||||
TAGS = {
|
TAGS = {
|
||||||
'b': '\\b',
|
'b': '\\b',
|
||||||
@ -77,6 +78,22 @@ TODO:
|
|||||||
* Tables
|
* Tables
|
||||||
* Fonts
|
* 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):
|
class RTFMLizer(object):
|
||||||
|
|
||||||
def __init__(self, log):
|
def __init__(self, log):
|
||||||
@ -217,7 +234,7 @@ class RTFMLizer(object):
|
|||||||
|
|
||||||
# Proccess tags that contain text.
|
# Proccess tags that contain text.
|
||||||
if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '':
|
if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '':
|
||||||
text += '%s' % elem.text
|
text += txt2rtf(elem.text)
|
||||||
|
|
||||||
for item in elem:
|
for item in elem:
|
||||||
text += self.dump_text(item, stylizer, tag_stack)
|
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 hasattr(elem, 'tail') and elem.tail != None and elem.tail.strip() != '':
|
||||||
if 'block' in tag_stack:
|
if 'block' in tag_stack:
|
||||||
text += '%s ' % elem.tail
|
text += '%s ' % txt2rtf(elem.tail)
|
||||||
else:
|
else:
|
||||||
text += '{\\par \\pard \\hyphpar %s}' % elem.tail
|
text += '{\\par \\pard \\hyphpar %s}' % txt2rtf(elem.tail)
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user