Skip to content

Commit

Permalink
Implement dash pattern scaling in pdf
Browse files Browse the repository at this point in the history
Factor the dash pattern scaling into a separate function so
GraphicsContextPdf.delta can call it. Combine the linewidth
and dash comparisons because now linewidth affects dashing.

Fixes matplotlib#6588
  • Loading branch information
jkseppan committed Jun 15, 2016
1 parent 7ba5c1f commit 08b64e4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
21 changes: 14 additions & 7 deletions lib/matplotlib/backend_bases.py
Expand Up @@ -858,6 +858,19 @@ def get_clip_path(self):
return self._clippath.get_transformed_path_and_affine()
return None, None

@staticmethod
def scale_dashes(linewidth, offset_dashes):
"""
Scale the given offset, dashlist tuple to fit linewidth.
"""
scale = max(1.0, linewidth)
offset, dashes = offset_dashes
if offset is not None:
offset = offset * scale
if dashes is not None:
dashes = [x * scale for x in dashes]
return offset, dashes

def get_dashes(self):
"""
Return the dash information as an offset dashlist tuple.
Expand All @@ -874,13 +887,7 @@ def get_dashes(self):
if rcParams['_internal.classic_mode']:
return self._dashes
else:
scale = max(1.0, self.get_linewidth())
offset, dashes = self._dashes
if offset is not None:
offset = offset * scale
if dashes is not None:
dashes = [x * scale for x in dashes]
return offset, dashes
return self.scale_dashes(self.get_linewidth(), self._dashes)

def get_forced_alpha(self):
"""
Expand Down
25 changes: 12 additions & 13 deletions lib/matplotlib/backends/backend_pdf.py
Expand Up @@ -2206,15 +2206,17 @@ def capstyle_cmd(self, style):
def joinstyle_cmd(self, style):
return [self.joinstyles[style], Op.setlinejoin]

def linewidth_cmd(self, width):
return [width, Op.setlinewidth]

def dash_cmd(self, dashes):
offset, dash = dashes
if dash is None:
dash = []
offset = 0
return [list(dash), offset, Op.setdash]
def linewidth_dash_cmd(self, width, dashes):
result = []
if self.get_linewidth() != width:
result += [width, Op.setlinewidth]
if self._dashes != dashes:
offset, dash = self.scale_dashes(width, dashes)
if offset is None or dash is None:
dash = []
offset = 0
result += [list(dash), offset, Op.setdash]
return result

def alpha_cmd(self, alpha, forced, effective_alphas):
name = self.file.alphaState(effective_alphas)
Expand Down Expand Up @@ -2288,14 +2290,11 @@ def clip_cmd(self, cliprect, clippath):
(('_capstyle',), capstyle_cmd),
(('_fillcolor',), fillcolor_cmd),
(('_joinstyle',), joinstyle_cmd),
(('_linewidth',), linewidth_cmd),
(('_dashes',), dash_cmd),
(('_linewidth', '_dashes'), linewidth_dash_cmd),
(('_rgb',), rgb_cmd),
(('_hatch',), hatch_cmd), # must come after fillcolor and rgb
)

# TODO: _linestyle

def delta(self, other):
"""
Copy properties of other into self and return PDF commands
Expand Down

0 comments on commit 08b64e4

Please sign in to comment.