/// <summary> /// Constructor /// </summary> public HelmOffScreenBrowserCef() { CefMx.InitializeOffScreenCef(); if (Debug) { DebugLog.Message("CefOffScreenMx instance created"); } return; }
/// <summary> /// Get SVG of the specified HELM in the specified size /// </summary> /// <param name="helm"></param> /// <param name="size"></param> /// <returns></returns> public string GetSvg( string helm, Size size) { ManualResetEvent GetSvgEvent = new ManualResetEvent(false); string svg = null; Initialize(); if (Debug) { DebugLog.Message("GetSvg Entered: " + helm + ", " + size); } Stopwatch sw = Stopwatch.StartNew(); Helm = helm; CurrentSize = size; int initialOnPaintCount = OnPaintCount; // save current paint count so we can tell when page has been re-rendered with new image string script = ""; if (!String.IsNullOrWhiteSpace(helm)) { script += "jsd.setHelm(\"" + helm + "\");"; } if (!size.IsEmpty) { int width = size.Width; int height = size.Height; if (height <= 0) { height = width; } script += "jsd.setSize(" + width + "," + height + ");"; } script += "jsd.refresh();"; // redraws the structure script += "jsd.getSvg();"; svg = CefMx.ExecuteStringResultJavaScript(OffScreenBrowser, script); GetSvgCount++; if (Debug) { DebugLog.StopwatchMessage("GetSvg Complete, Time: ", sw); } return(svg); }
/// <summary> /// Constructor /// </summary> public HelmWinFormsBrowserCef( HelmControlMode renderMode, Control containingControl) { CefMx.InitializeCef(); RendererMode = renderMode; if (renderMode == HelmControlMode.OffScreenSvg) { Browser = new CefSharp.WinForms.ChromiumWebBrowser(""); // Create the Chromium browser to contain the generated SVG Browser.FrameLoadEnd += OnFrameLoadEnd; // used to remove scroll bars } ContainingControl = containingControl; if (Debug) { DebugLog.Message("CefWinFormsMx instance created"); } return; }
public void SetHelmAndRender( string helm, Size size = new Size()) { string script = ""; Helm = helm; if (RendererMode == HelmControlMode.BrowserViewOnly) { if (!String.IsNullOrWhiteSpace(helm)) { script += "jsd.setHelm(\"" + helm + "\");"; // var jsd = new JSDraw(...) is JSDraw canvas object JavaScript variable } if (!size.IsEmpty) { script += "jsd.setSize(" + size.Width + "," + size.Height + ");"; } script += "jsd.refresh();"; // redraws the structure } else // editor mode { script += // set the helm allowing for blank helm to clear the structure "app.canvas.setHelm(\"" + helm + "\");"; // var app = new scil.helm.App(), app.canvas is JSDraw canvas object //if (!size.IsEmpty) // script += "app.canvas.setSize(" + scaledCanvasWidth + "," + scaledCanvasHeight + ");"; script += "app.canvas.refresh();"; // redraws the structure } CefMx.ExecuteJavaScript(Browser, script); return; }
/// <summary> /// Execute JavaScript that returns a string result /// </summary> /// <param name="script"></param> /// <returns></returns> public string ExecuteStringResultJavaScript( string script) { return(CefMx.ExecuteStringResultJavaScript(Browser, script)); }
/// <summary> /// Execute JavaScript that return a string result /// </summary> /// <param name="script"></param> /// <returns></returns> public static string ExecuteStringResultJavaScript( IWebBrowser browser, string script) { return(CefMx.ExecuteStringResultJavaScript(browser, script)); }