Revision: 7035
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7035&view=rev
Author: jouni
Date: 2009-04-06 18:59:47 +0000 (Mon, 06 Apr 2009)
Log Message:
-----------
The pdf backend now escapes newlines and linefeeds in strings - fixes #2708559
Modified Paths:
--------------
branches/v0_98_5_maint/CHANGELOG
branches/v0_98_5_maint/examples/pylab_examples/usetex_demo.py
branches/v0_98_5_maint/lib/matplotlib/backends/backend_pdf.py
Modified: branches/v0_98_5_maint/CHANGELOG
===================================================================
--- branches/v0_98_5_maint/CHANGELOG 2009-04-06 17:12:37 UTC (rev 7034)
+++ branches/v0_98_5_maint/CHANGELOG 2009-04-06 18:59:47 UTC (rev 7035)
@@ -1,3 +1,6 @@
+2009-04-06 The pdf backend now escapes newlines and linefeeds in strings.
+ Fixes sf bug #2708559; thanks to Tiago Pereira for the report.
+
2009-04-06 texmanager.make_dvi now raises an error if LaTeX failed to
create an output file. Thanks to Joao Luis Silva for reporting
this. - JKS
Modified: branches/v0_98_5_maint/examples/pylab_examples/usetex_demo.py
===================================================================
--- branches/v0_98_5_maint/examples/pylab_examples/usetex_demo.py
2009-04-06 17:12:37 UTC (rev 7034)
+++ branches/v0_98_5_maint/examples/pylab_examples/usetex_demo.py
2009-04-06 18:59:47 UTC (rev 7035)
@@ -56,4 +56,8 @@
## phase field equations
pylab.text(0.2, 0.15, r'$\mathcal{F} = \int f\left( \phi, c \right) dV,$
\newline $ \frac{ \partial \phi } { \partial t } = -M_{ \phi } \frac{ \delta
\mathcal{F} } { \delta \phi }$', {'color' : 'b', 'fontsize' : 20})
+## these went wrong in pdf in a previous version
+pylab.text(-.9,.42,r'gamma: $\gamma$', {'color': 'r', 'fontsize': 20})
+pylab.text(-.9,.36,r'Omega: $\Omega$', {'color': 'b', 'fontsize': 20})
+
pylab.show()
Modified: branches/v0_98_5_maint/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- branches/v0_98_5_maint/lib/matplotlib/backends/backend_pdf.py
2009-04-06 17:12:37 UTC (rev 7034)
+++ branches/v0_98_5_maint/lib/matplotlib/backends/backend_pdf.py
2009-04-06 18:59:47 UTC (rev 7035)
@@ -112,7 +112,20 @@
result.append(' '.join(strings[lasti:]))
return '\n'.join(result)
-_string_escape_regex = re.compile(r'([\\()])')
+# PDF strings are supposed to be able to include any eight-bit data,
+# except that unbalanced parens and backslashes must be escaped by a
+# backslash. However, sf bug #2708559 shows that the carriage return
+# character may get read as a newline; these characters correspond to
+# \gamma and \Omega in TeX's math font encoding. Escaping them fixes
+# the bug.
+_string_escape_regex = re.compile(r'([\\()\r\n])')
+def _string_escape(match):
+ m = match.group(0)
+ if m in r'\()': return '\\' + m
+ elif m == '\n': return r'\n'
+ elif m == '\r': return r'\r'
+ assert False
+
def pdfRepr(obj):
"""Map Python objects to PDF syntax."""
@@ -138,7 +151,7 @@
# simpler to escape them all. TODO: cut long strings into lines;
# I believe there is some maximum line length in PDF.
elif is_string_like(obj):
- return '(' + _string_escape_regex.sub(r'\\\1', obj) + ')'
+ return '(' + _string_escape_regex.sub(_string_escape, obj) + ')'
# Dictionaries. The keys must be PDF names, so if we find strings
# there, we make Name objects from them. The values may be
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins