lib/parse/glyf.js
function getPath(points) {
    var p, contours, i, realFirstPoint, j, contour, pt, firstPt,
        prevPt, midPt, curvePt, lastPt;
    p = new path.Path();
    if (!points) {
        return p;
    }
    contours = getContours(points);
    for (i = 0; i < contours.length; i += 1) {
        contour = contours[i];
        firstPt = contour[0];
        lastPt = contour[contour.length - 1];
        if (firstPt.onCurve) {
            curvePt = null;
            // The first point will be consumed by the moveTo command,
            // so skip it in the loop.
            realFirstPoint = true;
        } else {
            if (lastPt.onCurve) {
                // If the first point is off-curve and the last point is on-curve,
                // start at the last point.
                firstPt = lastPt;
            } else {
                // If both first and last points are off-curve, start at their middle.
                firstPt = { x: (firstPt.x + lastPt.x) / 2, y: (firstPt.y + lastPt.y) / 2 };
            }
            curvePt = firstPt;
            // The first point is synthesized, so don't skip the real first point.
            realFirstPoint = false;
        }
        p.moveTo(firstPt.x, firstPt.y);

        for (j = realFirstPoint ? 1 : 0; j < contour.length; j += 1) {
            pt = contour[j];
            prevPt = j === 0 ? firstPt : contour[j - 1];
            if (prevPt.onCurve && pt.onCurve) {
                // This is a straight line.
                p.lineTo(pt.x, pt.y);
            } else if (prevPt.onCurve && !pt.onCurve) {
                curvePt = pt;
            } else if (!prevPt.onCurve && !pt.onCurve) {
                midPt = { x: (prevPt.x + pt.x) / 2, y: (prevPt.y + pt.y) / 2 };
                p.quadraticCurveTo(prevPt.x, prevPt.y, midPt.x, midPt.y);
                curvePt = pt;
            } else if (!prevPt.onCurve && pt.onCurve) {
                // Previous point off-curve, this point on-curve.
                p.quadraticCurveTo(curvePt.x, curvePt.y, pt.x, pt.y);
                curvePt = null;
            } else {
                throw new Error('Invalid state.');
            }
        }
        if (firstPt !== lastPt) {
            // Connect the last and first points
            if (curvePt) {
                p.quadraticCurveTo(curvePt.x, curvePt.y, firstPt.x, firstPt.y);
            } else {
                p.lineTo(firstPt.x, firstPt.y);
            }
        }
    }
    p.closePath();
    return p;
}
function getPath(points) {
    var p, contours, i, realFirstPoint, j, contour, pt, firstPt,
        prevPt, midPt, curvePt, lastPt;
    p = new path.Path();
    if (!points) {
        return p;
    }
    contours = getContours(points);
    for (i = 0; i < contours.length; i += 1) {
        contour = contours[i];
        firstPt = contour[0];
        lastPt = contour[contour.length - 1];
        if (firstPt.onCurve) {
            curvePt = null;
            // The first point will be consumed by the moveTo command,
            // so skip it in the loop.
            realFirstPoint = true;
        } else {
            if (lastPt.onCurve) {
                // If the first point is off-curve and the last point is on-curve,
                // start at the last point.
                firstPt = lastPt;
            } else {
                // If both first and last points are off-curve, start at their middle.
                firstPt = { x: (firstPt.x + lastPt.x) / 2, y: (firstPt.y + lastPt.y) / 2 };
            }
            curvePt = firstPt;
            // The first point is synthesized, so don't skip the real first point.
            realFirstPoint = false;
        }
        p.moveTo(firstPt.x, firstPt.y);

        for (j = realFirstPoint ? 1 : 0; j < contour.length; j += 1) {
            pt = contour[j];
            prevPt = j === 0 ? firstPt : contour[j - 1];
            if (prevPt.onCurve && pt.onCurve) {
                // This is a straight line.
                p.lineTo(pt.x, pt.y);
            } else if (prevPt.onCurve && !pt.onCurve) {
                curvePt = pt;
            } else if (!prevPt.onCurve && !pt.onCurve) {
                midPt = { x: (prevPt.x + pt.x) / 2, y: (prevPt.y + pt.y) / 2 };
                p.quadraticCurveTo(prevPt.x, prevPt.y, midPt.x, midPt.y);
                curvePt = pt;
            } else if (!prevPt.onCurve && pt.onCurve) {
                // Previous point off-curve, this point on-curve.
                p.quadraticCurveTo(curvePt.x, curvePt.y, pt.x, pt.y);
                curvePt = null;
            } else {
                throw new Error('Invalid state.');
            }
        }
        if (firstPt !== lastPt) {
            // Connect the last and first points
            if (curvePt) {
                p.quadraticCurveTo(curvePt.x, curvePt.y, firstPt.x, firstPt.y);
            } else {
                p.lineTo(firstPt.x, firstPt.y);
            }
        }
    }
    p.closePath();
    return p;
}
function getPath ( points ) { var p , contours , i , realFirstPoint , j , contour , pt , firstPt , prevPt , midPt , curvePt , lastPt ; p = new path . Path ( ) ; if ( ! points ) { return p ; } contours = getContours ( points ) ; for ( i = 0 ; i < contours . length ; i += 1 ) { contour = contours [ i ] ; firstPt = contour [ 0 ] ; lastPt = contour [ contour . length - 1 ] ; if ( firstPt . onCurve ) { curvePt = null ; // The first point will be consumed by the moveTo command, // so skip it in the loop. realFirstPoint = true ; } else { if ( lastPt . onCurve ) { // If the first point is off-curve and the last point is on-curve, // start at the last point. firstPt = lastPt ; } else { // If both first and last points are off-curve, start at their middle. firstPt = { x : ( firstPt . x + lastPt . x ) / 2 , y : ( firstPt . y + lastPt . y ) / 2 } ; } curvePt = firstPt ; // The first point is synthesized, so don't skip the real first point. realFirstPoint = false ; } p . moveTo ( firstPt . x , firstPt . y ) ; for ( j = realFirstPoint ? 1 : 0 ; j < contour . length ; j += 1 ) { pt = contour [ j ] ; prevPt = j === 0 ? firstPt : contour [ j - 1 ] ; if ( prevPt . onCurve && pt . onCurve ) { // This is a straight line. p . lineTo ( pt . x , pt . y ) ; } else if ( prevPt . onCurve && ! pt . onCurve ) { curvePt = pt ; } else if ( ! prevPt . onCurve && ! pt . onCurve ) { midPt = { x : ( prevPt . x + pt . x ) / 2 , y : ( prevPt . y + pt . y ) / 2 } ; p . quadraticCurveTo ( prevPt . x , prevPt . y , midPt . x , midPt . y ) ; curvePt = pt ; } else if ( ! prevPt . onCurve && pt . onCurve ) { // Previous point off-curve, this point on-curve. p . quadraticCurveTo ( curvePt . x , curvePt . y , pt . x , pt . y ) ; curvePt = null ; } else { throw new Error ( 'Invalid state.' ) ; } } if ( firstPt !== lastPt ) { // Connect the last and first points if ( curvePt ) { p . quadraticCurveTo ( curvePt . x , curvePt . y , firstPt . x , firstPt . y ) ; } else { p . lineTo ( firstPt . x , firstPt . y ) ; } } } p . closePath ( ) ; return p ; }
Convert the TrueType glyph outline to a Path.
Convert the TrueType glyph outline to a Path .