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

convertShapeToPath: Convert rectangles with radius to paths #1516

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

santhoshtr
Copy link

Currently rect shapes with rx or ry radius attributes are not converted to path by convertShapeToPath plugin.

This PR adds support for converting those radius to paths under convertArcs setting of convertShapeToPath plugin.

Reference spec: https://www.w3.org/TR/SVG11/shapes.html#RectElementRXAttribute

Usecase example: When icons are converted to single path using mergePaths with force=true setting icons with at least one rectangle with given radius is left out. This is problematic for single path icons patterns followed by materialicons, or fontawesome and others.

item.attributes.height != null &&
item.attributes.rx == null &&
item.attributes.ry == null
item.attributes.height != null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it should be node.attributes.width instead of item as per 2.7.0

Copy link

@moatorres moatorres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you've forked the current version, but this code seems to work if we change item to node as in:

enter: (node, parentNode) => { ...

But using let rx = Number( ... actually messes up the code as this variable name is used down the line.

    // optionally covert ellipse
        if (node.name === 'ellipse' && convertArcs) {
          const ecx = Number(node.attributes.cx || '0');
          const ecy = Number(node.attributes.cy || '0');
          const rx = Number(node.attributes.rx || '0');
          const ry = Number(node.attributes.ry || '0');
          if (Number.isNaN(ecx - ecy + rx - ry)) {
            return;
          }

Maybe it could be named rry to avoid conflicts? Shooting in the dark here.

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

Successfully merging this pull request may close these issues.

None yet

2 participants