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 ba7e9bd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
26 changes: 12 additions & 14 deletions plugins/convertPathData.js
@@ -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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions test/regression.js
Expand Up @@ -108,9 +108,7 @@ 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' ||
name === 'struct-cond-overview-03-f' ||
name === 'struct-use-07-b' ||
Expand Down

0 comments on commit ba7e9bd

Please sign in to comment.