Skip to content

BUG : fix svg corner case #4388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions doc/api/api_changes/2015-04-27_svgclip_url.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Add salt to cilpPath id
```````````````````````

Add salt to the hash used to determine the id of the ``clipPath``
nodes. This is to avoid conflicts in two svg documents with the same
clip path are included in the same document (see
https://github.com/ipython/ipython/issues/8133 and
https://github.com/matplotlib/matplotlib/issues/4349 ), however this
means that the svg output is no longer deterministic if the same
figure is saved twice. It is not expected that this will affect any
users as the current ids are generated from an md5 hash of properties
of the clip path and any user would have a very difficult time
anticipating the value of the id.
12 changes: 9 additions & 3 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import numpy as np

from hashlib import md5
import uuid

from matplotlib import verbose, __version__, rcParams
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
Expand Down Expand Up @@ -255,7 +256,7 @@ def __init__(self, width, height, svgwriter, basename=None, image_dpi=72):
self.width = width
self.height = height
self.writer = XMLWriter(svgwriter)
self.image_dpi = image_dpi # the actual dpi we want to rasterize stuff with
self.image_dpi = image_dpi # the actual dpi we want to rasterize stuff with

self._groupd = {}
if not rcParams['svg.image_inline']:
Expand Down Expand Up @@ -309,9 +310,14 @@ def _write_default_style(self):

def _make_id(self, type, content):
content = str(content)
salt = str(uuid.uuid4())
if six.PY3:
content = content.encode('utf8')
return '%s%s' % (type, md5(content).hexdigest()[:10])
salt = salt.encode('utf8')
m = md5()
m.update(salt)
m.update(content)
return '%s%s' % (type, m.hexdigest()[:10])

def _make_flip_transform(self, transform):
return (transform +
Expand Down Expand Up @@ -532,7 +538,7 @@ def close_group(self, s):

def option_image_nocomposite(self):
"""
return whether to generate a composite image from multiple images on
return whether to generate a composite image from multiple images on
a set of axes
"""
if rcParams['svg.image_noscale']:
Expand Down