Search code examples
c++delphiadobe-indesignadobe-illustratorbezier

How to draw curve by InDesign/Illustrator path points?


The following numbers are the path points of a very simple curve from Adobe InDesign:

pathPoint0 = app.selection[0].paths[0].pathPoints[0]  // PointType: SMOOTH
pathPoint1 = app.selection[0].paths[0].pathPoints[1]  // PointType: PLAIN

pathPoint0.leftDirection : {x=87.32570997045623, y=30.81406367905744}   
pathPoint0.anchor : {x=67.69218412206757, y=134.53280706833522}  
pathPoint0.rightDirection : {x=48.0586582736789, y=238.25155045761298}  

pathPoint1.anchor : {117.05865827421783, 143.2515504576449} 

The curve contains 2 path points, an smooth point and a plain point.

InDesign simple curve:

(source: no-ip.org)

I am trying to draw this curve by this code:

MoveToEx(hDC, 67, 134, NULL);  
POINT points[] = {{87, 30}, {48, 238}, {117, 143}};  
PolyBezierTo(hDC, points, 3);  

But I can not draw same curve, my drawn curve is:


(source: no-ip.org)

Where is my mistake? Is any conversion need?
Thanks.


Solution

  • Hmm...

    MoveToEx(hDC, 67, 134, NULL);  
    POINT points[] = {{87, 30}, {48, 238}, {117, 143}};  
    

    Your first point is 67,134 your second is 87,30 and your third 48,238.

    With Y values of 134 then 30 then 238, I'd expect about what you seem to be getting -- a line that goes one direction, then sharply back in about the opposite direction.

    The first point you're getting from InDesign is a "direction" point -- but for PolyBezier, the first and last points are the anchors. I'm not absolutely certain, but I think what you want is to rearrange the points so your anchors come first and last, and InDesign's "direction" points are used as the two control points in between:

    POINT points[] = {{87, 30}, {67, 134}, {48,238}, {117, 143}};   
    //                 anchor,   control,   control,  anchor
    PolyBezier(hDC, points, 4);
    

    Unless you're using MoveTo/LineTo (and such) otherwise, I'd just PolyBezier instead of PolyBezierTo -- keeps all the data in one place.