/**
 * @file otf轮廓转ttf轮廓
 * @author mengke01(kekee000@gmail.com)
 */


define(
    function (require) {
        var bezierCubic2Q2 = require('math/bezierCubic2Q2');
        var pathCeil = require('graphics/pathCeil');

        /**
         * 转换轮廓
         * @param  {Array} otfContour otf轮廓
         * @return {Array}            ttf轮廓
         */
        function transformContour(otfContour) {
            var contour = [];
            var prevPoint;
            var curPoint;
            var nextPoint;
            var nextNextPoint;

            contour.push(prevPoint = otfContour[0]);
            for (var i = 1, l = otfContour.length; i < l; i++) {
                curPoint = otfContour[i];

                if (curPoint.onCurve) {
                    contour.push(curPoint);
                    prevPoint = curPoint;
                }
                // 三次bezier曲线
                else {
                    nextPoint =  otfContour[i + 1];
                    nextNextPoint =  i === l - 2 ? otfContour[0] : otfContour[i + 2];
                    var bezierArray = bezierCubic2Q2(prevPoint, curPoint, nextPoint, nextNextPoint);
                    bezierArray[0][2].onCurve = true;
                    contour.push(bezierArray[0][1]);
                    contour.push(bezierArray[0][2]);

                    // 第二个曲线
                    if (bezierArray[1]) {
                        bezierArray[1][2].onCurve = true;
                        contour.push(bezierArray[1][1]);
                        contour.push(bezierArray[1][2]);
                    }

                    prevPoint = nextNextPoint;
                    i += 2;
                }
            }

            return pathCeil(contour);
        }


        /**
         * otf轮廓转ttf轮廓
         * @param  {Array} otfContours otf轮廓数组
         * @return {Array} ttf轮廓
         */
        function otfContours2ttfContours(otfContours) {
            if (!otfContours || !otfContours.length) {
                return otfContours;
            }
            var contours = [];
            for (var i = 0, l = otfContours.length; i < l; i++) {
                contours.push(transformContour(otfContours[i]));
            }

            return contours;
        }

        return otfContours2ttfContours;
    }
);

@@ -2089,32 +2089,207 @@
 ; i %3C l; i++) %7B%0A
+%0A                // %E8%BF%99%E9%87%8C%E5%8F%AF%E8%83%BD%E7%94%B1%E4%BA%8E%E8%BD%AC%E6%8D%A2%E9%94%99%E8%AF%AF%E5%AF%BC%E8%87%B4%E7%A9%BA%E8%BD%AE%E5%BB%93%EF%BC%8C%E9%9C%80%E8%A6%81%E5%8E%BB%E9%99%A4%0A                if (!otfContours%5Bi%5D%5B0%5D) %7B%0A                    console.warn(otfContours);%0A                %7D%0A                else %7B%0A    
                 
@@ -2337,16 +2337,34 @@
 s%5Bi%5D));%0A
+                %7D%0A
         

remove empty contour