summaryrefslogtreecommitdiff
path: root/pygments/formatters/rtf.py
diff options
context:
space:
mode:
authorgbrandl <devnull@localhost>2009-03-31 10:26:55 -0500
committergbrandl <devnull@localhost>2009-03-31 10:26:55 -0500
commit7b95efab48d9ec79e995bf4d6db10fd049e3395a (patch)
tree48fc9b840dab83976a85af85d1c705dbaa051a0b /pygments/formatters/rtf.py
parentf12c878ed096137c91658a0f62f0070e08c2afea (diff)
downloadpygments-7b95efab48d9ec79e995bf4d6db10fd049e3395a.tar.gz
Port Pygments to Python 3.1.
Diffstat (limited to 'pygments/formatters/rtf.py')
-rw-r--r--pygments/formatters/rtf.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/pygments/formatters/rtf.py b/pygments/formatters/rtf.py
index 1f1023d0..501ef424 100644
--- a/pygments/formatters/rtf.py
+++ b/pygments/formatters/rtf.py
@@ -52,8 +52,6 @@ class RtfFormatter(Formatter):
"""
Formatter.__init__(self, **options)
self.fontface = options.get('fontface') or ''
- if self.encoding in ('utf-8', 'utf-16', 'utf-32'):
- self.encoding = None
def _escape(self, text):
return text.replace('\\', '\\\\') \
@@ -67,7 +65,10 @@ class RtfFormatter(Formatter):
# escape text
text = self._escape(text)
- encoding = self.encoding or 'iso-8859-15'
+ if self.encoding in ('utf-8', 'utf-16', 'utf-32'):
+ encoding = 'iso-8859-15'
+ else:
+ encoding = self.encoding or 'iso-8859-15'
buf = []
for c in text:
@@ -75,13 +76,15 @@ class RtfFormatter(Formatter):
ansic = c.encode(encoding, 'ignore') or '?'
if ord(ansic) > 128:
ansic = '\\\'%x' % ord(ansic)
+ else:
+ ansic = c
buf.append(r'\ud{\u%d%s}' % (ord(c), ansic))
else:
buf.append(str(c))
return ''.join(buf).replace('\n', '\\par\n')
- def format(self, tokensource, outfile):
+ def format_unencoded(self, tokensource, outfile):
# rtf 1.8 header
outfile.write(r'{\rtf1\ansi\deff0'
r'{\fonttbl{\f0\fmodern\fprq1\fcharset0%s;}}'