Пример #1
0
        private void DrawHtml(FRPaintEventArgs e)
        {
            using (var container = new HtmlContainer())
            {
                var state = e.Graphics.Save();
                try
                {
                    e.Graphics.ScaleTransform(e.ScaleX, e.ScaleY);
                    container.Location = new PointF(AbsLeft, AbsTop);
                    container.MaxSize  = new SizeF(Width, Height);
                    container.AvoidAsyncImagesLoading = true;
                    container.AvoidImagesLateLoading  = true;
                    container.UseGdiPlusTextRendering = true;



                    //if (stylesheetLoad != null)
                    //    container.StylesheetLoad += stylesheetLoad;
                    //if (imageLoad != null)
                    //    container.ImageLoad += imageLoad;

                    container.SetHtml(Text, null /*cssData*/);
                    container.PerformLayout(e.Graphics);
                    container.PerformPaint(e.Graphics);

                    //actualSize = container.ActualSize;
                }
                finally
                {
                    e.Graphics.Restore(state);
                }
            }
        }
Пример #2
0
        void CreateBitmap()
        {
            int width = (int)m_WidthSlider.Value;

            m_HtmlContainer.MaxSize = new Size(width, 0);
            using (Graphics g = Graphics.CreateDefaultGraphics())
            {
                m_HtmlContainer.PerformLayout(g);
                int height = (int)m_HtmlContainer.ActualSize.Height;

                if (m_Image != null &&
                    m_Image.PixelSize != new SizeI(width, height))
                {
                    m_Image.Dispose();
                    m_Image = null;
                }

                if (!m_HtmlContainer.ActualSize.IsEmpty)
                {
                    if (m_Image == null)
                    {
                        m_Image = new Bitmap(width, height);//m_HtmlContainer.ActualSize.ToSizeI());
                    }

                    using (Graphics graphics = Graphics.FromImage(m_Image))
                    {
                        if (m_FillBackground.IsChecked)
                        {
                            graphics.Clear(Color.FromArgb(128, Color.White));
                        }
                        else
                        {
                            graphics.Clear(Color.Empty);//Transparent);
                        }

                        m_HtmlContainer.ScrollOffset = Point.Zero;
#if !SILVERLIGHT
                        graphics.TextRenderingHint = m_AntiAliasText.IsChecked ? TextRenderingHint.AntiAliasGridFit : TextRenderingHint.Default;
#endif
                        m_HtmlContainer.PerformPaint(graphics);
                    }

                    m_ImagePanel.Size = m_Image.PixelSize;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Used to execute performance test run for memory profiler so the form is not loaded,
        /// only html container is working.
        /// </summary>
        public static void Run(bool layout, bool paint)
        {
            try
            {
                LoadRunSamples();

                var htmlContainer = new HtmlContainer();
                htmlContainer.MaxSize = new SizeF(800, 0);

                GC.Collect();
                Thread.Sleep(3000);

                using (var img = new Bitmap(1, 1))
                    using (var g = Graphics.FromImage(img))
                    {
                        for (int i = 0; i < Iterations; i++)
                        {
                            foreach (var html in _perfTestSamples)
                            {
                                htmlContainer.SetResourceServerAsync(new WinFormsDemoResourceServer(html));

                                if (layout)
                                {
                                    htmlContainer.PerformLayout(g);
                                }

                                if (paint)
                                {
                                    htmlContainer.PerformPaint(g);
                                }
                            }
                        }
                    }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
Пример #4
0
        static void Main()
        {
            using (var bitmap = new Bitmap(300, 200, PixelFormat.Format24bppRgb))
            {
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    graphics.Clear(Color.Black);

                    graphics.DrawLine(Pens.Fuchsia, 0,0,300,200);

                    TextRenderer.DrawText(graphics, "TEST", new Font("Arial", 20), new Point(0, 0), Color.FromArgb(50, 0, 255, 0),Color.White);

                    graphics.CompositingQuality = CompositingQuality.HighQuality;
                    graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    graphics.SmoothingMode = SmoothingMode.HighQuality;
                    graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

                    using (var htmlContainer = new HtmlContainer())
                    {
                        htmlContainer.TextRenderingMethod = TextRenderingMethod.Gdi;
                        htmlContainer.AvoidGeometryAntialias = false;
                        htmlContainer.SetHtml(File.ReadAllText(@"c:\source\html.txt"));
                        htmlContainer.MaxSize = new SizeF(bitmap.Width, bitmap.Height);
                        htmlContainer.PerformLayout(graphics);
                        htmlContainer.PerformPaint(graphics);
                    }
                }

                bitmap.Save(@"c:\source\test.png");
            }

            return;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new DemoForm());

            //            Application.Run(new PerfForm());

            //            ObfuscateHtml();
        }
Пример #5
0
        static void Main(string[] args)
        {
            SDL2.SDL2_CS_libs_bundle.Init();
            InitSDL2();

            var window = SDL.SDL_CreateWindow("HtmlRenderer.SDL2-CS.Demo", SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED,
                                              640, 480, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN | SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE);

            if (!window.ShowSDLError("Window could not be created!"))
            {
                Console.WriteLine("Window created!");
            }

            var renderer = SDL.SDL_CreateRenderer(window, -1, SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED);

            renderer.ShowSDLError("Renderer could not be created!");


            using (var hc = new HtmlContainer(renderer,
                                              fm_font_directory: "fonts", fm_serif: "PT Serif", fm_sans_serif: "PT Sans", fm_monospace: "PT Mono"))
            {
                //fm_font_directory: @"C:\Windows\Fonts\", fm_serif: "Segoe UI", fm_sans_serif: "Arial", fm_monospace: "Lucida Console");


                //string html_text = System.IO.File.ReadAllText(@"../../../HTML-Renderer/Source/Demo/Common/Samples/02.Text.htm");
                //string html_tables = System.IO.File.ReadAllText(@"../../../HTML-Renderer/Source/Demo/Common/TestSamples/13.Tables.htm");


                //string html_file = @"../../html/test.html";
                //string html_dir = "html/";

                string html_file = @"../../../HTML-Renderer/Source/Demo/Common/Samples/02.Text.htm";
                string html_dir  = @"../../../HTML-Renderer/Source/Demo/Common/Samples/";


                hc.SetHtml(System.IO.File.ReadAllText(html_file), html_dir);
                //hc.SetHtml(html_text);
                //hc.SetHtml(html_tables);

                bool exit = false;
                int  i    = 0;
                while (!exit)
                {
                    while (SDL.SDL_PollEvent(out SDL.SDL_Event e) == 1)
                    {
                        switch (e.type)
                        {
                        case SDL.SDL_EventType.SDL_QUIT:
                            exit = true;
                            break;

                        case SDL.SDL_EventType.SDL_KEYDOWN:
                            switch (e.key.keysym.scancode)
                            {
                            case SDL.SDL_Scancode.SDL_SCANCODE_F5:
                                Console.WriteLine("F5 - reload {0}", html_file);
                                hc.SetHtml(System.IO.File.ReadAllText(html_file), html_dir);
                                break;

                            case SDL.SDL_Scancode.SDL_SCANCODE_ESCAPE:
                                exit = true;
                                break;
                            }

                            break;

                        case SDL.SDL_EventType.SDL_MOUSEMOTION:
                            hc.HandleMouseMove(e.motion);
                            break;

                        case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
                            hc.HandleMouseDown(e.button);
                            break;

                        case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
                            hc.HandleMouseUp(e.button);
                            break;
                        }
                    }


                    hc.MaxSize = hc.adapter.GetRendererRect().ToRSize();

                    /*
                     * var el = hc.document.getElementById("text");
                     * el.style["height"] = "" + i + "px";
                     * el.style["width"] = "" + i + "px";
                     * el.innerHTML = "" + i;
                     */
                    hc.PerformLayout();
                    hc.PerformPaint();
                    SDL.SDL_RenderPresent(renderer);
                    SDL.SDL_Delay(50);
                    i++;
                }
            }
            QuitSDL2();
        }