Hi,
I tried to use matplotlib.rcParams['svg.embed_char_paths'] = False in
order to have editable text in exported SVG, but there was an encoding
issue and the file data could not be written (traceback appended).

Therefore I exchanged the XML character escaping from sax in
backend_svg.py with python's native XML escape capability (see appended
diff), and voilĂ  it works!

The conversion of mathtext to SVG is still not so nice because specific
fonts (cmmi10, cmr10, cmsy10) are used that encode mathematic symbols
with other unrelated characters. The formula display will totally break
if these fonts aren't installed, and editing is a pain. It would
therefore be great if unicode characters were used so that the correct
display is not so much dependent on those specific fonts. Would this
introduce other problems and where would be the best point to make that
change?

Greetings,
Dieter

Traceback (most recent call last):
  File "/home/weber/Promotion/svn/report/MainWindow.py", line 218, in onExport
    figure.savefig(tmp, format=format, transparent=True)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/figure.py", line 
1160, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File 
"/usr/local/lib/python2.6/dist-packages/matplotlib/backends/backend_wxagg.py", 
line 100, in print_figure
    FigureCanvasAgg.print_figure(self, filename, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/backend_bases.py", 
line 1963, in print_figure
    **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/backend_bases.py", 
line 1758, in print_svg
    return svg.print_svg(*args, **kwargs)
  File 
"/usr/local/lib/python2.6/dist-packages/matplotlib/backends/backend_svg.py", 
line 870, in print_svg
    return self._print_svg(filename, svgwriter, fh_to_close, **kwargs)
  File 
"/usr/local/lib/python2.6/dist-packages/matplotlib/backends/backend_svg.py", 
line 905, in _print_svg
    self.figure.draw(renderer)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/artist.py", line 55, 
in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/figure.py", line 874, 
in draw
    func(*args)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/artist.py", line 55, 
in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/axes.py", line 1954, 
in draw
    a.draw(renderer)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/artist.py", line 55, 
in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/axis.py", line 986, 
in draw
    tick.draw(renderer)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/artist.py", line 55, 
in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/axis.py", line 234, 
in draw
    self.label1.draw(renderer)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/artist.py", line 55, 
in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/text.py", line 591, 
in draw
    ismath=ismath)
  File 
"/usr/local/lib/python2.6/dist-packages/matplotlib/backends/backend_svg.py", 
line 676, in draw_text
    write(svg)
  File "/usr/lib/python2.6/codecs.py", line 801, in write
    data, bytesdecoded = self.decode(data, self.errors)
  File "/usr/lib/python2.6/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2212' in position 
155: ordinal not in range(128)

Index: lib/matplotlib/backends/backend_svg.py
===================================================================
--- lib/matplotlib/backends/backend_svg.py	(Revision 8841)
+++ lib/matplotlib/backends/backend_svg.py	(Arbeitskopie)
@@ -23,8 +23,11 @@
 from matplotlib.transforms import Affine2D
 from matplotlib import _png
 
-from xml.sax.saxutils import escape as escape_xml_text
+#from xml.sax.saxutils import escape as escape_xml_text
 
+def escape_xml_text(s):
+    return s.encode('ascii', 'xmlcharrefreplace')
+
 backend_version = __version__
 
 def new_figure_manager(num, *args, **kwargs):
------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to