<commit_before>/**
 * Copyright (c) 2012, <NAME> <EMAIL>, http://graphicore.de
 * 
 * You should have received a copy of the MIT License along with this program.
 * If not, see http://www.opensource.org/licenses/mit-license.php
 * 
 * This is a port of glifLib.GLIFPointPen defined in
 * robofab/branches/ufo3k/Lib/ufoLib/gliflib.py
 * 
 */ 
 
define(
    [
        'ufojs',
        'ufojs/errors',
        'ufojs/xml/main',
        'AbstractPointPen',
        'ufojs/ufoLib/validators',
        './constants'
    ],
    function(
        main,
        errors,
        xml,
        AbstractPointPen,
        validators,
        constants
) {
    "use strict";
    //shortcuts
    var enhance = main.enhance,
        isNumber = main.isNumber,
        assert = errors.assert,
        GlifLibError = errors.GlifLib,
        identifierValidator = validators.identifierValidator,
        transformationInfo = constants.transformationInfo;
    
    /*constructor*/
    
    /**
     * Helper class using the PointPen protocol to write the <outline>
     * part of .glif files.
     */
    function GLIFPointPen(
        element /* DOM Element*/,
        identifiers /* dict optional */,
        formatVersion /*default 2*/
    ) {
        this.document = element.ownerDocument;
        this.element = element;
        this.formatVersion = formatVersion === undefined ? 2 : formatVersion;
        this.identifiers = identifiers || {};
        
        this.prevPointTypes = [];
        this.prevOffCurveCount = 0;
        this._currentPath = null;
    }
    
    /*inheritance*/
    GLIFPointPen.prototype = Object.create(AbstractPointPen.prototype);
    
    /*definition*/
    enhance(GLIFPointPen, {
        beginPath: function(identifier /* optional */, kwargs /* optional */) {
            assert(this.currentPath === null,
                'currentPath is not null, call endPath');
            this._currentPath = this.document.createElement('contour');
            if(this._checkIdentifier(identifier))
                this._currentContour.setAttribute('identifier', identifier);
            this.prevOffCurveCount = 0
        },
        endPath: function () {
            assert(this._currentPath !== null,
                'currentPath is null, call beginPath');
            
            if ( this.prevPointTypes.length
                && this.prevPointTypes[0] === 'move'
                && this.prevPointTypes.slice(-1)[0] == 'offcurve'
            )
                throw new GlifLibError('open contour has loose offcurve point');
            
            this.element.appendChild(this._currentPath);
            this._currentPath = null;
            this.prevOffCurveCount = 0;
            this.prevPointTypes = [];
        },
        addPoint: function(
            pt,
            segmentType /* default null */,
            smooth /* default false */,
            name /* default null */,
            identifier /* default undefined */,
            kwargs /* default an object, javascript has no **kwargs syntax */
        ) {
            assert(this._currentPath !== null,
                'currentPath is null, call beginPath');
            
            segmentType = (segmentType === undefined) ? null : segmentType;
            smooth = (smooth || false);
            name = (name === undefined) ? null : name;
            kwargs = (kwargs || {});//an "options" object
            
            var point = this.document.createElement('point');
            
            // coordinates
            if(pt === undefined)
                throw new GlifLibError('Missing point argument');
            if(pt.filter(isNumber).length < 2)
                throw new GlifLibError('coordinates must be int or float')
            
            point.setAttribute('x', pt[0]);
            point.setAttribute('y', pt[1]);
            
            // segment type
            if (segmentType === 'offcurve')
                segmentType = null
            else if(segmentType == 'move' && this.prevPointTypes.length)
                throw new GlifLibError('move occurs after a point has '
                    +'already been added to the contour.')
            else if(
                segmentType in {move:1, line:1}<commit_msg>FIXME: wrong method signature, python-to-javascript kind of problem<commit_after>/**
 * Copyright (c) 2012, <NAME> <EMAIL>, http://graphicore.de
 * 
 * You should have received a copy of the MIT License along with this program.
 * If not, see http://www.opensource.org/licenses/mit-license.php
 * 
 * This is a port of glifLib.GLIFPointPen defined in
 * robofab/branches/ufo3k/Lib/ufoLib/gliflib.py
 * 
 */ 
 
define(
    [
        'ufojs',
        'ufojs/errors',
        'ufojs/xml/main',
        'AbstractPointPen',
        'ufojs/ufoLib/validators',
        './constants'
    ],
    function(
        main,
        errors,
        xml,
        AbstractPointPen,
        validators,
        constants
) {
    "use strict";
    //shortcuts
    var enhance = main.enhance,
        isNumber = main.isNumber,
        assert = errors.assert,
        GlifLibError = errors.GlifLib,
        identifierValidator = validators.identifierValidator,
        transformationInfo = constants.transformationInfo;
    
    /*constructor*/
    
    /**
     * Helper class using the PointPen protocol to write the <outline>
     * part of .glif files.
     */
    function GLIFPointPen(
        element /* DOM Element*/,
        identifiers /* dict optional */,
        formatVersion /*default 2*/
    ) {
        this.document = element.ownerDocument;
        this.element = element;
        this.formatVersion = formatVersion === undefined ? 2 : formatVersion;
        this.identifiers = identifiers || {};
        
        this.prevPointTypes = [];
        this.prevOffCurveCount = 0;
        this._currentPath = null;
    }
    
    /*inheritance*/
    GLIFPointPen.prototype = Object.create(AbstractPointPen.prototype);
    
    /*definition*/
    enhance(GLIFPointPen, {
        beginPath: function(identifier /* optional */, kwargs /* optional */) {
            assert(this.currentPath === null,
                'currentPath is not null, call endPath');
            this._currentPath = this.document.createElement('contour');
            if(this._checkIdentifier(identifier))
                this._currentContour.setAttribute('identifier', identifier);
            this.prevOffCurveCount = 0
        },
        endPath: function () {
            assert(this._currentPath !== null,
                'currentPath is null, call beginPath');
            
            if ( this.prevPointTypes.length
                && this.prevPointTypes[0] === 'move'
                && this.prevPointTypes.slice(-1)[0] == 'offcurve'
            )
                throw new GlifLibError('open contour has loose offcurve point');
            
            this.element.appendChild(this._currentPath);
            this._currentPath = null;
            this.prevOffCurveCount = 0;
            this.prevPointTypes = [];
        },
        addPoint: function(
            pt,
            segmentType /* default null */,
            smooth /* default false */,
            name /* default null */,
            // FIXME: in lib/tools/pens/AbstractPointPen is no identifier
            // argument, because that is not original point protocol. In
            // python we can use the **kwargs syntax to reach good extensibility
            // and just add keywords as arguments while staying backwards
            // compatible. But this is not the same for JavaScript, because
            // a generic kwargs object from a generic draw method would
            // in this case end up as identifier! So we MUST document that
            // an identifier can be a key in kwarg.
            identifier /* default undefined */,
            kwargs /* default an object, javascript has no **kwargs syntax */
        ) {
            assert(this._currentPath !== null,
                'currentPath is null, call beginPath');
            
            segmentType = (segmentType === undefined) ? null : segmentType;
            smooth = (smooth || false);
            name = (name === undefined) ? null : name;
            kwargs = (kwargs || {});//an "options" object
            
            var point = this.document.createElement('point');
            
            // coordinates
            if(pt === undefined)
                throw new GlifLibError('Missing point argument');
            if(pt.filter(isNumber).length < 2)
                throw new GlifLibError('coordinates must be int or float')
            
            point.setAttribute('x', pt[0]);
            point.setAttribute('y', pt[1]);
            
            // segment type
            if (segmentType === 'offcurve')
                segmentType = null
            else if(segmentType == 'move' && this.prevPointTypes.length)
                throw new GlifLibError('move occurs after a point has '
                    +'already been added to the contour.')
            else if(
                segmentType in {move:1, line:1}
{'fraction_non_alphanumeric': 0.10649322015213317, 'fraction_numerical': 0.003968691434240988, 'mean_word_length': 1.7399577167019027, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5696587', 'n_tokens_mistral': 2340, 'n_tokens_neox': 2286, 'n_words': 611}