Permalink
Browse files

Fixes #1860: Unfilled members of collections are not handled correct…

…ly in the PDF backend. Also fixes a related bug that alpha could not be set on individual members of a collection.
  • Loading branch information...
mdboom authored and HubertHolin committed Mar 27, 2013
1 parent 44227e9 commit 1ce8484422ab6be1228412f93776b4c15012f555
@@ -362,6 +362,8 @@ def _iter_collection(self, gc, master_transform, all_transforms,
gc0 = self.new_gc()
gc0.copy_properties(gc)
+ original_alpha = gc.get_alpha()
+
if Nfacecolors == 0:
rgbFace = None
@@ -385,22 +387,38 @@ def _iter_collection(self, gc, master_transform, all_transforms,
yo = -(yp - yo)
if not (np.isfinite(xo) and np.isfinite(yo)):
continue
+ gc0.set_alpha(original_alpha)
if Nfacecolors:
rgbFace = facecolors[i % Nfacecolors]
if Nedgecolors:
+<<<<<<< HEAD
fg = edgecolors[i % Nedgecolors]
if Nfacecolors == 0 and len(fg) == 4:
gc0.set_alpha(fg[3])
gc0.set_foreground(fg)
+=======
+>>>>>>> Fixes #1860: Unfilled members of collections are not handled correctly in the PDF backend. Also fixes a related bug that alpha could not be set on individual members of a collection.
if Nlinewidths:
gc0.set_linewidth(linewidths[i % Nlinewidths])
if Nlinestyles:
gc0.set_dashes(*linestyles[i % Nlinestyles])
+<<<<<<< HEAD
+=======
+ fg = edgecolors[i % Nedgecolors]
+ if len(fg) == 4:
+ if fg[3] == 0.0:
+ gc0.set_linewidth(0)
+ else:
+ gc0.set_alpha(gc0.get_alpha() * fg[3])
+ gc0.set_foreground(fg[:3])
+ else:
+ gc0.set_foreground(fg)
+>>>>>>> Fixes #1860: Unfilled members of collections are not handled correctly in the PDF backend. Also fixes a related bug that alpha could not be set on individual members of a collection.
if rgbFace is not None and len(rgbFace) == 4:
if rgbFace[3] == 0:
rgbFace = None
else:
- gc0.set_alpha(rgbFace[3])
+ gc0.set_alpha(gc0.get_alpha() * rgbFace[3])
rgbFace = rgbFace[:3]
gc0.set_antialiased(antialiaseds[i % Naa])
if Nurls:
@@ -1523,10 +1523,36 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
offsets, offsetTrans, facecolors, edgecolors,
linewidths, linestyles, antialiaseds, urls,
offset_position):
+ # We can only reuse the objects if the presence of fill and
+ # stroke (and the amount of alpha for each) is the same for
+ # all of them
+ can_do_optimization = True
+
+ if not len(facecolors):
+ filled = False
+ else:
+ if np.all(facecolors[:, 3] == facecolors[0, 3]):
+ filled = facecolors[0, 3] != 0.0
+ else:
+ can_do_optimization = False
+
+ if not len(edgecolors):
+ stroked = False
+ else:
+ if np.all(edgecolors[:, 3] == edgecolors[0, 3]):
+ stroked = edgecolors[0, 3] != 0.0
+ else:
+ can_do_optimization = False
+
+ if not can_do_optimization:
+ return RendererBase.draw_path_collection(
+ self, gc, master_transform, paths, all_transforms,
+ offsets, offsetTrans, facecolors, edgecolors,
+ linewidths, linestyles, antialiaseds, urls,
+ offset_position)
+
padding = np.max(linewidths)
path_codes = []
- filled = len(facecolors)
- stroked = len(edgecolors)
for i, (path, transform) in enumerate(self._iter_collection_raw_paths(
master_transform, paths, all_transforms)):
name = self.file.pathCollectionObject(
Oops, something went wrong.

0 comments on commit 1ce8484

Please sign in to comment.