Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate better SVG code parsing #49

Open
tomayac opened this issue Jan 20, 2022 · 2 comments
Open

Investigate better SVG code parsing #49

tomayac opened this issue Jan 20, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@tomayac
Copy link
Owner

tomayac commented Jan 20, 2022

Maybe use https://github.com/WebReflection/linkedom for

svg = svg.replace(
'fill="#000000" stroke="none"',
`fill="rgb(${r},${g},${b})" stroke="rgb(${r},${g},${b})"${
a === '255'
? ''
: ` fill-opacity="${alpha}" stroke-opacity="${alpha}"`
} stroke-width="${params.strokeWidth}px"`,
);
const pathRegEx = /<path\s*d="([^"]+)"\/>/g;
let matches;
const shortPaths = [];
while ((matches = pathRegEx.exec(svg)) !== null) {
const path = matches[1];
if (path.split(' ').length < params.minPathSegments) {
shortPaths.push(matches[0]);
}
}
shortPaths.forEach((path) => {
svg = svg.replace(path, '');
});
.

@tomayac tomayac self-assigned this Jan 20, 2022
@tomayac tomayac added the enhancement New feature or request label Jan 28, 2022
@tomayac tomayac removed their assignment Aug 5, 2022
@xwiz
Copy link

xwiz commented Aug 24, 2022

Well done, really great job... I'm interested in improving the performance/speed of this tool, do you have any pointers where I should start from?

@tomayac
Copy link
Owner Author

tomayac commented Aug 24, 2022

The present issue is purely about replacing string-based replacement with proper DOM parsing.

If you are interested in improving the performance: see tomayac/esm-potrace-wasm#8. The latest version of esm-potrace-wasm is capable of dealing with color, but fails on too large inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants