Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
MoinMoin.support.pygments.formatters.rtf.RtfFormatter Class Reference
Inheritance diagram for MoinMoin.support.pygments.formatters.rtf.RtfFormatter:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.pygments.formatters.rtf.RtfFormatter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def format_unencoded

Public Attributes

 fontface

Static Public Attributes

string name = 'RTF'
list aliases = ['rtf']
list filenames = ['*.rtf']
 unicodeoutput = False

Private Member Functions

def _escape
def _escape_text

Detailed Description

Format tokens as RTF markup. This formatter automatically outputs full RTF
documents with color information and other useful stuff. Perfect for Copy and
Paste into Microsoft® Word® documents.

*New in Pygments 0.6.*

Additional options accepted:

`style`
    The style to use, can be a string or a Style subclass (default:
    ``'default'``).

`fontface`
    The used font famliy, for example ``Bitstream Vera Sans``. Defaults to
    some generic font which is supposed to have fixed width.

Definition at line 18 of file rtf.py.


Constructor & Destructor Documentation

Additional options accepted:

``fontface``
    Name of the font used. Could for example be ``'Courier New'``
    to further specify the default which is ``'\fmodern'``. The RTF
    specification claims that ``\fmodern`` are "Fixed-pitch serif
    and sans serif fonts". Hope every RTF implementation thinks
    the same about modern...

Definition at line 42 of file rtf.py.

00042 
00043     def __init__(self, **options):
00044         """
00045         Additional options accepted:
00046 
00047         ``fontface``
00048             Name of the font used. Could for example be ``'Courier New'``
00049             to further specify the default which is ``'\fmodern'``. The RTF
00050             specification claims that ``\fmodern`` are "Fixed-pitch serif
00051             and sans serif fonts". Hope every RTF implementation thinks
00052             the same about modern...
00053         """
00054         Formatter.__init__(self, **options)
00055         self.fontface = options.get('fontface') or ''


Member Function Documentation

Definition at line 56 of file rtf.py.

00056 
00057     def _escape(self, text):
00058         return text.replace('\\', '\\\\') \
00059                    .replace('{', '\\{') \
00060                    .replace('}', '\\}')

Here is the caller graph for this function:

Definition at line 61 of file rtf.py.

00061 
00062     def _escape_text(self, text):
00063         # empty strings, should give a small performance improvment
00064         if not text:
00065             return ''
00066 
00067         # escape text
00068         text = self._escape(text)
00069         if self.encoding in ('utf-8', 'utf-16', 'utf-32'):
00070             encoding = 'iso-8859-15'
00071         else:
00072             encoding = self.encoding or 'iso-8859-15'
00073 
00074         buf = []
00075         for c in text:
00076             if ord(c) > 128:
00077                 ansic = c.encode(encoding, 'ignore') or '?'
00078                 if ord(ansic) > 128:
00079                     ansic = '\\\'%x' % ord(ansic)
00080                 else:
00081                     ansic = c
00082                 buf.append(r'\ud{\u%d%s}' % (ord(c), ansic))
00083             else:
00084                 buf.append(str(c))
00085 
00086         return ''.join(buf).replace('\n', '\\par\n')

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.pygments.formatters.rtf.RtfFormatter.format_unencoded (   self,
  tokensource,
  outfile 
)

Definition at line 87 of file rtf.py.

00087 
00088     def format_unencoded(self, tokensource, outfile):
00089         # rtf 1.8 header
00090         outfile.write(r'{\rtf1\ansi\deff0'
00091                       r'{\fonttbl{\f0\fmodern\fprq1\fcharset0%s;}}'
00092                       r'{\colortbl;' % (self.fontface and
00093                                         ' ' + self._escape(self.fontface) or
00094                                         ''))
00095 
00096         # convert colors and save them in a mapping to access them later.
00097         color_mapping = {}
00098         offset = 1
00099         for _, style in self.style:
00100             for color in style['color'], style['bgcolor'], style['border']:
00101                 if color and color not in color_mapping:
00102                     color_mapping[color] = offset
00103                     outfile.write(r'\red%d\green%d\blue%d;' % (
00104                         int(color[0:2], 16),
00105                         int(color[2:4], 16),
00106                         int(color[4:6], 16)
00107                     ))
00108                     offset += 1
00109         outfile.write(r'}\f0')
00110 
00111         # highlight stream
00112         for ttype, value in tokensource:
00113             while not self.style.styles_token(ttype) and ttype.parent:
00114                 ttype = ttype.parent
00115             style = self.style.style_for_token(ttype)
00116             buf = []
00117             if style['bgcolor']:
00118                 buf.append(r'\cb%d' % color_mapping[style['bgcolor']])
00119             if style['color']:
00120                 buf.append(r'\cf%d' % color_mapping[style['color']])
00121             if style['bold']:
00122                 buf.append(r'\b')
00123             if style['italic']:
00124                 buf.append(r'\i')
00125             if style['underline']:
00126                 buf.append(r'\ul')
00127             if style['border']:
00128                 buf.append(r'\chbrdr\chcfpat%d' %
00129                            color_mapping[style['border']])
00130             start = ''.join(buf)
00131             if start:
00132                 outfile.write('{%s ' % start)
00133             outfile.write(self._escape_text(value))
00134             if start:
00135                 outfile.write('}')
00136 
00137         outfile.write('}')

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 37 of file rtf.py.

Definition at line 38 of file rtf.py.

Definition at line 54 of file rtf.py.

Definition at line 36 of file rtf.py.

Definition at line 40 of file rtf.py.


The documentation for this class was generated from the following file: