<commit_before>define([
    'specimenTools/_BaseWidget'
  , 'Atem-Pen-Case/pens/SVGPen'
], function(
    Parent
  , SVGPen
){
    "use strict";
    /*globals window, console*/

    var svgns = 'http://www.w3.org/2000/svg';

    function GlyphTable(doc, font, options) {
        Parent.call(this, options);
        this._element = doc.createElement('div');
        this._font = font;
        this._setDimensions = null;
        this._loadProgress = [0, null];
        this.__initCells = this._initCells.bind(this);

        this._element.addEventListener('click', this._glyphClickHandler.bind(this));
    }

    var _p = GlyphTable.prototype = Object.create(Parent.prototype);
    _p.constructor = GlyphTable;

    GlyphTable.defaultOptions = {
        glyphClass: 'glyph'
      , loadAtOnce: 50
      , loadSerial: false
      , glyphActiveClass: 'active'
    };

    Object.defineProperty(_p, 'element', {
        get: function() {
            this.activate();
            return this._element;
        }
    });

    function draw(glyph, pen) {
        var i, l, cmd;
        for(i=0,l=glyph.path.commands.length;i<l;i++){
            cmd = glyph.path.commands[i];
            switch (cmd.type) {
                case 'M':
                    pen.moveTo([cmd.x, cmd.y]);
                    break;
                case 'Z':
                    pen.closePath();
                    break;
                case 'Q':
                    pen.qCurveTo([cmd.x1, cmd.y1], [cmd.x, cmd.y]);
                    break;
                case 'C':
                    pen.curveTo([cmd.x1, cmd.y1], [cmd.x2, cmd.y2],[cmd.x, cmd.y]);
                    break;
                case 'L':
                    pen.lineTo([cmd.x, cmd.y]);
                    break;
                default:
                    console.warn('Unknown path command:', cmd.type);
            }
        }
    }

    _p.setDimensions = function(width, ascent, descent) {
        this._setDimensions = {
            width: width
          , ascent: ascent
          , descent: descent
        };
    };

    _p.getDimensions = function(forceOwnDimensions) {
        var ascent, descent, width, yMax, yMin;
        if(!forceOwnDimensions && this._setDimensions) {
            width = this._setDimensions.width;
            ascent = this._setDimensions.ascent;
            descent = this._setDimensions.descent;
        }
        else {
            yMax = this._font.tables.head.yMax;
            yMin = this._font.tables.head.yMin;
            width =  yMax + (yMin > 0 ? 0 : Math.abs(yMin));
            //usWinAscent and usWinDescent should be the maximum values for
            // all glyphs over the complete family.
            // So,if it ain't broken, styles of the same family should
            // all render with the same size.
            ascent =  this._font.tables.os2.usWinAscent;
            descent = this._font.tables.os2.usWinDescent;

        }
        return {
              width: width
            , height: ascent + descent
            , ascent: ascent
            , descent: descent
        };
    };

    _p._glyphClickHandler = function(evt) {
        var active = this._element.getElementsByClassName(this._options.glyphActiveClass)
          , i, l
          , element
          , glyph = null
          ;

        element = evt.target;//evt.srcElement || evt.originalTarget
        do {
            if(element.classList.contains(this._options.glyphClass)) {
                glyph = element;
                break;
            }
            else
                element = element.parentElement;
        } while(element !== this._element);

        for(i=0,l=active.length;i<l;i++) {
            if (active[i] === glyph)
                // the clicked element was active, so we just deactivate it
                glyph = null;
            active[i].classList.remove(this._options.glyphActiveClass);
        }

        if(glyph)
            glyph.classList.add(this._options.glyphActiveClass);
    };


    _p._initCell = function(glyphName, glyphIndex) {
        var element = this._element.ownerDocument.createElement('div')
          , svg = this._element.ownerDocument.createElementNS(svgns, 'svg')
          , path = this._element.ownerDocument.createElementNS(svgns, 'path')
          , glyphSet = {}
          , pen = new SVGPen(path, glyphSet)
          , glyph = this._font.glyphs.get(glyphIndex)
          , dimensions = this.getDimensions()
          , width = dimensions.width
          , height = dimensions.height
          , ascent = dimensions.ascent<commit_msg>GlyphTable: 'while' is better than 'do' in this case<commit_after>define([
    'specimenTools/_BaseWidget'
  , 'Atem-Pen-Case/pens/SVGPen'
], function(
    Parent
  , SVGPen
){
    "use strict";
    /*globals window, console*/

    var svgns = 'http://www.w3.org/2000/svg';

    function GlyphTable(doc, font, options) {
        Parent.call(this, options);
        this._element = doc.createElement('div');
        this._font = font;
        this._setDimensions = null;
        this._loadProgress = [0, null];
        this.__initCells = this._initCells.bind(this);

        this._element.addEventListener('click', this._glyphClickHandler.bind(this));
    }

    var _p = GlyphTable.prototype = Object.create(Parent.prototype);
    _p.constructor = GlyphTable;

    GlyphTable.defaultOptions = {
        glyphClass: 'glyph'
      , loadAtOnce: 50
      , loadSerial: false
      , glyphActiveClass: 'active'
    };

    Object.defineProperty(_p, 'element', {
        get: function() {
            this.activate();
            return this._element;
        }
    });

    function draw(glyph, pen) {
        var i, l, cmd;
        for(i=0,l=glyph.path.commands.length;i<l;i++){
            cmd = glyph.path.commands[i];
            switch (cmd.type) {
                case 'M':
                    pen.moveTo([cmd.x, cmd.y]);
                    break;
                case 'Z':
                    pen.closePath();
                    break;
                case 'Q':
                    pen.qCurveTo([cmd.x1, cmd.y1], [cmd.x, cmd.y]);
                    break;
                case 'C':
                    pen.curveTo([cmd.x1, cmd.y1], [cmd.x2, cmd.y2],[cmd.x, cmd.y]);
                    break;
                case 'L':
                    pen.lineTo([cmd.x, cmd.y]);
                    break;
                default:
                    console.warn('Unknown path command:', cmd.type);
            }
        }
    }

    _p.setDimensions = function(width, ascent, descent) {
        this._setDimensions = {
            width: width
          , ascent: ascent
          , descent: descent
        };
    };

    _p.getDimensions = function(forceOwnDimensions) {
        var ascent, descent, width, yMax, yMin;
        if(!forceOwnDimensions && this._setDimensions) {
            width = this._setDimensions.width;
            ascent = this._setDimensions.ascent;
            descent = this._setDimensions.descent;
        }
        else {
            yMax = this._font.tables.head.yMax;
            yMin = this._font.tables.head.yMin;
            width =  yMax + (yMin > 0 ? 0 : Math.abs(yMin));
            //usWinAscent and usWinDescent should be the maximum values for
            // all glyphs over the complete family.
            // So,if it ain't broken, styles of the same family should
            // all render with the same size.
            ascent =  this._font.tables.os2.usWinAscent;
            descent = this._font.tables.os2.usWinDescent;

        }
        return {
              width: width
            , height: ascent + descent
            , ascent: ascent
            , descent: descent
        };
    };

    _p._glyphClickHandler = function(evt) {
        var active = this._element.getElementsByClassName(this._options.glyphActiveClass)
          , i, l
          , element
          , glyph = null
          ;

        element = evt.target;
        while(element && element !== this._element) {
            if(element.classList.contains(this._options.glyphClass)) {
                glyph = element;
                break;
            }
            else
                element = element.parentElement;
        }

        for(i=0,l=active.length;i<l;i++) {
            if (active[i] === glyph)
                // the clicked element was active, so we just deactivate it
                glyph = null;
            active[i].classList.remove(this._options.glyphActiveClass);
        }

        if(glyph)
            glyph.classList.add(this._options.glyphActiveClass);
    };


    _p._initCell = function(glyphName, glyphIndex) {
        var element = this._element.ownerDocument.createElement('div')
          , svg = this._element.ownerDocument.createElementNS(svgns, 'svg')
          , path = this._element.ownerDocument.createElementNS(svgns, 'path')
          , glyphSet = {}
          , pen = new SVGPen(path, glyphSet)
          , glyph = this._font.glyphs.get(glyphIndex)
          , dimensions = this.getDimensions()
          , width = dimensions.width
          , height = dimensions.height
          , ascent = dimensions.ascent
{'fraction_non_alphanumeric': 0.1167068097219181, 'fraction_numerical': 0.004379242391066345, 'mean_word_length': 1.5936967632027257, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '4118837', 'n_tokens_mistral': 2707, 'n_tokens_neox': 2552, 'n_words': 512}