Skip to Content

Is it possible to get the data points of a vector path?

Estimated Reading Time: 1 Minutes

If you are trying to recognize the shape of a  vector path, attempting to locate all rectangles for example, you would need to parse the segments from the Path element. It is important to keep in mind that specific shapes can be built in many ways, using different operators. For example, you could build a filled rectangle with a rect operator, or using four lineto operators followed by a fill, or three lineto operators, a closepath and a fill.

Adobe C/C++

The data that comprises a PDEPath object can be obtained from the PDEPathGetDataFloat() API. This is raw data containing the operands and operators (moveto, lineto, etc.) that draw the path.

The data essentially consists of an array of structs containing an operator identifier then 3 (x,y) point coordinates. Below is some example code for extracting this data from a PDEPath.

  ASInt32         PathSize = PDEPathGetDataFloat(Path, NULL, 0);
    ASFloat         *PathData = (ASFloat *)ASmalloc(PathSize + 24); /* Allow read ahead, without crashing */
    ASInt32         DataSize = PathSize / 4;
    ASInt32         Index;
  DURING
        PDEPathGetDataFloat(Path, PathData, PathSize);
    Index = 0;
    while (1)
    {
        PDEPathElementType  Operator;
        ASDoublePoint        One = { 0,0 }, Two = { 0,0 }, Three = { 0,0 };
        ASInt32             Increment;
        wchar_t             Line[220];

        if (Index >= DataSize)
            break;

        Operator = static_cast<PDEPathElementType>(PathData[Index]);

        One.h = static_cast<ASDouble>(PathData[Index + 1]);
        One.v = static_cast<ASDouble>(PathData[Index + 2]);
        Two.h = static_cast<ASDouble>(PathData[Index + 3]);
        Two.v = static_cast<ASDouble>(PathData[Index + 4]);
        Three.h = static_cast<ASDouble>(PathData[Index + 5]);
        Three.v = static_cast<ASDouble>(PathData[Index + 6]);

        switch (Operator)
        {
        case kPDEMoveTo: [...]

 

Modern C++ SDK

The equivalent method is Path.get_Segments()

.NET and Java

The equivalent functions are Path.Segments and Path.getSegments() respectively.

Is it possible to get the data points of a vector path?
  • COMMENT