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); } } }
public override void SetHtml(string text) { m_ImageScrollControl.ScrollToTop(); m_ImageScrollControl.ScrollToLeft(); m_HtmlContainer.SetHtml(text, HtmlRender.ParseStyleSheet//CssData.Parse (null, true)); CreateBitmap(); m_ImagePanel.Show(); }
/// <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.SetHtml(html); if (layout) { htmlContainer.PerformLayout(g); } if (paint) { htmlContainer.PerformPaint(g); } } } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error"); } }
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(); }
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(); }
private void SetText(string text) { _htmlContainer.SetHtml(text.StartsWith(@"<html") ? text : @"<html><body>" + text + @"</body><html>", YamuiThemeManager.CurrentThemeCss); }