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

rx == 0 or ry == 0 ellipse or rectangle can paralyze Cairo port, at least. #69

Closed
mpsuzuki opened this issue Dec 19, 2019 · 4 comments
Closed
Assignees

Comments

@mpsuzuki
Copy link
Collaborator

mpsuzuki commented Dec 19, 2019

During the investigation of my patch for Issue #67, I found my cairo port is paralyzed by the ellipse or rectangles with rx == 0 or ry == 0. I think Skia and CoreGraphics ports are safe from this issue, because they have direct functions to draw ellipse or rounded-rectangle.

Cairo has no direct functions to draw ellipse or rounded-rectangle, so I inserted cairo_scale() to stretch the circle or rounded-corner of the rounded rectangle. Maybe, cairo_scale(cr, 0, scale_y) or cairo_scale(cr, scale_x, 0) and following cairo_arc() makes cairo confused, and all following objects are not drawn correctly.

So, I drafted a patch to replace "rx == 0 or ry == 0 ellipse" by a squashed bounding-box, and to replace "rx == 0 or ry == 0 rounded rectangle" by normal rectangle.

Another option might be "if an ellipse or a rounded-rectangle with rx==0 or ry==0, do not take it as a drawable element". I wish if the experts give some comments on the direction we should go.

@mpsuzuki mpsuzuki self-assigned this Dec 19, 2019
@mpsuzuki
Copy link
Collaborator Author

If rx and ry are non-zero, like,

<svg xmlns="http://www.w3.org/2000/svg" width="300" height="200" viewBox="0 0 300 200">
  <ellipse cx="150" cy="50" rx="25" ry="25"/>
  <rect x="120" y="120" width="60" height="60" rx="15"  ry="15"/>

  <ellipse cx="50"  cy="50" rx="1" ry="25"/>
  <rect x="20"  y="120" width="60" height="60" rx="1"   ry="15"/>

  <ellipse cx="250" cy="50" rx="50" ry="25"/>
  <rect x="220" y="120" width="60" height="60" rx="150" ry="15"/>
</svg>

The result is looking like
rect2-fixed

@mpsuzuki
Copy link
Collaborator Author

But, if rx == 0, like,

<svg xmlns="http://www.w3.org/2000/svg" width="300" height="200" viewBox="0 0 300 200">
  <ellipse cx="150" cy="50" rx="25" ry="25"/>
  <rect x="120" y="120" width="60" height="60" rx="15"  ry="15"/>

  <ellipse cx="50"  cy="50" rx="0" ry="25"/>
  <rect x="20"  y="120" width="60" height="60" rx="0"   ry="15"/>

  <ellipse cx="250" cy="50" rx="50" ry="25"/>
  <rect x="220" y="120" width="60" height="60" rx="150" ry="15"/>
</svg>

The source at abfb9aa gives such result.
rect2-zero-orig. You can find the rx == 0 elements (at the left side) are not drawn, and, following elements at the right sides are not drawn at all. It is what I call as "paralyzed".

@mpsuzuki
Copy link
Collaborator Author

mpsuzuki commented Dec 19, 2019

The source at abfb9aa, plus my 2 patches (741849a and 0df194c), another for rounded-rectangle), the result is like this.
rect2-zero-fixed

The web browsers would show such results.

@dirkschulze
Copy link
Member

According to https://svgwg.org/svg2-draft/shapes.html#EllipseElement a value of 0 for either rx or ry disables the rendering of the element. Same for r on circle or width/height on rect.

So we should skip the element if one of the attributes is 0.

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

No branches or pull requests

2 participants