diff options
Diffstat (limited to 'pygments/formatters/rtf.py')
-rw-r--r-- | pygments/formatters/rtf.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/pygments/formatters/rtf.py b/pygments/formatters/rtf.py index 83414c58..4b03f8a7 100644 --- a/pygments/formatters/rtf.py +++ b/pygments/formatters/rtf.py @@ -5,11 +5,12 @@ A formatter that generates RTF files. - :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ from pygments.formatter import Formatter +from pygments.util import get_int_opt __all__ = ['RtfFormatter'] @@ -21,7 +22,7 @@ class RtfFormatter(Formatter): documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft® Word® documents. - *New in Pygments 0.6.* + .. versionadded:: 0.6 Additional options accepted: @@ -32,6 +33,12 @@ class RtfFormatter(Formatter): `fontface` The used font famliy, for example ``Bitstream Vera Sans``. Defaults to some generic font which is supposed to have fixed width. + + `fontsize` + Size of the font used. Size is specified in half points. The + default is 24 half-points, giving a size 12 font. + + .. versionadded:: 2.0 """ name = 'RTF' aliases = ['rtf'] @@ -49,9 +56,11 @@ class RtfFormatter(Formatter): specification claims that ``\fmodern`` are "Fixed-pitch serif and sans serif fonts". Hope every RTF implementation thinks the same about modern... + """ Formatter.__init__(self, **options) self.fontface = options.get('fontface') or '' + self.fontsize = get_int_opt(options, 'fontsize', 0) def _escape(self, text): return text.replace('\\', '\\\\') \ @@ -73,11 +82,11 @@ class RtfFormatter(Formatter): buf = [] for c in text: if ord(c) > 128: - ansic = c.encode(encoding, 'ignore') or '?' - if ord(ansic) > 128: + ansic = c.encode(encoding, 'ignore') + if ansic and ord(ansic) > 128: ansic = '\\\'%x' % ord(ansic) else: - ansic = c + ansic = '?' buf.append(r'\ud{\u%d%s}' % (ord(c), ansic)) else: buf.append(str(c)) @@ -106,6 +115,8 @@ class RtfFormatter(Formatter): )) offset += 1 outfile.write(r'}\f0') + if self.fontsize: + outfile.write(r'\fs%d' % (self.fontsize)) # highlight stream for ttype, value in tokensource: |