diff options
author | Andrew Pinkham <code@andrewsforge.com> | 2014-04-28 18:27:31 -0500 |
---|---|---|
committer | Andrew Pinkham <code@andrewsforge.com> | 2014-04-28 18:27:31 -0500 |
commit | bab23e5abb2f8a10aa41d13d9c431738491631bf (patch) | |
tree | 6b2f9303ea8b5e4a716175900ebad08f223cf77b /pygments/formatters/rtf.py | |
parent | 2364f8848dbc16bf78123704eb82d9bb53dc0c8b (diff) | |
download | pygments-bab23e5abb2f8a10aa41d13d9c431738491631bf.tar.gz |
RTF Formatter: inlined surrogate pair calculation.
Diffstat (limited to 'pygments/formatters/rtf.py')
-rw-r--r-- | pygments/formatters/rtf.py | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/pygments/formatters/rtf.py b/pygments/formatters/rtf.py index 2047dbc3..1a5a356f 100644 --- a/pygments/formatters/rtf.py +++ b/pygments/formatters/rtf.py @@ -72,22 +72,6 @@ class RtfFormatter(Formatter): if not text: return '' - def calculate_surrogate_pair(cn): - """Calculate the surrogate pair of character. - - Given a unicode character code - with length greater than 16 bits, - return the two 16 bit surrogate pair. - From example D28 of: - http://www.unicode.org/book/ch03.pdf - """ - cn = int(cn) - if (2**16) <= cn: - h = ((cn - 0x10000) / 0x400) + 0xD800 - l = ((cn - 0x10000) % 0x400) + 0xDC00 - return h,l - else: - return cn # escape text text = self._escape(text) @@ -102,10 +86,16 @@ class RtfFormatter(Formatter): # single unicode escape sequence buf.append(r'{\u%d}' % cn) elif (2**16) <= cn: - # RTF limits unicode to 16 bits - # surrogates enforced - for uc in calculate_surrogate_pair(cn): - buf.append(r'{\u%d}' % uc) + # RTF limits unicode to 16 bits. + # Given a unicode character code + # with length greater than 16 bits, + # print the two 16 bit surrogate pair. + # From example D28 of: + # http://www.unicode.org/book/ch03.pdf + h = ((cn - 0x10000) / 0x400) + 0xD800 + l = ((cn - 0x10000) % 0x400) + 0xDC00 + buf.append(r'{\u%d}' % h) + buf.append(r'{\u%d}' % l) return ''.join(buf).replace('\n', '\\par\n') |