-->

Path2D.addPath got removed?

2019-07-31 08:32发布

问题:

I have been working with Path2D for a while, but now it seems like it's function Path2D.addPath(path, matrix?) got removed (at least in chrome).

Is there actually any replacement?
Is it permanent, or just a mistake on browser part?

回答1:

This is the information on addPath from MDN (and shameless plug):

"addPath" (NOTE: EXPERIMENTAL, on standard track)

  DESKTOP:
  Chrome  | Firefox | Edge    | IE      | Opera   | Safari
  --------+---------+---------+---------+---------+----------
    Yes   |    34   |     -   |     -   |   Yes   |   Yes

  MOBILE:
  Android | Chrome  | Edge    | Firefox | Opera   | Safari
  --------+---------+---------+---------+---------+----------
    Yes   |   Yes   |     -   |    34   |   Yes   |   Yes

Data from MDN - 'npm i -g mdncomp' by K3N / epistemex.com (c) 2018.

But you're right, it seem to be gone from the prototype in current Chrome version(s). My guess is that it is related to changing the API to use DOMMatrix instead of SVGMatrix, though by now that should be in place and there is currently nothing to be found at bugs.chromium.org. In any case, we're left to wait for an update.

There are no good workarounds for this besides from adding the path directly to context. If the scope is limited you might be able to use a secondary context and draw the paths back in from there. A polyfill approach will be extensive as you would need to rebuild the entire Path2D API to get access to the path information.