I'm using a rather complex SVG shape exported from Illustrator as a clipping path.
The problem is that objectBoundingBox requires path data to be within the 0-1 range, and my path contains path data out of this range. Here is what I'm using:
<svg>
<clippath id="clipping" clipPathUnits="objectBoundingBox">
<path d="M228.6,94.8L176.8, 5.5c-2-3.5-5.8-5.5-9.9-5.5H63.2c-4.1, 0-7.8, 1.9-9.9,5.5L1.5,94.9c-2, 3.5-2,7.8,0, 11.4 l51.8, 89.8c2,3.5, 5.8,5.9,9.9,5.9h103.7c4.1, 0, 7.8-2.4,9.9-6l51.8-89.7C230.7, 102.8,230.7, 98.3,228.6,94.8z M192.8,104.4l-35.5,
61.5c-1.4,2.4-4,4.1-6.8, 4.1h-71c-2.8,0-5.4-1.7-6.8-4.1l-35.5-61.4c-1.4-2.4-1.4-5.5,0-7.9l35.5-61.5c1.4-2.4,4-4.1,6.8-4.1h71c2.8, 0, 5.4,1.7,6.8,4.1l35.5, 61.4C194.2,98.9, 194.2, 102, 192.8, 104.4z"/>
</clippath>
</svg>
Is there an easy solution to convert this to the 0-1 range so that I can use objectBoundingBox?
RE: Comment. I am able to apply any number of transforms to the SVG element, but it still doesn't work with objectBoundingBox. For example:
<clippath id="clipping" transform="scale(1,1)" clipPathUnits="objectBoundingBox">
I wrote a converter on CodePen as an attempt to solve this problem. It is loosely based on skywlkrs answer, but it supports exponential floats and adds some UI to it:
https://codepen.io/21sieben/full/gQYdEB/
As an example, this will convert
M11.214377,3.55271368e-15 L64,0 L64,64 L11.214377,64 L1.88513642,41.4772208 C-0.628378807,35.4090582 -0.628378807,28.5909418 1.88513642,22.5227792 L11.214377,3.55271368e-15 Z
to
M0.17522,0 L1,0 L1,1 L0.17522,1 L0.02946,0.64808 C-0.00982,0.55327 -0.00982,0.44673 0.02946,0.35192 L0.17522,0 Z
Notice the exponents in some floats (Sketch likes to export those).
With the following php script, you can transform them:
Just set the proper width and height variables based on your boundingbox.
This script can be found in the answer of the following question: How to apply clipPath to a div with the clipPath position being relative to the div position
Following the comments from @Robert Longson, just transform the scale of the
<clipPath>
.The shape I have taken from Figma for this example is 248 x 239, so I just apply the equivalent scale(1/248, 1/239). This gives:
This along with
clipPathUnits="objectBoundingBox"
means that we can use this shape to clip at any size or aspect ratio.