Skip to content

Commit

Permalink
Fix collapsing repeated with marker-mid in style rule
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Mar 5, 2021
1 parent 21c04e4 commit 10c8b56
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
26 changes: 12 additions & 14 deletions plugins/convertPathData.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

const { computeStyle } = require('../lib/style.js');
const { pathElems } = require('./_collections.js');
const { path2js, js2path, applyTransforms } = require('./_path.js');
const { cleanupOutData } = require('../lib/svgo/tools');

exports.type = 'perItem';

Expand Down Expand Up @@ -30,17 +33,11 @@ exports.params = {
forceAbsolutePath: false,
};

var pathElems = require('./_collections.js').pathElems,
path2js = require('./_path.js').path2js,
js2path = require('./_path.js').js2path,
applyTransforms = require('./_path.js').applyTransforms,
cleanupOutData = require('../lib/svgo/tools').cleanupOutData,
roundData,
precision,
error,
arcThreshold,
arcTolerance,
hasMarkerMid;
let roundData;
let precision;
let error;
let arcThreshold;
let arcTolerance;

/**
* Convert absolute Path to relative,
Expand Down Expand Up @@ -69,7 +66,7 @@ exports.fn = function (item, params) {
arcThreshold = params.makeArcs.threshold;
arcTolerance = params.makeArcs.tolerance;
}
hasMarkerMid = item.hasAttr('marker-mid');
const hasMarkerMid = computedStyle['marker-mid'] != null;

const maybeHasStroke =
computedStyle.stroke &&
Expand All @@ -93,6 +90,7 @@ exports.fn = function (item, params) {

data = filters(data, params, {
maybeHasStrokeAndLinecap,
hasMarkerMid,
});

if (params.utilizeAbsolute) {
Expand Down Expand Up @@ -256,7 +254,7 @@ function convertToRelative(path) {
* @param {Object} params plugin params
* @return {Array} output path data
*/
function filters(path, params, { maybeHasStrokeAndLinecap }) {
function filters(path, params, { maybeHasStrokeAndLinecap, hasMarkerMid }) {
var stringify = data2Path.bind(null, params),
relSubpoint = [0, 0],
pathBase = [0, 0],
Expand Down Expand Up @@ -499,7 +497,7 @@ function filters(path, params, { maybeHasStrokeAndLinecap }) {
// h 20 h 30 -> h 50
if (
params.collapseRepeated &&
!hasMarkerMid &&
hasMarkerMid === false &&
'mhv'.indexOf(instruction) > -1 &&
prev.instruction &&
instruction == prev.instruction.toLowerCase() &&
Expand Down
24 changes: 20 additions & 4 deletions test/plugins/convertPathData.03.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion test/regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ const runTests = async ({ svgFiles }) => {
// unstable test
name === 'filters-light-04-f' ||
// mismatched draft cases
name === 'imp-path-01-f' ||
name === 'interact-pointer-04-f' ||
name === 'painting-marker-properties-01-f' ||
name === 'pservers-pattern-05-f' ||
Expand Down

0 comments on commit 10c8b56

Please sign in to comment.