Will a Raphael / SVG path definition always start with 'M'? (and if not, will such a path's origin always be 0,0?)

孤街浪徒 提交于 2019-12-12 03:34:22

问题


I'm working on some plugin-like code to simplify moving Raphael paths to fixed positions.

Normally, the first part of a Raphael path (which uses syntax based on SVG syntax) is an 'M' moveto command, defining the origin point of the path.

Two closely related questions:

  1. Is it reasonable to assume that any arbitrary path will begin with an 'M' moveto command? (I suspect the answer is 'no' to this)
  2. Assuming 'No' to Q1. above, on encountering a Raphael path array which doesn't begin with 'M' (somePath.attr(path)[0][0] != 'M'), can it be assumed that this path's point of origin will always be 0,0? And therefore, that any movement from 0,0 will be from a past transformation and therefore will be described in somePath.attr(transform)?

From the Raphael docs, it looks like there's nothing in the spec for the Path array that would contradict 2., but it's always worth checking for unexpected cases before making an assumption.


To put it another way, is there any case in which this function won't return the correct X and Y co-ordinates for a Raphael path origin (assuming it's passed the output from somePath.attr('path') of a valid Raphael path):

function getPathOrigin (path) {
    if (path[0][0] == 'M') {
        return {x: path[0][1], y: path[0][2]}
    } else {
        return {x: 0, y: 0}
    }
}

回答1:


According to the specification a path must begin with a moveto command.



来源:https://stackoverflow.com/questions/15231523/will-a-raphael-svg-path-definition-always-start-with-m-and-if-not-will-su

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!