<commit_before>﻿//Apache2, 2014-present, WinterDev

using PixelFarm.Drawing;
namespace LayoutFarm.CustomWidgets
{


    public class CustomTextRun : RenderElement
    {
        char[] _textBuffer;
        Color _textColor = Color.Black; //default
        Color _backColor = Color.Transparent;
        RequestFont _font;
        RenderVxFormattedString _renderVxFormattedString;
        byte _contentLeft;
        byte _contentTop;
        byte _contentRight;
        byte _contentBottom;

        byte _borderLeft;
        byte _borderTop;
        byte _borderRight;
        byte _borderBottom;

        public CustomTextRun(RootGraphic rootgfx, int width, int height)
            : base(rootgfx, width, height)
        {
#if DEBUG
            //dbugBreak = true;
#endif
            _font = rootgfx.DefaultTextEditFontInfo;
            NeedPreRenderEval = true;
            DrawTextTechnique = DrawTextTechnique.Stencil;//default
        }

        public DrawTextTechnique DrawTextTechnique { get; set; }
        public bool DelayFormattedString { get; set; }

        public override void ResetRootGraphics(RootGraphic rootgfx)
        {
            DirectSetRootGraphics(this, rootgfx);
        }
        public Color TextColor
        {
            get => _textColor;
            set => _textColor = value;
        }
        public Color BackColor
        {
            get => _backColor;
            set
            {
                _backColor = value;
                BgIsNotOpaque = value.A < 255;
            }
        }

        
        public string Text
        {
            get => new string(_textBuffer);
            set
            {
                //TODO: review here
                //if input string is null => textBuffer= null

               
                _textBuffer = (value == null) ? null : value.ToCharArray();
                //reset 
                if (_renderVxFormattedString != null)
                {
                    _contentChanged = true;
                    _renderVxFormattedString.Dispose();
                    _renderVxFormattedString = null;
                    //----------

                    //new text may change the size of this text run
                    //similar to size change
                    //for gfx-invalidation, we need a size before change and after change 

                    TextBufferSpan textBufferSpan = new TextBufferSpan(_textBuffer);
                    Size newSize = Root.TextServices.MeasureString(ref textBufferSpan, _font);//just measure
                    int newW = Width;
                    int newH = Height;
                    if (!this.HasSpecificWidth)
                    {
                        newW = _contentLeft + (int)System.Math.Ceiling((float)newSize.Width) + _contentRight;
                    }
                    if (!this.HasSpecificHeight)<commit_msg>2426.1<commit_after>﻿//Apache2, 2014-present, WinterDev

using PixelFarm.Drawing;
namespace LayoutFarm.CustomWidgets
{


    public class CustomTextRun : RenderElement
    {
        char[] _textBuffer;
        Color _textColor = Color.Black; //default
        Color _backColor = Color.Transparent;
        RequestFont _font;
        RenderVxFormattedString _renderVxFormattedString;
        byte _contentLeft;
        byte _contentTop;
        byte _contentRight;
        byte _contentBottom;

        byte _borderLeft;
        byte _borderTop;
        byte _borderRight;
        byte _borderBottom;

        public CustomTextRun(RootGraphic rootgfx, int width, int height)
            : base(rootgfx, width, height)
        {
#if DEBUG
            //dbugBreak = true;
#endif
            _font = rootgfx.DefaultTextEditFontInfo;
            NeedPreRenderEval = true;
            DrawTextTechnique = DrawTextTechnique.Stencil;//default
        }

        public DrawTextTechnique DrawTextTechnique { get; set; }
        public bool DelayFormattedString { get; set; }

        public override void ResetRootGraphics(RootGraphic rootgfx)
        {
            DirectSetRootGraphics(this, rootgfx);
        }
        public Color TextColor
        {
            get => _textColor;
            set => _textColor = value;
        }
        public Color BackColor
        {
            get => _backColor;
            set
            {
                _backColor = value;
                BgIsNotOpaque = value.A < 255;
            }
        }

        
        public string Text
        {
            get => new string(_textBuffer);
            set
            {
                //TODO: review here
                //if input string is null => textBuffer= null

               
                _textBuffer = (value == null) ? null : value.ToCharArray();
                //reset 
                if (_renderVxFormattedString != null)
                {
                  
                    _renderVxFormattedString.Dispose();
                    _renderVxFormattedString = null;
                    //----------

                    //new text may change the size of this text run
                    //similar to size change
                    //for gfx-invalidation, we need a size before change and after change 

                    TextBufferSpan textBufferSpan = new TextBufferSpan(_textBuffer);
                    Size newSize = Root.TextServices.MeasureString(ref textBufferSpan, _font);//just measure
                    int newW = Width;
                    int newH = Height;
                    if (!this.HasSpecificWidth)
                    {
                        newW = _contentLeft + (int)System.Math.Ceiling((float)newSize.Width) + _contentRight;
                    }
                    if (!this.HasSpecificHeight)
{'fraction_non_alphanumeric': 0.07075140449438203, 'fraction_numerical': 0.0036867977528089887, 'mean_word_length': 1.3936974789915966, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3233213', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1378, 'n_words': 351}