<commit_before>/// <reference path="../Runtime/Nullstone.js" />
/// CODE
/// <reference path="../Engine/RenderContext.js"/>

//#region _TextLayoutGlyphCluster
var _TextLayoutGlyphCluster = Nullstone.Create("_TextLayoutGlyphCluster", null, 3);

_TextLayoutGlyphCluster.Instance.Init = function (text, font, selected) {
    this._Text = text;
    this._Selected = selected == true;
    this._Advance = Surface.MeasureText(text, font).Width;
};

_TextLayoutGlyphCluster.Instance._Render = function (ctx, origin, attrs, x, y) {
    /// <param name="ctx" type="_RenderContext"></param>
    if (this._Text.length == 0 || this._Advance == 0.0)
        return;
    var font = attrs.GetFont();
    var y0 = font._Ascender();
    ctx.Transform(Matrix.CreateTranslate(x, y - y0));

    var brush;
    var area;
    if (this._Selected && (brush = attrs.GetBackground(true))) {
        area = new Rect(origin.X, origin.Y, this._Advance, font.GetActualHeight());
        ctx.FillRect(brush, area); //selection background
    }
    if (!(brush = attrs.GetForeground(this._Selected)))
        return;

    var canvasCtx = ctx.GetCanvasContext();
    brush.SetupBrush(canvasCtx);
    canvasCtx.fillStyle = brush.ToHtml5Object();
    canvasCtx.font = font.ToHtml5Object();
    canvasCtx.textAlign = "left";
    canvasCtx.textBaseline = "top";
    canvasCtx.fillText(this._Text, 0, 0);

    if (attrs.IsUnderlined()) {
        //TODO: Underline
    }
};

Nullstone.FinishCreate(_TextLayoutGlyphCluster);
//#endregion<commit_msg>Implemented underlining on text.<commit_after>/// <reference path="../Runtime/Nullstone.js" />
/// CODE
/// <reference path="../Engine/RenderContext.js"/>

//#region _TextLayoutGlyphCluster
var _TextLayoutGlyphCluster = Nullstone.Create("_TextLayoutGlyphCluster", null, 3);

_TextLayoutGlyphCluster.Instance.Init = function (text, font, selected) {
    this._Text = text;
    this._Selected = selected == true;
    this._Advance = Surface.MeasureText(text, font).Width;
};

_TextLayoutGlyphCluster.Instance._Render = function (ctx, origin, attrs, x, y) {
    /// <param name="ctx" type="_RenderContext"></param>
    if (this._Text.length == 0 || this._Advance == 0.0)
        return;
    var font = attrs.GetFont();
    var y0 = font._Ascender();
    ctx.Transform(Matrix.CreateTranslate(x, y - y0));

    var brush;
    var area;
    var fontHeight = font.GetActualHeight();
    if (this._Selected && (brush = attrs.GetBackground(true))) {
        area = new Rect(origin.X, origin.Y, this._Advance, fontHeight);
        ctx.FillRect(brush, area); //selection background
    }
    if (!(brush = attrs.GetForeground(this._Selected)))
        return;

    var canvasCtx = ctx.GetCanvasContext();
    brush.SetupBrush(canvasCtx);
    var brushHtml5 = brush.ToHtml5Object();
    canvasCtx.fillStyle = brushHtml5;
    canvasCtx.font = font.ToHtml5Object();
    canvasCtx.textAlign = "left";
    canvasCtx.textBaseline = "top";
    canvasCtx.fillText(this._Text, 0, 0);

    if (attrs.IsUnderlined()) {
        canvasCtx.beginPath();
        canvasCtx.moveTo(0, fontHeight);
        canvasCtx.lineTo(this._Advance, fontHeight);
        canvasCtx.lineWidth = 2;
        canvasCtx.strokeStyle = brushHtml5;
        canvasCtx.stroke();
    }
};

Nullstone.FinishCreate(_TextLayoutGlyphCluster);
//#endregion
{'fraction_non_alphanumeric': 0.14786815845176898, 'fraction_numerical': 0.0075597218022376775, 'mean_word_length': 3.4343163538873993, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2656735', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1041, 'n_words': 204}