'use strict';

var charWidth = require('./char-width');

/**
    Calculates text string width in pixels.

    @param {String} str text string to be measured
    @param {Number} size font size used
    @return {Number} text string width
*/

module.exports = function (str, size) {
    var i, len, c, w, width;
    size = size || 11; // default size 11pt
    len = str.length;
    width = 0;
    for (i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        w = charWidth.chars[c];
        if (w === undefined) {
            w = charWidth.other;
        }
        width += w;
    }
    return (width * size) / 100; // normalize
};

'use strict';

var charWidth = require('./char-width.json');

/**
    Calculates text string width in pixels.

    @param {String} str text string to be measured
    @param {Number} size font size used
    @return {Number} text string width
*/

module.exports = function (str, size) {
    var i, len, c, w, width;
    size = size || 11; // default size 11pt
    len = str.length;
    width = 0;
    for (i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        w = charWidth.chars[c];
        if (w === undefined) {
            w = charWidth.other;
        }
        width += w;
    }
    return (width * size) / 100; // normalize
};

Add json extension