Example #1
0
        public HtmlHost(HtmlHostCreationConfig config)
        {
            //use default style sheet

#if DEBUG
            if (!config.ValidateConfig())
            {
                throw new NotSupportedException();
            }
#endif

            _commonHtmlDoc = new HtmlDocument(this);
            if (config.ActiveSheet != null)
            {
                _commonHtmlDoc.CssActiveSheet = this.BaseStylesheet = config.ActiveSheet;
            }
            else
            {
                //use default
                _commonHtmlDoc.CssActiveSheet = this.BaseStylesheet =
                    LayoutFarm.WebDom.Parser.CssParserHelper.ParseStyleSheet(null,
                                                                             LayoutFarm.Composers.CssDefaults.DefaultCssData,
                                                                             true);
            }

            _rootgfx       = config.RootGraphic;
            _txtsx         = config.TextService;
            _svgCreator    = new PaintLab.Svg.SvgCreator();
            _mathMLCreator = new PaintLab.MathML.MathMLBoxTreeCreator();
        }
Example #2
0
        public static HtmlBoxes.HtmlHost CreateHtmlHost(AppHost appHost,
                                                        EventHandler <ContentManagers.ImageRequestEventArgs> imageReqHandler,
                                                        EventHandler <ContentManagers.TextRequestEventArgs> textReq)
        {
            List <HtmlBoxes.HtmlVisualRoot> htmlVisualRootUpdateList = new List <HtmlBoxes.HtmlVisualRoot>();

            var config = new HtmlBoxes.HtmlHostCreationConfig()
            {
                RootGraphic = appHost.RootGfx,
                TextService = appHost.RootGfx.TextServices
            };

            //1.
            HtmlBoxes.HtmlHost htmlhost = new HtmlBoxes.HtmlHost(config);  //create html host with config
            appHost.RootGfx.ClearingBeforeRender += (s, e) =>
            {
                //
                htmlhost.ClearUpdateWaitingCssBoxes();
                //
                int j = htmlVisualRootUpdateList.Count;
                for (int i = 0; i < j; ++i)
                {
                    HtmlBoxes.HtmlVisualRoot htmlVisualRoot = htmlVisualRootUpdateList[i];
                    htmlVisualRoot.RefreshDomIfNeed();
                    htmlVisualRoot.IsInUpdateQueue = false;
                }
                htmlVisualRootUpdateList.Clear();
            };
            //2.
            htmlhost.RegisterCssBoxGenerator(new LayoutFarm.CustomWidgets.MyCustomCssBoxGenerator(htmlhost));
            //3.
            htmlhost.AttachEssentailHandlers(imageReqHandler, textReq);
            //4.
            htmlhost.SetHtmlVisualRootUpdateHandler(htmlVisualRoot =>
            {
                if (!htmlVisualRoot.IsInUpdateQueue)
                {
                    htmlVisualRoot.IsInUpdateQueue = true;
                    htmlVisualRootUpdateList.Add(htmlVisualRoot);
                }
            });

            //-----------------------------------------------------------------

            if (PaintLab.Svg.VgResourceIO.VgImgIOHandler == null)
            {
                var imgLoadingQ = new ContentManagers.ImageLoadingQueueManager();
                imgLoadingQ.AskForImage += (s, e) =>
                {
                    //check loading policy here
                    //
                    e.SetResultImage(LoadImage(e.ImagSource));
                };
                PaintLab.Svg.VgResourceIO.VgImgIOHandler = (LayoutFarm.ImageBinder binder, PaintLab.Svg.VgVisualElement imgRun, object requestFrom) =>
                {
                    imgLoadingQ.AddRequestImage(binder);
                };
            }

            return(htmlhost);
        }