<commit_before>﻿namespace MakerJs.models {

    export class OpentypeText implements IModel {

        public models: IModelMap = {};
        public paths: IPathMap = {};

        constructor(text: string, font: opentypejs.Font) {

            var p = font.getPath(text, 0, 0, 72);

            var firstPoint: IPoint;
            var currPoint: IPoint;
            var pathCount = 0;

            p.commands.map((command, i) => {

                var points: IPoint[] = [[command.x, command.y], [command.x1, command.y1], [command.x2, command.y2]].map(
                    function (p) {
                        if (p[0] !== void 0) {
                            return point.mirror(p, false, true);
                        }
                    }
                );

                switch (command.type) {

                    case 'M':
                        firstPoint = points[0];
                        break;

                    case 'Z':
                        if (measure.isPointEqual(firstPoint, currPoint)) {
                            break;
                        }
                        //fall through to line
                        points[0] = firstPoint;

                    case 'L':
                        this.paths['p_' + ++pathCount] = new paths.Line(currPoint, points[0]);
                        break;

                    case 'C':
                        this.models['p_' + ++pathCount] = new models.BezierCurve(currPoint, points[1], points[2], points[0]);
                        break;

                    case 'Q':
                        this.models['p_' + ++pathCount] = new models.BezierCurve(currPoint, points[1], points[0]);
                        break;

                }

                currPoint = points[0];

            });

        }

    }

}<commit_msg>glyphs as child models<commit_after>﻿namespace MakerJs.models {

    export class OpentypeText implements IModel {

        public models: IModelMap = {};

        constructor(text: string, font: opentypejs.Font, fontSize: number, combine = false) {

            var charIndex = 0;
            var combineOptions: ICombineOptions = {};

            var cb = (glyph: opentypejs.Glyph, x: number, y: number, fontSize: number, options: opentypejs.RenderOptions) => {
                var m = glyph.getMetrics();
                var charModel: IModel = {};
                var firstPoint: IPoint;
                var currPoint: IPoint;
                var pathCount = 0;

                function addPath(p: IPath) {
                    if (!charModel.paths) {
                        charModel.paths = {};
                    }
                    charModel.paths['p_' + ++pathCount] = p;
                }

                function addModel(m: IModel) {
                    if (!charModel.models) {
                        charModel.models = {};
                    }
                    charModel.models['p_' + ++pathCount] = m;
                }

                var p = glyph.getPath(0, 0, fontSize);
                p.commands.map((command, i) => {

                    var points: IPoint[] = [[command.x, command.y], [command.x1, command.y1], [command.x2, command.y2]].map(
                        function (p) {
                            if (p[0] !== void 0) {
                                return point.mirror(p, false, true);
                            }
                        }
                    );

                    switch (command.type) {

                        case 'M':
                            firstPoint = points[0];
                            break;

                        case 'Z':
                            points[0] = firstPoint;
                        //fall through to line

                        case 'L':
                            if (!measure.isPointEqual(currPoint, points[0])) {
                                addPath(new paths.Line(currPoint, points[0]));
                            }
                            break;

                        case 'C':
                            addModel(new models.BezierCurve(currPoint, points[1], points[2], points[0]));
                            break;

                        case 'Q':
                            addModel(new models.BezierCurve(currPoint, points[1], points[0]));
                            break;

                    }

                    currPoint = points[0];

                });

                //TODO - add centering
                charModel.origin = [x, 0];

                if (combine && charIndex > 0) {
                    model.combine(this, charModel, false, true, false, true, combineOptions);
                    delete combineOptions.measureB;

                    //TODO - optimize for left to right 
                    combineOptions.measureA.modelsMeasured = false;
                }

                this.models[charIndex] = charModel;
                charIndex++;
            };

            font.forEachGlyph(text, 0, 0, fontSize, null, cb);

        }

    }

}
{'fraction_non_alphanumeric': 0.10468594217347957, 'fraction_numerical': 0.008773678963110668, 'mean_word_length': 0.9841772151898734, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1330962', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1187, 'n_words': 276}