<commit_before>var Base = require('fontpath-renderer')

function FontpathRenderer(options) {
    if (!(this instanceof FontpathRenderer))
        return new FontpathRenderer(options)
    options = options||{}
    Base.call(this, options.font, options.fontSize)

    if (typeof options.align === 'string')
        this.align = options.align
    if (typeof options.underline === 'boolean')
        this.underline = options.underline
    if (typeof options.underlineThickness === 'number')
        this.underlineThickness = options.underlineThickness
    if (typeof options.underlinePosition === 'number')
        this.underlinePosition = options.underlinePosition
    if (typeof options.text === 'string')
        this.text = options.text
    if (typeof options.wrapMode === 'string')
        this.wordwrap.mode = options.wrapMode
    if (typeof options.wrapWidth === 'number')
        this.layout(options.wrapWidth)
}

FontpathRenderer.prototype = Object.create(Base.prototype)
FontpathRenderer.constructor = FontpathRenderer
FontpathRenderer.Align = Base.Align

FontpathRenderer.prototype.renderGlyph = function(i, glyph, scale, x, y) {
    this.data.glyphs.push({
        glyph: glyph,
        charCode: this.text.charCodeAt(i),
        scale: [ scale, -scale ],
        position: [ x, y ],
        index: i
    })
}

FontpathRenderer.prototype.renderUnderline = function(x, y, width, height) {
    this.data.underlines.push({
        position: [ x, y ],
        size: [ width, height ]
    })
}

FontpathRenderer.prototype.render = function(x, y, start, end) {
    //new data for result
    this.data = {
        glyphs: [],
        underlines: []
    }
    Base.prototype.render.call(this, x, y, start, end)
    return this.data
}

module.exports = FontpathRenderer<commit_msg>using classes as optimization<commit_after>var Base = require('fontpath-renderer')

//TODO: Eventually lots of this code will just replace fontpath-renderer...

function FontpathRenderer(options) {
    if (!(this instanceof FontpathRenderer))
        return new FontpathRenderer(options)
    options = options||{}
    Base.call(this, options.font, options.fontSize)

    if (typeof options.align === 'string')
        this.align = options.align
    if (typeof options.underline === 'boolean')
        this.underline = options.underline
    if (typeof options.underlineThickness === 'number')
        this.underlineThickness = options.underlineThickness
    if (typeof options.underlinePosition === 'number')
        this.underlinePosition = options.underlinePosition
    if (typeof options.text === 'string')
        this.text = options.text
    if (typeof options.wrapMode === 'string')
        this.wordwrap.mode = options.wrapMode
    if (typeof options.wrapWidth === 'number')
        this.layout(options.wrapWidth)

    this.data = {
        glyphs: [],
        underlines: []
    }
}

FontpathRenderer.prototype = Object.create(Base.prototype)
FontpathRenderer.constructor = FontpathRenderer
FontpathRenderer.Align = Base.Align

FontpathRenderer.prototype.renderGlyph = function(i, glyph, scale, x, y) {
    this.data.glyphs.push(new Glyph(i, glyph, 
                this.text.charCodeAt(i), 
                [ scale, this.font.bitmap ? scale : -scale ],
                [ x, y ]))
}

FontpathRenderer.prototype.renderUnderline = function(x, y, width, height) {
    this.data.underlines.push(new Underline(
        [ x, y ],
        [ width, height ]
    ))
}

FontpathRenderer.prototype.render = function(x, y, start, end) {
    //new data for result
    this.data.glyphs.length = 0
    this.data.underlines.length = 0
    Base.prototype.render.call(this, x, y, start, end)
    return this.data
}

function Glyph(index, glyph, charCode, scale, position) {
    this.glyph = glyph
    this.index = index
    this.charCode = charCode
    this.position = position
    this.scale = scale
}

function Underline(position, size) {
    this.position = position
    this.size = size
}

module.exports = FontpathRenderer
{'fraction_non_alphanumeric': 0.12037037037037036, 'fraction_numerical': 0.0005005005005005005, 'mean_word_length': 3.0537525354969572, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6995361', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1138, 'n_words': 267}