Ejemplo n.º 1
0
        /// <summary>
        /// Init.
        /// </summary>
        public DemoForm()
        {
            SamplesLoader.Init(HtmlRenderingHelper.IsRunningOnMono() ? "Mono" : "WinForms", typeof(HtmlRender).Assembly.GetName().Version.ToString());

            InitializeComponent();

            Icon = GetIcon();
            _openSampleFormTSB.Image     = Common.Properties.Resources.form;
            _showIEViewTSSB.Image        = Common.Properties.Resources.browser;
            _openInExternalViewTSB.Image = Common.Properties.Resources.chrome;
            _useGeneratedHtmlTSB.Image   = Common.Properties.Resources.code;
            _generateImageSTB.Image      = Common.Properties.Resources.image;
            _generatePdfTSB.Image        = Common.Properties.Resources.pdf;
            _runPerformanceTSB.Image     = Common.Properties.Resources.stopwatch;

            StartPosition = FormStartPosition.CenterScreen;
            var size = Screen.GetWorkingArea(Point.Empty);

            Size = new Size((int)(size.Width * 0.7), (int)(size.Height * 0.8));

            LoadCustomFonts();

            _showIEViewTSSB.Enabled = !HtmlRenderingHelper.IsRunningOnMono();
            _generatePdfTSB.Enabled = !HtmlRenderingHelper.IsRunningOnMono();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fix the raw html by replacing bridge object properties calls with path to file with the data returned from the property.
        /// </summary>
        /// <returns>fixed html</returns>
        private string GetFixedHtml()
        {
            var html = _htmlEditor.Text;

            html = Regex.Replace(html, @"src=\""(\w.*?)\""", match =>
            {
                var img = HtmlRenderingHelper.TryLoadResourceImage(match.Groups[1].Value);
                if (img != null)
                {
                    var tmpFile = Path.GetTempFileName();
                    img.Save(tmpFile, ImageFormat.Jpeg);
                    return(string.Format("src=\"{0}\"", tmpFile));
                }
                return(match.Value);
            }, RegexOptions.IgnoreCase);

            html = Regex.Replace(html, @"href=\""(\w.*?)\""", match =>
            {
                var stylesheet = DemoUtils.GetStylesheet(match.Groups[1].Value);
                if (stylesheet != null)
                {
                    var tmpFile = Path.GetTempFileName();
                    File.WriteAllText(tmpFile, stylesheet);
                    return(string.Format("href=\"{0}\"", tmpFile));
                }
                return(match.Value);
            }, RegexOptions.IgnoreCase);

            return(html);
        }
Ejemplo n.º 3
0
        private void GenerateImage()
        {
            if (_backgroundColorTSB.SelectedItem != null && _textRenderingHintTSCB.SelectedItem != null)
            {
                var backgroundColor = Color.FromName(_backgroundColorTSB.SelectedItem.ToString());
                TextRenderingHint textRenderingHint = (TextRenderingHint)Enum.Parse(typeof(TextRenderingHint), _textRenderingHintTSCB.SelectedItem.ToString());

                Image img;
                if (_useGdiPlusTSB.Checked || HtmlRenderingHelper.IsRunningOnMono())
                {
                    img = HtmlRender.RenderToImageGdiPlus(_html, _pictureBox.ClientSize, textRenderingHint, null, DemoUtils.OnStylesheetLoad, HtmlRenderingHelper.OnImageLoad);
                }
                else
                {
                    EventHandler <HtmlStylesheetLoadEventArgs> stylesheetLoad = DemoUtils.OnStylesheetLoad;
                    EventHandler <HtmlImageLoadEventArgs>      imageLoad      = HtmlRenderingHelper.OnImageLoad;
                    var objects = new object[] { _html, _pictureBox.ClientSize, backgroundColor, null, stylesheetLoad, imageLoad };

                    var types = new[] { typeof(String), typeof(Size), typeof(Color), typeof(CssData), typeof(EventHandler <HtmlStylesheetLoadEventArgs>), typeof(EventHandler <HtmlImageLoadEventArgs>) };
                    var m     = typeof(HtmlRender).GetMethod("RenderToImage", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, types, null);
                    img = (Image)m.Invoke(null, objects);
                }
                _pictureBox.Image = img;
            }
        }
Ejemplo n.º 4
0
        public GenerateImageForm(string html)
        {
            _html = html;
            InitializeComponent();

            Icon = DemoForm.GetIcon();

            _background = HtmlRenderingHelper.CreateImageForTransparentBackground();

            foreach (var color in GetColors())
            {
                if (color != Color.Transparent)
                {
                    _backgroundColorTSB.Items.Add(color.Name);
                }
            }
            _backgroundColorTSB.SelectedItem = Color.White.Name;

            foreach (var hint in Enum.GetNames(typeof(TextRenderingHint)))
            {
                _textRenderingHintTSCB.Items.Add(hint);
            }
            _textRenderingHintTSCB.SelectedItem = TextRenderingHint.AntiAlias.ToString();

            _useGdiPlusTSB.Enabled      = !HtmlRenderingHelper.IsRunningOnMono();
            _backgroundColorTSB.Enabled = !HtmlRenderingHelper.IsRunningOnMono();
        }
Ejemplo n.º 5
0
        public SampleForm()
        {
            InitializeComponent();

            Icon = DemoForm.GetIcon();

            _htmlLabel.Text = DemoUtils.SampleHtmlLabelText;
            _htmlPanel.Text = DemoUtils.SampleHtmlPanelText;

            _background = HtmlRenderingHelper.CreateImageForTransparentBackground();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// On tree view node click load the html to the html panel and html editor.
        /// </summary>
        private void OnSamplesTreeViewAfterSelect(object sender, TreeViewEventArgs e)
        {
            var sample = e.Node.Tag as HtmlSample;

            if (sample != null)
            {
                _updateLock = true;

                if (!HtmlRenderingHelper.IsRunningOnMono() && e.Node.Parent.Text != PerformanceSamplesTreeNodeName)
                {
                    SetColoredText(sample.Html);
                }
                else
                {
                    _htmlEditor.Text = sample.Html;
                }

                Application.UseWaitCursor = true;

                try
                {
                    _htmlPanel.AvoidImagesLateLoading = !sample.FullName.Contains("Many images");

                    _htmlPanel.Text = sample.Html;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Failed to render HTML");
                }

                Application.UseWaitCursor = false;
                _updateLock = false;

                UpdateWebBrowserHtml();
            }
        }