@@ -600,6 +600,30 @@ def _print_pgf_path(self, gc, path, transform, rgbFace=None):
600600 r"{\pgfqpoint{%fin}{%fin}}"
601601 % coords )
602602
603+ # apply pgf decorators
604+ sketch_params = gc .get_sketch_params () if gc else None
605+ if sketch_params is not None :
606+ # Only "length" directly maps to "segment length" in PGF's API.
607+ # PGF uses "amplitude" to pass the combined deviation in both x-
608+ # and y-direction, while matplotlib only varies the length of the
609+ # wiggle along the line ("randomness" and "length" parameters)
610+ # and has a separate "scale" argument for the amplitude.
611+ # -> Use "randomness" as PRNG seed to allow the user to force the
612+ # same shape on multiple sketched lines
613+ scale , length , randomness = sketch_params
614+ if scale is not None :
615+ # make matplotlib and PGF rendering visually similar
616+ length *= 0.5
617+ scale *= 2
618+ # PGF guarantees that repeated loading is a no-op
619+ writeln (self .fh , r"\usepgfmodule{decorations}" )
620+ writeln (self .fh , r"\usepgflibrary{decorations.pathmorphing}" )
621+ writeln (self .fh , r"\pgfkeys{/pgf/decoration/.cd, "
622+ f"segment length = { (length * f ):f} in, "
623+ f"amplitude = { (scale * f ):f} in}}" )
624+ writeln (self .fh , f"\\ pgfmathsetseed{{{ int (randomness )} }}" )
625+ writeln (self .fh , r"\pgfdecoratecurrentpath{random steps}" )
626+
603627 def _pgf_path_draw (self , stroke = True , fill = False ):
604628 actions = []
605629 if stroke :
0 commit comments