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

using System.IO;
using PixelFarm.Drawing;
using LayoutFarm.ContentManagers;
using LayoutFarm.Svg;
using PaintLab.Svg;

namespace LayoutFarm
{
    public abstract class AppHost
    {

        protected int _primaryScreenWorkingAreaW;
        protected int _primaryScreenWorkingAreaH;
        protected int _formTitleBarHeight;

        public AppHost()
        {


        }
        public abstract string OwnerFormTitle { get; set; }
        public abstract Image LoadImage(string imgName, int reqW, int reqH);
        public Image LoadImage(string imgName)
        {
            return LoadImage(imgName, 0, 0);
        }
        public int OwnerFormTitleBarHeight { get { return _formTitleBarHeight; } }


        public virtual System.IO.Stream GetReadStream(string src)
        {
            return App.ReadStreamS(src);
        }
        public virtual System.IO.Stream GetWriteStream(string dest)
        {
            return App.GetWriteStream(dest);
        }
        public virtual bool UploadStream(string url, Stream stream)
        {
            return App.UploadStream(url, stream);
        }
        protected abstract void LazyImageLoad(ImageBinder binder);


        public int PrimaryScreenWidth
        {
            get { return this._primaryScreenWorkingAreaW; }
        }
        public int PrimaryScreenHeight
        {
            get { return this._primaryScreenWorkingAreaH; }
        }
        public abstract void AddChild(RenderElement renderElement);
        public abstract void AddChild(RenderElement renderElement, object owner);

        public abstract RootGraphic RootGfx { get; }

        public ImageBinder GetImageBinder(string src)
        {
            ClientImageBinder clientImgBinder = new ClientImageBinder(src);
            clientImgBinder.SetLazyLoaderFunc(LazyImageLoad);
            //if use lazy img load func
            //imageContentMan.AddRequestImage(clientImgBinder);
            return clientImgBinder;
        }
        public ImageBinder GetImageBinder2(string src)
        {
            ClientImageBinder clientImgBinder = new ClientImageBinder(src);
            clientImgBinder.SetImage(LoadImage(src));
            clientImgBinder.State = BinderState.Loaded;
            return clientImgBinder;
        }
    }



    public class WinFormAppHost : AppHost
    {
        ImageLoadingQueueManager _imageLoadingQueue;
        LayoutFarm.UI.UISurfaceViewportControl _vw;
        System.Windows.Forms.Form _ownerForm;
        public WinFormAppHost(LayoutFarm.UI.UISurfaceViewportControl vw)
        {
            //---------------------------------------
            //this specific for WindowForm viewport
            //---------------------------------------
            this._vw = vw;
            _ownerForm = this._vw.FindForm();
            System.Drawing.Rectangle screenRectangle = _ownerForm.RectangleToScreen(_ownerForm.ClientRectangle);
            _formTitleBarHeight = screenRectangle.Top - _ownerForm.Top;


            System.Drawing.Rectangle primScreenWorkingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
            this._primaryScreenWorkingAreaW = primScreenWorkingArea.Width;
            this._primaryScreenWorkingAreaH = primScreenWorkingArea.Height;

            //--------------
            _imageLoadingQueue = new ImageLoadingQueueManager();
            _imageLoadingQueue.AskForImage += (s, e) =>
            {
                e.SetResultImage(LoadImage(e.ImagSource));
            };
            //------- 
        }
        protected override void LazyImageLoad(ImageBinder binder)
        {
            //load here as need
            _imageLoadingQueue.AddRequestImage(binder);
        }
        public override string OwnerFormTitle
        {
            get { return _ownerForm.Text; }
            set
            {
                _ownerForm.Text = value;
            }
        }
        internal LayoutFarm.UI.UISurfaceViewportControl ViewportControl
        {
            get { return this._vw; }
        }

        public override RootGraphic RootGfx
        {
            get { return this._vw.RootGfx; }
        }
        
        public override void AddChild(RenderElement renderElement)
        {
            this._vw.AddChild(renderElement);
        }
        public override void AddChild(RenderElement renderElement, object owner)
        {
            this._vw.AddChild(renderElement, owner);
        }

        public override Image LoadImage(string imgName, int reqW, int reqH)
        {
            if (!File.Exists(imgName)) //resolve to actual img 
            {
                return null;
            }

            //we support svg as src of img
            //...
            //THIS version => just check an extension of the request file
            string ext = System.IO.Path.GetExtension(imgName).ToLower();
            switch (ext)
            {
                default: return null;
                case ".svg":

                    try
                    {
                        string svg_str = File.ReadAllText(imgName);
                        VgRenderVx vgRenderVx = ReadSvgFile(imgName);
                        return CreateBitmap(vgRenderVx);

                    }
                    catch (System.Exception ex)
                    {
                        return null;
                    }
                case ".png":
                case ".jpg":
                    {
                        try
                        {

                            System.Drawing.Bitmap gdiBmp = new System.Drawing.Bitmap(imgName);
                            GdiPlusBitmap bmp = new GdiPlusBitmap(gdiBmp.Width, gdiBmp.Height, gdiBmp);
                            return bmp;
                        }
                        catch (System.Exception ex)
                        {
                            //return error img
                            return null;
                        }<commit_msg>1020: remove unused code<commit_after>﻿//Apache2, 2014-present, WinterDev

using System.IO;
using PixelFarm.Drawing;
using LayoutFarm.Svg;
using PaintLab.Svg;

namespace LayoutFarm
{
    public abstract class AppHost
    {

        protected int _primaryScreenWorkingAreaW;
        protected int _primaryScreenWorkingAreaH;
        protected int _formTitleBarHeight;

        public AppHost()
        {


        }
        public abstract string OwnerFormTitle { get; set; }
        public abstract Image LoadImage(string imgName, int reqW, int reqH);
        public Image LoadImage(string imgName)
        {
            return LoadImage(imgName, 0, 0);
        }
        public int OwnerFormTitleBarHeight { get { return _formTitleBarHeight; } }


        public virtual System.IO.Stream GetReadStream(string src)
        {
            return App.ReadStreamS(src);
        }
        public virtual System.IO.Stream GetWriteStream(string dest)
        {
            return App.GetWriteStream(dest);
        }
        public virtual bool UploadStream(string url, Stream stream)
        {
            return App.UploadStream(url, stream);
        }


        public int PrimaryScreenWidth
        {
            get { return this._primaryScreenWorkingAreaW; }
        }
        public int PrimaryScreenHeight
        {
            get { return this._primaryScreenWorkingAreaH; }
        }
        public abstract void AddChild(RenderElement renderElement);
        public abstract void AddChild(RenderElement renderElement, object owner);

        public abstract RootGraphic RootGfx { get; }
    }



    public class WinFormAppHost : AppHost
    {

        LayoutFarm.UI.UISurfaceViewportControl _vw;
        System.Windows.Forms.Form _ownerForm;
        public WinFormAppHost(LayoutFarm.UI.UISurfaceViewportControl vw)
        {
            //---------------------------------------
            //this specific for WindowForm viewport
            //---------------------------------------
            this._vw = vw;
            _ownerForm = this._vw.FindForm();
            System.Drawing.Rectangle screenRectangle = _ownerForm.RectangleToScreen(_ownerForm.ClientRectangle);
            _formTitleBarHeight = screenRectangle.Top - _ownerForm.Top;


            System.Drawing.Rectangle primScreenWorkingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
            this._primaryScreenWorkingAreaW = primScreenWorkingArea.Width;
            this._primaryScreenWorkingAreaH = primScreenWorkingArea.Height;


        }

        public override string OwnerFormTitle
        {
            get { return _ownerForm.Text; }
            set
            {
                _ownerForm.Text = value;
            }
        }
        internal LayoutFarm.UI.UISurfaceViewportControl ViewportControl
        {
            get { return this._vw; }
        }

        public override RootGraphic RootGfx
        {
            get { return this._vw.RootGfx; }
        }

        public override void AddChild(RenderElement renderElement)
        {
            this._vw.AddChild(renderElement);
        }
        public override void AddChild(RenderElement renderElement, object owner)
        {
            this._vw.AddChild(renderElement, owner);
        }

        public override Image LoadImage(string imgName, int reqW, int reqH)
        {
            if (!File.Exists(imgName)) //resolve to actual img 
            {
                return null;
            }

            //we support svg as src of img
            //...
            //THIS version => just check an extension of the request file
            string ext = System.IO.Path.GetExtension(imgName).ToLower();
            switch (ext)
            {
                default: return null;
                case ".svg":
                    try
                    {
                        string svg_str = File.ReadAllText(imgName);
                        VgRenderVx vgRenderVx = ReadSvgFile(imgName);
                        return CreateBitmap(vgRenderVx);

                    }
                    catch (System.Exception ex)
                    {
                        return null;
                    }
                case ".png":
                case ".jpg":
                    {
                        try
                        {

                            System.Drawing.Bitmap gdiBmp = new System.Drawing.Bitmap(imgName);
                            GdiPlusBitmap bmp = new GdiPlusBitmap(gdiBmp.Width, gdiBmp.Height, gdiBmp);
                            return bmp;
                        }
                        catch (System.Exception ex)
                        {
                            //return error img
                            return null;
                        }
{'fraction_non_alphanumeric': 0.08186046511627906, 'fraction_numerical': 0.0017674418604651163, 'mean_word_length': 1.436763372620127, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 6, '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': '1458517', 'n_tokens_mistral': 2708, 'n_tokens_neox': 2551, 'n_words': 588}