Skip to content

convertShapeToPath: Convert rectangles with radius to paths - #1516

Open
santhoshtr wants to merge 1 commit into
svg:mainfrom
santhoshtr:convertShapeToPath-rectangle-radius
Open

convertShapeToPath: Convert rectangles with radius to paths#1516
santhoshtr wants to merge 1 commit into
svg:mainfrom
santhoshtr:convertShapeToPath-rectangle-radius

Conversation

@santhoshtr

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

@moatorres moatorres left a comment

Copy link
Copy Markdown

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.

2 participants