summaryrefslogtreecommitdiff
path: root/pygments/formatters/rtf.py
diff options
context:
space:
mode:
authorAndrew Pinkham <code@andrewsforge.com>2014-05-06 10:46:43 -0500
committerAndrew Pinkham <code@andrewsforge.com>2014-05-06 10:46:43 -0500
commit354626a0807e6a71d8294b170431aa2b47b402fe (patch)
treeb3d15559955bf6f578caa2d6503734a486f3b2db /pygments/formatters/rtf.py
parent8e2a616970dae8574c1adae73de6ba12b3ea7ed7 (diff)
downloadpygments-354626a0807e6a71d8294b170431aa2b47b402fe.tar.gz
RTF Formatter: replaced surrogate pair calculation with util.
Diffstat (limited to 'pygments/formatters/rtf.py')
-rw-r--r--pygments/formatters/rtf.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/pygments/formatters/rtf.py b/pygments/formatters/rtf.py
index b6a60df3..cf65a927 100644
--- a/pygments/formatters/rtf.py
+++ b/pygments/formatters/rtf.py
@@ -10,7 +10,7 @@
"""
from pygments.formatter import Formatter
-from pygments.util import get_int_opt
+from pygments.util import get_int_opt, _surrogatepair
__all__ = ['RtfFormatter']
@@ -90,13 +90,8 @@ class RtfFormatter(Formatter):
buf.append(r'{\u%d}' % cn)
elif (2**16) <= cn:
# 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
+ # Force surrogate pairs
+ h,l = _surrogatepair(cn)
buf.append(r'{\u%d}{\u%d}' % (h,l))
return ''.join(buf).replace('\n', '\\par\n')