summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pygments/formatters/img.py4
-rw-r--r--pygments/formatters/rtf.py12
-rw-r--r--tests/test_basic_api.py2
3 files changed, 9 insertions, 9 deletions
diff --git a/pygments/formatters/img.py b/pygments/formatters/img.py
index 4f9fb1b0..db5bee3b 100644
--- a/pygments/formatters/img.py
+++ b/pygments/formatters/img.py
@@ -295,6 +295,7 @@ class ImageFormatter(Formatter):
raise PilNotAvailable(
'Python Imaging Library is required for this formatter')
Formatter.__init__(self, **options)
+ self.encoding = 'latin1' # let pygments.format() do the right thing
# Read the style
self.styles = dict(self.style)
if self.style.background_color is None:
@@ -478,8 +479,7 @@ class ImageFormatter(Formatter):
draw = ImageDraw.Draw(im)
recth = im.size[-1]
rectw = self.image_pad + self.line_number_width - self.line_number_pad
- draw.rectangle([(0, 0),
- (rectw, recth)],
+ draw.rectangle([(0, 0), (rectw, recth)],
fill=self.line_number_bg)
draw.line([(rectw, 0), (rectw, recth)], fill=self.line_number_fg)
del draw
diff --git a/pygments/formatters/rtf.py b/pygments/formatters/rtf.py
index cf65a927..de768ac1 100644
--- a/pygments/formatters/rtf.py
+++ b/pygments/formatters/rtf.py
@@ -9,6 +9,8 @@
:license: BSD, see LICENSE for details.
"""
+from __future__ import unicode_literals
+
from pygments.formatter import Formatter
from pygments.util import get_int_opt, _surrogatepair
@@ -48,8 +50,6 @@ class RtfFormatter(Formatter):
aliases = ['rtf']
filenames = ['*.rtf']
- unicodeoutput = False
-
def __init__(self, **options):
"""
Additional options accepted:
@@ -87,18 +87,18 @@ class RtfFormatter(Formatter):
buf.append(str(c))
elif (2**7) <= cn < (2**16):
# single unicode escape sequence
- buf.append(r'{\u%d}' % cn)
+ buf.append('{\\u%d}' % cn)
elif (2**16) <= cn:
# RTF limits unicode to 16 bits.
# Force surrogate pairs
h,l = _surrogatepair(cn)
- buf.append(r'{\u%d}{\u%d}' % (h,l))
+ buf.append('{\\u%d}{\\u%d}' % (h,l))
return ''.join(buf).replace('\n', '\\par\n')
def format_unencoded(self, tokensource, outfile):
# rtf 1.8 header
- outfile.write(r'{\rtf1\ansi\uc0\deff0'
+ outfile.write('{\\rtf1\\ansi\\uc0\\deff0'
r'{\fonttbl{\f0\fmodern\fprq1\fcharset0%s;}}'
r'{\colortbl;' % (self.fontface and
' ' + self._escape(self.fontface) or
@@ -136,7 +136,7 @@ class RtfFormatter(Formatter):
if style['italic']:
buf.append(r'\i')
if style['underline']:
- buf.append(r'\ul')
+ buf.append('\\ul')
if style['border']:
buf.append(r'\chbrdr\chcfpat%d' %
color_mapping[style['border']])
diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py
index 6069f97c..37d170aa 100644
--- a/tests/test_basic_api.py
+++ b/tests/test_basic_api.py
@@ -217,7 +217,7 @@ def test_formatter_unicode_handling():
if formatter.name != 'Raw tokens':
out = format(tokens, inst)
if formatter.unicodeoutput:
- assert type(out) is text_type
+ assert type(out) is text_type, '%s: %r' % (formatter, out)
inst = formatter(encoding='utf-8')
out = format(tokens, inst)